@tracepass/gs1-utils 0.7.0 → 0.9.0
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/README.md +22 -7
- package/dist/digital-link.d.ts +22 -3
- package/dist/digital-link.d.ts.map +1 -1
- package/dist/digital-link.js +42 -7
- package/dist/digital-link.js.map +1 -1
- package/dist/gtin.d.ts +27 -0
- package/dist/gtin.d.ts.map +1 -1
- package/dist/gtin.js +49 -0
- package/dist/gtin.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,21 +18,36 @@ npm install @tracepass/gs1-utils
|
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
```ts
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
validateGtin, normalizeGtin, toGtin14,
|
|
23
|
+
validateGln, normalizeGln,
|
|
24
|
+
buildDigitalLinkUri, parseDigitalLinkUri,
|
|
25
|
+
} from "@tracepass/gs1-utils";
|
|
22
26
|
|
|
23
|
-
validateGtin("09520123456788"); // true — mod-10 check digit
|
|
27
|
+
validateGtin("09520123456788"); // true — mod-10 check digit, must be 14 digits
|
|
24
28
|
validateGtin("09520123456780"); // false
|
|
29
|
+
|
|
25
30
|
validateGln("5012345678900"); // true — 13 digits, mod-10
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
// "
|
|
32
|
+
// Normalise any GTIN length to 14 digits (left-pad then check check digit)
|
|
33
|
+
normalizeGtin("5449000000996"); // "05449000000996" — GTIN-13 → GTIN-14
|
|
34
|
+
normalizeGtin("012345678905"); // "00012345678905" — GTIN-12 → GTIN-14
|
|
35
|
+
normalizeGtin("96385074"); // "00000096385074" — GTIN-8 → GTIN-14
|
|
36
|
+
normalizeGtin("05449000000997"); // null — bad check digit
|
|
37
|
+
|
|
38
|
+
toGtin14("5449000000996"); // alias for normalizeGtin
|
|
39
|
+
|
|
40
|
+
buildDigitalLinkUri("id.example.com", "5449000000996", "SN-1");
|
|
41
|
+
// "https://id.example.com/01/05449000000996/21/SN-1" — GTIN-13 auto-normalised to 14
|
|
29
42
|
|
|
30
|
-
parseDigitalLinkUri("https://id.example.com/01/
|
|
31
|
-
// { gtin: "
|
|
43
|
+
parseDigitalLinkUri("https://id.example.com/01/5449000000996/21/SN-1");
|
|
44
|
+
// { gtin: "05449000000996", serialNumber: "SN-1" } — GTIN-13 in path normalised
|
|
32
45
|
```
|
|
33
46
|
|
|
34
47
|
`buildDigitalLinkUri` takes a **bare domain** — `id.example.com`, not
|
|
35
|
-
`https://id.example.com`.
|
|
48
|
+
`https://id.example.com`. GTINs of any valid length (8/12/13/14) are accepted and
|
|
49
|
+
always emitted as 14 digits. `parseDigitalLinkUri` normalises shorter GTINs found
|
|
50
|
+
in paths to 14 digits on the way out.
|
|
36
51
|
|
|
37
52
|
## QR codes are a separate subpath
|
|
38
53
|
|
package/dist/digital-link.d.ts
CHANGED
|
@@ -6,20 +6,38 @@
|
|
|
6
6
|
*
|
|
7
7
|
* https://example.com/01/<gtin>/21/<serial>
|
|
8
8
|
*
|
|
9
|
+
* Accepts GTIN-8, GTIN-12, GTIN-13 and GTIN-14 on input; always emits
|
|
10
|
+
* 14-digit GTINs in the URI. GS1 guarantees that any GTIN format becomes a
|
|
11
|
+
* valid GTIN-14 when left-padded to 14 digits with zeros — the check digit
|
|
12
|
+
* is preserved. For 14-digit inputs the behaviour is byte-identical to prior
|
|
13
|
+
* versions.
|
|
14
|
+
*
|
|
9
15
|
* See: https://www.gs1.org/standards/gs1-digital-link
|
|
16
|
+
*
|
|
17
|
+
* ⚠️ MIRRORED INTO THE PUBLIC npm PACKAGE @tracepass/gs1-utils.
|
|
18
|
+
* `tracepass-open/packages/gs1-utils/src/digital-link.ts` is a hand-copy of this
|
|
19
|
+
* file — nothing generates one from the other, and a stale copy fails silently
|
|
20
|
+
* (it still compiles and still returns a plausible answer). tracepass-open
|
|
21
|
+
* gates on a hash of this file in CI, so after changing it:
|
|
22
|
+
*
|
|
23
|
+
* cd ../tracepass-open && node scripts/build-mirror-manifest.mjs \
|
|
24
|
+
* && npm run check:mirrors
|
|
25
|
+
*
|
|
26
|
+
* and commit `mirror-manifest.json` with the code.
|
|
10
27
|
*/
|
|
11
28
|
/**
|
|
12
29
|
* Build a GS1 Digital Link URI from components.
|
|
13
30
|
*
|
|
14
|
-
* @param domain - fully qualified domain (e.g. "id.tracepass.eu")
|
|
15
|
-
* @param gtin -
|
|
31
|
+
* @param domain - fully qualified domain, no scheme (e.g. "id.tracepass.eu")
|
|
32
|
+
* @param gtin - GTIN-8, GTIN-12, GTIN-13, or GTIN-14; always emitted as 14 digits
|
|
16
33
|
* @param serialNumber - product serial number (percent-encoded if needed)
|
|
17
34
|
* @returns full URI, e.g. "https://id.tracepass.eu/01/01234567890128/21/ABC-123"
|
|
18
35
|
*/
|
|
19
36
|
export declare function buildDigitalLinkUri(domain: string, gtin: string, serialNumber: string): string;
|
|
20
37
|
/**
|
|
21
38
|
* Parse a GS1 Digital Link URI and extract GTIN + serial number.
|
|
22
|
-
* Accepts URIs with or without scheme.
|
|
39
|
+
* Accepts URIs with or without scheme. Accepts GTIN-8, -12, -13, and -14 in
|
|
40
|
+
* the path; always returns the GTIN normalised to 14 digits.
|
|
23
41
|
*
|
|
24
42
|
* @returns parsed components or null if the URI doesn't match the expected pattern
|
|
25
43
|
*/
|
|
@@ -30,6 +48,7 @@ export declare function parseDigitalLinkUri(uri: string): {
|
|
|
30
48
|
/**
|
|
31
49
|
* Build the path segments array for the [...uri] catch-all route.
|
|
32
50
|
* Returns e.g. ["01", "01234567890128", "21", "ABC-123"]
|
|
51
|
+
* GTIN is normalised to 14 digits.
|
|
33
52
|
*/
|
|
34
53
|
export declare function buildDigitalLinkSegments(gtin: string, serialNumber: string): string[];
|
|
35
54
|
//# sourceMappingURL=digital-link.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digital-link.d.ts","sourceRoot":"","sources":["../src/digital-link.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"digital-link.d.ts","sourceRoot":"","sources":["../src/digital-link.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAsBH;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,GACnB,MAAM,CAKR;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,GACV;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAa/C;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,GACnB,MAAM,EAAE,CAEV"}
|
package/dist/digital-link.js
CHANGED
|
@@ -6,47 +6,82 @@
|
|
|
6
6
|
*
|
|
7
7
|
* https://example.com/01/<gtin>/21/<serial>
|
|
8
8
|
*
|
|
9
|
+
* Accepts GTIN-8, GTIN-12, GTIN-13 and GTIN-14 on input; always emits
|
|
10
|
+
* 14-digit GTINs in the URI. GS1 guarantees that any GTIN format becomes a
|
|
11
|
+
* valid GTIN-14 when left-padded to 14 digits with zeros — the check digit
|
|
12
|
+
* is preserved. For 14-digit inputs the behaviour is byte-identical to prior
|
|
13
|
+
* versions.
|
|
14
|
+
*
|
|
9
15
|
* See: https://www.gs1.org/standards/gs1-digital-link
|
|
16
|
+
*
|
|
17
|
+
* ⚠️ MIRRORED INTO THE PUBLIC npm PACKAGE @tracepass/gs1-utils.
|
|
18
|
+
* `tracepass-open/packages/gs1-utils/src/digital-link.ts` is a hand-copy of this
|
|
19
|
+
* file — nothing generates one from the other, and a stale copy fails silently
|
|
20
|
+
* (it still compiles and still returns a plausible answer). tracepass-open
|
|
21
|
+
* gates on a hash of this file in CI, so after changing it:
|
|
22
|
+
*
|
|
23
|
+
* cd ../tracepass-open && node scripts/build-mirror-manifest.mjs \
|
|
24
|
+
* && npm run check:mirrors
|
|
25
|
+
*
|
|
26
|
+
* and commit `mirror-manifest.json` with the code.
|
|
10
27
|
*/
|
|
11
28
|
/** GS1 Application Identifier for GTIN */
|
|
12
29
|
const AI_GTIN = "01";
|
|
13
30
|
/** GS1 Application Identifier for serial number */
|
|
14
31
|
const AI_SERIAL = "21";
|
|
32
|
+
/**
|
|
33
|
+
* Left-pad a GTIN-8, -12, -13, or -14 to 14 digits.
|
|
34
|
+
* No check-digit validation — callers that need validation use normalizeGtin
|
|
35
|
+
* from gtin.ts. A 14-digit input is returned unchanged (byte-identical to the
|
|
36
|
+
* prior single-length behaviour).
|
|
37
|
+
*/
|
|
38
|
+
function padToGtin14(gtin) {
|
|
39
|
+
switch (gtin.length) {
|
|
40
|
+
case 8: return "000000" + gtin;
|
|
41
|
+
case 12: return "00" + gtin;
|
|
42
|
+
case 13: return "0" + gtin;
|
|
43
|
+
default: return gtin; // 14 digits: unchanged. Other lengths: pass through.
|
|
44
|
+
}
|
|
45
|
+
}
|
|
15
46
|
/**
|
|
16
47
|
* Build a GS1 Digital Link URI from components.
|
|
17
48
|
*
|
|
18
|
-
* @param domain - fully qualified domain (e.g. "id.tracepass.eu")
|
|
19
|
-
* @param gtin -
|
|
49
|
+
* @param domain - fully qualified domain, no scheme (e.g. "id.tracepass.eu")
|
|
50
|
+
* @param gtin - GTIN-8, GTIN-12, GTIN-13, or GTIN-14; always emitted as 14 digits
|
|
20
51
|
* @param serialNumber - product serial number (percent-encoded if needed)
|
|
21
52
|
* @returns full URI, e.g. "https://id.tracepass.eu/01/01234567890128/21/ABC-123"
|
|
22
53
|
*/
|
|
23
54
|
export function buildDigitalLinkUri(domain, gtin, serialNumber) {
|
|
24
55
|
const cleanDomain = domain.replace(/\/+$/, "");
|
|
56
|
+
const gtin14 = padToGtin14(gtin);
|
|
25
57
|
const encodedSerial = encodeURIComponent(serialNumber);
|
|
26
|
-
return `https://${cleanDomain}/${AI_GTIN}/${
|
|
58
|
+
return `https://${cleanDomain}/${AI_GTIN}/${gtin14}/${AI_SERIAL}/${encodedSerial}`;
|
|
27
59
|
}
|
|
28
60
|
/**
|
|
29
61
|
* Parse a GS1 Digital Link URI and extract GTIN + serial number.
|
|
30
|
-
* Accepts URIs with or without scheme.
|
|
62
|
+
* Accepts URIs with or without scheme. Accepts GTIN-8, -12, -13, and -14 in
|
|
63
|
+
* the path; always returns the GTIN normalised to 14 digits.
|
|
31
64
|
*
|
|
32
65
|
* @returns parsed components or null if the URI doesn't match the expected pattern
|
|
33
66
|
*/
|
|
34
67
|
export function parseDigitalLinkUri(uri) {
|
|
35
68
|
// Strip scheme + authority to get the path.
|
|
36
69
|
// Handles https://domain/01/…, http://domain/01/…, or bare path /01/…
|
|
37
|
-
|
|
70
|
+
// Accepts any of the four valid GTIN lengths in the path segment.
|
|
71
|
+
const match = uri.match(/\/01\/(\d{8}|\d{12}|\d{13}|\d{14})\/21\/([^/?#]+)/);
|
|
38
72
|
if (!match)
|
|
39
73
|
return null;
|
|
40
74
|
return {
|
|
41
|
-
gtin: match[1],
|
|
75
|
+
gtin: padToGtin14(match[1]),
|
|
42
76
|
serialNumber: decodeURIComponent(match[2]),
|
|
43
77
|
};
|
|
44
78
|
}
|
|
45
79
|
/**
|
|
46
80
|
* Build the path segments array for the [...uri] catch-all route.
|
|
47
81
|
* Returns e.g. ["01", "01234567890128", "21", "ABC-123"]
|
|
82
|
+
* GTIN is normalised to 14 digits.
|
|
48
83
|
*/
|
|
49
84
|
export function buildDigitalLinkSegments(gtin, serialNumber) {
|
|
50
|
-
return [AI_GTIN, gtin, AI_SERIAL, encodeURIComponent(serialNumber)];
|
|
85
|
+
return [AI_GTIN, padToGtin14(gtin), AI_SERIAL, encodeURIComponent(serialNumber)];
|
|
51
86
|
}
|
|
52
87
|
//# sourceMappingURL=digital-link.js.map
|
package/dist/digital-link.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digital-link.js","sourceRoot":"","sources":["../src/digital-link.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"digital-link.js","sourceRoot":"","sources":["../src/digital-link.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,0CAA0C;AAC1C,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,mDAAmD;AACnD,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB;;;;;GAKG;AACH,SAAS,WAAW,CAAC,IAAY;IAC/B,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC,CAAC,CAAE,OAAO,QAAQ,GAAG,IAAI,CAAC;QAChC,KAAK,EAAE,CAAC,CAAC,OAAO,IAAI,GAAO,IAAI,CAAC;QAChC,KAAK,EAAE,CAAC,CAAC,OAAO,GAAG,GAAQ,IAAI,CAAC;QAChC,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,qDAAqD;IAC7E,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAc,EACd,IAAY,EACZ,YAAoB;IAEpB,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,aAAa,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;IACvD,OAAO,WAAW,WAAW,IAAI,OAAO,IAAI,MAAM,IAAI,SAAS,IAAI,aAAa,EAAE,CAAC;AACrF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAW;IAEX,4CAA4C;IAC5C,sEAAsE;IACtE,kEAAkE;IAClE,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CACrB,mDAAmD,CACpD,CAAC;IACF,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IAExB,OAAO;QACL,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC3B,YAAY,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAC3C,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAAY,EACZ,YAAoB;IAEpB,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAC;AACnF,CAAC"}
|
package/dist/gtin.d.ts
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A GTIN-14 is a 14-digit string. The last digit is a check digit computed
|
|
5
5
|
* using the GS1 modulo-10 algorithm (alternating ×3/×1 from the right).
|
|
6
|
+
*
|
|
7
|
+
* ⚠️ MIRRORED INTO THE PUBLIC npm PACKAGE @tracepass/gs1-utils.
|
|
8
|
+
* `tracepass-open/packages/gs1-utils/src/gtin.ts` is a hand-copy of this
|
|
9
|
+
* file — nothing generates one from the other, and a stale copy fails silently
|
|
10
|
+
* (it still compiles and still returns a plausible answer). tracepass-open
|
|
11
|
+
* gates on a hash of this file in CI, so after changing it:
|
|
12
|
+
*
|
|
13
|
+
* cd ../tracepass-open && node scripts/build-mirror-manifest.mjs \
|
|
14
|
+
* && npm run check:mirrors
|
|
15
|
+
*
|
|
16
|
+
* and commit `mirror-manifest.json` with the code.
|
|
6
17
|
*/
|
|
7
18
|
/**
|
|
8
19
|
* Calculate the GS1 check digit for the first 13 digits of a GTIN-14.
|
|
@@ -16,4 +27,20 @@ export declare function calculateCheckDigit(gtin13: string): string;
|
|
|
16
27
|
* digit matches.
|
|
17
28
|
*/
|
|
18
29
|
export declare function validateGtin(gtin: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Normalise a GTIN of any standard length (8, 12, 13, or 14 digits) to 14 digits
|
|
32
|
+
* by left-padding with zeros.
|
|
33
|
+
*
|
|
34
|
+
* GS1 guarantees that any GTIN format becomes a valid GTIN-14 when left-padded
|
|
35
|
+
* to 14 digits — the mod-10 check digit is preserved. Returns null when:
|
|
36
|
+
* - the input is not a string or not all digits
|
|
37
|
+
* - the length is not one of 8, 12, 13, or 14
|
|
38
|
+
* - the mod-10 check digit does not match after padding
|
|
39
|
+
*/
|
|
40
|
+
export declare function normalizeGtin(input: string): string | null;
|
|
41
|
+
/**
|
|
42
|
+
* Alias for {@link normalizeGtin}. Returns the GTIN-14 form or null on invalid
|
|
43
|
+
* length or bad check digit.
|
|
44
|
+
*/
|
|
45
|
+
export declare const toGtin14: typeof normalizeGtin;
|
|
19
46
|
//# sourceMappingURL=gtin.d.ts.map
|
package/dist/gtin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gtin.d.ts","sourceRoot":"","sources":["../src/gtin.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"gtin.d.ts","sourceRoot":"","sources":["../src/gtin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAe1D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOlD;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAc1D;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,sBAAgB,CAAC"}
|
package/dist/gtin.js
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A GTIN-14 is a 14-digit string. The last digit is a check digit computed
|
|
5
5
|
* using the GS1 modulo-10 algorithm (alternating ×3/×1 from the right).
|
|
6
|
+
*
|
|
7
|
+
* ⚠️ MIRRORED INTO THE PUBLIC npm PACKAGE @tracepass/gs1-utils.
|
|
8
|
+
* `tracepass-open/packages/gs1-utils/src/gtin.ts` is a hand-copy of this
|
|
9
|
+
* file — nothing generates one from the other, and a stale copy fails silently
|
|
10
|
+
* (it still compiles and still returns a plausible answer). tracepass-open
|
|
11
|
+
* gates on a hash of this file in CI, so after changing it:
|
|
12
|
+
*
|
|
13
|
+
* cd ../tracepass-open && node scripts/build-mirror-manifest.mjs \
|
|
14
|
+
* && npm run check:mirrors
|
|
15
|
+
*
|
|
16
|
+
* and commit `mirror-manifest.json` with the code.
|
|
6
17
|
*/
|
|
7
18
|
/**
|
|
8
19
|
* Calculate the GS1 check digit for the first 13 digits of a GTIN-14.
|
|
@@ -35,4 +46,42 @@ export function validateGtin(gtin) {
|
|
|
35
46
|
const expected = calculateCheckDigit(gtin.slice(0, 13));
|
|
36
47
|
return gtin[13] === expected;
|
|
37
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Normalise a GTIN of any standard length (8, 12, 13, or 14 digits) to 14 digits
|
|
51
|
+
* by left-padding with zeros.
|
|
52
|
+
*
|
|
53
|
+
* GS1 guarantees that any GTIN format becomes a valid GTIN-14 when left-padded
|
|
54
|
+
* to 14 digits — the mod-10 check digit is preserved. Returns null when:
|
|
55
|
+
* - the input is not a string or not all digits
|
|
56
|
+
* - the length is not one of 8, 12, 13, or 14
|
|
57
|
+
* - the mod-10 check digit does not match after padding
|
|
58
|
+
*/
|
|
59
|
+
export function normalizeGtin(input) {
|
|
60
|
+
if (typeof input !== "string")
|
|
61
|
+
return null;
|
|
62
|
+
if (!/^\d+$/.test(input))
|
|
63
|
+
return null;
|
|
64
|
+
let gtin14;
|
|
65
|
+
switch (input.length) {
|
|
66
|
+
case 8:
|
|
67
|
+
gtin14 = "000000" + input;
|
|
68
|
+
break;
|
|
69
|
+
case 12:
|
|
70
|
+
gtin14 = "00" + input;
|
|
71
|
+
break;
|
|
72
|
+
case 13:
|
|
73
|
+
gtin14 = "0" + input;
|
|
74
|
+
break;
|
|
75
|
+
case 14:
|
|
76
|
+
gtin14 = input;
|
|
77
|
+
break;
|
|
78
|
+
default: return null;
|
|
79
|
+
}
|
|
80
|
+
return validateGtin(gtin14) ? gtin14 : null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Alias for {@link normalizeGtin}. Returns the GTIN-14 form or null on invalid
|
|
84
|
+
* length or bad check digit.
|
|
85
|
+
*/
|
|
86
|
+
export const toGtin14 = normalizeGtin;
|
|
38
87
|
//# sourceMappingURL=gtin.js.map
|
package/dist/gtin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gtin.js","sourceRoot":"","sources":["../src/gtin.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"gtin.js","sourceRoot":"","sources":["../src/gtin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAChC,iEAAiE;QACjE,wEAAwE;QACxE,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,SAAS,GAAG,GAAG,GAAG,EAAE,CAAC;IAC3B,OAAO,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,QAAQ,GAAG,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACxD,OAAO,IAAI,CAAC,EAAE,CAAC,KAAK,QAAQ,CAAC;AAC/B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEtC,IAAI,MAAc,CAAC;IACnB,QAAQ,KAAK,CAAC,MAAM,EAAE,CAAC;QACrB,KAAK,CAAC;YAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;YAAC,MAAM;QAC1C,KAAK,EAAE;YAAE,MAAM,GAAG,IAAI,GAAO,KAAK,CAAC;YAAC,MAAM;QAC1C,KAAK,EAAE;YAAE,MAAM,GAAG,GAAG,GAAQ,KAAK,CAAC;YAAC,MAAM;QAC1C,KAAK,EAAE;YAAE,MAAM,GAAG,KAAK,CAAC;YAAY,MAAM;QAC1C,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC;IACvB,CAAC;IAED,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9C,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,aAAa,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { buildDigitalLinkUri, parseDigitalLinkUri, buildDigitalLinkSegments, } from "./digital-link.js";
|
|
8
8
|
export { validateGln, normalizeGln, calculateCheckDigit as calculateGlnCheckDigit, } from "./gln.js";
|
|
9
|
-
export { validateGtin, calculateCheckDigit as calculateGtinCheckDigit, } from "./gtin.js";
|
|
9
|
+
export { validateGtin, normalizeGtin, toGtin14, calculateCheckDigit as calculateGtinCheckDigit, } from "./gtin.js";
|
|
10
10
|
export { parseAcceptLanguage, detectLanguage } from "./language.js";
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EACL,WAAW,EACX,YAAY,EACZ,mBAAmB,IAAI,sBAAsB,GAC9C,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,YAAY,EACZ,mBAAmB,IAAI,uBAAuB,GAC/C,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EACL,WAAW,EACX,YAAY,EACZ,mBAAmB,IAAI,sBAAsB,GAC9C,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,mBAAmB,IAAI,uBAAuB,GAC/C,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,6 @@ export { buildDigitalLinkUri, parseDigitalLinkUri, buildDigitalLinkSegments, } f
|
|
|
9
9
|
// algorithm but different length rules, so each is re-exported under its own
|
|
10
10
|
// name rather than colliding at the barrel.
|
|
11
11
|
export { validateGln, normalizeGln, calculateCheckDigit as calculateGlnCheckDigit, } from "./gln.js";
|
|
12
|
-
export { validateGtin, calculateCheckDigit as calculateGtinCheckDigit, } from "./gtin.js";
|
|
12
|
+
export { validateGtin, normalizeGtin, toGtin14, calculateCheckDigit as calculateGtinCheckDigit, } from "./gtin.js";
|
|
13
13
|
export { parseAcceptLanguage, detectLanguage } from "./language.js";
|
|
14
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAE3B,+EAA+E;AAC/E,6EAA6E;AAC7E,4CAA4C;AAC5C,OAAO,EACL,WAAW,EACX,YAAY,EACZ,mBAAmB,IAAI,sBAAsB,GAC9C,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,YAAY,EACZ,mBAAmB,IAAI,uBAAuB,GAC/C,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAE3B,+EAA+E;AAC/E,6EAA6E;AAC7E,4CAA4C;AAC5C,OAAO,EACL,WAAW,EACX,YAAY,EACZ,mBAAmB,IAAI,sBAAsB,GAC9C,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,mBAAmB,IAAI,uBAAuB,GAC/C,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tracepass/gs1-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "GS1 identifier utilities for Digital Product Passports — GTIN and GLN check-digit validation, GS1 Digital Link URI build/parse. Zero dependencies in the core; the optional QR subpath asks for qrcode as a peer.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gs1",
|