
Product
Introducing Pull Request Stories to Help Security Teams Track Supply Chain Risks
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
snowflaketmpscoped
Advanced tools
Twitter's Snowflake generator implementation for NodeJS
Twitter's Snowflake generator for NodeJS.
Snowflake-UUID can generate unique Id numbers at high scale with some simple guarantees.
npm install snowflake-uuid
// or
yarn add snowflake-uuid
// or
pnpm add snowflake-uuid
import { Worker } from 'snowflake-uuid';
// const { Worker } = require('snowflake-uuid');
const generator = new Worker(0, 1, {
workerIdBits: 5,
datacenterIdBits: 5,
sequenceBits: 12,
});
generator.nextId(); // 87559690812260352n
generator.nextId().toString(); // '87559690833231872'
generator.currentSequence; // 0n
generator.datacenterId; // 1n
generator.lastTimestamp; // 1630335057075n
generator.workerId; // 0n
Generated IDs are BigInt and can be easily converted into strings.
Property | Description | Optional? | Type | Default Value |
---|---|---|---|---|
workerId | Id for the worker | Yes | Number or BigInt | 0 |
datacenterId | Identifier of the datacenter to which the worker belongs | Yes | Number or BigInt | 0 |
options | Custom options for the worker | Yes | Object | undefined |
options.epoch | Custom epoch for timestamp generation. By default, the number of milliseconds since the first second of 2021 | Yes | Number or BigInt | 1609459200000 |
options.workerIdBits | Number of usable bits for Worker Id. 5 by default, allows up to 31 Workers | Yes | Number or BigInt | 5 |
options.datacenterIdBits | Number of usable bits for Datacenter Id. 5 by default, allows up to 31 Datacenters | Yes | Number or BigInt | 5 |
options.sequence | For every Id that is generated on that process, this number is incremented | Yes | Number or BigInt | 0 |
options.sequenceBits | Number of usable bits for Sequence Id. 12 by default, allows up to 4095 generations per millisecond per Worker per Datacenter | Yes | Number or BigInt | 12 |
Refer to the LICENSE file.
FAQs
Twitter's Snowflake generator implementation for NodeJS
We found that snowflaketmpscoped demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.