fantomid 1.0.7 → 1.0.8

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.
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import { random } from '@lukeed/csprng';
2
2
 
3
3
  const EPOCH = /* @__PURE__ */ new Date("2024-09-08");
4
+ const TIMESTAMP_LENGTH = 36;
5
+ const RANDOM_BITS_LENGTH = 17;
6
+ const TIMESTAMP_PRECISION_DIVIDER = 100;
4
7
  function fantomid() {
5
- const TIMESTAMP_LENGTH = 36;
6
- const RANDOM_BITS_LENGTH = 17;
7
- const TIMESTAMP_PRECISION_DIVIDER = 100;
8
8
  const bits = Array(TIMESTAMP_LENGTH + RANDOM_BITS_LENGTH);
9
9
  const timestamp = Math.round(
10
10
  // Use a more recent base date instead of the Unix Epoch to
11
11
  // increase the amount of time we can represent in the timestamp.
12
- (/* @__PURE__ */ new Date() - EPOCH) / // Decrease the precision of the timestamp to
12
+ (Date.now() - EPOCH) / // Decrease the precision of the timestamp to
13
13
  // increase the amount of bits we can fit in a key.
14
14
  TIMESTAMP_PRECISION_DIVIDER
15
15
  );
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/fantomid.js"],"sourcesContent":["import { random } from \"@lukeed/csprng\";\n\nconst EPOCH = new Date(\"2024-09-08\");\n\nexport function fantomid() {\n const TIMESTAMP_LENGTH = 36;\n const RANDOM_BITS_LENGTH = 17;\n const TIMESTAMP_PRECISION_DIVIDER = 100;\n\n const bits = Array(TIMESTAMP_LENGTH + RANDOM_BITS_LENGTH);\n\n // Generates a timestamp to be part of the key. This is\n // inspired by how UUID v7 works: the idea is that this\n // will guarantee keys are generated evenly across time.\n const timestamp = Math.round(\n // Use a more recent base date instead of the Unix Epoch to\n // increase the amount of time we can represent in the timestamp.\n (new Date() - EPOCH) /\n // Decrease the precision of the timestamp to\n // increase the amount of bits we can fit in a key.\n TIMESTAMP_PRECISION_DIVIDER,\n );\n for (let i = 0; i < TIMESTAMP_LENGTH; i++) {\n bits[TIMESTAMP_LENGTH + RANDOM_BITS_LENGTH - 1 - i] = (timestamp >> i) & 1;\n }\n\n // Generates a randomized part of the key. If multiple machines generate a\n // key at the exact same time (limited by the precision of the timestamp),\n // we are ensured to have a chance of collision of `1` in `2 ** RANDOM_BITS_LENGTH`.\n const randomBytes = random(Math.ceil(RANDOM_BITS_LENGTH / 8));\n for (let i = 0; i < RANDOM_BITS_LENGTH; i++) {\n bits[RANDOM_BITS_LENGTH - 1 - i] =\n (randomBytes[Math.floor(i / 8)] >> i % 8) & 1;\n }\n\n return Number(\"0b\" + bits.reduce((id, bit) => id + bit, String()));\n}\n"],"names":[],"mappings":";;AACA,MAAM,KAAK,mBAAmB,IAAI,IAAI,CAAC,YAAY,CAAC;AAC7C,SAAS,QAAQ,GAAG;AAC3B,EAAE,MAAM,gBAAgB,GAAG,EAAE;AAC7B,EAAE,MAAM,kBAAkB,GAAG,EAAE;AAC/B,EAAE,MAAM,2BAA2B,GAAG,GAAG;AACzC,EAAE,MAAM,IAAI,GAAG,KAAK,CAAC,gBAAgB,GAAG,kBAAkB,CAAC;AAC3D,EAAE,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK;AAC9B;AACA;AACA,IAAI,iBAAiB,IAAI,IAAI,EAAE,GAAG,KAAK;AACvC;AACA,IAAI;AACJ,GAAG;AACH,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,gBAAgB,EAAE,CAAC,EAAE,EAAE;AAC7C,IAAI,IAAI,CAAC,gBAAgB,GAAG,kBAAkB,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,IAAI,CAAC,GAAG,CAAC;AAC5E,EAAE;AACF,EAAE,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC,CAAC;AAC/D,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,kBAAkB,EAAE,CAAC,EAAE,EAAE;AAC/C,IAAI,IAAI,CAAC,kBAAkB,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAClF,EAAE;AACF,EAAE,OAAO,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,KAAK,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;AACpE;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/fantomid.js"],"sourcesContent":["import { random } from \"@lukeed/csprng\";\n\nconst EPOCH = new Date(\"2024-09-08\");\nconst TIMESTAMP_LENGTH = 36;\nconst RANDOM_BITS_LENGTH = 17;\nconst TIMESTAMP_PRECISION_DIVIDER = 100;\n\nexport function fantomid() {\n const bits = Array(TIMESTAMP_LENGTH + RANDOM_BITS_LENGTH);\n\n // Generates a timestamp to be part of the key. This is\n // inspired by how UUID v7 works: the idea is that this\n // will guarantee keys are generated evenly across time.\n const timestamp = Math.round(\n // Use a more recent base date instead of the Unix Epoch to\n // increase the amount of time we can represent in the timestamp.\n (Date.now() - EPOCH) /\n // Decrease the precision of the timestamp to\n // increase the amount of bits we can fit in a key.\n TIMESTAMP_PRECISION_DIVIDER,\n );\n for (let i = 0; i < TIMESTAMP_LENGTH; i++) {\n bits[TIMESTAMP_LENGTH + RANDOM_BITS_LENGTH - 1 - i] = (timestamp >> i) & 1;\n }\n\n // Generates a randomized part of the key. If multiple machines generate a\n // key at the exact same time (limited by the precision of the timestamp),\n // we are ensured to have a chance of collision of `1` in `2 ** RANDOM_BITS_LENGTH`.\n const randomBytes = random(Math.ceil(RANDOM_BITS_LENGTH / 8));\n for (let i = 0; i < RANDOM_BITS_LENGTH; i++) {\n bits[RANDOM_BITS_LENGTH - 1 - i] =\n (randomBytes[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ACpE;;;;"}
package/dist/index.mjs CHANGED
@@ -1,15 +1,15 @@
1
1
  import { random } from '@lukeed/csprng';
