@aidc-toolkit/gs1 1.0.23-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.
- package/dist/index.cjs +4813 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1949 -0
- package/dist/index.d.ts +1949 -36
- package/dist/index.js +4727 -19
- package/dist/index.js.map +1 -1
- package/package.json +8 -12
- package/src/abstract-identifier-creator.ts +97 -0
- package/src/abstract-identifier-validator.ts +140 -0
- package/{dist/numeric-identifier-creator.js → src/abstract-numeric-identifier-creator.ts} +61 -28
- package/src/abstract-numeric-identifier-validator.ts +69 -0
- package/src/character-set.ts +24 -9
- 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 +9 -8
- 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 +11 -75
- 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 +43 -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 -5
- package/src/locale/i18next.d.ts +1 -1
- package/src/non-gtin-numeric-identifier-creator.ts +6 -12
- 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 +8 -18
- 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 +5 -15
- 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/creator.test.ts +4 -6
- package/test/gtin-creator.ts +6 -2
- package/test/gtin-validator.test.ts +6 -9
- package/test/identifier-creator.ts +5 -4
- 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 +2 -2
- package/test/non-numeric-identifier-creator.ts +93 -0
- package/test/non-numeric-identifier-validator.ts +2 -2
- package/test/numeric-identifier-creator.ts +11 -5
- package/test/numeric-identifier-validator.ts +4 -8
- package/test/prefix-manager.test.ts +1 -1
- package/test/serializable-numeric-identifier-creator.ts +11 -3
- package/test/serializable-numeric-identifier-validator.ts +2 -2
- package/test/validator.test.ts +63 -39
- package/tsup.config.ts +3 -0
- package/typedoc.json +1 -3
- package/dist/character-set.d.ts +0 -22
- package/dist/character-set.d.ts.map +0 -1
- package/dist/character-set.js +0 -36
- package/dist/character-set.js.map +0 -1
- package/dist/check.d.ts +0 -81
- package/dist/check.d.ts.map +0 -1
- package/dist/check.js +0 -218
- package/dist/check.js.map +0 -1
- package/dist/gtin-creator.d.ts +0 -68
- package/dist/gtin-creator.d.ts.map +0 -1
- package/dist/gtin-creator.js +0 -158
- package/dist/gtin-creator.js.map +0 -1
- package/dist/gtin-validator.d.ts +0 -202
- package/dist/gtin-validator.d.ts.map +0 -1
- package/dist/gtin-validator.js +0 -470
- package/dist/gtin-validator.js.map +0 -1
- package/dist/identifier-creator.d.ts +0 -72
- package/dist/identifier-creator.d.ts.map +0 -1
- package/dist/identifier-creator.js +0 -50
- package/dist/identifier-creator.js.map +0 -1
- package/dist/identifier-type.d.ts +0 -58
- package/dist/identifier-type.d.ts.map +0 -1
- package/dist/identifier-type.js +0 -54
- package/dist/identifier-type.js.map +0 -1
- package/dist/identifier-validator.d.ts +0 -174
- package/dist/identifier-validator.d.ts.map +0 -1
- package/dist/identifier-validator.js +0 -145
- package/dist/identifier-validator.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/locale/en/locale-resources.d.ts +0 -43
- package/dist/locale/en/locale-resources.d.ts.map +0 -1
- package/dist/locale/en/locale-resources.js +0 -42
- package/dist/locale/en/locale-resources.js.map +0 -1
- package/dist/locale/fr/locale-resources.d.ts +0 -43
- package/dist/locale/fr/locale-resources.d.ts.map +0 -1
- package/dist/locale/fr/locale-resources.js +0 -42
- package/dist/locale/fr/locale-resources.js.map +0 -1
- package/dist/locale/i18n.d.ts +0 -27
- package/dist/locale/i18n.d.ts.map +0 -1
- package/dist/locale/i18n.js +0 -37
- package/dist/locale/i18n.js.map +0 -1
- package/dist/non-gtin-numeric-identifier-creator.d.ts +0 -30
- package/dist/non-gtin-numeric-identifier-creator.d.ts.map +0 -1
- package/dist/non-gtin-numeric-identifier-creator.js +0 -30
- package/dist/non-gtin-numeric-identifier-creator.js.map +0 -1
- package/dist/non-gtin-numeric-identifier-validator.d.ts +0 -41
- package/dist/non-gtin-numeric-identifier-validator.d.ts.map +0 -1
- package/dist/non-gtin-numeric-identifier-validator.js +0 -40
- package/dist/non-gtin-numeric-identifier-validator.js.map +0 -1
- package/dist/non-numeric-identifier-creator.d.ts +0 -55
- package/dist/non-numeric-identifier-creator.d.ts.map +0 -1
- package/dist/non-numeric-identifier-creator.js +0 -93
- package/dist/non-numeric-identifier-creator.js.map +0 -1
- package/dist/non-numeric-identifier-validator.d.ts +0 -78
- package/dist/non-numeric-identifier-validator.d.ts.map +0 -1
- package/dist/non-numeric-identifier-validator.js +0 -95
- package/dist/non-numeric-identifier-validator.js.map +0 -1
- package/dist/numeric-identifier-creator.d.ts +0 -121
- package/dist/numeric-identifier-creator.d.ts.map +0 -1
- package/dist/numeric-identifier-creator.js.map +0 -1
- package/dist/numeric-identifier-validator.d.ts +0 -76
- package/dist/numeric-identifier-validator.d.ts.map +0 -1
- package/dist/numeric-identifier-validator.js +0 -84
- package/dist/numeric-identifier-validator.js.map +0 -1
- package/dist/prefix-manager.d.ts +0 -224
- package/dist/prefix-manager.d.ts.map +0 -1
- package/dist/prefix-manager.js +0 -369
- package/dist/prefix-manager.js.map +0 -1
- package/dist/prefix-provider.d.ts +0 -27
- package/dist/prefix-provider.d.ts.map +0 -1
- package/dist/prefix-provider.js +0 -2
- package/dist/prefix-provider.js.map +0 -1
- package/dist/prefix-type.d.ts +0 -22
- package/dist/prefix-type.d.ts.map +0 -1
- package/dist/prefix-type.js +0 -18
- package/dist/prefix-type.js.map +0 -1
- package/dist/prefix-validator.d.ts +0 -58
- package/dist/prefix-validator.d.ts.map +0 -1
- package/dist/prefix-validator.js +0 -154
- package/dist/prefix-validator.js.map +0 -1
- package/dist/serializable-numeric-identifier-creator.d.ts +0 -86
- package/dist/serializable-numeric-identifier-creator.d.ts.map +0 -1
- package/dist/serializable-numeric-identifier-creator.js +0 -116
- package/dist/serializable-numeric-identifier-creator.js.map +0 -1
- package/dist/serializable-numeric-identifier-validator.d.ts +0 -79
- package/dist/serializable-numeric-identifier-validator.d.ts.map +0 -1
- package/dist/serializable-numeric-identifier-validator.js +0 -99
- package/dist/serializable-numeric-identifier-validator.js.map +0 -1
package/src/creators.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isGTINDescriptor,
|
|
3
|
+
isNonGTINNumericIdentifierDescriptor,
|
|
4
|
+
isNonNumericIdentifierDescriptor,
|
|
5
|
+
isNumericIdentifierDescriptor,
|
|
6
|
+
isSerializableNumericIdentifierDescriptor
|
|
7
|
+
} from "./descriptors";
|
|
8
|
+
import type { GTINCreator } from "./gtin-creator";
|
|
9
|
+
import type { IdentifierCreator } from "./identifier-creator";
|
|
10
|
+
import type { IdentifierType, IdentifierTypes } from "./identifier-type";
|
|
11
|
+
import type { NonGTINNumericIdentifierCreator } from "./non-gtin-numeric-identifier-creator";
|
|
12
|
+
import type { NonGTINNumericIdentifierType } from "./non-gtin-numeric-identifier-type";
|
|
13
|
+
import type { NonNumericIdentifierCreator } from "./non-numeric-identifier-creator";
|
|
14
|
+
import type { NonNumericIdentifierType } from "./non-numeric-identifier-type";
|
|
15
|
+
import type { NumericIdentifierCreator } from "./numeric-identifier-creator";
|
|
16
|
+
import type { SerializableNumericIdentifierCreator } from "./serializable-numeric-identifier-creator";
|
|
17
|
+
import type { SerializableNumericIdentifierType } from "./serializable-numeric-identifier-type";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Determine the identifier creator type for an identifier type.
|
|
21
|
+
*
|
|
22
|
+
* @template TIdentifierType
|
|
23
|
+
* Identifier type type.
|
|
24
|
+
*/
|
|
25
|
+
export type IdentifierTypeCreator<TIdentifierType extends IdentifierType> = TIdentifierType extends NonNumericIdentifierType ?
|
|
26
|
+
NonNumericIdentifierCreator :
|
|
27
|
+
TIdentifierType extends SerializableNumericIdentifierType ?
|
|
28
|
+
SerializableNumericIdentifierCreator :
|
|
29
|
+
TIdentifierType extends NonGTINNumericIdentifierType ?
|
|
30
|
+
NonGTINNumericIdentifierCreator :
|
|
31
|
+
TIdentifierType extends typeof IdentifierTypes.GTIN ?
|
|
32
|
+
GTINCreator :
|
|
33
|
+
IdentifierCreator;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Identifier creators entry type based on identifier type type.
|
|
37
|
+
*
|
|
38
|
+
* @template TIdentifierType
|
|
39
|
+
* Identifier type type.
|
|
40
|
+
*/
|
|
41
|
+
export type IdentifierCreatorsEntry<TIdentifierType extends IdentifierType> = IdentifierTypeCreator<TIdentifierType>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Identifier creators record type.
|
|
45
|
+
*/
|
|
46
|
+
export type IdentifierCreatorsRecord = {
|
|
47
|
+
[TIdentifierType in IdentifierType]: IdentifierCreatorsEntry<TIdentifierType>;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Determine if identifier creator is a numeric identifier creator.
|
|
52
|
+
*
|
|
53
|
+
* @param identifierCreator
|
|
54
|
+
* Identifier creator.
|
|
55
|
+
*
|
|
56
|
+
* @returns
|
|
57
|
+
* True if identifier creator is a numeric identifier creator.
|
|
58
|
+
*/
|
|
59
|
+
export function isNumericIdentifierCreator(identifierCreator: IdentifierCreator): identifierCreator is NumericIdentifierCreator {
|
|
60
|
+
return isNumericIdentifierDescriptor(identifierCreator);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Determine if identifier creator is a GTIN creator.
|
|
65
|
+
*
|
|
66
|
+
* @param identifierCreator
|
|
67
|
+
* Identifier creator.
|
|
68
|
+
*
|
|
69
|
+
* @returns
|
|
70
|
+
* True if identifier creator is a GTIN creator.
|
|
71
|
+
*/
|
|
72
|
+
export function isGTINCreator(identifierCreator: IdentifierCreator): identifierCreator is GTINCreator {
|
|
73
|
+
return isGTINDescriptor(identifierCreator);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Determine if identifier creator is a non-GTIN numeric identifier creator.
|
|
78
|
+
*
|
|
79
|
+
* @param identifierCreator
|
|
80
|
+
* Identifier creator.
|
|
81
|
+
*
|
|
82
|
+
* @returns
|
|
83
|
+
* True if identifier creator is a non-GTIN numeric identifier creator.
|
|
84
|
+
*/
|
|
85
|
+
export function isNonGTINNumericIdentifierCreator(identifierCreator: IdentifierCreator): identifierCreator is NonGTINNumericIdentifierCreator {
|
|
86
|
+
return isNonGTINNumericIdentifierDescriptor(identifierCreator);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Determine if identifier creator is a serializable numeric identifier creator.
|
|
91
|
+
*
|
|
92
|
+
* @param identifierCreator
|
|
93
|
+
* Identifier creator.
|
|
94
|
+
*
|
|
95
|
+
* @returns
|
|
96
|
+
* True if identifier creator is a serializable numeric identifier creator.
|
|
97
|
+
*/
|
|
98
|
+
export function isSerializableNumericIdentifierCreator(identifierCreator: IdentifierCreator): identifierCreator is SerializableNumericIdentifierCreator {
|
|
99
|
+
return isSerializableNumericIdentifierDescriptor(identifierCreator);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Determine if identifier creator is a non-numeric identifier creator.
|
|
104
|
+
*
|
|
105
|
+
* @param identifierCreator
|
|
106
|
+
* Identifier creator.
|
|
107
|
+
*
|
|
108
|
+
* @returns
|
|
109
|
+
* True if identifier creator is a non-numeric identifier creator.
|
|
110
|
+
*/
|
|
111
|
+
export function isNonNumericIdentifierCreator(identifierCreator: IdentifierCreator): identifierCreator is NonNumericIdentifierCreator {
|
|
112
|
+
return isNonNumericIdentifierDescriptor(identifierCreator);
|
|
113
|
+
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { ContentCharacterSets } from "./content-character-set";
|
|
2
|
+
import type { GTINDescriptor } from "./gtin-descriptor";
|
|
3
|
+
import { type GTINBaseType, GTINTypes } from "./gtin-type";
|
|
4
|
+
import type { IdentifierDescriptor } from "./identifier-descriptor";
|
|
5
|
+
import { type IdentifierType, IdentifierTypes } from "./identifier-type";
|
|
6
|
+
import type { NonGTINNumericIdentifierDescriptor } from "./non-gtin-numeric-identifier-descriptor";
|
|
7
|
+
import type { NonGTINNumericIdentifierType } from "./non-gtin-numeric-identifier-type";
|
|
8
|
+
import type { NonNumericIdentifierDescriptor } from "./non-numeric-identifier-descriptor";
|
|
9
|
+
import type { NonNumericIdentifierType } from "./non-numeric-identifier-type";
|
|
10
|
+
import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor";
|
|
11
|
+
import { LeaderTypes, type NumericIdentifierType } from "./numeric-identifier-type";
|
|
12
|
+
import { PrefixTypes } from "./prefix-type";
|
|
13
|
+
import type { SerializableNumericIdentifierDescriptor } from "./serializable-numeric-identifier-descriptor";
|
|
14
|
+
import type { SerializableNumericIdentifierType } from "./serializable-numeric-identifier-type";
|
|
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,10 +6,11 @@ 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 {
|
|
9
|
+
import { AbstractNumericIdentifierCreator } from "./abstract-numeric-identifier-creator";
|
|
10
|
+
import { checkDigit, priceOrWeightCheckDigit } from "./check";
|
|
11
|
+
import { type GTINBaseType, GTINTypes } from "./gtin-type";
|
|
12
|
+
import { GTINValidator } from "./gtin-validator";
|
|
13
|
+
import { i18nextGS1 } from "./locale/i18n";
|
|
13
14
|
import type { PrefixProvider } from "./prefix-provider";
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -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";
|
|
2
|
+
import type { NumericIdentifierDescriptor } from "./numeric-identifier-descriptor";
|
|
3
|
+
import type { LeaderTypes } from "./numeric-identifier-type";
|
|
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";
|
|
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.
|
|
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
|
+
};
|