Javascript functions that are needed repeatedly but are missing in NodeJS.
Run npm install missing-in-node
or yarn add missing-in-node
.
You can then use the module in your project as the example below illustrates:
const M = require("missing-in-node");
console.log(M.btoa("Encode this string")); // outputs: RW5jb2RlIHRoaXMgc3RyaW5n
atob(input: string) : string
decodes a Base64 stringbtoa(input: string) : string
encodes into a Base64 stringchr(num: int) : string
an alias for String.fromCharCodeord(char: string) : int
an alias for String.prototype.charCodeAtreverse(input: string) : string
returns the reversed string without modifying the original onestartsWith(text: string, start: string) : bool
returns true only if the first arg starts with the second argendsWith(text: string, end: string) : bool
returns true only if the first arg ends with the second argoccurences(haystack: string, needle: string) : int
returns number of occurences of a string in another stringmultiplyString(str: string, count: int) : string
returns he original string repeated count times
performance.now() : float
returns the milliseconds that passed since the process startedsleep(milliseconds)
asynchronous function that sleeps the number of milliseconds provided in its argument
randomInt(n1: int, n2: int) : int
fast but cryptographically insecure function that returns an integer between 0 and (n1 - 1) if only n1 is provided, otherwise an integer between n1 and (n2 - 1)randomIntWeighted(n1: int, n2: int, weight: float) : int
same as ramdomInt but with weight parameter (between 0 and 1) that makes the random distribution leans towards n1 or n2randomIntsInRange(n1 : int, n2: int, count: int) : array
returns an array with count numbers of sorted random integers between n1 and (n2 - 1)randomFloat(n1: float, n2: float) : float
returns a float between 0 and n1 if only n1 is provided, otherwise a float between n1 and n2randomBool() : bool
returns true or false randomlyrandomAlphaNumeric() : string
returns a random alphanumeric character (from A-Z or a-z or 0-9)randomAlpha() : string
returns a random alpha character (from A-Z or a-z)randomAlphaUpper() : string
returns a random uppercase alpha character (from A-Z)randomAlphaLower() : string
returns a random lowercase alpha character (from a-z)randomDigit() : string
returns a random decimal digit character (from 0-9)randomHexDigit() : string
returns a random hexadecimal digit character (from 0-9 or A-F)randomFromList(list: array) : any
returns a random element from listrandomWithPercentage(obj: object): any
returns a random key from an object with format{"option1": percentage1, "option2": percentage2, ...}
randomFromObject(obj: object): object
returns a random key-value pair from an objectcrypto.randomInt(n1: int, n2: int) : int
cryptograhically secure random integer generatorcrypto.getRandomValues(array) : array
fills an array with random values similarly to its browser counterpart
bin(num: int) : string
an alias for .toString(2)oct(num: int) : string
an alias for .toString(8)hex(num: int) : string
an alias for .toString(16)hex(text: string) : string
converts a text or a binary string to hexadecimal stringhex(arr: array) : string
converts an array of bytes to hexadecimal stringdec(num: string, base: int) : int
an alias for parseInt(num, base)round(number: float or string, decimalDigits: int) : float
rounds a number to a particular number of decimal digitsreverse(input: number) : number
returns the reversed number without modifying the original onefactorial(num: int) : int
calculates the factorial of a positive integerfibonacci(num: int) : int
calculates the n-th number in fibonacci series using non-recursive methodisPrime(num: int) : bool
determines whether an integer is prime or not
listEquals(list1, list2) : bool
determines if two arrays or two sets are equal (for primitive type elements only)objectEquals(object1, object2) : bool
determines if two objects or are equal (for primitive type values only)reverse(input: array) : array
returns a reversed array without modifying the original oneshuffle(arr: array) : array
returns a shuffled array (using Knuth method) without modifying the original oneunion(set1: set, set2: set) : set
returns the union of two setsintersection(set1: set, set2: set) : set
returns the intersection of two setsdifference(set1: set, set2: set) : set
returns the difference of two setsclone(obj: any) : any
returns a shallow copy of an object or an array
repeatFunction(func: function, count: int, argsArray: array) : array
executes a function count times and returns the function return values in an arraymultiFunction(arg: any, funcArray: array, classObj: object) : any
applies the functions in funcArray in order on the argument arg; elements in funcArray must be either funciton objects if classObj is not supplied, or strings that represent methods of classObj otherwiserunSequential(funcArray: array) : array
executes functions in funcArray sequentially; each element in the array is an object in the form { func: funcObj, args: [] }; the return values are returned in the same order in an arrayrunConcurrent(funcArray: array) : array
executes functions in funcArray concurrently; each element in the array is an object in the form { func: funcObj, args: [] }; the return values are returned in the same order in an arraybenchmark(func: function, count: int, argsArray: array)
executes a function count times and prints the to stdout the total execution time