@jp6rt/utils

1.0.4 • Public • Published

node-utils

Utility functions for nodeJS applications

usage

const { random, hexrandom, format, inArray  } = require('@jp6rt/utils')

/**
 * random(min=1, max=10) returns a number within range(min, max)
 */

const rand = random(1,2) // returns 1 or 2

/**
 * hexrandom() returns a random hex char
 */

const hexchar = hexrandom()

/**
 * format - Formats a string e.g., format(foo+{0}, bar) => foo+bar
 */

const foobar = format('{0}{1}', 'foo', 'bar') // retuns 'foobar'

/**
 * Traditional in_array function
 * @param { string } needle 
 * @param { array } haystack 
 */

inArray('foo', ['foo', 'bar']) // returns true
inArray('oof', ['foo', 'bar']) // returns false

Dependents (4)

Package Sidebar

Install

npm i @jp6rt/utils

Weekly Downloads

1

Version

1.0.4

License

MIT

Unpacked Size

6.56 kB

Total Files

7

Last publish

Collaborators

  • jp6rt