@pubid/pubid 0.1.60 → 0.1.62
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/artifact/corpus.json.gz +0 -0
- package/dist/conformance/implementation.d.ts +2 -0
- package/dist/flavors/iho/index.js +244 -11
- package/dist/flavors/wmo/index.js +33 -8
- package/dist/flavors/wmo/model.d.ts +58 -8
- package/dist/flavors/wmo/model.js +114 -41
- package/dist/pubid-urn/schemas/iala.js +1 -0
- package/dist/pubid-urn/schemas/iho.js +1 -0
- package/dist/pubid-urn/schemas/wmo.js +4 -0
- package/dist/urn/parsers.js +373 -81
- package/dist/urn/types.d.ts +4 -1
- package/package.json +1 -1
- package/vendor/parg/adobe.json +1 -1
- package/vendor/parg/iala.json +1 -1
- package/vendor/parg/iho.json +1 -1
- package/vendor/parg/wmo.json +1 -1
package/dist/urn/parsers.js
CHANGED
|
@@ -3,6 +3,287 @@ import { splitParts, withYear } from "./types.js";
|
|
|
3
3
|
// including its lossiness (dropped segments stay dropped) and its error
|
|
4
4
|
// cases. The parity fixture (test/fixtures/urn-parity.json) pins the
|
|
5
5
|
// reference behavior for ~93k corpus URNs.
|
|
6
|
+
// --- the IHO URN decode (lib/pubid/iho/urn_parser.rb) -------------------
|
|
7
|
+
//
|
|
8
|
+
// Both namespaces decode onto the canonical shape through the same
|
|
9
|
+
// marker machinery: the segments build an attribute map (the positional
|
|
10
|
+
// ed-/year- attachment included), and the map renders the canonical
|
|
11
|
+
// human text for the text parse — the draft-era part faces rebind
|
|
12
|
+
// through the builder and the spelling face drops, so a decoded
|
|
13
|
+
// identifier renders the primary colon designator.
|
|
14
|
+
const IHO_MRN_TYPE_LETTERS = { spec: "S", per: "P", reg: "M" };
|
|
15
|
+
// The publication name: the lowercase series letter + number, the
|
|
16
|
+
// S-158 member hyphen-joined (s158-102).
|
|
17
|
+
const IHO_MRN_NAME_RE = /^([spmbc])(\d+)(?:-(\d+))?$/;
|
|
18
|
+
const IHO_DOTTED = /^\d+\.\d+\.\d+$/;
|
|
19
|
+
const IHO_SUBNUMBER = /^\d+$/;
|
|
20
|
+
// The docnumber's own charset: digits with : / - suffix runs.
|
|
21
|
+
const IHO_NUMBER = /^\d+(?:[:/-]\d+)*$/;
|
|
22
|
+
// Marker => attribute, with the value pattern each marker's slot
|
|
23
|
+
// accepts (the grammar's own production rules; values case-preserved).
|
|
24
|
+
const IHO_MARKERS = {
|
|
25
|
+
ed: { key: "ed", pattern: /^\d+\.\d+\.\d+$/ },
|
|
26
|
+
sup: { key: "supplement", pattern: /^\d+$/ },
|
|
27
|
+
part: { key: "part", pattern: /^(?:\d+[a-zA-Z]*|[A-Z]|[SPMBC]-\d+)$/ },
|
|
28
|
+
spec: { key: "spec", pattern: /^[1-6]\d\d$/ },
|
|
29
|
+
specsub: { key: "spec_sub", pattern: /^\d+$/ },
|
|
30
|
+
specvar: { key: "spec_variant", pattern: /^[A-Z]+$/ },
|
|
31
|
+
annex: { key: "annex", pattern: /^[A-Z]$/ },
|
|
32
|
+
appendix: { key: "appendix", pattern: /^(?:[A-Z](?:-\d+)?|\d+)$/ },
|
|
33
|
+
vol: { key: "volume", pattern: /^\d+$/ },
|
|
34
|
+
issue: { key: "issue", pattern: /^\d+$/ },
|
|
35
|
+
year: { key: "year", pattern: /^(?:19|20)\d{2}$/ },
|
|
36
|
+
};
|
|
37
|
+
const IHO_MARKER_RE = new RegExp(`^(${Object.keys(IHO_MARKERS).join("|")})-(.+)$`);
|
|
38
|
+
// Legacy dotted keys (deprecated; decodable, never emitted). "y." is
|
|
39
|
+
// the pre-positional year tag — a year IS a volume, so its value
|
|
40
|
+
// decodes into the volume.
|
|
41
|
+
const IHO_LEGACY_KEYS = {
|
|
42
|
+
part: "part",
|
|
43
|
+
annex: "annex",
|
|
44
|
+
suppl: "supplement",
|
|
45
|
+
ap: "appendix",
|
|
46
|
+
appendix: "appendix",
|
|
47
|
+
vol: "volume",
|
|
48
|
+
issue: "issue",
|
|
49
|
+
y: "volume",
|
|
50
|
+
};
|
|
51
|
+
/** The segments build the attribute map: marker segments validated
|
|
52
|
+
* against their own value pattern, ed-/year- positional (the edition
|
|
53
|
+
* attaches to the component it follows, the year to that component's
|
|
54
|
+
* edition owner), specsub-/specvar- only after their parent, the
|
|
55
|
+
* appendix carrying its subnumber hyphen-joined or as the bare atom
|
|
56
|
+
* directly after it. Unknown, reordered or junk segments reject. */
|
|
57
|
+
function ihoConsumeSegments(attrs, segments, body) {
|
|
58
|
+
let component;
|
|
59
|
+
let editionOwner;
|
|
60
|
+
const fail = (message, segment) => {
|
|
61
|
+
throw new Error(`${message} ${JSON.stringify(segment)} in ${JSON.stringify(body)}`);
|
|
62
|
+
};
|
|
63
|
+
const store = (key, value) => {
|
|
64
|
+
if (attrs[key] !== undefined)
|
|
65
|
+
fail("Duplicate", `${key}: ${value}`);
|
|
66
|
+
attrs[key] = value;
|
|
67
|
+
};
|
|
68
|
+
const isSpecNode = (node) => node === "spec" || node === "spec_sub" || node === "spec_variant";
|
|
69
|
+
for (let idx = 0; idx < segments.length; idx += 1) {
|
|
70
|
+
const segment = segments[idx];
|
|
71
|
+
const marker = IHO_MARKER_RE.exec(segment);
|
|
72
|
+
if (marker !== null) {
|
|
73
|
+
const tag = marker[1];
|
|
74
|
+
const value = marker[2];
|
|
75
|
+
const entry = IHO_MARKERS[tag];
|
|
76
|
+
if (!entry.pattern.test(value))
|
|
77
|
+
fail(`Invalid ${tag} value`, JSON.stringify(value));
|
|
78
|
+
const key = entry.key;
|
|
79
|
+
if ((key === "spec_sub" || key === "spec_variant") &&
|
|
80
|
+
component !== "spec" && component !== "spec_sub") {
|
|
81
|
+
fail(`${key}- is only allowed after spec- in`, segment);
|
|
82
|
+
}
|
|
83
|
+
if (key === "ed" || key === "year") {
|
|
84
|
+
// Positional: the edition attaches to the component it follows
|
|
85
|
+
// (the base when none precedes), the year to that component's
|
|
86
|
+
// edition owner. An S-4 spec carries neither — it rides its
|
|
87
|
+
// publication's edition.
|
|
88
|
+
if (isSpecNode(component)) {
|
|
89
|
+
fail("an S-4 spec rides its publication's edition:", segment);
|
|
90
|
+
}
|
|
91
|
+
if (key === "ed") {
|
|
92
|
+
store(component === undefined ? "edition" : `${component}_edition`, value);
|
|
93
|
+
editionOwner = component;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
store(editionOwner !== undefined ? `${editionOwner}_year` : "year", value);
|
|
97
|
+
editionOwner = undefined;
|
|
98
|
+
}
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (key === "appendix") {
|
|
102
|
+
// The hyphen-joined compound value ("D-2", the MRN emission)
|
|
103
|
+
// splits into the appendix and its subnumber; the legacy
|
|
104
|
+
// emission carries the subnumber as the bare atom below.
|
|
105
|
+
const compound = /^([A-Z])-(\d+)$/.exec(value);
|
|
106
|
+
if (compound !== null) {
|
|
107
|
+
store("appendix", compound[1]);
|
|
108
|
+
store("appendix_subnumber", compound[2]);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
store("appendix", value);
|
|
112
|
+
}
|
|
113
|
+
component = "appendix";
|
|
114
|
+
editionOwner = undefined;
|
|
115
|
+
const next = segments[idx + 1];
|
|
116
|
+
if (next !== undefined && IHO_SUBNUMBER.test(next)) {
|
|
117
|
+
store("appendix_subnumber", next);
|
|
118
|
+
idx += 1;
|
|
119
|
+
}
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
store(key, value);
|
|
123
|
+
component = key;
|
|
124
|
+
editionOwner = undefined;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const legacy = /^([a-z]+)\.(.*)$/.exec(segment);
|
|
128
|
+
if (legacy !== null) {
|
|
129
|
+
const key = IHO_LEGACY_KEYS[legacy[1]];
|
|
130
|
+
if (key === undefined)
|
|
131
|
+
fail("Unexpected segment", segment);
|
|
132
|
+
// The legacy appendix value stored the subnumber in one string
|
|
133
|
+
// ("appendix.D-2"); it decodes into the two components.
|
|
134
|
+
const sub = key === "appendix" ? /^([A-Z])-(\d+)$/.exec(legacy[2]) : null;
|
|
135
|
+
if (sub !== null) {
|
|
136
|
+
store("appendix", sub[1]);
|
|
137
|
+
store("appendix_subnumber", sub[2]);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
store(key, legacy[2]);
|
|
141
|
+
}
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (IHO_DOTTED.test(segment)) {
|
|
145
|
+
// A bare a.b.c segment is the legacy edition encoding.
|
|
146
|
+
store("edition", segment);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
fail("Unexpected segment", segment);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** The canonical human text of a decoded attribute map (the render's
|
|
153
|
+
* own FACES order: the colon designator on the code, the edition
|
|
154
|
+
* before the part, the citation replacing the Part face). */
|
|
155
|
+
function ihoCanonicalText(typeLetter, attrs) {
|
|
156
|
+
let text = `IHO ${typeLetter}-${attrs["number"] ?? ""}`;
|
|
157
|
+
if (attrs["checks_for"] !== undefined)
|
|
158
|
+
text += `:${attrs["checks_for"]}`;
|
|
159
|
+
if (attrs["edition"] !== undefined)
|
|
160
|
+
text += ` ${attrs["edition"]}`;
|
|
161
|
+
if (attrs["supplement"] !== undefined) {
|
|
162
|
+
text += ` Sup ${attrs["supplement"]}`;
|
|
163
|
+
if (attrs["supplement_edition"] !== undefined)
|
|
164
|
+
text += ` ${attrs["supplement_edition"]}`;
|
|
165
|
+
if (attrs["supplement_year"] !== undefined)
|
|
166
|
+
text += ` (${attrs["supplement_year"]})`;
|
|
167
|
+
}
|
|
168
|
+
if (attrs["spec"] !== undefined) {
|
|
169
|
+
// "B-401", "B-122.1", "B-521(I)" — the citation face replaces the
|
|
170
|
+
// Part face.
|
|
171
|
+
text += ` ${attrs["part"]}-${attrs["spec"]}`;
|
|
172
|
+
if (attrs["spec_sub"] !== undefined)
|
|
173
|
+
text += `.${attrs["spec_sub"]}`;
|
|
174
|
+
if (attrs["spec_variant"] !== undefined)
|
|
175
|
+
text += `(${attrs["spec_variant"]})`;
|
|
176
|
+
}
|
|
177
|
+
else if (attrs["part"] !== undefined) {
|
|
178
|
+
text += ` Part ${attrs["part"]}`;
|
|
179
|
+
if (attrs["part_edition"] !== undefined)
|
|
180
|
+
text += ` ${attrs["part_edition"]}`;
|
|
181
|
+
if (attrs["part_year"] !== undefined)
|
|
182
|
+
text += ` (${attrs["part_year"]})`;
|
|
183
|
+
}
|
|
184
|
+
if (attrs["annex"] !== undefined) {
|
|
185
|
+
text += ` Annex ${attrs["annex"]}`;
|
|
186
|
+
if (attrs["annex_edition"] !== undefined)
|
|
187
|
+
text += ` ${attrs["annex_edition"]}`;
|
|
188
|
+
if (attrs["annex_year"] !== undefined)
|
|
189
|
+
text += ` (${attrs["annex_year"]})`;
|
|
190
|
+
}
|
|
191
|
+
if (attrs["appendix"] !== undefined) {
|
|
192
|
+
text += ` Appendix ${attrs["appendix"]}`;
|
|
193
|
+
if (attrs["appendix_subnumber"] !== undefined)
|
|
194
|
+
text += `-${attrs["appendix_subnumber"]}`;
|
|
195
|
+
if (attrs["appendix_edition"] !== undefined)
|
|
196
|
+
text += ` ${attrs["appendix_edition"]}`;
|
|
197
|
+
if (attrs["appendix_year"] !== undefined)
|
|
198
|
+
text += ` (${attrs["appendix_year"]})`;
|
|
199
|
+
}
|
|
200
|
+
if (attrs["volume"] !== undefined) {
|
|
201
|
+
text += ` Vol. ${attrs["volume"]}`;
|
|
202
|
+
if (attrs["issue"] !== undefined)
|
|
203
|
+
text += ` (${attrs["issue"]})`;
|
|
204
|
+
if (attrs["volume_edition"] !== undefined)
|
|
205
|
+
text += ` ${attrs["volume_edition"]}`;
|
|
206
|
+
if (attrs["volume_year"] !== undefined)
|
|
207
|
+
text += ` (${attrs["volume_year"]})`;
|
|
208
|
+
}
|
|
209
|
+
if (attrs["year"] !== undefined)
|
|
210
|
+
text += ` (${attrs["year"]})`;
|
|
211
|
+
return text;
|
|
212
|
+
}
|
|
213
|
+
/** The S-158 family rebind on the decode path: a draft-era part face
|
|
214
|
+
* riding number 158 rebinds onto checks_for and the spelling face
|
|
215
|
+
* drops (the decoded identifier renders the primary colon
|
|
216
|
+
* designator). */
|
|
217
|
+
function ihoRebindChecks(typeLetter, attrs) {
|
|
218
|
+
if (typeLetter !== "S" || attrs["number"] !== "158" || attrs["checks_for"] !== undefined) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const part = attrs["part"];
|
|
222
|
+
if (part === undefined)
|
|
223
|
+
return;
|
|
224
|
+
const seriesRef = /^([SPMBC])-(\d+)$/.exec(part);
|
|
225
|
+
const digits = seriesRef !== null ? seriesRef[2] : /^\d+$/.test(part) ? part : undefined;
|
|
226
|
+
if (digits === undefined)
|
|
227
|
+
return;
|
|
228
|
+
delete attrs["part"];
|
|
229
|
+
// The edition/year that followed the draft-era part face are the
|
|
230
|
+
// BASE ones (the pubid#775 mis-bind fix).
|
|
231
|
+
if (attrs["edition"] === undefined && attrs["part_edition"] !== undefined) {
|
|
232
|
+
attrs["edition"] = attrs["part_edition"];
|
|
233
|
+
}
|
|
234
|
+
if (attrs["year"] === undefined && attrs["part_year"] !== undefined) {
|
|
235
|
+
attrs["year"] = attrs["part_year"];
|
|
236
|
+
}
|
|
237
|
+
delete attrs["part_edition"];
|
|
238
|
+
delete attrs["part_year"];
|
|
239
|
+
attrs["checks_for"] = digits;
|
|
240
|
+
}
|
|
241
|
+
/** The MRN guidance decode: type token, name (number + optional S-158
|
|
242
|
+
* member), the bare dotted edition, then the shared marker machinery. */
|
|
243
|
+
function ihoMrnText(body) {
|
|
244
|
+
const segments = splitParts(body);
|
|
245
|
+
const typeToken = (segments.shift() ?? "").toLowerCase();
|
|
246
|
+
const letter = IHO_MRN_TYPE_LETTERS[typeToken];
|
|
247
|
+
if (letter === undefined) {
|
|
248
|
+
throw new Error(`Unknown IHO publication type ${JSON.stringify(typeToken)} in ${JSON.stringify(body)}`);
|
|
249
|
+
}
|
|
250
|
+
const name = segments.shift() ?? "";
|
|
251
|
+
const nameMatch = IHO_MRN_NAME_RE.exec(name);
|
|
252
|
+
if (nameMatch === null) {
|
|
253
|
+
throw new Error(`Unknown IHO publication name ${JSON.stringify(name)} in ${JSON.stringify(body)}`);
|
|
254
|
+
}
|
|
255
|
+
const attrs = { number: nameMatch[2] };
|
|
256
|
+
if (nameMatch[3] !== undefined)
|
|
257
|
+
attrs["checks_for"] = nameMatch[3];
|
|
258
|
+
if (segments[0] !== undefined && IHO_DOTTED.test(segments[0])) {
|
|
259
|
+
attrs["edition"] = segments.shift();
|
|
260
|
+
}
|
|
261
|
+
ihoConsumeSegments(attrs, segments, body);
|
|
262
|
+
ihoRebindChecks(letter, attrs);
|
|
263
|
+
return ihoCanonicalText(letter, attrs);
|
|
264
|
+
}
|
|
265
|
+
/** The legacy positional decode: the type letter, the docnumber, a
|
|
266
|
+
* further bare digit segment binding the S-158 member (checks_for —
|
|
267
|
+
* "urn:iho:s:158:100"; another anchor rejects through the builder),
|
|
268
|
+
* then the shared marker machinery. */
|
|
269
|
+
function ihoLegacyText(body) {
|
|
270
|
+
const segments = splitParts(body);
|
|
271
|
+
const typeToken = (segments.shift() ?? "").toLowerCase();
|
|
272
|
+
if (!/^[spmbc]$/.test(typeToken)) {
|
|
273
|
+
throw new Error(`Unknown IHO series ${JSON.stringify(typeToken)} in ${JSON.stringify(body)}`);
|
|
274
|
+
}
|
|
275
|
+
const number = segments.shift() ?? "";
|
|
276
|
+
if (!IHO_NUMBER.test(number)) {
|
|
277
|
+
throw new Error(`Missing docnumber ${JSON.stringify(number)} in ${JSON.stringify(body)}`);
|
|
278
|
+
}
|
|
279
|
+
const attrs = { number };
|
|
280
|
+
if (segments[0] !== undefined && /^\d+$/.test(segments[0])) {
|
|
281
|
+
attrs["checks_for"] = segments.shift();
|
|
282
|
+
}
|
|
283
|
+
ihoConsumeSegments(attrs, segments, body);
|
|
284
|
+
ihoRebindChecks(typeToken.toUpperCase(), attrs);
|
|
285
|
+
return ihoCanonicalText(typeToken.toUpperCase(), attrs);
|
|
286
|
+
}
|
|
6
287
|
// The adopted CEN spine consumes its own supplements; their urn segments
|
|
7
288
|
// carry the consolidation marker ("plus" = "+A1", its absence = "/A1") —
|
|
8
289
|
// cen_cenelec/urn_generator.rb's supplement_segments.
|
|
@@ -286,72 +567,26 @@ export const URN_PARSERS = {
|
|
|
286
567
|
return parse(year ? `GOST ${number}-${year}` : `GOST ${number}`);
|
|
287
568
|
},
|
|
288
569
|
},
|
|
289
|
-
// lib/pubid/iho/urn_parser.rb
|
|
290
|
-
//
|
|
291
|
-
//
|
|
292
|
-
//
|
|
293
|
-
//
|
|
294
|
-
//
|
|
295
|
-
//
|
|
296
|
-
//
|
|
297
|
-
//
|
|
570
|
+
// lib/pubid/iho/urn_parser.rb — two namespaces. The EMITTED form for
|
|
571
|
+
// S/P/M is the IHO MRN guidance scheme
|
|
572
|
+
// "urn:mrn:iho:pub:<type>:<name>[:<dotted edition>][:<atoms>]" —
|
|
573
|
+
// type spec/per/reg mapping back to the series letter, the name the
|
|
574
|
+
// lowercase letter + number with the S-158 member hyphenated in
|
|
575
|
+
// (s158-102), the bare dotted edition right after the name, then the
|
|
576
|
+
// lowercase marker atoms. The LEGACY urn:iho: positional scheme (the
|
|
577
|
+
// B/C emission; decodable for every series, never emitted for S/P/M):
|
|
578
|
+
// the type letter, the docnumber, a further bare digit segment
|
|
579
|
+
// binding the S-158 member ("urn:iho:s:158:100"), then the markers.
|
|
580
|
+
// Legacy 2.0.x dotted keys (part./annex./suppl./ap./appendix./vol./
|
|
581
|
+
// issue./y.) stay decodable, never emitted. Both paths decode onto
|
|
582
|
+
// the canonical shape: the draft-era part faces rebind through the
|
|
583
|
+
// builder and the spelling face drops, so a decoded identifier
|
|
584
|
+
// renders the primary colon designator.
|
|
298
585
|
iho: {
|
|
299
|
-
prefix: "urn:iho:",
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const
|
|
303
|
-
const VERSION_SEGMENT = /^\d+\.\d+\.\d+$/;
|
|
304
|
-
const DIGITS = /^\d+$/;
|
|
305
|
-
const TAG_TEXT = {
|
|
306
|
-
ed: (v) => ` ${v}`,
|
|
307
|
-
year: (v) => ` (${v})`,
|
|
308
|
-
sup: (v) => ` Sup ${v}`,
|
|
309
|
-
part: (v) => ` Part ${v}`,
|
|
310
|
-
annex: (v) => ` Annex ${v}`,
|
|
311
|
-
appendix: (v) => ` Appendix ${v}`,
|
|
312
|
-
vol: (v) => ` Vol. ${v}`,
|
|
313
|
-
issue: (v) => ` (${v})`,
|
|
314
|
-
// Legacy dotted keys: decodable, never emitted. The dotted
|
|
315
|
-
// appendix value carries its subnumber in one string ("D-2").
|
|
316
|
-
ap: (v) => ` Ap. ${v}`,
|
|
317
|
-
suppl: (v) => ` Suppl ${v}`,
|
|
318
|
-
y: (v) => ` ${v}`,
|
|
319
|
-
};
|
|
320
|
-
const parts = splitParts(body);
|
|
321
|
-
const typeToken = (parts[0] ?? "").toUpperCase();
|
|
322
|
-
const tagged = (s) => /^[a-z]+[-.]/i.test(s);
|
|
323
|
-
const first = parts[1] ?? "";
|
|
324
|
-
let idx = 2;
|
|
325
|
-
while (idx < parts.length && !tagged(parts[idx]) && !VERSION_SEGMENT.test(parts[idx])) {
|
|
326
|
-
idx += 1;
|
|
327
|
-
}
|
|
328
|
-
const number = [first, ...parts.slice(2, idx)];
|
|
329
|
-
let text = `IHO ${typeToken}-${number.join(":")}`;
|
|
330
|
-
let appendixSeen = false;
|
|
331
|
-
for (; idx < parts.length; idx += 1) {
|
|
332
|
-
const segment = parts[idx];
|
|
333
|
-
if (VERSION_SEGMENT.test(segment)) {
|
|
334
|
-
text += ` ${segment}`;
|
|
335
|
-
continue;
|
|
336
|
-
}
|
|
337
|
-
if (DIGITS.test(segment)) {
|
|
338
|
-
// The appendix subnumber is the only bare atom past the
|
|
339
|
-
// markers, allowed directly after its appendix segment.
|
|
340
|
-
if (!appendixSeen)
|
|
341
|
-
throw new Error(`unexpected bare segment: ${segment}`);
|
|
342
|
-
text += `-${segment}`;
|
|
343
|
-
continue;
|
|
344
|
-
}
|
|
345
|
-
const match = NEW_TAG.exec(segment) ?? LEGACY_TAG.exec(segment);
|
|
346
|
-
const tag = match?.[1]?.toLowerCase();
|
|
347
|
-
const value = match?.[2] ?? "";
|
|
348
|
-
const fn = tag !== undefined ? TAG_TEXT[tag] : undefined;
|
|
349
|
-
if (fn === undefined)
|
|
350
|
-
throw new Error(`unknown iho urn segment: ${segment}`);
|
|
351
|
-
if (tag === "appendix")
|
|
352
|
-
appendixSeen = true;
|
|
353
|
-
text += fn(value);
|
|
354
|
-
}
|
|
586
|
+
prefix: "urn:mrn:iho:pub:",
|
|
587
|
+
prefixes: ["urn:mrn:iho:pub:", "urn:iho:"],
|
|
588
|
+
reconstruct(body, parse, prefix) {
|
|
589
|
+
const text = prefix === "urn:iho:" ? ihoLegacyText(body) : ihoMrnText(body);
|
|
355
590
|
return parse(text);
|
|
356
591
|
},
|
|
357
592
|
},
|
|
@@ -732,13 +967,18 @@ export const URN_PARSERS = {
|
|
|
732
967
|
return parse(text);
|
|
733
968
|
},
|
|
734
969
|
},
|
|
735
|
-
// lib/pubid/wmo/urn_parser.rb — the MRN segments
|
|
736
|
-
//
|
|
737
|
-
//
|
|
738
|
-
//
|
|
739
|
-
//
|
|
740
|
-
//
|
|
741
|
-
//
|
|
970
|
+
// lib/pubid/wmo/urn_parser.rb — the MRN segments of the widening: the
|
|
971
|
+
// code resolves the series slug ("wmo-td-"/"wmo-"/"jcomm-tr-"/"gaw-"
|
|
972
|
+
// publications, longest slug first; "s-" the S-100 specs). A
|
|
973
|
+
// publication takes the caseless volume ("vol-i.1"), status
|
|
974
|
+
// ("status-provisional"), updated-in ("updated-2025") and one
|
|
975
|
+
// "ed<year>" (the year pair hyphenated, "ed2021-2018") segments; an
|
|
976
|
+
// "s-" code takes a caseless annex segment (at most one, rebuilt as
|
|
977
|
+
// the attested "Annex" face) then the dotted edition. Every other
|
|
978
|
+
// segment must be "ed" + the shape the code declares (a year for a
|
|
979
|
+
// publication, dotted for a standard) — per the ISO urn_parser
|
|
980
|
+
// strictness. The rebuild walks the comma-optional faces and the text
|
|
981
|
+
// parser normalizes (one construction path).
|
|
742
982
|
wmo: {
|
|
743
983
|
prefix: "urn:mrn:wmo:pub:",
|
|
744
984
|
reconstruct(body, parse) {
|
|
@@ -758,18 +998,69 @@ export const URN_PARSERS = {
|
|
|
758
998
|
}
|
|
759
999
|
return edition;
|
|
760
1000
|
};
|
|
761
|
-
|
|
762
|
-
|
|
1001
|
+
// Longest slug first: "wmo-td-" also starts with "wmo-". The face
|
|
1002
|
+
// is the series key's citation face (the gem reads
|
|
1003
|
+
// Identifier.series_config(series)[:face]).
|
|
1004
|
+
const SERIES_CODES = [
|
|
1005
|
+
["wmo-td-", "TD", "WMO/TD-No."],
|
|
1006
|
+
["wmo-", undefined, "WMO-No."],
|
|
1007
|
+
["jcomm-tr-", "JCOMM", "JCOMM Technical Report No."],
|
|
1008
|
+
["gaw-", "GAW", "GAW Report No."],
|
|
1009
|
+
];
|
|
1010
|
+
const publicationCode = SERIES_CODES
|
|
1011
|
+
.map(([slug, series, face]) => ({
|
|
1012
|
+
series,
|
|
1013
|
+
face,
|
|
1014
|
+
match: new RegExp(`^${slug}(\\d+)$`, "i").exec(code),
|
|
1015
|
+
}))
|
|
1016
|
+
.find(({ match }) => match !== null);
|
|
1017
|
+
if (publicationCode !== undefined) {
|
|
1018
|
+
let volume;
|
|
1019
|
+
let status;
|
|
763
1020
|
let edition;
|
|
1021
|
+
let updatedIn;
|
|
764
1022
|
for (const seg of segments) {
|
|
1023
|
+
const vol = /^vol-([a-z]+(?:\.\d+)*)$/i.exec(seg);
|
|
1024
|
+
if (vol !== null) {
|
|
1025
|
+
if (volume !== undefined) {
|
|
1026
|
+
throw new Error(`Invalid WMO URN segment (duplicate volume): ${JSON.stringify(seg)}`);
|
|
1027
|
+
}
|
|
1028
|
+
volume = vol[1].toUpperCase();
|
|
1029
|
+
continue;
|
|
1030
|
+
}
|
|
1031
|
+
const stat = /^status-([a-z]+)$/i.exec(seg);
|
|
1032
|
+
if (stat !== null) {
|
|
1033
|
+
if (status !== undefined) {
|
|
1034
|
+
throw new Error(`Invalid WMO URN segment (duplicate status): ${JSON.stringify(seg)}`);
|
|
1035
|
+
}
|
|
1036
|
+
status = stat[1].charAt(0).toUpperCase() + stat[1].slice(1);
|
|
1037
|
+
continue;
|
|
1038
|
+
}
|
|
1039
|
+
const updated = /^updated-(\d{4})$/i.exec(seg);
|
|
1040
|
+
if (updated !== null) {
|
|
1041
|
+
if (updatedIn !== undefined) {
|
|
1042
|
+
throw new Error(`Invalid WMO URN segment (duplicate updated): ${JSON.stringify(seg)}`);
|
|
1043
|
+
}
|
|
1044
|
+
updatedIn = updated[1];
|
|
1045
|
+
continue;
|
|
1046
|
+
}
|
|
765
1047
|
if (edition !== undefined) {
|
|
766
1048
|
throw new Error(`Invalid WMO URN segment (duplicate edition): ${JSON.stringify(seg)}`);
|
|
767
1049
|
}
|
|
768
|
-
|
|
1050
|
+
// The year pair keeps its slash out of the NSS as a hyphen;
|
|
1051
|
+
// the rebuild restores it ("ed2021-2018" -> "2021/2018").
|
|
1052
|
+
edition = editionValue(seg, /^\d{4}(?:-\d{4})?$/).replaceAll("-", "/");
|
|
769
1053
|
}
|
|
770
|
-
let text =
|
|
771
|
-
if (
|
|
772
|
-
text +=
|
|
1054
|
+
let text = `${publicationCode.face} ${publicationCode.match[1]}`;
|
|
1055
|
+
if (volume !== undefined)
|
|
1056
|
+
text += ` Volume ${volume}`;
|
|
1057
|
+
if (edition !== undefined) {
|
|
1058
|
+
text += status !== undefined
|
|
1059
|
+
? `, ${status} ${edition} edition`
|
|
1060
|
+
: `, ${edition} edition`;
|
|
1061
|
+
}
|
|
1062
|
+
if (updatedIn !== undefined)
|
|
1063
|
+
text += `, updated in ${updatedIn}`;
|
|
773
1064
|
return parse(text);
|
|
774
1065
|
}
|
|
775
1066
|
const standard = /^s-(\d+)$/i.exec(code);
|
|
@@ -813,9 +1104,10 @@ export function lookupUrnParser(flavor) {
|
|
|
813
1104
|
return URN_PARSERS[flavor];
|
|
814
1105
|
}
|
|
815
1106
|
export function parseUrnFor(def, urn, parse) {
|
|
816
|
-
const
|
|
817
|
-
|
|
1107
|
+
const prefixes = def.prefixes ?? [def.prefix];
|
|
1108
|
+
const hit = prefixes.find((p) => urn.toLowerCase().startsWith(p));
|
|
1109
|
+
if (hit === undefined) {
|
|
818
1110
|
throw new Error(`Invalid ${def.prefix.toUpperCase()} URN: ${JSON.stringify(urn)}`);
|
|
819
1111
|
}
|
|
820
|
-
return def.reconstruct(urn.slice(
|
|
1112
|
+
return def.reconstruct(urn.slice(hit.length), parse, hit);
|
|
821
1113
|
}
|
package/dist/urn/types.d.ts
CHANGED
|
@@ -3,8 +3,11 @@ export type UrnParserDef = {
|
|
|
3
3
|
/** Full URN prefix including the trailing colon
|
|
4
4
|
* (gem UrnParser PREFIX / "urn:" + flavor_name + ":"). */
|
|
5
5
|
prefix: string;
|
|
6
|
+
/** Additional accepted namespaces (legacy spellings stay decodable,
|
|
7
|
+
* never emitted). reconstruct receives the matched prefix. */
|
|
8
|
+
prefixes?: readonly string[];
|
|
6
9
|
/** Rebuild the human text (or parse directly) from the URN body. */
|
|
7
|
-
reconstruct: (body: string, parse: (text: string) => Identifier) => Identifier;
|
|
10
|
+
reconstruct: (body: string, parse: (text: string) => Identifier, prefix?: string) => Identifier;
|
|
8
11
|
};
|
|
9
12
|
/** Split the body on ":" (gem Base#split_parts). */
|
|
10
13
|
export declare function splitParts(body: string): string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pubid/pubid",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.62",
|
|
4
4
|
"description": "TypeScript PubID identifiers: resolution, normalization and canonical hashes for every identifier in the pubid-testsuite corpus (41 standards bodies), with a conformance runner mirroring the Ruby reference",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/vendor/parg/adobe.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"bindings":null,"version":"0.
|
|
1
|
+
{"bindings":null,"version":"0.2.0","grammar":"PubidAdobe","shape":"parsanol-tree/v2","binding_version":1,"entries":{"identifier":{"root":"identifier","grammar":{"atoms":[{"Entity":{"atom":40}},{"Str":{"pattern":"Adobe"}},{"Str":{"pattern":" "}},{"Str":{"pattern":"TN"}},{"Str":{"pattern":" "}},{"Repetition":{"atom":4,"min":0,"max":1,"tag":"Maybe"}},{"Sequence":{"atoms":[1,2,3,5]}},{"Str":{"pattern":"Adobe"}},{"Str":{"pattern":" "}},{"Str":{"pattern":"Technical"}},{"Str":{"pattern":" "}},{"Str":{"pattern":"Note"}},{"Str":{"pattern":" "}},{"Repetition":{"atom":12,"min":0,"max":1,"tag":"Maybe"}},{"Str":{"pattern":"#"}},{"Repetition":{"atom":14,"min":0,"max":1,"tag":"Maybe"}},{"Str":{"pattern":" "}},{"Repetition":{"atom":16,"min":0,"max":1,"tag":"Maybe"}},{"Sequence":{"atoms":[13,15,17]}},{"Repetition":{"atom":18,"min":0,"max":1,"tag":"Maybe"}},{"Sequence":{"atoms":[7,8,9,10,11,19]}},{"Str":{"pattern":"ATN"}},{"Str":{"pattern":" "}},{"Repetition":{"atom":22,"min":0,"max":1,"tag":"Maybe"}},{"Sequence":{"atoms":[21,23]}},{"Alternative":{"atoms":[6,20,24]}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Repetition":{"atom":26,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"number","atom":27}},{"Str":{"pattern":"."}},{"Re":{"pattern":"[\\x41-\\x5a]"}},{"Re":{"pattern":"[\\x61-\\x7a]"}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Re":{"pattern":"[_]"}},{"Alternative":{"atoms":[30,31,32,33]}},{"Repetition":{"atom":34,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"slug","atom":35}},{"Sequence":{"atoms":[29,36]}},{"Repetition":{"atom":37,"min":0,"max":1,"tag":"Maybe"}},{"Sequence":{"atoms":[25,28,38]}},{"Named":{"name":"tech_note","atom":39}},{"Entity":{"atom":44}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Repetition":{"atom":42,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"tech_note_bare","atom":43}},{"Entity":{"atom":98}},{"Str":{"pattern":"Adobe Publication "}},{"Repetition":{"atom":46,"min":0,"max":1,"tag":"Maybe"}},{"Entity":{"atom":97}},{"Entity":{"atom":78}},{"Re":{"pattern":"[\\x61-\\x7a]"}},{"Repetition":{"atom":50,"min":1,"max":null,"tag":"Repetition"}},{"Re":{"pattern":"[\\x61-\\x7a]"}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Alternative":{"atoms":[52,53]}},{"Repetition":{"atom":54,"min":0,"max":null,"tag":"Repetition"}},{"Str":{"pattern":"-"}},{"Re":{"pattern":"[\\x61-\\x7a]"}},{"Repetition":{"atom":57,"min":1,"max":null,"tag":"Repetition"}},{"Re":{"pattern":"[\\x61-\\x7a]"}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Alternative":{"atoms":[59,60]}},{"Repetition":{"atom":61,"min":0,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[56,58,62]}},{"Repetition":{"atom":63,"min":0,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[51,55,64]}},{"Named":{"name":"slug","atom":65}},{"Str":{"pattern":"-"}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Repetition":{"atom":68,"min":1,"max":null,"tag":"Repetition"}},{"Str":{"pattern":"."}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Repetition":{"atom":71,"min":1,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[70,72]}},{"Repetition":{"atom":73,"min":0,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[69,74]}},{"Named":{"name":"version","atom":75}},{"Sequence":{"atoms":[66,67,76]}},{"Named":{"name":"publication_version","atom":77}},{"Entity":{"atom":96}},{"Re":{"pattern":"[\\x61-\\x7a]"}},{"Repetition":{"atom":80,"min":1,"max":null,"tag":"Repetition"}},{"Re":{"pattern":"[\\x61-\\x7a]"}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Alternative":{"atoms":[82,83]}},{"Repetition":{"atom":84,"min":0,"max":null,"tag":"Repetition"}},{"Str":{"pattern":"-"}},{"Re":{"pattern":"[\\x61-\\x7a]"}},{"Repetition":{"atom":87,"min":1,"max":null,"tag":"Repetition"}},{"Re":{"pattern":"[\\x61-\\x7a]"}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Alternative":{"atoms":[89,90]}},{"Repetition":{"atom":91,"min":0,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[86,88,92]}},{"Repetition":{"atom":93,"min":0,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[81,85,94]}},{"Named":{"name":"slug","atom":95}},{"Alternative":{"atoms":[49,79]}},{"Sequence":{"atoms":[47,48]}},{"Alternative":{"atoms":[0,41,45]}}],"root":99},"bindings":[{"capture":"tech_note","path":"tech_note","type":"raw","card":null,"preprocess":null},{"capture":"tech_note_bare","path":"tech_note_bare","type":"string","card":null,"preprocess":null},{"capture":"publication_version","path":"publication_version","type":"raw","card":null,"preprocess":null},{"capture":"number","path":"number","type":"string","card":null,"preprocess":null},{"capture":"slug","path":"slug","type":"string","card":null,"preprocess":null},{"capture":"version","path":"version","type":"string","card":null,"preprocess":null}]}},"preprocess":{},"tables":{},"lint":{"order_warnings":["rule publication_slug_or_version: branches 1 and 2 are order-dependent (shared first bytes; ordered choice is decisive)","rule identifier: branches 1 and 3 are order-dependent (shared first bytes; ordered choice is decisive)"]},"default_entry":"identifier","render":{},"derive":{},"tests":[{"entry":"identifier","kind":"accept","input":"Adobe TN 15","expect":{}},{"entry":"identifier","kind":"accept","input":"ATN 30","expect":{}},{"entry":"identifier","kind":"accept","input":"Adobe Technical Note #12","expect":{}},{"entry":"identifier","kind":"accept","input":"pdf-reference-1.7","expect":{}},{"entry":"identifier","kind":"accept","input":"Adobe Publication tiff-6.0","expect":{}},{"entry":"identifier","kind":"accept","input":"Adobe Publication xfa-3.3","expect":{}},{"entry":"identifier","kind":"accept","input":"adobe-japan1-7","expect":{}},{"entry":"identifier","kind":"reject","input":"###","expect":{}}],"docs":{},"source":"# Port of lib/pubid/adobe/parser.rb: tech notes (Adobe TN 5014, legacy\n# \"Adobe Technical Note #5014\", ATN5014, bare 5014) and publications\n# (adobe-glyph-list, adobe-japan1-7 with the version split tried first).\n#\n# Edition 2: every reference inside a captured body is inlined to raw\n# terms (a rule reference materializes as a named node in the edition-2\n# tree, so only a raw capture binds a scalar span). The prefix spellings\n# and slug shapes live inline below; the wrapper captures (tech_note,\n# tech_note_bare, publication_version) keep the v1 tree shape and the\n# bindings name their scalar leaves.\n\ngrammar PubidAdobe version \"0.2.0\" edition 2 {\n\n # Capture precedence: (*rep) as name wraps the whole repetition, so a\n # digit run joins to one string instead of re-keying every character;\n # slug is captured exactly once (the bare form) or as a sibling of\n # version inside the publication_version capture. The three prefix\n # spellings are inlined longest-first (ordered choice is decisive).\n tech_note = {\n (\n ( \"Adobe\" \" \" \"TN\" [\" \"]\n / \"Adobe\" \" \" \"Technical\" \" \" \"Note\" [[\" \"] [\"#\"] [\" \"]]\n / \"ATN\" [\" \"] )\n (1*%x30-39) as number\n [(\".\" (1*(%x41-5A / %x61-7A / %x30-39 / %x5F)) as slug)]\n ) as tech_note\n }\n # The bare form captures the digit run as one span: the builder\n # stringifies the :tech_note_bare value AS the number (no nested read),\n # so an inner capture here would render the hash, not the digits.\n bare_number = (1*%x30-39) as tech_note_bare\n # Slug text: a lower-case lead segment, then dash-joined segments.\n # The version face is a dot-joined digit run (\"7\", \"1.7\", \"6.0\") — the\n # PDF Reference editions, TIFF 6.0 and XFA 3.3 carry dotted versions.\n publication_with_version = {\n (\n ( 1*%x61-7A *(%x61-7A / %x30-39)\n *(\"-\" 1*%x61-7A *(%x61-7A / %x30-39)) ) as slug\n \"-\"\n ( 1*%x30-39 *( \".\" 1*%x30-39 ) ) as version\n ) as publication_version\n }\n slug_inner = {\n ( 1*%x61-7A *(%x61-7A / %x30-39)\n *(\"-\" 1*%x61-7A *(%x61-7A / %x30-39)) ) as slug\n }\n publication_slug_or_version = publication_with_version / slug_inner\n publication = [\"Adobe Publication \"] publication_slug_or_version\n identifier = tech_note / bare_number / publication\n\n entry identifier: identifier\n\n test {\n accept \"Adobe TN 15\"\n accept \"ATN 30\"\n accept \"Adobe Technical Note #12\"\n accept \"pdf-reference-1.7\"\n accept \"Adobe Publication tiff-6.0\"\n accept \"Adobe Publication xfa-3.3\"\n accept \"adobe-japan1-7\"\n reject \"###\"\n }\n\n bindings identifier {\n # The builder dispatches on the wrapper keys and reads the leaves from\n # inside them (adobe/builder.rb build_tech_note / build_publication_version),\n # so the wrappers bind uncast — the nested hash the builder expects. The\n # scalar bindings carry the same leaves flat for typed consumers.\n tech_note -> tech_note (raw)\n tech_note_bare -> tech_note_bare (string)\n publication_version -> publication_version (raw)\n number -> number (string)\n slug -> slug (string)\n version -> version (string)\n }\n}\n","source_hash":"716ecf16e7525972b7a01fa986f4e6a81898080dbdf0a84e516447e729d8e7b4","unicode_tables":"onigmo (Ruby 3.4.8)","compiler_version":"1.5.1.0","edition":2,"semantics_hash":"sha256:77a3e453cf351ab679c4295ff10126a094b6c8d390f54f67703dc8cc7799c12b","checksum":"sha256:680933a1482ee9cf4875d20f36496986cf7b2f20f2c4ca5cf6ceff6f5a093328","validated":{"lint_errors":0,"lint_warnings":2,"tests_total":8,"tests_failures":0,"self_test":true}}
|