@aidc-toolkit/gs1 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.
Files changed (131) hide show
  1. package/dist/index.cjs +4624 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +1588 -0
  4. package/dist/index.d.ts +1588 -36
  5. package/dist/index.js +4541 -19
  6. package/dist/index.js.map +1 -1
  7. package/package.json +4 -8
  8. package/src/character-set.ts +16 -1
  9. package/src/check.ts +2 -2
  10. package/src/gtin-creator.ts +4 -4
  11. package/src/gtin-validator.ts +6 -6
  12. package/src/identifier-creator.ts +3 -3
  13. package/src/identifier-validator.ts +4 -4
  14. package/src/index.ts +19 -19
  15. package/src/locale/i18n.ts +3 -5
  16. package/src/locale/i18next.d.ts +1 -1
  17. package/src/non-gtin-numeric-identifier-creator.ts +4 -4
  18. package/src/non-gtin-numeric-identifier-validator.ts +3 -3
  19. package/src/non-numeric-identifier-creator.ts +6 -6
  20. package/src/non-numeric-identifier-validator.ts +6 -6
  21. package/src/numeric-identifier-creator.ts +3 -3
  22. package/src/numeric-identifier-validator.ts +5 -5
  23. package/src/prefix-manager.ts +16 -16
  24. package/src/prefix-provider.ts +1 -1
  25. package/src/prefix-validator.ts +2 -2
  26. package/src/serializable-numeric-identifier-creator.ts +4 -4
  27. package/src/serializable-numeric-identifier-validator.ts +5 -5
  28. package/test/creator.test.ts +3 -3
  29. package/test/gtin-creator.ts +1 -1
  30. package/test/gtin-validator.test.ts +1 -1
  31. package/test/identifier-creator.ts +4 -4
  32. package/test/non-gtin-numeric-identifier-creator.ts +1 -1
  33. package/test/non-gtin-numeric-identifier-validator.ts +1 -1
  34. package/test/non-numeric-identifier-validator.ts +2 -2
  35. package/test/numeric-identifier-creator.ts +1 -1
  36. package/test/numeric-identifier-validator.ts +1 -1
  37. package/test/prefix-manager.test.ts +1 -1
  38. package/test/serializable-numeric-identifier-creator.ts +1 -1
  39. package/test/serializable-numeric-identifier-validator.ts +2 -2
  40. package/test/validator.test.ts +4 -4
  41. package/tsup.config.ts +3 -0
  42. package/typedoc.json +1 -3
  43. package/dist/character-set.d.ts +0 -22
  44. package/dist/character-set.d.ts.map +0 -1
  45. package/dist/character-set.js +0 -36
  46. package/dist/character-set.js.map +0 -1
  47. package/dist/check.d.ts +0 -81
  48. package/dist/check.d.ts.map +0 -1
  49. package/dist/check.js +0 -218
  50. package/dist/check.js.map +0 -1
  51. package/dist/gtin-creator.d.ts +0 -68
  52. package/dist/gtin-creator.d.ts.map +0 -1
  53. package/dist/gtin-creator.js +0 -158
  54. package/dist/gtin-creator.js.map +0 -1
  55. package/dist/gtin-validator.d.ts +0 -202
  56. package/dist/gtin-validator.d.ts.map +0 -1
  57. package/dist/gtin-validator.js +0 -470
  58. package/dist/gtin-validator.js.map +0 -1
  59. package/dist/identifier-creator.d.ts +0 -72
  60. package/dist/identifier-creator.d.ts.map +0 -1
  61. package/dist/identifier-creator.js +0 -50
  62. package/dist/identifier-creator.js.map +0 -1
  63. package/dist/identifier-type.d.ts +0 -58
  64. package/dist/identifier-type.d.ts.map +0 -1
  65. package/dist/identifier-type.js +0 -54
  66. package/dist/identifier-type.js.map +0 -1
  67. package/dist/identifier-validator.d.ts +0 -174
  68. package/dist/identifier-validator.d.ts.map +0 -1
  69. package/dist/identifier-validator.js +0 -145
  70. package/dist/identifier-validator.js.map +0 -1
  71. package/dist/index.d.ts.map +0 -1
  72. package/dist/locale/en/locale-resources.d.ts +0 -43
  73. package/dist/locale/en/locale-resources.d.ts.map +0 -1
  74. package/dist/locale/en/locale-resources.js +0 -42
  75. package/dist/locale/en/locale-resources.js.map +0 -1
  76. package/dist/locale/fr/locale-resources.d.ts +0 -43
  77. package/dist/locale/fr/locale-resources.d.ts.map +0 -1
  78. package/dist/locale/fr/locale-resources.js +0 -42
  79. package/dist/locale/fr/locale-resources.js.map +0 -1
  80. package/dist/locale/i18n.d.ts +0 -27
  81. package/dist/locale/i18n.d.ts.map +0 -1
  82. package/dist/locale/i18n.js +0 -37
  83. package/dist/locale/i18n.js.map +0 -1
  84. package/dist/non-gtin-numeric-identifier-creator.d.ts +0 -30
  85. package/dist/non-gtin-numeric-identifier-creator.d.ts.map +0 -1
  86. package/dist/non-gtin-numeric-identifier-creator.js +0 -30
  87. package/dist/non-gtin-numeric-identifier-creator.js.map +0 -1
  88. package/dist/non-gtin-numeric-identifier-validator.d.ts +0 -41
  89. package/dist/non-gtin-numeric-identifier-validator.d.ts.map +0 -1
  90. package/dist/non-gtin-numeric-identifier-validator.js +0 -40
  91. package/dist/non-gtin-numeric-identifier-validator.js.map +0 -1
  92. package/dist/non-numeric-identifier-creator.d.ts +0 -55
  93. package/dist/non-numeric-identifier-creator.d.ts.map +0 -1
  94. package/dist/non-numeric-identifier-creator.js +0 -93
  95. package/dist/non-numeric-identifier-creator.js.map +0 -1
  96. package/dist/non-numeric-identifier-validator.d.ts +0 -78
  97. package/dist/non-numeric-identifier-validator.d.ts.map +0 -1
  98. package/dist/non-numeric-identifier-validator.js +0 -95
  99. package/dist/non-numeric-identifier-validator.js.map +0 -1
  100. package/dist/numeric-identifier-creator.d.ts +0 -121
  101. package/dist/numeric-identifier-creator.d.ts.map +0 -1
  102. package/dist/numeric-identifier-creator.js +0 -135
  103. package/dist/numeric-identifier-creator.js.map +0 -1
  104. package/dist/numeric-identifier-validator.d.ts +0 -76
  105. package/dist/numeric-identifier-validator.d.ts.map +0 -1
  106. package/dist/numeric-identifier-validator.js +0 -84
  107. package/dist/numeric-identifier-validator.js.map +0 -1
  108. package/dist/prefix-manager.d.ts +0 -224
  109. package/dist/prefix-manager.d.ts.map +0 -1
  110. package/dist/prefix-manager.js +0 -369
  111. package/dist/prefix-manager.js.map +0 -1
  112. package/dist/prefix-provider.d.ts +0 -27
  113. package/dist/prefix-provider.d.ts.map +0 -1
  114. package/dist/prefix-provider.js +0 -2
  115. package/dist/prefix-provider.js.map +0 -1
  116. package/dist/prefix-type.d.ts +0 -22
  117. package/dist/prefix-type.d.ts.map +0 -1
  118. package/dist/prefix-type.js +0 -18
  119. package/dist/prefix-type.js.map +0 -1
  120. package/dist/prefix-validator.d.ts +0 -58
  121. package/dist/prefix-validator.d.ts.map +0 -1
  122. package/dist/prefix-validator.js +0 -154
  123. package/dist/prefix-validator.js.map +0 -1
  124. package/dist/serializable-numeric-identifier-creator.d.ts +0 -86
  125. package/dist/serializable-numeric-identifier-creator.d.ts.map +0 -1
  126. package/dist/serializable-numeric-identifier-creator.js +0 -116
  127. package/dist/serializable-numeric-identifier-creator.js.map +0 -1
  128. package/dist/serializable-numeric-identifier-validator.d.ts +0 -79
  129. package/dist/serializable-numeric-identifier-validator.d.ts.map +0 -1
  130. package/dist/serializable-numeric-identifier-validator.js +0 -99
  131. package/dist/serializable-numeric-identifier-validator.js.map +0 -1
