Home

Awesome

nodeON-helpers

A Collection of helper methods.

Build Status

Install

Install the module using NPM:

npm install nodeon-helpers --save

<a name='TOC'>Table of Contents</a>

  1. API
    1. Generate a random string
    2. Generate a random number
    3. Get a url safe string
    4. Truncate arguments from a function
    5. Skip arguments from a function
    6. Will copy an array over an existing one
    7. Get the current user HOME dir
    8. Determine if a value is numeric
    9. Determine if Express Request Accepts JSON
    10. Zero Padding on a number 2 --> '002'

API

<a name='generateRandomString'>Generate a random string</a>

helpers.generateRandomString(optLength)

Returns string The random string.

Returns a randomized string.

[⬆]

<a name='generateRandomNumber'>Generate a random number</a>

helpers.generateRandomNumber(optLength)

Returns string The random string of numbers.

Returns a randomized string only with numbers.

[⬆]

<a name='urlify'>Get a url safe string</a>

helpers.urlify(text, optRandLen)

Get a url safe string.

var helpers = require('nodeon-helpers');

var urlString = helpers.urlify('a name with spaces');

console.log(urlString);
// prints: "458202-a-name-with-spaces"

[⬆]

<a name='truncateArgs'>Truncate arguments from a function</a>

helpers.truncateArgs(fn, count, optSelf)

Return Function The function to invoke.

Will truncate arguments from a function.

var helpers = require('nodeon-helpers');

function run(one, two, three) {
    console.log(one); // prints 1
    console.log(two); // prints "undefined"
    console.log(three); // prints "undefined"
}

var fn = helpers.truncateArgs(run, 1);

fn(1, 2, 3);

[⬆]

<a name='skipArgs'>Skip arguments from a function</a>

helpers.skipArgs(fn, count, optSelf)

Return Function The function to invoke.

Will skip the first n arguments from a function.

var helpers = require('nodeon-helpers');

function run(one) {
    console.log(one); // prints 3
}

var fn = helpers.skipArgs(run, 2);

fn(1, 2, 3);

[⬆]

<a name='pushCopy'>Will copy an array over an existing one</a>

helpers.pushCopy(src, dst)

Will copy an array over an existing one.

var helpers = require('nodeon-helpers');

var src = [4,5,6];
var dst = [1,2,3];

helpers.pushCopy(src, dst);

console.log(dst);
// prints: [1, 2, 3, 4, 5, 6]

[⬆]

<a name='getUserHome'>Get the current user HOME dir.</a>

helpers.getUserHome()

Return string The full path to the user's HOME.

Get the user's HOME directory.

[⬆]

<a name='isNumeric'>Determine if a value is numeric.</a>

helpers.isNumeric(value)

Return boolean If the value is numeric.

[⬆]

<a name='isRequestJson'>Determine if Express Request Accepts JSON</a>

helpers.isRequestJson(req)

Return boolean If client accepts JSON.

[⬆]

<a name='zeroPadding'>Zero Padding on a number</a>

helpers.zeroPadding(number, width)

Return string The zero padded number.

var padded = helpers.zeroPadding(2, 3);
// '002'

[⬆]

Release History

License

Copyright Thanasis Polychronakis. Licensed under the MIT license.