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 = require('fwsp-jsutils');
let hash = Utils.stringHash('This is a test');
Tests
Tests can be found in the specs
folder.
$ npm test
API
strip - strips white space characters - except for spaces
static strip(str)
zeroPad - add preceeding zeros to maintain desired places
static zeroPad(num, places)
stringHash - returns a hash value for a supplied string
static stringHash(str)
shortID - generate a random id composed of alphanumeric characters
static shortID()
UUID - Pseudo UUID
static UUID()
UUID - Test
static isUUID(str)
isObject - Determines whether a variable is an object
static isObject(obj)
isArray - Determines whether a variable is an array
static isArray(obj)
safeJSONStringify - Safe JSON stringify
static safeJSONStringify(obj)
safeJSONParse - Safe JSON parse
static safeJSONParse(str)
shuffleArray - Uses the Durstenfeld shuffle algorithm
static shuffleArray(array)
htmlEncode - Encode HTML text by converting characters to html codes
static htmlEncode(text)
htmlDecode - Decode HTML text to original form
static htmlDecode(text)
md5Hash - Hashes a key to produce an MD5 hash
static md5Hash(key)
getGeoDistance - Get the distance between to lat/lngs
static getGeoDistance(lat1, lng1, lat2, lng2) {
getRandom - Returns a random number between 0 (inclusive) and 1 (exclusive)
static getRandom()
getRandomArbitrary - Returns a random number between min (inclusive) and max (exclusive)
static getRandomArbitrary(min, max)
getRandomInt - Returns a random integer between min (included) and max (excluded)
static getRandomInt(min, max)
getRandomIntInclusive - Returns a random integer between min (included) and max (included)
static getRandomIntInclusive(min, max)