@aidc-toolkit/utility 0.9.5 → 0.9.7-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/dist/index.cjs CHANGED
@@ -33,10 +33,89 @@ __export(src_exports, {
33
33
  RecordValidator: () => RecordValidator,
34
34
  RegExpValidator: () => RegExpValidator,
35
35
  Sequencer: () => Sequencer,
36
- Transformer: () => Transformer
36
+ Transformer: () => Transformer,
37
+ utilityNS: () => utilityNS
37
38
  });
38
39
  module.exports = __toCommonJS(src_exports);
39
40
 
41
+ // src/locale/i18n.ts
42
+ var import_core = require("@aidc-toolkit/core");
43
+
44
+ // src/locale/en/locale_strings.ts
45
+ var localeStrings = {
46
+ Transformer: {
47
+ domainMustBeGreaterThanZero: "Domain {{domain}} must be greater than 0",
48
+ tweakMustBeGreaterThanOrEqualToZero: "Tweak {{tweak}} must be greater than or equal to 0",
49
+ valueMustBeGreaterThanOrEqualToZero: "Value {{value}} must be greater than or equal to 0",
50
+ valueMustBeLessThan: "Value {{value}} must be less than {{domain}}",
51
+ minValueMustBeGreaterThanOrEqualToZero: "Minimum value {{minValue}} must be greater than or equal to 0",
52
+ maxValueMustBeLessThan: "Maximum value {{maxValue}} must be less than {{domain}}"
53
+ },
54
+ RegExpValidator: {
55
+ stringDoesNotMatchPattern: "String {{s}} does not match pattern"
56
+ },
57
+ CharacterSetValidator: {
58
+ firstZeroFirstCharacter: "Character set must support zero as first character",
59
+ allNumericAllNumericCharacters: "Character set must support all numeric characters in sequence",
60
+ stringMustNotBeAllNumeric: "String must not be all numeric",
61
+ lengthMustBeGreaterThanOrEqualTo: "Length {{length}} must be greater than or equal to {{minimumLength}}",
62
+ lengthMustBeLessThanOrEqualTo: "Length {{length}} must be less than or equal to {{maximumLength}}",
63
+ lengthMustBeEqualTo: "Length {{length}} must be equal to {{exactLength}}",
64
+ lengthOfComponentMustBeGreaterThanOrEqualTo: "Length {{length}} of {{component}} must be greater than or equal to {{minimumLength}}",
65
+ lengthOfComponentMustBeLessThanOrEqualTo: "Length {{length}} of {{component}} must be less than or equal to {{maximumLength}}",
66
+ lengthOfComponentMustBeEqualTo: "Length {{length}} of {{component}} must be equal to {{exactLength}}",
67
+ invalidCharacterAtPosition: "Invalid character '{{c}}' at position {{position}}",
68
+ invalidCharacterAtPositionOfComponent: "Invalid character '{{c}}' at position {{position}} of {{component}}",
69
+ exclusionNotSupported: "Exclusion value of {{exclusion}} is not supported",
70
+ invalidTweakWithAllNumericExclusion: "Tweak must not be used with all-numeric exclusion",
71
+ endSequenceValueMustBeLessThanOrEqualTo: "End sequence value (start sequence value + count - 1) must be less than {{domain}}"
72
+ },
73
+ RecordValidator: {
74
+ typeNameKeyNotFound: '{{typeName}} "{{key}}" not found'
75
+ }
76
+ };
77
+
78
+ // src/locale/fr/locale_strings.ts
79
+ var localeStrings2 = {
80
+ Transformer: {
81
+ domainMustBeGreaterThanZero: "Le domaine {{domain}} doit \xEAtre sup\xE9rieur \xE0 0",
82
+ tweakMustBeGreaterThanOrEqualToZero: "Le r\xE9glage {{tweak}} doit \xEAtre sup\xE9rieur ou \xE9gal \xE0 0",
83
+ valueMustBeGreaterThanOrEqualToZero: "La valeur {{value}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 0",
84
+ valueMustBeLessThan: "La valeur {{value}} doit \xEAtre inf\xE9rieure \xE0 {{domain}}",
85
+ minValueMustBeGreaterThanOrEqualToZero: "La valeur minimale {{minValue}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 0",
86
+ maxValueMustBeLessThan: "La valeur maximale {{maxValue}} doit \xEAtre inf\xE9rieure \xE0 {{domain}}"
87
+ },
88
+ RegExpValidator: {
89
+ stringDoesNotMatchPattern: "La cha\xEEne {{s}} ne correspond pas au mod\xE8le"
90
+ },
91
+ CharacterSetValidator: {
92
+ firstZeroFirstCharacter: "Le jeu de caract\xE8res doit prendre en charge z\xE9ro comme premier caract\xE8re",
93
+ allNumericAllNumericCharacters: "Le jeu de caract\xE8res doit prendre en charge tous les caract\xE8res num\xE9riques en s\xE9quence",
94
+ stringMustNotBeAllNumeric: "La cha\xEEne ne doit pas \xEAtre enti\xE8rement num\xE9rique",
95
+ lengthMustBeGreaterThanOrEqualTo: "La longueur {{length}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 {{minimumLength}}",
96
+ lengthMustBeLessThanOrEqualTo: "La longueur {{length}} doit \xEAtre inf\xE9rieure ou \xE9gale \xE0 {{maximumLength}}",
97
+ lengthMustBeEqualTo: "La longueur {{length}} doit \xEAtre \xE9gale \xE0 {{exactLength}}",
98
+ lengthOfComponentMustBeGreaterThanOrEqualTo: "La longueur {{length}} de {{component}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 {{minimumLength}}",
99
+ lengthOfComponentMustBeLessThanOrEqualTo: "La longueur {{length}} de {{component}} doit \xEAtre inf\xE9rieure ou \xE9gale \xE0 {{maximumLength}}",
100
+ lengthOfComponentMustBeEqualTo: "La longueur {{length}} de {{component}} doit \xEAtre \xE9gale \xE0 {{exactLength}}",
101
+ invalidCharacterAtPosition: "Caract\xE8re non valide '{{c}}' \xE0 la position {{position}}",
102
+ invalidCharacterAtPositionOfComponent: "Caract\xE8re non valide '{{c}}' \xE0 la position {{position}} de {{component}}",
103
+ exclusionNotSupported: "La valeur d'exclusion de {{exclusion}} n'est pas prise en charge",
104
+ invalidTweakWithAllNumericExclusion: "Le r\xE9glage ne doit pas \xEAtre utilis\xE9 avec une exclusion enti\xE8rement num\xE9rique",
105
+ endSequenceValueMustBeLessThanOrEqualTo: "La valeur de la s\xE9quence de fin (valeur de la s\xE9quence de d\xE9but + nombre - 1) doit \xEAtre inf\xE9rieure \xE0 {{domaine}}"
106
+ },
107
+ RecordValidator: {
108
+ typeNameKeyNotFound: '{{typeName}} "{{key}}" introuvable'
109
+ }
110
+ };
111
+
112
+ // src/locale/i18n.ts
113
+ var utilityNS = "aidct_utility";
114
+ (0, import_core.i18nAssertValidResources)(localeStrings, "fr", localeStrings2);
115
+ (0, import_core.i18nAddResourceBundle)("en", utilityNS, localeStrings);
116
+ (0, import_core.i18nAddResourceBundle)("fr", utilityNS, localeStrings2);
117
+ var i18n_default = import_core.i18next;
118
+
40
119
  // src/iterator_proxy.ts
