npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

missing-in-node

v1.8.2

Published

Functions that exist in common browsers but are missing in node

Downloads

17

Readme

missing-in-node

Build

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: RW5jb2RlIHRoaXMgc3RyaW5n

Functions provided in this package

String functions

  • atob(input: string) : string decodes a Base64 string
  • btoa(input: string) : string encodes into a Base64 string
  • chr(num: int) : string an alias for String.fromCharCode
  • ord(char: string) : int an alias for String.prototype.charCodeAt
  • reverse(input: string) : string returns the reversed string without modifying the original one
  • startsWith(text: string, start: string) : bool returns true only if the first arg starts with the second arg
  • endsWith(text: string, end: string) : bool returns true only if the first arg ends with the second arg
  • occurences(haystack: string, needle: string) : int returns number of occurences of a string in another string
  • multiplyString(str: string, count: int) : string returns he original string repeated count times

Time functions

  • performance.now() : float returns the milliseconds that passed since the process started
  • sleep(milliseconds) asynchronous function that sleeps the number of milliseconds provided in its argument

Random functions

  • 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 n2
  • randomIntsInRange(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 n2
  • randomBool() : bool returns true or false randomly
  • randomAlphaNumeric() : 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 list
  • randomWithPercentage(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 object
  • crypto.randomInt(n1: int, n2: int) : int cryptograhically secure random integer generator
  • crypto.getRandomValues(array) : array fills an array with random values similarly to its browser counterpart

Numerical functions

  • 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 string
  • hex(arr: array) : string converts an array of bytes to hexadecimal string
  • dec(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 digits
  • reverse(input: number) : number returns the reversed number without modifying the original one
  • factorial(num: int) : int calculates the factorial of a positive integer
  • fibonacci(num: int) : int calculates the n-th number in fibonacci series using non-recursive method
  • isPrime(num: int) : bool determines whether an integer is prime or not

List functions

  • 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 one
  • shuffle(arr: array) : array returns a shuffled array (using Knuth method) without modifying the original one
  • union(set1: set, set2: set) : set returns the union of two sets
  • intersection(set1: set, set2: set) : set returns the intersection of two sets
  • difference(set1: set, set2: set) : set returns the difference of two sets
  • clone(obj: any) : any returns a shallow copy of an object or an array

function-related functions

  • repeatFunction(func: function, count: int, argsArray: array) : array executes a function count times and returns the function return values in an array
  • multiFunction(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 otherwise
  • runSequential(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 array
  • runConcurrent(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 array
  • benchmark(func: function, count: int, argsArray: array) executes a function count times and prints the to stdout the total execution time