@stryke/unique-id 0.3.1 → 0.3.3

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/README.md CHANGED
@@ -22,7 +22,7 @@ This package is part of Storm Software's **đŸŒŠī¸ Stryke** monorepo. Stryke pac
22
22
 
23
23
  <h3 align="center">đŸ’ģ Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
24
24
 
25
- [![Version](https://img.shields.io/badge/version-0.3.0-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/stryke/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
25
+ [![Version](https://img.shields.io/badge/version-0.3.1-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/stryke/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
26
26
 
27
27
  > [!IMPORTANT] Important
28
28
  > This repository, and the apps, libraries, and tools contained within, is still in it's initial development phase. As a result, bugs and issues are expected with it's usage. When the main development phase completes, a proper release will be performed, the packages will be available through NPM (and other distributions), and this message will be removed. However, in the meantime, please feel free to report any issues you may come across.
@@ -57,6 +57,7 @@ This package includes generator functions for the following type of identifiers:
57
57
 
58
58
  <!-- START doctoc -->
59
59
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
60
+
60
61
  ## Table of Contents
61
62
 
62
63
  - [Installing](#installing)
package/dist/cuid.cjs CHANGED
@@ -6,25 +6,25 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.cuid = cuid;
7
7
  var _hash = require("@stryke/hash");
8
8
  var _random = require("./random.cjs");
9
- const s = 476782367,
9
+ const l = 476782367,
10
10
  t = 36,
11
11
  c = 1,
12
- h = Math.floor(Math.random() * s) + c;
13
- function a(o = 4, e = Math.random) {
12
+ g = Math.floor(Math.random() * l) + c;
13
+ function i(o = 4, r = Math.random) {
14
14
  let n = "";
15
- for (; n.length < o;) n += Math.floor(e() * t).toString(t);
15
+ for (; n.length < o;) n += Math.floor(r() * t).toString(t);
16
16
  return n;
17
17
  }
18
- function g(o) {
19
- const e = (o?.globalObj ?? typeof globalThis > "u") && typeof globalThis > "u" ? {} : globalThis,
20
- n = Object.keys(e).toString(),
21
- r = n.length > 0 ? n + a(t, Math.random) : a(t, Math.random);
22
- return (0, _hash.hash)(r).slice(0, Math.max(0, t));
18
+ function h(o) {
19
+ const r = (o?.globalObj ?? typeof globalThis > "u") && typeof globalThis > "u" ? {} : globalThis,
20
+ n = Object.keys(r).toString(),
21
+ e = n.length > 0 ? n + i(t, Math.random) : i(t, Math.random);
22
+ return (0, _hash.hash)(e).slice(0, Math.max(0, t));
23
23
  }
24
24
  function cuid() {
25
25
  const o = Date.now().toString(t),
26
- e = h.toString(t),
27
- n = a(t, Math.random),
28
- r = (0, _hash.hash)(`${o + n + e + g()}`);
29
- return `${(0, _random.randomLetter)() + r.slice(1, Math.min(r.length - 1, t))}`;
26
+ r = g.toString(t),
27
+ n = i(t, Math.random),
28
+ e = (0, _hash.hash)(`${o + n + r + h()}`);
29
+ return `${(0, _random.randomLetter)() + e.slice(1, Math.min(e.length - 1, t))}`;
30
30
  }
package/dist/cuid.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ export interface FingerprintOptions {
2
+ globalObj?: any;
3
+ }
1
4
  /**
2
5
  * Generate a random CUID
3
6
  *
package/dist/cuid.mjs CHANGED
@@ -1 +1 @@
1
- import{hash as l}from"@stryke/hash";import{randomLetter as i}from"./random";const s=476782367,t=36,c=1,h=Math.floor(Math.random()*s)+c;function a(o=4,e=Math.random){let n="";for(;n.length<o;)n+=Math.floor(e()*t).toString(t);return n}function g(o){const e=(o?.globalObj??typeof globalThis>"u")&&typeof globalThis>"u"?{}:globalThis,n=Object.keys(e).toString(),r=n.length>0?n+a(t,Math.random):a(t,Math.random);return l(r).slice(0,Math.max(0,t))}export function cuid(){const o=Date.now().toString(t),e=h.toString(t),n=a(t,Math.random),r=l(`${o+n+e+g()}`);return`${i()+r.slice(1,Math.min(r.length-1,t))}`}
1
+ import{hash as a}from"@stryke/hash";import{randomLetter as s}from"./random";const l=476782367,t=36,c=1,g=Math.floor(Math.random()*l)+c;function i(o=4,r=Math.random){let n="";for(;n.length<o;)n+=Math.floor(r()*t).toString(t);return n}function h(o){const r=(o?.globalObj??typeof globalThis>"u")&&typeof globalThis>"u"?{}:globalThis,n=Object.keys(r).toString(),e=n.length>0?n+i(t,Math.random):i(t,Math.random);return a(e).slice(0,Math.max(0,t))}export function cuid(){const o=Date.now().toString(t),r=g.toString(t),n=i(t,Math.random),e=a(`${o+n+r+h()}`);return`${s()+e.slice(1,Math.min(e.length-1,t))}`}
@@ -9,30 +9,31 @@ exports.isValidSnowflake = isValidSnowflake;
9
9
  exports.snowflake = snowflake;
10
10
  const DEFAULT_SHARD_ID = exports.DEFAULT_SHARD_ID = 1,
11
11
  DEFAULT_EPOCH = exports.DEFAULT_EPOCH = Date.UTC(1970, 0, 1).valueOf();
12
- let i = 1;
13
- function o(e) {
12
+ let s = 1;
13
+ function a(e) {
14
14
  const t = "0000000000000000000000000000000000000000000000000000000000000000",
15
15
  n = BigInt(e).toString(2);
16
16
  return n.length < 64 ? t.slice(0, Math.max(0, 64 - n.length)) + n : n;
17
17
  }
18
- function a(e, t, n) {
19
- return Number.parseInt(n ? o(e).slice(t, t + n) : o(e).slice(Math.max(0, t)), 2);
18
+ function i(e, t, n) {
19
+ return Number.parseInt(n ? a(e).slice(t, t + n) : a(e).slice(Math.max(0, t)), 2);
20
20
  }
21
- function snowflake({
22
- shardId: e,
23
- epoch: t,
24
- timestamp: n
25
- }) {
26
- let r = BigInt(n ? n instanceof Date ? n.valueOf() : new Date(n).valueOf() : Date.now()) - BigInt(t ?? DEFAULT_EPOCH) << BigInt(22);
27
- return r |= BigInt((e ?? 1) % 1024) << BigInt(12), r |= BigInt(i++ % 4096), r.toString();
21
+ function snowflake(e = {}) {
22
+ const {
23
+ shardId: t,
24
+ epoch: n,
25
+ timestamp: r
26
+ } = e ?? {};
27
+ let o = BigInt(r ? r instanceof Date ? r.valueOf() : new Date(r).valueOf() : Date.now()) - BigInt(n ?? DEFAULT_EPOCH) << BigInt(22);
28
+ return o |= BigInt((t ?? 1) % 1024) << BigInt(12), o |= BigInt(s++ % 4096), o.toString();
28
29
  }
29
30
  function deconstructSnowflake(e) {
30
- const t = o(e);
31
+ const t = a(e);
31
32
  return {
32
33
  snowflake: e,
33
- timestamp: a(e, 1, 41),
34
- shard_id: a(e, 42, 10),
35
- sequence: a(e, 52),
34
+ timestamp: i(e, 1, 41),
35
+ shard_id: i(e, 42, 10),
36
+ sequence: i(e, 52),
36
37
  binary: t
37
38
  };
38
39
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Options passed to the `generate` function to create a snowflake identifier.
3
3
  */
4
- export interface ISnowflakeGeneratorOptions {
4
+ export interface SnowflakeGeneratorOptions {
5
5
  /**
6
6
  * The id of the shard running this generator.
7
7
  *
@@ -81,7 +81,7 @@ export declare const DEFAULT_EPOCH: number;
81
81
  * @param options - The options to use when generating the snowflake
82
82
  * @returns A snowflake
83
83
  */
84
- export declare function snowflake({ shardId, epoch, timestamp }: ISnowflakeGeneratorOptions): string;
84
+ export declare function snowflake(options?: SnowflakeGeneratorOptions): string;
85
85
  /**
86
86
  * Deconstruct a snowflake to its values using the `epoch`.
87
87
  *
@@ -1 +1 @@
1
- export const DEFAULT_SHARD_ID=1,DEFAULT_EPOCH=Date.UTC(1970,0,1).valueOf();let i=1;function o(e){const t="0000000000000000000000000000000000000000000000000000000000000000",n=BigInt(e).toString(2);return n.length<64?t.slice(0,Math.max(0,64-n.length))+n:n}function a(e,t,n){return Number.parseInt(n?o(e).slice(t,t+n):o(e).slice(Math.max(0,t)),2)}export function snowflake({shardId:e,epoch:t,timestamp:n}){let r=BigInt(n?n instanceof Date?n.valueOf():new Date(n).valueOf():Date.now())-BigInt(t??DEFAULT_EPOCH)<<BigInt(22);return r|=BigInt((e??1)%1024)<<BigInt(12),r|=BigInt(i++%4096),r.toString()}export function deconstructSnowflake(e){const t=o(e);return{snowflake:e,timestamp:a(e,1,41),shard_id:a(e,42,10),sequence:a(e,52),binary:t}}export function isValidSnowflake(e){if(!/^\d{19}$/.test(e))return!1;try{return deconstructSnowflake(e),!0}catch{return!1}}
1
+ export const DEFAULT_SHARD_ID=1,DEFAULT_EPOCH=Date.UTC(1970,0,1).valueOf();let s=1;function a(e){const t="0000000000000000000000000000000000000000000000000000000000000000",n=BigInt(e).toString(2);return n.length<64?t.slice(0,Math.max(0,64-n.length))+n:n}function i(e,t,n){return Number.parseInt(n?a(e).slice(t,t+n):a(e).slice(Math.max(0,t)),2)}export function snowflake(e={}){const{shardId:t,epoch:n,timestamp:r}=e??{};let o=BigInt(r?r instanceof Date?r.valueOf():new Date(r).valueOf():Date.now())-BigInt(n??DEFAULT_EPOCH)<<BigInt(22);return o|=BigInt((t??1)%1024)<<BigInt(12),o|=BigInt(s++%4096),o.toString()}export function deconstructSnowflake(e){const t=a(e);return{snowflake:e,timestamp:i(e,1,41),shard_id:i(e,42,10),sequence:i(e,52),binary:t}}export function isValidSnowflake(e){if(!/^\d{19}$/.test(e))return!1;try{return deconstructSnowflake(e),!0}catch{return!1}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/unique-id",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "description": "A package containing various helper functions to generate unique identifier strings",
6
6
  "repository": {
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "private": false,
12
12
  "publishConfig": { "access": "public" },
13
- "dependencies": { "@stryke/hash": "^0.9.5" },
13
+ "dependencies": { "@stryke/hash": "^0.9.7" },
14
14
  "devDependencies": {},
15
15
  "sideEffects": false,
16
16
  "files": ["dist/**/*"],
@@ -127,5 +127,6 @@
127
127
  },
128
128
  "main": "./dist/index.cjs",
129
129
  "module": "./dist/index.mjs",
130
- "types": "./dist/index.d.ts"
130
+ "types": "./dist/index.d.ts",
131
+ "gitHead": "a5ed5552046d1a8b313d88aed4d8bce7f33caec8"
131
132
  }