grofc_utils 1.0.0

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/src/random.js ADDED
@@ -0,0 +1,372 @@
1
+ import {
2
+ throwIfIsNotIterable,
3
+ throwIfIsNotFiniteNumber,
4
+ throwIfIsNotNonNegativeFiniteNumber,
5
+ throwIfIsNotPositiveFiniteNumber,
6
+ throwIfIsNotNonNegativeInteger,
7
+ throwIfIsNotNonNegativeIntegerArray,
8
+ throwIfIsNotFunction,
9
+ throwIfIsNullishValue
10
+ } from "./guard.js";
11
+
12
+ /**
13
+ * 本函数用于生成指定范围内的随机整数。包含边界。
14
+ * @param {number} a
15
+ * @param {number} b
16
+ * @returns {number} 属于 [min,max]
17
+ */
18
+ export function randomInt(a, b) {
19
+ a = Number(a), b = Number(b);
20
+ throwIfIsNotFiniteNumber(a, "a");
21
+ throwIfIsNotFiniteNumber(b, "b");
22
+ const [l, r] = a > b ? [b, a] : [a, b];
23
+ return Math.floor(Math.random() * (r - l + 1)) + l;
24
+ }
25
+
26
+ /**
27
+ * 本函数用于生成指定范围内的随机整数数组。
28
+ * @param {number} len
29
+ * @param {Iterable<number>} range 默认为[0,100]
30
+ * @returns {number[]} 每个元素属于[min,max]
31
+ */
32
+ export function randomInts(len, range = [0, 100]) {
33
+ throwIfIsNotNonNegativeInteger(len, "len");
34
+ throwIfIsNotIterable(range, "range");
35
+ const [a, b] = range;
36
+ return Array.from({ length: len }, () => randomInt(a, b));
37
+ }
38
+ /**
39
+ * 本函数用于生成指定范围内的随机浮点数。
40
+ * @param {number} a
41
+ * @param {number} b
42
+ * @returns {number} 属于 [min,max)
43
+ */
44
+ export function randomFloat(a, b) {
45
+ a = Number(a), b = Number(b);
46
+ throwIfIsNotFiniteNumber(a, "a");
47
+ throwIfIsNotFiniteNumber(b, "b");
48
+ const [l, r] = a > b ? [b, a] : [a, b];
49
+ return Math.random() * (r - l) + l;
50
+ }
51
+ /**
52
+ * 本函数用于生成指定范围内的随机浮点数数组。
53
+ * @param {number} len
54
+ * @param {Iterable<number>} range 默认为[0,1]
55
+ * @returns {number[]} 每个元素属于[min,max)
56
+ */
57
+ export function randomFloats(len, range = [0, 1]) {
58
+ throwIfIsNotNonNegativeInteger(len, "len");
59
+ throwIfIsNotIterable(range, "range");
60
+ const [a, b] = range;
61
+ return Array.from({ length: len }, () => randomFloat(a, b));
62
+ }
63
+ /**
64
+ * 利用box-muller变换生成标准正态分布随机数
65
+ * @returns {number} 服从标准正态分布的随机数
66
+ */
67
+ export function randomGaussian() {
68
+ const u = Math.random(), v = Math.random();
69
+ const mod = Math.sqrt(-2.0 * Math.log(u));
70
+ const arg = 2.0 * Math.PI * v;
71
+ return mod * Math.cos(arg);
72
+ }
73
+ /**
74
+ * 生成标准正态分布随机数数组
75
+ * @param {number} len 数组长度
76
+ * @param {()=>number} generator 标准正态分布随机数生成器
77
+ * @returns
78
+ */
79
+ export function randomGaussians(len, generator = randomGaussian) {
80
+ throwIfIsNotNonNegativeInteger(len, "len");
81
+ throwIfIsNotFunction(generator, "generator");
82
+ return Array.from({ length: len }, () => generator());
83
+ }
84
+ /**
85
+ * 生成指定均值和标准差的正态分布随机数
86
+ * @param {number} mu 正态分布的均值
87
+ * @param {number} sigma 正态分布的标准差
88
+ * @param {()=>number} generator 标准正态分布随机数生成器
89
+ * @returns
90
+ */
91
+ export function randomNormal(mu = 0, sigma = 1, generator = randomGaussian) {
92
+ throwIfIsNotFiniteNumber(mu, "mu");
93
+ throwIfIsNotPositiveFiniteNumber(sigma, "sigma");
94
+ throwIfIsNotFunction(generator, "generator");
95
+ return mu + sigma * generator();
96
+ }
97
+ /**
98
+ * 生成指定均值和标准差的正态分布随机数数组
99
+ * @param {number} len 数组长度
100
+ * @param {number} mu 正态分布的均值
101
+ * @param {number} sigma 正态分布的标准差
102
+ * @param {()=>number} generator 标准正态分布随机数生成器
103
+ * @returns {number[]}
104
+ */
105
+ export function randomNormals(len, mu = 0, sigma = 1, generator = randomGaussian) {
106
+ throwIfIsNotNonNegativeInteger(len, "len");
107
+ return Array.from({ length: len }, () => randomNormal(mu, sigma, generator));
108
+ }
109
+ /**
110
+ * 生成指定维度和模长的随机向量
111
+ * @param {number} dim 生成向量的维度
112
+ * @param {number} mod 生成向量的模长
113
+ * @param {()=>number} generator 标准正态分布随机数生成器
114
+ * @returns {number[]}
115
+ */
116
+ export function randomVector(dim = 2, mod = 1, generator = randomGaussian) {
117
+ throwIfIsNotPositiveFiniteNumber(dim, "dim");
118
+ throwIfIsNotNonNegativeFiniteNumber(mod, "mod");
119
+ throwIfIsNotFunction(generator, "generator");
120
+ if (mod === 0) return Array.from({ length: dim }, () => 0);
121
+ const MAX_ATTEMPTS = 10, EPSILON_SQ = 1e-24;
122
+ for (let i = 0; i < MAX_ATTEMPTS; i++) {
123
+ const vec = Array.from({ length: dim }, () => generator());
124
+ const squaredLength = vec.reduce((acc, val) => acc + val * val, 0);
125
+ if (squaredLength > EPSILON_SQ) {
126
+ const length = Math.sqrt(squaredLength);
127
+ return vec.map(v => v / length * mod);
128
+ }
129
+ }
130
+ throw new Error(
131
+ `Failed to generate non-zero random vector after ${MAX_ATTEMPTS} attempts. Check your generator function.`
132
+ )
133
+ }
134
+ /**
135
+ * 生成指定数量的随机向量数组
136
+ * @param {number} len 需要生成的向量数量
137
+ * @param {number} dim 向量的维度,默认为2
138
+ * @param {number} mod 向量的模长,默认为1
139
+ * @param {()=>number} generator 随机数生成器函数,默认为randomGaussian
140
+ * @returns {number[][]} 包含len个随机向量的数组,每个向量都是指定维度和模长的数组
141
+ */
142
+ export function randomVectors(len, dim = 2, mod = 1, generator = randomGaussian) {
143
+ throwIfIsNotNonNegativeInteger(len, "len");
144
+ return Array.from({ length: len }, () => randomVector(dim, mod, generator));
145
+ }
146
+
147
+ /**
148
+ * 生成一个指定行列数的随机矩阵
149
+ * @param {number} rows 矩阵的行数,默认为2
150
+ * @param {number} cols 矩阵的列数,默认等于行数
151
+ * @param {(r: number, c: number) => number} generator 用于生成矩阵元素的函数,接收行列索引作为参数,默认生成0-10的随机整数
152
+ * @returns {number[][]} 二维数组表示的矩阵,大小为rows×cols
153
+ */
154
+ export function randomMatrix(rows = 2, cols = rows, generator = (_r, _c) => randomInt(0, 10)) {
155
+ throwIfIsNotNonNegativeInteger(rows, "rows");
156
+ throwIfIsNotNonNegativeInteger(cols, "cols");
157
+ throwIfIsNotFunction(generator, "generator");
158
+ return Array.from({ length: rows }, (_v, r) => Array.from({ length: cols }, (_w, c) => generator(r, c)));
159
+ }
160
+
161
+ /**
162
+ * 生成指定数量的随机矩阵数组
163
+ * @param {number} len 需要生成的矩阵数量
164
+ * @param {number} rows 每个矩阵的行数
165
+ * @param {number} cols 每个矩阵的列数,默认等于行数
166
+ * @param {(r: number, c: number) => number} generator 用于生成矩阵元素的函数,接收行列索引作为参数,默认生成0-10的随机整数
167
+ * @returns {number[][][]} 包含len个矩阵的数组,每个矩阵都是二维数组
168
+ */
169
+ export function randomMatrices(len, rows = 2, cols = rows, generator = (_r, _c) => randomInt(0, 10)) {
170
+ throwIfIsNotNonNegativeInteger(len, "len");
171
+ return Array.from({ length: len }, () => randomMatrix(rows, cols, generator))
172
+ }
173
+
174
+ /**
175
+ * 传入高斯随机数生成器,并生成对应的函数对象
176
+ * @param {()=>number} generator
177
+ * @returns {{
178
+ * randomGaussian: ()=>number,
179
+ * randomGaussians: (len:number)=>number[],
180
+ * randomNormal: (mu:number,sigma:number)=>number,
181
+ * randomNormals: (len:number,mu:number,sigma:number)=>number[],
182
+ * randomVector: (dim:number,mod:number)=>number[]
183
+ * }}
184
+ */
185
+ export function withGaussianGenerator(generator) {
186
+ if (typeof generator !== "function") throw TypeError("generator must be a function that returns a standard normal random number.")
187
+ return {
188
+ randomGaussian: () => generator(),
189
+ randomGaussians: (len) => randomGaussians(len, generator),
190
+ randomNormal: (mu, sigma) => randomNormal(mu, sigma, generator),
191
+ randomNormals: (len, mu, sigma) => randomNormals(len, mu, sigma, generator),
192
+ randomVector: (dim, mod) => randomVector(dim, mod, generator),
193
+ randomVectors: (len, dim, mod) => randomVectors(len, dim, mod, generator)
194
+ }
195
+ }
196
+
197
+ /**
198
+ * 传入矩阵元素生成器,并生成对应的矩阵操作函数对象
199
+ * @param {(r: number, c: number) => number} generator 用于生成矩阵元素的函数,接收行列索引作为参数
200
+ * @returns {{
201
+ * randomMatrix: (rows: number, cols: number) => number[][],
202
+ * randomMatrices: (len: number, rows: number, cols: number) => number[][][]
203
+ * }} 返回包含随机矩阵生成函数的对象
204
+ */
205
+ export function withMatrixGenerator(generator) {
206
+ return {
207
+ randomMatrix: (rows, cols) => randomMatrix(rows, cols, generator),
208
+ randomMatrices: (len, rows, cols) => randomMatrices(len, rows, cols, generator)
209
+ }
210
+ }
211
+
212
+ export function randomColor() {
213
+ return "#" + randomInt(0, 0x100000000 - 1).toString(16).slice(2, 8)
214
+ }
215
+ export function randomColors(len) {
216
+ throwIfIsNotPositiveFiniteNumber(len, "len")
217
+ return Array.from({ length: len }, randomColor)
218
+ }
219
+
220
+ /**
221
+ * @template T
222
+ * @param {Iterable<T>} inputFlow
223
+ * @returns {T[]}
224
+ */
225
+ export function randomSort(inputFlow) {
226
+ throwIfIsNotIterable(inputFlow, "inputFlow");
227
+ const result = Array.from(inputFlow);
228
+ let lastIndex = result.length - 1;
229
+ while (lastIndex > 0) {
230
+ const randomIndex = randomInt(0, lastIndex)
231
+ const temp = result[randomIndex];
232
+ result[randomIndex] = result[lastIndex];
233
+ result[lastIndex] = temp;
234
+ lastIndex--;
235
+ }
236
+ return result;
237
+ }
238
+
239
+ export const shuffle = randomSort;
240
+
241
+ /**
242
+ * 简单随机选取一个样本
243
+ * @template T
244
+ * @param {Iterable<T>} inputFlow
245
+ * @returns {T}
246
+ */
247
+ export function randomPick(inputFlow) {
248
+ throwIfIsNotIterable(inputFlow, "inputFlow");
249
+ const dataList = Array.from(inputFlow);
250
+ return dataList[randomInt(0, dataList.length - 1)]
251
+ }
252
+
253
+ /**
254
+ * 简单放回抽样
255
+ * @template T
256
+ * @param {Iterable<T>} inputList
257
+ * @param {number} len
258
+ * @returns {T[]}
259
+ */
260
+ export function randomPicks(inputList, len) {
261
+ throwIfIsNotNonNegativeInteger(len, "len");
262
+ if (typeof inputList?.[Symbol.iterator] !== 'function') throw new TypeError("inputList must be an iterable.");
263
+ const dataList = Array.from(inputList);
264
+ return dataList.length ? Array.from({ length: len }, () => dataList[randomInt(0, dataList.length - 1)]) :
265
+ Array.from({ length: len })
266
+ }
267
+ /**
268
+ * 带权重的随机选取一个样本
269
+ * @template T
270
+ * @param {Map<T,number>} inputMap
271
+ * @returns {T}
272
+ */
273
+ export function randomChoice(inputMap) {
274
+ throwIfIsNullishValue(inputMap, "inputMap");
275
+ if (!(inputMap instanceof Map)) {
276
+ inputMap = new Map(Object.entries(inputMap));
277
+ }
278
+ const samples = [];
279
+ const weights = [];
280
+ for (const [k, v] of inputMap) {
281
+ samples.push(k);
282
+ weights.push(Number(v));
283
+ }
284
+ throwIfIsNotNonNegativeIntegerArray(weights, "weights", "all weights")
285
+ const cum_weights = weights.slice();
286
+ for (let i = 1; i < cum_weights.length; i++) {
287
+ cum_weights[i] += cum_weights[i - 1];
288
+ }
289
+ const totalWeight = cum_weights[cum_weights.length - 1];
290
+ if (totalWeight === 0) {
291
+ throw new RangeError("At least one weight must be positive.");
292
+ }
293
+ const r = randomFloat(0, totalWeight);
294
+ let left = 0, right = cum_weights.length;
295
+ while (left < right) {
296
+ const mid = Math.floor((left + right) / 2);
297
+ if (r > cum_weights[mid]) {
298
+ left = mid + 1;
299
+ } else {
300
+ right = mid;
301
+ }
302
+ }
303
+ return samples[left];
304
+ }
305
+
306
+ /**
307
+ * 带权重的放回抽样
308
+ * @template T
309
+ * @param {Map<T,number>} inputMap
310
+ * @param {number} len
311
+ * @returns {T[]}
312
+ */
313
+ export function randomChoices(inputMap, len) {
314
+ throwIfIsNotNonNegativeInteger(len, "len");
315
+ throwIfIsNullishValue(inputMap, "inputMap");
316
+ if (!(inputMap instanceof Map)) {
317
+ inputMap = new Map(Object.entries(inputMap));
318
+ }
319
+ const samples = [];
320
+ const weights = [];
321
+ for (const [k, v] of inputMap) {
322
+ samples.push(k);
323
+ weights.push(Number(v));
324
+ }
325
+ throwIfIsNotNonNegativeIntegerArray(weights, "weights", "all weights")
326
+ const cum_weights = weights.slice();
327
+ for (let i = 1; i < cum_weights.length; i++) {
328
+ cum_weights[i] += cum_weights[i - 1];
329
+ }
330
+ const totalWeight = cum_weights[cum_weights.length - 1];
331
+ if (totalWeight === 0) {
332
+ throw new RangeError("At least one weight must be positive.");
333
+ }
334
+ const result = [];
335
+ for (let i = 0; i < len; i++) {
336
+ const r = randomFloat(0, totalWeight);
337
+ let left = 0, right = cum_weights.length;
338
+ while (left < right) {
339
+ const mid = Math.floor((left + right) / 2);
340
+ if (r > cum_weights[mid]) {
341
+ left = mid + 1;
342
+ } else {
343
+ right = mid;
344
+ }
345
+ }
346
+ result.push(samples[left]);
347
+ }
348
+ return result;
349
+ }
350
+
351
+ /**
352
+ * 随机抽取样本,由于采用了蓄水池抽样,数据输出的顺序与原顺序相关联
353
+ * @template T
354
+ * @param {Iterable<T>} inputFlow
355
+ * @param {number} len
356
+ * @returns {T[]}
357
+ */
358
+ export function randomSample(inputFlow, len) {
359
+ throwIfIsNotNonNegativeInteger(len, "len");
360
+ throwIfIsNotIterable(inputFlow, "inputFlow");
361
+ const result = [];
362
+ let index = 0;
363
+ for (const input of inputFlow) {
364
+ if (index < len) result.push(input);
365
+ else {
366
+ const r = randomInt(0, index);
367
+ if (r < len) result[r] = input;
368
+ }
369
+ index++;
370
+ }
371
+ return result
372
+ }
package/src/string.js ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * 将字符串按照指定步长进行分块处理
3
+ * @param {string} input - 需要分块的输入字符串
4
+ * @param {number} step - 分块步长,必须为非零整数。正数表示从左到右分块,负数表示从右到左分块
5
+ * @returns {string[]} 返回分块后的字符串数组
6
+ * @throws {TypeError} 当input不是字符串或step不是整数时抛出
7
+ * @throws {RangeError} 当step为0时抛出
8
+ */
9
+ export function chunkString(input, step) {
10
+ if (typeof input !== "string") throw new TypeError(`${input} must be string.`);
11
+ if (!Number.isInteger(step)) throw new TypeError(`${step} must be an integer.`);
12
+ if (step === 0) throw new RangeError(`step must not be zero.`);
13
+ const result = [];
14
+ if (step > 0) {
15
+ for (let i = 0; i < input.length; i += step) {
16
+ result.push(input.slice(i, i + step));
17
+ }
18
+ } else if (step < 0) {
19
+ for (let i = input.length; i > 0; i += step) {
20
+ result.push(input.slice(Math.max(0, i + step), i));
21
+ }
22
+ }
23
+ return result;
24
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,112 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig to read more about this file */
4
+
5
+ /* Projects */
6
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
+
13
+ /* Language and Environment */
14
+ "target": "es2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
17
+ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
18
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
+
27
+ /* Modules */
28
+ "module": "commonjs", /* Specify what module code is generated. */
29
+ // "rootDir": "./", /* Specify the root folder within your source files. */
30
+ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
31
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38
+ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
39
+ // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
40
+ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
41
+ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
42
+ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
43
+ // "noUncheckedSideEffectImports": true, /* Check side effect imports. */
44
+ // "resolveJsonModule": true, /* Enable importing .json files. */
45
+ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
46
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
47
+
48
+ /* JavaScript Support */
49
+ "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
50
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
51
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
52
+
53
+ /* Emit */
54
+ "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
55
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
56
+ "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
57
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
58
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
59
+ // "noEmit": true, /* Disable emitting files from a compilation. */
60
+ // "outFile": "", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
61
+ "outDir": "./types", /* Specify an output folder for all emitted files. */
62
+ // "removeComments": true, /* Disable emitting comments. */
63
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
64
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
65
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
66
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
67
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
68
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
69
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
70
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
71
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
72
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
73
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
74
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
75
+
76
+ /* Interop Constraints */
77
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
78
+ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
79
+ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
80
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
81
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
82
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
83
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
84
+
85
+ /* Type Checking */
86
+ "strict": true, /* Enable all strict type-checking options. */
87
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
88
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
89
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
90
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
91
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
92
+ // "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
93
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
94
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
95
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
96
+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
97
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
98
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
99
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
100
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
101
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
102
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
103
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
104
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
105
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
106
+
107
+ /* Completeness */
108
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
109
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
110
+ },
111
+ "exclude": ["./src","types","./generate.exports.js"]
112
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./src/array.js";
2
+ export * from "./src/guard.js";
3
+ export * from "./src/missingData.js";
4
+ export * from "./src/random.js";
5
+ export * from "./src/string.js";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @template T
3
+ * @param {T[]} input
4
+ * @param {number} step
5
+ * @returns {T[][]}
6
+ */
7
+ export function chunk<T>(input: T[], step: number): T[][];