@chainfuse/helpers 4.0.3 → 4.0.4
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/common.d.mts +10 -0
- package/dist/common.mjs +12 -0
- package/dist/uuid8.mjs +5 -7
- package/package.json +2 -2
package/dist/common.d.mts
CHANGED
|
@@ -39,5 +39,15 @@ export declare class Helpers {
|
|
|
39
39
|
* @returns A promise that resolves after the specified delay.
|
|
40
40
|
*/
|
|
41
41
|
static sleep(ms: number): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Replaces a substring in the input string between the specified start and end indices with the provided replacement string.
|
|
44
|
+
*
|
|
45
|
+
* @param input - The original string to modify.
|
|
46
|
+
* @param start - The starting index (inclusive) of the substring to replace.
|
|
47
|
+
* @param end - The ending index (exclusive) of the substring to replace.
|
|
48
|
+
* @param replacement - The string to insert in place of the specified substring.
|
|
49
|
+
* @returns The resulting string after replacement.
|
|
50
|
+
*/
|
|
51
|
+
static replaceByIndex(input: string, start: number, end: number, replacement: string): string;
|
|
42
52
|
}
|
|
43
53
|
export {};
|
package/dist/common.mjs
CHANGED
|
@@ -97,4 +97,16 @@ export class Helpers {
|
|
|
97
97
|
static sleep(ms) {
|
|
98
98
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
99
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Replaces a substring in the input string between the specified start and end indices with the provided replacement string.
|
|
102
|
+
*
|
|
103
|
+
* @param input - The original string to modify.
|
|
104
|
+
* @param start - The starting index (inclusive) of the substring to replace.
|
|
105
|
+
* @param end - The ending index (exclusive) of the substring to replace.
|
|
106
|
+
* @param replacement - The string to insert in place of the specified substring.
|
|
107
|
+
* @returns The resulting string after replacement.
|
|
108
|
+
*/
|
|
109
|
+
static replaceByIndex(input, start, end, replacement) {
|
|
110
|
+
return input.slice(0, start) + replacement + input.slice(end);
|
|
111
|
+
}
|
|
100
112
|
}
|
package/dist/uuid8.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { ShardType } from '@chainfuse/types/d0';
|
|
|
3
3
|
import { v7 } from 'uuid';
|
|
4
4
|
import * as z from 'zod/mini';
|
|
5
5
|
import { BufferHelpersInternals } from "./bufferInternals.mjs";
|
|
6
|
+
import { Helpers } from "./common.mjs";
|
|
6
7
|
const v8OptionsBase = z.object({
|
|
7
8
|
/**
|
|
8
9
|
* RFC "timestamp" field
|
|
@@ -46,9 +47,6 @@ export const v8Options = z.union([
|
|
|
46
47
|
rng: z.optional(z.pipe(z.unknown(), z.transform((fn) => fn))),
|
|
47
48
|
}),
|
|
48
49
|
]);
|
|
49
|
-
function replaceByIndex(input, start, end, replacement) {
|
|
50
|
-
return input.slice(0, start) + replacement + input.slice(end);
|
|
51
|
-
}
|
|
52
50
|
/**
|
|
53
51
|
* Generates a UUID version 8 with custom fields for location, shard type, and suffix.
|
|
54
52
|
*
|
|
@@ -70,11 +68,11 @@ export function v8(_options) {
|
|
|
70
68
|
// 36 character string including hyphens
|
|
71
69
|
const uuid7 = v7(options);
|
|
72
70
|
// Swap version
|
|
73
|
-
const uuid8 = replaceByIndex(uuid7, 14, 15, '8');
|
|
71
|
+
const uuid8 = Helpers.replaceByIndex(uuid7, 14, 15, '8');
|
|
74
72
|
// Inject
|
|
75
|
-
const uuid8Suffix = replaceByIndex(uuid8, 15, 18, options.suffix);
|
|
76
|
-
const uuid8SuffixLocation = replaceByIndex(uuid8Suffix, 20, 22, options.location);
|
|
77
|
-
const uuid8SuffixLocationShard = replaceByIndex(uuid8SuffixLocation, 22, 23, options.shardType);
|
|
73
|
+
const uuid8Suffix = Helpers.replaceByIndex(uuid8, 15, 18, options.suffix);
|
|
74
|
+
const uuid8SuffixLocation = Helpers.replaceByIndex(uuid8Suffix, 20, 22, options.location);
|
|
75
|
+
const uuid8SuffixLocationShard = Helpers.replaceByIndex(uuid8SuffixLocation, 22, 23, options.shardType);
|
|
78
76
|
return uuid8SuffixLocationShard;
|
|
79
77
|
}
|
|
80
78
|
export default v8;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainfuse/helpers",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "ChainFuse",
|
|
6
6
|
"homepage": "https://github.com/ChainFuse/packages/tree/main/packages/helpers#readme",
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"@cloudflare/workers-types": "^4.20250910.0",
|
|
94
94
|
"@types/node": "^22.18.1"
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "1cb8770950dfb9b294ada5352427cca884fd27bb"
|
|
97
97
|
}
|