@thi.ng/ksuid
Advanced tools
Comparing version 3.1.14 to 3.1.15
@@ -29,5 +29,5 @@ import type { BaseN } from "@thi.ng/base-n"; | ||
protected ensureSize(buf: Uint8Array): Uint8Array; | ||
protected ensureTime(t: number): number; | ||
protected ensureTime(t: number, max?: number): number; | ||
protected u32(buf: Uint8Array, i?: number): number; | ||
} | ||
//# sourceMappingURL=aksuid.d.ts.map |
@@ -48,4 +48,5 @@ import { BASE62 } from "@thi.ng/base-n/62"; | ||
} | ||
ensureTime(t) { | ||
ensureTime(t, max) { | ||
assert(t >= 0, "configured base epoch must be in the past"); | ||
max && assert(t <= max, `given epoch is out of range ([0...${max}])`); | ||
return t; | ||
@@ -52,0 +53,0 @@ } |
# Change Log | ||
- **Last updated**: 2023-08-04T10:58:19Z | ||
- **Last updated**: 2023-08-06T09:21:31Z | ||
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub) | ||
@@ -12,2 +12,11 @@ | ||
### [3.1.15](https://github.com/thi-ng/umbrella/tree/@thi.ng/ksuid@3.1.15) (2023-08-06) | ||
#### 🩹 Bug fixes | ||
- fix [#403](https://github.com/thi-ng/umbrella/issues/403), update KSUID32 epoch handling ([abbfc5a](https://github.com/thi-ng/umbrella/commit/abbfc5a)) | ||
- update .ensureTime() to check against optional max value | ||
- fix int coercion in KSUID32.timeOnlyBinary() | ||
- update readme | ||
## [3.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/ksuid@3.1.0) (2023-02-10) | ||
@@ -14,0 +23,0 @@ |
import { AKSUID } from "./aksuid.js"; | ||
const MAX_EPOCH = -1 >>> 0; | ||
export class KSUID32 extends AKSUID { | ||
@@ -12,3 +13,3 @@ constructor(opts) { | ||
const buf = new Uint8Array(this.size); | ||
const t = this.ensureTime(((epoch - this.epoch) / 1000) | 0); | ||
const t = this.ensureTime((epoch - this.epoch) / 1000, MAX_EPOCH) >>> 0; | ||
buf.set([t >>> 24, (t >> 16) & 0xff, (t >> 8) & 0xff, t & 0xff]); | ||
@@ -15,0 +16,0 @@ return buf; |
{ | ||
"name": "@thi.ng/ksuid", | ||
"version": "3.1.14", | ||
"version": "3.1.15", | ||
"description": "Configurable K-sortable unique IDs, ULIDs, binary & base-N encoded, 32/48/64bit time resolutions", | ||
@@ -39,3 +39,3 @@ "type": "module", | ||
"dependencies": { | ||
"@thi.ng/base-n": "^2.5.6", | ||
"@thi.ng/base-n": "^2.5.7", | ||
"@thi.ng/errors": "^2.3.0", | ||
@@ -118,3 +118,3 @@ "@thi.ng/random": "^3.5.1", | ||
}, | ||
"gitHead": "9fa3f7f8169efa30e3c71b43c82f77393581c3b5\n" | ||
"gitHead": "888293c74f2e9a481d500d4ec319f1e2bd765ec6\n" | ||
} |
@@ -32,12 +32,12 @@ <!-- This file is generated - DO NOT EDIT! --> | ||
| Feature | KSUID default | ULID default | | ||
|---------------------------------------|------------------------|------------------------| | ||
| Configurable bit size | 160 bits | 128 bits | | ||
| Base-N encoding scheme | base62<sup>(1)</sup> | base32 (Crockford) | | ||
| Timestamp resolution | seconds (32 bits) | milliseconds (48 bits) | | ||
| | milliseconds (64 bits) | | | ||
| Epoch start time offset | approx. 2020-09-13 | none | | ||
| Time-only base ID generation | ✅ | ✅ | | ||
| ID parsing / decomposition | ✅ | ✅ | | ||
| Configurable RNG source<sup>(2)</sup> | ✅ | ✅ | | ||
| Feature | KSUID default | ULID default | | ||
|---------------------------------------|----------------------------------|------------------------| | ||
| Configurable bit size | 160 bits | 128 bits | | ||
| Base-N encoding scheme | base62<sup>(1)</sup> | base32 (Crockford) | | ||
| Timestamp resolution | seconds (32 bits) | milliseconds (48 bits) | | ||
| | milliseconds (64 bits) | | | ||
| Epoch start time offset | approx. 2020-09-13<sup>(2)</sup> | none | | ||
| Time-only base ID generation | ✅ | ✅ | | ||
| ID parsing / decomposition | ✅ | ✅ | | ||
| Configurable RNG source<sup>(3)</sup> | ✅ | ✅ | | ||
@@ -47,3 +47,4 @@ - <sup>(1)</sup> See | ||
for alternatives | ||
- <sup>(2)</sup> Default: `window.crypto`, `Math.random` as fallback | ||
- <sup>(2)</sup> With the default offset, the max. supported date for `KSUID32` is 2156-10-20T18:54:55Z | ||
- <sup>(3)</sup> Default: `window.crypto`, `Math.random` as fallback | ||
@@ -115,3 +116,3 @@ IDs generated w/ this package are composed of a 32, 48 or 64 bit Unix epochs and | ||
Package sizes (brotli'd, pre-treeshake): ESM: 769 bytes | ||
Package sizes (brotli'd, pre-treeshake): ESM: 809 bytes | ||
@@ -118,0 +119,0 @@ ## Dependencies |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39710
385
224
149
5
8
53
+ Added@thi.ng/api@8.11.12(transitive)
+ Added@thi.ng/base-n@2.7.24(transitive)
+ Added@thi.ng/checks@3.6.14(transitive)
+ Added@thi.ng/errors@2.5.18(transitive)
+ Added@thi.ng/hex@2.3.56(transitive)
+ Added@thi.ng/memoize@4.0.2(transitive)
+ Added@thi.ng/strings@3.8.10(transitive)
- Removed@thi.ng/api@8.11.11(transitive)
- Removed@thi.ng/base-n@2.7.23(transitive)
- Removed@thi.ng/checks@3.6.13(transitive)
- Removed@thi.ng/errors@2.5.17(transitive)
- Removed@thi.ng/hex@2.3.55(transitive)
- Removed@thi.ng/memoize@4.0.1(transitive)
- Removed@thi.ng/strings@3.8.9(transitive)
Updated@thi.ng/base-n@^2.5.7