@aidc-toolkit/utility 0.9.8-beta → 0.9.10-beta
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/LICENSE +0 -27
- package/README.md +14 -0
- package/dist/index.cjs +95 -74
- package/dist/index.d.cts +71 -550
- package/dist/index.d.ts +71 -550
- package/dist/index.js +91 -70
- package/package.json +7 -8
- package/src/character-set.ts +1 -1
- package/src/index.ts +17 -1
- package/src/locale/en/locale-strings.ts +2 -2
- package/src/locale/fr/locale-strings.ts +2 -2
- package/src/locale/i18n.ts +3 -2
- package/src/{sequencer.ts → sequence.ts} +12 -12
- package/src/transformer.ts +102 -99
- package/test/character-set.test.ts +4 -4
- package/test/{sequencer.test.ts → sequence.test.ts} +16 -16
- package/test/transformer.test.ts +20 -21
package/LICENSE
CHANGED
|
@@ -172,30 +172,3 @@
|
|
|
172
172
|
defend, and hold each Contributor harmless for any liability
|
|
173
173
|
incurred by, or claims asserted against, such Contributor by reason
|
|
174
174
|
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright © 2024 Dolphin Data Development Ltd.
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# Utility Package
|
|
2
|
+
|
|
3
|
+
**Copyright © 2024-2025 Dolphin Data Development Ltd. and AIDC Toolkit contributors**
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
|
|
6
|
+
License. You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
|
|
11
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
1
15
|
⚠️ **This software is in beta**, with production release is scheduled for 2024Q4. To follow the status of that and other
|
|
2
16
|
projects, go to the AIDC Toolkit [projects](https://github.com/orgs/aidc-toolkit/projects) page.
|
|
3
17
|
|
package/dist/index.cjs
CHANGED
|
@@ -28,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
33
|
ALPHABETIC_CREATOR: () => ALPHABETIC_CREATOR,
|
|
34
34
|
ALPHANUMERIC_CREATOR: () => ALPHANUMERIC_CREATOR,
|
|
35
35
|
CharacterSetCreator: () => CharacterSetCreator,
|
|
@@ -41,7 +41,7 @@ __export(src_exports, {
|
|
|
41
41
|
NUMERIC_CREATOR: () => NUMERIC_CREATOR,
|
|
42
42
|
RecordValidator: () => RecordValidator,
|
|
43
43
|
RegExpValidator: () => RegExpValidator,
|
|
44
|
-
|
|
44
|
+
Sequence: () => Sequence,
|
|
45
45
|
Transformer: () => Transformer,
|
|
46
46
|
i18nUtilityInit: () => i18nUtilityInit,
|
|
47
47
|
i18nextUtility: () => i18nextUtility,
|
|
@@ -49,7 +49,7 @@ __export(src_exports, {
|
|
|
49
49
|
utilityNS: () => utilityNS,
|
|
50
50
|
utilityResources: () => utilityResources
|
|
51
51
|
});
|
|
52
|
-
module.exports = __toCommonJS(
|
|
52
|
+
module.exports = __toCommonJS(index_exports);
|
|
53
53
|
|
|
54
54
|
// src/locale/i18n.ts
|
|
55
55
|
var import_core = require("@aidc-toolkit/core");
|
|
@@ -62,8 +62,8 @@ var localeStrings = {
|
|
|
62
62
|
tweakMustBeGreaterThanOrEqualToZero: "Tweak {{tweak}} must be greater than or equal to 0",
|
|
63
63
|
valueMustBeGreaterThanOrEqualToZero: "Value {{value}} must be greater than or equal to 0",
|
|
64
64
|
valueMustBeLessThan: "Value {{value}} must be less than {{domain}}",
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
minimumValueMustBeGreaterThanOrEqualToZero: "Minimum value {{minimumValue}} must be greater than or equal to 0",
|
|
66
|
+
maximumValueMustBeLessThan: "Maximum value {{maximumValue}} must be less than {{domain}}"
|
|
67
67
|
},
|
|
68
68
|
RegExpValidator: {
|
|
69
69
|
stringDoesNotMatchPattern: "String {{s}} does not match pattern"
|
|
@@ -96,8 +96,8 @@ var localeStrings2 = {
|
|
|
96
96
|
tweakMustBeGreaterThanOrEqualToZero: "Le r\xE9glage {{tweak}} doit \xEAtre sup\xE9rieur ou \xE9gal \xE0 0",
|
|
97
97
|
valueMustBeGreaterThanOrEqualToZero: "La valeur {{value}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 0",
|
|
98
98
|
valueMustBeLessThan: "La valeur {{value}} doit \xEAtre inf\xE9rieure \xE0 {{domain}}",
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
minimumValueMustBeGreaterThanOrEqualToZero: "La valeur minimale {{minimumValue}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 0",
|
|
100
|
+
maximumValueMustBeLessThan: "La valeur maximale {{maximumValue}} doit \xEAtre inf\xE9rieure \xE0 {{domain}}"
|
|
101
101
|
},
|
|
102
102
|
RegExpValidator: {
|
|
103
103
|
stringDoesNotMatchPattern: "La cha\xEEne {{s}} ne correspond pas au mod\xE8le"
|
|
@@ -139,8 +139,8 @@ async function i18nUtilityInit(environment, debug = false) {
|
|
|
139
139
|
await (0, import_core.i18nCoreInit)(i18nextUtility, environment, debug, utilityNS, utilityResources);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
// src/
|
|
143
|
-
var
|
|
142
|
+
// src/sequence.ts
|
|
143
|
+
var Sequence = class {
|
|
144
144
|
/**
|
|
145
145
|
* Start value (inclusive).
|
|
146
146
|
*/
|
|
@@ -160,11 +160,11 @@ var Sequencer = class {
|
|
|
160
160
|
/**
|
|
161
161
|
* Minimum value (inclusive).
|
|
162
162
|
*/
|
|
163
|
-
|
|
163
|
+
_minimumValue;
|
|
164
164
|
/**
|
|
165
165
|
* Maximum value (inclusive).
|
|
166
166
|
*/
|
|
167
|
-
|
|
167
|
+
_maximumValue;
|
|
168
168
|
/**
|
|
169
169
|
* Constructor.
|
|
170
170
|
*
|
|
@@ -181,12 +181,12 @@ var Sequencer = class {
|
|
|
181
181
|
this._count = count;
|
|
182
182
|
if (count >= 0) {
|
|
183
183
|
this._nextDelta = 1n;
|
|
184
|
-
this.
|
|
185
|
-
this.
|
|
184
|
+
this._minimumValue = this._startValue;
|
|
185
|
+
this._maximumValue = this._endValue - 1n;
|
|
186
186
|
} else {
|
|
187
187
|
this._nextDelta = -1n;
|
|
188
|
-
this.
|
|
189
|
-
this.
|
|
188
|
+
this._minimumValue = this._endValue + 1n;
|
|
189
|
+
this._maximumValue = this._startValue;
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
@@ -210,14 +210,14 @@ var Sequencer = class {
|
|
|
210
210
|
/**
|
|
211
211
|
* Get the minimum value (inclusive).
|
|
212
212
|
*/
|
|
213
|
-
get
|
|
214
|
-
return this.
|
|
213
|
+
get minimumValue() {
|
|
214
|
+
return this._minimumValue;
|
|
215
215
|
}
|
|
216
216
|
/**
|
|
217
217
|
* Get the maximum value (inclusive).
|
|
218
218
|
*/
|
|
219
|
-
get
|
|
220
|
-
return this.
|
|
219
|
+
get maximumValue() {
|
|
220
|
+
return this._maximumValue;
|
|
221
221
|
}
|
|
222
222
|
/**
|
|
223
223
|
* Iterable implementation.
|
|
@@ -233,12 +233,18 @@ var Sequencer = class {
|
|
|
233
233
|
};
|
|
234
234
|
|
|
235
235
|
// src/transformer.ts
|
|
236
|
-
function transformIterable(
|
|
236
|
+
function transformIterable(values, transformerCallback) {
|
|
237
237
|
return {
|
|
238
|
+
/**
|
|
239
|
+
* Iterable implementation.
|
|
240
|
+
*
|
|
241
|
+
* @yields
|
|
242
|
+
* Next output value.
|
|
243
|
+
*/
|
|
238
244
|
*[Symbol.iterator]() {
|
|
239
245
|
let index = 0;
|
|
240
|
-
for (const
|
|
241
|
-
yield transformerCallback(
|
|
246
|
+
for (const value of values) {
|
|
247
|
+
yield transformerCallback(value, index++);
|
|
242
248
|
}
|
|
243
249
|
}
|
|
244
250
|
};
|
|
@@ -321,45 +327,58 @@ var Transformer = class _Transformer {
|
|
|
321
327
|
}));
|
|
322
328
|
}
|
|
323
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Validate that a value is within the domain and do the work of transforming it forward.
|
|
332
|
+
*
|
|
333
|
+
* @param value
|
|
334
|
+
* Value.
|
|
335
|
+
*
|
|
336
|
+
* @returns
|
|
337
|
+
* Transformed value.
|
|
338
|
+
*/
|
|
339
|
+
validateDoForward(value) {
|
|
340
|
+
const valueN = BigInt(value);
|
|
341
|
+
this.validate(valueN);
|
|
342
|
+
return this.doForward(valueN);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Validate that a value is within the domain, do the work of transforming it forward, and apply a callback.
|
|
346
|
+
*
|
|
347
|
+
* @param transformerCallback
|
|
348
|
+
* Called after each value is transformed to convert it to its final value.
|
|
349
|
+
*
|
|
350
|
+
* @param value
|
|
351
|
+
* Value.
|
|
352
|
+
*
|
|
353
|
+
* @param index
|
|
354
|
+
* Index in sequence (0 for single transformation).
|
|
355
|
+
*
|
|
356
|
+
* @returns
|
|
357
|
+
* Transformed value.
|
|
358
|
+
*/
|
|
359
|
+
validateDoForwardCallback(transformerCallback, value, index) {
|
|
360
|
+
return transformerCallback(this.validateDoForward(value), index);
|
|
361
|
+
}
|
|
324
362
|
// eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
|
|
325
363
|
forward(valueOrValues, transformerCallback) {
|
|
326
364
|
let result;
|
|
327
365
|
if (typeof valueOrValues !== "object") {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
if (valueOrValues.minValue < 0n) {
|
|
334
|
-
throw new RangeError(i18nextUtility.t("Transformer.minValueMustBeGreaterThanOrEqualToZero", {
|
|
335
|
-
minValue: valueOrValues.minValue
|
|
366
|
+
result = transformerCallback === void 0 ? this.validateDoForward(valueOrValues) : this.validateDoForwardCallback(transformerCallback, valueOrValues, 0);
|
|
367
|
+
} else if (valueOrValues instanceof Sequence) {
|
|
368
|
+
if (valueOrValues.minimumValue < 0n) {
|
|
369
|
+
throw new RangeError(i18nextUtility.t("Transformer.minimumValueMustBeGreaterThanOrEqualToZero", {
|
|
370
|
+
minimumValue: valueOrValues.minimumValue
|
|
336
371
|
}));
|
|
337
372
|
}
|
|
338
|
-
if (valueOrValues.
|
|
339
|
-
throw new RangeError(i18nextUtility.t("Transformer.
|
|
340
|
-
|
|
373
|
+
if (valueOrValues.maximumValue >= this.domain) {
|
|
374
|
+
throw new RangeError(i18nextUtility.t("Transformer.maximumValueMustBeLessThan", {
|
|
375
|
+
maximumValue: valueOrValues.maximumValue,
|
|
341
376
|
domain: this.domain
|
|
342
377
|
}));
|
|
343
378
|
}
|
|
344
|
-
|
|
345
|
-
result = transformIterable(valueOrValues, (value) => this.doForward(value));
|
|
346
|
-
} else {
|
|
347
|
-
result = transformIterable(valueOrValues, (value, index) => transformerCallback(this.doForward(value), index));
|
|
348
|
-
}
|
|
379
|
+
result = transformerCallback === void 0 ? transformIterable(valueOrValues, (value) => this.doForward(value)) : transformIterable(valueOrValues, (value, index) => transformerCallback(this.doForward(value), index));
|
|
349
380
|
} else {
|
|
350
|
-
|
|
351
|
-
result = transformIterable(valueOrValues, (value) => {
|
|
352
|
-
const valueN = BigInt(value);
|
|
353
|
-
this.validate(valueN);
|
|
354
|
-
return this.doForward(valueN);
|
|
355
|
-
});
|
|
356
|
-
} else {
|
|
357
|
-
result = transformIterable(valueOrValues, (value, index) => {
|
|
358
|
-
const valueN = BigInt(value);
|
|
359
|
-
this.validate(valueN);
|
|
360
|
-
return transformerCallback(this.doForward(valueN), index);
|
|
361
|
-
});
|
|
362
|
-
}
|
|
381
|
+
result = transformerCallback === void 0 ? transformIterable(valueOrValues, (value) => this.validateDoForward(value)) : transformIterable(valueOrValues, (value, index) => this.validateDoForwardCallback(transformerCallback, value, index));
|
|
363
382
|
}
|
|
364
383
|
return result;
|
|
365
384
|
}
|
|
@@ -423,10 +442,6 @@ var EncryptionTransformer = class _EncryptionTransformer extends Transformer {
|
|
|
423
442
|
* Number of bytes covered by the domain.
|
|
424
443
|
*/
|
|
425
444
|
_domainBytes;
|
|
426
|
-
/**
|
|
427
|
-
* Tweak.
|
|
428
|
-
*/
|
|
429
|
-
_tweak;
|
|
430
445
|
/**
|
|
431
446
|
* Xor bytes array generated from the domain and tweak.
|
|
432
447
|
*/
|
|
@@ -460,18 +475,16 @@ var EncryptionTransformer = class _EncryptionTransformer extends Transformer {
|
|
|
460
475
|
}));
|
|
461
476
|
}
|
|
462
477
|
let domainBytes = 0;
|
|
463
|
-
for (let reducedDomainMinusOne = this.domain - 1n; reducedDomainMinusOne !== 0n; reducedDomainMinusOne
|
|
478
|
+
for (let reducedDomainMinusOne = this.domain - 1n; reducedDomainMinusOne !== 0n; reducedDomainMinusOne >>= 8n) {
|
|
464
479
|
domainBytes++;
|
|
465
480
|
}
|
|
466
481
|
this._domainBytes = domainBytes;
|
|
467
|
-
this._tweak = BigInt(tweak);
|
|
468
482
|
const xorBytes = new Array();
|
|
469
483
|
const bits = new Array();
|
|
470
484
|
const inverseBits = new Array();
|
|
471
|
-
for (let reducedKey = this.domain *
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
const bitNumber = keyByte & 7;
|
|
485
|
+
for (let reducedKey = this.domain * BigInt(tweak) * 603868999n; reducedKey !== 0n; reducedKey >>= 8n) {
|
|
486
|
+
xorBytes.unshift(Number(BigInt.asUintN(8, reducedKey)));
|
|
487
|
+
const bitNumber = Number(BigInt.asUintN(3, reducedKey));
|
|
475
488
|
bits.push(_EncryptionTransformer.BITS[bitNumber]);
|
|
476
489
|
inverseBits.push(_EncryptionTransformer.INVERSE_BITS[bitNumber]);
|
|
477
490
|
}
|
|
@@ -488,12 +501,6 @@ var EncryptionTransformer = class _EncryptionTransformer extends Transformer {
|
|
|
488
501
|
this._rounds = xorBytes.length;
|
|
489
502
|
}
|
|
490
503
|
}
|
|
491
|
-
/**
|
|
492
|
-
* Get the tweak.
|
|
493
|
-
*/
|
|
494
|
-
get tweak() {
|
|
495
|
-
return this._tweak;
|
|
496
|
-
}
|
|
497
504
|
/**
|
|
498
505
|
* Convert a value to a byte array big enough to handle the entire domain.
|
|
499
506
|
*
|
|
@@ -505,10 +512,8 @@ var EncryptionTransformer = class _EncryptionTransformer extends Transformer {
|
|
|
505
512
|
*/
|
|
506
513
|
valueToBytes(value) {
|
|
507
514
|
const bytes = new Uint8Array(this._domainBytes);
|
|
508
|
-
let reducedValue = value;
|
|
509
|
-
|
|
510
|
-
bytes[index] = Number(reducedValue & 0xFFn);
|
|
511
|
-
reducedValue = reducedValue >> 8n;
|
|
515
|
+
for (let index = this._domainBytes - 1, reducedValue = value; index >= 0 && reducedValue !== 0n; index--, reducedValue >>= 8n) {
|
|
516
|
+
bytes[index] = Number(BigInt.asUintN(8, reducedValue));
|
|
512
517
|
}
|
|
513
518
|
return bytes;
|
|
514
519
|
}
|
|
@@ -1164,7 +1169,7 @@ var CharacterSetCreator = class _CharacterSetCreator extends CharacterSetValidat
|
|
|
1164
1169
|
}
|
|
1165
1170
|
s = this.character(exclusion === 1 /* FirstZero */ ? Number(convertValue % this._characterSetSizeMinusOneN) + 1 : Number(convertValue % this._characterSetSizeN)) + s;
|
|
1166
1171
|
}
|
|
1167
|
-
return creatorCallback
|
|
1172
|
+
return creatorCallback === void 0 ? s : creatorCallback(s, index);
|
|
1168
1173
|
});
|
|
1169
1174
|
}
|
|
1170
1175
|
/**
|
|
@@ -1327,7 +1332,7 @@ var ALPHANUMERIC_CREATOR = new CharacterSetCreator([
|
|
|
1327
1332
|
NUMERIC_CREATOR,
|
|
1328
1333
|
RecordValidator,
|
|
1329
1334
|
RegExpValidator,
|
|
1330
|
-
|
|
1335
|
+
Sequence,
|
|
1331
1336
|
Transformer,
|
|
1332
1337
|
i18nUtilityInit,
|
|
1333
1338
|
i18nextUtility,
|
|
@@ -1335,3 +1340,19 @@ var ALPHANUMERIC_CREATOR = new CharacterSetCreator([
|
|
|
1335
1340
|
utilityNS,
|
|
1336
1341
|
utilityResources
|
|
1337
1342
|
});
|
|
1343
|
+
/*!
|
|
1344
|
+
* Copyright © 2024-2025 Dolphin Data Development Ltd. and AIDC Toolkit
|
|
1345
|
+
* contributors
|
|
1346
|
+
*
|
|
1347
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1348
|
+
* you may not use this file except in compliance with the License.
|
|
1349
|
+
* You may obtain a copy of the License at
|
|
1350
|
+
*
|
|
1351
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
1352
|
+
*
|
|
1353
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1354
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1355
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1356
|
+
* See the License for the specific language governing permissions and
|
|
1357
|
+
* limitations under the License.
|
|
1358
|
+
*/
|