1.8.2 • Published 3 years ago
missing-in-node v1.8.2
missing-in-node
Javascript functions that are needed repeatedly but are missing in NodeJS.
How to install and use
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: RW5jb2RlIHRoaXMgc3RyaW5nFunctions provided in this package
String functions
atob(input: string) : stringdecodes a Base64 stringbtoa(input: string) : stringencodes into a Base64 stringchr(num: int) : stringan alias for String.fromCharCodeord(char: string) : intan alias for String.prototype.charCodeAtreverse(input: string) : stringreturns the reversed string without modifying the original onestartsWith(text: string, start: string) : boolreturns true only if the first arg starts with the second argendsWith(text: string, end: string) : boolreturns true only if the first arg ends with the second argoccurences(haystack: string, needle: string) : intreturns number of occurences of a string in another stringmultiplyString(str: string, count: int) : stringreturns he original string repeated count times
Time functions
performance.now() : floatreturns the milliseconds that passed since the process startedsleep(milliseconds)asynchronous function that sleeps the number of milliseconds provided in its argument
Random functions
randomInt(n1: int, n2: int) : intfast 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) : intsame 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) : arrayreturns an array with count numbers of sorted random integers between n1 and (n2 - 1)randomFloat(n1: float, n2: float) : floatreturns a float between 0 and n1 if only n1 is provided, otherwise a float between n1 and n2randomBool() : boolreturns true or false randomlyrandomAlphaNumeric() : stringreturns a random alphanumeric character (from A-Z or a-z or 0-9)randomAlpha() : stringreturns a random alpha character (from A-Z or a-z)randomAlphaUpper() : stringreturns a random uppercase alpha character (from A-Z)randomAlphaLower() : stringreturns a random lowercase alpha character (from a-z)randomDigit() : stringreturns a random decimal digit character (from 0-9)randomHexDigit() : stringreturns a random hexadecimal digit character (from 0-9 or A-F)randomFromList(list: array) : anyreturns a random element from listrandomWithPercentage(obj: object): anyreturns a random key from an object with format{"option1": percentage1, "option2": percentage2, ...}randomFromObject(obj: object): objectreturns a random key-value pair from an objectcrypto.randomInt(n1: int, n2: int) : intcryptograhically secure random integer generatorcrypto.getRandomValues(array) : arrayfills an array with random values similarly to its browser counterpart
Numerical functions
bin(num: int) : stringan alias for .toString(2)oct(num: int) : stringan alias for .toString(8)hex(num: int) : stringan alias for .toString(16)hex(text: string) : stringconverts a text or a binary string to hexadecimal stringhex(arr: array) : stringconverts an array of bytes to hexadecimal stringdec(num: string, base: int) : intan alias for parseInt(num, base)round(number: float or string, decimalDigits: int) : floatrounds a number to a particular number of decimal digitsreverse(input: number) : numberreturns the reversed number without modifying the original onefactorial(num: int) : intcalculates the factorial of a positive integerfibonacci(num: int) : intcalculates the n-th number in fibonacci series using non-recursive methodisPrime(num: int) : booldetermines whether an integer is prime or not
List functions
listEquals(list1, list2) : booldetermines if two arrays or two sets are equal (for primitive type elements only)objectEquals(object1, object2) : booldetermines if two objects or are equal (for primitive type values only)reverse(input: array) : arrayreturns a reversed array without modifying the original oneshuffle(arr: array) : arrayreturns a shuffled array (using Knuth method) without modifying the original oneunion(set1: set, set2: set) : setreturns the union of two setsintersection(set1: set, set2: set) : setreturns the intersection of two setsdifference(set1: set, set2: set) : setreturns the difference of two setsclone(obj: any) : anyreturns a shallow copy of an object or an array
function-related functions
repeatFunction(func: function, count: int, argsArray: array) : arrayexecutes a function count times and returns the function return values in an arraymultiFunction(arg: any, funcArray: array, classObj: object) : anyapplies 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) : arrayexecutes 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) : arrayexecutes 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
1.8.2
3 years ago
1.8.1
3 years ago
1.8.0
4 years ago
1.7.3
4 years ago
1.7.2
4 years ago
1.7.1
4 years ago
1.7.0
4 years ago
1.7.5
4 years ago
1.7.4
4 years ago
1.6.4
4 years ago
1.6.3
4 years ago
1.6.2
4 years ago
1.6.1
4 years ago
1.6.0
4 years ago
1.6.5
4 years ago
1.5.1
4 years ago
1.5.0
4 years ago
1.4.0
4 years ago
1.2.0
4 years ago
1.1.0
4 years ago
1.3.1
4 years ago
1.3.0
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago