mirror of
https://github.com/Wessel/Snowflakey.git
synced 2026-07-12 10:47:26 +02:00
Complete refractor
This commit is contained in:
18
test.js
Normal file
18
test.js
Normal file
@@ -0,0 +1,18 @@
|
||||
// require & generate the instance
|
||||
const Snowflake = require( './generator' );
|
||||
const snowflake = new Snowflake.generator({
|
||||
processBits: 0,
|
||||
workerBits: 8,
|
||||
incrementBits: 14,
|
||||
workerId: process.env.CLUSTER_ID || 31
|
||||
});
|
||||
|
||||
// exports for global use
|
||||
exports.makeSnowflake = ( date ) => { return snowflake._generate( date ); };
|
||||
exports.unmakeSnowflake = ( flake ) => { let decon = snowflake.deconstruct( flake ); return decon.timestamp.valueOf(); };
|
||||
|
||||
// example
|
||||
const flake = this.makeSnowflake( Date.now() );
|
||||
console.log( flake );
|
||||
console.log( `Creation date: ${Snowflake.lookup( flake, 1420070400000 )}` );
|
||||
console.log( this.unmakeSnowflake( flake ) );
|
||||
Reference in New Issue
Block a user