@aidc-toolkit/utility 1.0.24-beta → 1.0.26-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.
Files changed (72) hide show
  1. package/dist/character-set.d.ts +308 -0
  2. package/dist/character-set.d.ts.map +1 -0
  3. package/dist/character-set.js +564 -0
  4. package/dist/character-set.js.map +1 -0
  5. package/dist/exclusion.d.ts +26 -0
  6. package/dist/exclusion.d.ts.map +1 -0
  7. package/dist/exclusion.js +18 -0
  8. package/dist/exclusion.js.map +1 -0
  9. package/dist/index.d.ts +26 -947
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +8 -3504
  12. package/dist/index.js.map +1 -1
  13. package/dist/iterable-utility.d.ts +39 -0
  14. package/dist/iterable-utility.d.ts.map +1 -0
  15. package/dist/iterable-utility.js +35 -0
  16. package/dist/iterable-utility.js.map +1 -0
  17. package/dist/locale/en/locale-resources.d.ts +33 -0
  18. package/dist/locale/en/locale-resources.d.ts.map +1 -0
  19. package/dist/locale/en/locale-resources.js +32 -0
  20. package/dist/locale/en/locale-resources.js.map +1 -0
  21. package/dist/locale/fr/locale-resources.d.ts +33 -0
  22. package/dist/locale/fr/locale-resources.d.ts.map +1 -0
  23. package/dist/locale/fr/locale-resources.js +32 -0
  24. package/dist/locale/fr/locale-resources.js.map +1 -0
  25. package/dist/locale/i18n.d.ts +27 -0
  26. package/dist/locale/i18n.d.ts.map +1 -0
  27. package/dist/locale/i18n.js +34 -0
  28. package/dist/locale/i18n.js.map +1 -0
  29. package/dist/record.d.ts +44 -0
  30. package/dist/record.d.ts.map +1 -0
  31. package/dist/record.js +58 -0
  32. package/dist/record.js.map +1 -0
  33. package/dist/reg-exp.d.ts +43 -0
  34. package/dist/reg-exp.d.ts.map +1 -0
  35. package/dist/reg-exp.js +55 -0
  36. package/dist/reg-exp.js.map +1 -0
  37. package/dist/sequence.d.ts +68 -0
  38. package/dist/sequence.d.ts.map +1 -0
  39. package/dist/sequence.js +96 -0
  40. package/dist/sequence.js.map +1 -0
  41. package/dist/string.d.ts +25 -0
  42. package/dist/string.d.ts.map +1 -0
  43. package/dist/string.js +2 -0
  44. package/dist/string.js.map +1 -0
  45. package/dist/transformer.d.ts +347 -0
  46. package/dist/transformer.d.ts.map +1 -0
  47. package/dist/transformer.js +457 -0
  48. package/dist/transformer.js.map +1 -0
  49. package/package.json +11 -7
  50. package/src/character-set.ts +20 -19
  51. package/src/exclusion.ts +6 -1
  52. package/src/index.ts +9 -9
  53. package/src/locale/i18n.ts +3 -3
  54. package/src/locale/i18next.d.ts +1 -1
  55. package/src/record.ts +2 -2
  56. package/src/reg-exp.ts +7 -7
  57. package/src/string.ts +3 -3
  58. package/src/transformer.ts +19 -18
  59. package/test/character-set.test.ts +1 -1
  60. package/test/record.test.ts +4 -2
  61. package/test/reg-exp.test.ts +1 -1
  62. package/test/sequence.test.ts +1 -1
  63. package/test/setup.ts +1 -1
  64. package/test/transformer.test.ts +1 -1
  65. package/tsconfig-config.json +4 -0
  66. package/tsconfig-src.json +8 -0
  67. package/tsconfig-test.json +9 -0
  68. package/tsconfig.json +12 -1
  69. package/tsup.config.ts +3 -2
  70. package/dist/index.cjs +0 -3569
  71. package/dist/index.cjs.map +0 -1
  72. package/dist/index.d.cts +0 -947
package/src/index.ts CHANGED
@@ -14,12 +14,12 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- export * from "./locale/i18n";
18
- export * from "./sequence";
19
- export * from "./iterable-utility";
20
- export * from "./transformer";
21
- export type * from "./string";
22
- export * from "./reg-exp";
23
- export * from "./record";
24
- export * from "./exclusion";
25
- export * from "./character-set";
17
+ export * from "./locale/i18n.js";
18
+ export * from "./sequence.js";
19
+ export * from "./iterable-utility.js";
20
+ export * from "./transformer.js";
21
+ export type * from "./string.js";
22
+ export * from "./reg-exp.js";
23
+ export * from "./record.js";
24
+ export * from "./exclusion.js";
25
+ export * from "./character-set.js";
@@ -1,7 +1,7 @@
1
1
  import { i18nCoreInit, type I18nEnvironment } from "@aidc-toolkit/core";
