JSPM

incremental-id-generator

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 38
  • Score
    100M100P100Q52823F
  • License MIT

Generates incremental string IDs

Package Exports

  • incremental-id-generator

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (incremental-id-generator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.

Param Type Description
characters string The characters that will be used to encode the ID.
Must not contain duplicate characters.
[options.prefix] string A 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