@aidc-toolkit/gs1 0.9.17-beta → 0.9.19-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.
@@ -1,5 +1,5 @@
1
- import { type I18NEnvironment } from "@aidc-toolkit/core";
2
- import { type i18n } from "i18next";
1
+ import { type I18nEnvironment } from "@aidc-toolkit/core";
2
+ import { type i18n, type Resource } from "i18next";
3
3
  import { localeStrings as enLocaleStrings } from "./en/locale-strings.js";
4
4
  export declare const gs1NS = "aidct_gs1";
5
5
  /**
@@ -9,86 +9,7 @@ export type GS1LocaleStrings = typeof enLocaleStrings;
9
9
  /**
10
10
  * GS1 resources.
11
11
  */
12
- export declare const gs1Resources: {
13
- en: {
14
- aidct_gs1: {
15
- readonly Check: {
16
- readonly lengthOfStringForPriceOrWeightMustBeExactly: "Length {{length}} of string for price or weight sum must be exactly {{exactLength}}";
17
- readonly priceOrWeightComponent: "price or weight";
18
- readonly lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "Length {{length}} of string for check character pair must be less than or equal to {{maximumLength}}";
19
- };
20
- readonly IdentificationKey: {
21
- readonly identificationKeyTypeLength: "{{identificationKeyType}} must be {{length}} digits long";
22
- readonly invalidCheckDigit: "Invalid check digit";
23
- readonly invalidGTINLength: "GTIN must be 13, 12, 8, or 14 digits long";
24
- readonly invalidGTIN14Length: "GTIN must be 14 digits long";
25
- readonly invalidZeroSuppressedGTIN12: "Invalid zero-suppressed GTIN-12";
26
- readonly invalidZeroSuppressibleGTIN12: "GTIN-12 not zero-suppressible";
27
- readonly invalidZeroSuppressedGTIN12AsGTIN13: "Invalid zero-suppressed GTIN-12 as GTIN-13";
28
- readonly invalidZeroSuppressedGTIN12AsGTIN14: "Invalid zero-suppressed GTIN-12 as GTIN-14";
29
- readonly invalidGTIN13AtRetail: "GTIN-13 at retail consumer trade item level can't start with zero";
30
- readonly invalidGTINAtRetail: "GTIN not supported at retail consumer trade item level";
31
- readonly invalidGTINAtOtherThanRetail: "GTIN not supported at other than retail consumer trade item level";
32
- readonly indicatorDigit: "indicator digit";
33
- readonly serialComponent: "serial component";
34
- readonly reference: "reference";
35
- readonly referenceCantBeAllNumeric: "Reference can't be all-numeric";
36
- readonly invalidCheckCharacterPair: "Invalid check character pair";
37
- };
38
- readonly Prefix: {
39
- readonly gs1CompanyPrefix: "GS1 Company Prefix";
40
- readonly upcCompanyPrefix: "U.P.C. Company Prefix";
41
- readonly gs18Prefix: "GS1-8 Prefix";
42
- readonly invalidPrefixType: "Invalid prefix type";
43
- readonly gs1CompanyPrefixCantStartWith0: "GS1 Company Prefix can't start with \"0\"";
44
- readonly gs1CompanyPrefixCantStartWith00000: "GS1 Company Prefix can't start with \"00000\"";
45
- readonly gs1CompanyPrefixCantStartWith000000: "GS1 Company Prefix can't start with \"000000\"";
46
- readonly upcCompanyPrefixCantStartWith0000: "U.P.C. Company Prefix can't start with \"0000\"";
47
- readonly gs18PrefixCantStartWith0: "GS1-8 Prefix can't start with \"0\"";
48
- readonly identificationKeyTypeNotSupportedByGS18Prefix: "{{identificationKeyType}} not supported by GS1-8 Prefix";
49
- };
50
- };
51
- };
52
- fr: {
53
- aidct_gs1: {
54
- readonly Check: {
55
- readonly lengthOfStringForPriceOrWeightMustBeExactly: "La longueur {{longueur}} de la chaîne pour le prix ou la somme du poids doit être exactement {{exactLength}}";
56
- readonly priceOrWeightComponent: "prix ou poids";
57
- readonly lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "La longueur {{length}} de la chaîne pour la paire de caractères de vérification doit être inférieure ou égale à {{maximum Length}}";
58
- };
59
- readonly IdentificationKey: {
60
- readonly identificationKeyTypeLength: "{{identificationKeyType}} doit comporter {{length}} chiffres";
61
- readonly invalidCheckDigit: "Chiffre de contrôle non valide";
62
- readonly invalidGTINLength: "Le GTIN doit comporter 13, 12, 8 ou 14 chiffres";
63
- readonly invalidGTIN14Length: "Le GTIN doit comporter 14 chiffres";
64
- readonly invalidZeroSuppressedGTIN12: "Code GTIN-12 non valide avec zéro supprimé";
65
- readonly invalidZeroSuppressibleGTIN12: "Le GTIN-12 ne peut pas être supprimé par zéro";
66
- readonly invalidZeroSuppressedGTIN12AsGTIN13: "GTIN-12 non valide avec zéro supprimé en tant que GTIN-13";
67
- readonly invalidZeroSuppressedGTIN12AsGTIN14: "GTIN-12 non valide avec zéro supprimé en tant que GTIN-14";
68
- readonly invalidGTIN13AtRetail: "Le GTIN-13 au niveau des articles de consommation au détail ne peut pas commencer par zéro";
69
- readonly invalidGTINAtRetail: "Le GTIN n'est pas pris en charge au niveau des articles de consommation au détail";
70
- readonly invalidGTINAtOtherThanRetail: "Le GTIN n'est pas pris en charge à d'autres niveaux que ceux des articles de consommation au détail";
71
- readonly indicatorDigit: "chiffre indicateur";
72
- readonly serialComponent: "composant série";
73
- readonly reference: "référence";
74
- readonly referenceCantBeAllNumeric: "La référence ne peut pas être entièrement numérique";
75
- readonly invalidCheckCharacterPair: "Paire de caractères de contrôle non valide";
76
- };
77
- readonly Prefix: {
78
- readonly gs1CompanyPrefix: "Préfixe de l'entreprise GS1";
79
- readonly upcCompanyPrefix: "Préfixe de l'entreprise U.P.C.";
80
- readonly gs18Prefix: "Préfixe GS1-8";
81
- readonly invalidPrefixType: "Type de préfixe invalide";
82
- readonly gs1CompanyPrefixCantStartWith0: "Le préfixe de l'entreprise GS1 ne peut pas commencer par \"0\"";
83
- readonly gs1CompanyPrefixCantStartWith00000: "Le préfixe de l'entreprise GS1 ne peut pas commencer par \"00000\"";
84
- readonly gs1CompanyPrefixCantStartWith000000: "Le préfixe de l'entreprise GS1 ne peut pas commencer par \"000000\"";
85
- readonly upcCompanyPrefixCantStartWith0000: "Le préfixe de l'entreprise U.P.C. ne peut pas commencer par \"0000\"";
86
- readonly gs18PrefixCantStartWith0: "Le préfixe GS1-8 ne peut pas commencer par \"0\"";
87
- readonly identificationKeyTypeNotSupportedByGS18Prefix: "{{identificationKeyType}} non pris en charge par le préfixe GS1-8";
88
- };
89
- };
90
- };
91
- };
12
+ export declare const gs1Resources: Resource;
92
13
  export declare const i18nextGS1: i18n;