2
2
 
3
3
  const EPOCH = /* @__PURE__ */ new Date("2024-09-08");
4
+ const TIMESTAMP_LENGTH = 36;
5
+ const RANDOM_BITS_LENGTH = 17;
6
+ const TIMESTAMP_PRECISION_DIVIDER = 100;
4
7
  function fantomid() {
5
- const TIMESTAMP_LENGTH = 36;
6
- const RANDOM_BITS_LENGTH = 17;
7
- const TIMESTAMP_PRECISION_DIVIDER = 100;
8
8
  const bits = Array(TIMESTAMP_LENGTH + RANDOM_BITS_LENGTH);
9
9
  const timestamp = Math.round(
10
10
  // Use a more recent base date instead of the Unix Epoch to
11
11
  // increase the amount of time we can represent in the timestamp.
12
- (/* @__PURE__ */ new Date() - EPOCH) / // Decrease the precision of the timestamp to
12
+ (Date.now() - EPOCH) / // Decrease the precision of the timestamp to
13
13
  // increase the amount of bits we can fit in a key.
14
14
  TIMESTAMP_PRECISION_DIVIDER
15
15
  );
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/fantomid.js"],"sourcesContent":["import { random } from \"@lukeed/csprng\";\n\nconst EPOCH = new Date(\"2024-09-08\");\n\nexport function fantomid() {\n const TIMESTAMP_LENGTH = 36;\n const RANDOM_BITS_LENGTH = 17;\n const TIMESTAMP_PRECISION_DIVIDER = 100;\n\n const bits = Array(TIMESTAMP_LENGTH + RANDOM_BITS_LENGTH);\n\n // Generates a timestamp to be part of the key. This is\n // inspired by how UUID v7 works: the idea is that this\n // will guarantee keys are generated evenly across time.\n const timestamp = Math.round(\n // Use a more recent base date instead of the Unix Epoch to\n // increase the amount of time we can represent in the timestamp.\n (new Date() - EPOCH) /\n // Decrease the precision of the timestamp to\n // increase the amount of bits we can fit in a key.\n TIMESTAMP_PRECISION_DIVIDER,\n );\n for (let i = 0; i < TIMESTAMP_LENGTH; i++) {\n bits[TIMESTAMP_LENGTH + RANDOM_BITS_LENGTH - 1 - i] = (timestamp >> i) & 1;\n }\n\n // Generates a randomized part of the key. If multiple machines generate a\n // key at the exact same time (limited by the precision of the timestamp),\n // we are ensured to have a chance of collision of `1` in `2 ** RANDOM_BITS_LENGTH`.\n const randomBytes = random(Math.ceil(RANDOM_BITS_LENGTH / 8));\n for (let i = 0; i < RANDOM_BITS_LENGTH; i++) {\n bits[RANDOM_BITS_LENGTH - 1 - i] =\n (randomBytes[Math.floor(i / 8)] >> i % 8) & 1;\n }\n\n return Number(\"0b\" + bits.reduce((id, bit) => id + bit, String()));\n}\n"],"names":[],"mappings":";;AACA,MAAM,KAAK,mBAAmB,IAAI,IAAI,CAAC,YAAY,CAAC;AAC7C,SAAS,QAAQ,GAAG;AAC3B,EAAE,MAAM,gBAAgB,GAAG,EAAE;AAC7B,EAAE,MAAM,kBAAkB,GAAG,EAAE;AAC/B,EAAE,MAAM,2BAA2B,GAAG,GAAG;AACzC,EAAE,MAAM,IAAI,GAAG,KAAK,CAAC,gBAAgB,GAAG,kBAAkB,CAAC;AAC3D,EAAE,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK;AAC9B;AACA;AACA,IAAI,iBAAiB,IAAI,IAAI,EAAE,GAAG,KAAK;AACvC;AACA,IAAI;AACJ,GAAG;AACH,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,gBAAgB,EAAE,CAAC,EAAE,EAAE;AAC7C,IAAI,IAAI,CAAC,gBAAgB,GAAG,kBAAkB,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,IAAI,CAAC,GAAG,CAAC;AAC5E,EAAE;AACF,EAAE,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC,CAAC;AAC/D,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,kBAAkB,EAAE,CAAC,EAAE,EAAE;AAC/C,IAAI,IAAI,CAAC,kBAAkB,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAClF,EAAE;AACF,EAAE,OAAO,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,KAAK,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;AACpE;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/fantomid.js"],"sourcesContent":["import { random } from \"@lukeed/csprng\";\n\nconst EPOCH = new Date(\"2024-09-08\");\nconst TIMESTAMP_LENGTH = 36;\nconst RANDOM_BITS_LENGTH = 17;\nconst TIMESTAMP_PRECISION_DIVIDER = 100;\n\nexport function fantomid() {\n const bits = Array(TIMESTAMP_LENGTH + RANDOM_BITS_LENGTH);\n\n // Generates a timestamp to be part of the key. This is\n // inspired by how UUID v7 works: the idea is that this\n // will guarantee keys are generated evenly across time.\n const timestamp = Math.round(\n // Use a more recent base date instead of the Unix Epoch to\n // increase the amount of time we can represent in the timestamp.\n (Date.now() - EPOCH) /\n // Decrease the precision of the timestamp to\n // increase the amount of bits we can fit in a key.\n TIMESTAMP_PRECISION_DIVIDER,\n );\n for (let i = 0; i < TIMESTAMP_LENGTH; i++) {\n bits[TIMESTAMP_LENGTH + RANDOM_BITS_LENGTH - 1 - i] = (timestamp >> i) & 1;\n }\n\n // Generates a randomized part of the key. If multiple machines generate a\n // key at the exact same time (limited by the precision of the timestamp),\n // we are ensured to have a chance of collision of `1` in `2 ** RANDOM_BITS_LENGTH`.\n const randomBytes = random(Math.ceil(RANDOM_BITS_LENGTH / 8));\n for (let i = 0; i < RANDOM_BITS_LENGTH; i++) {\n bits[RANDOM_BITS_LENGTH - 1 - i] =\n (randomBytes[Math.floor(i / 8)] >> i % 8) & 1;\n }\n\n return Number(\"0b\" + bits.reduce((id, bit) => id + bit, String()));\n}\n"],"names":[],"mappings":";;AACA,MAA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4
4
  "type": "module",
