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

sequential-id-generator

v2.1.2

Published

String / code / id sequential generator

Downloads

4

Readme

sequential-id-generator

npm CI Pipeline Build Status Coverage Status Scrutinizer Code Quality Code Climate Known Vulnerabilities

String / code / id sequential generator.

Generator function that produces a sequence of IDs.

Most sequential ID generators need you to start from the first ID, but this one alows you to easily pass the current ID (that you might have retrieved from a DB) and generate the next ones with an instant performance.

The sequence is based on a list of characters (sequence parameter) and has the lenght based on an initial ID (initialOrLength parameter when a string is passed) or on a length o characters (initialOrLength parameter when a number is passed).

A generator function can be iterated with a 'for of', that will return the next ID for each iteration or can be called using "next()", that will return an object like { value: <the ID>, done: <boolean that is true when the sequence is finished> }.

Installation

$ npm i sequential-id-generator

Parameters

The function has two parameters: initialOrLength and sequence.

initialOrLength (default = 5)

The initial ID string if you want to start the generation from a certain point or the length of the ID to start from the first ID.

Example:

initialOrLength = '00' will produce a sequence from '01' on. The passed current ID is skipped.

initialOrLength = 2 will start from '00', as the sequence will start from the beginning of the sequence with the specified length.

sequence (default = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')

The string with the sequence of characters to produce the IDs. The order of the characters mather to the result.

Usage examples

import generator from './index'

let ids = idGenerator('28')
ids.next() // { value: '29', done: false }
ids.next() // { value: '2A', done: false }
ids.next() // { value: '2B', done: false }

ids = idGenerator('ZZ')
ids.next() // { value: undefined, done: true }

ids = idGenerator(2, '01')
ids.next() // { value: '00', done: false }
ids.next() // { value: '01', done: false }
ids.next() // { value: '10', done: false }
ids.next() // { value: '11', done: false }
ids.next() // { value: undefined, done: true }

ids = idGenerator('4', '0123456')
for (const str of ids) {
    console.log(str)
} // '5', '6'

ids = idGenerator(2, '012')
for (const str of ids) {
    console.log(str)
} // '00', '01', '02', '10', '11', '12', '20', '21', '22'

Version history

1.0.0

Working version but with performance issues for large IDs due to how the generator was constructed sequentially, going through every ID before the passed one.

2.0.0

Improved ID generator can now continue to the next ID without going through all previous IDs. The code is also muche easier to understand how the next ID is being generated.

2.1.1

Fixed package instalation for projects without TS.