41
120
  var IteratorProxyBase = class _IteratorProxyBase {
42
121
  /**
@@ -539,84 +618,6 @@ var Sequencer = class {
539
618
  }
540
619
  };
541
620
 
542
- // src/locale/i18n.ts
543
- var import_core = require("@aidc-toolkit/core");
544
-
545
- // src/locale/en/locale_strings.ts
546
- var localeStrings = {
547
- Transformer: {
548
- domainMustBeGreaterThanZero: "Domain {{domain}} must be greater than 0",
549
- tweakMustBeGreaterThanOrEqualToZero: "Tweak {{tweak}} must be greater than or equal to 0",
550
- valueMustBeGreaterThanOrEqualToZero: "Value {{value}} must be greater than or equal to 0",
551
- valueMustBeLessThan: "Value {{value}} must be less than {{domain}}",
552
- minValueMustBeGreaterThanOrEqualToZero: "Minimum value {{minValue}} must be greater than or equal to 0",
553
- maxValueMustBeLessThan: "Maximum value {{maxValue}} must be less than {{domain}}"
554
- },
555
- RegExpValidator: {
556
- stringDoesNotMatchPattern: "String {{s}} does not match pattern"
557
- },
558
- CharacterSetValidator: {
559
- firstZeroFirstCharacter: "Character set must support zero as first character",
560
- allNumericAllNumericCharacters: "Character set must support all numeric characters in sequence",
561
- stringMustNotBeAllNumeric: "String must not be all numeric",
562
- lengthMustBeGreaterThanOrEqualTo: "Length {{length}} must be greater than or equal to {{minimumLength}}",
563
- lengthMustBeLessThanOrEqualTo: "Length {{length}} must be less than or equal to {{maximumLength}}",
564
- lengthMustBeEqualTo: "Length {{length}} must be equal to {{exactLength}}",
565
- lengthOfComponentMustBeGreaterThanOrEqualTo: "Length {{length}} of {{component}} must be greater than or equal to {{minimumLength}}",
566
- lengthOfComponentMustBeLessThanOrEqualTo: "Length {{length}} of {{component}} must be less than or equal to {{maximumLength}}",
567
- lengthOfComponentMustBeEqualTo: "Length {{length}} of {{component}} must be equal to {{exactLength}}",
568
- invalidCharacterAtPosition: "Invalid character '{{c}}' at position {{position}}",
569
- invalidCharacterAtPositionOfComponent: "Invalid character '{{c}}' at position {{position}} of {{component}}",
570
- exclusionNotSupported: "Exclusion value of {{exclusion}} is not supported",
571
- invalidTweakWithAllNumericExclusion: "Tweak must not be used with all-numeric exclusion",
572
- endSequenceValueMustBeLessThanOrEqualTo: "End sequence value (start sequence value + count - 1) must be less than {{domain}}"
573
- },
574
- RecordValidator: {
575
- typeNameKeyNotFound: '{{typeName}} "{{key}}" not found'
576
- }
577
- };
578
-
579
- // src/locale/fr/locale_strings.ts
580
- var localeStrings2 = {
581
- Transformer: {
582
- domainMustBeGreaterThanZero: "Le domaine {{domain}} doit \xEAtre sup\xE9rieur \xE0 0",
583
- tweakMustBeGreaterThanOrEqualToZero: "Le r\xE9glage {{tweak}} doit \xEAtre sup\xE9rieur ou \xE9gal \xE0 0",
584
- valueMustBeGreaterThanOrEqualToZero: "La valeur {{value}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 0",
585
- valueMustBeLessThan: "La valeur {{value}} doit \xEAtre inf\xE9rieure \xE0 {{domain}}",
586
- minValueMustBeGreaterThanOrEqualToZero: "La valeur minimale {{minValue}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 0",
587
- maxValueMustBeLessThan: "La valeur maximale {{maxValue}} doit \xEAtre inf\xE9rieure \xE0 {{domain}}"
588
- },
589
- RegExpValidator: {
590
- stringDoesNotMatchPattern: "La cha\xEEne {{s}} ne correspond pas au mod\xE8le"
591
- },
592
- CharacterSetValidator: {
593
- firstZeroFirstCharacter: "Le jeu de caract\xE8res doit prendre en charge z\xE9ro comme premier caract\xE8re",
594
- allNumericAllNumericCharacters: "Le jeu de caract\xE8res doit prendre en charge tous les caract\xE8res num\xE9riques en s\xE9quence",
595
- stringMustNotBeAllNumeric: "La cha\xEEne ne doit pas \xEAtre enti\xE8rement num\xE9rique",
596
- lengthMustBeGreaterThanOrEqualTo: "La longueur {{length}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 {{minimumLength}}",
597
- lengthMustBeLessThanOrEqualTo: "La longueur {{length}} doit \xEAtre inf\xE9rieure ou \xE9gale \xE0 {{maximumLength}}",
598
- lengthMustBeEqualTo: "La longueur {{length}} doit \xEAtre \xE9gale \xE0 {{exactLength}}",
599
- lengthOfComponentMustBeGreaterThanOrEqualTo: "La longueur {{length}} de {{component}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 {{minimumLength}}",
600
- lengthOfComponentMustBeLessThanOrEqualTo: "La longueur {{length}} de {{component}} doit \xEAtre inf\xE9rieure ou \xE9gale \xE0 {{maximumLength}}",
601
- lengthOfComponentMustBeEqualTo: "La longueur {{length}} de {{component}} doit \xEAtre \xE9gale \xE0 {{exactLength}}",
602
- invalidCharacterAtPosition: "Caract\xE8re non valide '{{c}}' \xE0 la position {{position}}",
603
- invalidCharacterAtPositionOfComponent: "Caract\xE8re non valide '{{c}}' \xE0 la position {{position}} de {{component}}",
604
- exclusionNotSupported: "La valeur d'exclusion de {{exclusion}} n'est pas prise en charge",
605
- invalidTweakWithAllNumericExclusion: "Le r\xE9glage ne doit pas \xEAtre utilis\xE9 avec une exclusion enti\xE8rement num\xE9rique",
606
- endSequenceValueMustBeLessThanOrEqualTo: "La valeur de la s\xE9quence de fin (valeur de la s\xE9quence de d\xE9but + nombre - 1) doit \xEAtre inf\xE9rieure \xE0 {{domaine}}"
607
- },
608
- RecordValidator: {
609
- typeNameKeyNotFound: '{{typeName}} "{{key}}" introuvable'
610
- }
611
- };
612
-
613
- // src/locale/i18n.ts
614
- var utilityNS = "aidct_utility";
615
- (0, import_core.i18nAssertValidResources)(localeStrings, "fr", localeStrings2);
616
- (0, import_core.i18nAddResourceBundle)("en", utilityNS, localeStrings);
617
- (0, import_core.i18nAddResourceBundle)("fr", utilityNS, localeStrings2);
618
- var i18n_default = import_core.i18next;
619
-
620
621
  // src/transformer.ts
621
622
  var Transformer = class _Transformer {
622
623
  /**
@@ -699,28 +700,14 @@ var Transformer = class _Transformer {
699
700
  }));
700
701
  }
701
702
  }
702
- /**
703
- * Transform a value or values forward.
704
- *
705
- * @template T
706
- * Type returned by transformation callback.
707
- *
708
- * @param valueOrValues
709
- * Value(s).
710
- *
711
- * @param transformationCallback
712
- * Called after value(s) is/are transformed to convert it/them to its/their final value(s).
713
- *
714
- * @returns
715
- * Value(s) transformed into object(s).
716
- */
717
- forward(valueOrValues, transformationCallback) {
703
+ // eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
704
+ forward(valueOrValues, transformerCallback) {
718
705
  let result;
719
706
  if (typeof valueOrValues !== "object") {
720
707
  const valueN = BigInt(valueOrValues);
721
708
  this.validate(valueN);
722
709
  const transformedValue = this.doForward(valueN);
723
- result = transformationCallback === void 0 ? transformedValue : transformationCallback(transformedValue, 0);
710
+ result = transformerCallback === void 0 ? transformedValue : transformerCallback(transformedValue, 0);
724
711
  } else if (valueOrValues instanceof Sequencer) {
725
712
  if (valueOrValues.minValue < 0n) {
726
713
  throw new RangeError(i18n_default.t("Transformer.minValueMustBeGreaterThanOrEqualToZero", {
@@ -735,16 +722,16 @@ var Transformer = class _Transformer {
735
722
  domain: this.domain
736
723
  }));
737
724
  }
738
- result = transformationCallback === void 0 ? IteratorProxy.from(valueOrValues).map((value) => this.doForward(value)) : IteratorProxy.from(valueOrValues).map((value, index) => transformationCallback(this.doForward(value), index));
725
+ result = transformerCallback === void 0 ? IteratorProxy.from(valueOrValues).map((value) => this.doForward(value)) : IteratorProxy.from(valueOrValues).map((value, index) => transformerCallback(this.doForward(value), index));
739
726
  } else {
740
- result = transformationCallback === void 0 ? IteratorProxy.from(valueOrValues).map((value) => {
727
+ result = transformerCallback === void 0 ? IteratorProxy.from(valueOrValues).map((value) => {
741
728
  const valueN = BigInt(value);
742
729
  this.validate(valueN);
743
730
  return this.doForward(valueN);
744
731
  }) : IteratorProxy.from(valueOrValues).map((value, index) => {
745
732
  const valueN = BigInt(value);
746
733
  this.validate(valueN);
747
- return transformationCallback(this.doForward(valueN), index);
734
+ return transformerCallback(this.doForward(valueN), index);
748
735
  });
749
736
  }
750
737
  return result;
@@ -1426,17 +1413,21 @@ var CharacterSetCreator = class _CharacterSetCreator extends CharacterSetValidat
1426
1413
  exclusionDomains[1 /* FirstZero */] = exclusionFirstZeroDomains;
1427
1414
  }
1428
1415
  if (exclusionSupport.includes(2 /* AllNumeric */)) {
1416
+ let validateNumberIndexes2 = function(numberIndexes2) {
1417
+ let expectedNumberIndex = numberIndexes2[0];
1418
+ for (const numberIndex of numberIndexes2) {
1419
+ if (numberIndex === void 0 || numberIndex !== expectedNumberIndex) {
1420
+ throw new RangeError(i18n_default.t("CharacterSetValidator.allNumericAllNumericCharacters", {
1421
+ ns: utilityNS
1422
+ }));
1423
+ }
1424
+ expectedNumberIndex = numberIndex + 1;
1425
+ }
1426
+ };
1427
+ var validateNumberIndexes = validateNumberIndexes2;
1429
1428
  const exclusionAllNumericDomains = new Array(_CharacterSetCreator.MAXIMUM_STRING_LENGTH + 1);
1430
1429
  const numberIndexes = this.characterIndexes("0123456789");
1431
- let expectedNumberIndex = numberIndexes[0];
1432
- for (const numberIndex of numberIndexes) {
1433
- if (numberIndex === void 0 || numberIndex !== expectedNumberIndex) {
1434
- throw new RangeError(i18n_default.t("CharacterSetValidator.allNumericAllNumericCharacters", {
1435
- ns: utilityNS
1436
- }));
1437
- }
1438
- expectedNumberIndex = numberIndex + 1;
1439
- }
1430
+ validateNumberIndexes2(numberIndexes);
1440
1431
  const zeroIndex = BigInt(numberIndexes[0]);
1441
1432
  const allZerosValues = new Array(_CharacterSetCreator.MAXIMUM_STRING_LENGTH + 1);
1442
1433
  let allZerosValue = 0n;
@@ -1523,8 +1514,30 @@ var CharacterSetCreator = class _CharacterSetCreator extends CharacterSetValidat
1523
1514
  }));
1524
1515
  }
1525
1516
  }
1526
- // eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
1527
- create(length, valueOrValues, exclusion = 0 /* None */, tweak, creationCallback) {
1517
+ /**
1518
+ * Create string(s) by mapping value(s) to the equivalent characters in the character set across the length of the
1519
+ * string.
1520
+ *
1521
+ * @param length
1522
+ * Required string length.
1523
+ *
1524
+ * @param valueOrValues
1525
+ * Numeric value(s) of the string(s).
1526
+ *
1527
+ * @param exclusion
1528
+ * String(s) to be excluded from the range of outputs. See {@link Exclusion} for possible values and their meaning.
1529
+ *
1530
+ * @param tweak
1531
+ * If provided, the numerical value of the string(s) is/are "tweaked" using an {@link EncryptionTransformer |
1532
+ * encryption transformer}.
1533
+ *
1534
+ * @param creatorCallback
1535
+ * If provided, called after each string is constructed to create the final value.
1536
+ *
1537
+ * @returns
1538
+ * String(s) created from the value(s).
1539
+ */
1540
+ create(length, valueOrValues, exclusion = 0 /* None */, tweak, creatorCallback) {
1528
1541
  this.validateLength(length);
1529
1542
  this.validateExclusion(exclusion);
1530
1543
  const allZerosValue = exclusion === 2 /* AllNumeric */ ? this._allZerosValues[length] : 0n;
@@ -1543,7 +1556,7 @@ var CharacterSetCreator = class _CharacterSetCreator extends CharacterSetValidat
1543
1556
  }
1544
1557
  s = this.character(exclusion === 1 /* FirstZero */ ? Number(convertValue % this._characterSetSizeMinusOneN) + 1 : Number(convertValue % this._characterSetSizeN)) + s;
1545
1558
  }
1546
- return creationCallback !== void 0 ? creationCallback(s, index) : s;
1559
+ return creatorCallback !== void 0 ? creatorCallback(s, index) : s;
1547
1560
  });