5
5
  "description": "A tiny, universal ID generator compatible with JavaScript integers",
6
6
  "repository": "th3rius/fantomid",
package/src/fantomid.js CHANGED
@@ -1,12 +1,11 @@
1
1
  import { random } from "@lukeed/csprng";
2
2
 
3
3
  const EPOCH = new Date("2024-09-08");
4
+ const TIMESTAMP_LENGTH = 36;
5
+ const RANDOM_BITS_LENGTH = 17;
6
+ const TIMESTAMP_PRECISION_DIVIDER = 100;
4
7
 
5
8
  export function fantomid() {
6
- const TIMESTAMP_LENGTH = 36;
7
- const RANDOM_BITS_LENGTH = 17;
8
- const TIMESTAMP_PRECISION_DIVIDER = 100;
9
-
10
9
  const bits = Array(TIMESTAMP_LENGTH + RANDOM_BITS_LENGTH);
11
10
 
12
11
  // Generates a timestamp to be part of the key. This is
@@ -15,7 +14,7 @@ export function fantomid() {
15
14
  const timestamp = Math.round(
16
15
  // Use a more recent base date instead of the Unix Epoch to
17
16
  // increase the amount of time we can represent in the timestamp.
18
- (new Date() - EPOCH) /
17
+ (Date.now() - EPOCH) /
19
18
  // Decrease the precision of the timestamp to
20
19
  // increase the amount of bits we can fit in a key.
21
20
  TIMESTAMP_PRECISION_DIVIDER,