@aidc-toolkit/gs1 1.0.22-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/dist/index.cjs +4624 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1588 -0
- package/dist/index.d.ts +1588 -36
- package/dist/index.js +4541 -19
- package/dist/index.js.map +1 -1
- package/package.json +4 -8
- package/src/character-set.ts +16 -1
- package/src/check.ts +2 -2
- package/src/gtin-creator.ts +4 -4
- package/src/gtin-validator.ts +6 -6
- package/src/identifier-creator.ts +3 -3
- package/src/identifier-validator.ts +4 -4
- package/src/index.ts +19 -19
- package/src/locale/en/{locale-strings.ts → locale-resources.ts} +1 -1
- package/src/locale/fr/{locale-strings.ts → locale-resources.ts} +2 -2
- package/src/locale/i18n.ts +6 -8
- package/src/locale/i18next.d.ts +4 -4
- package/src/non-gtin-numeric-identifier-creator.ts +4 -4
- package/src/non-gtin-numeric-identifier-validator.ts +3 -3
- package/src/non-numeric-identifier-creator.ts +6 -6
- package/src/non-numeric-identifier-validator.ts +6 -6
- package/src/numeric-identifier-creator.ts +3 -3
- package/src/numeric-identifier-validator.ts +5 -5
- package/src/prefix-manager.ts +36 -35
- package/src/prefix-provider.ts +1 -1
- package/src/prefix-validator.ts +2 -2
- package/src/serializable-numeric-identifier-creator.ts +4 -4
- package/src/serializable-numeric-identifier-validator.ts +5 -5
- package/test/creator.test.ts +3 -3
- package/test/gtin-creator.ts +1 -1
- package/test/gtin-validator.test.ts +1 -1
- package/test/identifier-creator.ts +4 -4
- package/test/non-gtin-numeric-identifier-creator.ts +1 -1
- package/test/non-gtin-numeric-identifier-validator.ts +1 -1
- package/test/non-numeric-identifier-validator.ts +2 -2
- package/test/numeric-identifier-creator.ts +1 -1
- package/test/numeric-identifier-validator.ts +1 -1
- package/test/prefix-manager.test.ts +1 -1
- package/test/serializable-numeric-identifier-creator.ts +1 -1
- package/test/serializable-numeric-identifier-validator.ts +2 -2
- package/test/validator.test.ts +4 -4
- package/tsup.config.ts +3 -0
- package/typedoc.json +1 -3
- package/dist/character-set.d.ts +0 -22
- package/dist/character-set.d.ts.map +0 -1
- package/dist/character-set.js +0 -36
- package/dist/character-set.js.map +0 -1
- package/dist/check.d.ts +0 -81
- package/dist/check.d.ts.map +0 -1
- package/dist/check.js +0 -218
- package/dist/check.js.map +0 -1
- package/dist/gtin-creator.d.ts +0 -68
- package/dist/gtin-creator.d.ts.map +0 -1
- package/dist/gtin-creator.js +0 -158
- package/dist/gtin-creator.js.map +0 -1
- package/dist/gtin-validator.d.ts +0 -202
- package/dist/gtin-validator.d.ts.map +0 -1
- package/dist/gtin-validator.js +0 -470
- package/dist/gtin-validator.js.map +0 -1
- package/dist/identifier-creator.d.ts +0 -72
- package/dist/identifier-creator.d.ts.map +0 -1
- package/dist/identifier-creator.js +0 -50
- package/dist/identifier-creator.js.map +0 -1
- package/dist/identifier-type.d.ts +0 -58
- package/dist/identifier-type.d.ts.map +0 -1
- package/dist/identifier-type.js +0 -54
- package/dist/identifier-type.js.map +0 -1
- package/dist/identifier-validator.d.ts +0 -174
- package/dist/identifier-validator.d.ts.map +0 -1
- package/dist/identifier-validator.js +0 -145
- package/dist/identifier-validator.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/locale/en/locale-strings.d.ts +0 -42
- package/dist/locale/en/locale-strings.d.ts.map +0 -1
- package/dist/locale/en/locale-strings.js +0 -42
- package/dist/locale/en/locale-strings.js.map +0 -1
- package/dist/locale/fr/locale-strings.d.ts +0 -42
- package/dist/locale/fr/locale-strings.d.ts.map +0 -1
- package/dist/locale/fr/locale-strings.js +0 -42
- package/dist/locale/fr/locale-strings.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 -37
- package/dist/locale/i18n.js.map +0 -1
- package/dist/non-gtin-numeric-identifier-creator.d.ts +0 -30
- package/dist/non-gtin-numeric-identifier-creator.d.ts.map +0 -1
- package/dist/non-gtin-numeric-identifier-creator.js +0 -30
- package/dist/non-gtin-numeric-identifier-creator.js.map +0 -1
- package/dist/non-gtin-numeric-identifier-validator.d.ts +0 -41
- package/dist/non-gtin-numeric-identifier-validator.d.ts.map +0 -1
- package/dist/non-gtin-numeric-identifier-validator.js +0 -40
- package/dist/non-gtin-numeric-identifier-validator.js.map +0 -1
- package/dist/non-numeric-identifier-creator.d.ts +0 -55
- package/dist/non-numeric-identifier-creator.d.ts.map +0 -1
- package/dist/non-numeric-identifier-creator.js +0 -93
- package/dist/non-numeric-identifier-creator.js.map +0 -1
- package/dist/non-numeric-identifier-validator.d.ts +0 -78
- package/dist/non-numeric-identifier-validator.d.ts.map +0 -1
- package/dist/non-numeric-identifier-validator.js +0 -95
- package/dist/non-numeric-identifier-validator.js.map +0 -1
- package/dist/numeric-identifier-creator.d.ts +0 -121
- package/dist/numeric-identifier-creator.d.ts.map +0 -1
- package/dist/numeric-identifier-creator.js +0 -135
- package/dist/numeric-identifier-creator.js.map +0 -1
- package/dist/numeric-identifier-validator.d.ts +0 -76
- package/dist/numeric-identifier-validator.d.ts.map +0 -1
- package/dist/numeric-identifier-validator.js +0 -84
- package/dist/numeric-identifier-validator.js.map +0 -1
- package/dist/prefix-manager.d.ts +0 -224
- package/dist/prefix-manager.d.ts.map +0 -1
- package/dist/prefix-manager.js +0 -369
- package/dist/prefix-manager.js.map +0 -1
- package/dist/prefix-provider.d.ts +0 -27
- package/dist/prefix-provider.d.ts.map +0 -1
- package/dist/prefix-provider.js +0 -2
- package/dist/prefix-provider.js.map +0 -1
- package/dist/prefix-type.d.ts +0 -22
- package/dist/prefix-type.d.ts.map +0 -1
- package/dist/prefix-type.js +0 -18
- package/dist/prefix-type.js.map +0 -1
- package/dist/prefix-validator.d.ts +0 -58
- package/dist/prefix-validator.d.ts.map +0 -1
- package/dist/prefix-validator.js +0 -154
- package/dist/prefix-validator.js.map +0 -1
- package/dist/serializable-numeric-identifier-creator.d.ts +0 -86
- package/dist/serializable-numeric-identifier-creator.d.ts.map +0 -1
- package/dist/serializable-numeric-identifier-creator.js +0 -116
- package/dist/serializable-numeric-identifier-creator.js.map +0 -1
- package/dist/serializable-numeric-identifier-validator.d.ts +0 -79
- package/dist/serializable-numeric-identifier-validator.d.ts.map +0 -1
- package/dist/serializable-numeric-identifier-validator.js +0 -99
- package/dist/serializable-numeric-identifier-validator.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidc-toolkit/gs1",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.24-beta",
|
|
4
4
|
"description": "GS1 AIDC Toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"homepage": "https://aidc-toolkit.com/",
|
|
8
|
-
"repository":
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/aidc-toolkit/gs1.git"
|
|
11
|
-
},
|
|
8
|
+
"repository": "aidc-toolkit/gs1",
|
|
12
9
|
"bugs": {
|
|
13
10
|
"url": "https://github.com/aidc-toolkit/gs1/issues"
|
|
14
11
|
},
|
|
@@ -20,9 +17,8 @@
|
|
|
20
17
|
},
|
|
21
18
|
"scripts": {
|
|
22
19
|
"lint": "eslint",
|
|
23
|
-
"build:
|
|
24
|
-
"build:
|
|
25
|
-
"build:release": "npm run build:core -- node_modules/@aidc-toolkit/dev/tsconfig-build.json",
|
|
20
|
+
"build:dev": "tsup --define.mode=dev",
|
|
21
|
+
"build:release": "tsup",
|
|
26
22
|
"build:doc": "npm run build:dev",
|
|
27
23
|
"test": "vitest run"
|
|
28
24
|
},
|
package/src/character-set.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CharacterSetCreator,
|
|
1
|
+
import { CharacterSetCreator, CharacterSetValidator, Exclusions } from "@aidc-toolkit/utility";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* GS1 AI encodable character set 82 creator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs | GS1
|
|
@@ -37,3 +37,18 @@ export const AI39_CREATOR = new CharacterSetCreator([
|
|
|
37
37
|
* GS1 General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
|
|
38
38
|
*/
|
|
39
39
|
export const AI39_VALIDATOR = AI39_CREATOR as CharacterSetValidator;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* GS1 AI encodable character set 64 validator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs |
|
|
43
|
+
* GS1 General Specifications}. Doesn't support any exclusions.
|
|
44
|
+
*/
|
|
45
|
+
export const AI64_VALIDATOR = new CharacterSetValidator([
|
|
46
|
+
"-",
|
|
47
|
+
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
|
|
48
|
+
"=",
|
|
49
|
+
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
|
|
50
|
+
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
|
|
51
|
+
"_",
|
|
52
|
+
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
|
|
53
|
+
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
|
|
54
|
+
]);
|
package/src/check.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NUMERIC_CREATOR, utilityNS } from "@aidc-toolkit/utility";
|
|
2
|
-
import { AI82_CREATOR } from "./character-set
|
|
3
|
-
import { i18nextGS1 } from "./locale/i18n
|
|
2
|
+
import { AI82_CREATOR } from "./character-set";
|
|
3
|
+
import { i18nextGS1 } from "./locale/i18n";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Results of multiplying digits by 3.
|
package/src/gtin-creator.ts
CHANGED
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
type TransformerOutput
|
|
7
7
|
} from "@aidc-toolkit/utility";
|
|
8
8
|
import { Mixin } from "ts-mixer";
|
|
9
|
-
import { checkDigit, priceOrWeightCheckDigit } from "./check
|
|
10
|
-
import { type GTINType, GTINTypes, GTINValidator } from "./gtin-validator
|
|
11
|
-
import { i18nextGS1 } from "./locale/i18n
|
|
12
|
-
import { AbstractNumericIdentifierCreator } from "./numeric-identifier-creator
|
|
9
|
+
import { checkDigit, priceOrWeightCheckDigit } from "./check";
|
|
10
|
+
import { type GTINType, GTINTypes, GTINValidator } from "./gtin-validator";
|
|
11
|
+
import { i18nextGS1 } from "./locale/i18n";
|
|
12
|
+
import { AbstractNumericIdentifierCreator } from "./numeric-identifier-creator";
|
|
13
13
|
import type { PrefixProvider } from "./prefix-provider";
|
|
14
14
|
|
|
15
15
|
/**
|
package/src/gtin-validator.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type CharacterSetValidation, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
2
|
-
import { checkDigit, hasValidCheckDigit, isValidPriceOrWeightCheckDigit } from "./check
|
|
3
|
-
import { IdentifierTypes } from "./identifier-type
|
|
4
|
-
import { i18nextGS1 } from "./locale/i18n
|
|
5
|
-
import { AbstractNumericIdentifierValidator, LeaderTypes } from "./numeric-identifier-validator
|
|
6
|
-
import { type PrefixType, PrefixTypes } from "./prefix-type
|
|
7
|
-
import { PrefixValidator } from "./prefix-validator
|
|
2
|
+
import { checkDigit, hasValidCheckDigit, isValidPriceOrWeightCheckDigit } from "./check";
|
|
3
|
+
import { IdentifierTypes } from "./identifier-type";
|
|
4
|
+
import { i18nextGS1 } from "./locale/i18n";
|
|
5
|
+
import { AbstractNumericIdentifierValidator, LeaderTypes } from "./numeric-identifier-validator";
|
|
6
|
+
import { type PrefixType, PrefixTypes } from "./prefix-type";
|
|
7
|
+
import { PrefixValidator } from "./prefix-validator";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* GTIN types. The numeric values are equal to the lengths of the GTIN types.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { CharacterSetCreator } from "@aidc-toolkit/utility";
|
|
2
|
-
import type { IdentifierType } from "./identifier-type
|
|
3
|
-
import type { ContentCharacterSet, IdentifierValidation, IdentifierValidator } from "./identifier-validator
|
|
2
|
+
import type { IdentifierType } from "./identifier-type";
|
|
3
|
+
import type { ContentCharacterSet, IdentifierValidation, IdentifierValidator } from "./identifier-validator";
|
|
4
4
|
import type { PrefixProvider } from "./prefix-provider";
|
|
5
|
-
import type { PrefixType } from "./prefix-type
|
|
5
|
+
import type { PrefixType } from "./prefix-type";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Identifier creator. Creates an identifier based on its definition in section 3 of the {@link
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
type StringValidation,
|
|
5
5
|
type StringValidator
|
|
6
6
|
} from "@aidc-toolkit/utility";
|
|
7
|
-
import { AI39_CREATOR, AI82_CREATOR } from "./character-set
|
|
8
|
-
import type { IdentifierType } from "./identifier-type
|
|
9
|
-
import type { PrefixType } from "./prefix-type
|
|
10
|
-
import { PrefixValidator } from "./prefix-validator
|
|
7
|
+
import { AI39_CREATOR, AI82_CREATOR } from "./character-set";
|
|
8
|
+
import type { IdentifierType } from "./identifier-type";
|
|
9
|
+
import type { PrefixType } from "./prefix-type";
|
|
10
|
+
import { PrefixValidator } from "./prefix-validator";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Character sets supported by the reference portion of an identifier or the serial component of a numeric identifier.
|
package/src/index.ts
CHANGED
|
@@ -14,22 +14,22 @@
|
|
|
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 "./character-set
|
|
19
|
-
export * from "./check
|
|
20
|
-
export * from "./prefix-type
|
|
21
|
-
export * from "./prefix-validator
|
|
22
|
-
export * from "./identifier-type
|
|
23
|
-
export * from "./identifier-validator
|
|
24
|
-
export * from "./numeric-identifier-validator
|
|
25
|
-
export * from "./gtin-validator
|
|
26
|
-
export * from "./non-gtin-numeric-identifier-validator
|
|
27
|
-
export * from "./serializable-numeric-identifier-validator
|
|
28
|
-
export * from "./non-numeric-identifier-validator
|
|
29
|
-
export * from "./identifier-creator
|
|
30
|
-
export * from "./numeric-identifier-creator
|
|
31
|
-
export * from "./gtin-creator
|
|
32
|
-
export * from "./non-gtin-numeric-identifier-creator
|
|
33
|
-
export * from "./serializable-numeric-identifier-creator
|
|
34
|
-
export * from "./non-numeric-identifier-creator
|
|
35
|
-
export * from "./prefix-manager
|
|
17
|
+
export * from "./locale/i18n";
|
|
18
|
+
export * from "./character-set";
|
|
19
|
+
export * from "./check";
|
|
20
|
+
export * from "./prefix-type";
|
|
21
|
+
export * from "./prefix-validator";
|
|
22
|
+
export * from "./identifier-type";
|
|
23
|
+
export * from "./identifier-validator";
|
|
24
|
+
export * from "./numeric-identifier-validator";
|
|
25
|
+
export * from "./gtin-validator";
|
|
26
|
+
export * from "./non-gtin-numeric-identifier-validator";
|
|
27
|
+
export * from "./serializable-numeric-identifier-validator";
|
|
28
|
+
export * from "./non-numeric-identifier-validator";
|
|
29
|
+
export * from "./identifier-creator";
|
|
30
|
+
export * from "./numeric-identifier-creator";
|
|
31
|
+
export * from "./gtin-creator";
|
|
32
|
+
export * from "./non-gtin-numeric-identifier-creator";
|
|
33
|
+
export * from "./serializable-numeric-identifier-creator";
|
|
34
|
+
export * from "./non-numeric-identifier-creator";
|
|
35
|
+
export * from "./prefix-manager";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export
|
|
1
|
+
export default {
|
|
2
2
|
Check: {
|
|
3
3
|
lengthOfStringForPriceOrWeightMustBeExactly: "La longueur {{length, number}} de la chaîne pour le prix ou le poids doit être 4 ou 5",
|
|
4
4
|
priceOrWeightComponent: "prix ou poids",
|
|
5
|
-
lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "La longueur {{length, number}} de la chaîne pour la paire de caractères de vérification doit être inférieure ou égale à {{
|
|
5
|
+
lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "La longueur {{length, number}} de la chaîne pour la paire de caractères de vérification doit être inférieure ou égale à {{maximumLength, number}}"
|
|
6
6
|
},
|
|
7
7
|
Identifier: {
|
|
8
8
|
identifierTypeLength: "{{identifierType}} doit comporter {{length, number}} chiffres",
|
package/src/locale/i18n.ts
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i18nCoreInit, type I18nEnvironment } from "@aidc-toolkit/core";
|
|
2
2
|
import { i18nUtilityInit, utilityResources } from "@aidc-toolkit/utility";
|
|
3
3
|
import i18next, { type i18n, type Resource } from "i18next";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import enLocaleResources from "./en/locale-resources";
|
|
5
|
+
import frLocaleResources from "./fr/locale-resources";
|
|
6
6
|
|
|
7
7
|
export const gs1NS = "aidct_gs1";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Locale strings type is extracted from the English locale strings object.
|
|
11
11
|
*/
|
|
12
|
-
export type
|
|
13
|
-
|
|
14
|
-
i18nAssertValidResources(enLocaleStrings, "fr", frLocaleStrings);
|
|
12
|
+
export type GS1LocaleResources = typeof enLocaleResources;
|
|
15
13
|
|
|
16
14
|
/**
|
|
17
15
|
* GS1 resources.
|
|
18
16
|
*/
|
|
19
17
|
export const gs1Resources: Resource = {
|
|
20
18
|
en: {
|
|
21
|
-
aidct_gs1:
|
|
19
|
+
aidct_gs1: enLocaleResources
|
|
22
20
|
},
|
|
23
21
|
fr: {
|
|
24
|
-
aidct_gs1:
|
|
22
|
+
aidct_gs1: frLocaleResources
|
|
25
23
|
}
|
|
26
24
|
};
|
|
27
25
|
|
package/src/locale/i18next.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { UtilityLocaleResources } from "@aidc-toolkit/utility";
|
|
2
|
+
import type { GS1LocaleResources } from "./i18n";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Internationalization module.
|
|
@@ -11,8 +11,8 @@ declare module "i18next" {
|
|
|
11
11
|
interface CustomTypeOptions {
|
|
12
12
|
defaultNS: "aidct_gs1";
|
|
13
13
|
resources: {
|
|
14
|
-
aidct_utility:
|
|
15
|
-
aidct_gs1:
|
|
14
|
+
aidct_utility: UtilityLocaleResources;
|
|
15
|
+
aidct_gs1: GS1LocaleResources;
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Mixin } from "ts-mixer";
|
|
2
|
-
import type { IdentifierType } from "./identifier-type
|
|
3
|
-
import { NonGTINNumericIdentifierValidator } from "./non-gtin-numeric-identifier-validator
|
|
4
|
-
import { AbstractNumericIdentifierCreator } from "./numeric-identifier-creator
|
|
5
|
-
import { type LeaderType, LeaderTypes } from "./numeric-identifier-validator
|
|
2
|
+
import type { IdentifierType } from "./identifier-type";
|
|
3
|
+
import { NonGTINNumericIdentifierValidator } from "./non-gtin-numeric-identifier-validator";
|
|
4
|
+
import { AbstractNumericIdentifierCreator } from "./numeric-identifier-creator";
|
|
5
|
+
import { type LeaderType, LeaderTypes } from "./numeric-identifier-validator";
|
|
6
6
|
import type { PrefixProvider } from "./prefix-provider";
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type IdentifierType, IdentifierTypes } from "./identifier-type
|
|
1
|
+
import { type IdentifierType, IdentifierTypes } from "./identifier-type";
|
|
2
2
|
import {
|
|
3
3
|
AbstractNumericIdentifierValidator,
|
|
4
4
|
type LeaderType,
|
|
5
5
|
LeaderTypes,
|
|
6
6
|
type NumericIdentifierType
|
|
7
|
-
} from "./numeric-identifier-validator
|
|
8
|
-
import { PrefixTypes } from "./prefix-type
|
|
7
|
+
} from "./numeric-identifier-validator";
|
|
8
|
+
import { PrefixTypes } from "./prefix-type";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Non-GTIN numeric identifier type.
|
|
@@ -5,12 +5,12 @@ import {
|
|
|
5
5
|
type TransformerOutput
|
|
6
6
|
} from "@aidc-toolkit/utility";
|
|
7
7
|
import { Mixin } from "ts-mixer";
|
|
8
|
-
import { checkCharacterPair } from "./check
|
|
9
|
-
import { AbstractIdentifierCreator } from "./identifier-creator
|
|
10
|
-
import type { IdentifierType } from "./identifier-type
|
|
11
|
-
import type { ContentCharacterSet } from "./identifier-validator
|
|
12
|
-
import { i18nextGS1 } from "./locale/i18n
|
|
13
|
-
import { NonNumericIdentifierValidator } from "./non-numeric-identifier-validator
|
|
8
|
+
import { checkCharacterPair } from "./check";
|
|
9
|
+
import { AbstractIdentifierCreator } from "./identifier-creator";
|
|
10
|
+
import type { IdentifierType } from "./identifier-type";
|
|
11
|
+
import type { ContentCharacterSet } from "./identifier-validator";
|
|
12
|
+
import { i18nextGS1 } from "./locale/i18n";
|
|
13
|
+
import { NonNumericIdentifierValidator } from "./non-numeric-identifier-validator";
|
|
14
14
|
import type { PrefixProvider } from "./prefix-provider";
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Exclusions, RegExpValidator } from "@aidc-toolkit/utility";
|
|
2
|
-
import { hasValidCheckCharacterPair } from "./check
|
|
3
|
-
import { type IdentifierType, IdentifierTypes } from "./identifier-type
|
|
2
|
+
import { hasValidCheckCharacterPair } from "./check";
|
|
3
|
+
import { type IdentifierType, IdentifierTypes } from "./identifier-type";
|
|
4
4
|
import {
|
|
5
5
|
AbstractIdentifierValidator,
|
|
6
6
|
type ContentCharacterSet,
|
|
7
7
|
ContentCharacterSets,
|
|
8
8
|
type IdentifierValidation
|
|
9
|
-
} from "./identifier-validator
|
|
10
|
-
import { i18nextGS1 } from "./locale/i18n
|
|
11
|
-
import type { NumericIdentifierType } from "./numeric-identifier-validator
|
|
12
|
-
import { PrefixTypes } from "./prefix-type
|
|
9
|
+
} from "./identifier-validator";
|
|
10
|
+
import { i18nextGS1 } from "./locale/i18n";
|
|
11
|
+
import type { NumericIdentifierType } from "./numeric-identifier-validator";
|
|
12
|
+
import { PrefixTypes } from "./prefix-type";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Non-numeric identifier type.
|
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
type TransformerInput,
|
|
6
6
|
type TransformerOutput
|
|
7
7
|
} from "@aidc-toolkit/utility";
|
|
8
|
-
import { checkDigit, checkDigitSum } from "./check
|
|
9
|
-
import { AbstractIdentifierCreator, type IdentifierCreator } from "./identifier-creator
|
|
10
|
-
import { type LeaderType, LeaderTypes, type NumericIdentifierValidator } from "./numeric-identifier-validator
|
|
8
|
+
import { checkDigit, checkDigitSum } from "./check";
|
|
9
|
+
import { AbstractIdentifierCreator, type IdentifierCreator } from "./identifier-creator";
|
|
10
|
+
import { type LeaderType, LeaderTypes, type NumericIdentifierValidator } from "./numeric-identifier-validator";
|
|
11
11
|
import type { PrefixProvider } from "./prefix-provider";
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { hasValidCheckDigit } from "./check
|
|
2
|
-
import type { IdentifierType, IdentifierTypes } from "./identifier-type
|
|
1
|
+
import { hasValidCheckDigit } from "./check";
|
|
2
|
+
import type { IdentifierType, IdentifierTypes } from "./identifier-type";
|
|
3
3
|
import {
|
|
4
4
|
AbstractIdentifierValidator,
|
|
5
5
|
ContentCharacterSets,
|
|
6
6
|
type IdentifierValidation,
|
|
7
7
|
type IdentifierValidator
|
|
8
|
-
} from "./identifier-validator
|
|
9
|
-
import { i18nextGS1 } from "./locale/i18n
|
|
10
|
-
import type { PrefixType } from "./prefix-type
|
|
8
|
+
} from "./identifier-validator";
|
|
9
|
+
import { i18nextGS1 } from "./locale/i18n";
|
|
10
|
+
import type { PrefixType } from "./prefix-type";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Numeric identifier type.
|
package/src/prefix-manager.ts
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
|
-
import { GTINCreator } from "./gtin-creator
|
|
2
|
-
import { type GTINType, GTINTypes } from "./gtin-validator
|
|
3
|
-
import type { IdentifierCreator } from "./identifier-creator
|
|
4
|
-
import { type IdentifierType, IdentifierTypes } from "./identifier-type
|
|
5
|
-
import { i18nextGS1 } from "./locale/i18n
|
|
6
|
-
import { NonGTINNumericIdentifierCreator } from "./non-gtin-numeric-identifier-creator
|
|
1
|
+
import { GTINCreator } from "./gtin-creator";
|
|
2
|
+
import { type GTINType, GTINTypes } from "./gtin-validator";
|
|
3
|
+
import type { IdentifierCreator } from "./identifier-creator";
|
|
4
|
+
import { type IdentifierType, IdentifierTypes } from "./identifier-type";
|
|
5
|
+
import { i18nextGS1 } from "./locale/i18n";
|
|
6
|
+
import { NonGTINNumericIdentifierCreator } from "./non-gtin-numeric-identifier-creator";
|
|
7
7
|
import {
|
|
8
8
|
GLN_VALIDATOR,
|
|
9
9
|
GSIN_VALIDATOR,
|
|
10
10
|
GSRN_VALIDATOR,
|
|
11
11
|
type NonGTINNumericIdentifierValidator,
|
|
12
12
|
SSCC_VALIDATOR
|
|
13
|
-
} from "./non-gtin-numeric-identifier-validator
|
|
14
|
-
import { NonNumericIdentifierCreator } from "./non-numeric-identifier-creator
|
|
13
|
+
} from "./non-gtin-numeric-identifier-validator";
|
|
14
|
+
import { NonNumericIdentifierCreator } from "./non-numeric-identifier-creator";
|
|
15
15
|
import {
|
|
16
16
|
CPID_VALIDATOR,
|
|
17
17
|
GIAI_VALIDATOR,
|
|
18
18
|
GINC_VALIDATOR,
|
|
19
19
|
GMN_VALIDATOR,
|
|
20
20
|
type NonNumericIdentifierValidator
|
|
21
|
-
} from "./non-numeric-identifier-validator
|
|
22
|
-
import type { AbstractNumericIdentifierCreator } from "./numeric-identifier-creator
|
|
23
|
-
import type {
|
|
24
|
-
import
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
21
|
+
} from "./non-numeric-identifier-validator";
|
|
22
|
+
import type { AbstractNumericIdentifierCreator } from "./numeric-identifier-creator";
|
|
23
|
+
import type { NumericIdentifierType } from "./numeric-identifier-validator";
|
|
24
|
+
import type { PrefixProvider } from "./prefix-provider";
|
|
25
|
+
import { type PrefixType, PrefixTypes } from "./prefix-type";
|
|
26
|
+
import { PrefixValidator } from "./prefix-validator";
|
|
27
|
+
import { SerializableNumericIdentifierCreator } from "./serializable-numeric-identifier-creator";
|
|
27
28
|
import {
|
|
28
29
|
GCN_VALIDATOR,
|
|
29
30
|
GDTI_VALIDATOR,
|
|
30
31
|
GRAI_VALIDATOR,
|
|
31
32
|
type SerializableNumericIdentifierValidator
|
|
32
|
-
} from "./serializable-numeric-identifier-validator
|
|
33
|
+
} from "./serializable-numeric-identifier-validator";
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Prefix manager. This is the core class for identifier creation.
|
|
@@ -59,19 +60,19 @@ export class PrefixManager implements PrefixProvider {
|
|
|
59
60
|
private static readonly PREFIX_MANAGERS_MAP = new Map<string, PrefixManager>();
|
|
60
61
|
|
|
61
62
|
/**
|
|
62
|
-
* Creator tweak factors. Different numeric identifier types have different tweak factors so that sparse
|
|
63
|
-
*
|
|
63
|
+
* Creator tweak factors. Different numeric identifier types have different tweak factors so that sparse creation
|
|
64
|
+
* generates different sequences for each.
|
|
64
65
|
*/
|
|
65
|
-
private static readonly
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
private static readonly CREATOR_TWEAK_FACTORS: Readonly<Record<NumericIdentifierType, bigint>> = {
|
|
67
|
+
GTIN: 1987n,
|
|
68
|
+
GLN: 4241n,
|
|
69
|
+
SSCC: 8087n,
|
|
70
|
+
GRAI: 3221n,
|
|
71
|
+
GSRN: 2341n,
|
|
72
|
+
GDTI: 7333n,
|
|
73
|
+
GSIN: 5623n,
|
|
74
|
+
GCN: 6869n
|
|
75
|
+
};
|
|
75
76
|
|
|
76
77
|
/**
|
|
77
78
|
* Normalized prefix type.
|
|
@@ -111,7 +112,7 @@ export class PrefixManager implements PrefixProvider {
|
|
|
111
112
|
/**
|
|
112
113
|
* Cached identifier creators.
|
|
113
114
|
*/
|
|
114
|
-
private readonly
|
|
115
|
+
private readonly _identifierCreators: Partial<Record<IdentifierType, IdentifierCreator>> = {};
|
|
115
116
|
|
|
116
117
|
/**
|
|
117
118
|
* Constructor.
|
|
@@ -184,11 +185,11 @@ export class PrefixManager implements PrefixProvider {
|
|
|
184
185
|
* Identifier creator.
|
|
185
186
|
*/
|
|
186
187
|
private setCreatorTweak(creator: IdentifierCreator): void {
|
|
187
|
-
|
|
188
|
+
if (creator.identifierType in PrefixManager.CREATOR_TWEAK_FACTORS) {
|
|
189
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type is known by testing for presence in record.
|
|
190
|
+
const creatorTweakFactor = PrefixManager.CREATOR_TWEAK_FACTORS[creator.identifierType as NumericIdentifierType];
|
|
188
191
|
|
|
189
|
-
|
|
190
|
-
if (creatorTweakFactor !== undefined) {
|
|
191
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion,no-param-reassign -- Explicit cast without testing is necessary as "instanceof" doesn't work for mixin types. Method purpose is to set the tweak.
|
|
192
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion,no-param-reassign -- Type is known by testing identifier type. Method purpose is to set the tweak.
|
|
192
193
|
(creator as AbstractNumericIdentifierCreator).tweak = this.tweakFactor * creatorTweakFactor;
|
|
193
194
|
}
|
|
194
195
|
}
|
|
@@ -212,7 +213,7 @@ export class PrefixManager implements PrefixProvider {
|
|
|
212
213
|
if (this._tweakFactor !== tweakFactor) {
|
|
213
214
|
this._tweakFactor = tweakFactor;
|
|
214
215
|
|
|
215
|
-
for (const creator of
|
|
216
|
+
for (const creator of Object.values(this._identifierCreators)) {
|
|
216
217
|
this.setCreatorTweak(creator);
|
|
217
218
|
}
|
|
218
219
|
}
|
|
@@ -284,7 +285,7 @@ export class PrefixManager implements PrefixProvider {
|
|
|
284
285
|
*/
|
|
285
286
|
private getIdentifierCreator<TIdentifierCreator extends IdentifierCreator>(identifierType: IdentifierType, constructorCallback: () => TIdentifierCreator): TIdentifierCreator {
|
|
286
287
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type is paired with constructor callback.
|
|
287
|
-
let creator = this.
|
|
288
|
+
let creator = this._identifierCreators[identifierType] as TIdentifierCreator | undefined;
|
|
288
289
|
|
|
289
290
|
if (creator === undefined) {
|
|
290
291
|
if (this.prefixType === PrefixTypes.GS18Prefix && identifierType !== IdentifierTypes.GTIN) {
|
|
@@ -297,7 +298,7 @@ export class PrefixManager implements PrefixProvider {
|
|
|
297
298
|
|
|
298
299
|
this.setCreatorTweak(creator);
|
|
299
300
|
|
|
300
|
-
this.
|
|
301
|
+
this._identifierCreators[identifierType] = creator;
|
|
301
302
|
}
|
|
302
303
|
|
|
303
304
|
return creator;
|
package/src/prefix-provider.ts
CHANGED
package/src/prefix-validator.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type CharacterSetValidation, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
2
|
-
import { i18nextGS1 } from "./locale/i18n
|
|
3
|
-
import { type PrefixType, PrefixTypes } from "./prefix-type
|
|
2
|
+
import { i18nextGS1 } from "./locale/i18n";
|
|
3
|
+
import { type PrefixType, PrefixTypes } from "./prefix-type";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Prefix validation parameters.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { mapIterable, type TransformerInput, type TransformerOutput } from "@aidc-toolkit/utility";
|
|
2
2
|
import { Mixin } from "ts-mixer";
|
|
3
|
-
import type { IdentifierType } from "./identifier-type
|
|
4
|
-
import type { ContentCharacterSet } from "./identifier-validator
|
|
5
|
-
import { AbstractNumericIdentifierCreator } from "./numeric-identifier-creator
|
|
3
|
+
import type { IdentifierType } from "./identifier-type";
|
|
4
|
+
import type { ContentCharacterSet } from "./identifier-validator";
|
|
5
|
+
import { AbstractNumericIdentifierCreator } from "./numeric-identifier-creator";
|
|
6
6
|
import type { PrefixProvider } from "./prefix-provider";
|
|
7
|
-
import { SerializableNumericIdentifierValidator } from "./serializable-numeric-identifier-validator
|
|
7
|
+
import { SerializableNumericIdentifierValidator } from "./serializable-numeric-identifier-validator";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Serializable numeric identifier creator.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { CharacterSetCreator, CharacterSetValidation } from "@aidc-toolkit/utility";
|
|
2
|
-
import { type IdentifierType, IdentifierTypes } from "./identifier-type
|
|
3
|
-
import { type ContentCharacterSet, ContentCharacterSets, type IdentifierValidation } from "./identifier-validator
|
|
4
|
-
import { i18nextGS1 } from "./locale/i18n
|
|
2
|
+
import { type IdentifierType, IdentifierTypes } from "./identifier-type";
|
|
3
|
+
import { type ContentCharacterSet, ContentCharacterSets, type IdentifierValidation } from "./identifier-validator";
|
|
4
|
+
import { i18nextGS1 } from "./locale/i18n";
|
|
5
5
|
import {
|
|
6
6
|
type NonGTINNumericIdentifierType,
|
|
7
7
|
NonGTINNumericIdentifierValidator
|
|
8
|
-
} from "./non-gtin-numeric-identifier-validator
|
|
9
|
-
import { LeaderTypes } from "./numeric-identifier-validator
|
|
8
|
+
} from "./non-gtin-numeric-identifier-validator";
|
|
9
|
+
import { LeaderTypes } from "./numeric-identifier-validator";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Serializable numeric identifier type.
|
package/test/creator.test.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { describe } from "vitest";
|
|
2
2
|
import { PrefixManager, PrefixTypes } from "../src";
|
|
3
|
-
import { testGTINCreator } from "./gtin-creator
|
|
3
|
+
import { testGTINCreator } from "./gtin-creator";
|
|
4
4
|
import {
|
|
5
5
|
testNonGTINNumericIdentifierCreator,
|
|
6
6
|
testNonNumericIdentifierCreator
|
|
7
|
-
} from "./non-gtin-numeric-identifier-creator
|
|
8
|
-
import { testSerializableNumericIdentifierCreator } from "./serializable-numeric-identifier-creator
|
|
7
|
+
} from "./non-gtin-numeric-identifier-creator";
|
|
8
|
+
import { testSerializableNumericIdentifierCreator } from "./serializable-numeric-identifier-creator";
|
|
9
9
|
|
|
10
10
|
describe("Creators", () => {
|
|
11
11
|
testGTINCreator(PrefixManager.get(PrefixTypes.GS1CompanyPrefix, "952123456").gtinCreator);
|
package/test/gtin-creator.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CharacterSetCreator, Sequence } from "@aidc-toolkit/utility";
|
|
2
2
|
import { expect, test } from "vitest";
|
|
3
3
|
import { type GTINCreator, GTINTypes, GTINValidator, hasValidCheckDigit, PrefixTypes } from "../src";
|
|
4
|
-
import { testNumericIdentifierCreator } from "./numeric-identifier-creator
|
|
4
|
+
import { testNumericIdentifierCreator } from "./numeric-identifier-creator";
|
|
5
5
|
|
|
6
6
|
export function testGTINCreator(creator: GTINCreator): void {
|
|
7
7
|
testNumericIdentifierCreator(creator, () => {
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
type PrefixType,
|
|
10
10
|
PrefixTypes
|
|
11
11
|
} from "../src";
|
|
12
|
-
import { validateNumericIdentifierValidator } from "./numeric-identifier-validator
|
|
12
|
+
import { validateNumericIdentifierValidator } from "./numeric-identifier-validator";
|
|
13
13
|
|
|
14
14
|
export function validateGTINValidator(validator: GTINValidator, isCreator: boolean, gtinType: GTINType): void {
|
|
15
15
|
let prefixType: PrefixType;
|
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
type PrefixManager,
|
|
9
9
|
PrefixTypes
|
|
10
10
|
} from "../src";
|
|
11
|
-
import { validateGTINValidator } from "./gtin-validator.test
|
|
12
|
-
import { validateNonGTINNumericIdentifierValidator } from "./non-gtin-numeric-identifier-validator
|
|
13
|
-
import { validateNonNumericIdentifierValidator } from "./non-numeric-identifier-validator
|
|
14
|
-
import { validateSerializableNumericIdentifierValidator } from "./serializable-numeric-identifier-validator
|
|
11
|
+
import { validateGTINValidator } from "./gtin-validator.test";
|
|
12
|
+
import { validateNonGTINNumericIdentifierValidator } from "./non-gtin-numeric-identifier-validator";
|
|
13
|
+
import { validateNonNumericIdentifierValidator } from "./non-numeric-identifier-validator";
|
|
14
|
+
import { validateSerializableNumericIdentifierValidator } from "./serializable-numeric-identifier-validator";
|
|
15
15
|
|
|
16
16
|
export function validateIdentifierCreators(prefixManager: PrefixManager): void {
|
|
17
17
|
let gtinType: GTINType;
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
type NonGTINNumericIdentifierCreator,
|
|
6
6
|
type NonNumericIdentifierCreator
|
|
7
7
|
} from "../src";
|
|
8
|
-
import { testNumericIdentifierCreator } from "./numeric-identifier-creator
|
|
8
|
+
import { testNumericIdentifierCreator } from "./numeric-identifier-creator";
|
|
9
9
|
|
|
10
10
|
export function testNonGTINNumericIdentifierCreator(creator: NonGTINNumericIdentifierCreator, preTestCallback?: () => void, postTestCallback?: () => void): void {
|
|
11
11
|
testNumericIdentifierCreator(creator, preTestCallback, postTestCallback);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type IdentifierType, type LeaderType, type NonGTINNumericIdentifierValidator, PrefixTypes } from "../src";
|
|
2
|
-
import { validateNumericIdentifierValidator } from "./numeric-identifier-validator
|
|
2
|
+
import { validateNumericIdentifierValidator } from "./numeric-identifier-validator";
|
|
3
3
|
|
|
4
4
|
export function validateNonGTINNumericIdentifierValidator(validator: NonGTINNumericIdentifierValidator, isCreator: boolean, identifierType: IdentifierType, length: number, leaderType: LeaderType): void {
|
|
5
5
|
validateNumericIdentifierValidator(validator, isCreator, identifierType, PrefixTypes.GS1CompanyPrefix, length, leaderType);
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
type NonNumericIdentifierValidator,
|
|
7
7
|
PrefixTypes
|
|
8
8
|
} from "../src";
|
|
9
|
-
import { validateIdentifierValidator } from "./identifier-validator
|
|
10
|
-
import { creatorFor } from "./utility
|
|
9
|
+
import { validateIdentifierValidator } from "./identifier-validator";
|
|
10
|
+
import { creatorFor } from "./utility";
|
|
11
11
|
|
|
12
12
|
export function validateNonNumericIdentifierValidator(validator: NonNumericIdentifierValidator, isCreator: boolean, identifierType: IdentifierType, length: number, referenceCharacterSet: ContentCharacterSet, requiresCheckCharacterPair: boolean): void {
|
|
13
13
|
validateIdentifierValidator(validator, identifierType, PrefixTypes.GS1CompanyPrefix, length);
|