Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
sequential-ids
Advanced tools
A Node.js module that allows centralized generation of sequential and human-readable ids.
Sample Id: ACB - 00423
aspect | detail |
---|---|
version | 0.0.0-alpha.4.1 |
dependencies | none |
last updated | 4th Oct, 2014 |
From Npm:
$ npm install sequential-ids --save
// assuming `db` is a variable holding a database connection with the
// method `.store(key, value)`
var sequential = require("sequential-ids");
var generator = new sequential.Generator({
digits: 6, letters: 3,
store: function(ids) {
db.store("last-id", ids[ids.length - 1]);
},
restore: "AAB - 000"
});
generator.start();
var new_id = generator.generate(); // => AAB - 001
// possibly in another file
var accessor = new sequential.Accessor();
accessor.next(function(err, id) {
console.log("new id: %s", id); // => AAB - 002
});
you only require to create a single generator instance
options is an object having the following attributes:
digits
:
0
(zero) lets you ignore the number part6
.letters
:
0
(zero) lets you ignore the letters part3
.store
:
null
.store_freq
:
1
(called every 1 ID is generated)restore
:
digits
and letters
will be ignored so as to follow the restore ID style.null
.port
:
9876
.in a case where you may require more than one generator, you would allocate them to different ports. See ahead on how to target each of the different generators.
var sequential = require("sequential-ids");
var generatorA = new sequential.Generator({port: 8998});
var generatorB = new sequential.Generator({port: 7667});
A generator has the following methods:
Generator#start()
Generator#generate()
Generator#stop()
used to access ids.
port is the port number of your generator. In case where, you did not specify a port when creating a Generator instance, you may leave this out. Defaults to 9876
.
an accessor may be initialized in a separate file. Ensure you got the port numbers correct.
an accessor has the following methods:
Accessor#next(callback)
:
function(err, id)
Accessor#ping(callback)
function(err)
All methods are asynchronous, the Node.js way
session(callback)
- passes the number of IDs generated in the session..used(callback)
- passes the total number of IDs generated..semantics(callback)
- passes the remaining no. of ids to be generated before breaking our semantics specified while creating the generator./tests
directoryCopyright (c) 2014 Forfuture LLC
Sequential Ids and its source code are licensed under the MIT license. See LICENSE file accompanying this text.
FAQs
centralized generation of sequential, human-readable ids
The npm package sequential-ids receives a total of 24 weekly downloads. As such, sequential-ids popularity was classified as not popular.
We found that sequential-ids demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.