1548
1561
  }
1549
1562
  /**
@@ -1710,5 +1723,6 @@ var ALPHANUMERIC_CREATOR = new CharacterSetCreator([
1710
1723
  RecordValidator,
1711
1724
  RegExpValidator,
1712
1725
  Sequencer,
1713
- Transformer
1726
+ Transformer,
1727
+ utilityNS
1714
1728
  });
package/dist/index.d.cts CHANGED
@@ -1,8 +1,53 @@
1
+ declare const utilityNS = "aidct_utility";
2
+
3
+ /**
4
+ * Transformer input, one of:
5
+ *
6
+ * - T (primitive type)
7
+ * - Iterable<T>
8
+ *
9
+ * @template T
10
+ * Primitive type.
11
+ */
12
+ type TransformerInput<T extends string | number | bigint | boolean> = T | Iterable<T>;
13
+ /**
14
+ * Transformer callback, used to convert transformed value to its final value.
15
+ *
16
+ * @template TInput
17
+ * Type of input to callback.
18
+ *
19
+ * @template TOutput
20
+ * Type of output to callback.
21
+ *
22
+ * @param input
23
+ * Input value.
24
+ *
25
+ * @param index
26
+ * Index in sequence (0 for single transformation).
27
+ *
28
+ * @returns
29
+ * Output value.
30
+ */
31
+ type TransformerCallback<TInput, TOutput> = (input: TInput, index: number) => TOutput;
32
+ /**
33
+ * Transformer output, based on transformer input:
34
+ *
35
+ * - If type T is primitive type, result is type U.
36
+ * - If type T is Iterable type, result is type IterableIterator<U>.
37
+ *
38
+ * @template T
39
+ * Transformer input type.
40
+ *
41
+ * @template U
42
+ * Output base type.
43
+ */
44
+ type TransformerOutput<T extends TransformerInput<string | number | bigint | boolean>, U> = T extends (T extends TransformerInput<infer V> ? V : never) ? U : IterableIterator<U>;
45
+
1
46
  /**
2
47
  * Iterator proxy. In environments where
3
48
  * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator#iterator_helpers |
4
- * iterator helpers} are supported, this references the {@link Iterator} variable directly. Otherwise, it references an
5
- * implementation of "from" that uses an internally-defined iterator proxy object.
49
+ * iterator helpers} are supported, this references the {@linkcode Iterator} variable directly. Otherwise, it references
50
+ * an implementation of "from" that uses an internally-defined iterator proxy object.
6
51
  *
7
52
  * Client applications should **not** rely on long-term availability of this variable as it will be removed once there
8
53
  * is widespread support for iterator helpers.
@@ -92,22 +137,6 @@ declare class Sequencer implements Iterable<bigint>, IterableIterator<bigint> {
92
137
  reset(): void;
93
138
  }
94
139
 
95
- /**
96
- * Transformation callback, used to convert transformed value to its final value.
97
- *
98
- * @template T
99
- * Type returned by callback.
100
- *
101
- * @param transformedValue
102
- * Transformed value.
103
- *
104
- * @param index
105
- * Index in sequence transformation (0 for single transformation).
106
- *
107
- * @returns
108
- * Final value.
109
- */
110
- type TransformationCallback<T> = (transformedValue: bigint, index: number) => T;
111
140
  /**
112
141
  * Transformer that transforms values in a numeric domain to values in a range equal to the domain or to another range
113
142
  * defined by a callback function. In other words, the domain determines valid input values and, without a callback, the
@@ -179,81 +208,39 @@ declare abstract class Transformer {
179
208
  */
