JS Utils
Flywheel JS utils is a library of useful JavaScript utilities.
Install
You can install it via NPM:
$ npm -i fwsp-jsutils
Usage
const Utils = ;let hash = Utils;
Tests
Tests can be found in the specs
folder.
$ npm test
API
strip - strips white space characters - except for spaces
/** * @name strip * @summary strips white space characters - except for spaces * @param * @return */ static
zeroPad - add preceeding zeros to maintain desired places
/** * @name zeroPad * @summary add preceeding zeros to maintain desired places * @param * @param * @return */ static
stringHash - returns a hash value for a supplied string
/** * @name stringHash * @summary returns a hash value for a supplied string * @see https://github.com/darkskyapp/string-hash * @private * @param * @return */ static
shortID - generate a random id composed of alphanumeric characters
/** * @name shortID * @summary generate a random id composed of alphanumeric characters * @see https://en.wikipedia.org/wiki/Base36 * @return */ static
UUID - Pseudo UUID
/** * @name UUID * @summary Pseudo UUID * @return */ static
UUID - Test
/** * @name isUUID4 * @summary determine whether a string is a valid UUID * @param * @return */ static
isObject - Determines whether a variable is an object
/** * @name isObject * @summary Determines whether a variable is an object * @param * @return */ static
isArray - Determines whether a variable is an array
/** * @name isArray * @summary Determines whether a variable is an array * @param * @return */ static
safeJSONStringify - Safe JSON stringify
/** * @name safeJSONParse * @summary Safe JSON parse * @private * @param * @return * Returns undefined if string can't be parsed into an object */ static
safeJSONParse - Safe JSON parse
/** * @name safeJSONParse * @summary Safe JSON parse * @private * @param * @return * Returns undefined if string can't be parsed into an object */ static
shuffleArray - Uses the Durstenfeld shuffle algorithm
/** * @name shuffleArray * @summary Shuffles and array * @description Uses the Durstenfeld shuffle algorithm * @param * @return */ static
htmlEncode - Encode HTML text by converting characters to html codes
/** * @name htmlEncode * @summary Encode HTML text by converting characters to html codes * @param * @return */ static
htmlDecode - Decode HTML text to original form
/** * @name htmlDecode * @summary Decode HTML text to original form * @param * @return */ static
md5Hash - Hashes a key to produce an MD5 hash
/** * @name md5Hash * @summary Hashes a key to produce an MD5 hash * @param * @return */ static
getGeoDistance - Get the distance between to lat/lngs
/** * @name getGeoDistance * @summary Get the distance between to lat/lngs * @notes http://stackoverflow.com/questions/27928/how-do-i-calculate-distance-between-two-latitude-longitude-points * @param * @param * @param * @param * @return */ static {
getRandom - Returns a random number between 0 (inclusive) and 1 (exclusive)
/** * @name getRandom * @summary Returns a random number between 0 (inclusive) and 1 (exclusive) * @return */ static
getRandomArbitrary - Returns a random number between min (inclusive) and max (exclusive)
/** * @name getRandomArbitrary * @summary Returns a random number between min (inclusive) and max (exclusive) * @return */ static
getRandomInt - Returns a random integer between min (included) and max (excluded)
/** * @name getRandomInt * @summary Returns a random integer between min (included) and max (excluded) * @return */ static
getRandomIntInclusive - Returns a random integer between min (included) and max (included)
/** * @name getRandomIntInclusive * @summary Returns a random integer between min (included) and max (included) * @return */ static