93
14
  /**
94
15
  * Initialize internationalization.
@@ -102,5 +23,5 @@ export declare const i18nextGS1: i18n;
102
23
  * @returns
103
24
  * Void promise.
104
25
  */
105
- export declare function i18nGS1Init(environment: I18NEnvironment, debug?: boolean): Promise<void>;
26
+ export declare function i18nGS1Init(environment: I18nEnvironment, debug?: boolean): Promise<void>;
106
27
  //# sourceMappingURL=i18n.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../src/locale/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0C,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAElG,OAAgB,EAAE,KAAK,IAAI,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAG1E,eAAO,MAAM,KAAK,cAAc,CAAC;AAEjC;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,eAAe,CAAC;AAItD;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAOxB,CAAC;AAGF,eAAO,MAAM,UAAU,EAAE,IAA+B,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,wBAAsB,WAAW,CAAC,WAAW,EAAE,eAAe,EAAE,KAAK,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAG5F"}
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../src/locale/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0C,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAElG,OAAgB,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,aAAa,IAAI,eAA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,CAAC;IAC1C,MAAM,YAAY,CAAC,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,YAAY,CAAC,CAAC;AAC9F,CAAC"}
1
+ {"version":3,"file":"i18n.js","sourceRoot":"","sources":["../../src/locale/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAwB,MAAM,oBAAoB,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,OAAqC,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE1E,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC;AAOjC,wBAAwB,CAAC,eAAe,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC;AAEjE;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAa;IAClC,EAAE,EAAE;QACA,SAAS,EAAE,eAAe;KAC7B;IACD,EAAE,EAAE;QACA,SAAS,EAAE,eAAe;KAC7B;CACJ,CAAC;AAEF,wFAAwF;AACxF,MAAM,CAAC,MAAM,UAAU,GAAS,OAAO,CAAC,cAAc,EAAE,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,WAA4B,EAAE,KAAK,GAAG,KAAK;IACzE,MAAM,eAAe,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAC1C,MAAM,YAAY,CAAC,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,YAAY,CAAC,CAAC;AAC9F,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aidc-toolkit/gs1",
3
- "version": "0.9.17-beta",
3
+ "version": "0.9.19-beta",
4
4
  "description": "GS1 AIDC Toolkit",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -27,13 +27,13 @@
27
27
  "test": "vitest run"
28
28
  },
29
29
  "devDependencies": {
30
- "@aidc-toolkit/dev": "^0.9.17-beta",
31
- "vitest": "^3.0.7"
30
+ "@aidc-toolkit/dev": "beta",
31
+ "vitest": "^4.0.13"
32
32
  },
33
33
  "dependencies": {
34
- "@aidc-toolkit/core": "^0.9.17-beta",
35
- "@aidc-toolkit/utility": "^0.9.17-beta",
36
- "i18next": "^24.2.2",
34
+ "@aidc-toolkit/core": "beta",
35
+ "@aidc-toolkit/utility": "beta",
36
+ "i18next": "^25.6.3",
37
37
  "ts-mixer": "^6.0.4"
38
38
  }
39
39
  }