2
2
  import i18next, { type i18n, type Resource } from "i18next";
3
- import enLocaleResources from "./en/locale-resources";
4
- import frLocaleResources from "./fr/locale-resources";
3
+ import enLocaleResources from "./en/locale-resources.js";
4
+ import frLocaleResources from "./fr/locale-resources.js";
5
5
 
6
6
  export const utilityNS = "aidct_utility";
7
7
 
@@ -22,7 +22,7 @@ export const utilityResources: Resource = {
22
22
  }
23
23
  };
24
24
 
25
- // Explicit type is necessary to work around bug in type discovery with linked packages.
25
+ // Explicit type is necessary because type can't be inferred without additional references.
26
26
  export const i18nextUtility: i18n = i18next.createInstance();
27
27
 
28
28
  /**
@@ -1,4 +1,4 @@
1
- import type { UtilityLocaleResources } from "./i18n";
1
+ import type { UtilityLocaleResources } from "./i18n.js";
2
2
 
3
3
  /**
4
4
  * Internationalization module.
package/src/record.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { i18nextUtility } from "./locale/i18n";
2
- import type { StringValidator } from "./string";
1
+ import { i18nextUtility } from "./locale/i18n.js";
2
+ import type { StringValidator } from "./string.js";
3
3
 
4
4
  /**
5
5
  * Record validator. Validation is performed against a record with a string key type and throws an error if the key is
package/src/reg-exp.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { i18nextUtility } from "./locale/i18n";
2
- import type { StringValidator } from "./string";
1
+ import { i18nextUtility } from "./locale/i18n.js";
2
+ import type { StringValidator } from "./string.js";
3
3
 
4
4
  /**
5
5
  * Regular expression validator. The regular expression applies to the full string only if constructed as such. For
6
- * example, <code>&#x2F;\d&#x2A;&#x2F;</code> (0 or more digits) matches every string, <code>&#x2F;\d+&#x2F;</code>
7
- * (1 or more digits) matches strings with at least one digit, <code>&#x2F;^\d&#x2A;$&#x2F;</code> matches strings that
8
- * are all digits or empty, and <code>&#x2F;^\d+$&#x2F;</code> matches strings that are all digits and not empty.
6
+ * example, <code>&#x2F;\d&#x2A;&#x2F;</code> (0 or more digits) matches every string, <code>&#x2F;\d+&#x2F;</code> (1
7
+ * or more digits) matches strings with at least one digit, <code>&#x2F;^\d&#x2A;$&#x2F;</code> matches strings that are
8
+ * all digits or empty, and <code>&#x2F;^\d+$&#x2F;</code> matches strings that are all digits and not empty.
9
9
  *
10
- * Clients of this class are recommended to override the {@link createErrorMessage} method create a more suitable error
11
- * message for their use case.
10
+ * Clients of this class are recommended to override the {@linkcode createErrorMessage | createErrorMessage()} method
11
+ * to create a more suitable error message for their use case.
12
12
  */
