
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
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 |
dependencies | none |
node | 0.11, 0.10 |
last updated | 11th December, 2014 |
From Npm:
$ npm install sequential-ids --save
// assuming `db` is a variable holding a database connection with the
// method `.store(key, value)`
// a '__default' key is created by default
var sequential = require("sequential-ids");
var generator = new sequential.Generator({
digits: 6, letters: 3,
store: function(key, ids) {
db.store(key, ids[ids.length - 1]);
},
restore: "AAB - 000"
});
generator.add('otherKey', {
digits : 3, letters: 1,
store: function(key, ids) {
db.store(key, ids[ids.length - 1]);
},
restore: "A - 00"
});
generator.start();
var new_id_1 = generator.generate(); // => AAB - 001
var new_id_2 = generator.generate(); // => AAB - 002
// ...
var other_id_1 = generator.generate('otherKey'); // => A - 01
var other_id_2 = generator.generate('otherKey'); // => A - 02
// ...
// possibly in another file
var accessor = new sequential.Accessor();
accessor.next(function(err, id) {
console.log("new id: %s", id); // => AAB - 003
});
accessor.next('otherKey',function(err, id) {
console.log("new id (otherKey): %s", id); // => A - 03
});
you only require to create a single generator instance
options is an object having the following attributes:
port
:
9876
.and, additionally, the same attributes as the Generator#add options object
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#add(key, [options])
adds a new key to the generator. If no Error is thrown, the generator will be ready for Accessors.
returns false
if key
had already been added to the
generator; otherwise, returns true
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..digits
and .letters
options.null
.autoAddKeys
:
true
, such a key is added and an ID returned as though
the key was already added using the Generator's options.false
, an Error is passed to callback, if any, or null
is
returned.false
.Generator#generate(key)
generates a new ID for key. If no key is given, uses the default one. The new ID is returned immediately.
if the key does not exist and the option autoAddKeys
is not
set, returns null
. If autoAddKeys
is set, the key is
added on-the-fly with the default options, and returns the new
ID.
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(key,callback)
:
function(err, id)
autoAddKeys
set, an error is passed to the callback, and no
ID is generated.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
directoryA list of contributors:
Copyright (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
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.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.