
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
snowflake-generator
Advanced tools
A lightweight Twitter Snowflake generation package utilising TypeScript.
Install the npm package
npm install snowflake-generator
Require the package into your code
const { Generator } = require('snowflake-generator');
Construct a new Snowflake Generator with the EPOCH timestamp in milliseconds
const SnowflakeGenerator = new Generator(1420070400000);
// Thursday, 1 January 2015 00:00:00
Generate a Snowflake
const Snowflake = SnowflakeGenerator.generate();
(class)new Generator(epoch?: Date|number, shardID?: number);
| param | type | optional | default | description |
|---|---|---|---|---|
| epoch | Date|number | true | 946684800000 | The epoch timestamp to generate from. |
| shardID | number | true | 1 | Useful when running multiple generators at the same time to prevent duplicates. |
The generators epoch timestamp in milliseconds.
@typenumber
The id of the shard running this generator.
@typenumber
The current increment iteration this generator is on.
@typenumber
Generates snowflakes.
Generator.generate(amount?: number, timestamp?: Date|number);
| parameter | type | optional | default | description |
|---|---|---|---|---|
| amount | number | true | 1 | Amount of snowflakes to generate, recommended not to go above 1024 or duplicates will arise. |
| timestamp | Date|number | true | Date.now | Timestamp to generate from |
@returns bigint|bigint[]
Deconstruct a snowflake to its values using the Generator.epoch.
Generator.deconstruct(snowflake: SnowflakeResolvable);
| parameters | type | description |
|---|---|---|
| snowflake | SnowflakeResolvable | Snowflake(s) to deconstruct |
@returns DeconstructedSnowflake
Resolvable value types for a valid Snowflake.
- string
- number
- bigint
Interface of a Snowflake after
Generator.deconstruct().
- snowflake - Snowflake deconstructed from
@typebigint- timestamp - The timestamp the snowflake was generated
@typebigint- shard_id - The shard_id used when generating
@typebigint- increment - The increment of this snowflake
@typebigint- binary - The 64Bit snowflake binary string
@typestring
let snowflakes = [];
let ts = Date.now();
let amount = 20000;
for (let i = 0; i < (amount / 1024); i++) {
// this could be improved, but is proof of concept.
let new_amount = i + 1 >= (amount / 1024) ? amount % 1024 : 1024;
snowflakes = snowflakes.concat(generator.generate(new_amount, ts + i));
}
Note: When parsing this array through a duplication checking function it returns
0found duplicates.
> console.log(generator) after running script.
> Note: increment == amount.
Generator { epoch: 1420070400000, shard_id: 1, increment: 20000 }
FAQs
A 64-bit Snowflake generator written in JavaScript
The npm package snowflake-generator receives a total of 208 weekly downloads. As such, snowflake-generator popularity was classified as not popular.
We found that snowflake-generator 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.