180
209
  protected abstract doForward(value: bigint): bigint;
181
210
  /**
182
- * Transform a value forward.
183
- *
184
- * @param value
185
- * Value.
186
- *
187
- * @returns
188
- * Transformed value.
189
- */
190
- forward(value: number | bigint): bigint;
191
- /**
192
- * Transform a value forward.
211
+ * Transform value(s) forward.
193
212
  *
194
213
  * @template T
195
- * Type returned by transformation callback.
196
- *
197
- * @param value
198
- * Value.
199
- *
200
- * @param transformationCallback
201
- * Called after the value is transformed to convert it to its final value.
202
- *
203
- * @returns
204
- * Value transformed into object.
205
- */
206
- forward<T>(value: number | bigint, transformationCallback: TransformationCallback<T>): T;
207
- /**
208
- * Transform values forward.
209
- *
210
- * @param values
211
- * Values. If this is an instance of {@link Sequencer}, the minimum and maximum values are validated prior to
212
- * transformation. Otherwise, the individual values are validated at the time of transformation.
213
- *
214
- * @returns
215
- * Transformed values.
216
- */
217
- forward(values: Iterable<number | bigint>): IterableIterator<bigint>;
218
- /**
219
- * Transform values forward.
220
- *
221
- * @template T
222
- * Type returned by transformation callback.
223
- *
224
- * @param values
225
- * Values. If this is an instance of {@link Sequencer}, the minimum and maximum values are validated prior to
226
- * transformation. Otherwise, the individual values are validated at the time of transformation.
227
- *
228
- * @param transformationCallback
229
- * Called after each value is transformed to convert it to its final value.
230
- *
231
- * @returns
232
- * Values transformed into objects.
233
- */
234
- forward<T>(values: Iterable<number | bigint>, transformationCallback: TransformationCallback<T>): IterableIterator<T>;
235
- /**
236
- * Transform a value or values forward. This signature exists to allow similar overloaded methods in other classes
237
- * to call this method correctly.
214
+ * Value(s) input type.
238
215
  *
239
216
  * @param valueOrValues
217
+ * Value(s). If this is an instance of {@link Sequencer}, the minimum and maximum values are validated prior to
218
+ * transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
240
219
  *
241
220
  * @returns
221
+ * Transformed value(s).
242
222
  */
