New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

scru128

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scru128 - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

35

dist/index.js

@@ -38,3 +38,6 @@ "use strict";

};
/** Represents a SCRU128 ID generator. */
/**
* Represents a SCRU128 ID generator and provides an interface to do more than
* just generate a string representation.
*/
class Generator {

@@ -80,13 +83,10 @@ constructor() {

}
return new Identifier(this.tsLastGen - TIMESTAMP_EPOCH, this.counter, this.perSecRandom, this.getRandomBits(32));
return Scru128Id.fromFields(this.tsLastGen - TIMESTAMP_EPOCH, this.counter, this.perSecRandom, this.getRandomBits(32));
}
}
/** Represents a SCRU128 ID. */
class Identifier {
/**
* @param timestamp - 44-bit millisecond timestamp field.
* @param counter - 28-bit per-millisecond counter field.
* @param perSecRandom - 24-bit per-second randomness field.
* @param perGenRandom - 32-bit per-generation randomness field.
*/
/**
* Represents a SCRU128 ID and provides converters to/from string and numbers.
*/
class Scru128Id {
/** Creates an object from field values. */
constructor(timestamp, counter, perSecRandom, perGenRandom) {

@@ -112,2 +112,13 @@ this.timestamp = timestamp;

}
/**
* Creates an object from field values.
*
* @param timestamp - 44-bit millisecond timestamp field.
* @param counter - 28-bit per-millisecond counter field.
* @param perSecRandom - 24-bit per-second randomness field.
* @param perGenRandom - 32-bit per-generation randomness field.
*/
static fromFields(timestamp, counter, perSecRandom, perGenRandom) {
return new Scru128Id(timestamp, counter, perSecRandom, perGenRandom);
}
/** Returns the 26-digit canonical string representation. */

@@ -131,3 +142,3 @@ toString() {

const l40 = parseInt(m[3], 32);
return new Identifier(Math.trunc(h48 / 0x10), (h48 % 0x10 << 24) | Math.trunc(m40 / 65536), (m40 % 65536 << 8) | Math.trunc(l40 / 4294967296), l40 % 4294967296);
return new Scru128Id(Math.trunc(h48 / 0x10), (h48 % 0x10 << 24) | Math.trunc(m40 / 65536), (m40 % 65536 << 8) | Math.trunc(l40 / 4294967296), l40 % 4294967296);
}

@@ -148,2 +159,2 @@ }

*/
exports._internal = { Identifier, detectRng };
exports._internal = { Scru128Id, detectRng };
{
"name": "scru128",
"version": "0.2.2",
"version": "0.2.3",
"description": "SCRU128: Sortable, Clock and Random number-based Unique identifier",

@@ -45,8 +45,8 @@ "main": "./dist/index.js",

"devDependencies": {
"mocha": "^9.1.2",
"typedoc": "^0.22.4",
"typescript": "^4.4.3",
"webpack": "^5.55.1",
"webpack-cli": "^4.8.0"
"mocha": "^9.1.3",
"typedoc": "^0.22.5",
"typescript": "^4.4.4",
"webpack": "^5.58.2",
"webpack-cli": "^4.9.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc