Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

incremental-id-generator

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

incremental-id-generator

Generates incremental string IDs

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

incremental-id-generator

NPM Version Build Status Coverage Status devDependency Status

Generates incremental string IDs.

Installation

npm install incremental-id-generator --save-dev

Usage

const idGenerator = require('incremental-id-generator');
const nextID = idGenerator('ab');

nextID(); // -> a
nextID(); // -> b
nextID(); // -> aa
nextID(); // -> ab
nextID(); // -> ba
nextID(); // -> bb
nextID(); // -> aaa
nextID(); // -> aab

API

idGenerator(characters, [options]) ⇒ function

Returns a function that will return a new, incrementing ID each time it is called.

ParamTypeDescription
charactersstringThe characters that will be used to encode the ID.
Must not contain duplicate characters.
[options.prefix]stringA prefix to prepend to every generated ID.

Example

const idGenerator = require('incremental-id-generator');

const nextBinID = idGenerator('01');
nextBinID(); // -> 0
nextBinID(); // -> 1
nextBinID(); // -> 00
nextBinID(); // -> 01

const nextPrefixedID = idGenerator('abc', {prefix: '_'});
nextPrefixedID(); // -> _a
nextPrefixedID(); // -> _b
nextPrefixedID(); // -> _c
nextPrefixedID(); // -> _aa
nextPrefixedID(); // -> _ab
nextPrefixedID(); // -> _ac
nextPrefixedID(); // -> _ba

Keywords

incremental

FAQs

Package last updated on 02 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts