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

nodeon-helpers

v1.0.0

Published

A collection of helper funcs

Downloads

30

Readme

nodeON-helpers

A Collection of helper methods.

Build Status

Install

Install the module using NPM:

npm install nodeon-helpers --save

Table of Contents

  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

Generate a random string

helpers.generateRandomString(optLength)

  • optLength number= Define length, default 32.

Returns string The random string.

Returns a randomized string.

[⬆]

Generate a random number

helpers.generateRandomNumber(optLength)

  • optLength number= Define length, default 20.

Returns string The random string of numbers.

Returns a randomized string only with numbers.

[⬆]

Get a url safe string

helpers.urlify(text, optRandLen)

  • text string The string to urlify.
  • optRandLen number How many numbers to use for randomizing the url, default 6.

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"

[⬆]

Truncate arguments from a function

helpers.truncateArgs(fn, count, optSelf)

  • fn Function The function to truncate arguments.
  • count number How many arguments to allow before truncating.
  • optSelf Object= Optionally apply context.

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);

[⬆]

Skip arguments from a function

helpers.skipArgs(fn, count, optSelf)

  • fn Function The function to skip arguments for.
  • count number How many arguments to skip.
  • optSelf Object= Optionally apply context.

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);

[⬆]

Will copy an array over an existing one

helpers.pushCopy(src, dst)

  • src Array The source array.
  • dst Array The destination array.

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]

[⬆]

Get the current user HOME dir.

helpers.getUserHome()

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

Get the user's HOME directory.

[⬆]

Determine if a value is numeric.

helpers.isNumeric(value)

  • value string|number The value to check.

Return boolean If the value is numeric.

[⬆]

Determine if Express Request Accepts JSON

helpers.isRequestJson(req)

  • req Object The Express request object.

Return boolean If client accepts JSON.

[⬆]

Zero Padding on a number

helpers.zeroPadding(number, width)

  • number number The number to apply zeropadding on.
  • number width The padding.

Return string The zero padded number.

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

[⬆]

Release History

  • v1.0.0, 04 May 2016
    • Remove bcrypt dependency by decoupling all crypto methods into the new package nodeON-crypto.
    • Removed methods:
      • salt
      • setSalt
      • hash
      • hashVerify
  • v0.1.9, 17 Aug 2015
    • Added option to ignore char limit for hash.
  • v0.1.8, 14 Aug 2015
    • Will now return error if string for hash is 72chars or longer, bcrypt will not handle it.
    • Upgraded all dependencies to latest.
  • v0.1.7, 14 May 2015
    • Made all npm dependencies specific, thank you @kbariotis.
  • v0.1.6, 03 Apr 2015
    • Added the zeroPadding method.
  • v0.1.5, 11 Dec 2014
    • Added the isRequestJson method.
  • v0.1.4, 24 Oct 2014
    • Added skipArgs() method.
  • v0.1.3, 19 Sep 2014
    • Added isNumeric() method.
  • v0.1.0, 14 Aug 2014
    • Big Bang

License

Copyright Thanasis Polychronakis. Licensed under the MIT license.