@oh-my-pi/pi-utils 11.0.0 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/snowflake.ts +4 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oh-my-pi/pi-utils",
3
- "version": "11.0.0",
3
+ "version": "11.0.1",
4
4
  "description": "Shared utilities for pi packages",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/snowflake.ts CHANGED
@@ -39,12 +39,10 @@ namespace Snowflake {
39
39
  // Formats a sequence and timestamp into a snowflake hex string.
40
40
  //
41
41
  export function formatParts(dt: number, seq: number): Snowflake {
42
- // Split 64-bit value into two 32-bit parts for number arithmetic
43
- // high32 = delta >> 10 (timestamp bits 41-10)
44
- // low32 = (delta & 0x3ff) << 22 | seq
45
- const hi = dt >>> 10;
46
- const lo = (dt << 22) | seq;
47
-
42
+ // Keep everything in Number space; dt is < 2^53 for current epochs.
43
+ const value = dt * 0x400000 + seq; // dt << 22
44
+ const hi = Math.floor(value / 0x100000000);
45
+ const lo = (value - hi * 0x100000000) >>> 0;
48
46
  const hi1 = (hi >>> 16) & 0xffff;
49
47
  const hi2 = hi & 0xffff;
50
48
  const lo1 = (lo >>> 16) & 0xffff;