@aidc-toolkit/gs1 1.0.24-beta → 1.0.25-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 (60) hide show
  1. package/dist/index.cjs +562 -373
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +776 -415
  4. package/dist/index.d.ts +776 -415
  5. package/dist/index.js +549 -363
  6. package/dist/index.js.map +1 -1
  7. package/package.json +5 -5
  8. package/src/abstract-identifier-creator.ts +97 -0
  9. package/src/abstract-identifier-validator.ts +140 -0
  10. package/src/abstract-numeric-identifier-creator.ts +168 -0
  11. package/src/abstract-numeric-identifier-validator.ts +69 -0
  12. package/src/character-set.ts +10 -10
  13. package/src/check.ts +7 -7
  14. package/src/content-character-set.ts +29 -0
  15. package/src/creators.ts +113 -0
  16. package/src/descriptors.ts +332 -0
  17. package/src/gtin-creator.ts +7 -6
  18. package/src/gtin-descriptor.ts +18 -0
  19. package/src/gtin-type.ts +50 -0
  20. package/src/gtin-validator.ts +36 -60
  21. package/src/identifier-creator.ts +11 -75
  22. package/src/identifier-descriptor.ts +30 -0
  23. package/src/identifier-type.ts +6 -1
  24. package/src/identifier-validator.ts +12 -188
  25. package/src/index.ts +29 -5
  26. package/src/locale/en/locale-resources.ts +0 -1
  27. package/src/locale/fr/locale-resources.ts +0 -1
  28. package/src/non-gtin-numeric-identifier-creator.ts +5 -11
  29. package/src/non-gtin-numeric-identifier-descriptor.ts +24 -0
  30. package/src/non-gtin-numeric-identifier-type.ts +7 -0
  31. package/src/non-gtin-numeric-identifier-validator.ts +8 -42
  32. package/src/non-numeric-identifier-creator.ts +5 -15
  33. package/src/non-numeric-identifier-descriptor.ts +29 -0
  34. package/src/non-numeric-identifier-type.ts +7 -0
  35. package/src/non-numeric-identifier-validator.ts +15 -53
  36. package/src/numeric-identifier-creator.ts +20 -163
  37. package/src/numeric-identifier-descriptor.ts +23 -0
  38. package/src/numeric-identifier-type.ts +44 -0
  39. package/src/numeric-identifier-validator.ts +13 -116
  40. package/src/prefix-manager.ts +84 -142
  41. package/src/prefix-provider.ts +2 -2
  42. package/src/prefix-type.ts +6 -1
  43. package/src/prefix-validator.ts +141 -79
  44. package/src/serializable-numeric-identifier-creator.ts +4 -14
  45. package/src/serializable-numeric-identifier-descriptor.ts +29 -0
  46. package/src/serializable-numeric-identifier-type.ts +9 -0
  47. package/src/serializable-numeric-identifier-validator.ts +17 -45
  48. package/src/validators.ts +203 -0
  49. package/test/creator.test.ts +2 -4
  50. package/test/gtin-creator.ts +5 -1
  51. package/test/gtin-validator.test.ts +5 -8
  52. package/test/identifier-creator.ts +1 -0
  53. package/test/identifier-validator.ts +2 -2
  54. package/test/non-gtin-numeric-identifier-creator.ts +8 -92
  55. package/test/non-gtin-numeric-identifier-validator.ts +1 -1
  56. package/test/non-numeric-identifier-creator.ts +93 -0
  57. package/test/numeric-identifier-creator.ts +9 -3
  58. package/test/numeric-identifier-validator.ts +3 -7
  59. package/test/serializable-numeric-identifier-creator.ts +10 -2
  60. package/test/validator.test.ts +59 -35
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aidc-toolkit/gs1",
3
- "version": "1.0.24-beta",
3
+ "version": "1.0.25-beta",
4
4
  "description": "GS1 AIDC Toolkit",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -23,12 +23,12 @@
23
23
  "test": "vitest run"
24
24
  },
25
25
  "devDependencies": {
26
- "@aidc-toolkit/dev": "beta",
27
- "vitest": "^4.0.14"
26
+ "@aidc-toolkit/dev": "1.0.25-beta",
27
+ "vitest": "^4.0.15"
28
28
  },