13
13
  export class RegExpValidator implements StringValidator {
14
14
  /**
package/src/string.ts CHANGED
@@ -8,10 +8,10 @@ export interface StringValidation {
8
8
  /**
9
9
  * String validator interface.
10
10
  *
11
- * @template V
11
+ * @template TStringValidation
12
12
  * String validation type.
13
13
  */
14
- export interface StringValidator<V extends StringValidation = StringValidation> {
14
+ export interface StringValidator<TStringValidation extends StringValidation = StringValidation> {
15
15
  /**
16
16
  * Validate a string and throw an error if validation fails.
17
17
  *
@@ -21,5 +21,5 @@ export interface StringValidator<V extends StringValidation = StringValidation>
21
21
  * @param validation
22
22
  * String validation parameters.
23
23
  */
24
- validate: (s: string, validation?: V) => void;
24
+ validate: (s: string, validation?: TStringValidation) => void;
25
25
  }
@@ -1,6 +1,6 @@
1
- import { type IndexedCallback, mapIterable } from "./iterable-utility";
2
- import { i18nextUtility } from "./locale/i18n";
3
- import { Sequence } from "./sequence";
1
+ import { type IndexedCallback, mapIterable } from "./iterable-utility.js";
2
+ import { i18nextUtility } from "./locale/i18n.js";
3
+ import { Sequence } from "./sequence.js";
4
4
 
5
5
  /**
6
6
  * Transformer primitive type.
@@ -43,11 +43,12 @@ export type TransformerOutput<TTransformerInput extends TransformerInput<Transfo
43
43
  * into values in the same domain, typically for storage in a database where the data type and length are already fixed
44
44
  * and exfiltration of the data can have significant repercussions.
45
45
  *
46
- * Two subclasses are supported directly by this class: {@link IdentityTransformer} (which operates based on a domain
47
- * only) and {@link EncryptionTransformer} (which operates based on a domain and a tweak). If an application is expected
48
- * to make repeated use of a transformer with the same domain and (optional) tweak and can't manage the transformer
49
- * object, an in-memory cache is available via the {@link get} method. Properties in {@link IdentityTransformer} and
50
- * {@link EncryptionTransformer} are read-only once constructed, so there is no issue with their shared use.
46
+ * Two subclasses are supported directly by this class: {@linkcode IdentityTransformer} (which operates based on a
47
+ * domain only) and {@linkcode EncryptionTransformer} (which operates based on a domain and a tweak). If an application
48
+ * is expected to make repeated use of a transformer with the same domain and (optional) tweak and can't manage the
49
+ * transformer object, an in-memory cache is available via the {@linkcode get | get()} method. Properties in {@linkcode
50
+ * IdentityTransformer} and {@linkcode EncryptionTransformer} are read-only once constructed, so there is no issue with
51
+ * their shared use.
51
52
  */
52
53
  export abstract class Transformer {
53
54
  /**
@@ -77,10 +78,10 @@ export abstract class Transformer {
77
78
  }
78
79
 
79
80
  /**
80
- * Get a transformer, constructing it if necessary. The type returned is {@link IdentityTransformer} if tweak is
81
- * undefined, {@link EncryptionTransformer} if tweak is defined. Note that although an {@link EncryptionTransformer}
82
- * with a zero tweak operates as an {@link IdentityTransformer}, {@link EncryptionTransformer} is still the type
83
- * returned if a zero tweak is explicitly specified.
81
+ * Get a transformer, constructing it if necessary. The type returned is {@linkcode IdentityTransformer} if tweak is
82
+ * undefined, {@linkcode EncryptionTransformer} if tweak is defined. Note that although an {@linkcode
83
+ * EncryptionTransformer} with a zero tweak operates as an {@linkcode IdentityTransformer}, {@linkcode
84
+ * EncryptionTransformer} is still the type returned if a zero tweak is explicitly specified.
84
85
  *
85
86
  * @param domain
86
87
  * Domain.
@@ -89,7 +90,7 @@ export abstract class Transformer {
89
90
  * Tweak.
90
91
  *
91
92
  * @returns
92
- * {@link IdentityTransformer} if tweak is undefined, {@link EncryptionTransformer} if tweak is defined.
93
+ * {@linkcode IdentityTransformer} if tweak is undefined, {@linkcode EncryptionTransformer} if tweak is defined.
93
94
  */
94
95
  static get(domain: number | bigint, tweak?: number | bigint): Transformer {
95
96
  const domainN = BigInt(domain);
@@ -195,7 +196,7 @@ export abstract class Transformer {
195
196
  * Value(s) input type.
196
197
  *
197
198
  * @param valueOrValues
198
- * Value(s). If this is an instance of {@link Sequence}, the minimum and maximum values are validated prior to
199
+ * Value(s). If this is an instance of {@linkcode Sequence}, the minimum and maximum values are validated prior to
199
200
  * transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
200
201
  *
201
202
  * @returns
@@ -213,7 +214,7 @@ export abstract class Transformer {
213
214
  * Transformation callback output type.
214
215
  *
215
216
  * @param valueOrValues
216
- * Value(s). If this is an instance of {@link Sequence}, the minimum and maximum values are validated prior to
217
+ * Value(s). If this is an instance of {@linkcode Sequence}, the minimum and maximum values are validated prior to
217
218
  * transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
218
219
  *
219
220
  * @param transformerCallback
@@ -305,9 +306,9 @@ export class IdentityTransformer extends Transformer {
305
306
  /**
306
307
  * Encryption transformer. Values are transformed using repeated shuffle and xor operations, similar to those found in
307
308
  * many cryptography algorithms, particularly AES. While sufficient for obfuscation of numeric sequences (e.g., serial
308
- * number generation, below), if true format-preserving encryption is required, a more robust algorithm such as
309
- * {@link https://doi.org/10.6028/NIST.SP.800-38Gr1-draft | FF1} is recommended. Furthermore, no work has been done to
310
- * mitigate {@link https://timing.attacks.cr.yp.to/index.html | timing attacks} for key detection.
309
+ * number generation, below), if true format-preserving encryption is required, a more robust algorithm such as {@link
310
+ * https://doi.org/10.6028/NIST.SP.800-38Gr1.2pd | FF1} is recommended. Furthermore, no work has been done to mitigate
311
+ * {@link https://timing.attacks.cr.yp.to/index.html | timing attacks} for key detection.
311
312
  *
312
313
  * The purpose of the encryption transformer is to generate pseudo-random values in a deterministic manner to obscure
313
314
  * the sequence of values generated over time. A typical example is for serial number generation, where knowledge of the
@@ -13,7 +13,7 @@ import {
13
13
  NUMERIC_CREATOR,
14
14
  NUMERIC_VALIDATOR,
15
15
  Sequence
16
- } from "../src";
16
+ } from "../src/index.js";
17
17
 
18
18
  // Type is used to ensure that testCharacterSet() is not called with creator twice.
19
19
  type ValidatorNotCreator<T extends CharacterSetValidator> = T extends CharacterSetCreator ? never : T;
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from "vitest";
2
- import { RecordValidator } from "../src";
2
+ import { RecordValidator } from "../src/index.js";
3
3
 
4
4
  describe("Record validator", () => {
5
5
  const StringIndexes = {
@@ -9,7 +9,9 @@ describe("Record validator", () => {
9
9
  ValueD: "D"
10
10
  } as const;
11
11
 
12
- type StringIndex = typeof StringIndexes[keyof typeof StringIndexes];
12
+ type StringIndexKey = keyof typeof StringIndexes;
13
+
14
+ type StringIndex = typeof StringIndexes[StringIndexKey];
13
15
 
14
16
  const stringRecord: Record<StringIndex, string> = {
15
17
  [StringIndexes.ValueA]: "This is for Value A",
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from "vitest";
2
- import { RegExpValidator } from "../src";
2
+ import { RegExpValidator } from "../src/index.js";
3
3
 
4
4
  describe("Regular expression validator", () => {
5
5
  test("Validation", () => {
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from "vitest";
2
- import { Sequence } from "../src";
2
+ import { Sequence } from "../src/index.js";
3
3
 
4
4
  describe("Sequence", () => {
5
5
  const sequence1 = new Sequence(10, 20);
package/test/setup.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { I18nEnvironments } from "@aidc-toolkit/core";
2
- import { i18nUtilityInit } from "../src";
2
+ import { i18nUtilityInit } from "../src/index.js";
3
3
 
4
4
  await i18nUtilityInit(I18nEnvironments.CLI);
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from "vitest";
2
- import { EncryptionTransformer, IdentityTransformer, Sequence, Transformer } from "../src";
2
+ import { EncryptionTransformer, IdentityTransformer, Sequence, Transformer } from "../src/index.js";
3
3
 
4
4
  function testTransformer(domain: number, tweak?: number, callback?: (value: bigint, forwardValue: bigint) => void): void {
5
5
  const transformer = Transformer.get(domain, tweak);
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "@aidc-toolkit/dev/tsconfig-template.json",
3
+ "files": ["./eslint.config.ts", "./tsup.config.ts", "vitest.config.ts"]
4
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "@aidc-toolkit/dev/tsconfig-template.json",
3
+ "include": ["./src/**/*"],
4
+ "compilerOptions": {
5
+ // Emit.
6
+ "outDir": "dist"
7
+ }
8
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@aidc-toolkit/dev/tsconfig-template.json",
3
+ "include": ["./test/**/*"],
4
+ "references": [
5
+ {
6
+ "path": "./tsconfig-src.json"
7
+ }
8
+ ]
9
+ }
package/tsconfig.json CHANGED
@@ -1,3 +1,14 @@
1
1
  {
2
- "extends": "@aidc-toolkit/dev/tsconfig.json"
2
+ "include": [],
3
+ "references": [
4
+ {
5
+ "path": "./tsconfig-src.json"
6
+ },
7
+ {
8
+ "path": "./tsconfig-test.json"
9
+ },
10
+ {
11
+ "path": "./tsconfig-config.json"
12
+ }
13
+ ]
3
14
  }
package/tsup.config.ts CHANGED
@@ -1,3 +1,4 @@
1
- import { tsupConfigAIDCToolkit } from "@aidc-toolkit/dev";
1
+ import { tsupConfig } from "@aidc-toolkit/dev";
2
+ import { defineConfig } from "tsup";
2
3
 
3
- export default tsupConfigAIDCToolkit;
4
+ export default defineConfig(tsupConfig);