@md-oss/common 0.1.6 → 0.1.7
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/arrays-6DA6GfsQ.mjs +2 -0
- package/dist/arrays-6DA6GfsQ.mjs.map +1 -0
- package/dist/arrays-DvPJ1GeR.d.cts +163 -0
- package/dist/arrays-DvPJ1GeR.d.mts +163 -0
- package/dist/arrays-bgbansWs.cjs +2 -0
- package/dist/arrays-bgbansWs.cjs.map +1 -0
- package/dist/constants/bytes.cjs +1 -1
- package/dist/constants/bytes.cjs.map +1 -1
- package/dist/constants/bytes.d.cts +31 -1
- package/dist/constants/bytes.d.mts +31 -1
- package/dist/constants/bytes.mjs +1 -1
- package/dist/constants/bytes.mjs.map +1 -1
- package/dist/files-DzKYei0a.mjs +2 -0
- package/dist/files-DzKYei0a.mjs.map +1 -0
- package/dist/files-m1nnj5gT.cjs +2 -0
- package/dist/files-m1nnj5gT.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +10 -8
- package/dist/index.d.mts +10 -8
- package/dist/index.mjs +1 -1
- package/dist/mime-types-BmvBrrZ7.cjs.map +1 -1
- package/dist/mime-types-D_K53zgk.mjs.map +1 -1
- package/dist/{mime-types-Bjt4NvnE.d.cts → mime-types-Dajfhq2c.d.cts} +58 -1
- package/dist/{mime-types-Bjt4NvnE.d.mts → mime-types-Dajfhq2c.d.mts} +58 -1
- package/dist/numbers-B_mptknO.cjs +2 -0
- package/dist/numbers-B_mptknO.cjs.map +1 -0
- package/dist/numbers-C2680fmA.d.cts +184 -0
- package/dist/numbers-C2680fmA.d.mts +184 -0
- package/dist/numbers-lJ6gwIpk.mjs +2 -0
- package/dist/numbers-lJ6gwIpk.mjs.map +1 -0
- package/dist/objects-VXf3mqE5.mjs +2 -0
- package/dist/objects-VXf3mqE5.mjs.map +1 -0
- package/dist/objects-fiFExjsf.d.cts +116 -0
- package/dist/objects-fiFExjsf.d.mts +116 -0
- package/dist/objects-wcO6hNA8.cjs +2 -0
- package/dist/objects-wcO6hNA8.cjs.map +1 -0
- package/dist/random-668tofPV.cjs +2 -0
- package/dist/random-668tofPV.cjs.map +1 -0
- package/dist/random-BqJDZAPb.d.cts +131 -0
- package/dist/random-BqJDZAPb.d.mts +131 -0
- package/dist/random-ihslkInn.mjs +2 -0
- package/dist/random-ihslkInn.mjs.map +1 -0
- package/dist/runtime-7fkN5_oL.d.cts +206 -0
- package/dist/runtime-7fkN5_oL.d.mts +206 -0
- package/dist/runtime-Bfs-yn_-.cjs +2 -0
- package/dist/runtime-Bfs-yn_-.cjs.map +1 -0
- package/dist/runtime-CE36Va0l.mjs +2 -0
- package/dist/runtime-CE36Va0l.mjs.map +1 -0
- package/dist/strings-CrzGdnZH.mjs +3 -0
- package/dist/strings-CrzGdnZH.mjs.map +1 -0
- package/dist/strings-_1vAPvzS.cjs +3 -0
- package/dist/strings-_1vAPvzS.cjs.map +1 -0
- package/dist/strings-jE1j-qqa.d.cts +213 -0
- package/dist/strings-jE1j-qqa.d.mts +213 -0
- package/dist/time-BrLHgSth.d.mts +68 -0
- package/dist/time-DmJNWZeL.mjs.map +1 -1
- package/dist/time-ufhllID1.d.cts +68 -0
- package/dist/time-yNkQSJnQ.cjs.map +1 -1
- package/dist/utils/arrays.cjs +1 -1
- package/dist/utils/arrays.d.cts +1 -1
- package/dist/utils/arrays.d.mts +1 -1
- package/dist/utils/arrays.mjs +1 -1
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.cts +187 -8
- package/dist/utils/index.d.mts +187 -8
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/mime-types.d.cts +1 -1
- package/dist/utils/mime-types.d.mts +1 -1
- package/dist/utils/numbers.cjs +1 -1
- package/dist/utils/numbers.d.cts +1 -1
- package/dist/utils/numbers.d.mts +1 -1
- package/dist/utils/numbers.mjs +1 -1
- package/dist/utils/objects.cjs +1 -1
- package/dist/utils/objects.d.cts +1 -1
- package/dist/utils/objects.d.mts +1 -1
- package/dist/utils/objects.mjs +1 -1
- package/dist/utils/random.cjs +1 -1
- package/dist/utils/random.d.cts +1 -1
- package/dist/utils/random.d.mts +1 -1
- package/dist/utils/random.mjs +1 -1
- package/dist/utils/runtime.cjs +1 -1
- package/dist/utils/runtime.d.cts +1 -1
- package/dist/utils/runtime.d.mts +1 -1
- package/dist/utils/runtime.mjs +1 -1
- package/dist/utils/strings.cjs +1 -1
- package/dist/utils/strings.d.cts +1 -1
- package/dist/utils/strings.d.mts +1 -1
- package/dist/utils/strings.mjs +1 -1
- package/dist/utils/time.d.cts +1 -1
- package/dist/utils/time.d.mts +1 -1
- package/package.json +2 -2
- package/dist/arrays-BkHBzTDO.mjs +0 -2
- package/dist/arrays-BkHBzTDO.mjs.map +0 -1
- package/dist/arrays-CElcW69H.d.cts +0 -43
- package/dist/arrays-CElcW69H.d.mts +0 -43
- package/dist/arrays-DaB1Xn47.cjs +0 -2
- package/dist/arrays-DaB1Xn47.cjs.map +0 -1
- package/dist/numbers-CtAqd3eH.d.cts +0 -49
- package/dist/numbers-CtAqd3eH.d.mts +0 -49
- package/dist/numbers-D2K-8sJL.mjs +0 -2
- package/dist/numbers-D2K-8sJL.mjs.map +0 -1
- package/dist/numbers-Du__2-8Y.cjs +0 -2
- package/dist/numbers-Du__2-8Y.cjs.map +0 -1
- package/dist/objects--cO_X3EV.mjs +0 -2
- package/dist/objects--cO_X3EV.mjs.map +0 -1
- package/dist/objects-CnGoVkh6.cjs +0 -2
- package/dist/objects-CnGoVkh6.cjs.map +0 -1
- package/dist/objects-cf8j7rS8.d.cts +0 -26
- package/dist/objects-cf8j7rS8.d.mts +0 -26
- package/dist/random-D1e1NTOt.cjs +0 -2
- package/dist/random-D1e1NTOt.cjs.map +0 -1
- package/dist/random-DbidGSrQ.mjs +0 -2
- package/dist/random-DbidGSrQ.mjs.map +0 -1
- package/dist/random-DpNyGGAZ.d.cts +0 -28
- package/dist/random-DpNyGGAZ.d.mts +0 -28
- package/dist/runtime-DY-8W6Jr.mjs +0 -2
- package/dist/runtime-DY-8W6Jr.mjs.map +0 -1
- package/dist/runtime-T8Kcf7Af.d.cts +0 -28
- package/dist/runtime-T8Kcf7Af.d.mts +0 -28
- package/dist/runtime-peVFcWot.cjs +0 -2
- package/dist/runtime-peVFcWot.cjs.map +0 -1
- package/dist/strings-B0BRwNX9.mjs +0 -3
- package/dist/strings-B0BRwNX9.mjs.map +0 -1
- package/dist/strings-DV446vv-.cjs +0 -3
- package/dist/strings-DV446vv-.cjs.map +0 -1
- package/dist/strings-DhPbrpq7.d.cts +0 -47
- package/dist/strings-DhPbrpq7.d.mts +0 -47
- package/dist/time-8KLG8kBO.d.cts +0 -29
- package/dist/time-D8Wfqzu6.d.mts +0 -29
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a random integer between min and max (inclusive)
|
|
3
|
+
* @param min - Minimum value
|
|
4
|
+
* @param max - Maximum value
|
|
5
|
+
* @returns Random integer
|
|
6
|
+
* @example randomInt(1, 10) // Random integer from 1 to 10
|
|
7
|
+
*/
|
|
8
|
+
declare const randomInt: (min: number, max: number) => number;
|
|
9
|
+
/**
|
|
10
|
+
* Generate a random float between min and max
|
|
11
|
+
* @param min - Minimum value
|
|
12
|
+
* @param max - Maximum value
|
|
13
|
+
* @returns Random float
|
|
14
|
+
* @example randomFloat(1.0, 10.0) // Random float from 1.0 to 10.0
|
|
15
|
+
*/
|
|
16
|
+
declare const randomFloat: (min: number, max: number) => number;
|
|
17
|
+
/**
|
|
18
|
+
* Get a random item from an array
|
|
19
|
+
* @param items - Array to pick from
|
|
20
|
+
* @returns Random item or undefined if array is empty
|
|
21
|
+
* @example randomItem([1, 2, 3]) // Could return 1, 2, or 3
|
|
22
|
+
*/
|
|
23
|
+
declare const randomItem: <T>(items: T[]) => T | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Get a random key from an object or array
|
|
26
|
+
* @param items - Object or array to pick from
|
|
27
|
+
* @returns Random key or undefined
|
|
28
|
+
* @example randomKey({a: 1, b: 2}) // Could return "a" or "b"
|
|
29
|
+
*/
|
|
30
|
+
declare const randomKey: <T>(items: Record<string, T> | T[]) => string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Get a random value from an object or array
|
|
33
|
+
* @param items - Object or array to pick from
|
|
34
|
+
* @returns Random value or undefined
|
|
35
|
+
* @example randomValue({a: 1, b: 2}) // Could return 1 or 2
|
|
36
|
+
*/
|
|
37
|
+
declare const randomValue: <T>(items: Record<string, T> | T[]) => T | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Generate a random boolean value
|
|
40
|
+
* @returns Random true or false
|
|
41
|
+
* @example randomBoolean() // Could return true or false with 50% probability each
|
|
42
|
+
*/
|
|
43
|
+
declare const randomBoolean: () => boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Generate a random string of specified length
|
|
46
|
+
* @param length - Length of the string to generate
|
|
47
|
+
* @param characters - Character set to use (string or options object)
|
|
48
|
+
* @returns Random string
|
|
49
|
+
* @example randomString(10) // Random 10-char string with uppercase, lowercase, and numbers
|
|
50
|
+
* @example randomString(5, 'abc') // Random 5-char string using only 'a', 'b', 'c'
|
|
51
|
+
* @example randomString(8, {useUppercase: true, useLowercase: false, useNumeric: false})
|
|
52
|
+
*/
|
|
53
|
+
declare const randomString: (length: number, characters?: string | RandomStringOptions) => string;
|
|
54
|
+
/**
|
|
55
|
+
* Generate a random hex string (lowercase)
|
|
56
|
+
* @param length - Length of the hex string (default: 16)
|
|
57
|
+
* @returns Random hex string
|
|
58
|
+
* @example randomHex(8) // "a3f5c9d1"
|
|
59
|
+
*/
|
|
60
|
+
declare const randomHex: (length?: number) => string;
|
|
61
|
+
/**
|
|
62
|
+
* Generate a UUID v4 (random)
|
|
63
|
+
* @returns UUID string
|
|
64
|
+
* @example randomUUID() // "f47ac10b-58cc-4372-a567-0e02b2c3d479"
|
|
65
|
+
*/
|
|
66
|
+
declare const randomUUID: () => string;
|
|
67
|
+
/**
|
|
68
|
+
* Pick N random items from an array without replacement
|
|
69
|
+
* @param items - Array to sample from
|
|
70
|
+
* @param count - Number of items to pick
|
|
71
|
+
* @returns Array of randomly selected items
|
|
72
|
+
* @example sample([1, 2, 3, 4, 5], 3) // [2, 5, 1]
|
|
73
|
+
*/
|
|
74
|
+
declare const sample: <T>(items: T[], count: number) => T[];
|
|
75
|
+
/**
|
|
76
|
+
* Pick a random item with weighted probabilities
|
|
77
|
+
* @param items - Array of items
|
|
78
|
+
* @param weights - Array of weights (must be same length as items)
|
|
79
|
+
* @returns Random item based on weights
|
|
80
|
+
* @example weightedRandom(['a', 'b', 'c'], [1, 2, 3]) // 'c' is 3x more likely than 'a'
|
|
81
|
+
*/
|
|
82
|
+
declare const weightedRandom: <T>(items: T[], weights: number[]) => T | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Get a random enum value
|
|
85
|
+
* @param enumObj - Enum object
|
|
86
|
+
* @returns Random enum value
|
|
87
|
+
* @example enum Color { Red, Green, Blue }; randomEnum(Color) // Color.Green
|
|
88
|
+
*/
|
|
89
|
+
declare const randomEnum: <T extends Record<string, string | number>>(enumObj: T) => T[keyof T];
|
|
90
|
+
/**
|
|
91
|
+
* Generate a random hex color
|
|
92
|
+
* @returns Random hex color string (e.g., "#a3f5c9")
|
|
93
|
+
* @example randomColor() // "#a3f5c9"
|
|
94
|
+
*/
|
|
95
|
+
declare const randomColor: () => string;
|
|
96
|
+
/**
|
|
97
|
+
* Generate a random date between two dates
|
|
98
|
+
* @param start - Start date
|
|
99
|
+
* @param end - End date
|
|
100
|
+
* @returns Random date between start and end
|
|
101
|
+
* @example randomDate(new Date(2020, 0, 1), new Date(2021, 0, 1))
|
|
102
|
+
*/
|
|
103
|
+
declare const randomDate: (start: Date, end: Date) => Date;
|
|
104
|
+
type RandomStringOptions = {
|
|
105
|
+
useNumeric?: boolean;
|
|
106
|
+
useLowercase?: boolean;
|
|
107
|
+
useUppercase?: boolean;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
type random_RandomStringOptions = RandomStringOptions;
|
|
111
|
+
declare const random_randomBoolean: typeof randomBoolean;
|
|
112
|
+
declare const random_randomColor: typeof randomColor;
|
|
113
|
+
declare const random_randomDate: typeof randomDate;
|
|
114
|
+
declare const random_randomEnum: typeof randomEnum;
|
|
115
|
+
declare const random_randomFloat: typeof randomFloat;
|
|
116
|
+
declare const random_randomHex: typeof randomHex;
|
|
117
|
+
declare const random_randomInt: typeof randomInt;
|
|
118
|
+
declare const random_randomItem: typeof randomItem;
|
|
119
|
+
declare const random_randomKey: typeof randomKey;
|
|
120
|
+
declare const random_randomString: typeof randomString;
|
|
121
|
+
declare const random_randomUUID: typeof randomUUID;
|
|
122
|
+
declare const random_randomValue: typeof randomValue;
|
|
123
|
+
declare const random_sample: typeof sample;
|
|
124
|
+
declare const random_weightedRandom: typeof weightedRandom;
|
|
125
|
+
declare namespace random {
|
|
126
|
+
export { random_randomBoolean as randomBoolean, random_randomColor as randomColor, random_randomDate as randomDate, random_randomEnum as randomEnum, random_randomFloat as randomFloat, random_randomHex as randomHex, random_randomInt as randomInt, random_randomItem as randomItem, random_randomKey as randomKey, random_randomString as randomString, random_randomUUID as randomUUID, random_randomValue as randomValue, random_sample as sample, random_weightedRandom as weightedRandom };
|
|
127
|
+
export type { random_RandomStringOptions as RandomStringOptions };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { randomInt as a, randomFloat as b, randomItem as c, randomKey as d, randomValue as e, randomBoolean as f, randomString as g, randomHex as h, randomUUID as i, randomEnum as j, randomColor as k, randomDate as l, random as r, sample as s, weightedRandom as w };
|
|
131
|
+
export type { RandomStringOptions as R };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a random integer between min and max (inclusive)
|
|
3
|
+
* @param min - Minimum value
|
|
4
|
+
* @param max - Maximum value
|
|
5
|
+
* @returns Random integer
|
|
6
|
+
* @example randomInt(1, 10) // Random integer from 1 to 10
|
|
7
|
+
*/
|
|
8
|
+
declare const randomInt: (min: number, max: number) => number;
|
|
9
|
+
/**
|
|
10
|
+
* Generate a random float between min and max
|
|
11
|
+
* @param min - Minimum value
|
|
12
|
+
* @param max - Maximum value
|
|
13
|
+
* @returns Random float
|
|
14
|
+
* @example randomFloat(1.0, 10.0) // Random float from 1.0 to 10.0
|
|
15
|
+
*/
|
|
16
|
+
declare const randomFloat: (min: number, max: number) => number;
|
|
17
|
+
/**
|
|
18
|
+
* Get a random item from an array
|
|
19
|
+
* @param items - Array to pick from
|
|
20
|
+
* @returns Random item or undefined if array is empty
|
|
21
|
+
* @example randomItem([1, 2, 3]) // Could return 1, 2, or 3
|
|
22
|
+
*/
|
|
23
|
+
declare const randomItem: <T>(items: T[]) => T | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Get a random key from an object or array
|
|
26
|
+
* @param items - Object or array to pick from
|
|
27
|
+
* @returns Random key or undefined
|
|
28
|
+
* @example randomKey({a: 1, b: 2}) // Could return "a" or "b"
|
|
29
|
+
*/
|
|
30
|
+
declare const randomKey: <T>(items: Record<string, T> | T[]) => string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Get a random value from an object or array
|
|
33
|
+
* @param items - Object or array to pick from
|
|
34
|
+
* @returns Random value or undefined
|
|
35
|
+
* @example randomValue({a: 1, b: 2}) // Could return 1 or 2
|
|
36
|
+
*/
|
|
37
|
+
declare const randomValue: <T>(items: Record<string, T> | T[]) => T | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Generate a random boolean value
|
|
40
|
+
* @returns Random true or false
|
|
41
|
+
* @example randomBoolean() // Could return true or false with 50% probability each
|
|
42
|
+
*/
|
|
43
|
+
declare const randomBoolean: () => boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Generate a random string of specified length
|
|
46
|
+
* @param length - Length of the string to generate
|
|
47
|
+
* @param characters - Character set to use (string or options object)
|
|
48
|
+
* @returns Random string
|
|
49
|
+
* @example randomString(10) // Random 10-char string with uppercase, lowercase, and numbers
|
|
50
|
+
* @example randomString(5, 'abc') // Random 5-char string using only 'a', 'b', 'c'
|
|
51
|
+
* @example randomString(8, {useUppercase: true, useLowercase: false, useNumeric: false})
|
|
52
|
+
*/
|
|
53
|
+
declare const randomString: (length: number, characters?: string | RandomStringOptions) => string;
|
|
54
|
+
/**
|
|
55
|
+
* Generate a random hex string (lowercase)
|
|
56
|
+
* @param length - Length of the hex string (default: 16)
|
|
57
|
+
* @returns Random hex string
|
|
58
|
+
* @example randomHex(8) // "a3f5c9d1"
|
|
59
|
+
*/
|
|
60
|
+
declare const randomHex: (length?: number) => string;
|
|
61
|
+
/**
|
|
62
|
+
* Generate a UUID v4 (random)
|
|
63
|
+
* @returns UUID string
|
|
64
|
+
* @example randomUUID() // "f47ac10b-58cc-4372-a567-0e02b2c3d479"
|
|
65
|
+
*/
|
|
66
|
+
declare const randomUUID: () => string;
|
|
67
|
+
/**
|
|
68
|
+
* Pick N random items from an array without replacement
|
|
69
|
+
* @param items - Array to sample from
|
|
70
|
+
* @param count - Number of items to pick
|
|
71
|
+
* @returns Array of randomly selected items
|
|
72
|
+
* @example sample([1, 2, 3, 4, 5], 3) // [2, 5, 1]
|
|
73
|
+
*/
|
|
74
|
+
declare const sample: <T>(items: T[], count: number) => T[];
|
|
75
|
+
/**
|
|
76
|
+
* Pick a random item with weighted probabilities
|
|
77
|
+
* @param items - Array of items
|
|
78
|
+
* @param weights - Array of weights (must be same length as items)
|
|
79
|
+
* @returns Random item based on weights
|
|
80
|
+
* @example weightedRandom(['a', 'b', 'c'], [1, 2, 3]) // 'c' is 3x more likely than 'a'
|
|
81
|
+
*/
|
|
82
|
+
declare const weightedRandom: <T>(items: T[], weights: number[]) => T | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Get a random enum value
|
|
85
|
+
* @param enumObj - Enum object
|
|
86
|
+
* @returns Random enum value
|
|
87
|
+
* @example enum Color { Red, Green, Blue }; randomEnum(Color) // Color.Green
|
|
88
|
+
*/
|
|
89
|
+
declare const randomEnum: <T extends Record<string, string | number>>(enumObj: T) => T[keyof T];
|
|
90
|
+
/**
|
|
91
|
+
* Generate a random hex color
|
|
92
|
+
* @returns Random hex color string (e.g., "#a3f5c9")
|
|
93
|
+
* @example randomColor() // "#a3f5c9"
|
|
94
|
+
*/
|
|
95
|
+
declare const randomColor: () => string;
|
|
96
|
+
/**
|
|
97
|
+
* Generate a random date between two dates
|
|
98
|
+
* @param start - Start date
|
|
99
|
+
* @param end - End date
|
|
100
|
+
* @returns Random date between start and end
|
|
101
|
+
* @example randomDate(new Date(2020, 0, 1), new Date(2021, 0, 1))
|
|
102
|
+
*/
|
|
103
|
+
declare const randomDate: (start: Date, end: Date) => Date;
|
|
104
|
+
type RandomStringOptions = {
|
|
105
|
+
useNumeric?: boolean;
|
|
106
|
+
useLowercase?: boolean;
|
|
107
|
+
useUppercase?: boolean;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
type random_RandomStringOptions = RandomStringOptions;
|
|
111
|
+
declare const random_randomBoolean: typeof randomBoolean;
|
|
112
|
+
declare const random_randomColor: typeof randomColor;
|
|
113
|
+
declare const random_randomDate: typeof randomDate;
|
|
114
|
+
declare const random_randomEnum: typeof randomEnum;
|
|
115
|
+
declare const random_randomFloat: typeof randomFloat;
|
|
116
|
+
declare const random_randomHex: typeof randomHex;
|
|
117
|
+
declare const random_randomInt: typeof randomInt;
|
|
118
|
+
declare const random_randomItem: typeof randomItem;
|
|
119
|
+
declare const random_randomKey: typeof randomKey;
|
|
120
|
+
declare const random_randomString: typeof randomString;
|
|
121
|
+
declare const random_randomUUID: typeof randomUUID;
|
|
122
|
+
declare const random_randomValue: typeof randomValue;
|
|
123
|
+
declare const random_sample: typeof sample;
|
|
124
|
+
declare const random_weightedRandom: typeof weightedRandom;
|
|
125
|
+
declare namespace random {
|
|
126
|
+
export { random_randomBoolean as randomBoolean, random_randomColor as randomColor, random_randomDate as randomDate, random_randomEnum as randomEnum, random_randomFloat as randomFloat, random_randomHex as randomHex, random_randomInt as randomInt, random_randomItem as randomItem, random_randomKey as randomKey, random_randomString as randomString, random_randomUUID as randomUUID, random_randomValue as randomValue, random_sample as sample, random_weightedRandom as weightedRandom };
|
|
127
|
+
export type { random_RandomStringOptions as RandomStringOptions };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { randomInt as a, randomFloat as b, randomItem as c, randomKey as d, randomValue as e, randomBoolean as f, randomString as g, randomHex as h, randomUUID as i, randomEnum as j, randomColor as k, randomDate as l, random as r, sample as s, weightedRandom as w };
|
|
131
|
+
export type { RandomStringOptions as R };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var b=Object.defineProperty;var n=(r,e)=>b(r,"name",{value:e,configurable:!0});const d=n((r,e)=>Math.floor(Math.random()*(e-r+1))+r,"randomInt"),h=n((r,e)=>Math.random()*(e-r)+r,"randomFloat"),m=n(r=>r[Math.floor(Math.random()*r.length)],"randomItem"),x=n(r=>m(Object.keys(r)),"randomKey"),u=n(r=>m(Array.isArray(r)?r:Object.values(r)),"randomValue"),g=n(()=>Math.random()<.5,"randomBoolean"),l=n((r,e)=>{const t=typeof e=="string"?e:n((a={})=>{const s=a.useUppercase!==void 0||a.useLowercase!==void 0||a.useNumeric!==void 0;return[a.useUppercase??!s?"ABCDEFGHIJKLMNOPQRSTUVWXYZ":"",a.useLowercase??!s?"abcdefghijklmnopqrstuvwxyz":"",a.useNumeric??!s?"0123456789":""].join("")},"resolveCharactersFromOptions")(e);if(t.length===0&&r>0)throw new Error("Character set cannot be empty");return r<=0?"":Array.from({length:r}).map(()=>t.charAt(d(0,t.length-1))).join("")},"randomString"),c=n((r=16)=>l(r,"0123456789abcdef"),"randomHex"),i=n(()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{const e=Math.random()*16|0;return(r==="x"?e:e&3|8).toString(16)}),"randomUUID"),f=n((r,e)=>{if(e>r.length)throw new Error(`Cannot sample ${e} items from array of length ${r.length}`);if(e<=0)return[];const o=[],t=[...r];for(let a=0;a<e;a++){const s=d(0,t.length-1);o.push(t[s]),t.splice(s,1)}return o},"sample"),p=n((r,e)=>{if(r.length===0)return;if(r.length!==e.length)throw new Error("Items and weights arrays must have the same length");const o=e.reduce((a,s)=>a+s,0);if(o<=0)throw new Error("Total weight must be greater than 0");let t=Math.random()*o;for(let a=0;a<r.length;a++)if(t-=e[a],t<=0)return r[a];return r[r.length-1]},"weightedRandom"),y=n(r=>{const e=Object.keys(r).filter(o=>Number.isNaN(Number(o))).map(o=>r[o]);return m(e)},"randomEnum"),w=n(()=>`#${c(6)}`,"randomColor"),v=n((r,e)=>new Date(r.getTime()+Math.random()*(e.getTime()-r.getTime())),"randomDate");var M=Object.freeze({__proto__:null,randomBoolean:g,randomColor:w,randomDate:v,randomEnum:y,randomFloat:h,randomHex:c,randomInt:d,randomItem:m,randomKey:x,randomString:l,randomUUID:i,randomValue:u,sample:f,weightedRandom:p});export{d as a,h as b,m as c,x as d,u as e,g as f,l as g,c as h,i,y as j,w as k,v as l,M as r,f as s,p as w};
|
|
2
|
+
//# sourceMappingURL=random-ihslkInn.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random-ihslkInn.mjs","sources":["../src/utils/random.ts"],"sourcesContent":["/**\n * Generate a random integer between min and max (inclusive)\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Random integer\n * @example randomInt(1, 10) // Random integer from 1 to 10\n */\nconst randomInt = (min: number, max: number): number =>\n\tMath.floor(Math.random() * (max - min + 1)) + min;\n\n/**\n * Generate a random float between min and max\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Random float\n * @example randomFloat(1.0, 10.0) // Random float from 1.0 to 10.0\n */\nconst randomFloat = (min: number, max: number): number =>\n\tMath.random() * (max - min) + min;\n\n/**\n * Get a random item from an array\n * @param items - Array to pick from\n * @returns Random item or undefined if array is empty\n * @example randomItem([1, 2, 3]) // Could return 1, 2, or 3\n */\nconst randomItem = <T>(items: T[]): T | undefined =>\n\titems[Math.floor(Math.random() * items.length)];\n\n/**\n * Get a random key from an object or array\n * @param items - Object or array to pick from\n * @returns Random key or undefined\n * @example randomKey({a: 1, b: 2}) // Could return \"a\" or \"b\"\n */\nconst randomKey = <T>(items: Record<string, T> | T[]): string | undefined =>\n\trandomItem(Object.keys(items));\n\n/**\n * Get a random value from an object or array\n * @param items - Object or array to pick from\n * @returns Random value or undefined\n * @example randomValue({a: 1, b: 2}) // Could return 1 or 2\n */\nconst randomValue = <T>(items: Record<string, T> | T[]): T | undefined =>\n\trandomItem(Array.isArray(items) ? items : Object.values(items));\n\n/**\n * Generate a random boolean value\n * @returns Random true or false\n * @example randomBoolean() // Could return true or false with 50% probability each\n */\nconst randomBoolean = (): boolean => Math.random() < 0.5;\n\n/**\n * Generate a random string of specified length\n * @param length - Length of the string to generate\n * @param characters - Character set to use (string or options object)\n * @returns Random string\n * @example randomString(10) // Random 10-char string with uppercase, lowercase, and numbers\n * @example randomString(5, 'abc') // Random 5-char string using only 'a', 'b', 'c'\n * @example randomString(8, {useUppercase: true, useLowercase: false, useNumeric: false})\n */\nconst randomString = (\n\tlength: number,\n\tcharacters?: string | RandomStringOptions\n): string => {\n\tconst resolveCharactersFromOptions = (options: RandomStringOptions = {}) => {\n\t\t// Default to all character types if none specified\n\t\tconst hasAnyOption =\n\t\t\toptions.useUppercase !== undefined ||\n\t\t\toptions.useLowercase !== undefined ||\n\t\t\toptions.useNumeric !== undefined;\n\n\t\treturn [\n\t\t\t(options.useUppercase ?? !hasAnyOption)\n\t\t\t\t? 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'\n\t\t\t\t: '',\n\t\t\t(options.useLowercase ?? !hasAnyOption)\n\t\t\t\t? 'abcdefghijklmnopqrstuvwxyz'\n\t\t\t\t: '',\n\t\t\t(options.useNumeric ?? !hasAnyOption) ? '0123456789' : '',\n\t\t].join('');\n\t};\n\n\tconst resolvedCharacters =\n\t\ttypeof characters === 'string'\n\t\t\t? characters\n\t\t\t: resolveCharactersFromOptions(characters);\n\n\tif (resolvedCharacters.length === 0 && length > 0) {\n\t\tthrow new Error('Character set cannot be empty');\n\t}\n\n\tif (length <= 0) return '';\n\n\treturn Array.from({ length })\n\t\t.map(() =>\n\t\t\tresolvedCharacters.charAt(randomInt(0, resolvedCharacters.length - 1))\n\t\t)\n\t\t.join('');\n};\n\n/**\n * Generate a random hex string (lowercase)\n * @param length - Length of the hex string (default: 16)\n * @returns Random hex string\n * @example randomHex(8) // \"a3f5c9d1\"\n */\nconst randomHex = (length = 16): string => {\n\treturn randomString(length, '0123456789abcdef');\n};\n\n/**\n * Generate a UUID v4 (random)\n * @returns UUID string\n * @example randomUUID() // \"f47ac10b-58cc-4372-a567-0e02b2c3d479\"\n */\nconst randomUUID = (): string => {\n\treturn 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n\t\tconst r = (Math.random() * 16) | 0;\n\t\tconst v = c === 'x' ? r : (r & 0x3) | 0x8;\n\t\treturn v.toString(16);\n\t});\n};\n\n/**\n * Pick N random items from an array without replacement\n * @param items - Array to sample from\n * @param count - Number of items to pick\n * @returns Array of randomly selected items\n * @example sample([1, 2, 3, 4, 5], 3) // [2, 5, 1]\n */\nconst sample = <T>(items: T[], count: number): T[] => {\n\tif (count > items.length) {\n\t\tthrow new Error(\n\t\t\t`Cannot sample ${count} items from array of length ${items.length}`\n\t\t);\n\t}\n\tif (count <= 0) return [];\n\n\tconst result: T[] = [];\n\tconst copy = [...items];\n\n\tfor (let i = 0; i < count; i++) {\n\t\tconst index = randomInt(0, copy.length - 1);\n\t\tresult.push(copy[index]);\n\t\tcopy.splice(index, 1);\n\t}\n\n\treturn result;\n};\n\n/**\n * Pick a random item with weighted probabilities\n * @param items - Array of items\n * @param weights - Array of weights (must be same length as items)\n * @returns Random item based on weights\n * @example weightedRandom(['a', 'b', 'c'], [1, 2, 3]) // 'c' is 3x more likely than 'a'\n */\nconst weightedRandom = <T>(items: T[], weights: number[]): T | undefined => {\n\tif (items.length === 0) return undefined;\n\tif (items.length !== weights.length) {\n\t\tthrow new Error('Items and weights arrays must have the same length');\n\t}\n\n\tconst totalWeight = weights.reduce((sum, weight) => sum + weight, 0);\n\tif (totalWeight <= 0) {\n\t\tthrow new Error('Total weight must be greater than 0');\n\t}\n\n\tlet random = Math.random() * totalWeight;\n\n\tfor (let i = 0; i < items.length; i++) {\n\t\trandom -= weights[i];\n\t\tif (random <= 0) {\n\t\t\treturn items[i];\n\t\t}\n\t}\n\n\t// Fallback (should never reach here)\n\treturn items[items.length - 1];\n};\n\n/**\n * Get a random enum value\n * @param enumObj - Enum object\n * @returns Random enum value\n * @example enum Color { Red, Green, Blue }; randomEnum(Color) // Color.Green\n */\nconst randomEnum = <T extends Record<string, string | number>>(\n\tenumObj: T\n): T[keyof T] => {\n\t// Filter out numeric keys (reverse mappings in numeric enums)\n\tconst enumValues = Object.keys(enumObj)\n\t\t.filter((key) => Number.isNaN(Number(key)))\n\t\t.map((key) => enumObj[key]);\n\n\treturn randomItem(enumValues as T[keyof T][]) as T[keyof T];\n};\n\n/**\n * Generate a random hex color\n * @returns Random hex color string (e.g., \"#a3f5c9\")\n * @example randomColor() // \"#a3f5c9\"\n */\nconst randomColor = (): string => {\n\treturn `#${randomHex(6)}`;\n};\n\n/**\n * Generate a random date between two dates\n * @param start - Start date\n * @param end - End date\n * @returns Random date between start and end\n * @example randomDate(new Date(2020, 0, 1), new Date(2021, 0, 1))\n */\nconst randomDate = (start: Date, end: Date): Date => {\n\treturn new Date(\n\t\tstart.getTime() + Math.random() * (end.getTime() - start.getTime())\n\t);\n};\n\ntype RandomStringOptions = {\n\tuseNumeric?: boolean;\n\tuseLowercase?: boolean;\n\tuseUppercase?: boolean;\n};\n\nexport {\n\trandomInt,\n\trandomFloat,\n\trandomItem,\n\trandomKey,\n\trandomValue,\n\trandomBoolean,\n\trandomString,\n\trandomHex,\n\trandomUUID,\n\tsample,\n\tweightedRandom,\n\trandomEnum,\n\trandomColor,\n\trandomDate,\n\ttype RandomStringOptions,\n};\n"],"names":["randomInt","__name","min","max","randomFloat","randomItem","items","randomKey","randomValue","randomBoolean","randomString","length","characters","resolvedCharacters","options","hasAnyOption","randomHex","randomUUID","c","r","sample","count","result","copy","i","index","weightedRandom","weights","totalWeight","sum","weight","random","randomEnum","enumObj","enumValues","key","randomColor","randomDate","start","end"],"mappings":"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"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sleep for a specified number of milliseconds
|
|
3
|
+
* @param ms - Milliseconds to sleep
|
|
4
|
+
* @returns Promise that resolves after the specified time
|
|
5
|
+
* @example await sleep(1000) // Sleep for 1 second
|
|
6
|
+
*/
|
|
7
|
+
declare const sleep: (ms: number) => Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Sleep until a condition becomes true
|
|
10
|
+
* @param condition - Function that returns true when ready to continue
|
|
11
|
+
* @param interval - How often to check the condition in ms (default: 1000)
|
|
12
|
+
* @returns Promise that resolves when condition is true
|
|
13
|
+
* @example await sleepUntil(() => dataLoaded, 500)
|
|
14
|
+
*/
|
|
15
|
+
declare const sleepUntil: (condition: () => boolean | Promise<boolean>, interval?: number) => Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Sleep until a condition becomes true or timeout is reached
|
|
18
|
+
* @param condition - Function that returns true when ready to continue
|
|
19
|
+
* @param timeout - Maximum time to wait in ms
|
|
20
|
+
* @param interval - How often to check the condition in ms (default: 1000)
|
|
21
|
+
* @returns Promise that resolves when condition is true or timeout is reached
|
|
22
|
+
* @example await sleepUntilOrTimeout(() => dataLoaded, 5000, 500)
|
|
23
|
+
*/
|
|
24
|
+
declare const sleepUntilOrTimeout: (condition: () => boolean | Promise<boolean>, timeout: number, interval?: number) => Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Race a promise against a timeout
|
|
27
|
+
* @param promise - Promise to await
|
|
28
|
+
* @param timeout - Timeout in milliseconds
|
|
29
|
+
* @returns Promise that resolves with the value or rejects on timeout
|
|
30
|
+
* @example await awaitOrTimeout(fetchData(), 5000)
|
|
31
|
+
*/
|
|
32
|
+
declare const awaitOrTimeout: <T>(promise: Promise<T>, timeout: number) => Promise<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Safely set a timeout that handles values larger than INT32_MAX
|
|
35
|
+
* @param timeoutMs - Timeout in milliseconds
|
|
36
|
+
* @param scheduleOverflowInFuture - Whether to schedule overflow timeouts automatically
|
|
37
|
+
* @param fn - Function to execute
|
|
38
|
+
* @param onNewTimeout - Callback when a new timeout is scheduled
|
|
39
|
+
* @returns Timeout handle
|
|
40
|
+
* @example safeSetTimeout(2147483648, true, () => console.log('Done'))
|
|
41
|
+
*/
|
|
42
|
+
declare const safeSetTimeout: (timeoutMs: number, scheduleOverflowInFuture: boolean, fn: () => void, onNewTimeout?: (timeout: NodeJS.Timeout, isTimeoutForRunFn: boolean) => void) => NodeJS.Timeout;
|
|
43
|
+
/**
|
|
44
|
+
* Safely set an interval that handles values larger than INT32_MAX
|
|
45
|
+
* @param intervalMs - Interval in milliseconds
|
|
46
|
+
* @param fn - Function to execute
|
|
47
|
+
* @param onNewTimeout - Callback when a new timeout is scheduled
|
|
48
|
+
* @returns Timeout handle
|
|
49
|
+
* @example safeSetInterval(2147483648, () => console.log('Tick'))
|
|
50
|
+
*/
|
|
51
|
+
declare const safeSetInterval: (intervalMs: number, fn: () => void, onNewTimeout?: (timeout: NodeJS.Timeout, isTimeoutForRunFn: boolean) => void) => NodeJS.Timeout;
|
|
52
|
+
/**
|
|
53
|
+
* Safely set an async interval that handles values larger than INT32_MAX
|
|
54
|
+
* @param intervalMs - Interval in milliseconds
|
|
55
|
+
* @param fn - Async function to execute
|
|
56
|
+
* @param onNewTimeout - Callback when a new timeout is scheduled
|
|
57
|
+
* @returns Timeout handle
|
|
58
|
+
* @example safeSetAsyncInterval(2147483648, async () => await doWork())
|
|
59
|
+
*/
|
|
60
|
+
declare const safeSetAsyncInterval: (intervalMs: number, fn: () => Promise<void>, onNewTimeout?: (timeout: NodeJS.Timeout, isTimeoutForRunFn: boolean) => void) => NodeJS.Timeout;
|
|
61
|
+
/**
|
|
62
|
+
* Result of a batch operation
|
|
63
|
+
*/
|
|
64
|
+
type BatchResult<T> = {
|
|
65
|
+
/** Successfully processed results */
|
|
66
|
+
results: T[];
|
|
67
|
+
/** Errors that occurred during processing */
|
|
68
|
+
errors: Array<{
|
|
69
|
+
index: number;
|
|
70
|
+
error: Error;
|
|
71
|
+
}>;
|
|
72
|
+
/** Total number of tasks */
|
|
73
|
+
total: number;
|
|
74
|
+
/** Number of successful tasks */
|
|
75
|
+
successful: number;
|
|
76
|
+
/** Number of failed tasks */
|
|
77
|
+
failed: number;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Options for batch processing
|
|
81
|
+
*/
|
|
82
|
+
interface BatchProcessOptions {
|
|
83
|
+
/** Maximum number of concurrent executions (default: 5) */
|
|
84
|
+
concurrency?: number;
|
|
85
|
+
/** Whether to stop on first error (default: false) */
|
|
86
|
+
stopOnError?: boolean;
|
|
87
|
+
/** Timeout per task in milliseconds (default: none) */
|
|
88
|
+
taskTimeout?: number;
|
|
89
|
+
/** Delay between batches in milliseconds (default: 0) */
|
|
90
|
+
batchDelay?: number;
|
|
91
|
+
/** Callback for progress updates */
|
|
92
|
+
onProgress?: (completed: number, total: number) => void;
|
|
93
|
+
/** Callback for each error */
|
|
94
|
+
onError?: (error: Error, index: number) => void;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Options for batch processing with retry
|
|
98
|
+
*/
|
|
99
|
+
interface BatchProcessWithRetryOptions extends BatchProcessOptions {
|
|
100
|
+
/** Maximum number of retry attempts (default: 3) */
|
|
101
|
+
maxRetries?: number;
|
|
102
|
+
/** Delay between retries in milliseconds (default: 1000) */
|
|
103
|
+
retryDelay?: number;
|
|
104
|
+
/** Backoff multiplier for retry delay (default: 2) */
|
|
105
|
+
retryBackoff?: number;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Execute async tasks with controlled concurrency
|
|
109
|
+
* @param tasks - Array of async functions to execute
|
|
110
|
+
* @param concurrency - Maximum number of concurrent executions (default: 5)
|
|
111
|
+
* @returns Array of results in the same order as input tasks
|
|
112
|
+
* @throws Error if any task fails (use batchProcess for error handling)
|
|
113
|
+
* @example
|
|
114
|
+
* const results = await executeWithConcurrency(
|
|
115
|
+
* urls.map(url => () => fetch(url)),
|
|
116
|
+
* 3
|
|
117
|
+
* );
|
|
118
|
+
*/
|
|
119
|
+
declare function executeWithConcurrency<T>(tasks: (() => Promise<T>)[], concurrency?: number): Promise<T[]>;
|
|
120
|
+
/**
|
|
121
|
+
* Process tasks in batches with advanced error handling and progress tracking
|
|
122
|
+
* @param tasks - Array of async functions to execute
|
|
123
|
+
* @param options - Batch processing options
|
|
124
|
+
* @returns BatchResult with results and error information
|
|
125
|
+
* @example
|
|
126
|
+
* const result = await batchProcess(
|
|
127
|
+
* urls.map(url => () => fetchData(url)),
|
|
128
|
+
* {
|
|
129
|
+
* concurrency: 3,
|
|
130
|
+
* stopOnError: false,
|
|
131
|
+
* onProgress: (done, total) => console.log(`${done}/${total}`)
|
|
132
|
+
* }
|
|
133
|
+
* );
|
|
134
|
+
*/
|
|
135
|
+
declare function batchProcess<T>(tasks: (() => Promise<T>)[], options?: BatchProcessOptions): Promise<BatchResult<T>>;
|
|
136
|
+
/**
|
|
137
|
+
* Map over an array with controlled concurrency
|
|
138
|
+
* @param items - Array of items to process
|
|
139
|
+
* @param mapper - Async function to transform each item
|
|
140
|
+
* @param concurrency - Maximum number of concurrent executions (default: 5)
|
|
141
|
+
* @returns Array of transformed results in the same order
|
|
142
|
+
* @throws Error if any transformation fails
|
|
143
|
+
* @example
|
|
144
|
+
* const users = await batchMap(
|
|
145
|
+
* userIds,
|
|
146
|
+
* async (id) => await fetchUser(id),
|
|
147
|
+
* 3
|
|
148
|
+
* );
|
|
149
|
+
*/
|
|
150
|
+
declare function batchMap<T, R>(items: T[], mapper: (item: T, index: number) => Promise<R>, concurrency?: number): Promise<R[]>;
|
|
151
|
+
/**
|
|
152
|
+
* Map over an array with controlled concurrency and retry logic
|
|
153
|
+
* @param items - Array of items to process
|
|
154
|
+
* @param mapper - Async function to transform each item
|
|
155
|
+
* @param options - Batch processing options with retry configuration
|
|
156
|
+
* @returns BatchResult with results and error information
|
|
157
|
+
* @example
|
|
158
|
+
* const result = await batchMapWithRetry(
|
|
159
|
+
* userIds,
|
|
160
|
+
* async (id) => await fetchUser(id),
|
|
161
|
+
* {
|
|
162
|
+
* concurrency: 3,
|
|
163
|
+
* maxRetries: 3,
|
|
164
|
+
* retryDelay: 1000,
|
|
165
|
+
* stopOnError: false
|
|
166
|
+
* }
|
|
167
|
+
* );
|
|
168
|
+
*/
|
|
169
|
+
declare function batchMapWithRetry<T, R>(items: T[], mapper: (item: T, index: number) => Promise<R>, options?: BatchProcessWithRetryOptions): Promise<BatchResult<R>>;
|
|
170
|
+
/**
|
|
171
|
+
* Process items in chunks/batches sequentially
|
|
172
|
+
* @param items - Array of items to process
|
|
173
|
+
* @param batchSize - Number of items per batch
|
|
174
|
+
* @param processor - Function to process each batch
|
|
175
|
+
* @returns Array of batch results
|
|
176
|
+
* @example
|
|
177
|
+
* const results = await processBatches(
|
|
178
|
+
* allUsers,
|
|
179
|
+
* 100,
|
|
180
|
+
* async (batch) => await bulkInsert(batch)
|
|
181
|
+
* );
|
|
182
|
+
*/
|
|
183
|
+
declare function processBatches<T, R>(items: T[], batchSize: number, processor: (batch: T[], batchIndex: number) => Promise<R>): Promise<R[]>;
|
|
184
|
+
|
|
185
|
+
type runtime_BatchProcessOptions = BatchProcessOptions;
|
|
186
|
+
type runtime_BatchProcessWithRetryOptions = BatchProcessWithRetryOptions;
|
|
187
|
+
type runtime_BatchResult<T> = BatchResult<T>;
|
|
188
|
+
declare const runtime_awaitOrTimeout: typeof awaitOrTimeout;
|
|
189
|
+
declare const runtime_batchMap: typeof batchMap;
|
|
190
|
+
declare const runtime_batchMapWithRetry: typeof batchMapWithRetry;
|
|
191
|
+
declare const runtime_batchProcess: typeof batchProcess;
|
|
192
|
+
declare const runtime_executeWithConcurrency: typeof executeWithConcurrency;
|
|
193
|
+
declare const runtime_processBatches: typeof processBatches;
|
|
194
|
+
declare const runtime_safeSetAsyncInterval: typeof safeSetAsyncInterval;
|
|
195
|
+
declare const runtime_safeSetInterval: typeof safeSetInterval;
|
|
196
|
+
declare const runtime_safeSetTimeout: typeof safeSetTimeout;
|
|
197
|
+
declare const runtime_sleep: typeof sleep;
|
|
198
|
+
declare const runtime_sleepUntil: typeof sleepUntil;
|
|
199
|
+
declare const runtime_sleepUntilOrTimeout: typeof sleepUntilOrTimeout;
|
|
200
|
+
declare namespace runtime {
|
|
201
|
+
export { runtime_awaitOrTimeout as awaitOrTimeout, runtime_batchMap as batchMap, runtime_batchMapWithRetry as batchMapWithRetry, runtime_batchProcess as batchProcess, runtime_executeWithConcurrency as executeWithConcurrency, runtime_processBatches as processBatches, runtime_safeSetAsyncInterval as safeSetAsyncInterval, runtime_safeSetInterval as safeSetInterval, runtime_safeSetTimeout as safeSetTimeout, runtime_sleep as sleep, runtime_sleepUntil as sleepUntil, runtime_sleepUntilOrTimeout as sleepUntilOrTimeout };
|
|
202
|
+
export type { runtime_BatchProcessOptions as BatchProcessOptions, runtime_BatchProcessWithRetryOptions as BatchProcessWithRetryOptions, runtime_BatchResult as BatchResult };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export { sleepUntil as a, sleepUntilOrTimeout as b, awaitOrTimeout as c, safeSetTimeout as d, safeSetInterval as e, safeSetAsyncInterval as f, executeWithConcurrency as g, batchProcess as h, batchMap as i, batchMapWithRetry as j, processBatches as p, runtime as r, sleep as s };
|
|
206
|
+
export type { BatchResult as B, BatchProcessOptions as k, BatchProcessWithRetryOptions as l };
|