pino-ulid 2.12.2

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.
@@ -0,0 +1,49 @@
1
+ import { PRNG, ULID, ULIDFactory } from "./types.js";
2
+ /**
3
+ * Decode time from a ULID
4
+ * @param id The ULID
5
+ * @returns The decoded timestamp
6
+ */
7
+ export declare function decodeTime(id: ULID): number;
8
+ /**
9
+ * Detect the best PRNG (pseudo-random number generator)
10
+ * @param root The root to check from (global/window)
11
+ * @returns The PRNG function
12
+ */
13
+ export declare function detectPRNG(root?: any): PRNG;
14
+ export declare function encodeRandom(len: number, prng: PRNG): string;
15
+ /**
16
+ * Encode the time portion of a ULID
17
+ * @param now The current timestamp
18
+ * @param len Length to generate
19
+ * @returns The encoded time
20
+ */
21
+ export declare function encodeTime(now: number, len?: number): string;
22
+ /**
23
+ * Check if a ULID is valid
24
+ * @param id The ULID to test
25
+ * @returns True if valid, false otherwise
26
+ * @example
27
+ * isValid("01HNZX8JGFACFA36RBXDHEQN6E"); // true
28
+ * isValid(""); // false
29
+ */
30
+ export declare function isValid(id: string): boolean;
31
+ /**
32
+ * Create a ULID factory to generate monotonically-increasing
33
+ * ULIDs
34
+ * @param prng The PRNG to use
35
+ * @returns A ulid factory
36
+ * @example
37
+ * const ulid = monotonicFactory();
38
+ * ulid(); // "01HNZXD07M5CEN5XA66EMZSRZW"
39
+ */
40
+ export declare function monotonicFactory(prng?: PRNG): ULIDFactory;
41
+ /**
42
+ * Generate a ULID
43
+ * @param seedTime Optional time seed
44
+ * @param prng Optional PRNG function
45
+ * @returns A ULID string
46
+ * @example
47
+ * ulid(); // "01HNZXD07M5CEN5XA66EMZSRZW"
48
+ */
49
+ export declare function ulid(seedTime?: number, prng?: PRNG): ULID;
package/dist/ulid.d.ts ADDED
@@ -0,0 +1,49 @@
1
+ import { PRNG, ULID, ULIDFactory } from "./types.js";
2
+ /**
3
+ * Decode time from a ULID
4
+ * @param id The ULID
5
+ * @returns The decoded timestamp
6
+ */
7
+ export declare function decodeTime(id: ULID): number;
8
+ /**
9
+ * Detect the best PRNG (pseudo-random number generator)
10
+ * @param root The root to check from (global/window)
11
+ * @returns The PRNG function
12
+ */
13
+ export declare function detectPRNG(root?: any): PRNG;
14
+ export declare function encodeRandom(len: number, prng: PRNG): string;
15
+ /**
16
+ * Encode the time portion of a ULID
17
+ * @param now The current timestamp
18
+ * @param len Length to generate
19
+ * @returns The encoded time
20
+ */
21
+ export declare function encodeTime(now: number, len?: number): string;
22
+ /**
23
+ * Check if a ULID is valid
24
+ * @param id The ULID to test
25
+ * @returns True if valid, false otherwise
26
+ * @example
27
+ * isValid("01HNZX8JGFACFA36RBXDHEQN6E"); // true
28
+ * isValid(""); // false
29
+ */
30
+ export declare function isValid(id: string): boolean;
31
+ /**
32
+ * Create a ULID factory to generate monotonically-increasing
33
+ * ULIDs
34
+ * @param prng The PRNG to use
35
+ * @returns A ulid factory
36
+ * @example
37
+ * const ulid = monotonicFactory();
38
+ * ulid(); // "01HNZXD07M5CEN5XA66EMZSRZW"
39
+ */
40
+ export declare function monotonicFactory(prng?: PRNG): ULIDFactory;
41
+ /**
42
+ * Generate a ULID
43
+ * @param seedTime Optional time seed
44
+ * @param prng Optional PRNG function
45
+ * @returns A ULID string
46
+ * @example
47
+ * ulid(); // "01HNZXD07M5CEN5XA66EMZSRZW"
48
+ */
49
+ export declare function ulid(seedTime?: number, prng?: PRNG): ULID;
@@ -0,0 +1,3 @@
1
+ import { PRNG } from "./types.js";
2
+ export declare function randomChar(prng: PRNG): string;
3
+ export declare function replaceCharAt(str: string, index: number, char: string): string;
@@ -0,0 +1,3 @@
1
+ import { PRNG } from "./types.js";
2
+ export declare function randomChar(prng: PRNG): string;
3
+ export declare function replaceCharAt(str: string, index: number, char: string): string;
@@ -0,0 +1,14 @@
1
+ import { UUID } from "crypto";
2
+ import { ULID } from "./types.js";
3
+ /**
4
+ * Convert a ULID to a UUID
5
+ * @param ulid The ULID to convert
6
+ * @returns A UUID string
7
+ */
8
+ export declare function ulidToUUID(ulid: ULID): UUID;
9
+ /**
10
+ * Convert a UUID to a ULID
11
+ * @param uuid The UUID to convert
12
+ * @returns A ULID string
13
+ */
14
+ export declare function uuidToULID(uuid: string): ULID;
package/dist/uuid.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { UUID } from "crypto";
2
+ import { ULID } from "./types.js";
3
+ /**
4
+ * Convert a ULID to a UUID
5
+ * @param ulid The ULID to convert
6
+ * @returns A UUID string
7
+ */
8
+ export declare function ulidToUUID(ulid: ULID): UUID;
9
+ /**
10
+ * Convert a UUID to a ULID
11
+ * @param uuid The UUID to convert
12
+ * @returns A ULID string
13
+ */
14
+ export declare function uuidToULID(uuid: string): ULID;
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "pino-ulid",
3
+ "version": "2.12.2",
4
+ "description": "A universally-unique, lexicographically-sortable, identifier generator",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": {
9
+ "require": "./dist/index.d.cts",
10
+ "default": "./dist/index.d.ts"
11
+ },
12
+ "node": {
13
+ "require": "./dist/node/index.cjs",
14
+ "default": "./dist/node/index.js"
15
+ },
16
+ "default": {
17
+ "require": "./dist/browser/index.cjs",
18
+ "default": "./dist/browser/index.js"
19
+ }
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "main": "dist/node/index.cjs",
24
+ "module": "./dist/node/index.js",
25
+ "browser": {
26
+ "./dist/node/index.cjs": "./dist/browser/index.cjs",
27
+ "./dist/node/index.js": "./dist/browser/index.js"
28
+ },
29
+ "react-native": "./dist/browser/index.cjs",
30
+ "types": "dist/index.d.ts",
31
+ "sideEffects": false,
32
+ "bin": "./dist/cli.js",
33
+ "scripts": {
34
+ "bench": "npm run build && node test/benchmark.js",
35
+ "build": "npm run build:node:cjs && npm run build:node:esm && npm run build:browser:cjs && npm run build:browser:esm && npm run build:cli && npm run build:types",
36
+ "build:browser:cjs": "FMT=cjs ENV=browser rollup -c --name ulidx",
37
+ "build:browser:esm": "FMT=esm ENV=browser rollup -c --name ulidx",
38
+ "build:cli": "FMT=esm ENV=cli rollup -c && chmod +x ./dist/cli.js",
39
+ "build:node:cjs": "FMT=cjs ENV=node rollup -c",
40
+ "build:node:esm": "FMT=esm ENV=node rollup -c",
41
+ "build:types": "tsc -p tsconfig.dec.json --emitDeclarationOnly && find ./dist -name '*.d.ts' -exec sh -c 'cp {} $(dirname {})/$(basename -s .d.ts {}).d.cts' \\;",
42
+ "format": "prettier --write \"{{source,test}/**/*.{js,ts},rollup.config.js,vitest.config.js}\"",
43
+ "test": "npm run build && npm run test:specs && npm run test:format && npm run test:types",
44
+ "test:format": "prettier --check \"{{source,test}/**/*.{js,ts},rollup.config.js,vitest.config.js}\"",
45
+ "test:specs": "vitest",
46
+ "test:types": "npx --yes @arethetypeswrong/cli --pack ."
47
+ },
48
+ "files": [
49
+ "dist/**/*"
50
+ ],
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/ulid/javascript.git"
54
+ },
55
+ "author": "Alizain Feerasta",
56
+ "license": "MIT",
57
+ "bugs": {
58
+ "url": "https://github.com/ulid/javascript/issues"
59
+ },
60
+ "homepage": "https://github.com/ulid/javascript#readme",
61
+ "devDependencies": {
62
+ "@rollup/plugin-alias": "^5.1.1",
63
+ "@rollup/plugin-commonjs": "^28.0.3",
64
+ "@rollup/plugin-node-resolve": "^16.0.1",
65
+ "@rollup/plugin-typescript": "^12.1.2",
66
+ "@types/node": "^22.15.30",
67
+ "benchmark": "^2.1.4",
68
+ "prettier": "^3.5.3",
69
+ "rollup": "^4.42.0",
70
+ "tslib": "^2.8.1",
71
+ "typescript": "^5.8.3",
72
+ "vitest": "^3.2.2"
73
+ }
74
+ }