ympc-utils
v1.1.2
Published
Utilily functions used throughout YOMYPOPCORN apps
Downloads
3
Readme
ympc-utils
Utility functions used throughout YOMYPOPCORN apps.
Installation
npm install ympc-utils --save
API
var utils = require('ympc-utils');
str = utils.padTime(time)
Left-pads a timestamp with '0's and returns a 16-character string;
utils.padTime(+new Date());
// '0001438304724009'
utils.cb(callback [, ...arguments])
A callback helper for optional callbacks. Only calls callback
with
arguments
if callback
is actually a function.
function somethingAsync (callback) {
setTimeout(function fakeAsync () {
cb(callback, null, 'w00t');
}, 1000);
}
somethingAsync();
int = utils.sien(season, episode)
Creates a season-independent episode number by multiplying the season number by 1000 and adding it to the episode number. It assumes that a show has never more than 999 episodes per season. fingers crossed
Season 1, Episode 22 becomes 1022.
utils.sien(1, 22);
// 1022
object = utils.removeNonScalars(obj)
Returns a new object that has all non-scalar properties removed.
var myObj = {
heeey: 'hooo',
yolo: true,
feet: {
left: 2,
right: 0
},
spin: function () { return 'weeeeee'; }
};
utils.removeNonScalars(myObj);
// { heeey: 'hooo', yolo: true }
string = utils.generateUserToken(secret, username)
Returns a hex-encoded SHA1 hash of username
and secret
.
utils.generateUserToken('secret', 'peter');
// '4df9d4f8adcd0736'
boolean = utils.validateUserToken(secret, username, token)
Validates a token generated by utils.generateUserToken()
.
utils.validateUserToken('secret', 'peter', '4df9d4f8adcd0736');
// true
License
MIT