@@ -1,36 +0,0 @@
1
- import { CharacterSetCreator, Exclusions } from "@aidc-toolkit/utility";
2
- /**
3
- * GS1 AI encodable character set 82 creator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs | GS1
4
- * General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
5
- */
6
- export const AI82_CREATOR = new CharacterSetCreator([
7
- "!", "\"", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/",
8
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
9
- ":", ";", "<", "=", ">", "?",
10
- "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
11
- "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
12
- "_",
13
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
14
- "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
15
- ], Exclusions.AllNumeric);
16
- /**
17
- * GS1 AI encodable character set 82 validator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs |
18
- * GS1 General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
19
- */
20
- export const AI82_VALIDATOR = AI82_CREATOR;
21
- /**
22
- * GS1 AI encodable character set 39 creator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs | GS1
23
- * General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
24
- */
25
- export const AI39_CREATOR = new CharacterSetCreator([
26
- "#", "-", "/",
27
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
28
- "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
29
- "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
30
- ], Exclusions.AllNumeric);
31
- /**
32
- * GS1 AI encodable character set 39 validator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs |
33
- * GS1 General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
34
- */
35
- export const AI39_VALIDATOR = AI39_CREATOR;
36
- //# sourceMappingURL=character-set.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"character-set.js","sourceRoot":"","sources":["../src/character-set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAA8B,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEpG;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,mBAAmB,CAAC;IAChD,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAChE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAChD,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAC5B,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EA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CAAC,MAAM,cAAc,GAAG,YAAqC,CAAC"}
package/dist/check.d.ts DELETED
@@ -1,81 +0,0 @@
1
- /**
2
- * Calculate the check digit sum for a numeric string as per section 7.9.1 of the {@link https://www.gs1.org/genspecs |
3
- * GS1 General Specifications}.
4
- *
5
- * @param exchangeWeights
6
- * If true, start the weights at 1 instead of 3 on the right.
7
- *
8
- * @param s
9
- * Numeric string.
10
- *
11
- * @returns
12
- * Accumulated sum of each digit multiplied by the weight at its position.
13
- */
14
- export declare function checkDigitSum(exchangeWeights: boolean, s: string): number;
15
- /**
16
- * Calculate the check digit for a numeric string as per section 7.9.1 of the {@link https://www.gs1.org/genspecs | GS1
17
- * General Specifications}.
18
- *
19
- * @param s
20
- * Numeric string.
21
- *
22
- * @returns
23
- * Check digit 0-9 as a string.
24
- */
25
- export declare function checkDigit(s: string): string;
26
- /**
27
- * Determine if a numeric string has a valid check digit.
28
- *
29
- * @param s
30
- * Numeric string with check digit.
31
- *
32
- * @returns
33
- * True if the check digit is valid.
34
- */
35
- export declare function hasValidCheckDigit(s: string): boolean;
36
- /**
37
- * Calculate the price or weight check digit for a four-or five-digit numeric string as per section 7.9.3 of the {@link
38
- * https://www.gs1.org/genspecs | GS1 General Specifications}.
39
- *
40
- * @param s
41
- * Numeric string exactly four or five characters long.
42
- *
43
- * @returns
44
- * Check digit 0-9 as a string.
45
- */
46
- export declare function priceOrWeightCheckDigit(s: string): string;
47
- /**
48
- * Determine if a price or weight check digit is valid for numeric string.
49
- *
50
- * @param s
51
- * Numeric string exactly four or five characters long.
52
- *
53
- * @param checkDigit
54
- * Price or weight check digit.
55
- *
56
- * @returns
57
- * True if the check digit is valid.
58
- */
59
- export declare function isValidPriceOrWeightCheckDigit(s: string, checkDigit: string): boolean;
60
- /**
61
- * Calculate the check character for a GS1 AI encodable character set 82 string as per section 7.9.5 of the {@link
62
- * https://www.gs1.org/genspecs | GS1 General Specifications}.
63
- *
64
- * @param s
65
- * GS1 AI encodable character set 82 string.
66
- *
67
- * @returns
68
- * Check character pair.
69
- */
70
- export declare function checkCharacterPair(s: string): string;
71
- /**
72
- * Determine if a GS1 AI encodable character set 82 string has a valid check character pair.
73
- *
74
- * @param s
75
- * GS1 AI encodable character set 82 string with check character pair.
76
- *
77
- * @returns
78
- * True if the check character pair is valid.
79
- */
80
- export declare function hasValidCheckCharacterPair(s: string): boolean;
81
- //# sourceMappingURL=check.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAuCA;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,eAAe,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAkBzE;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAG5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAGrD;AA+BD;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAmBzD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,8BAA8B,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAErF;AAiBD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CA4BpD;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAI7D"}
package/dist/check.js DELETED
@@ -1,218 +0,0 @@
1
- import { NUMERIC_CREATOR, utilityNS } from "@aidc-toolkit/utility";
2
- import { AI82_CREATOR } from "./character-set.js";
3
- import { i18nextGS1 } from "./locale/i18n.js";
4
- /**
5
- * Results of multiplying digits by 3.
6
- */
7
- const THREE_WEIGHT_RESULTS = [
8
- 0, 3, 6, 9, 12, 15, 18, 21, 24, 27
9
- ];
10
- /**
11
- * Results of multiplying digits by 2, subtracting tens digit, and extracting units digit.
12
- */
13
- const TWO_MINUS_WEIGHT_RESULTS = [
14
- 0, 2, 4, 6, 8, 9, 1, 3, 5, 7
15
- ];
16
- /**
17
- * Results of multiplying digits by 5, adding tens digit, and extracting units digit.
18
- */
19
- const FIVE_PLUS_WEIGHT_RESULTS = [
20
- 0, 5, 1, 6, 2, 7, 3, 8, 4, 9
21
- ];
22
- /**
23
- * Results of multiplying digits by 5, subtracting tens digit, and extracting units digit.
24
- */
25
- const FIVE_MINUS_WEIGHT_RESULTS = [
26
- 0, 5, 9, 4, 8, 3, 7, 2, 6, 1
27
- ];
28
- /**
29
- * Inverse mapping of FIVE_MINUS_WEIGHT_RESULTS.
30
- */
31
- const INVERSE_FIVE_MINUS_WEIGHT_RESULTS = [
32
- 0, 9, 7, 5, 3, 1, 8, 6, 4, 2
33
- ];
34
- /**
35
- * Calculate the check digit sum for a numeric string as per section 7.9.1 of the {@link https://www.gs1.org/genspecs |
36
- * GS1 General Specifications}.
37
- *
38
- * @param exchangeWeights
39
- * If true, start the weights at 1 instead of 3 on the right.
40
- *
41
- * @param s
42
- * Numeric string.
43
- *
44
- * @returns
45
- * Accumulated sum of each digit multiplied by the weight at its position.
46
- */
47
- export function checkDigitSum(exchangeWeights, s) {
48
- // Initial setting will be the opposite of that used for first character because it gets flipped before being used.
49
- let weight3 = (s.length + Number(exchangeWeights)) % 2 === 0;
50
- // Calculate sum of each character value multiplied by the weight at its position.
51
- return NUMERIC_CREATOR.characterIndexes(s).reduce((accumulator, characterIndex, index) => {
52
- if (characterIndex === undefined) {
53
- throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPosition", {
54
- ns: utilityNS,
55
- c: s.charAt(index),
56
- position: index + 1
57
- }));
58
- }
59
- weight3 = !weight3;
60
- return accumulator + (weight3 ? THREE_WEIGHT_RESULTS[characterIndex] : characterIndex);
61
- }, 0);
62
- }
63
- /**
64
- * Calculate the check digit for a numeric string as per section 7.9.1 of the {@link https://www.gs1.org/genspecs | GS1
65
- * General Specifications}.
66
- *
67
- * @param s
68
- * Numeric string.
69
- *
70
- * @returns
71
- * Check digit 0-9 as a string.
72
- */
73
- export function checkDigit(s) {
74
- // Check digit is the difference from the equal or next of multiple of 10.
75
- return NUMERIC_CREATOR.character(9 - (checkDigitSum(false, s) + 9) % 10);
76
- }
77
- /**
78
- * Determine if a numeric string has a valid check digit.
79
- *
80
- * @param s
81
- * Numeric string with check digit.
82
- *
83
- * @returns
84
- * True if the check digit is valid.
85
- */
86
- export function hasValidCheckDigit(s) {
87
- // Check digit is valid if the check digit sum with the weights exchanged is a multiple of 10.
88
- return checkDigitSum(true, s) % 10 === 0;
89
- }
90
- /**
91
- * Calculate the price or weight sum for a numeric string.
92
- *
93
- * @param weightsResults
94
- * Array of weight results arrays to apply to each digit.
95
- *
96
- * @param s
97
- * Numeric string the same length as the weightsResults array.
98
- *
99
- * @returns
100
- * Accumulated sum of the weight result for each digit at the digit's position.
101
- */
102
- function priceOrWeightSum(weightsResults, s) {
103
- // Calculate sum of each weight result for each digit at its position.
104
- return NUMERIC_CREATOR.characterIndexes(s).reduce((accumulator, characterIndex, index) => {
105
- if (characterIndex === undefined) {
106
- throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPositionOfComponent", {
107
- ns: utilityNS,
108
- c: s.charAt(index),
109
- position: index + 1,
110
- component: i18nextGS1.t("Check.priceOrWeightComponent")
111
- }));
112
- }
113
- // Add the weight result of the character index to the accumulator.
114
- return accumulator + weightsResults[index][characterIndex];
115
- }, 0);
116
- }
117
- /**
118
- * Calculate the price or weight check digit for a four-or five-digit numeric string as per section 7.9.3 of the {@link
119
- * https://www.gs1.org/genspecs | GS1 General Specifications}.
120
- *
121
- * @param s
122
- * Numeric string exactly four or five characters long.
123
- *
124
- * @returns
125
- * Check digit 0-9 as a string.
126
- */
127
- export function priceOrWeightCheckDigit(s) {
128
- let checkDigit;
129
- switch (s.length) {
130
- case 4:
131
- checkDigit = NUMERIC_CREATOR.character(priceOrWeightSum([TWO_MINUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS, THREE_WEIGHT_RESULTS, FIVE_MINUS_WEIGHT_RESULTS], s) * 3 % 10);
132
- break;
133
- case 5:
134
- 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]);
135
- break;
136
- default:
137
- throw new RangeError(i18nextGS1.t("Check.lengthOfStringForPriceOrWeightMustBeExactly", {
138
- length: s.length
139
- }));
140
- }
141
- return checkDigit;
142
- }
143
- /**
144
- * Determine if a price or weight check digit is valid for numeric string.
145
- *
146
- * @param s
147
- * Numeric string exactly four or five characters long.
148
- *
149
- * @param checkDigit
150
- * Price or weight check digit.
151
- *
152
- * @returns
153
- * True if the check digit is valid.
154
- */
155
- export function isValidPriceOrWeightCheckDigit(s, checkDigit) {
156
- return priceOrWeightCheckDigit(s) === checkDigit;
157
- }
158
- /**
159
- * Weights for check character pair calculation.
160
- */
161
- const CHECK_CHARACTER_WEIGHTS = [
162
- 107, 103, 101, 97, 89, 83, 79, 73, 71, 67, 61, 59, 53, 47, 43, 41, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2
163
- ];
164
- /**
165
- * Characters used to build check character pair.
166
- */
167
- const CHECK_CHARACTERS = [
168
- "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H",
169
- "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
170
- ];
171
- /**
172
- * Calculate the check character for a GS1 AI encodable character set 82 string as per section 7.9.5 of the {@link
173
- * https://www.gs1.org/genspecs | GS1 General Specifications}.
174
- *
175
- * @param s
176
- * GS1 AI encodable character set 82 string.
177
- *
178
- * @returns
179
- * Check character pair.
180
- */
181
- export function checkCharacterPair(s) {
182
- // Weights are applied from right to left.
183
- const weightIndexStart = CHECK_CHARACTER_WEIGHTS.length - s.length;
184
- if (weightIndexStart < 0) {
185
- throw new RangeError(i18nextGS1.t("Check.lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo", {
186
- length: s.length,
187
- maximumLength: CHECK_CHARACTER_WEIGHTS.length
188
- }));
189
- }
190
- // Calculate sum of each character value multiplied by the weight at its position, mod 1021.
191
- const checkCharacterPairSum = AI82_CREATOR.characterIndexes(s).reduce((accumulator, characterIndex, index) => {
192
- if (characterIndex === undefined) {
193
- throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPosition", {
194
- ns: utilityNS,
195
- c: s.charAt(index),
196
- position: index + 1
197
- }));
198
- }
199
- return accumulator + characterIndex * CHECK_CHARACTER_WEIGHTS[weightIndexStart + index];
200
- }, 0) % 1021;
201
- const checkCharacterPairSumMod32 = checkCharacterPairSum % 32;
202
- // Check character pair is the concatenation of the character at position sum div 32 and the character at the position sum mod 32.
203
- return CHECK_CHARACTERS[(checkCharacterPairSum - checkCharacterPairSumMod32) / 32] + CHECK_CHARACTERS[checkCharacterPairSumMod32];
204
- }
205
- /**
206
- * Determine if a GS1 AI encodable character set 82 string has a valid check character pair.
207
- *
208
- * @param s
209
- * GS1 AI encodable character set 82 string with check character pair.
210
- *
211
- * @returns
212
- * True if the check character pair is valid.
213
- */
214
- export function hasValidCheckCharacterPair(s) {
215
- const checkCharacterPairIndex = s.length - 2;
216
- return checkCharacterPair(s.substring(0, checkCharacterPairIndex)) === s.substring(checkCharacterPairIndex);
217
- }
218
- //# sourceMappingURL=check.js.map
package/dist/check.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"check.js","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,S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AC,CAAC,CAAC;IACR,CAAC;IAED,4FAA4F;IAC5F,MAAM,qBAAqB,GAAG,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAS,CAAC,WAAW,EAAE,cAAc,EAAE,KAAK,EAAE,EAAE;QACjH,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;YAC/B,MAAM,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,kDAAkD,EAAE;gBAClF,EAAE,EAAE,SAAS;gBACb,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBAClB,QAAQ,EAAE,KAAK,GAAG,CAAC;aACtB,CAAC,CAAC,CAAC;QACR,CAAC;QAED,OAAO,WAAW,GAAG,cAAc,GAAG,uBAAuB,CAAC,gBAAgB,GAAG,KAAK,CAAC,CAAC;IAC5F,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;IAEb,MAAM,0BAA0B,GAAG,qBAAqB,GAAG,EAAE,CAAC;IAE9D,kIAAkI;IAClI,OAAO,gBAAgB,CAAC,CAAC,qBAAqB,GAAG,0BAA0B,CAAC,GAAG,EAAE,CAAC,GAAG,gBAAgB,CAAC,0BAA0B,CAAC,CAAC;AACtI,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,0BAA0B,CAAC,CAAS;IAChD,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAE7C,OAAO,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC;AAChH,CAAC"}
@@ -1,68 +0,0 @@
1
- import { type TransformerInput, type TransformerOutput } from "@aidc-toolkit/utility";
2
- import { type GTINType, GTINValidator } from "./gtin-validator.js";
3
- import { AbstractNumericIdentifierCreator } from "./numeric-identifier-creator.js";
4
- import type { PrefixProvider } from "./prefix-provider";
5
- declare const GTINCreator_base: import("ts-mixer/dist/types/types.js").Class<any[], GTINValidator & AbstractNumericIdentifierCreator, typeof GTINValidator & typeof AbstractNumericIdentifierCreator>;
6
- /**
7
- * GTIN creator. Applicable to GTIN-13, GTIN-12, and GTIN-8 types; no applicable to GTIN-14 type.
8
- */
9
- export declare class GTINCreator extends GTINCreator_base {
10
- /**
11
- * Validation parameters for required indicator digit.
12
- */
13
- private static readonly REQUIRED_INDICATOR_DIGIT_VALIDATION;
14
- /**
15
- * Constructor. Typically called internally by a prefix manager but may be called by other code with another prefix
16
- * provider type.
17
- *
18
- * @param prefixProvider
19
- * Prefix provider.
20
- *
21
- * @param gtinType
22
- * GTIN type.
23
- */
24
- constructor(prefixProvider: PrefixProvider, gtinType: GTINType);
25
- /**
26
- * @inheritDoc
27
- */
28
- get prefix(): string;
29
- /**
30
- * Create GTIN-14(s) with an indicator digit and reference(s) based on numeric value(s). The value(s) is/are
31
- * converted to reference(s) of the appropriate length using {@linkcode NUMERIC_CREATOR}.
32
- *
33
- * @template TTransformerInput
34
- * Transformer input type.
35
- *
36
- * @param indicatorDigit
37
- * Indicator digit.
38
- *
39
- * @param valueOrValues
40
- * Numeric value(s).
41
- *
42
- * @param sparse
43
- * If true, the value(s) is/are mapped to a sparse sequence resistant to discovery. Default is false.
44
- *
45
- * @returns
46
- * GTIN-14(s).
47
- */
48
- createGTIN14<TTransformerInput extends TransformerInput<number | bigint>>(indicatorDigit: string, valueOrValues: TTransformerInput, sparse?: boolean): TransformerOutput<TTransformerInput, string>;
49
- /**
50
- * Create a Restricted Circulation Number (RCN) using a variable measure trade item format. See {@linkcode
51
- * GTINValidator.parseVariableMeasureRCN} for format details.
52
- *
53
- * @param format
54
- * Format.
55
- *
56
- * @param itemReference
57
- * Item reference.
58
- *
59
- * @param priceOrWeight
60
- * Price or weight (whole number only).
61
- *
62
- * @returns
63
- * RCN-12 or RCN-13.
64
- */
65
- static createVariableMeasureRCN(format: string, itemReference: number, priceOrWeight: number): string;
66
- }
67
- export {};
68
- //# sourceMappingURL=gtin-creator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gtin-creator.d.ts","sourceRoot":"","sources":["../src/gtin-creator.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACzB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,KAAK,QAAQ,EAAa,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE9E,OAAO,EAAE,gCAAgC,EAAE,MAAM,iCAAiC,CAAC;AACnF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;;AAExD;;GAEG;AACH,qBAAa,WAAY,SAAQ,gBAAsD;IACnF;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mCAAmC,CAIzD;IAEF;;;;;;;;;OASG;gBACS,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ;IAM9D;;OAEG;IACH,IAAa,MAAM,IAAI,MAAM,CAE5B;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAAY,CAAC,iBAAiB,SAAS,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,UAAQ,GAAG,iBAAiB,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAUjM;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM;CAmGxG"}
@@ -1,158 +0,0 @@
1
- import { Exclusions, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
2
- import { Mixin } from "ts-mixer";
3
- import { checkDigit, priceOrWeightCheckDigit } from "./check.js";
4
- import { GTINTypes, GTINValidator } from "./gtin-validator.js";
5
- import { i18nextGS1 } from "./locale/i18n.js";
6
- import { AbstractNumericIdentifierCreator } from "./numeric-identifier-creator.js";
7
- /**
8
- * GTIN creator. Applicable to GTIN-13, GTIN-12, and GTIN-8 types; no applicable to GTIN-14 type.
9
- */
10
- export class GTINCreator extends Mixin(GTINValidator, AbstractNumericIdentifierCreator) {
11
- /**
12
- * Validation parameters for required indicator digit.
13
- */
14
- static REQUIRED_INDICATOR_DIGIT_VALIDATION = {
15
- minimumLength: 1,
16
- maximumLength: 1,
17
- component: () => i18nextGS1.t("Identifier.indicatorDigit")
18
- };
19
- /**
20
- * Constructor. Typically called internally by a prefix manager but may be called by other code with another prefix
21
- * provider type.
22
- *
23
- * @param prefixProvider
24
- * Prefix provider.
25
- *
26
- * @param gtinType
27
- * GTIN type.
28
- */
29
- constructor(prefixProvider, gtinType) {
30
- super(gtinType);
31
- this.init(prefixProvider, prefixProvider.prefix);
32
- }
33
- /**
34
- * @inheritDoc
35
- */
36
- get prefix() {
37
- return this.prefixProvider.prefix;
38
- }
39
- /**
40
- * Create GTIN-14(s) with an indicator digit and reference(s) based on numeric value(s). The value(s) is/are
41
- * converted to reference(s) of the appropriate length using {@linkcode NUMERIC_CREATOR}.
42
- *
43
- * @template TTransformerInput
44
- * Transformer input type.
45
- *
46
- * @param indicatorDigit
47
- * Indicator digit.
48
- *
49
- * @param valueOrValues
50
- * Numeric value(s).
51
- *
52
- * @param sparse
53
- * If true, the value(s) is/are mapped to a sparse sequence resistant to discovery. Default is false.
54
- *
55
- * @returns
56
- * GTIN-14(s).
57
- */
58
- createGTIN14(indicatorDigit, valueOrValues, sparse = false) {
59
- NUMERIC_CREATOR.validate(indicatorDigit, GTINCreator.REQUIRED_INDICATOR_DIGIT_VALIDATION);
60
- return NUMERIC_CREATOR.create(GTINTypes.GTIN13 - this.prefixProvider.gs1CompanyPrefix.length - 1, valueOrValues, Exclusions.None, sparse ? this.tweak : undefined, (reference) => {
61
- const partialIdentifier = indicatorDigit + this.prefixProvider.gs1CompanyPrefix + reference;
62
- return partialIdentifier + checkDigit(partialIdentifier);
63
- });
64
- }
65
- /**
66
- * Create a Restricted Circulation Number (RCN) using a variable measure trade item format. See {@linkcode
67
- * GTINValidator.parseVariableMeasureRCN} for format details.
68
- *
69
- * @param format
70
- * Format.
71
- *
72
- * @param itemReference
73
- * Item reference.
74
- *
75
- * @param priceOrWeight
76
- * Price or weight (whole number only).
77
- *
78
- * @returns
79
- * RCN-12 or RCN-13.
80
- */
81
- static createVariableMeasureRCN(format, itemReference, priceOrWeight) {
82
- const formatLength = format.length;
83
- let validFormat = formatLength === 12 || formatLength === 13;
84
- let rcnPrefix = "";
85
- let buildingItemReference = false;
86
- let itemReferenceString = "";
87
- let itemReferenceLength = 0;
88
- let buildingPriceOrWeight = false;
89
- let priceOrWeightString = "";
90
- let priceOrWeightLength = 0;
91
- let calculatePriceOrWeightCheckDigit = false;
92
- // RCN may be built in almost any order, so defer to builders that will be in ordered array.
93
- const rcnPrefixBuilder = (partialRCN) => partialRCN + rcnPrefix;
94
- const itemReferenceBuilder = (partialRCN) => partialRCN + itemReferenceString;
95
- const priceOrWeightBuilder = (partialRCN) => partialRCN + priceOrWeightString;
96
- const priceOrWeightCheckDigitBuilder = (partialRCN) => partialRCN + priceOrWeightCheckDigit(priceOrWeightString);
97
- const checkDigitBuilder = (partialRCN) => partialRCN + checkDigit(partialRCN);
98
- const rcnBuilders = [rcnPrefixBuilder];
99
- for (let index = 0; validFormat && index < formatLength; index++) {
100
- const formatChar = format.charAt(index);
101
- if (index === 0) {
102
- validFormat = formatChar === "2";
103
- rcnPrefix = formatChar;
104
- }
105
- else if (formatLength === 13 && index === 1) {
106
- validFormat = NUMERIC_CREATOR.characterIndex(formatChar) !== undefined;
107
- rcnPrefix += formatChar;
108
- }
109
- else if (index === formatLength - 1) {
110
- validFormat = formatChar === "C";
111
- }
112
- else {
113
- switch (formatChar) {
114
- case "I":
115
- if (!buildingItemReference) {
116
- // Item reference can't appear more than once.
117
- validFormat = itemReferenceLength === 0;
118
- buildingItemReference = true;
119
- buildingPriceOrWeight = false;
120
- rcnBuilders.push(itemReferenceBuilder);
121
- }
122
- itemReferenceLength++;
123
- break;
124
- case "P":
125
- if (!buildingPriceOrWeight) {
126
- // Price or weight can't appear more than once.
127
- validFormat = priceOrWeightLength === 0;
128
- buildingPriceOrWeight = true;
129
- buildingItemReference = false;
130
- rcnBuilders.push(priceOrWeightBuilder);
131
- }
132
- priceOrWeightLength++;
133
- break;
134
- case "V":
135
- // Price or weight check digit can't appear more than once.
136
- validFormat = !calculatePriceOrWeightCheckDigit;
137
- buildingItemReference = false;
138
- buildingPriceOrWeight = false;
139
- calculatePriceOrWeightCheckDigit = true;
140
- rcnBuilders.push(priceOrWeightCheckDigitBuilder);
141
- break;
142
- default:
143
- validFormat = false;
144
- break;
145
- }
146
- }
147
- }
148
- validFormat &&= itemReferenceLength !== 0 && priceOrWeightLength !== 0;
149
- if (!validFormat) {
150
- throw new RangeError(i18nextGS1.t("Identifier.invalidVariableMeasureRCNFormat"));
151
- }
152
- itemReferenceString = NUMERIC_CREATOR.create(itemReferenceLength, itemReference);
153
- priceOrWeightString = NUMERIC_CREATOR.create(priceOrWeightLength, priceOrWeight);
154
- rcnBuilders.push(checkDigitBuilder);
155
- return rcnBuilders.reduce((partialRCN, rcnBuilder) => rcnBuilder(partialRCN), "");
156
- }
157
- }
158
- //# sourceMappingURL=gtin-creator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gtin-creator.js","sourceRoot":"","sources":["../src/gtin-creator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,UAAU,EACV,eAAe,EAGlB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAiB,SAAS,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gCAAgC,EAAE,MAAM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