1.0.4 • Published 7 years ago

@jp6rt/utils v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
7 years ago

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