243
- forward(valueOrValues: number | bigint | Iterable<number | bigint>): bigint | IterableIterator<bigint>;
223
+ forward<T extends TransformerInput<number | bigint>>(valueOrValues: T): TransformerOutput<T, bigint>;
244
224
  /**
245
- * Transform a value or values forward. This signature exists to allow similar overloaded methods in other classes
246
- * to call this method correctly.
225
+ * Transform value(s) forward, optionally applying a transformation.
247
226
  *
248
227
  * @template T
228
+ * Value(s) input type.
229
+ *
230
+ * @template U
231
+ * Transformation callback output type.
249
232
  *
250
233
  * @param valueOrValues
234
+ * Value(s). If this is an instance of {@link Sequencer}, the minimum and maximum values are validated prior to
235
+ * transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
251
236
  *
252
- * @param transformationCallback
237
+ * @param transformerCallback
238
+ * Called after each value is transformed to convert it to its final value.
253
239
  *
254
240
  * @returns
241
+ * Transformed value(s).
255
242
  */
256
- forward<T>(valueOrValues: number | bigint | Iterable<number | bigint>, transformationCallback: TransformationCallback<T>): T | IterableIterator<T>;
243
+ forward<T extends TransformerInput<number | bigint>, U>(valueOrValues: T, transformerCallback: TransformerCallback<bigint, U>): TransformerOutput<T, U>;
257
244
  /**
258
245
  * Do the work of transforming a value in reverse.
259
246
  *
@@ -699,19 +686,6 @@ declare class CharacterSetValidator implements StringValidator<CharacterSetValid
699
686
  */