@@ -1,4 +1,4 @@
1
- import { CharacterSetCreator, Exclusion } from "@aidc-toolkit/utility";
1
+ import { CharacterSetCreator, type CharacterSetValidator, Exclusion } 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
@@ -15,6 +15,12 @@ export const AI82_CREATOR = new CharacterSetCreator([
15
15
  "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
16
16
  ], Exclusion.AllNumeric);
17
17
 
18
+ /**
19
+ * GS1 AI encodable character set 82 validator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs |
20
+ * GS1 General Specifications}. Supports {@linkcode Exclusion.AllNumeric}.
21
+ */
22
+ export const AI82_VALIDATOR = AI82_CREATOR as CharacterSetValidator;
23
+
18
24
  /**
19
25
  * GS1 AI encodable character set 39 creator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs | GS1
20
26
  * General Specifications}. Supports {@linkcode Exclusion.AllNumeric}.
@@ -25,3 +31,9 @@ export const AI39_CREATOR = new CharacterSetCreator([
25
31
  "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
26
32
  "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
27
33
  ], Exclusion.AllNumeric);
34
+
35
+ /**
36
+ * GS1 AI encodable character set 39 validator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs |
37
+ * GS1 General Specifications}. Supports {@linkcode Exclusion.AllNumeric}.
38
+ */
39
+ export const AI39_VALIDATOR = AI39_CREATOR as CharacterSetValidator;
package/src/check.ts CHANGED
@@ -100,7 +100,7 @@ export function hasValidCheckDigit(s: string): boolean {
100
100
  }
101
101
 
102
102
  /**
103
- * Calculate the price/weight sum for a numeric string.
103
+ * Calculate the price or weight sum for a numeric string.
104
104
  *
105
105
  * @param weightsResults
106
106
  * Array of weight results arrays to apply to each digit.
@@ -111,19 +111,9 @@ export function hasValidCheckDigit(s: string): boolean {
111
111
  * @returns
112
112
  * Accumulated sum of the weight result for each digit at the digit's position.
113
113
  */
