@aidc-toolkit/gs1 1.0.24-beta → 1.0.26-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/abstract-identifier-creator.d.ts +75 -0
- package/dist/abstract-identifier-creator.d.ts.map +1 -0
- package/dist/abstract-identifier-creator.js +56 -0
- package/dist/abstract-identifier-creator.js.map +1 -0
- package/dist/abstract-identifier-validator.d.ts +95 -0
- package/dist/abstract-identifier-validator.d.ts.map +1 -0
- package/dist/abstract-identifier-validator.js +123 -0
- package/dist/abstract-identifier-validator.js.map +1 -0
- package/dist/abstract-numeric-identifier-creator.d.ts +92 -0
- package/dist/abstract-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/abstract-numeric-identifier-creator.js +137 -0
- package/dist/abstract-numeric-identifier-creator.js.map +1 -0
- package/dist/abstract-numeric-identifier-validator.d.ts +35 -0
- package/dist/abstract-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/abstract-numeric-identifier-validator.js +61 -0
- package/dist/abstract-numeric-identifier-validator.js.map +1 -0
- package/dist/character-set.d.ts +27 -0
- package/dist/character-set.d.ts.map +1 -0
- package/dist/character-set.js +50 -0
- package/dist/character-set.js.map +1 -0
- package/dist/check.d.ts +81 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +218 -0
- package/dist/check.js.map +1 -0
- package/dist/content-character-set.d.ts +26 -0
- package/dist/content-character-set.d.ts.map +1 -0
- package/dist/content-character-set.js +18 -0
- package/dist/content-character-set.js.map +1 -0
- package/dist/creators.d.ts +81 -0
- package/dist/creators.d.ts.map +1 -0
- package/dist/creators.js +62 -0
- package/dist/creators.js.map +1 -0
- package/dist/descriptors.d.ts +96 -0
- package/dist/descriptors.d.ts.map +1 -0
- package/dist/descriptors.js +266 -0
- package/dist/descriptors.js.map +1 -0
- package/dist/gtin-creator.d.ts +69 -0
- package/dist/gtin-creator.d.ts.map +1 -0
- package/dist/gtin-creator.js +159 -0
- package/dist/gtin-creator.js.map +1 -0
- package/dist/gtin-descriptor.d.ts +17 -0
- package/dist/gtin-descriptor.d.ts.map +1 -0
- package/dist/gtin-descriptor.js +2 -0
- package/dist/gtin-descriptor.js.map +1 -0
- package/dist/gtin-type.d.ts +39 -0
- package/dist/gtin-type.d.ts.map +1 -0
- package/dist/gtin-type.js +31 -0
- package/dist/gtin-type.js.map +1 -0
- package/dist/gtin-validator.d.ts +191 -0
- package/dist/gtin-validator.d.ts.map +1 -0
- package/dist/gtin-validator.js +450 -0
- package/dist/gtin-validator.js.map +1 -0
- package/dist/identifier-creator.d.ts +31 -0
- package/dist/identifier-creator.d.ts.map +1 -0
- package/dist/identifier-creator.js +2 -0
- package/dist/identifier-creator.js.map +1 -0
- package/dist/identifier-descriptor.d.ts +27 -0
- package/dist/identifier-descriptor.d.ts.map +1 -0
- package/dist/identifier-descriptor.js +2 -0
- package/dist/identifier-descriptor.js.map +1 -0
- package/dist/identifier-type.d.ts +62 -0
- package/dist/identifier-type.d.ts.map +1 -0
- package/dist/identifier-type.js +54 -0
- package/dist/identifier-type.js.map +1 -0
- package/dist/identifier-validator.d.ts +53 -0
- package/dist/identifier-validator.d.ts.map +1 -0
- package/dist/identifier-validator.js +2 -0
- package/dist/identifier-validator.js.map +1 -0
- package/dist/index.d.ts +52 -1588
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -4541
- package/dist/index.js.map +1 -1
- package/dist/locale/en/locale-resources.d.ts +42 -0
- package/dist/locale/en/locale-resources.d.ts.map +1 -0
- package/dist/locale/en/locale-resources.js +41 -0
- package/dist/locale/en/locale-resources.js.map +1 -0
- package/dist/locale/fr/locale-resources.d.ts +42 -0
- package/dist/locale/fr/locale-resources.d.ts.map +1 -0
- package/dist/locale/fr/locale-resources.js +41 -0
- package/dist/locale/fr/locale-resources.js.map +1 -0
- package/dist/locale/i18n.d.ts +27 -0
- package/dist/locale/i18n.d.ts.map +1 -0
- package/dist/locale/i18n.js +36 -0
- package/dist/locale/i18n.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-creator.d.ts +24 -0
- package/dist/non-gtin-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-creator.js +23 -0
- package/dist/non-gtin-numeric-identifier-creator.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts +22 -0
- package/dist/non-gtin-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-descriptor.js +2 -0
- package/dist/non-gtin-numeric-identifier-descriptor.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-type.d.ts +7 -0
- package/dist/non-gtin-numeric-identifier-type.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-type.js +2 -0
- package/dist/non-gtin-numeric-identifier-type.js.map +1 -0
- package/dist/non-gtin-numeric-identifier-validator.d.ts +17 -0
- package/dist/non-gtin-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-gtin-numeric-identifier-validator.js +17 -0
- package/dist/non-gtin-numeric-identifier-validator.js.map +1 -0
- package/dist/non-numeric-identifier-creator.d.ts +45 -0
- package/dist/non-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/non-numeric-identifier-creator.js +84 -0
- package/dist/non-numeric-identifier-creator.js.map +1 -0
- package/dist/non-numeric-identifier-descriptor.d.ts +26 -0
- package/dist/non-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/non-numeric-identifier-descriptor.js +2 -0
- package/dist/non-numeric-identifier-descriptor.js.map +1 -0
- package/dist/non-numeric-identifier-type.d.ts +7 -0
- package/dist/non-numeric-identifier-type.d.ts.map +1 -0
- package/dist/non-numeric-identifier-type.js +2 -0
- package/dist/non-numeric-identifier-type.js.map +1 -0
- package/dist/non-numeric-identifier-validator.d.ts +49 -0
- package/dist/non-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/non-numeric-identifier-validator.js +69 -0
- package/dist/non-numeric-identifier-validator.js.map +1 -0
- package/dist/numeric-identifier-creator.d.ts +53 -0
- package/dist/numeric-identifier-creator.d.ts.map +1 -0
- package/dist/numeric-identifier-creator.js +2 -0
- package/dist/numeric-identifier-creator.js.map +1 -0
- package/dist/numeric-identifier-descriptor.d.ts +21 -0
- package/dist/numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/numeric-identifier-descriptor.js +2 -0
- package/dist/numeric-identifier-descriptor.js.map +1 -0
- package/dist/numeric-identifier-type.d.ts +31 -0
- package/dist/numeric-identifier-type.d.ts.map +1 -0
- package/dist/numeric-identifier-type.js +18 -0
- package/dist/numeric-identifier-type.js.map +1 -0
- package/dist/numeric-identifier-validator.d.ts +24 -0
- package/dist/numeric-identifier-validator.d.ts.map +1 -0
- package/dist/numeric-identifier-validator.js +2 -0
- package/dist/numeric-identifier-validator.js.map +1 -0
- package/dist/prefix-manager.d.ts +232 -0
- package/dist/prefix-manager.d.ts.map +1 -0
- package/dist/prefix-manager.js +334 -0
- package/dist/prefix-manager.js.map +1 -0
- package/dist/prefix-provider.d.ts +27 -0
- package/dist/prefix-provider.d.ts.map +1 -0
- package/dist/prefix-provider.js +2 -0
- package/dist/prefix-provider.js.map +1 -0
- package/dist/prefix-type.d.ts +26 -0
- package/dist/prefix-type.d.ts.map +1 -0
- package/dist/prefix-type.js +18 -0
- package/dist/prefix-type.js.map +1 -0
- package/dist/prefix-validator.d.ts +70 -0
- package/dist/prefix-validator.d.ts.map +1 -0
- package/dist/prefix-validator.js +208 -0
- package/dist/prefix-validator.js.map +1 -0
- package/dist/serializable-numeric-identifier-creator.d.ts +76 -0
- package/dist/serializable-numeric-identifier-creator.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-creator.js +107 -0
- package/dist/serializable-numeric-identifier-creator.js.map +1 -0
- package/dist/serializable-numeric-identifier-descriptor.d.ts +26 -0
- package/dist/serializable-numeric-identifier-descriptor.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-descriptor.js +2 -0
- package/dist/serializable-numeric-identifier-descriptor.js.map +1 -0
- package/dist/serializable-numeric-identifier-type.d.ts +6 -0
- package/dist/serializable-numeric-identifier-type.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-type.js +2 -0
- package/dist/serializable-numeric-identifier-type.js.map +1 -0
- package/dist/serializable-numeric-identifier-validator.d.ts +56 -0
- package/dist/serializable-numeric-identifier-validator.d.ts.map +1 -0
- package/dist/serializable-numeric-identifier-validator.js +77 -0
- package/dist/serializable-numeric-identifier-validator.js.map +1 -0
- package/dist/validators.d.ts +96 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +140 -0
- package/dist/validators.js.map +1 -0
- package/package.json +12 -8
- package/src/abstract-identifier-creator.ts +97 -0
- package/src/abstract-identifier-validator.ts +140 -0
- package/src/abstract-numeric-identifier-creator.ts +168 -0
- package/src/abstract-numeric-identifier-validator.ts +69 -0
- package/src/character-set.ts +10 -10
- package/src/check.ts +9 -9
- package/src/content-character-set.ts +29 -0
- package/src/creators.ts +113 -0
- package/src/descriptors.ts +332 -0
- package/src/gtin-creator.ts +10 -9
- package/src/gtin-descriptor.ts +18 -0
- package/src/gtin-type.ts +50 -0
- package/src/gtin-validator.ts +40 -64
- package/src/identifier-creator.ts +12 -76
- package/src/identifier-descriptor.ts +30 -0
- package/src/identifier-type.ts +6 -1
- package/src/identifier-validator.ts +12 -188
- package/src/index.ts +44 -19
- package/src/locale/en/locale-resources.ts +0 -1
- package/src/locale/fr/locale-resources.ts +0 -1
- package/src/locale/i18n.ts +3 -3
- package/src/locale/i18next.d.ts +1 -1
- package/src/non-gtin-numeric-identifier-creator.ts +7 -13
- package/src/non-gtin-numeric-identifier-descriptor.ts +24 -0
- package/src/non-gtin-numeric-identifier-type.ts +7 -0
- package/src/non-gtin-numeric-identifier-validator.ts +8 -42
- package/src/non-numeric-identifier-creator.ts +9 -19
- package/src/non-numeric-identifier-descriptor.ts +29 -0
- package/src/non-numeric-identifier-type.ts +7 -0
- package/src/non-numeric-identifier-validator.ts +17 -55
- package/src/numeric-identifier-creator.ts +20 -163
- package/src/numeric-identifier-descriptor.ts +23 -0
- package/src/numeric-identifier-type.ts +44 -0
- package/src/numeric-identifier-validator.ts +13 -116
- package/src/prefix-manager.ts +94 -152
- package/src/prefix-provider.ts +3 -3
- package/src/prefix-type.ts +6 -1
- package/src/prefix-validator.ts +143 -81
- package/src/serializable-numeric-identifier-creator.ts +6 -16
- package/src/serializable-numeric-identifier-descriptor.ts +29 -0
- package/src/serializable-numeric-identifier-type.ts +9 -0
- package/src/serializable-numeric-identifier-validator.ts +18 -46
- package/src/validators.ts +203 -0
- package/test/check.test.ts +1 -1
- package/test/creator.test.ts +5 -7
- package/test/gtin-creator.ts +6 -2
- package/test/gtin-validator.test.ts +7 -10
- package/test/identifier-creator.ts +6 -5
- package/test/identifier-validator.ts +2 -2
- package/test/non-gtin-numeric-identifier-creator.ts +9 -93
- package/test/non-gtin-numeric-identifier-validator.ts +3 -3
- package/test/non-numeric-identifier-creator.ts +93 -0
- package/test/non-numeric-identifier-validator.ts +3 -3
- package/test/numeric-identifier-creator.ts +11 -5
- package/test/numeric-identifier-validator.ts +5 -9
- package/test/prefix-manager.test.ts +2 -2
- package/test/serializable-numeric-identifier-creator.ts +11 -3
- package/test/serializable-numeric-identifier-validator.ts +3 -3
- package/test/setup.ts +1 -1
- package/test/sparse.test.ts +1 -1
- package/test/utility.ts +1 -1
- package/test/validator.test.ts +64 -40
- package/test/variable-measure-rcn.test.ts +1 -1
- package/tsconfig-config.json +4 -0
- package/tsconfig-src.json +8 -0
- package/tsconfig-test.json +9 -0
- package/tsconfig.json +12 -1
- package/tsup.config.ts +3 -2
- package/dist/index.cjs +0 -4624
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1588
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { ContentCharacterSets } from "./content-character-set.js";
|
|
2
|
+
import type { GTINDescriptor } from "./gtin-descriptor.js";
|
|
3
|
+
import { type GTINBaseType, GTINTypes } from "./gtin-type.js";
|
|
4
|
+
import type { IdentifierDescriptor } from "./identifier-descriptor.js";
|
|
5
|
+
import { type IdentifierType, IdentifierTypes } from "./identifier-type.js";
|
|
6
|
+
import type { NonGTINNumericIdentifierDescriptor } from "./non-gtin-numeric-identifier-descriptor.js";
|
|
7
|
+
import type { NonGTINNumericIdentifierType } from "./non-gtin-numeric-identifier-type.js";
|
|
8
|
+
import type { NonNumericIdentifierDescriptor } from "./non-numeric-identifier-descriptor.js";
|
|
9
|
+
import type { NonNumericIdentifierType } from "./non-numeric-identifier-type.js";
|
|
10
|
+
import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor.js";
|
|
11
|
+
import { LeaderTypes, type NumericIdentifierType } from "./numeric-identifier-type.js";
|
|
12
|
+
import { PrefixTypes } from "./prefix-type.js";
|
|
13
|
+
import type { SerializableNumericIdentifierDescriptor } from "./serializable-numeric-identifier-descriptor.js";
|
|
14
|
+
import type { SerializableNumericIdentifierType } from "./serializable-numeric-identifier-type.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* GTIN-13 descriptor.
|
|
18
|
+
*/
|
|
19
|
+
const GTIN13_DESCRIPTOR: GTINDescriptor = {
|
|
20
|
+
identifierType: IdentifierTypes.GTIN,
|
|
21
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
22
|
+
length: GTINTypes.GTIN13,
|
|
23
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
24
|
+
leaderType: LeaderTypes.IndicatorDigit
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* GTIN-12 descriptor.
|
|
29
|
+
*/
|
|
30
|
+
const GTIN12_DESCRIPTOR: GTINDescriptor = {
|
|
31
|
+
identifierType: IdentifierTypes.GTIN,
|
|
32
|
+
prefixType: PrefixTypes.UPCCompanyPrefix,
|
|
33
|
+
length: GTINTypes.GTIN12,
|
|
34
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
35
|
+
leaderType: LeaderTypes.IndicatorDigit
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* GTIN-8 descriptor.
|
|
40
|
+
*/
|
|
41
|
+
const GTIN8_DESCRIPTOR: GTINDescriptor = {
|
|
42
|
+
identifierType: IdentifierTypes.GTIN,
|
|
43
|
+
prefixType: PrefixTypes.GS18Prefix,
|
|
44
|
+
length: GTINTypes.GTIN8,
|
|
45
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
46
|
+
leaderType: LeaderTypes.IndicatorDigit
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* GTIN descriptors indexed by prefix type.
|
|
51
|
+
*/
|
|
52
|
+
const GTIN_DESCRIPTORS: Readonly<Record<GTINBaseType, GTINDescriptor>> = {
|
|
53
|
+
[GTINTypes.GTIN13]: GTIN13_DESCRIPTOR,
|
|
54
|
+
[GTINTypes.GTIN12]: GTIN12_DESCRIPTOR,
|
|
55
|
+
[GTINTypes.GTIN8]: GTIN8_DESCRIPTOR
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* GLN descriptor.
|
|
60
|
+
*/
|
|
61
|
+
const GLN_DESCRIPTOR: NonGTINNumericIdentifierDescriptor = {
|
|
62
|
+
identifierType: IdentifierTypes.GLN,
|
|
63
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
64
|
+
length: 13,
|
|
65
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
66
|
+
leaderType: LeaderTypes.None
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* SSCC descriptor.
|
|
71
|
+
*/
|
|
72
|
+
const SSCC_DESCRIPTOR: NonGTINNumericIdentifierDescriptor = {
|
|
73
|
+
identifierType: IdentifierTypes.SSCC,
|
|
74
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
75
|
+
length: 18,
|
|
76
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
77
|
+
leaderType: LeaderTypes.ExtensionDigit
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* GRAI descriptor.
|
|
82
|
+
*/
|
|
83
|
+
const GRAI_DESCRIPTOR: SerializableNumericIdentifierDescriptor = {
|
|
84
|
+
identifierType: IdentifierTypes.GRAI,
|
|
85
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
86
|
+
length: 13,
|
|
87
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
88
|
+
leaderType: LeaderTypes.None,
|
|
89
|
+
serialComponentLength: 16,
|
|
90
|
+
serialComponentCharacterSet: ContentCharacterSets.AI82
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* GIAI descriptor.
|
|
95
|
+
*/
|
|
96
|
+
const GIAI_DESCRIPTOR: NonNumericIdentifierDescriptor = {
|
|
97
|
+
identifierType: IdentifierTypes.GIAI,
|
|
98
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
99
|
+
length: 30,
|
|
100
|
+
referenceCharacterSet: ContentCharacterSets.AI82,
|
|
101
|
+
requiresCheckCharacterPair: false
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* GSRN descriptor.
|
|
106
|
+
*/
|
|
107
|
+
const GSRN_DESCRIPTOR: NonGTINNumericIdentifierDescriptor = {
|
|
108
|
+
identifierType: IdentifierTypes.GSRN,
|
|
109
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
110
|
+
length: 18,
|
|
111
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
112
|
+
leaderType: LeaderTypes.None
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* GDTI descriptor.
|
|
117
|
+
*/
|
|
118
|
+
const GDTI_DESCRIPTOR: SerializableNumericIdentifierDescriptor = {
|
|
119
|
+
identifierType: IdentifierTypes.GDTI,
|
|
120
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
121
|
+
length: 13,
|
|
122
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
123
|
+
leaderType: LeaderTypes.None,
|
|
124
|
+
serialComponentLength: 17,
|
|
125
|
+
serialComponentCharacterSet: ContentCharacterSets.AI82
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* GINC descriptor.
|
|
130
|
+
*/
|
|
131
|
+
const GINC_DESCRIPTOR: NonNumericIdentifierDescriptor = {
|
|
132
|
+
identifierType: IdentifierTypes.GINC,
|
|
133
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
134
|
+
length: 30,
|
|
135
|
+
referenceCharacterSet: ContentCharacterSets.AI82,
|
|
136
|
+
requiresCheckCharacterPair: false
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* GSIN descriptor.
|
|
141
|
+
*/
|
|
142
|
+
const GSIN_DESCRIPTOR: NonGTINNumericIdentifierDescriptor = {
|
|
143
|
+
identifierType: IdentifierTypes.GSIN,
|
|
144
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
145
|
+
length: 17,
|
|
146
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
147
|
+
leaderType: LeaderTypes.None
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* GCN descriptor.
|
|
152
|
+
*/
|
|
153
|
+
const GCN_DESCRIPTOR: SerializableNumericIdentifierDescriptor = {
|
|
154
|
+
identifierType: IdentifierTypes.GCN,
|
|
155
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
156
|
+
length: 13,
|
|
157
|
+
referenceCharacterSet: ContentCharacterSets.Numeric,
|
|
158
|
+
leaderType: LeaderTypes.None,
|
|
159
|
+
serialComponentLength: 12,
|
|
160
|
+
serialComponentCharacterSet: ContentCharacterSets.Numeric
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* CPID descriptor.
|
|
165
|
+
*/
|
|
166
|
+
const CPID_DESCRIPTOR: NonNumericIdentifierDescriptor = {
|
|
167
|
+
identifierType: IdentifierTypes.CPID,
|
|
168
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
169
|
+
length: 30,
|
|
170
|
+
referenceCharacterSet: ContentCharacterSets.AI39,
|
|
171
|
+
requiresCheckCharacterPair: false
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* GMN descriptor.
|
|
176
|
+
*/
|
|
177
|
+
const GMN_DESCRIPTOR: NonNumericIdentifierDescriptor = {
|
|
178
|
+
identifierType: IdentifierTypes.GMN,
|
|
179
|
+
prefixType: PrefixTypes.GS1CompanyPrefix,
|
|
180
|
+
length: 25,
|
|
181
|
+
referenceCharacterSet: ContentCharacterSets.AI82,
|
|
182
|
+
requiresCheckCharacterPair: true
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Identifier descriptor type based on identifier type type.
|
|
187
|
+
*
|
|
188
|
+
* @template TIdentifierType
|
|
189
|
+
* Identifier type type.
|
|
190
|
+
*/
|
|
191
|
+
export type IdentifierTypeDescriptor<TIdentifierType extends IdentifierType> = TIdentifierType extends NonNumericIdentifierType ?
|
|
192
|
+
NonNumericIdentifierDescriptor :
|
|
193
|
+
TIdentifierType extends SerializableNumericIdentifierType ?
|
|
194
|
+
SerializableNumericIdentifierDescriptor :
|
|
195
|
+
TIdentifierType extends NonGTINNumericIdentifierType ?
|
|
196
|
+
NonGTINNumericIdentifierDescriptor :
|
|
197
|
+
TIdentifierType extends typeof IdentifierTypes.GTIN ?
|
|
198
|
+
GTINDescriptor :
|
|
199
|
+
IdentifierDescriptor;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Identifier descriptors entry type based on identifier type type.
|
|
203
|
+
*
|
|
204
|
+
* @template TIdentifierType
|
|
205
|
+
* Identifier type type.
|
|
206
|
+
*/
|
|
207
|
+
export type IdentifierDescriptorsEntry<TIdentifierType extends IdentifierType> = TIdentifierType extends typeof IdentifierTypes.GTIN ?
|
|
208
|
+
Readonly<Record<GTINBaseType, GTINDescriptor>> :
|
|
209
|
+
IdentifierTypeDescriptor<TIdentifierType>;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Identifier descriptors record type.
|
|
213
|
+
*/
|
|
214
|
+
export type IdentifierDescriptorsRecord = {
|
|
215
|
+
[TIdentifierType in IdentifierType]: IdentifierDescriptorsEntry<TIdentifierType>;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Identifier descriptors for all identifier types.
|
|
220
|
+
*/
|
|
221
|
+
export const IdentifierDescriptors: IdentifierDescriptorsRecord = {
|
|
222
|
+
[IdentifierTypes.GTIN]: GTIN_DESCRIPTORS,
|
|
223
|
+
[IdentifierTypes.GLN]: GLN_DESCRIPTOR,
|
|
224
|
+
[IdentifierTypes.SSCC]: SSCC_DESCRIPTOR,
|
|
225
|
+
[IdentifierTypes.GRAI]: GRAI_DESCRIPTOR,
|
|
226
|
+
[IdentifierTypes.GIAI]: GIAI_DESCRIPTOR,
|
|
227
|
+
[IdentifierTypes.GSRN]: GSRN_DESCRIPTOR,
|
|
228
|
+
[IdentifierTypes.GDTI]: GDTI_DESCRIPTOR,
|
|
229
|
+
[IdentifierTypes.GINC]: GINC_DESCRIPTOR,
|
|
230
|
+
[IdentifierTypes.GSIN]: GSIN_DESCRIPTOR,
|
|
231
|
+
[IdentifierTypes.GCN]: GCN_DESCRIPTOR,
|
|
232
|
+
[IdentifierTypes.CPID]: CPID_DESCRIPTOR,
|
|
233
|
+
[IdentifierTypes.GMN]: GMN_DESCRIPTOR
|
|
234
|
+
} as const;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Determine if identifier descriptors or descriptor is GTIN descriptors.
|
|
238
|
+
*
|
|
239
|
+
* @param identifierDescriptorsOrDescriptor
|
|
240
|
+
* Identifier descriptors or descriptor.
|
|
241
|
+
*
|
|
242
|
+
* @returns
|
|
243
|
+
* True if GTIN descriptors.
|
|
244
|
+
*/
|
|
245
|
+
export function isGTINDescriptors(identifierDescriptorsOrDescriptor: IdentifierDescriptorsEntry<IdentifierType>): identifierDescriptorsOrDescriptor is Readonly<Record<GTINBaseType, GTINDescriptor>> {
|
|
246
|
+
return !("identifierType" in identifierDescriptorsOrDescriptor);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Determine if an array of identifier types includes a given identifier type.
|
|
251
|
+
*
|
|
252
|
+
* @param identifierTypes
|
|
253
|
+
* Identifier types.
|
|
254
|
+
*
|
|
255
|
+
* @param identifierType
|
|
256
|
+
* Identifier type.
|
|
257
|
+
*
|
|
258
|
+
* @returns
|
|
259
|
+
* True if element is included in the array.
|
|
260
|
+
*/
|
|
261
|
+
function identifierTypesIncludes(identifierTypes: readonly IdentifierType[], identifierType: IdentifierType): boolean {
|
|
262
|
+
return identifierTypes.includes(identifierType);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const NUMERIC_IDENTIFIER_TYPES: readonly NumericIdentifierType[] = [IdentifierTypes.GTIN, IdentifierTypes.GLN, IdentifierTypes.SSCC, IdentifierTypes.GRAI, IdentifierTypes.GSRN, IdentifierTypes.GDTI, IdentifierTypes.GSIN, IdentifierTypes.GCN];
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Determine if identifier descriptor is a numeric identifier descriptor.
|
|
269
|
+
*
|
|
270
|
+
* @param identifierDescriptor
|
|
271
|
+
* Identifier descriptor.
|
|
272
|
+
*
|
|
273
|
+
* @returns
|
|
274
|
+
* True if identifier descriptor is a numeric identifier descriptor.
|
|
275
|
+
*/
|
|
276
|
+
export function isNumericIdentifierDescriptor(identifierDescriptor: IdentifierDescriptor): identifierDescriptor is NumericIdentifierDescriptor {
|
|
277
|
+
return identifierTypesIncludes(NUMERIC_IDENTIFIER_TYPES, identifierDescriptor.identifierType);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Determine if identifier descriptor is a GTIN descriptor.
|
|
282
|
+
*
|
|
283
|
+
* @param identifierDescriptor
|
|
284
|
+
* Identifier descriptor.
|
|
285
|
+
*
|
|
286
|
+
* @returns
|
|
287
|
+
* True if identifier descriptor is a GTIN descriptor.
|
|
288
|
+
*/
|
|
289
|
+
export function isGTINDescriptor(identifierDescriptor: IdentifierDescriptor): identifierDescriptor is GTINDescriptor {
|
|
290
|
+
return identifierDescriptor.identifierType === IdentifierTypes.GTIN;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Determine if identifier descriptor is a non-GTIN numeric identifier descriptor.
|
|
295
|
+
*
|
|
296
|
+
* @param identifierDescriptor
|
|
297
|
+
* Identifier descriptor.
|
|
298
|
+
*
|
|
299
|
+
* @returns
|
|
300
|
+
* True if identifier descriptor is a non-GTIN numeric identifier descriptor.
|
|
301
|
+
*/
|
|
302
|
+
export function isNonGTINNumericIdentifierDescriptor(identifierDescriptor: IdentifierDescriptor): identifierDescriptor is NonGTINNumericIdentifierDescriptor {
|
|
303
|
+
return isNumericIdentifierDescriptor(identifierDescriptor) && !isGTINDescriptor(identifierDescriptor);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const SERIALIZABLE_NUMERIC_IDENTIFIER_TYPES: readonly SerializableNumericIdentifierType[] = [IdentifierTypes.GRAI, IdentifierTypes.GDTI, IdentifierTypes.GCN];
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Determine if identifier descriptor is a serializable numeric identifier descriptor.
|
|
310
|
+
*
|
|
311
|
+
* @param identifierDescriptor
|
|
312
|
+
* Identifier descriptor.
|
|
313
|
+
*
|
|
314
|
+
* @returns
|
|
315
|
+
* True if identifier descriptor is a serializable numeric identifier descriptor.
|
|
316
|
+
*/
|
|
317
|
+
export function isSerializableNumericIdentifierDescriptor(identifierDescriptor: IdentifierDescriptor): identifierDescriptor is SerializableNumericIdentifierDescriptor {
|
|
318
|
+
return identifierTypesIncludes(SERIALIZABLE_NUMERIC_IDENTIFIER_TYPES, identifierDescriptor.identifierType);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Determine if identifier descriptor is a non-numeric identifier descriptor.
|
|
323
|
+
*
|
|
324
|
+
* @param identifierDescriptor
|
|
325
|
+
* Identifier descriptor.
|
|
326
|
+
*
|
|
327
|
+
* @returns
|
|
328
|
+
* True if identifier descriptor is a non-numeric identifier descriptor.
|
|
329
|
+
*/
|
|
330
|
+
export function isNonNumericIdentifierDescriptor(identifierDescriptor: IdentifierDescriptor): identifierDescriptor is NonNumericIdentifierDescriptor {
|
|
331
|
+
return !isNumericIdentifierDescriptor(identifierDescriptor);
|
|
332
|
+
}
|
package/src/gtin-creator.ts
CHANGED
|
@@ -6,11 +6,12 @@ import {
|
|
|
6
6
|
type TransformerOutput
|
|
7
7
|
} from "@aidc-toolkit/utility";
|
|
8
8
|
import { Mixin } from "ts-mixer";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
9
|
+
import { AbstractNumericIdentifierCreator } from "./abstract-numeric-identifier-creator.js";
|
|
10
|
+
import { checkDigit, priceOrWeightCheckDigit } from "./check.js";
|
|
11
|
+
import { type GTINBaseType, GTINTypes } from "./gtin-type.js";
|
|
12
|
+
import { GTINValidator } from "./gtin-validator.js";
|
|
13
|
+
import { i18nextGS1 } from "./locale/i18n.js";
|
|
14
|
+
import type { PrefixProvider } from "./prefix-provider.js";
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* GTIN creator. Applicable to GTIN-13, GTIN-12, and GTIN-8 types; no applicable to GTIN-14 type.
|
|
@@ -32,11 +33,11 @@ export class GTINCreator extends Mixin(GTINValidator, AbstractNumericIdentifierC
|
|
|
32
33
|
* @param prefixProvider
|
|
33
34
|
* Prefix provider.
|
|
34
35
|
*
|
|
35
|
-
* @param
|
|
36
|
-
* GTIN type.
|
|
36
|
+
* @param gtinBaseType
|
|
37
|
+
* GTIN base type (all except GTIN-14).
|
|
37
38
|
*/
|
|
38
|
-
constructor(prefixProvider: PrefixProvider,
|
|
39
|
-
super(
|
|
39
|
+
constructor(prefixProvider: PrefixProvider, gtinBaseType: GTINBaseType) {
|
|
40
|
+
super(gtinBaseType);
|
|
40
41
|
|
|
41
42
|
this.init(prefixProvider, prefixProvider.prefix);
|
|
42
43
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IdentifierTypes } from "./identifier-type.js";
|
|
2
|
+
import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor.js";
|
|
3
|
+
import type { LeaderTypes } from "./numeric-identifier-type.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GTIN descriptor.
|
|
7
|
+
*/
|
|
8
|
+
export interface GTINDescriptor extends NumericIdentifierDescriptor {
|
|
9
|
+
/**
|
|
10
|
+
* @inheritDoc
|
|
11
|
+
*/
|
|
12
|
+
readonly identifierType: typeof IdentifierTypes.GTIN;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @inheritDoc
|
|
16
|
+
*/
|
|
17
|
+
readonly leaderType: typeof LeaderTypes.IndicatorDigit;
|
|
18
|
+
}
|
package/src/gtin-type.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type PrefixType, PrefixTypes } from "./prefix-type.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GTIN types. The numeric values are equal to the lengths of the GTIN types.
|
|
5
|
+
*/
|
|
6
|
+
export const GTINTypes = {
|
|
7
|
+
/**
|
|
8
|
+
* GTIN-13.
|
|
9
|
+
*/
|
|
10
|
+
GTIN13: 13,
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* GTIN-12.
|
|
14
|
+
*/
|
|
15
|
+
GTIN12: 12,
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* GTIN-8.
|
|
19
|
+
*/
|
|
20
|
+
GTIN8: 8,
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* GTIN-14.
|
|
24
|
+
*/
|
|
25
|
+
GTIN14: 14
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* GTIN type key.
|
|
30
|
+
*/
|
|
31
|
+
export type GTINTypeKey = keyof typeof GTINTypes;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* GTIN type.
|
|
35
|
+
*/
|
|
36
|
+
export type GTINType = typeof GTINTypes[GTINTypeKey];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* GTIN base type (all except GTIN-14).
|
|
40
|
+
*/
|
|
41
|
+
export type GTINBaseType = Exclude<GTINType, typeof GTINTypes.GTIN14>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* GTIN base types by prefix type. Used to determine the GTIN type supported by a prefix type.
|
|
45
|
+
*/
|
|
46
|
+
export const GTIN_BASE_TYPES: Readonly<Record<PrefixType, GTINBaseType>> = {
|
|
47
|
+
[PrefixTypes.GS1CompanyPrefix]: GTINTypes.GTIN13,
|
|
48
|
+
[PrefixTypes.UPCCompanyPrefix]: GTINTypes.GTIN12,
|
|
49
|
+
[PrefixTypes.GS18Prefix]: GTINTypes.GTIN8
|
|
50
|
+
};
|
package/src/gtin-validator.ts
CHANGED
|
@@ -1,40 +1,12 @@
|
|
|
1
1
|
import { type CharacterSetValidation, NUMERIC_CREATOR } from "@aidc-toolkit/utility";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { type
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* GTIN types. The numeric values are equal to the lengths of the GTIN types.
|
|
11
|
-
*/
|
|
12
|
-
export const GTINTypes = {
|
|
13
|
-
/**
|
|
14
|
-
* GTIN-13.
|
|
15
|
-
*/
|
|
16
|
-
GTIN13: 13,
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* GTIN-12.
|
|
20
|
-
*/
|
|
21
|
-
GTIN12: 12,
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* GTIN-8.
|
|
25
|
-
*/
|
|
26
|
-
GTIN8: 8,
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* GTIN-14.
|
|
30
|
-
*/
|
|
31
|
-
GTIN14: 14
|
|
32
|
-
} as const;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* GTIN type.
|
|
36
|
-
*/
|
|
37
|
-
export type GTINType = typeof GTINTypes[keyof typeof GTINTypes];
|
|
2
|
+
import { AbstractNumericIdentifierValidator } from "./abstract-numeric-identifier-validator.js";
|
|
3
|
+
import { checkDigit, hasValidCheckDigit, isValidPriceOrWeightCheckDigit } from "./check.js";
|
|
4
|
+
import { IdentifierDescriptors } from "./descriptors.js";
|
|
5
|
+
import type { GTINDescriptor } from "./gtin-descriptor.js";
|
|
6
|
+
import { type GTINBaseType, type GTINType, GTINTypes } from "./gtin-type.js";
|
|
7
|
+
import { i18nextGS1 } from "./locale/i18n.js";
|
|
8
|
+
import { type PrefixType, PrefixTypes } from "./prefix-type.js";
|
|
9
|
+
import { PrefixValidator } from "./prefix-validator.js";
|
|
38
10
|
|
|
39
11
|
/**
|
|
40
12
|
* Levels at which GTIN is to be validated.
|
|
@@ -56,10 +28,15 @@ export const GTINLevels = {
|
|
|
56
28
|
OtherThanRetailConsumer: 2
|
|
57
29
|
} as const;
|
|
58
30
|
|
|
31
|
+
/**
|
|
32
|
+
* GTIN level key.
|
|
33
|
+
*/
|
|
34
|
+
export type GTINLevelKey = keyof typeof GTINLevels;
|
|
35
|
+
|
|
59
36
|
/**
|
|
60
37
|
* GTIN level.
|
|
61
38
|
*/
|
|
62
|
-
export type GTINLevel = typeof GTINLevels[
|
|
39
|
+
export type GTINLevel = typeof GTINLevels[GTINLevelKey];
|
|
63
40
|
|
|
64
41
|
/**
|
|
65
42
|
* Restricted Circulation Number reference.
|
|
@@ -79,7 +56,7 @@ export interface RCNReference {
|
|
|
79
56
|
/**
|
|
80
57
|
* GTIN validator.
|
|
81
58
|
*/
|
|
82
|
-
export class GTINValidator extends AbstractNumericIdentifierValidator {
|
|
59
|
+
export class GTINValidator extends AbstractNumericIdentifierValidator<GTINDescriptor> {
|
|
83
60
|
/**
|
|
84
61
|
* Validation parameters for optional indicator digit.
|
|
85
62
|
*/
|
|
@@ -97,35 +74,30 @@ export class GTINValidator extends AbstractNumericIdentifierValidator {
|
|
|
97
74
|
maximumLength: 8
|
|
98
75
|
};
|
|
99
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Prefix type.
|
|
79
|
+
*/
|
|
80
|
+
private readonly _prefixType: PrefixType;
|
|
81
|
+
|
|
100
82
|
/**
|
|
101
83
|
* Constructor.
|
|
102
84
|
*
|
|
103
|
-
* @param
|
|
104
|
-
* GTIN type.
|
|
85
|
+
* @param gtinBaseType
|
|
86
|
+
* GTIN base type (all except GTIN-14).
|
|
105
87
|
*/
|
|
106
|
-
constructor(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// Determine the prefix type based on the GTIN type.
|
|
110
|
-
switch (gtinType) {
|
|
111
|
-
case GTINTypes.GTIN13:
|
|
112
|
-
prefixType = PrefixTypes.GS1CompanyPrefix;
|
|
113
|
-
break;
|
|
88
|
+
constructor(gtinBaseType: GTINBaseType) {
|
|
89
|
+
const identifierDescriptor = IdentifierDescriptors.GTIN[gtinBaseType];
|
|
114
90
|
|
|
115
|
-
|
|
116
|
-
prefixType = PrefixTypes.UPCCompanyPrefix;
|
|
117
|
-
break;
|
|
118
|
-
|
|
119
|
-
case GTINTypes.GTIN8:
|
|
120
|
-
prefixType = PrefixTypes.GS18Prefix;
|
|
121
|
-
break;
|
|
91
|
+
super(identifierDescriptor);
|
|
122
92
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
throw new Error("Not supported");
|
|
126
|
-
}
|
|
93
|
+
this._prefixType = identifierDescriptor.prefixType;
|
|
94
|
+
}
|
|
127
95
|
|
|
128
|
-
|
|
96
|
+
/**
|
|
97
|
+
* @inheritDoc
|
|
98
|
+
*/
|
|
99
|
+
override get prefixType(): PrefixType {
|
|
100
|
+
return this._prefixType;
|
|
129
101
|
}
|
|
130
102
|
|
|
131
103
|
/**
|
|
@@ -542,23 +514,27 @@ export class GTINValidator extends AbstractNumericIdentifierValidator {
|
|
|
542
514
|
/**
|
|
543
515
|
* GTIN-13 validator.
|
|
544
516
|
*/
|
|
517
|
+
// Defined here because of circular reference.
|
|
545
518
|
export const GTIN13_VALIDATOR = new GTINValidator(GTINTypes.GTIN13);
|
|
546
519
|
|
|
547
520
|
/**
|
|
548
521
|
* GTIN-12 validator.
|
|
549
522
|
*/
|
|
523
|
+
// Defined here because of circular reference.
|
|
550
524
|
export const GTIN12_VALIDATOR = new GTINValidator(GTINTypes.GTIN12);
|
|
551
525
|
|
|
552
526
|
/**
|
|
553
527
|
* GTIN-8 validator.
|
|
554
528
|
*/
|
|
529
|
+
// Defined here because of circular reference.
|
|
555
530
|
export const GTIN8_VALIDATOR = new GTINValidator(GTINTypes.GTIN8);
|
|
556
531
|
|
|
557
532
|
/**
|
|
558
533
|
* GTIN validators indexed by prefix type.
|
|
559
534
|
*/
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
[
|
|
563
|
-
[
|
|
535
|
+
// Defined here because of circular reference.
|
|
536
|
+
export const GTIN_VALIDATORS: Readonly<Record<GTINBaseType, GTINValidator>> = {
|
|
537
|
+
[GTINTypes.GTIN13]: GTIN13_VALIDATOR,
|
|
538
|
+
[GTINTypes.GTIN12]: GTIN12_VALIDATOR,
|
|
539
|
+
[GTINTypes.GTIN8]: GTIN8_VALIDATOR
|
|
564
540
|
};
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type { PrefixProvider } from "./prefix-provider";
|
|
5
|
-
import type { PrefixType } from "./prefix-type";
|
|
1
|
+
import type { IdentifierDescriptor } from "./identifier-descriptor.js";
|
|
2
|
+
import type { IdentifierValidation, IdentifierValidator } from "./identifier-validator.js";
|
|
3
|
+
import type { PrefixProvider } from "./prefix-provider.js";
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Identifier creator. Creates an identifier based on its definition in section 3 of the {@link
|
|
9
|
-
* https://
|
|
7
|
+
* https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}.
|
|
10
8
|
*
|
|
11
|
-
* Keys are created based on a prefix defined in a prefix
|
|
9
|
+
* Keys are created based on a prefix defined in a prefix provider to which the identifier creator is bound.
|
|
10
|
+
*
|
|
11
|
+
* @template TIdentifierDescriptor
|
|
12
|
+
* Identifier descriptor type.
|
|
13
|
+
*
|
|
14
|
+
* @template TIdentifierValidation
|
|
15
|
+
* Identifier validation type.
|
|
12
16
|
*/
|
|
13
|
-
export interface IdentifierCreator extends IdentifierValidator {
|
|
17
|
+
export interface IdentifierCreator<TIdentifierDescriptor extends IdentifierDescriptor = IdentifierDescriptor, TIdentifierValidation extends IdentifierValidation = IdentifierValidation> extends IdentifierValidator<TIdentifierDescriptor, TIdentifierValidation> {
|
|
14
18
|
/**
|
|
15
19
|
* Get the prefix provider to which this identifier creator is bound.
|
|
16
20
|
*/
|
|
@@ -27,71 +31,3 @@ export interface IdentifierCreator extends IdentifierValidator {
|
|
|
27
31
|
*/
|
|
28
32
|
get referenceLength(): number;
|
|
29
33
|
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Abstract identifier creator. Implements common functionality for an identifier creator, bound to a
|
|
33
|
-
* {@link PrefixProvider}.
|
|
34
|
-
*/
|
|
35
|
-
export abstract class AbstractIdentifierCreator implements IdentifierCreator {
|
|
36
|
-
/**
|
|
37
|
-
* Prefix provider.
|
|
38
|
-
*/
|
|
39
|
-
private _prefixProvider!: PrefixProvider;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Reference length.
|
|
43
|
-
*/
|
|
44
|
-
private _referenceLength!: number;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Initialize the prefix manager. This method is in lieu of a constructor due to the mixin architecture.
|
|
48
|
-
*
|
|
49
|
-
* @param prefixProvider
|
|
50
|
-
* Prefix provider.
|
|
51
|
-
*
|
|
52
|
-
* @param prefix
|
|
53
|
-
* Prefix within prefix manager to use to calculate reference length.
|
|
54
|
-
*
|
|
55
|
-
* @param checkAllowance
|
|
56
|
-
* Number of characters to allow for check digit or check character pair.
|
|
57
|
-
*/
|
|
58
|
-
protected init(prefixProvider: PrefixProvider, prefix: string, checkAllowance: number): void {
|
|
59
|
-
this._prefixProvider = prefixProvider;
|
|
60
|
-
|
|
61
|
-
// Reference length allows for prefix and optionally check digit or check character pair.
|
|
62
|
-
this._referenceLength = this.length - prefix.length - checkAllowance;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
abstract get identifierType(): IdentifierType;
|
|
66
|
-
|
|
67
|
-
abstract get prefixType(): PrefixType;
|
|
68
|
-
|
|
69
|
-
abstract get length(): number;
|
|
70
|
-
|
|
71
|
-
abstract get referenceCharacterSet(): ContentCharacterSet;
|
|
72
|
-
|
|
73
|
-
abstract get referenceCreator(): CharacterSetCreator;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @inheritDoc
|
|
77
|
-
*/
|
|
78
|
-
get prefixProvider(): PrefixProvider {
|
|
79
|
-
return this._prefixProvider;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* @inheritDoc
|
|
84
|
-
*/
|
|
85
|
-
get prefix(): string {
|
|
86
|
-
return this.prefixProvider.gs1CompanyPrefix;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @inheritDoc
|
|
91
|
-
*/
|
|
92
|
-
get referenceLength(): number {
|
|
93
|
-
return this._referenceLength;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
abstract validate(identifier: string, validation?: IdentifierValidation): void;
|
|
97
|
-
}
|