@rasmx/uid 1.0.0 → 1.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.
- package/index.d.ts +16 -22
- package/index.js +28 -30
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,31 +1,25 @@
|
|
|
1
1
|
export interface UuidNamespace {
|
|
2
|
-
v1():
|
|
3
|
-
v3(namespace: string, name: string):
|
|
4
|
-
v4():
|
|
5
|
-
v5(namespace: string, name: string):
|
|
6
|
-
v6():
|
|
7
|
-
v7():
|
|
8
|
-
bulk(amount?: number):
|
|
9
|
-
isValid(str: string):
|
|
10
|
-
toShort(str: string):
|
|
11
|
-
fromShort(short: string):
|
|
12
|
-
getTimestamp(str: string):
|
|
2
|
+
v1(): string;
|
|
3
|
+
v3(namespace: string, name: string): string;
|
|
4
|
+
v4(): string;
|
|
5
|
+
v5(namespace: string, name: string): string;
|
|
6
|
+
v6(): string;
|
|
7
|
+
v7(): string;
|
|
8
|
+
bulk(amount?: number): string[];
|
|
9
|
+
isValid(str: string): boolean;
|
|
10
|
+
toShort(str: string): string;
|
|
11
|
+
fromShort(short: string): string;
|
|
12
|
+
getTimestamp(str: string): Date | null;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export interface UlidNamespace {
|
|
16
|
-
generate():
|
|
17
|
-
fromTime(ms: number | bigint):
|
|
18
|
-
getTimestamp(str: string):
|
|
16
|
+
generate(): string;
|
|
17
|
+
fromTime(ms: number | bigint): string;
|
|
18
|
+
getTimestamp(str: string): Date | null;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export const uuid: UuidNamespace;
|
|
22
22
|
export const ulid: UlidNamespace;
|
|
23
|
-
export const nanoid: (size?: number, alphabet?: string) =>
|
|
23
|
+
export const nanoid: (size?: number, alphabet?: string) => string;
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
uuid: UuidNamespace;
|
|
27
|
-
ulid: UlidNamespace;
|
|
28
|
-
nanoid: typeof nanoid;
|
|
29
|
-
}>;
|
|
30
|
-
|
|
31
|
-
export default init;
|
|
25
|
+
export default function init(input?: string | URL | Request): Promise<void>;
|
package/index.js
CHANGED
|
@@ -1,48 +1,46 @@
|
|
|
1
|
-
import
|
|
1
|
+
import initWasm, * as wasm from './pkg/rasmx_uuid.js';
|
|
2
2
|
|
|
3
|
-
let
|
|
3
|
+
let ready = false;
|
|
4
4
|
|
|
5
|
-
async function
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return initialized;
|
|
5
|
+
export default async function init(input) {
|
|
6
|
+
if (ready) return;
|
|
7
|
+
await initWasm(input);
|
|
8
|
+
ready = true;
|
|
10
9
|
}
|
|
11
10
|
|
|
11
|
+
const check = () => {
|
|
12
|
+
if (!ready) throw new Error("@rasmx/uuid: WASM module not initialized. Call 'await init()' once before use.");
|
|
13
|
+
};
|
|
14
|
+
|
|
12
15
|
export const uuid = {
|
|
13
|
-
v1:
|
|
14
|
-
v3:
|
|
15
|
-
v4:
|
|
16
|
-
v5:
|
|
17
|
-
v6:
|
|
18
|
-
v7:
|
|
19
|
-
bulk:
|
|
20
|
-
isValid:
|
|
21
|
-
toShort:
|
|
22
|
-
fromShort:
|
|
23
|
-
getTimestamp:
|
|
24
|
-
|
|
16
|
+
v1: () => { check(); return wasm.v1(); },
|
|
17
|
+
v3: (ns, name) => { check(); return wasm.v3(ns, name); },
|
|
18
|
+
v4: () => { check(); return wasm.v4(); },
|
|
19
|
+
v5: (ns, name) => { check(); return wasm.v5(ns, name); },
|
|
20
|
+
v6: () => { check(); return wasm.v6(); },
|
|
21
|
+
v7: () => { check(); return wasm.v7(); },
|
|
22
|
+
bulk: (amount = 10) => { check(); return wasm.bulk_v7(amount); },
|
|
23
|
+
isValid: (str) => { check(); return wasm.is_valid_uuid(str); },
|
|
24
|
+
toShort: (str) => { check(); return wasm.to_short_id(str); },
|
|
25
|
+
fromShort: (short) => { check(); return wasm.from_short_id(short); },
|
|
26
|
+
getTimestamp: (str) => {
|
|
27
|
+
check();
|
|
25
28
|
const ts = wasm.get_timestamp(str);
|
|
26
29
|
return ts ? new Date(Number(ts)) : null;
|
|
27
30
|
}
|
|
28
31
|
};
|
|
29
32
|
|
|
30
|
-
export const nanoid =
|
|
31
|
-
|
|
33
|
+
export const nanoid = (size = 21, alphabet) => {
|
|
34
|
+
check();
|
|
32
35
|
return wasm.nanoid(size, alphabet);
|
|
33
36
|
};
|
|
34
37
|
|
|
35
38
|
export const ulid = {
|
|
36
|
-
generate:
|
|
37
|
-
fromTime:
|
|
38
|
-
getTimestamp:
|
|
39
|
-
|
|
39
|
+
generate: () => { check(); return wasm.ulid(); },
|
|
40
|
+
fromTime: (ms) => { check(); return wasm.ulid_from_time(BigInt(ms)); },
|
|
41
|
+
getTimestamp: (str) => {
|
|
42
|
+
check();
|
|
40
43
|
const ts = wasm.get_timestamp(str);
|
|
41
44
|
return ts ? new Date(Number(ts)) : null;
|
|
42
45
|
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export default async () => {
|
|
46
|
-
await ensure();
|
|
47
|
-
return { uuid, nanoid, ulid };
|
|
48
46
|
};
|
package/package.json
CHANGED