114
- function priceWeightSum(weightsResults: ReadonlyArray<readonly number[]>, s: string): number {
115
- if (s.length !== weightsResults.length) {
116
- throw new RangeError(i18nextGS1.t("Check.lengthOfStringForPriceOrWeightMustBeExactly", {
117
- length: s.length,
118
- exactLength: weightsResults.length
119
- }));
120
- }
121
-
122
- // The value of each character is its index in the character set.
123
- const characterIndexes = NUMERIC_CREATOR.characterIndexes(s);
124
-
114
+ function priceOrWeightSum(weightsResults: ReadonlyArray<readonly number[]>, s: string): number {
125
115
  // Calculate sum of each weight result for each digit at its position.
126
- return characterIndexes.reduce<number>((accumulator, characterIndex, index) => {
116
+ return NUMERIC_CREATOR.characterIndexes(s).reduce<number>((accumulator, characterIndex, index) => {
127
117
  if (characterIndex === undefined) {
128
118
  throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPositionOfComponent", {
129
119
  ns: utilityNS,
@@ -139,31 +129,50 @@ function priceWeightSum(weightsResults: ReadonlyArray<readonly number[]>, s: str
139
129
  }
140
130
 
141
131
  /**
142
- * Calculate the price/weight check digit for a four-digit numeric string as per section 7.9.3 of the {@link
132
+ * Calculate the price or weight check digit for a four-or five-digit numeric string as per section 7.9.3 of the {@link
143
133
  * https://www.gs1.org/genspecs | GS1 General Specifications}.
144
134
  *
145
135
  * @param s
146
- * Numeric string exactly four characters long.
136
+ * Numeric string exactly four or five characters long.
147
137
  *
148
138
  * @returns
149
139
  * Check digit 0-9 as a string.
150
140
  */
151
- export function fourDigitPriceWeightCheckDigit(s: string): string {
152
- return NUMERIC_CREATOR.character(priceWeightSum([TWO_MINUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS, THREE_WEIGHT_RESULTS, FIVE_MINUS_WEIGHT_RESULTS], s) * 3 % 10);
141
+ export function priceOrWeightCheckDigit(s: string): string {
142
+ let checkDigit: string;
143
+
144
+ switch (s.length) {
145
+ case 4:
146
+ checkDigit = NUMERIC_CREATOR.character(priceOrWeightSum([TWO_MINUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS, THREE_WEIGHT_RESULTS, FIVE_MINUS_WEIGHT_RESULTS], s) * 3 % 10);
147
+ break;
148
+
149
+ case 5:
150
+ checkDigit = NUMERIC_CREATOR.character(INVERSE_FIVE_MINUS_WEIGHT_RESULTS[9 - (priceOrWeightSum([FIVE_PLUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS, FIVE_MINUS_WEIGHT_RESULTS, FIVE_PLUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS], s) + 9) % 10]);
151
+ break;
152
+
153
+ default:
154
+ throw new RangeError(i18nextGS1.t("Check.lengthOfStringForPriceOrWeightMustBeExactly", {
155
+ length: s.length
156
+ }));
157
+ }
158
+
159
+ return checkDigit;
153
160
  }
154
161
 
155
162
  /**
156
- * Calculate the price/weight check digit for a five-digit numeric string as per section 7.9.3 of the {@link
157
- * https://www.gs1.org/genspecs | GS1 General Specifications}.
163
+ * Determine if a price or weight check digit is valid for numeric string.
158
164
  *
159
165
  * @param s
160
- * Numeric string exactly five characters long.
166
+ * Numeric string exactly four or five characters long.
167
+ *
168
+ * @param checkDigit
169
+ * Price or weight check digit.
161
170
  *
162
171
  * @returns
163
- * Check digit 0-9 as a string.
172
+ * True if the check digit is valid.
164
173
  */
165
- export function fiveDigitPriceWeightCheckDigit(s: string): string {
166
- return NUMERIC_CREATOR.character(INVERSE_FIVE_MINUS_WEIGHT_RESULTS[9 - (priceWeightSum([FIVE_PLUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS, FIVE_MINUS_WEIGHT_RESULTS, FIVE_PLUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS], s) + 9) % 10]);
174
+ export function isValidPriceOrWeightCheckDigit(s: string, checkDigit: string): boolean {
175
+ return priceOrWeightCheckDigit(s) === checkDigit;
167
176
  }
168
177
 
169
178
  /**