@aidc-toolkit/utility 1.0.23-beta → 1.0.24-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/README.md +30 -30
- package/dist/index.cjs +3569 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +947 -0
- package/dist/index.d.ts +947 -26
- package/dist/index.js +3504 -8
- package/dist/index.js.map +1 -1
- package/package.json +4 -8
- package/src/character-set.ts +6 -6
- package/src/index.ts +9 -9
- package/src/locale/i18n.ts +3 -5
- package/src/locale/i18next.d.ts +1 -1
- package/src/record.ts +2 -2
- package/src/reg-exp.ts +2 -2
- package/src/transformer.ts +3 -3
- package/tsup.config.ts +3 -0
- package/typedoc.json +1 -3
- package/dist/character-set.d.ts +0 -307
- package/dist/character-set.d.ts.map +0 -1
- package/dist/character-set.js +0 -563
- package/dist/character-set.js.map +0 -1
- package/dist/exclusion.d.ts +0 -22
- package/dist/exclusion.d.ts.map +0 -1
- package/dist/exclusion.js +0 -18
- package/dist/exclusion.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/iterable-utility.d.ts +0 -39
- package/dist/iterable-utility.d.ts.map +0 -1
- package/dist/iterable-utility.js +0 -35
- package/dist/iterable-utility.js.map +0 -1
- package/dist/locale/en/locale-resources.d.ts +0 -33
- package/dist/locale/en/locale-resources.d.ts.map +0 -1
- package/dist/locale/en/locale-resources.js +0 -32
- package/dist/locale/en/locale-resources.js.map +0 -1
- package/dist/locale/fr/locale-resources.d.ts +0 -33
- package/dist/locale/fr/locale-resources.d.ts.map +0 -1
- package/dist/locale/fr/locale-resources.js +0 -32
- package/dist/locale/fr/locale-resources.js.map +0 -1
- package/dist/locale/i18n.d.ts +0 -27
- package/dist/locale/i18n.d.ts.map +0 -1
- package/dist/locale/i18n.js +0 -35
- package/dist/locale/i18n.js.map +0 -1
- package/dist/record.d.ts +0 -44
- package/dist/record.d.ts.map +0 -1
- package/dist/record.js +0 -58
- package/dist/record.js.map +0 -1
- package/dist/reg-exp.d.ts +0 -43
- package/dist/reg-exp.d.ts.map +0 -1
- package/dist/reg-exp.js +0 -55
- package/dist/reg-exp.js.map +0 -1
- package/dist/sequence.d.ts +0 -68
- package/dist/sequence.d.ts.map +0 -1
- package/dist/sequence.js +0 -96
- package/dist/sequence.js.map +0 -1
- package/dist/string.d.ts +0 -25
- package/dist/string.d.ts.map +0 -1
- package/dist/string.js +0 -2
- package/dist/string.js.map +0 -1
- package/dist/transformer.d.ts +0 -346
- package/dist/transformer.d.ts.map +0 -1
- package/dist/transformer.js +0 -456
- package/dist/transformer.js.map +0 -1
package/README.md
CHANGED
|
@@ -24,9 +24,9 @@ To provide the most flexibility and to handle the most significant demands of th
|
|
|
24
24
|
|
|
25
25
|
Many of AIDC processes can be reduced to a simple statement about sequences:
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
- "Give me a million serial numbers for manufacturing."
|
|
28
|
+
- "Generate a handful of GTINs for my new product line."
|
|
29
|
+
- "Label the containers in the shipping area with SSCCs."
|
|
30
30
|
|
|
31
31
|
Each statement has a quantity and an output. Implicit in them is the requirement that the generated output be unique, not only within itself, but also within any previous outputs generated. A [`Sequence`](https://aidc-toolkit.com/api/Utility/classes/Sequence.html) is simply a utility to generate a sequence of integers given a start value and a count.
|
|
32
32
|
|
|
@@ -34,7 +34,7 @@ Each statement has a quantity and an output. Implicit in them is the requirement
|
|
|
34
34
|
>
|
|
35
35
|
> The AIDC Toolkit is not responsible for maintaining the history of any sequence. It is up to the application to ensure that the start value and count don't overlap with any other start value and count for a sequence used for the same purpose.
|
|
36
36
|
|
|
37
|
-
#### Creating and
|
|
37
|
+
#### Creating and Using a Sequence
|
|
38
38
|
|
|
39
39
|
1. Create a sequence with a start value and a count. The count is typically positive, which means that the sequence runs from the start value up. If negative, the sequence runs from the start value down.
|
|
40
40
|
```typescript
|
|
@@ -54,7 +54,7 @@ Each statement has a quantity and an output. Implicit in them is the requirement
|
|
|
54
54
|
```
|
|
55
55
|
* Pass it to a function.
|
|
56
56
|
```typescript
|
|
57
|
-
//
|
|
57
|
+
// Create a sequence of 10-character hexadecimal strings.
|
|
58
58
|
const stringSequence = HEXADECIMAL_STRING_CREATOR.create(10, sequence);
|
|
59
59
|
```
|
|
60
60
|
|
|
@@ -122,7 +122,7 @@ flowchart TD
|
|
|
122
122
|
|
|
123
123
|
## Strings
|
|
124
124
|
|
|
125
|
-
### String
|
|
125
|
+
### String Validation
|
|
126
126
|
|
|
127
127
|
Validation is a requirement for any application. The AIDC Toolkit provides a simple but extensible validation framework built on two interfaces: [`StringValidation`](https://aidc-toolkit.com/api/Utility/interfaces/StringValidation.html) and [`StringValidator`](https://aidc-toolkit.com/api/Utility/interfaces/StringValidator.html). The two are related in that an interface extending `StringValidation` may be passed as a parameter to the [`validate()`](https://aidc-toolkit.com/api/Utility/interfaces/StringValidator#validate.html) method of a class implementing `StringValidator` to restrict validation further than the default. For example, [`CharacterSetValidator`](https://aidc-toolkit.com/api/Utility/classes/CharacterSetValidator.html) accepts a [`CharacterSetValidation`](https://aidc-toolkit.com/api/Utility/interfaces/CharacterSetValidation.html) object that can constrain the length and limit the way numeric values are expressed (e.g., exclude zero as the first character or exclude strings that are all numeric).
|
|
128
128
|
|
|
@@ -130,41 +130,41 @@ The `StringValidation` interface is a placeholder only; it's empty, which, in a
|
|
|
130
130
|
|
|
131
131
|
If a string passed to a `validate()` method is valid, the method returns; if not, a [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) is thrown.
|
|
132
132
|
|
|
133
|
-
#### Predefined
|
|
133
|
+
#### Predefined Validators
|
|
134
134
|
|
|
135
135
|
The following validator types are predefined:
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
137
|
+
- [Regular expression](https://aidc-toolkit.com/api/Utility/classes/RegExpValidator.html)
|
|
138
|
+
- Validates a string against a [regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions).
|
|
139
|
+
- [Record](https://aidc-toolkit.com/api/Utility/classes/RecordValidator.html)
|
|
140
|
+
- Validates a string by looking it up in a [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type) object.
|
|
141
|
+
- [Character set](https://aidc-toolkit.com/api/Utility/classes/CharacterSetValidator.html)
|
|
142
|
+
- Validates a string by ensuring that each character is within a defined character set, with additional validation parameters optionally constraining the length and limiting the way numeric values are expressed. Predefined character set validators are:
|
|
143
|
+
- [Numeric (0-9)](https://aidc-toolkit.com/api/Utility/variables/NUMERIC_VALIDATOR.html)
|
|
144
|
+
- [Hexadecimal (0-9, A-F)](https://aidc-toolkit.com/api/Utility/variables/HEXADECIMAL_VALIDATOR.html)
|
|
145
|
+
- [Alphabetic (A-Z)](https://aidc-toolkit.com/api/Utility/variables/ALPHABETIC_VALIDATOR.html)
|
|
146
|
+
- [Alphanumeric (0-9, A-Z)](https://aidc-toolkit.com/api/Utility/variables/ALPHANUMERIC_VALIDATOR.html)
|
|
147
147
|
|
|
148
|
-
### String
|
|
148
|
+
### String Creation
|
|
149
149
|
|
|
150
150
|
String creation varies depending on the type of string being created, so there's no single interface that can be implemented. There is a pattern, however:
|
|
151
151
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
152
|
+
- Creation is done via a `create()` method. If the class can create more than one type of string, it can define additional `create*NNN*()` methods as appropriate.
|
|
153
|
+
- The `create()` (or `create*NNN*()`) method is overloaded, with a parameter accepting either a single value to create a single string or multiple values (as `Iterable`) to create multiple strings.
|
|
154
|
+
- If the value to create a string is numeric (`number` or `bigint`), the method uses a [`Transformer`](https://aidc-toolkit.com/api/Utility/classes/Transformer.html) and supports sparse creation.
|
|
155
|
+
- Because of this, passing in a [`Sequence`](https://aidc-toolkit.com/api/Utility/classes/Sequence.html) is strongly recommended when creating multiple strings.
|
|
156
156
|
|
|
157
|
-
#### Predefined
|
|
157
|
+
#### Predefined Creators
|
|
158
158
|
|
|
159
159
|
The following creator types are predefined:
|
|
160
160
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
161
|
+
- [Character set](https://aidc-toolkit.com/api/Utility/classes/CharacterSetCreator.html)
|
|
162
|
+
- Creates strings by mapping numeric (`number` and `bigint`) values to fixed-length string representations using the character set as the "digits" of the string. Predefined character set creators are:
|
|
163
|
+
- [Numeric (0-9)](https://aidc-toolkit.com/api/Utility/variables/NUMERIC_CREATOR.html)
|
|
164
|
+
- [Hexadecimal (0-9, A-F)](https://aidc-toolkit.com/api/Utility/variables/HEXADECIMAL_CREATOR.html)
|
|
165
|
+
- [Alphabetic (A-Z)](https://aidc-toolkit.com/api/Utility/variables/ALPHABETIC_CREATOR.html)
|
|
166
|
+
- [Alphanumeric (0-9, A-Z)](https://aidc-toolkit.com/api/Utility/variables/ALPHANUMERIC_CREATOR.html)
|
|
167
167
|
|
|
168
|
-
#### Output
|
|
168
|
+
#### Output Restriction
|
|
169
169
|
|
|
170
170
|
As with string validators, string creators can restrict their output to meet the needs of certain use cases. For example, when creating serial numbers, it may be necessary to generate values that either don't start with a zero (to prevent leading zeros from being dropped by other applications) or that aren't composed entirely of digits (to prevent strings from being interpreted as numbers).
|