29
29
  "dependencies": {
30
- "@aidc-toolkit/core": "beta",
31
- "@aidc-toolkit/utility": "beta",
30
+ "@aidc-toolkit/core": "1.0.25-beta",
31
+ "@aidc-toolkit/utility": "1.0.25-beta",
32
32
  "ts-mixer": "^6.0.4"
33
33
  }
34
34
  }
@@ -0,0 +1,97 @@
1
+ import type { CharacterSetCreator } from "@aidc-toolkit/utility";
2
+ import type { IdentifierCreator } from "./identifier-creator";
3
+ import type { IdentifierDescriptor } from "./identifier-descriptor";
4
+ import type { IdentifierValidation } from "./identifier-validator";
5
+ import type { PrefixProvider } from "./prefix-provider";
6
+
7
+ /**
8
+ * Abstract identifier creator. Implements common functionality for an identifier creator, bound to a {@link
9
+ * PrefixProvider | prefix provider}.
10
+ *
11
+ * @template TIdentifierDescriptor
12
+ * Identifier descriptor type.
13
+ *
14
+ * @template TIdentifierValidation
15
+ * Identifier validation type.
16
+ */
17
+ export abstract class AbstractIdentifierCreator<TIdentifierDescriptor extends IdentifierDescriptor, TIdentifierValidation extends IdentifierValidation> implements IdentifierCreator<TIdentifierDescriptor, TIdentifierValidation> {
18
+ /**
19
+ * Prefix provider.
20
+ */
21
+ private _prefixProvider!: PrefixProvider;
22
+
23
+ /**
24
+ * Reference length.
25
+ */
26
+ private _referenceLength!: number;
27
+
28
+ /**
29
+ * Initialize the prefix provider. This method is in lieu of a constructor due to the mixin architecture.
30
+ *
31
+ * @param prefixProvider
32
+ * Prefix provider.
33
+ *
34
+ * @param prefix
35
+ * Prefix within prefix provider to use to calculate reference length.
36
+ *
37
+ * @param checkAllowance
38
+ * Number of characters to allow for check digit or check character pair.
39
+ */
40
+ protected init(prefixProvider: PrefixProvider, prefix: string, checkAllowance: number): void {
41
+ this._prefixProvider = prefixProvider;
42
+
43
+ // Reference length allows for prefix and optionally check digit or check character pair.
44
+ this._referenceLength = this.length - prefix.length - checkAllowance;
45
+ }
46
+
47
+ /**
48
+ * @inheritDoc
49
+ */
50
+ abstract get identifierType(): TIdentifierDescriptor["identifierType"];
51
+
52
+ /**
53
+ * @inheritDoc
54
+ */
55
+ abstract get prefixType(): TIdentifierDescriptor["prefixType"];
56
+
57
+ /**
58
+ * @inheritDoc
59
+ */
60
+ abstract get length(): number;
61
+
62
+ /**
63
+ * @inheritDoc
64
+ */
65
+ abstract get referenceCharacterSet(): TIdentifierDescriptor["referenceCharacterSet"];
66
+
67
+ /**
68
+ * @inheritDoc
69
+ */
70
+ abstract get referenceCreator(): CharacterSetCreator;
71
+
72
+ /**
73
+ * @inheritDoc
74
+ */
75
+ get prefixProvider(): PrefixProvider {
76
+ return this._prefixProvider;
77
+ }
78
+
79
+ /**
80
+ * @inheritDoc
81
+ */
82
+ get prefix(): string {
83
+ return this.prefixProvider.gs1CompanyPrefix;
84
+ }
85
+
86
+ /**
87
+ * @inheritDoc
88
+ */
89
+ get referenceLength(): number {
90
+ return this._referenceLength;
91
+ }
92
+
93
+ /**
94
+ * @inheritDoc
95
+ */
96
+ abstract validate(identifier: string, validation?: TIdentifierValidation): void;
97
+ }
@@ -0,0 +1,140 @@
1
+ import { type CharacterSetCreator, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
2
+ import { AI39_CREATOR, AI82_CREATOR } from "./character-set";
3
+ import { type ContentCharacterSet, ContentCharacterSets } from "./content-character-set";
4
+ import type { IdentifierDescriptor } from "./identifier-descriptor";
5
+ import type { IdentifierValidation, IdentifierValidator } from "./identifier-validator";
6
+ import { PrefixTypes } from "./prefix-type";
7
+ import { PrefixValidator } from "./prefix-validator";
8
+
9
+ /**
10
+ * Abstract identifier validator. Implements common functionality for an identifier validator.
11
+ *
12
+ * @template TIdentifierDescriptor
13
+ * Identifier descriptor type.
14
+ *
15
+ * @template TIdentifierValidation
16
+ * Identifier validation type.
17
+ */
18
+ export abstract class AbstractIdentifierValidator<TIdentifierDescriptor extends IdentifierDescriptor, TIdentifierValidation extends IdentifierValidation> implements IdentifierValidator<TIdentifierDescriptor, TIdentifierValidation> {
19
+ private static readonly CHARACTER_SET_CREATORS: Record<ContentCharacterSet, CharacterSetCreator> = {
20
+ [ContentCharacterSets.Numeric]: NUMERIC_CREATOR,
21
+ [ContentCharacterSets.AI82]: AI82_CREATOR,
22
+ [ContentCharacterSets.AI39]: AI39_CREATOR
23
+ };
24
+
25
+ /**
26
+ * Identifier type.
27
+ */
28
+ private readonly _identifierType: TIdentifierDescriptor["identifierType"];
29
+
30
+ /**
31
+ * Length.
32
+ */
33
+ private readonly _length: number;
34
+
35
+ /**
36
+ * Reference character set.
37
+ */
38
+ private readonly _referenceCharacterSet: TIdentifierDescriptor["referenceCharacterSet"];
39
+
40
+ /**
41
+ * Reference creator.
42
+ */
43
+ private readonly _referenceCreator: CharacterSetCreator;
44
+
45
+ /**
46
+ * Get the character set creator for a character set.
47
+ *
48
+ * @param characterSet
49
+ * Character set.
50
+ *
51
+ * @returns
52
+ * Character set creator.
53
+ */
54
+ protected static creatorFor(characterSet: ContentCharacterSet): CharacterSetCreator {
55
+ return AbstractIdentifierValidator.CHARACTER_SET_CREATORS[characterSet];
56
+ }
57
+
58
+ /**
59
+ * Constructor.
60
+ *
61
+ * @param identifierDescriptor
62
+ * Identifier descriptor.
63
+ */
64
+ protected constructor(identifierDescriptor: IdentifierDescriptor) {
65
+ this._identifierType = identifierDescriptor.identifierType;
66
+ this._length = identifierDescriptor.length;
67
+ this._referenceCharacterSet = identifierDescriptor.referenceCharacterSet;
68
+ this._referenceCreator = AbstractIdentifierValidator.creatorFor(identifierDescriptor.referenceCharacterSet);
69
+ }
70
+
71
+ /**
72
+ * @inheritDoc
73
+ */
74
+ get identifierType(): TIdentifierDescriptor["identifierType"] {
75
+ return this._identifierType;
76
+ }
77
+
78
+ /**
79
+ * @inheritDoc
80
+ */
81
+ get prefixType(): TIdentifierDescriptor["prefixType"] {
82
+ // All identifier types except GTIN support only the GS1 Company Prefix.
83
+ return PrefixTypes.GS1CompanyPrefix;
84
+ }
85
+
86
+ /**
87
+ * @inheritDoc
88
+ */
89
+ get length(): number {
90
+ return this._length;
91
+ }
92
+
93
+ /**
94
+ * @inheritDoc
95
+ */
96
+ get referenceCharacterSet(): TIdentifierDescriptor["referenceCharacterSet"] {
97
+ return this._referenceCharacterSet;
98
+ }
99
+
100
+ /**
101
+ * @inheritDoc
102
+ */
103
+ get referenceCreator(): CharacterSetCreator {
104
+ return this._referenceCreator;
105
+ }
106
+
107
+ /**
108
+ * Pad an identifier on the left with zero-value character for validation purposes. This is done to align an
109
+ * identifier with a position offset for any error message that may be thrown by the reference validator.
110
+ *
111
+ * @param identifier
112
+ * Identifier.
113
+ *
114
+ * @param positionOffset
115
+ * Position offset within a larger string.
116
+ *
117
+ * @returns
118
+ * Padded identifier.
119
+ */
120
+ protected padIdentifier(identifier: string, positionOffset?: number): string {
121
+ // Identifier is returned as is if position offset is undefined.
122
+ return positionOffset === undefined ? identifier : this.referenceCreator.character(0).repeat(positionOffset).concat(identifier);
123
+ }
124
+
125
+ /**
126
+ * Validate the prefix within an identifier.
127
+ *
128
+ * @param partialIdentifier
129
+ * Partial identifier.
130
+ *
131
+ * @param positionOffset
132
+ * Position offset within a larger string.
133
+ */
134
+ protected validatePrefix(partialIdentifier: string, positionOffset?: number): void {
135
+ // Delegate to prefix validator with support for U.P.C. Company Prefix but not GS1-8 Prefix.
136
+ PrefixValidator.validate(this.prefixType, true, false, partialIdentifier, true, this.referenceCharacterSet === ContentCharacterSets.Numeric, positionOffset);
137
+ }
138
+
139
+ abstract validate(identifier: string, validation?: TIdentifierValidation): void;
140
+ }
@@ -0,0 +1,168 @@
1
+ import {
2
+ CharacterSetCreator,
3
+ Exclusions,
4
+ NUMERIC_CREATOR,
5
+ type TransformerInput,
6
+ type TransformerOutput
7
+ } from "@aidc-toolkit/utility";
8
+ import { AbstractIdentifierCreator } from "./abstract-identifier-creator";
9
+ import { checkDigit, checkDigitSum } from "./check";
10
+ import type { NumericIdentifierCreator } from "./numeric-identifier-creator";
11
+ import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor";
12
+ import { type LeaderType, LeaderTypes } from "./numeric-identifier-type";
13
+ import type { NumericIdentifierValidation } from "./numeric-identifier-validator";
14
+ import type { PrefixProvider } from "./prefix-provider";
15
+
16
+ /**
17
+ * Abstract numeric identifier creator. Implements common functionality for a numeric identifier creator.
18
+ *
19
+ * @template TNumericIdentifierDescriptor
20
+ * Numeric identifier descriptor type.
21
+ */
22
+ export abstract class AbstractNumericIdentifierCreator<TNumericIdentifierDescriptor extends NumericIdentifierDescriptor> extends AbstractIdentifierCreator<TNumericIdentifierDescriptor, NumericIdentifierValidation> implements NumericIdentifierCreator<TNumericIdentifierDescriptor> {
23
+ /**
24
+ * Capacity.
25
+ */
26
+ private _capacity!: number;
27
+
28
+ /**
29
+ * Tweak for sparse creation.
30
+ */
31
+ private _tweak = 0n;
32
+
33
+ /**
34
+ * Initialize the prefix provider. This method is in lieu of a constructor due to the mixin architecture.
35
+ *
36
+ * @param prefixProvider
37
+ * Prefix provider.
38
+ *
39
+ * @param prefix
40
+ * Prefix within prefix manager to use to calculate reference length.
41
+ */
42
+ protected override init(prefixProvider: PrefixProvider, prefix: string): void {
43
+ super.init(prefixProvider, prefix, 1);
44
+
45
+ // Capacity is always in number range.
46
+ this._capacity = Number(CharacterSetCreator.powerOf10(this.referenceLength));
47
+ }
48
+
49
+ /**
50
+ * Get the leader type.
51
+ */
52
+ abstract get leaderType(): LeaderType;
53
+
54
+ /**
55
+ * @inheritDoc
56
+ */
57
+ get capacity(): number {
58
+ return this._capacity;
59
+ }
60
+
61
+ /**
62
+ * @inheritDoc
63
+ */
64
+ get tweak(): bigint {
65
+ return this._tweak;
66
+ }
67
+
68
+ /**
69
+ * @inheritDoc
70
+ */
71
+ set tweak(value: bigint) {
72
+ this._tweak = value;
73
+ }
74
+
75
+ /**
76
+ * Build an identifier from a reference by merging it with the prefix and adding the check digit.
77
+ *
78
+ * @param reference
79
+ * Identifier reference.
80
+ *
81
+ * @returns
82
+ * Identifier.
83
+ */
84
+ private buildIdentifier(reference: string): string {
85
+ const partialIdentifier = this.leaderType === LeaderTypes.ExtensionDigit ? reference.substring(0, 1) + this.prefix + reference.substring(1) : this.prefix + reference;
86
+
87
+ return partialIdentifier + checkDigit(partialIdentifier);
88
+ }
89
+
90
+ /**
91
+ * @inheritDoc
92
+ */
93
+ create<TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput, sparse = false): TransformerOutput<TTransformerInput, string> {
94
+ return NUMERIC_CREATOR.create(this.referenceLength, valueOrValues, Exclusions.None, sparse ? this.tweak : undefined, reference => this.buildIdentifier(reference));
95
+ }
96
+
97
+ /**
98
+ * Create all identifiers from a partial identifier. Call is recursive until remaining reference
99
+ * length is 0.
100
+ *
101
+ * @param partialIdentifier
102
+ * Partial identifier. Initial value is `this.prefix`.
103
+ *
104
+ * @param remainingReferenceLength
105
+ * Remaining reference length. Initial value is `this.referenceLength`.
106
+ *
107
+ * @param extensionWeight
108
+ * If this value is not zero, the identifier has an extension digit, this call is setting it, and this value is
109
+ * applied to the calculation of the check digit.
110
+ *
111
+ * @param weight
112
+ * If the extension weight is zero, this value is applied to the calculation of the check digit.
113
+ *
114
+ * @param partialCheckDigitSum
115
+ * Partial check digit sum for the partial identifier.
116
+ *
117
+ * @yields
118
+ * Identifier.
119
+ */
120
+ private static * createAllPartial(partialIdentifier: string, remainingReferenceLength: number, extensionWeight: number, weight: number, partialCheckDigitSum: number): Generator<string> {
121
+ if (remainingReferenceLength === 0) {
122
+ // Finalize check digit calculation and append.
123
+ yield partialIdentifier + NUMERIC_CREATOR.character(9 - (partialCheckDigitSum + 9) % 10);
124
+ } else {
125
+ const nextRemainingReferenceLength = remainingReferenceLength - 1;
126
+
127
+ let nextPartialCheckDigitSum = partialCheckDigitSum;
128
+
129
+ if (extensionWeight !== 0) {
130
+ // Apply every digit to the extension digit.
131
+ for (const c of NUMERIC_CREATOR.characterSet) {
132
+ yield * AbstractNumericIdentifierCreator.createAllPartial(c + partialIdentifier, nextRemainingReferenceLength, 0, weight, nextPartialCheckDigitSum);
133
+
134
+ nextPartialCheckDigitSum += extensionWeight;
135
+ }
136
+ } else {
137
+ const nextWeight = 4 - weight;
138
+
139
+ // Apply every digit to the current character in the identifier.
140
+ for (const c of NUMERIC_CREATOR.characterSet) {
141
+ yield * AbstractNumericIdentifierCreator.createAllPartial(partialIdentifier + c, nextRemainingReferenceLength, 0, nextWeight, nextPartialCheckDigitSum);
142
+
143
+ nextPartialCheckDigitSum += weight;
144
+ }
145
+ }
146
+ }
147
+ }
148
+
149
+ /**
150
+ * @inheritDoc
151
+ */
152
+ createAll(): Iterable<string> {
153
+ const hasExtensionDigit = this.leaderType === LeaderTypes.ExtensionDigit;
154
+ const prefix = this.prefix;
155
+ const length = this.length;
156
+ const referenceLength = this.referenceLength;
157
+
158
+ // Start weight is for reference excluding extension digit, which has its weight calculated separately.
159
+ const startWeight = 3 - 2 * ((referenceLength + 1 - Number(hasExtensionDigit)) % 2);
160
+
161
+ // Returning separate Iterable object makes iteration repeatable.
162
+ return {
163
+ [Symbol.iterator]() {
164
+ return AbstractNumericIdentifierCreator.createAllPartial(prefix, referenceLength, hasExtensionDigit ? 3 - 2 * length % 2 : 0, startWeight, checkDigitSum(startWeight === 3, prefix));
165
+ }
166
+ };
167
+ }
168
+ }
@@ -0,0 +1,69 @@
1
+ import { AbstractIdentifierValidator } from "./abstract-identifier-validator";
2
+ import { hasValidCheckDigit } from "./check";
3
+ import { i18nextGS1 } from "./locale/i18n";
4
+ import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor";
5
+ import { LeaderTypes } from "./numeric-identifier-type";
6
+ import type { NumericIdentifierValidation, NumericIdentifierValidator } from "./numeric-identifier-validator";
7
+
8
+ /**
9
+ * Abstract numeric identifier validator.
10
+ *
11
+ * @template TNumericIdentifierDescriptor
12
+ * Numeric identifier descriptor type.
13
+ */
14
+ export abstract class AbstractNumericIdentifierValidator<TNumericIdentifierDescriptor extends NumericIdentifierDescriptor> extends AbstractIdentifierValidator<TNumericIdentifierDescriptor, NumericIdentifierValidation> implements NumericIdentifierValidator<TNumericIdentifierDescriptor> {
15
+ /**
16
+ * Leader type.
17
+ */
18
+ private readonly _leaderType: TNumericIdentifierDescriptor["leaderType"];
19
+
20
+ /**
21
+ * Prefix position, determined by the leader type.
22
+ */
23
+ private readonly _prefixPosition: number;
24
+
25
+ /**
26
+ * Constructor.
27
+ *
28
+ * @param identifierDescriptor
29
+ * Identifier descriptor.
30
+ */
31
+ constructor(identifierDescriptor: NumericIdentifierDescriptor) {
32
+ super(identifierDescriptor);
33
+
34
+ this._leaderType = identifierDescriptor.leaderType;
35
+ this._prefixPosition = Number(this.leaderType === LeaderTypes.ExtensionDigit);
36
+ }
37
+
38
+ /**
39
+ * @inheritDoc
40
+ */
41
+ get leaderType(): TNumericIdentifierDescriptor["leaderType"] {
42
+ return this._leaderType;
43
+ }
44
+
45
+ /**
46
+ * @inheritDoc
47
+ */
48
+ validate(identifier: string, validation?: NumericIdentifierValidation): void {
49
+ // Validate the prefix, with care taken for its position within the identifier.
50
+ if (this._prefixPosition === 0) {
51
+ super.validatePrefix(identifier, validation?.positionOffset);
52
+ } else {
53
+ super.validatePrefix(identifier.substring(this._prefixPosition), validation?.positionOffset === undefined ? this._prefixPosition : validation.positionOffset + this._prefixPosition);
54
+ }
55
+
56
+ // Validate the length.
57
+ if (identifier.length !== this.length) {
58
+ throw new RangeError(i18nextGS1.t("Identifier.identifierTypeLength", {
59
+ identifierType: this.identifierType,
60
+ length: this.length
61
+ }));
62
+ }
63
+
64
+ // Validating the check digit will also validate the characters.
65
+ if (!hasValidCheckDigit(this.padIdentifier(identifier, validation?.positionOffset))) {
66
+ throw new RangeError(i18nextGS1.t("Identifier.invalidCheckDigit"));
67
+ }
68
+ }
69
+ }
@@ -1,8 +1,8 @@
1
1
  import { CharacterSetCreator, CharacterSetValidator, Exclusions } from "@aidc-toolkit/utility";
