@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 +126 -112
- package/dist/index.d.cts +74 -141
- package/dist/index.d.ts +74 -141
- package/dist/index.js +124 -111
- package/package.json +8 -9
- package/src/character_set.ts +34 -83
- package/src/index.ts +2 -0
- package/src/iterator_proxy.ts +5 -5
- package/src/transformer.ts +29 -103
- package/src/types.ts +46 -0
- package/test/character_set.test.ts +2 -3
- package/test/sequencer.test.ts +4 -4
- package/test/transformer.test.ts +2 -2
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -32
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/workflows/build-publish.yml +0 -20
- package/.idea/inspectionProfiles/Project_Default.xml +0 -7
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/runConfigurations/Test_all.xml +0 -12
- package/.idea/runConfigurations/Test_character_set.xml +0 -12
- package/.idea/runConfigurations/Test_iterator_proxy.xml +0 -12
- package/.idea/runConfigurations/Test_record.xml +0 -12
- package/.idea/runConfigurations/Test_regular_expression.xml +0 -12
- package/.idea/runConfigurations/Test_transformer.xml +0 -12
- package/.idea/runConfigurations/build.xml +0 -12
- package/.idea/runConfigurations/eslint.xml +0 -12
- package/.idea/utility.iml +0 -9
- package/.idea/vcs.xml +0 -6
package/dist/index.d.ts
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 {@
|
|
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
|
|
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
|
-
*
|
|
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
|
|
223
|
+
forward<T extends TransformerInput<number | bigint>>(valueOrValues: T): TransformerOutput<T, bigint>;
|
|
244
224
|
/**
|
|
245
|
-
* Transform
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,81 @@
|
|
|
1
|
+
// src/locale/i18n.ts
|
|
2
|
+
import { i18nAddResourceBundle, i18nAssertValidResources, i18next } from "@aidc-toolkit/core";
|
|
3
|
+
|
|
4
|
+
// src/locale/en/locale_strings.ts
|
|
5
|
+
var localeStrings = {
|
|
6
|
+
Transformer: {
|
|
7
|
+
domainMustBeGreaterThanZero: "Domain {{domain}} must be greater than 0",
|
|
8
|
+
tweakMustBeGreaterThanOrEqualToZero: "Tweak {{tweak}} must be greater than or equal to 0",
|
|
9
|
+
valueMustBeGreaterThanOrEqualToZero: "Value {{value}} must be greater than or equal to 0",
|
|
10
|
+
valueMustBeLessThan: "Value {{value}} must be less than {{domain}}",
|
|
11
|
+
minValueMustBeGreaterThanOrEqualToZero: "Minimum value {{minValue}} must be greater than or equal to 0",
|
|
12
|
+
maxValueMustBeLessThan: "Maximum value {{maxValue}} must be less than {{domain}}"
|
|
13
|
+
},
|
|
14
|
+
RegExpValidator: {
|
|
15
|
+
stringDoesNotMatchPattern: "String {{s}} does not match pattern"
|
|
16
|
+
},
|
|
17
|
+
CharacterSetValidator: {
|
|
18
|
+
firstZeroFirstCharacter: "Character set must support zero as first character",
|
|
19
|
+
allNumericAllNumericCharacters: "Character set must support all numeric characters in sequence",
|
|
20
|
+
stringMustNotBeAllNumeric: "String must not be all numeric",
|
|
21
|
+
lengthMustBeGreaterThanOrEqualTo: "Length {{length}} must be greater than or equal to {{minimumLength}}",
|
|
22
|
+
lengthMustBeLessThanOrEqualTo: "Length {{length}} must be less than or equal to {{maximumLength}}",
|
|
23
|
+
lengthMustBeEqualTo: "Length {{length}} must be equal to {{exactLength}}",
|
|
24
|
+
lengthOfComponentMustBeGreaterThanOrEqualTo: "Length {{length}} of {{component}} must be greater than or equal to {{minimumLength}}",
|
|
25
|
+
lengthOfComponentMustBeLessThanOrEqualTo: "Length {{length}} of {{component}} must be less than or equal to {{maximumLength}}",
|
|
26
|
+
lengthOfComponentMustBeEqualTo: "Length {{length}} of {{component}} must be equal to {{exactLength}}",
|
|
27
|
+
invalidCharacterAtPosition: "Invalid character '{{c}}' at position {{position}}",
|
|
28
|
+
invalidCharacterAtPositionOfComponent: "Invalid character '{{c}}' at position {{position}} of {{component}}",
|
|
29
|
+
exclusionNotSupported: "Exclusion value of {{exclusion}} is not supported",
|
|
30
|
+
invalidTweakWithAllNumericExclusion: "Tweak must not be used with all-numeric exclusion",
|
|
31
|
+
endSequenceValueMustBeLessThanOrEqualTo: "End sequence value (start sequence value + count - 1) must be less than {{domain}}"
|
|
32
|
+
},
|
|
33
|
+
RecordValidator: {
|
|
34
|
+
typeNameKeyNotFound: '{{typeName}} "{{key}}" not found'
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/locale/fr/locale_strings.ts
|
|
39
|
+
var localeStrings2 = {
|
|
40
|
+
Transformer: {
|
|
41
|
+
domainMustBeGreaterThanZero: "Le domaine {{domain}} doit \xEAtre sup\xE9rieur \xE0 0",
|
|
42
|
+
tweakMustBeGreaterThanOrEqualToZero: "Le r\xE9glage {{tweak}} doit \xEAtre sup\xE9rieur ou \xE9gal \xE0 0",
|
|
43
|
+
valueMustBeGreaterThanOrEqualToZero: "La valeur {{value}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 0",
|
|
44
|
+
valueMustBeLessThan: "La valeur {{value}} doit \xEAtre inf\xE9rieure \xE0 {{domain}}",
|
|
45
|
+
minValueMustBeGreaterThanOrEqualToZero: "La valeur minimale {{minValue}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 0",
|
|
46
|
+
maxValueMustBeLessThan: "La valeur maximale {{maxValue}} doit \xEAtre inf\xE9rieure \xE0 {{domain}}"
|
|
47
|
+
},
|
|
48
|
+
RegExpValidator: {
|
|
49
|
+
stringDoesNotMatchPattern: "La cha\xEEne {{s}} ne correspond pas au mod\xE8le"
|
|
50
|
+
},
|
|
51
|
+
CharacterSetValidator: {
|
|
52
|
+
firstZeroFirstCharacter: "Le jeu de caract\xE8res doit prendre en charge z\xE9ro comme premier caract\xE8re",
|
|
53
|
+
allNumericAllNumericCharacters: "Le jeu de caract\xE8res doit prendre en charge tous les caract\xE8res num\xE9riques en s\xE9quence",
|
|
54
|
+
stringMustNotBeAllNumeric: "La cha\xEEne ne doit pas \xEAtre enti\xE8rement num\xE9rique",
|
|
55
|
+
lengthMustBeGreaterThanOrEqualTo: "La longueur {{length}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 {{minimumLength}}",
|
|
56
|
+
lengthMustBeLessThanOrEqualTo: "La longueur {{length}} doit \xEAtre inf\xE9rieure ou \xE9gale \xE0 {{maximumLength}}",
|
|
57
|
+
lengthMustBeEqualTo: "La longueur {{length}} doit \xEAtre \xE9gale \xE0 {{exactLength}}",
|
|
58
|
+
lengthOfComponentMustBeGreaterThanOrEqualTo: "La longueur {{length}} de {{component}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 {{minimumLength}}",
|
|
59
|
+
lengthOfComponentMustBeLessThanOrEqualTo: "La longueur {{length}} de {{component}} doit \xEAtre inf\xE9rieure ou \xE9gale \xE0 {{maximumLength}}",
|
|
60
|
+
lengthOfComponentMustBeEqualTo: "La longueur {{length}} de {{component}} doit \xEAtre \xE9gale \xE0 {{exactLength}}",
|
|
61
|
+
invalidCharacterAtPosition: "Caract\xE8re non valide '{{c}}' \xE0 la position {{position}}",
|
|
62
|
+
invalidCharacterAtPositionOfComponent: "Caract\xE8re non valide '{{c}}' \xE0 la position {{position}} de {{component}}",
|
|
63
|
+
exclusionNotSupported: "La valeur d'exclusion de {{exclusion}} n'est pas prise en charge",
|
|
64
|
+
invalidTweakWithAllNumericExclusion: "Le r\xE9glage ne doit pas \xEAtre utilis\xE9 avec une exclusion enti\xE8rement num\xE9rique",
|
|
65
|
+
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}}"
|
|
66
|
+
},
|
|
67
|
+
RecordValidator: {
|
|
68
|
+
typeNameKeyNotFound: '{{typeName}} "{{key}}" introuvable'
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/locale/i18n.ts
|
|
73
|
+
var utilityNS = "aidct_utility";
|
|
74
|
+
i18nAssertValidResources(localeStrings, "fr", localeStrings2);
|
|
75
|
+
i18nAddResourceBundle("en", utilityNS, localeStrings);
|
|
76
|
+
i18nAddResourceBundle("fr", utilityNS, localeStrings2);
|
|
77
|
+
var i18n_default = i18next;
|
|
78
|
+
|
|
1
79
|
// src/iterator_proxy.ts
|
|
2
80
|
var IteratorProxyBase = class _IteratorProxyBase {
|
|
3
81
|
/**
|
|
@@ -500,84 +578,6 @@ var Sequencer = class {
|
|
|
500
578
|
}
|
|
501
579
|
};
|
|
502
580
|
|
|
503
|
-
// src/locale/i18n.ts
|
|
504
|
-
import { i18nAddResourceBundle, i18nAssertValidResources, i18next } from "@aidc-toolkit/core";
|
|
505
|
-
|
|
506
|
-
// src/locale/en/locale_strings.ts
|
|
507
|
-
var localeStrings = {
|
|
508
|
-
Transformer: {
|
|
509
|
-
domainMustBeGreaterThanZero: "Domain {{domain}} must be greater than 0",
|
|
510
|
-
tweakMustBeGreaterThanOrEqualToZero: "Tweak {{tweak}} must be greater than or equal to 0",
|
|
511
|
-
valueMustBeGreaterThanOrEqualToZero: "Value {{value}} must be greater than or equal to 0",
|
|
512
|
-
valueMustBeLessThan: "Value {{value}} must be less than {{domain}}",
|
|
513
|
-
minValueMustBeGreaterThanOrEqualToZero: "Minimum value {{minValue}} must be greater than or equal to 0",
|
|
514
|
-
maxValueMustBeLessThan: "Maximum value {{maxValue}} must be less than {{domain}}"
|
|
515
|
-
},
|
|
516
|
-
RegExpValidator: {
|
|
517
|
-
stringDoesNotMatchPattern: "String {{s}} does not match pattern"
|
|
518
|
-
},
|
|
519
|
-
CharacterSetValidator: {
|
|
520
|
-
firstZeroFirstCharacter: "Character set must support zero as first character",
|
|
521
|
-
allNumericAllNumericCharacters: "Character set must support all numeric characters in sequence",
|
|
522
|
-
stringMustNotBeAllNumeric: "String must not be all numeric",
|
|
523
|
-
lengthMustBeGreaterThanOrEqualTo: "Length {{length}} must be greater than or equal to {{minimumLength}}",
|
|
524
|
-
lengthMustBeLessThanOrEqualTo: "Length {{length}} must be less than or equal to {{maximumLength}}",
|
|
525
|
-
lengthMustBeEqualTo: "Length {{length}} must be equal to {{exactLength}}",
|
|
526
|
-
lengthOfComponentMustBeGreaterThanOrEqualTo: "Length {{length}} of {{component}} must be greater than or equal to {{minimumLength}}",
|
|
527
|
-
lengthOfComponentMustBeLessThanOrEqualTo: "Length {{length}} of {{component}} must be less than or equal to {{maximumLength}}",
|
|
528
|
-
lengthOfComponentMustBeEqualTo: "Length {{length}} of {{component}} must be equal to {{exactLength}}",
|
|
529
|
-
invalidCharacterAtPosition: "Invalid character '{{c}}' at position {{position}}",
|
|
530
|
-
invalidCharacterAtPositionOfComponent: "Invalid character '{{c}}' at position {{position}} of {{component}}",
|
|
531
|
-
exclusionNotSupported: "Exclusion value of {{exclusion}} is not supported",
|
|
532
|
-
invalidTweakWithAllNumericExclusion: "Tweak must not be used with all-numeric exclusion",
|
|
533
|
-
endSequenceValueMustBeLessThanOrEqualTo: "End sequence value (start sequence value + count - 1) must be less than {{domain}}"
|
|
534
|
-
},
|
|
535
|
-
RecordValidator: {
|
|
536
|
-
typeNameKeyNotFound: '{{typeName}} "{{key}}" not found'
|
|
537
|
-
}
|
|
538
|
-
};
|
|
539
|
-
|
|
540
|
-
// src/locale/fr/locale_strings.ts
|
|
541
|
-
var localeStrings2 = {
|
|
542
|
-
Transformer: {
|
|
543
|
-
domainMustBeGreaterThanZero: "Le domaine {{domain}} doit \xEAtre sup\xE9rieur \xE0 0",
|
|
544
|
-
tweakMustBeGreaterThanOrEqualToZero: "Le r\xE9glage {{tweak}} doit \xEAtre sup\xE9rieur ou \xE9gal \xE0 0",
|
|
545
|
-
valueMustBeGreaterThanOrEqualToZero: "La valeur {{value}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 0",
|
|
546
|
-
valueMustBeLessThan: "La valeur {{value}} doit \xEAtre inf\xE9rieure \xE0 {{domain}}",
|
|
547
|
-
minValueMustBeGreaterThanOrEqualToZero: "La valeur minimale {{minValue}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 0",
|
|
548
|
-
maxValueMustBeLessThan: "La valeur maximale {{maxValue}} doit \xEAtre inf\xE9rieure \xE0 {{domain}}"
|
|
549
|
-
},
|
|
550
|
-
RegExpValidator: {
|
|
551
|
-
stringDoesNotMatchPattern: "La cha\xEEne {{s}} ne correspond pas au mod\xE8le"
|
|
552
|
-
},
|
|
553
|
-
CharacterSetValidator: {
|
|
554
|
-
firstZeroFirstCharacter: "Le jeu de caract\xE8res doit prendre en charge z\xE9ro comme premier caract\xE8re",
|
|
555
|
-
allNumericAllNumericCharacters: "Le jeu de caract\xE8res doit prendre en charge tous les caract\xE8res num\xE9riques en s\xE9quence",
|
|
556
|
-
stringMustNotBeAllNumeric: "La cha\xEEne ne doit pas \xEAtre enti\xE8rement num\xE9rique",
|
|
557
|
-
lengthMustBeGreaterThanOrEqualTo: "La longueur {{length}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 {{minimumLength}}",
|
|
558
|
-
lengthMustBeLessThanOrEqualTo: "La longueur {{length}} doit \xEAtre inf\xE9rieure ou \xE9gale \xE0 {{maximumLength}}",
|
|
559
|
-
lengthMustBeEqualTo: "La longueur {{length}} doit \xEAtre \xE9gale \xE0 {{exactLength}}",
|
|
560
|
-
lengthOfComponentMustBeGreaterThanOrEqualTo: "La longueur {{length}} de {{component}} doit \xEAtre sup\xE9rieure ou \xE9gale \xE0 {{minimumLength}}",
|
|
561
|
-
lengthOfComponentMustBeLessThanOrEqualTo: "La longueur {{length}} de {{component}} doit \xEAtre inf\xE9rieure ou \xE9gale \xE0 {{maximumLength}}",
|
|
562
|
-
lengthOfComponentMustBeEqualTo: "La longueur {{length}} de {{component}} doit \xEAtre \xE9gale \xE0 {{exactLength}}",
|
|
563
|
-
invalidCharacterAtPosition: "Caract\xE8re non valide '{{c}}' \xE0 la position {{position}}",
|
|
564
|
-
invalidCharacterAtPositionOfComponent: "Caract\xE8re non valide '{{c}}' \xE0 la position {{position}} de {{component}}",
|
|
565
|
-
exclusionNotSupported: "La valeur d'exclusion de {{exclusion}} n'est pas prise en charge",
|
|
566
|
-
invalidTweakWithAllNumericExclusion: "Le r\xE9glage ne doit pas \xEAtre utilis\xE9 avec une exclusion enti\xE8rement num\xE9rique",
|
|
567
|
-
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}}"
|
|
568
|
-
},
|
|
569
|
-
RecordValidator: {
|
|
570
|
-
typeNameKeyNotFound: '{{typeName}} "{{key}}" introuvable'
|
|
571
|
-
}
|
|
572
|
-
};
|
|
573
|
-
|
|
574
|
-
// src/locale/i18n.ts
|
|
575
|
-
var utilityNS = "aidct_utility";
|
|
576
|
-
i18nAssertValidResources(localeStrings, "fr", localeStrings2);
|
|
577
|
-
i18nAddResourceBundle("en", utilityNS, localeStrings);
|
|
578
|
-
i18nAddResourceBundle("fr", utilityNS, localeStrings2);
|
|
579
|
-
var i18n_default = i18next;
|
|
580
|
-
|
|
581
581
|
// src/transformer.ts
|
|
582
582
|
var Transformer = class _Transformer {
|
|
583
583
|
/**
|
|
@@ -660,28 +660,14 @@ var Transformer = class _Transformer {
|
|
|
660
660
|
}));
|
|
661
661
|
}
|
|
662
662
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
*
|
|
666
|
-
* @template T
|
|
667
|
-
* Type returned by transformation callback.
|
|
668
|
-
*
|
|
669
|
-
* @param valueOrValues
|
|
670
|
-
* Value(s).
|
|
671
|
-
*
|
|
672
|
-
* @param transformationCallback
|
|
673
|
-
* Called after value(s) is/are transformed to convert it/them to its/their final value(s).
|
|
674
|
-
*
|
|
675
|
-
* @returns
|
|
676
|
-
* Value(s) transformed into object(s).
|
|
677
|
-
*/
|
|
678
|
-
forward(valueOrValues, transformationCallback) {
|
|
663
|
+
// eslint-disable-next-line jsdoc/require-jsdoc -- Implementation of overloaded signatures.
|
|
664
|
+
forward(valueOrValues, transformerCallback) {
|
|
679
665
|
let result;
|
|
680
666
|
if (typeof valueOrValues !== "object") {
|
|
681
667
|
const valueN = BigInt(valueOrValues);
|
|
682
668
|
this.validate(valueN);
|
|
683
669
|
const transformedValue = this.doForward(valueN);
|
|
684
|
-
result =
|
|
670
|
+
result = transformerCallback === void 0 ? transformedValue : transformerCallback(transformedValue, 0);
|
|
685
671
|
} else if (valueOrValues instanceof Sequencer) {
|
|
686
672
|
if (valueOrValues.minValue < 0n) {
|
|
687
673
|
throw new RangeError(i18n_default.t("Transformer.minValueMustBeGreaterThanOrEqualToZero", {
|
|
@@ -696,16 +682,16 @@ var Transformer = class _Transformer {
|
|
|
696
682
|
domain: this.domain
|
|
697
683
|
}));
|
|
698
684
|
}
|
|
699
|
-
result =
|
|
685
|
+
result = transformerCallback === void 0 ? IteratorProxy.from(valueOrValues).map((value) => this.doForward(value)) : IteratorProxy.from(valueOrValues).map((value, index) => transformerCallback(this.doForward(value), index));
|
|
700
686
|
} else {
|
|
701
|
-
result =
|
|
687
|
+
result = transformerCallback === void 0 ? IteratorProxy.from(valueOrValues).map((value) => {
|
|
702
688
|
const valueN = BigInt(value);
|
|
703
689
|
this.validate(valueN);
|
|
704
690
|
return this.doForward(valueN);
|
|
705
691
|
}) : IteratorProxy.from(valueOrValues).map((value, index) => {
|
|
706
692
|
const valueN = BigInt(value);
|
|
707
693
|
this.validate(valueN);
|
|
708
|
-
return
|
|
694
|
+
return transformerCallback(this.doForward(valueN), index);
|
|
709
695
|
});
|
|
710
696
|
}
|
|
711
697
|
return result;
|
|
@@ -1387,17 +1373,21 @@ var CharacterSetCreator = class _CharacterSetCreator extends CharacterSetValidat
|
|
|
1387
1373
|
exclusionDomains[1 /* FirstZero */] = exclusionFirstZeroDomains;
|
|
1388
1374
|
}
|
|
1389
1375
|
if (exclusionSupport.includes(2 /* AllNumeric */)) {
|
|
1376
|
+
let validateNumberIndexes2 = function(numberIndexes2) {
|
|
1377
|
+
let expectedNumberIndex = numberIndexes2[0];
|
|
1378
|
+
for (const numberIndex of numberIndexes2) {
|
|
1379
|
+
if (numberIndex === void 0 || numberIndex !== expectedNumberIndex) {
|
|
1380
|
+
throw new RangeError(i18n_default.t("CharacterSetValidator.allNumericAllNumericCharacters", {
|
|
1381
|
+
ns: utilityNS
|
|
1382
|
+
}));
|
|
1383
|
+
}
|
|
1384
|
+
expectedNumberIndex = numberIndex + 1;
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
var validateNumberIndexes = validateNumberIndexes2;
|
|
1390
1388
|
const exclusionAllNumericDomains = new Array(_CharacterSetCreator.MAXIMUM_STRING_LENGTH + 1);
|
|
1391
1389
|
const numberIndexes = this.characterIndexes("0123456789");
|
|
1392
|
-
|
|
1393
|
-
for (const numberIndex of numberIndexes) {
|
|
1394
|
-
if (numberIndex === void 0 || numberIndex !== expectedNumberIndex) {
|
|
1395
|
-
throw new RangeError(i18n_default.t("CharacterSetValidator.allNumericAllNumericCharacters", {
|
|
1396
|
-
ns: utilityNS
|
|
1397
|
-
}));
|
|
1398
|
-
}
|
|
1399
|
-
expectedNumberIndex = numberIndex + 1;
|
|
1400
|
-
}
|
|
1390
|
+
validateNumberIndexes2(numberIndexes);
|
|
1401
1391
|
const zeroIndex = BigInt(numberIndexes[0]);
|
|
1402
1392
|
const allZerosValues = new Array(_CharacterSetCreator.MAXIMUM_STRING_LENGTH + 1);
|
|
1403
1393
|
let allZerosValue = 0n;
|
|
@@ -1484,8 +1474,30 @@ var CharacterSetCreator = class _CharacterSetCreator extends CharacterSetValidat
|
|
|
1484
1474
|
}));
|
|
1485
1475
|
}
|
|
1486
1476
|
}
|
|
1487
|
-
|
|
1488
|
-
|
|
1477
|
+
/**
|
|
1478
|
+
* Create string(s) by mapping value(s) to the equivalent characters in the character set across the length of the
|
|
1479
|
+
* string.
|
|
1480
|
+
*
|
|
1481
|
+
* @param length
|
|
1482
|
+
* Required string length.
|
|
1483
|
+
*
|
|
1484
|
+
* @param valueOrValues
|
|
1485
|
+
* Numeric value(s) of the string(s).
|
|
1486
|
+
*
|
|
1487
|
+
* @param exclusion
|
|
1488
|
+
* String(s) to be excluded from the range of outputs. See {@link Exclusion} for possible values and their meaning.
|
|
1489
|
+
*
|
|
1490
|
+
* @param tweak
|
|
1491
|
+
* If provided, the numerical value of the string(s) is/are "tweaked" using an {@link EncryptionTransformer |
|
|
1492
|
+
* encryption transformer}.
|
|
1493
|
+
*
|
|
1494
|
+
* @param creatorCallback
|
|
1495
|
+
* If provided, called after each string is constructed to create the final value.
|
|
1496
|
+
*
|
|
1497
|
+
* @returns
|
|
1498
|
+
* String(s) created from the value(s).
|
|
1499
|
+
*/
|
|
1500
|
+
create(length, valueOrValues, exclusion = 0 /* None */, tweak, creatorCallback) {
|
|
1489
1501
|
this.validateLength(length);
|
|
1490
1502
|
this.validateExclusion(exclusion);
|
|
1491
1503
|
const allZerosValue = exclusion === 2 /* AllNumeric */ ? this._allZerosValues[length] : 0n;
|
|
@@ -1504,7 +1516,7 @@ var CharacterSetCreator = class _CharacterSetCreator extends CharacterSetValidat
|
|
|
1504
1516
|
}
|
|
1505
1517
|
s = this.character(exclusion === 1 /* FirstZero */ ? Number(convertValue % this._characterSetSizeMinusOneN) + 1 : Number(convertValue % this._characterSetSizeN)) + s;
|
|
1506
1518
|
}
|
|
1507
|
-
return
|
|
1519
|
+
return creatorCallback !== void 0 ? creatorCallback(s, index) : s;
|
|
1508
1520
|
});
|
|
1509
1521
|
}
|
|
1510
1522
|
/**
|
|
@@ -1670,5 +1682,6 @@ export {
|
|
|
1670
1682
|
RecordValidator,
|
|
1671
1683
|
RegExpValidator,
|
|
1672
1684
|
Sequencer,
|
|
1673
|
-
Transformer
|
|
1685
|
+
Transformer,
|
|
1686
|
+
utilityNS
|
|
1674
1687
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidc-toolkit/utility",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7-beta",
|
|
4
4
|
"description": "Foundational utilities for AIDC Toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,22 +19,21 @@
|
|
|
19
19
|
"url": "https://www.linkedin.com/in/kdean"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
-
"
|
|
22
|
+
"lint": "eslint .",
|
|
23
23
|
"build": "tsup src/index.ts --clean --format cjs,esm --dts",
|
|
24
24
|
"build-doc": "npm run build && tsc src/index.ts --outDir dist --target esnext --moduleResolution nodenext --module nodenext --emitDeclarationOnly --declaration --declarationMap",
|
|
25
25
|
"test": "vitest run"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@aidc-toolkit/dev": "^0.9.
|
|
29
|
-
"eslint": "^9.
|
|
28
|
+
"@aidc-toolkit/dev": "^0.9.7-beta",
|
|
29
|
+
"eslint": "^9.16.0",
|
|
30
30
|
"ts-node": "^10.9.2",
|
|
31
31
|
"tsup": "^8.3.5",
|
|
32
|
-
"typescript": "^5.
|
|
33
|
-
"vitest": "^2.1.
|
|
32
|
+
"typescript": "^5.7.2",
|
|
33
|
+
"vitest": "^2.1.8"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@aidc-toolkit/core": "^0.9.
|
|
37
|
-
"@rollup/rollup-linux-x64-gnu": "^4.
|
|
38
|
-
"i18next": "^23.16.8"
|
|
36
|
+
"@aidc-toolkit/core": "^0.9.7-beta",
|
|
37
|
+
"@rollup/rollup-linux-x64-gnu": "^4.28.1"
|
|
39
38
|
}
|
|
40
39
|
}
|