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 🙏

© 2026 – Pkg Stats / Ryan Hefner

id-gen

v0.3.2

Published

Generator ids in sequence using defaults or a custom id generator function.

Downloads

25

Readme

id-gen NPM version

Generator ids in sequence using defaults or a custom id generator function.

$ npm i id-gen --save

Usage

Create a new generator and use the defaults:

// require in the IdGenerator
var IdGenerator = require('id-gen');

// create a new instance of a generator
var generator = new IdGenerator();

// start using the generator to create
// default ids in sequence, e.g. 001, 002, 003, 004
var id = generator.next();

Create a generator with named groups

// require in the IdGenerator
var IdGenerator = require('id-gen');

// create a new instance of a generator
var generator = new IdGenerator(options);

// create some named groups
// use 2 digits instead of 3
generator.create('default', { digits: 2 });

// use 5 digits instead of 3 and add a prefix e.g. page-00001
generator.create('page', { digits: 5, prefix: 'page-' });

// start using the generator to create
// default ids in sequence, e.g. 01, 02, 03, 04
var id = generator.next();

// specify the named group to use the group options
// page ids in sequence, e.g. page-00001, page-00002, page-00003
var pageId = generator.next('pages');

Create an id generator using a custom generator function.

// require in the IdGenerator
var IdGenerator = require('id-gen');

// create custom generator that takes a group name and options
function generator (groupName, options) {
  // just use an id value on the options if specified
  options = options || {};
  return options.id;
}

// create a new instance of a generator
var generator = new IdGenerator(generator);

// start using the generator to create
// default ids in sequence, e.g. 01, 02, 03, 04
var id = generator.next();

// specify the options with an id to return the actual id
// e.g. {id: 'foo'} => 'foo'
var id = generator.next({id: 'foo'});

API

IdGenerator

Create a new IdGenerator passing in an optional generator function that does the actual work.

Params

  • generator {Function}: Optional generator function used to generate new IDs

.create

Create a new group to segment IDs

Params

  • groupName {String}: Name of the group to create.
  • options {Object}: Additional options to define how the IDs are generated.
  • returns {Object} this: to enable chaining

.next

Get the next ID by groupName

Params

  • groupName {String}: Optional name of group to generate the ID for.
  • options {String}: Additional options to pass to the generator
  • cb {Function}: Optional callback function to get the next id async
  • returns {String}: Generated ID

Author

License

Copyright © 2015 Brian Woodward Released under the MIT license.


This file was generated by verb-cli on May 28, 2015.