2
2
 
3
3
  /**
4
- * GS1 AI encodable character set 82 creator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs | GS1
5
- * General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
4
+ * GS1 AI encodable character set 82 creator as defined in section 7.11 of the {@link
5
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
6
6
  */
7
7
  export const AI82_CREATOR = new CharacterSetCreator([
8
8
  "!", "\"", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/",
@@ -16,14 +16,14 @@ export const AI82_CREATOR = new CharacterSetCreator([
16
16
  ], Exclusions.AllNumeric);
17
17
 
18
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 Exclusions.AllNumeric}.
19
+ * GS1 AI encodable character set 82 validator as defined in section 7.11 of the {@link
20
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
21
21
  */
22
22
  export const AI82_VALIDATOR = AI82_CREATOR as CharacterSetValidator;
23
23
 
24
24
  /**
25
- * GS1 AI encodable character set 39 creator as defined in section 7.11 of the {@link https://www.gs1.org/genspecs | GS1
26
- * General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
25
+ * GS1 AI encodable character set 39 creator as defined in section 7.11 of the {@link
26
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
27
27
  */
28
28
  export const AI39_CREATOR = new CharacterSetCreator([
29
29
  "#", "-", "/",
@@ -33,14 +33,14 @@ export const AI39_CREATOR = new CharacterSetCreator([
33
33
  ], Exclusions.AllNumeric);
34
34
 
35
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 Exclusions.AllNumeric}.
36
+ * GS1 AI encodable character set 39 validator as defined in section 7.11 of the {@link
37
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
38
38
  */
39
39
  export const AI39_VALIDATOR = AI39_CREATOR as CharacterSetValidator;
40
40
 
41
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.
42
+ * GS1 AI encodable character set 64 validator as defined in section 7.11 of the {@link
43
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}. Doesn't support any exclusions.
44
44
  */
45
45
  export const AI64_VALIDATOR = new CharacterSetValidator([
46
46
  "-",
package/src/check.ts CHANGED
@@ -38,8 +38,8 @@ const INVERSE_FIVE_MINUS_WEIGHT_RESULTS: readonly number[] = [
38
38
  ];
39
39
 
40
40
  /**
41
- * Calculate the check digit sum for a numeric string as per section 7.9.1 of the {@link https://www.gs1.org/genspecs |
42
- * GS1 General Specifications}.
41
+ * Calculate the check digit sum for a numeric string as per section 7.9.1 of the {@link
42
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
43
43
  *
44
44
  * @param exchangeWeights
45
45
  * If true, start the weights at 1 instead of 3 on the right.
@@ -71,8 +71,8 @@ export function checkDigitSum(exchangeWeights: boolean, s: string): number {
71
71
  }
72
72
 
73
73
  /**
74
- * Calculate the check digit for a numeric string as per section 7.9.1 of the {@link https://www.gs1.org/genspecs | GS1
75
- * General Specifications}.
74
+ * Calculate the check digit for a numeric string as per section 7.9.1 of the {@link
75
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
76
76
  *
77
77
  * @param s
78
78
  * Numeric string.
@@ -129,8 +129,8 @@ function priceOrWeightSum(weightsResults: ReadonlyArray<readonly number[]>, s: s
129
129
  }
130
130
 
131
131
  /**
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
133
- * https://www.gs1.org/genspecs | GS1 General Specifications}.
132
+ * Calculate the price or weight check digit for a four-or five-digit numeric string as per sections 7.9.2-7.9.4 of the
133
+ * {@link https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
134
134
  *
135
135
  * @param s
136
136
  * Numeric string exactly four or five characters long.
@@ -192,7 +192,7 @@ const CHECK_CHARACTERS = [
192
192
 
193
193
  /**
194
194
  * Calculate the check character for a GS1 AI encodable character set 82 string as per section 7.9.5 of the {@link
195
- * https://www.gs1.org/genspecs | GS1 General Specifications}.
195
+ * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
196
196
  *
197
197
  * @param s
198
198
  * GS1 AI encodable character set 82 string.
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Character sets supported by the reference portion of an identifier or the serial component of a numeric identifier.
3
+ */
4
+ export const ContentCharacterSets = {
5
+ /**
6
+ * Numeric.
7
+ */
8
+ Numeric: "Numeric",
9
+
10
+ /**
11
+ * GS1 AI encodable character set 82.
12
+ */
13
+ AI82: "AI82",
14
+
15
+ /**
16
+ * GS1 AI encodable character set 39.
17
+ */
18
+ AI39: "AI39"
19
+ } as const;
20
+
21
+ /**
22
+ * Content character set key.
23
+ */
24
+ export type ContentCharacterSetKey = keyof typeof ContentCharacterSets;
25
+
26
+ /**
27
+ * Content character set.
28
+ */
29
+ export type ContentCharacterSet = typeof ContentCharacterSets[ContentCharacterSetKey];