700
687
  validate(s: string, validation?: CharacterSetValidation): void;
701
688
  }
702
- /**
703
- * Creation callback, used to convert created string to its final value.
704
- *
705
- * @param s
706
- * Created string.
707
- *
708
- * @param index
709
- * Index in sequence creation (0 for single creation).
710
- *
711
- * @returns
712
- * Final value.
713
- */
714
- type CreationCallback = (s: string, index: number) => string;
715
689
  /**
716
690
  * Character set creator. Maps numeric values to strings using the character set as digits.
717
691
  */
@@ -805,70 +779,29 @@ declare class CharacterSetCreator extends CharacterSetValidator {
805
779
  */
806
780
  private validateLength;
807
781
  /**
808
- * Create a string by mapping a value to the equivalent characters in the character set across the length of the
782
+ * Create string(s) by mapping value(s) to the equivalent characters in the character set across the length of the
809
783
  * string.
810
784
  *
811
785
  * @param length
812
786
  * Required string length.
813
787
  *
814
- * @param value
815
- * Numeric value of the string.
816
- *
817
- * @param exclusion
818
- * Strings to be excluded from the range of outputs. See {@link Exclusion} for possible values and their meaning.
819
- *
820
- * @param tweak
821
- * If provided, the numerical value of the string is "tweaked" using an {@link EncryptionTransformer | encryption
822
- * transformer}.
823
- *
824
- * @param creationCallback
825
- * If provided, called after the string is constructed to create the final value.
826
- *
827
- * @returns
828
- * String created from the value.
829
- */
830
- create(length: number, value: number | bigint, exclusion?: Exclusion, tweak?: number | bigint, creationCallback?: CreationCallback): string;
831
- /**
832
- * Create multiple strings by mapping each value to the equivalent characters in the character set across the length
833
- * of the string. Equivalent to calling this method for each individual value.
834
- *
835
- * @param length
836
- * Required string length.
837
- *
838
- * @param values
839
- * Numeric values of the strings.
840
- *
841
- * @param exclusion
842
- * Strings to be excluded from the range of outputs. See {@link Exclusion} for possible values and their meaning.
843
- *
844
- * @param tweak
845
- * If provided, the numerical value of the strings are "tweaked" using an {@link EncryptionTransformer | encryption
846
- * transformer}.
847
- *
848
- * @param creationCallback
849
- * If provided, called after each string is constructed to create the final value.
850
- *
851
- * @returns
852
- * Iterable iterator over strings created from the values.
853
- */
854
- create(length: number, values: Iterable<number | bigint>, exclusion?: Exclusion, tweak?: number | bigint, creationCallback?: CreationCallback): IterableIterator<string>;
855
- /**
856
- * Create a string or multiple strings. This signature exists to allow similar overloaded methods in other classes
857
- * to call this method correctly.
858
- *
859
- * @param length
860
- *
861
788
  * @param valueOrValues
789
+ * Numeric value(s) of the string(s).
862
790
  *
863
791
  * @param exclusion
792
+ * String(s) to be excluded from the range of outputs. See {@link Exclusion} for possible values and their meaning.
864
793
  *
865
794
  * @param tweak
795
+ * If provided, the numerical value of the string(s) is/are "tweaked" using an {@link EncryptionTransformer |
796
+ * encryption transformer}.
866
797
  *
867
- * @param creationCallback
798
+ * @param creatorCallback
799
+ * If provided, called after each string is constructed to create the final value.
868
800
  *
869
801
  * @returns
802
+ * String(s) created from the value(s).
870
803
  */
871
- create(length: number, valueOrValues: number | bigint | Iterable<number | bigint>, exclusion?: Exclusion, tweak?: number | bigint, creationCallback?: CreationCallback): string | IterableIterator<string>;
804
+ create<T extends TransformerInput<number | bigint>>(length: number, valueOrValues: T, exclusion?: Exclusion, tweak?: number | bigint, creatorCallback?: TransformerCallback<string, string>): TransformerOutput<T, string>;
872
805
  /**
873
806
  * Determine the value for a string.
874
807
  *
@@ -906,4 +839,4 @@ declare const ALPHABETIC_CREATOR: CharacterSetCreator;
906
839
  */
907
840
  declare const ALPHANUMERIC_CREATOR: CharacterSetCreator;
908
841
 
909
- export { ALPHABETIC_CREATOR, ALPHANUMERIC_CREATOR, CharacterSetCreator, type CharacterSetValidation, CharacterSetValidator, type CreationCallback, EncryptionTransformer, Exclusion, HEXADECIMAL_CREATOR, IdentityTransformer, IteratorProxy, NUMERIC_CREATOR, RecordValidator, RegExpValidator, Sequencer, type StringValidation, type StringValidator, type TransformationCallback, Transformer };
842
+ export { ALPHABETIC_CREATOR, ALPHANUMERIC_CREATOR, CharacterSetCreator, type CharacterSetValidation, CharacterSetValidator, EncryptionTransformer, Exclusion, HEXADECIMAL_CREATOR, IdentityTransformer, IteratorProxy, NUMERIC_CREATOR, RecordValidator, RegExpValidator, Sequencer, type StringValidation, type StringValidator, Transformer, type TransformerCallback, type TransformerInput, type TransformerOutput, utilityNS };