Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/ksuid

Package Overview
Dependencies
Maintainers
1
Versions
148
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/ksuid - npm Package Compare versions

Comparing version 2.1.31 to 3.0.0

2

aksuid.d.ts

@@ -21,2 +21,4 @@ import type { BaseN } from "@thi.ng/base-n";

abstract timeOnlyBinary(epoch?: number): Uint8Array;
fromEpoch(epoch?: number): string;
fromEpochBinary(epoch?: number): Uint8Array;
format(buf: Uint8Array): string;

@@ -23,0 +25,0 @@ abstract parse(id: string): {

@@ -31,2 +31,11 @@ import { BASE62 } from "@thi.ng/base-n/62";

}
fromEpoch(epoch) {
return this.format(this.fromEpochBinary(epoch));
}
fromEpochBinary(epoch) {
const buf = this.timeOnlyBinary(epoch);
return this.rnd
? randomBytesFrom(this.rnd, buf, this.epochSize)
: randomBytes(buf, this.epochSize);
}
format(buf) {

@@ -33,0 +42,0 @@ this.ensureSize(buf);

24

api.d.ts

@@ -36,2 +36,16 @@ import type { BaseN } from "@thi.ng/base-n";

/**
* Returns a new formatted ID, composed from user supplied timestamp
* (default: current time) and a random payload.
*
* @param epoch
*/
fromEpoch(epoch?: number): string;
/**
* Returns a new ID as byte array, composed from user supplied timestamp
* (default: current time) and a random payload.
*
* @param epoch
*/
fromEpochBinary(epoch?: number): Uint8Array;
/**
* Returns baseN encoded version of given binary ID (generated via

@@ -80,11 +94,11 @@ * `.nextBinary()`).

/**
* Time offset in seconds, relative to standard Unix epoch. This is used to
* extend the time headroom of IDs into the future.
* Time offset in milliseconds, relative to standard Unix epoch. This is
* used to extend the time headroom of IDs into the future.
*
* @remarks
* The default value (for both 32 & 64bit impls) is approx. 2020-09-13,
* meaning this is the T0 epoch for all IDs (providing an additional ~50
* year lifespan compared to the standard 1970-01-01 epoch)
* meaning this is the `t0` base epoch for all generated IDs (providing an
* additional ~50 year lifespan compared to the standard 1970-01-01 epoch)
*
* @defaultValue 1_600_000_000 or 1_600_000_000_000
* @defaultValue 1_600_000_000_000
*/

@@ -91,0 +105,0 @@ epoch: number;

# Change Log
- **Last updated**: 2023-01-10T15:20:19Z
- **Last updated**: 2023-01-17T10:57:27Z
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)

@@ -12,2 +12,25 @@

# [3.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/ksuid@3.0.0) (2023-01-17)
#### 🛑 Breaking changes
- update readme w/ v3.0.0 info ([f8d83c8](https://github.com/thi-ng/umbrella/commit/f8d83c8))
- BREAKING CHANGE: `epoch` config unified to use milliseconds
- add new section to readme
- see [3d73b1766](https://github.com/thi-ng/umbrella/commit/3d73b1766) for code details
#### 🚀 Features
- fix [#372](https://github.com/thi-ng/umbrella/issues/372), add fromEpoch() methods ([e416e91](https://github.com/thi-ng/umbrella/commit/e416e91))
- add fromEpoch/fromEpochBinary() to IKSUID interface
- add impls in AKSUID
- add tests for all 3 classes
#### ♻️ Refactoring
- use milliseconds as unified epoch offsets ([3d73b17](https://github.com/thi-ng/umbrella/commit/3d73b17))
- clarify KSUIDOpts.epoch docs
- refactor KSUID32 to use milliseconds as `epoch` offset
- update tests
## [2.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/ksuid@2.1.0) (2021-11-17)

@@ -14,0 +37,0 @@

@@ -5,3 +5,3 @@ import { AKSUID } from "./aksuid.js";

super(4, {
epoch: 1600000000,
epoch: 1600000000000,
bytes: 16,

@@ -13,3 +13,3 @@ ...opts,

const buf = new Uint8Array(this.size);
const t = this.ensureTime((epoch / 1000 - this.epoch) | 0);
const t = this.ensureTime(((epoch - this.epoch) / 1000) | 0);
buf.set([t >>> 24, (t >> 16) & 0xff, (t >> 8) & 0xff, t & 0xff]);

@@ -22,3 +22,3 @@ return buf;

return {
epoch: (this.u32(buf) + this.epoch) * 1000,
epoch: this.u32(buf) * 1000 + this.epoch,
id: buf.slice(4),

@@ -25,0 +25,0 @@ };

{
"name": "@thi.ng/ksuid",
"version": "2.1.31",
"version": "3.0.0",
"description": "Configurable K-sortable unique IDs, ULIDs, binary & base-N encoded, 32/48/64bit time resolutions",

@@ -112,3 +112,3 @@ "type": "module",

},
"gitHead": "3f0b3e2a7c82aefc7e46fb4338369836b5e1b8cf\n"
"gitHead": "02425e5d92d381af664430d56609ee82948b4f59\n"
}

@@ -14,2 +14,3 @@ <!-- This file is generated - DO NOT EDIT! -->

- [Status](#status)
- [Breaking changes](#breaking-changes)
- [Related packages](#related-packages)

@@ -62,2 +63,12 @@ - [Installation](#installation)

### Breaking changes
Since v3.0.0 all
[`epoch`](https://docs.thi.ng/umbrella/ksuid/interfaces/KSUIDOpts.html#epoch)
time-shift config values are to be given in milliseconds. This change is
unifying this behavior and is only a breaking change if using `KSUID32` and
specifying custom `epoch` offsets (using defaults is **not** impacted).
Previously, `KSUID32` used an offset given in seconds, whereas the other
implementations already used milliseconds.
## Related packages

@@ -89,3 +100,3 @@

Package sizes (brotli'd, pre-treeshake): ESM: 754 bytes
Package sizes (brotli'd, pre-treeshake): ESM: 769 bytes

@@ -149,2 +160,4 @@ ## Dependencies

const id36 = defKSUID32({ base: BASE36, epoch: 0, bytes: 8 });
id32.next();
// '2VOUKH4K59AG0RXR4XH'

@@ -151,0 +164,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