marc-ts 0.1.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/dist/index.js ADDED
@@ -0,0 +1,936 @@
1
+ import { n as p, t as S } from "./types-c4Mo9m9u.js";
2
+ var K = 27, v = "�", P = /* @__PURE__ */ new Map([
3
+ [33, "Ł"],
4
+ [34, "Ø"],
5
+ [35, "Đ"],
6
+ [36, "Þ"],
7
+ [37, "Æ"],
8
+ [38, "Œ"],
9
+ [39, "ʹ"],
10
+ [40, "·"],
11
+ [41, "♭"],
12
+ [42, "®"],
13
+ [43, "±"],
14
+ [44, "Ơ"],
15
+ [45, "Ư"],
16
+ [46, "ʼ"],
17
+ [48, "ʻ"],
18
+ [49, "ł"],
19
+ [50, "ø"],
20
+ [51, "đ"],
21
+ [52, "þ"],
22
+ [53, "æ"],
23
+ [54, "œ"],
24
+ [55, "ʺ"],
25
+ [56, "ı"],
26
+ [57, "£"],
27
+ [58, "ð"],
28
+ [59, "ơ"],
29
+ [60, "ư"],
30
+ [63, "°"]
31
+ ]), G = /* @__PURE__ */ new Map([
32
+ [96, "̉"],
33
+ [97, "̀"],
34
+ [98, "́"],
35
+ [99, "̂"],
36
+ [100, "̃"],
37
+ [101, "̄"],
38
+ [102, "̆"],
39
+ [103, "̇"],
40
+ [104, "̈"],
41
+ [105, "̌"],
42
+ [106, "̊"],
43
+ [107, "︠"],
44
+ [108, "︡"],
45
+ [109, "̕"],
46
+ [110, "̋"],
47
+ [111, "̐"],
48
+ [112, "̧"],
49
+ [113, "̨"],
50
+ [114, "̣"],
51
+ [115, "̤"],
52
+ [116, "̥"],
53
+ [117, "̳"],
54
+ [118, "̲"],
55
+ [119, "̦"],
56
+ [120, "̜"],
57
+ [121, "̮"],
58
+ [122, "︢"],
59
+ [123, "︣"],
60
+ [126, "̓"]
61
+ ]), V = new Map(Array.from(G.entries()).map(([e, t]) => [t, e + 128])), X = new Map(Array.from(P.entries()).map(([e, t]) => [t, e + 128])), Q = M(65, "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ", 97, "αβγδεζηθικλμνξοπρστυφχψω"), ee = M(96, "אבגדהוזחטיךכלםמןנסעףפץצקרשת"), te = M(65, "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ", 97, "абвгдежзийклмнопрстуфхцчшщъыьэюя"), ne = /* @__PURE__ */ new Map([
62
+ [33, "ء"],
63
+ [34, "آ"],
64
+ [35, "أ"],
65
+ [36, "ؤ"],
66
+ [37, "إ"],
67
+ [38, "ئ"],
68
+ [39, "ا"],
69
+ [40, "ب"],
70
+ [41, "ة"],
71
+ [42, "ت"],
72
+ [43, "ث"],
73
+ [44, "ج"],
74
+ [45, "ح"],
75
+ [46, "خ"],
76
+ [47, "د"],
77
+ [48, "ذ"],
78
+ [49, "ر"],
79
+ [50, "ز"],
80
+ [51, "س"],
81
+ [52, "ش"],
82
+ [53, "ص"],
83
+ [54, "ض"],
84
+ [55, "ط"],
85
+ [56, "ظ"],
86
+ [57, "ع"],
87
+ [58, "غ"],
88
+ [65, "ف"],
89
+ [66, "ق"],
90
+ [67, "ك"],
91
+ [68, "ل"],
92
+ [69, "م"],
93
+ [70, "ن"],
94
+ [71, "ه"],
95
+ [72, "و"],
96
+ [73, "ى"],
97
+ [74, "ي"]
98
+ ]), re = /* @__PURE__ */ new Map([
99
+ [40, "₍"],
100
+ [41, "₎"],
101
+ [43, "₊"],
102
+ [45, "₋"],
103
+ [48, "₀"],
104
+ [49, "₁"],
105
+ [50, "₂"],
106
+ [51, "₃"],
107
+ [52, "₄"],
108
+ [53, "₅"],
109
+ [54, "₆"],
110
+ [55, "₇"],
111
+ [56, "₈"],
112
+ [57, "₉"]
113
+ ]), ie = /* @__PURE__ */ new Map([
114
+ [40, "⁽"],
115
+ [41, "⁾"],
116
+ [43, "⁺"],
117
+ [45, "⁻"],
118
+ [48, "⁰"],
119
+ [49, "¹"],
120
+ [50, "²"],
121
+ [51, "³"],
122
+ [52, "⁴"],
123
+ [53, "⁵"],
124
+ [54, "⁶"],
125
+ [55, "⁷"],
126
+ [56, "⁸"],
127
+ [57, "⁹"],
128
+ [110, "ⁿ"]
129
+ ]), se = /* @__PURE__ */ new Map([
130
+ [2171169, "一"],
131
+ [2171170, "丁"],
132
+ [2171171, "七"],
133
+ [2171172, "万"],
134
+ [2171173, "丈"],
135
+ [2171174, "三"],
136
+ [2171175, "上"],
137
+ [2171176, "下"],
138
+ [2171177, "不"],
139
+ [2171178, "与"],
140
+ [2171179, "丐"],
141
+ [2171180, "丑"],
142
+ [2171181, "且"],
143
+ [2171182, "世"],
144
+ [2171183, "丘"],
145
+ [2171184, "丙"],
146
+ [2171185, "业"],
147
+ [2171186, "丛"],
148
+ [2171187, "东"],
149
+ [2171188, "丝"],
150
+ [2171189, "丞"],
151
+ [2171190, "丟"],
152
+ [2171191, "丠"],
153
+ [2171192, "両"],
154
+ [2171193, "丢"],
155
+ [2171194, "两"],
156
+ [2171195, "严"],
157
+ [2171196, "並"],
158
+ [2171197, "丧"],
159
+ [2171198, "丨"],
160
+ [2171199, "个"],
161
+ [2171200, "丫"],
162
+ [2171201, "中"],
163
+ [2171202, "丰"]
164
+ ]), oe = {
165
+ ascii: /* @__PURE__ */ new Map(),
166
+ ansel: ae(P, G),
167
+ greek: Q,
168
+ hebrew: ee,
169
+ cyrillic: te,
170
+ arabic: ne,
171
+ subscript: re,
172
+ superscript: ie
173
+ };
174
+ function M(...e) {
175
+ const t = /* @__PURE__ */ new Map();
176
+ for (let n = 0; n < e.length; n += 2) {
177
+ const r = e[n], i = e[n + 1];
178
+ Array.from(i).forEach((s, o) => t.set(r + o, s));
179
+ }
180
+ return t;
181
+ }
182
+ function ae(...e) {
183
+ const t = /* @__PURE__ */ new Map();
184
+ for (const n of e) for (const [r, i] of n) t.set(r, i);
185
+ return t;
186
+ }
187
+ function T(e) {
188
+ const t = e.codePointAt(0);
189
+ return t >= 768 && t <= 879 || t >= 65056 && t <= 65071;
190
+ }
191
+ function N(e, t) {
192
+ return t ? e - 128 : e;
193
+ }
194
+ function ce(e, t, n) {
195
+ const r = N(e, n);
196
+ return t === "ascii" ? r >= 32 && r <= 126 ? String.fromCharCode(r) : v : oe[t].get(r) ?? v;
197
+ }
198
+ function le(e, t, n) {
199
+ if (t + 2 >= e.length) return {
200
+ char: v,
201
+ next: e.length
202
+ };
203
+ const r = N(e[t], n), i = N(e[t + 1], n), s = N(e[t + 2], n), o = r << 16 | i << 8 | s;
204
+ return {
205
+ char: se.get(o) ?? v,
206
+ next: t + 3
207
+ };
208
+ }
209
+ function de(e, t, n) {
210
+ if (t + 1 >= e.length) return {
211
+ char: v,
212
+ next: e.length
213
+ };
214
+ const r = e[t + 1];
215
+ let i, s;
216
+ if (r === 40 || r === 44)
217
+ i = "g0", s = t + 2;
218
+ else if (r === 41 || r === 45)
219
+ i = "g1", s = t + 2;
220
+ else if (r === 36) {
221
+ const l = e[t + 2];
222
+ if (l === void 0) return {
223
+ char: v,
224
+ next: e.length
225
+ };
226
+ l === 40 || l === 44 ? (i = "g0", s = t + 3) : l === 41 || l === 45 ? (i = "g1", s = t + 3) : (i = "g0", s = t + 2);
227
+ } else return {
228
+ char: v,
229
+ next: t + 2
230
+ };
231
+ if (s >= e.length) return {
232
+ char: v,
233
+ next: e.length
234
+ };
235
+ let o = e[s];
236
+ if (o === 33) {
237
+ if (s++, s >= e.length) return {
238
+ char: v,
239
+ next: e.length
240
+ };
241
+ o = e[s];
242
+ }
243
+ const c = ue(o);
244
+ return c ? {
245
+ char: "",
246
+ next: fe(n, i, c, s + 1)
247
+ } : {
248
+ char: v,
249
+ next: s + 1
250
+ };
251
+ }
252
+ function fe(e, t, n, r) {
253
+ return e[t] = n, r;
254
+ }
255
+ function ue(e) {
256
+ switch (e) {
257
+ case 49:
258
+ return "eacc";
259
+ case 50:
260
+ return "hebrew";
261
+ case 51:
262
+ return "arabic";
263
+ case 52:
264
+ return "cyrillic";
265
+ case 66:
266
+ return "ascii";
267
+ case 69:
268
+ return "ansel";
269
+ case 78:
270
+ return "cyrillic";
271
+ case 81:
272
+ return "greek";
273
+ case 83:
274
+ return "greek";
275
+ case 98:
276
+ return "subscript";
277
+ case 112:
278
+ return "superscript";
279
+ default:
280
+ return;
281
+ }
282
+ }
283
+ function ge(e) {
284
+ const t = {
285
+ g0: "ascii",
286
+ g1: "ansel"
287
+ }, n = [];
288
+ let r = "", i = 0;
289
+ const s = (o) => {
290
+ if (o) {
291
+ if (T(o)) {
292
+ r += o;
293
+ return;
294
+ }
295
+ n.push(o + r), r = "";
296
+ }
297
+ };
298
+ for (; i < e.length; ) {
299
+ const o = e[i];
300
+ if (o === K) {
301
+ const d = de(e, i, t);
302
+ s(d.char), i = d.next;
303
+ continue;
304
+ }
305
+ if (o < 32) {
306
+ s(String.fromCharCode(o)), i++;
307
+ continue;
308
+ }
309
+ const c = o >= 160, l = c ? t.g1 : t.g0;
310
+ if (l === "eacc") {
311
+ const d = le(e, i, c);
312
+ s(d.char), i = d.next;
313
+ continue;
314
+ }
315
+ s(ce(o, l, c)), i++;
316
+ }
317
+ return r && n.push(r), n.join("");
318
+ }
319
+ function Te(e) {
320
+ return k(e).bytes;
321
+ }
322
+ function k(e) {
323
+ const t = e.normalize("NFD"), n = [];
324
+ let r = 0, i = 0;
325
+ for (; i < t.length; ) {
326
+ const s = t.codePointAt(i), o = t[i];
327
+ if (T(o)) {
328
+ n.push(63), r++, i++;
329
+ continue;
330
+ }
331
+ let c = i + (s > 65535 ? 2 : 1);
332
+ const l = [];
333
+ for (; c < t.length && T(t[c]); ) {
334
+ const d = V.get(t[c]);
335
+ d !== void 0 ? l.push(d) : (l.push(63), r++), c++;
336
+ }
337
+ if (n.push(...l), s < 128) n.push(s);
338
+ else {
339
+ const d = X.get(o);
340
+ d !== void 0 ? n.push(d) : (n.push(63), r++);
341
+ }
342
+ i = c;
343
+ }
344
+ return {
345
+ bytes: new Uint8Array(n),
346
+ lossyCount: r
347
+ };
348
+ }
349
+ var D = 31, W = 30, I = 24, C = 12, _ = 3, U = 4, R = new TextDecoder("utf-8", { fatal: !1 });
350
+ function H(e) {
351
+ return R.decode(e);
352
+ }
353
+ function J(e, t = 16) {
354
+ const n = e.slice(0, t), r = Array.from(n, (i) => i.toString(16).padStart(2, "0")).join(" ");
355
+ return e.length > t ? `${r} … (${e.length} bytes)` : r;
356
+ }
357
+ function he(e, t = {}) {
358
+ const n = t.strict ?? !1, r = t.maxWarnings ?? 100, i = [];
359
+ if (e.length < I + 1) {
360
+ const a = g("truncated_record", `Record too short: ${e.length} bytes`);
361
+ if (n) throw new Error(a.message);
362
+ return i.push(a), {
363
+ record: null,
364
+ warnings: i
365
+ };
366
+ }
367
+ const s = pe(e);
368
+ if (!we(s, i, n) && (n || i.length >= r))
369
+ return {
370
+ record: null,
371
+ warnings: i
372
+ };
373
+ const o = parseInt(s.substring(0, 5), 10);
374
+ if (isNaN(o) || o > e.length) {
375
+ const a = g("invalid_leader", `Invalid record length in leader: ${s.substring(0, 5)}`);
376
+ if (n) throw new Error(a.message);
377
+ i.push(a);
378
+ } else if (o < e.length) {
379
+ const a = g("truncated_record", `Buffer is longer than the record length declared in the leader: leader says ${o}, buffer is ${e.length} bytes. Trailing bytes ignored (likely a concatenated stream — split on 0x1D first).`);
380
+ if (n) throw new Error(a.message);
381
+ i.push(a), e = e.slice(0, o);
382
+ }
383
+ const c = parseInt(s.substring(12, 17), 10);
384
+ if (isNaN(c)) {
385
+ const a = g("invalid_leader", `Invalid base address in leader: ${s.substring(12, 17)}`);
386
+ if (n) throw new Error(a.message);
387
+ return i.push(a), {
388
+ record: null,
389
+ warnings: i
390
+ };
391
+ }
392
+ const l = I, d = e.indexOf(W, l);
393
+ if (d === -1) {
394
+ const a = g("invalid_directory", "Directory terminator not found");
395
+ if (n) throw new Error(a.message);
396
+ return i.push(a), {
397
+ record: null,
398
+ warnings: i
399
+ };
400
+ }
401
+ const u = Ee(e.slice(l, d), i, n, r);
402
+ if (u.length === 0) {
403
+ const a = g("invalid_directory", "No directory entries found");
404
+ if (n) throw new Error(a.message);
405
+ return i.push(a), {
406
+ record: null,
407
+ warnings: i
408
+ };
409
+ }
410
+ const f = s[9] === " ";
411
+ if (s[9] !== " " && s[9] !== "a") {
412
+ const a = g("invalid_leader", `Leader position 9 (encoding flag) is '${s[9]}'; expected 'a' (UTF-8) or ' ' (MARC-8). Defaulting to UTF-8.`);
413
+ if (n) throw new Error(a.message);
414
+ i.push(a);
415
+ }
416
+ return {
417
+ record: {
418
+ leader: s,
419
+ fields: me(e, u, c, f ? ge : (a) => R.decode(a), i, n, r)
420
+ },
421
+ warnings: i
422
+ };
423
+ }
424
+ function Me(e) {
425
+ const t = he(e, { strict: !0 });
426
+ if (!t.record) throw new Error("Failed to parse MARC record in strict mode");
427
+ return t.record;
428
+ }
429
+ function pe(e) {
430
+ const t = e.slice(0, I);
431
+ return R.decode(t);
432
+ }
433
+ function we(e, t, n) {
434
+ if (e.length !== I) {
435
+ const r = g("invalid_leader", `Leader length is ${e.length}, expected ${I}`);
436
+ if (n) throw new Error(r.message);
437
+ return t.push(r), !1;
438
+ }
439
+ if (e[10] !== "2") {
440
+ const r = g("invalid_leader", `Leader position 10 (indicator count) is '${e[10]}', expected '2'`);
441
+ t.push(r);
442
+ }
443
+ if (e[11] !== "2") {
444
+ const r = g("invalid_leader", `Leader position 11 (subfield code length) is '${e[11]}', expected '2'`);
445
+ t.push(r);
446
+ }
447
+ return !0;
448
+ }
449
+ function Ee(e, t, n, r) {
450
+ const i = [];
451
+ for (let s = 0; s < e.length; s += C) {
452
+ if (t.length >= r) {
453
+ t.push(g("truncated_record", `Directory parsing halted after reaching maxWarnings limit (${r}); remaining ${e.length - s} bytes of directory not parsed.`));
454
+ break;
455
+ }
456
+ if (s + C > e.length) break;
457
+ const o = e.slice(s, s + C), c = R.decode(o), l = c.substring(0, _), d = c.substring(_, _ + U), u = c.substring(_ + U, C), f = parseInt(d, 10), a = parseInt(u, 10);
458
+ if (isNaN(f) || isNaN(a)) {
459
+ const w = g("invalid_directory", `Invalid directory entry for tag ${l}: length=${d}, position=${u}`);
460
+ if (n) throw new Error(w.message);
461
+ t.push(w);
462
+ continue;
463
+ }
464
+ i.push({
465
+ tag: l,
466
+ fieldLength: f,
467
+ startingPosition: a
468
+ });
469
+ }
470
+ return i;
471
+ }
472
+ function me(e, t, n, r, i, s, o) {
473
+ const c = [];
474
+ for (const l of t) {
475
+ if (i.length >= o) {
476
+ i.push(g("truncated_record", `Field parsing halted after reaching maxWarnings limit (${o}); not all directory entries were processed.`, void 0, l.tag));
477
+ break;
478
+ }
479
+ const d = n + l.startingPosition, u = d + l.fieldLength - 1;
480
+ if (d >= e.length || u > e.length) {
481
+ const a = g("invalid_field", `Field ${l.tag} out of bounds: start=${d}, end=${u}, buffer length=${e.length}`, d, l.tag);
482
+ if (s) throw new Error(a.message);
483
+ i.push(a);
484
+ continue;
485
+ }
486
+ let f;
487
+ if (e[u] !== W) {
488
+ const a = g("invalid_field", `Field ${l.tag} does not end with a field terminator at byte ${u} (found 0x${(e[u] ?? 0).toString(16).padStart(2, "0")}); using the full declared length without stripping a terminator byte.`, d, l.tag);
489
+ if (s) throw new Error(a.message);
490
+ i.push(a), f = e.slice(d, d + l.fieldLength);
491
+ } else f = e.slice(d, u);
492
+ if (l.tag.startsWith("00")) {
493
+ try {
494
+ const a = r(f);
495
+ c.push({
496
+ tag: l.tag,
497
+ data: a
498
+ });
499
+ } catch (a) {
500
+ const w = g("encoding_error", `Failed to decode control field ${l.tag}: ${a instanceof Error ? a.message : String(a)}. Raw bytes (hex): ${J(f)}.`, d, l.tag);
501
+ if (s) throw new Error(w.message);
502
+ i.push(w), c.push({
503
+ tag: l.tag,
504
+ data: H(f)
505
+ });
506
+ }
507
+ continue;
508
+ }
509
+ if (f.length < 2) {
510
+ const a = g("invalid_field", `Data field ${l.tag} too short for indicators: ${f.length} bytes`, d, l.tag);
511
+ if (s) throw new Error(a.message);
512
+ i.push(a);
513
+ continue;
514
+ }
515
+ try {
516
+ const a = String.fromCharCode(f[0] ?? 0), w = String.fromCharCode(f[1] ?? 0), y = ve(f.slice(2), r, l.tag, i, s, o);
517
+ c.push({
518
+ tag: l.tag,
519
+ indicator1: a,
520
+ indicator2: w,
521
+ subfields: y
522
+ });
523
+ } catch (a) {
524
+ const w = g("invalid_field", `Failed to parse data field ${l.tag}: ${a instanceof Error ? a.message : String(a)}`, d, l.tag);
525
+ if (s) throw new Error(w.message);
526
+ i.push(w);
527
+ }
528
+ }
529
+ return c;
530
+ }
531
+ function ve(e, t, n, r, i, s) {
532
+ const o = [];
533
+ let c = 0;
534
+ for (; c < e.length; ) {
535
+ if (r.length >= s) {
536
+ r.push(g("truncated_record", `Subfield parsing halted after reaching maxWarnings limit (${s}) in field ${n}; not all subfields were processed.`, void 0, n));
537
+ break;
538
+ }
539
+ if (e[c] !== D) {
540
+ const f = g("invalid_field", `Expected subfield delimiter in field ${n} at position ${c}`, void 0, n);
541
+ if (i) throw new Error(f.message);
542
+ r.push(f);
543
+ break;
544
+ }
545
+ if (c++, c >= e.length) break;
546
+ const l = String.fromCharCode(e[c] ?? 0);
547
+ c++;
548
+ const d = c;
549
+ for (; c < e.length && e[c] !== D; ) c++;
550
+ const u = e.slice(d, c);
551
+ try {
552
+ const f = t(u);
553
+ o.push({
554
+ code: l,
555
+ value: f
556
+ });
557
+ } catch (f) {
558
+ const a = g("encoding_error", `Failed to decode subfield ${n}$${l}: ${f instanceof Error ? f.message : String(f)}. Raw bytes (hex): ${J(u)}.`, void 0, n);
559
+ if (i) throw new Error(a.message);
560
+ r.push(a), o.push({
561
+ code: l,
562
+ value: H(u)
563
+ });
564
+ }
565
+ }
566
+ return o;
567
+ }
568
+ function g(e, t, n, r) {
569
+ return {
570
+ type: e,
571
+ message: t,
572
+ position: n,
573
+ tag: r
574
+ };
575
+ }
576
+ function Se(e, t, n, r) {
577
+ return {
578
+ type: e,
579
+ message: t,
580
+ position: n,
581
+ tag: r
582
+ };
583
+ }
584
+ var be = 31, O = 30, $e = 29, F = 24, Ae = 3, Ie = 4, ye = 5;
585
+ function De(e, t = {}) {
586
+ return Ce(e, t).bytes;
587
+ }
588
+ function Ce(e, t = {}) {
589
+ _e(e);
590
+ const n = [], r = t.encoding === "marc8", i = new TextEncoder(), s = r ? (E, b) => {
591
+ const $ = k(E);
592
+ return $.lossyCount > 0 && n.push(Se("encoding_error", `MARC-8 encoding substituted ${$.lossyCount} character(s) with '?' because they have no MARC-8 equivalent.`, void 0, b)), $.bytes;
593
+ } : (E) => i.encode(E), o = [], c = [];
594
+ let l = 0;
595
+ for (const E of e.fields) {
596
+ const b = Ne(E, (Z) => s(Z, E.tag)), $ = b.length + 1, q = E.tag.padEnd(Ae, " ") + $.toString().padStart(Ie, "0") + l.toString().padStart(ye, "0");
597
+ o.push(q), c.push(b), c.push(new Uint8Array([O])), l += $;
598
+ }
599
+ const d = i.encode(o.join("")), u = new Uint8Array(d.length + 1);
600
+ u.set(d), u[d.length] = O;
601
+ const f = F + u.length, a = c.reduce((E, b) => E + b.length, 0), w = new Uint8Array(a);
602
+ let y = 0;
603
+ for (const E of c)
604
+ w.set(E, y), y += E.length;
605
+ const x = f + a + 1, Y = Fe(e.leader, x, f, r), A = new Uint8Array(x);
606
+ return A.set(i.encode(Y), 0), A.set(u, F), A.set(w, f), A[x - 1] = $e, {
607
+ bytes: A,
608
+ warnings: n
609
+ };
610
+ }
611
+ function L(e) {
612
+ const t = e.charCodeAt(0);
613
+ return t >= 32 && t <= 126;
614
+ }
615
+ function _e(e) {
616
+ for (const t of e.fields) {
617
+ if (typeof t.tag != "string" || t.tag.length !== 3) throw new Error(`MARC field tag must be exactly 3 characters; got ${JSON.stringify(t.tag)}`);
618
+ if (!S(t)) {
619
+ if (t.indicator1.length !== 1) throw new Error(`Field ${t.tag} indicator1 must be exactly 1 character; got ${JSON.stringify(t.indicator1)}`);
620
+ if (!L(t.indicator1)) throw new Error(`Field ${t.tag} indicator1 must be an ASCII printable character (U+0020–U+007E); got ${JSON.stringify(t.indicator1)}`);
621
+ if (t.indicator2.length !== 1) throw new Error(`Field ${t.tag} indicator2 must be exactly 1 character; got ${JSON.stringify(t.indicator2)}`);
622
+ if (!L(t.indicator2)) throw new Error(`Field ${t.tag} indicator2 must be an ASCII printable character (U+0020–U+007E); got ${JSON.stringify(t.indicator2)}`);
623
+ for (const n of t.subfields) {
624
+ if (n.code.length !== 1) throw new Error(`Field ${t.tag} subfield code must be exactly 1 character; got ${JSON.stringify(n.code)}`);
625
+ if (!L(n.code)) throw new Error(`Field ${t.tag} subfield code must be an ASCII printable character (U+0020–U+007E); got ${JSON.stringify(n.code)}`);
626
+ }
627
+ }
628
+ }
629
+ }
630
+ function Ne(e, t) {
631
+ if (S(e)) return t(e.data);
632
+ const n = [new Uint8Array([e.indicator1.charCodeAt(0), e.indicator2.charCodeAt(0)])];
633
+ for (const o of e.subfields) {
634
+ const c = new Uint8Array([be, o.code.charCodeAt(0)]);
635
+ n.push(c, t(o.value));
636
+ }
637
+ const r = n.reduce((o, c) => o + c.length, 0), i = new Uint8Array(r);
638
+ let s = 0;
639
+ for (const o of n)
640
+ i.set(o, s), s += o.length;
641
+ return i;
642
+ }
643
+ function Fe(e, t, n, r) {
644
+ let i = e.padEnd(F, " ").substring(0, F);
645
+ const s = t.toString().padStart(5, "0");
646
+ if (s.length > 5) throw new Error(`Record length ${t} exceeds maximum (99999)`);
647
+ i = s + i.substring(5);
648
+ const o = n.toString().padStart(5, "0");
649
+ if (o.length > 5) throw new Error(`Base address ${n} exceeds maximum (99999)`);
650
+ return i = i.substring(0, 12) + o + i.substring(17), i = i.substring(0, 9) + (r ? " " : "a") + i.substring(10), i;
651
+ }
652
+ function m(e, t) {
653
+ return e.fields.find((n) => n.tag === t);
654
+ }
655
+ function Ue(e, t) {
656
+ return e.fields.filter((n) => n.tag === t);
657
+ }
658
+ function h(e, t) {
659
+ return e.subfields.find((n) => n.code === t)?.value;
660
+ }
661
+ function Oe(e, t) {
662
+ return e.subfields.filter((n) => n.code === t).map((n) => n.value);
663
+ }
664
+ function Be(e) {
665
+ return e.subfields.map((t) => ({
666
+ code: t.code,
667
+ value: t.value
668
+ }));
669
+ }
670
+ function Pe(e) {
671
+ const t = m(e, "245");
672
+ if (!t || !p(t)) return;
673
+ const n = h(t, "a") ?? "", r = h(t, "b") ?? "";
674
+ return (n + " " + r).trim() || void 0;
675
+ }
676
+ function Ge(e) {
677
+ const t = m(e, "245");
678
+ if (!(!t || !p(t)))
679
+ return h(t, "a");
680
+ }
681
+ function ke(e) {
682
+ const t = m(e, "100");
683
+ if (t && p(t)) return h(t, "a");
684
+ const n = m(e, "110");
685
+ if (n && p(n)) return h(n, "a");
686
+ }
687
+ function We(e) {
688
+ const t = m(e, "250");
689
+ if (!(!t || !p(t)))
690
+ return h(t, "a");
691
+ }
692
+ function He(e) {
693
+ const t = m(e, "264");
694
+ if (t && p(t)) {
695
+ const r = h(t, "b");
696
+ if (r) return r;
697
+ }
698
+ const n = m(e, "260");
699
+ if (n && p(n)) return h(n, "b");
700
+ }
701
+ function Je(e) {
702
+ const t = m(e, "264");
703
+ if (t && p(t)) {
704
+ const r = h(t, "c");
705
+ if (r) return r;
706
+ }
707
+ const n = m(e, "260");
708
+ if (n && p(n)) return h(n, "c");
709
+ }
710
+ function je(e) {
711
+ const t = [];
712
+ for (const n of e.fields) if (n.tag === "020" && p(n)) {
713
+ const r = h(n, "a");
714
+ r && t.push(r);
715
+ }
716
+ return t;
717
+ }
718
+ function ze(e) {
719
+ const t = m(e, "022");
720
+ if (!(!t || !p(t)))
721
+ return h(t, "a");
722
+ }
723
+ function Ye(e) {
724
+ const t = m(e, "010");
725
+ if (!(!t || !p(t)))
726
+ return h(t, "a");
727
+ }
728
+ function qe(e) {
729
+ const t = [];
730
+ for (const n of e.fields) if (n.tag.startsWith("6") && p(n)) {
731
+ const r = h(n, "a");
732
+ r && t.push(r);
733
+ }
734
+ return t;
735
+ }
736
+ function Ze(e) {
737
+ const t = m(e, "490");
738
+ if (!(!t || !p(t)))
739
+ return h(t, "a");
740
+ }
741
+ function j(e, t) {
742
+ if (e.length !== 3 || t.length !== 3) return !1;
743
+ for (let n = 0; n < 3; n++) {
744
+ const r = t[n], i = e[n];
745
+ if (r === "." || r?.toUpperCase() === "X") {
746
+ if (i && !/\d/.test(i)) return !1;
747
+ continue;
748
+ }
749
+ if (r !== i) return !1;
750
+ }
751
+ return !0;
752
+ }
753
+ function Ke(e, t) {
754
+ return e.fields.filter((n) => j(n.tag, t));
755
+ }
756
+ function Ve(e, t) {
757
+ return e.fields.find((n) => j(n.tag, t));
758
+ }
759
+ function z(e, t) {
760
+ return {
761
+ ...e,
762
+ fields: [...e.fields, t]
763
+ };
764
+ }
765
+ function Xe(e, t, n) {
766
+ const r = e.fields.findIndex((s) => s.tag === t);
767
+ if (r === -1) return z(e, n);
768
+ const i = Array.from(e.fields);
769
+ return i.splice(r, 0, n), {
770
+ ...e,
771
+ fields: i
772
+ };
773
+ }
774
+ function Qe(e, t, n) {
775
+ const r = e.fields.findIndex((s) => s.tag === t);
776
+ if (r === -1) return z(e, n);
777
+ const i = Array.from(e.fields);
778
+ return i.splice(r + 1, 0, n), {
779
+ ...e,
780
+ fields: i
781
+ };
782
+ }
783
+ function et(e, t) {
784
+ const n = parseInt(t.tag, 10);
785
+ let r = e.fields.length;
786
+ for (let s = 0; s < e.fields.length; s++) {
787
+ const o = e.fields[s];
788
+ if (o && parseInt(o.tag, 10) > n) {
789
+ r = s;
790
+ break;
791
+ }
792
+ }
793
+ const i = Array.from(e.fields);
794
+ return i.splice(r, 0, t), {
795
+ ...e,
796
+ fields: i
797
+ };
798
+ }
799
+ function tt(e, t) {
800
+ return {
801
+ ...e,
802
+ fields: e.fields.filter((n) => n.tag !== t)
803
+ };
804
+ }
805
+ function nt(e, t) {
806
+ return {
807
+ ...e,
808
+ fields: e.fields.filter((n) => n !== t)
809
+ };
810
+ }
811
+ function Re(e, t, n) {
812
+ return {
813
+ ...e,
814
+ subfields: [...e.subfields, {
815
+ code: t,
816
+ value: n
817
+ }]
818
+ };
819
+ }
820
+ function rt(e, t) {
821
+ return {
822
+ ...e,
823
+ subfields: e.subfields.filter((n) => n.code !== t)
824
+ };
825
+ }
826
+ function it(e, t, n) {
827
+ const r = e.subfields.findIndex((s) => s.code === t);
828
+ if (r === -1) return Re(e, t, n);
829
+ const i = [...e.subfields];
830
+ return i[r] = {
831
+ code: t,
832
+ value: n
833
+ }, {
834
+ ...e,
835
+ subfields: i
836
+ };
837
+ }
838
+ function st(e) {
839
+ const t = new Array(e.fields.length);
840
+ for (let n = 0; n < e.fields.length; n++) {
841
+ const r = e.fields[n];
842
+ if (S(r)) t[n] = {
843
+ tag: r.tag,
844
+ data: r.data
845
+ };
846
+ else {
847
+ const i = new Array(r.subfields.length);
848
+ for (let s = 0; s < r.subfields.length; s++) {
849
+ const o = r.subfields[s];
850
+ i[s] = {
851
+ code: o.code,
852
+ value: o.value
853
+ };
854
+ }
855
+ t[n] = {
856
+ tag: r.tag,
857
+ indicator1: r.indicator1,
858
+ indicator2: r.indicator2,
859
+ subfields: i
860
+ };
861
+ }
862
+ }
863
+ return {
864
+ leader: e.leader,
865
+ fields: t
866
+ };
867
+ }
868
+ function ot(e, t, n = !1) {
869
+ if (e.leader !== t.leader || e.fields.length !== t.fields.length) return !1;
870
+ const r = n ? [...e.fields].sort(B) : e.fields, i = n ? [...t.fields].sort(B) : t.fields;
871
+ for (let s = 0; s < r.length; s++) {
872
+ const o = r[s], c = i[s];
873
+ if (!o || !c || !xe(o, c)) return !1;
874
+ }
875
+ return !0;
876
+ }
877
+ function xe(e, t) {
878
+ if (e.tag !== t.tag) return !1;
879
+ if (S(e) && S(t)) return e.data === t.data;
880
+ if (!S(e) && !S(t)) {
881
+ if (e.indicator1 !== t.indicator1 || e.indicator2 !== t.indicator2 || e.subfields.length !== t.subfields.length) return !1;
882
+ for (let n = 0; n < e.subfields.length; n++) {
883
+ const r = e.subfields[n], i = t.subfields[n];
884
+ if (!r || !i || r.code !== i.code || r.value !== i.value) return !1;
885
+ }
886
+ return !0;
887
+ }
888
+ return !1;
889
+ }
890
+ function B(e, t) {
891
+ return e.tag.localeCompare(t.tag);
892
+ }
893
+ export {
894
+ Re as addSubfield,
895
+ z as appendField,
896
+ ke as author,
897
+ st as cloneRecord,
898
+ Se as createWarning,
899
+ We as edition,
900
+ xe as fieldsEqual,
901
+ Be as getAllSubfields,
902
+ m as getField,
903
+ Ue as getFields,
904
+ Ke as getFieldsByPattern,
905
+ Ve as getFirstFieldByPattern,
906
+ h as getSubfield,
907
+ Oe as getSubfields,
908
+ Qe as insertFieldAfter,
909
+ Xe as insertFieldBefore,
910
+ et as insertGroupedField,
911
+ S as isControlField,
912
+ p as isDataField,
913
+ je as isbn,
914
+ ze as issn,
915
+ Ye as lccn,
916
+ ge as marc8ToUnicode,
917
+ he as parseMarcRecord,
918
+ Me as parseMarcRecordStrict,
919
+ Je as publicationDate,
920
+ He as publisher,
921
+ ot as recordsEqual,
922
+ nt as removeField,
923
+ tt as removeFields,
924
+ rt as removeSubfield,
925
+ it as replaceSubfield,
926
+ De as serializeMarcRecord,
927
+ Ce as serializeMarcRecordWithWarnings,
928
+ Ze as seriesStatement,
929
+ qe as subjects,
930
+ Pe as title,
931
+ Ge as titleProper,
932
+ Te as unicodeToMarc8,
933
+ k as unicodeToMarc8WithStats
934
+ };
935
+
936
+ //# sourceMappingURL=index.js.map