marc-ts 0.1.0 → 0.4.2
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 +118 -523
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +399 -358
- package/dist/index.js.map +1 -1
- package/dist/marcjson.cjs +1 -1
- package/dist/marcjson.cjs.map +1 -1
- package/dist/marcjson.d.ts +11 -6
- package/dist/marcjson.js +53 -44
- package/dist/marcjson.js.map +1 -1
- package/dist/marctxt.cjs +4 -4
- package/dist/marctxt.cjs.map +1 -1
- package/dist/marctxt.d.ts +0 -10
- package/dist/marctxt.js +44 -51
- package/dist/marctxt.js.map +1 -1
- package/dist/marcxml.cjs +6 -6
- package/dist/marcxml.cjs.map +1 -1
- package/dist/marcxml.d.ts +7 -11
- package/dist/marcxml.js +183 -129
- package/dist/marcxml.js.map +1 -1
- package/dist/parser.d.ts +15 -35
- package/dist/serializer.d.ts +16 -37
- package/dist/{types-c4Mo9m9u.js → types-BMKDHD1l.js} +1 -1
- package/dist/types-BMKDHD1l.js.map +1 -0
- package/dist/{types-CJcxHJff.cjs → types-CsOhH4OF.cjs} +1 -1
- package/dist/types-CsOhH4OF.cjs.map +1 -0
- package/dist/types.d.ts +23 -1
- package/dist/warnings-6yoB06xI.cjs +3 -0
- package/dist/warnings-6yoB06xI.cjs.map +1 -0
- package/dist/warnings-Bt6wvWFe.js +13 -0
- package/dist/warnings-Bt6wvWFe.js.map +1 -0
- package/dist/warnings.d.ts +1 -2
- package/package.json +2 -2
- package/dist/types-CJcxHJff.cjs.map +0 -1
- package/dist/types-c4Mo9m9u.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { n as p, t as S } from "./types-
|
|
2
|
-
|
|
1
|
+
import { n as p, t as S } from "./types-BMKDHD1l.js";
|
|
2
|
+
import { t as Q } from "./warnings-Bt6wvWFe.js";
|
|
3
|
+
var ee = 27, v = "�", W = /* @__PURE__ */ new Map([
|
|
3
4
|
[33, "Ł"],
|
|
4
5
|
[34, "Ø"],
|
|
5
6
|
[35, "Đ"],
|
|
@@ -58,7 +59,7 @@ var K = 27, v = "�", P = /* @__PURE__ */ new Map([
|
|
|
58
59
|
[122, "︢"],
|
|
59
60
|
[123, "︣"],
|
|
60
61
|
[126, "̓"]
|
|
61
|
-
]),
|
|
62
|
+
]), te = new Map(Array.from(G.entries()).map(([e, t]) => [t, e + 128])), ne = new Map(Array.from(W.entries()).map(([e, t]) => [t, e + 128])), re = T(65, "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ", 97, "αβγδεζηθικλμνξοπρστυφχψω"), ie = T(96, "אבגדהוזחטיךכלםמןנסעףפץצקרשת"), se = T(65, "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ", 97, "абвгдежзийклмнопрстуфхцчшщъыьэюя"), oe = /* @__PURE__ */ new Map([
|
|
62
63
|
[33, "ء"],
|
|
63
64
|
[34, "آ"],
|
|
64
65
|
[35, "أ"],
|
|
@@ -95,7 +96,7 @@ var K = 27, v = "�", P = /* @__PURE__ */ new Map([
|
|
|
95
96
|
[72, "و"],
|
|
96
97
|
[73, "ى"],
|
|
97
98
|
[74, "ي"]
|
|
98
|
-
]),
|
|
99
|
+
]), ae = /* @__PURE__ */ new Map([
|
|
99
100
|
[40, "₍"],
|
|
100
101
|
[41, "₎"],
|
|
101
102
|
[43, "₊"],
|
|
@@ -110,7 +111,7 @@ var K = 27, v = "�", P = /* @__PURE__ */ new Map([
|
|
|
110
111
|
[55, "₇"],
|
|
111
112
|
[56, "₈"],
|
|
112
113
|
[57, "₉"]
|
|
113
|
-
]),
|
|
114
|
+
]), ce = /* @__PURE__ */ new Map([
|
|
114
115
|
[40, "⁽"],
|
|
115
116
|
[41, "⁾"],
|
|
116
117
|
[43, "⁺"],
|
|
@@ -126,7 +127,7 @@ var K = 27, v = "�", P = /* @__PURE__ */ new Map([
|
|
|
126
127
|
[56, "⁸"],
|
|
127
128
|
[57, "⁹"],
|
|
128
129
|
[110, "ⁿ"]
|
|
129
|
-
]),
|
|
130
|
+
]), le = /* @__PURE__ */ new Map([
|
|
130
131
|
[2171169, "一"],
|
|
131
132
|
[2171170, "丁"],
|
|
132
133
|
[2171171, "七"],
|
|
@@ -161,69 +162,69 @@ var K = 27, v = "�", P = /* @__PURE__ */ new Map([
|
|
|
161
162
|
[2171200, "丫"],
|
|
162
163
|
[2171201, "中"],
|
|
163
164
|
[2171202, "丰"]
|
|
164
|
-
]),
|
|
165
|
+
]), de = {
|
|
165
166
|
ascii: /* @__PURE__ */ new Map(),
|
|
166
|
-
ansel:
|
|
167
|
-
greek:
|
|
168
|
-
hebrew:
|
|
169
|
-
cyrillic:
|
|
170
|
-
arabic:
|
|
171
|
-
subscript:
|
|
172
|
-
superscript:
|
|
167
|
+
ansel: fe(W, G),
|
|
168
|
+
greek: re,
|
|
169
|
+
hebrew: ie,
|
|
170
|
+
cyrillic: se,
|
|
171
|
+
arabic: oe,
|
|
172
|
+
subscript: ae,
|
|
173
|
+
superscript: ce
|
|
173
174
|
};
|
|
174
|
-
function
|
|
175
|
+
function T(...e) {
|
|
175
176
|
const t = /* @__PURE__ */ new Map();
|
|
176
177
|
for (let n = 0; n < e.length; n += 2) {
|
|
177
|
-
const
|
|
178
|
-
Array.from(
|
|
178
|
+
const i = e[n], r = e[n + 1];
|
|
179
|
+
Array.from(r).forEach((s, o) => t.set(i + o, s));
|
|
179
180
|
}
|
|
180
181
|
return t;
|
|
181
182
|
}
|
|
182
|
-
function
|
|
183
|
+
function fe(...e) {
|
|
183
184
|
const t = /* @__PURE__ */ new Map();
|
|
184
|
-
for (const n of e) for (const [
|
|
185
|
+
for (const n of e) for (const [i, r] of n) t.set(i, r);
|
|
185
186
|
return t;
|
|
186
187
|
}
|
|
187
|
-
function
|
|
188
|
+
function M(e) {
|
|
188
189
|
const t = e.codePointAt(0);
|
|
189
190
|
return t >= 768 && t <= 879 || t >= 65056 && t <= 65071;
|
|
190
191
|
}
|
|
191
|
-
function
|
|
192
|
+
function C(e, t) {
|
|
192
193
|
return t ? e - 128 : e;
|
|
193
194
|
}
|
|
194
|
-
function
|
|
195
|
-
const
|
|
196
|
-
return t === "ascii" ?
|
|
195
|
+
function ue(e, t, n) {
|
|
196
|
+
const i = C(e, n);
|
|
197
|
+
return t === "ascii" ? i >= 32 && i <= 126 ? String.fromCharCode(i) : v : de[t].get(i) ?? v;
|
|
197
198
|
}
|
|
198
|
-
function
|
|
199
|
+
function ge(e, t, n) {
|
|
199
200
|
if (t + 2 >= e.length) return {
|
|
200
201
|
char: v,
|
|
201
202
|
next: e.length
|
|
202
203
|
};
|
|
203
|
-
const
|
|
204
|
+
const i = C(e[t], n), r = C(e[t + 1], n), s = C(e[t + 2], n), o = i << 16 | r << 8 | s;
|
|
204
205
|
return {
|
|
205
|
-
char:
|
|
206
|
+
char: le.get(o) ?? v,
|
|
206
207
|
next: t + 3
|
|
207
208
|
};
|
|
208
209
|
}
|
|
209
|
-
function
|
|
210
|
+
function he(e, t, n) {
|
|
210
211
|
if (t + 1 >= e.length) return {
|
|
211
212
|
char: v,
|
|
212
213
|
next: e.length
|
|
213
214
|
};
|
|
214
|
-
const
|
|
215
|
-
let
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
else if (
|
|
219
|
-
|
|
220
|
-
else if (
|
|
215
|
+
const i = e[t + 1];
|
|
216
|
+
let r, s;
|
|
217
|
+
if (i === 40 || i === 44)
|
|
218
|
+
r = "g0", s = t + 2;
|
|
219
|
+
else if (i === 41 || i === 45)
|
|
220
|
+
r = "g1", s = t + 2;
|
|
221
|
+
else if (i === 36) {
|
|
221
222
|
const l = e[t + 2];
|
|
222
223
|
if (l === void 0) return {
|
|
223
224
|
char: v,
|
|
224
225
|
next: e.length
|
|
225
226
|
};
|
|
226
|
-
l === 40 || l === 44 ? (
|
|
227
|
+
l === 40 || l === 44 ? (r = "g0", s = t + 3) : l === 41 || l === 45 ? (r = "g1", s = t + 3) : (r = "g0", s = t + 2);
|
|
227
228
|
} else return {
|
|
228
229
|
char: v,
|
|
229
230
|
next: t + 2
|
|
@@ -240,19 +241,19 @@ function de(e, t, n) {
|
|
|
240
241
|
};
|
|
241
242
|
o = e[s];
|
|
242
243
|
}
|
|
243
|
-
const
|
|
244
|
-
return
|
|
244
|
+
const a = we(o);
|
|
245
|
+
return a ? {
|
|
245
246
|
char: "",
|
|
246
|
-
next:
|
|
247
|
+
next: pe(n, r, a, s + 1)
|
|
247
248
|
} : {
|
|
248
249
|
char: v,
|
|
249
250
|
next: s + 1
|
|
250
251
|
};
|
|
251
252
|
}
|
|
252
|
-
function
|
|
253
|
-
return e[t] = n,
|
|
253
|
+
function pe(e, t, n, i) {
|
|
254
|
+
return e[t] = n, i;
|
|
254
255
|
}
|
|
255
|
-
function
|
|
256
|
+
function we(e) {
|
|
256
257
|
switch (e) {
|
|
257
258
|
case 49:
|
|
258
259
|
return "eacc";
|
|
@@ -280,226 +281,252 @@ function ue(e) {
|
|
|
280
281
|
return;
|
|
281
282
|
}
|
|
282
283
|
}
|
|
283
|
-
function
|
|
284
|
+
function Ee(e) {
|
|
284
285
|
const t = {
|
|
285
286
|
g0: "ascii",
|
|
286
287
|
g1: "ansel"
|
|
287
288
|
}, n = [];
|
|
288
|
-
let
|
|
289
|
+
let i = "", r = 0;
|
|
289
290
|
const s = (o) => {
|
|
290
291
|
if (o) {
|
|
291
|
-
if (
|
|
292
|
-
|
|
292
|
+
if (M(o)) {
|
|
293
|
+
i += o;
|
|
293
294
|
return;
|
|
294
295
|
}
|
|
295
|
-
n.push(o +
|
|
296
|
+
n.push(o + i), i = "";
|
|
296
297
|
}
|
|
297
298
|
};
|
|
298
|
-
for (;
|
|
299
|
-
const o = e[
|
|
300
|
-
if (o ===
|
|
301
|
-
const d =
|
|
302
|
-
s(d.char),
|
|
299
|
+
for (; r < e.length; ) {
|
|
300
|
+
const o = e[r];
|
|
301
|
+
if (o === ee) {
|
|
302
|
+
const d = he(e, r, t);
|
|
303
|
+
s(d.char), r = d.next;
|
|
303
304
|
continue;
|
|
304
305
|
}
|
|
305
306
|
if (o < 32) {
|
|
306
|
-
s(String.fromCharCode(o)),
|
|
307
|
+
s(String.fromCharCode(o)), r++;
|
|
307
308
|
continue;
|
|
308
309
|
}
|
|
309
|
-
const
|
|
310
|
+
const a = o >= 160, l = a ? t.g1 : t.g0;
|
|
310
311
|
if (l === "eacc") {
|
|
311
|
-
const d =
|
|
312
|
-
s(d.char),
|
|
312
|
+
const d = ge(e, r, a);
|
|
313
|
+
s(d.char), r = d.next;
|
|
313
314
|
continue;
|
|
314
315
|
}
|
|
315
|
-
s(
|
|
316
|
+
s(ue(o, l, a)), r++;
|
|
316
317
|
}
|
|
317
|
-
return
|
|
318
|
+
return i && n.push(i), n.join("");
|
|
318
319
|
}
|
|
319
|
-
function
|
|
320
|
+
function Ue(e) {
|
|
320
321
|
return k(e).bytes;
|
|
321
322
|
}
|
|
322
323
|
function k(e) {
|
|
323
324
|
const t = e.normalize("NFD"), n = [];
|
|
324
|
-
let
|
|
325
|
-
for (;
|
|
326
|
-
const s = t.codePointAt(
|
|
327
|
-
if (
|
|
328
|
-
n.push(63),
|
|
325
|
+
let i = 0, r = 0;
|
|
326
|
+
for (; r < t.length; ) {
|
|
327
|
+
const s = t.codePointAt(r), o = t[r];
|
|
328
|
+
if (M(o)) {
|
|
329
|
+
n.push(63), i++, r++;
|
|
329
330
|
continue;
|
|
330
331
|
}
|
|
331
|
-
let
|
|
332
|
+
let a = r + (s > 65535 ? 2 : 1);
|
|
332
333
|
const l = [];
|
|
333
|
-
for (;
|
|
334
|
-
const d =
|
|
335
|
-
d !== void 0 ? l.push(d) : (l.push(63),
|
|
334
|
+
for (; a < t.length && M(t[a]); ) {
|
|
335
|
+
const d = te.get(t[a]);
|
|
336
|
+
d !== void 0 ? l.push(d) : (l.push(63), i++), a++;
|
|
336
337
|
}
|
|
337
338
|
if (n.push(...l), s < 128) n.push(s);
|
|
338
339
|
else {
|
|
339
|
-
const d =
|
|
340
|
-
d !== void 0 ? n.push(d) : (n.push(63),
|
|
340
|
+
const d = ne.get(o);
|
|
341
|
+
d !== void 0 ? n.push(d) : (n.push(63), i++);
|
|
341
342
|
}
|
|
342
|
-
|
|
343
|
+
r = a;
|
|
343
344
|
}
|
|
344
345
|
return {
|
|
345
346
|
bytes: new Uint8Array(n),
|
|
346
|
-
lossyCount:
|
|
347
|
+
lossyCount: i
|
|
347
348
|
};
|
|
348
349
|
}
|
|
349
|
-
var
|
|
350
|
+
var U = 31, z = 30, _ = 24, I = 12, B = 3, x = new TextDecoder("utf-8", { fatal: !1 });
|
|
350
351
|
function H(e) {
|
|
351
|
-
return
|
|
352
|
+
return x.decode(e);
|
|
352
353
|
}
|
|
353
354
|
function J(e, t = 16) {
|
|
354
|
-
const n = e.slice(0, t),
|
|
355
|
-
return e.length > t ? `${
|
|
356
|
-
}
|
|
357
|
-
function
|
|
358
|
-
const n = t.strict ?? !1,
|
|
359
|
-
if (e.length <
|
|
360
|
-
const
|
|
361
|
-
if (n) throw new Error(
|
|
362
|
-
return
|
|
355
|
+
const n = e.slice(0, t), i = Array.from(n, (r) => r.toString(16).padStart(2, "0")).join(" ");
|
|
356
|
+
return e.length > t ? `${i} … (${e.length} bytes)` : i;
|
|
357
|
+
}
|
|
358
|
+
function N(e, t = {}) {
|
|
359
|
+
const n = t.strict ?? !1, i = t.maxWarnings ?? 100, r = [];
|
|
360
|
+
if (e.length < 25) {
|
|
361
|
+
const c = u("truncated_record", `Record too short: ${e.length} bytes`);
|
|
362
|
+
if (n) throw new Error(c.message);
|
|
363
|
+
return r.push(c), {
|
|
363
364
|
record: null,
|
|
364
|
-
warnings:
|
|
365
|
+
warnings: r
|
|
365
366
|
};
|
|
366
367
|
}
|
|
367
|
-
const s =
|
|
368
|
-
if (!
|
|
368
|
+
const s = me(e);
|
|
369
|
+
if (!ve(s, r, n) && (n || r.length >= i))
|
|
369
370
|
return {
|
|
370
371
|
record: null,
|
|
371
|
-
warnings:
|
|
372
|
+
warnings: r
|
|
372
373
|
};
|
|
373
374
|
const o = parseInt(s.substring(0, 5), 10);
|
|
374
375
|
if (isNaN(o) || o > e.length) {
|
|
375
|
-
const
|
|
376
|
-
if (n) throw new Error(
|
|
377
|
-
|
|
376
|
+
const c = u("invalid_leader", `Invalid record length in leader: ${s.substring(0, 5)}`);
|
|
377
|
+
if (n) throw new Error(c.message);
|
|
378
|
+
r.push(c);
|
|
378
379
|
} else if (o < e.length) {
|
|
379
|
-
const
|
|
380
|
-
if (n) throw new Error(
|
|
381
|
-
|
|
382
|
-
}
|
|
383
|
-
const
|
|
384
|
-
if (isNaN(
|
|
385
|
-
const
|
|
386
|
-
if (n) throw new Error(
|
|
387
|
-
return
|
|
380
|
+
const c = u("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).`);
|
|
381
|
+
if (n) throw new Error(c.message);
|
|
382
|
+
r.push(c), e = e.slice(0, o);
|
|
383
|
+
}
|
|
384
|
+
const a = parseInt(s.substring(12, 17), 10);
|
|
385
|
+
if (isNaN(a)) {
|
|
386
|
+
const c = u("invalid_leader", `Invalid base address in leader: ${s.substring(12, 17)}`);
|
|
387
|
+
if (n) throw new Error(c.message);
|
|
388
|
+
return r.push(c), {
|
|
388
389
|
record: null,
|
|
389
|
-
warnings:
|
|
390
|
+
warnings: r
|
|
390
391
|
};
|
|
391
392
|
}
|
|
392
|
-
const l =
|
|
393
|
+
const l = _, d = e.indexOf(z, l);
|
|
393
394
|
if (d === -1) {
|
|
394
|
-
const
|
|
395
|
-
if (n) throw new Error(
|
|
396
|
-
return
|
|
395
|
+
const c = u("invalid_directory", "Directory terminator not found");
|
|
396
|
+
if (n) throw new Error(c.message);
|
|
397
|
+
return r.push(c), {
|
|
397
398
|
record: null,
|
|
398
|
-
warnings:
|
|
399
|
+
warnings: r
|
|
399
400
|
};
|
|
400
401
|
}
|
|
401
|
-
const
|
|
402
|
-
if (
|
|
403
|
-
const
|
|
404
|
-
if (n) throw new Error(
|
|
405
|
-
return
|
|
402
|
+
const g = Se(e.slice(l, d), r, n, i);
|
|
403
|
+
if (g.length === 0) {
|
|
404
|
+
const c = u("invalid_directory", "No directory entries found");
|
|
405
|
+
if (n) throw new Error(c.message);
|
|
406
|
+
return r.push(c), {
|
|
406
407
|
record: null,
|
|
407
|
-
warnings:
|
|
408
|
+
warnings: r
|
|
408
409
|
};
|
|
409
410
|
}
|
|
410
411
|
const f = s[9] === " ";
|
|
411
412
|
if (s[9] !== " " && s[9] !== "a") {
|
|
412
|
-
const
|
|
413
|
-
if (n) throw new Error(
|
|
414
|
-
|
|
413
|
+
const c = u("invalid_leader", `Leader position 9 (encoding flag) is '${s[9]}'; expected 'a' (UTF-8) or ' ' (MARC-8). Defaulting to UTF-8.`);
|
|
414
|
+
if (n) throw new Error(c.message);
|
|
415
|
+
r.push(c);
|
|
415
416
|
}
|
|
416
417
|
return {
|
|
417
418
|
record: {
|
|
418
419
|
leader: s,
|
|
419
|
-
fields:
|
|
420
|
+
fields: be(e, g, a, f ? Ee : (c) => x.decode(c), r, n, i)
|
|
420
421
|
},
|
|
421
|
-
warnings:
|
|
422
|
+
warnings: r
|
|
422
423
|
};
|
|
423
424
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
425
|
+
var j = 29;
|
|
426
|
+
function Be(e, t) {
|
|
427
|
+
const n = [];
|
|
428
|
+
let i = 0;
|
|
429
|
+
for (let r = 0; r < e.length; r++) if (e[r] === j) {
|
|
430
|
+
const s = e.slice(i, r + 1);
|
|
431
|
+
if (s.length > 0) {
|
|
432
|
+
const o = N(s, t);
|
|
433
|
+
o.record && n.push(o.record);
|
|
434
|
+
}
|
|
435
|
+
i = r + 1;
|
|
436
|
+
}
|
|
437
|
+
if (i < e.length) {
|
|
438
|
+
const r = N(e.slice(i), t);
|
|
439
|
+
r.record && n.push(r.record);
|
|
440
|
+
}
|
|
441
|
+
return n;
|
|
428
442
|
}
|
|
429
|
-
function
|
|
430
|
-
const
|
|
431
|
-
|
|
443
|
+
function Oe(e, t) {
|
|
444
|
+
const n = [];
|
|
445
|
+
let i = 0;
|
|
446
|
+
for (let r = 0; r < e.length; r++) if (e[r] === j) {
|
|
447
|
+
const s = e.slice(i, r + 1);
|
|
448
|
+
s.length > 0 && n.push(N(s, t)), i = r + 1;
|
|
449
|
+
}
|
|
450
|
+
if (i < e.length) {
|
|
451
|
+
const r = e.slice(i);
|
|
452
|
+
n.push(N(r, t));
|
|
453
|
+
}
|
|
454
|
+
return { results: n };
|
|
455
|
+
}
|
|
456
|
+
function me(e) {
|
|
457
|
+
const t = e.slice(0, _);
|
|
458
|
+
return x.decode(t);
|
|
432
459
|
}
|
|
433
|
-
function
|
|
434
|
-
if (e.length !==
|
|
435
|
-
const
|
|
436
|
-
if (n) throw new Error(
|
|
437
|
-
return t.push(
|
|
460
|
+
function ve(e, t, n) {
|
|
461
|
+
if (e.length !== _) {
|
|
462
|
+
const i = u("invalid_leader", `Leader length is ${e.length}, expected ${_}`);
|
|
463
|
+
if (n) throw new Error(i.message);
|
|
464
|
+
return t.push(i), !1;
|
|
438
465
|
}
|
|
439
466
|
if (e[10] !== "2") {
|
|
440
|
-
const
|
|
441
|
-
t.push(
|
|
467
|
+
const i = u("invalid_leader", `Leader position 10 (indicator count) is '${e[10]}', expected '2'`);
|
|
468
|
+
t.push(i);
|
|
442
469
|
}
|
|
443
470
|
if (e[11] !== "2") {
|
|
444
|
-
const
|
|
445
|
-
t.push(
|
|
471
|
+
const i = u("invalid_leader", `Leader position 11 (subfield code length) is '${e[11]}', expected '2'`);
|
|
472
|
+
t.push(i);
|
|
446
473
|
}
|
|
447
474
|
return !0;
|
|
448
475
|
}
|
|
449
|
-
function
|
|
450
|
-
const
|
|
451
|
-
for (let s = 0; s < e.length; s +=
|
|
452
|
-
if (t.length >=
|
|
453
|
-
t.push(
|
|
476
|
+
function Se(e, t, n, i) {
|
|
477
|
+
const r = [];
|
|
478
|
+
for (let s = 0; s < e.length; s += I) {
|
|
479
|
+
if (t.length >= i) {
|
|
480
|
+
t.push(u("truncated_record", `Directory parsing halted after reaching maxWarnings limit (${i}); remaining ${e.length - s} bytes of directory not parsed.`));
|
|
454
481
|
break;
|
|
455
482
|
}
|
|
456
|
-
if (s +
|
|
457
|
-
const o = e.slice(s, s +
|
|
458
|
-
if (isNaN(f) || isNaN(
|
|
459
|
-
const w =
|
|
483
|
+
if (s + I > e.length) break;
|
|
484
|
+
const o = e.slice(s, s + I), a = x.decode(o), l = a.substring(0, B), d = a.substring(B, 7), g = a.substring(7, I), f = parseInt(d, 10), c = parseInt(g, 10);
|
|
485
|
+
if (isNaN(f) || isNaN(c)) {
|
|
486
|
+
const w = u("invalid_directory", `Invalid directory entry for tag ${l}: length=${d}, position=${g}`);
|
|
460
487
|
if (n) throw new Error(w.message);
|
|
461
488
|
t.push(w);
|
|
462
489
|
continue;
|
|
463
490
|
}
|
|
464
|
-
|
|
491
|
+
r.push({
|
|
465
492
|
tag: l,
|
|
466
493
|
fieldLength: f,
|
|
467
|
-
startingPosition:
|
|
494
|
+
startingPosition: c
|
|
468
495
|
});
|
|
469
496
|
}
|
|
470
|
-
return
|
|
497
|
+
return r;
|
|
471
498
|
}
|
|
472
|
-
function
|
|
473
|
-
const
|
|
499
|
+
function be(e, t, n, i, r, s, o) {
|
|
500
|
+
const a = [];
|
|
474
501
|
for (const l of t) {
|
|
475
|
-
if (
|
|
476
|
-
|
|
502
|
+
if (r.length >= o) {
|
|
503
|
+
r.push(u("truncated_record", `Field parsing halted after reaching maxWarnings limit (${o}); not all directory entries were processed.`, void 0, l.tag));
|
|
477
504
|
break;
|
|
478
505
|
}
|
|
479
|
-
const d = n + l.startingPosition,
|
|
480
|
-
if (d >= e.length ||
|
|
481
|
-
const
|
|
482
|
-
if (s) throw new Error(
|
|
483
|
-
|
|
506
|
+
const d = n + l.startingPosition, g = d + l.fieldLength - 1;
|
|
507
|
+
if (d >= e.length || g > e.length) {
|
|
508
|
+
const c = u("invalid_field", `Field ${l.tag} out of bounds: start=${d}, end=${g}, buffer length=${e.length}`, d, l.tag);
|
|
509
|
+
if (s) throw new Error(c.message);
|
|
510
|
+
r.push(c);
|
|
484
511
|
continue;
|
|
485
512
|
}
|
|
486
513
|
let f;
|
|
487
|
-
if (e[
|
|
488
|
-
const
|
|
489
|
-
if (s) throw new Error(
|
|
490
|
-
|
|
491
|
-
} else f = e.slice(d,
|
|
514
|
+
if (e[g] !== z) {
|
|
515
|
+
const c = u("invalid_field", `Field ${l.tag} does not end with a field terminator at byte ${g} (found 0x${(e[g] ?? 0).toString(16).padStart(2, "0")}); using the full declared length without stripping a terminator byte.`, d, l.tag);
|
|
516
|
+
if (s) throw new Error(c.message);
|
|
517
|
+
r.push(c), f = e.slice(d, d + l.fieldLength);
|
|
518
|
+
} else f = e.slice(d, g);
|
|
492
519
|
if (l.tag.startsWith("00")) {
|
|
493
520
|
try {
|
|
494
|
-
const
|
|
495
|
-
|
|
521
|
+
const c = i(f);
|
|
522
|
+
a.push({
|
|
496
523
|
tag: l.tag,
|
|
497
|
-
data:
|
|
524
|
+
data: c
|
|
498
525
|
});
|
|
499
|
-
} catch (
|
|
500
|
-
const w =
|
|
526
|
+
} catch (c) {
|
|
527
|
+
const w = u("encoding_error", `Failed to decode control field ${l.tag}: ${c instanceof Error ? c.message : String(c)}. Raw bytes (hex): ${J(f)}.`, d, l.tag);
|
|
501
528
|
if (s) throw new Error(w.message);
|
|
502
|
-
|
|
529
|
+
r.push(w), a.push({
|
|
503
530
|
tag: l.tag,
|
|
504
531
|
data: H(f)
|
|
505
532
|
});
|
|
@@ -507,104 +534,96 @@ function me(e, t, n, r, i, s, o) {
|
|
|
507
534
|
continue;
|
|
508
535
|
}
|
|
509
536
|
if (f.length < 2) {
|
|
510
|
-
const
|
|
511
|
-
if (s) throw new Error(
|
|
512
|
-
|
|
537
|
+
const c = u("invalid_field", `Data field ${l.tag} too short for indicators: ${f.length} bytes`, d, l.tag);
|
|
538
|
+
if (s) throw new Error(c.message);
|
|
539
|
+
r.push(c);
|
|
513
540
|
continue;
|
|
514
541
|
}
|
|
515
542
|
try {
|
|
516
|
-
const
|
|
517
|
-
|
|
543
|
+
const c = String.fromCharCode(f[0] ?? 0), w = String.fromCharCode(f[1] ?? 0), A = ye(f.slice(2), i, l.tag, r, s, o);
|
|
544
|
+
a.push({
|
|
518
545
|
tag: l.tag,
|
|
519
|
-
indicator1:
|
|
546
|
+
indicator1: c,
|
|
520
547
|
indicator2: w,
|
|
521
|
-
subfields:
|
|
548
|
+
subfields: A
|
|
522
549
|
});
|
|
523
|
-
} catch (
|
|
524
|
-
const w =
|
|
550
|
+
} catch (c) {
|
|
551
|
+
const w = u("invalid_field", `Failed to parse data field ${l.tag}: ${c instanceof Error ? c.message : String(c)}`, d, l.tag);
|
|
525
552
|
if (s) throw new Error(w.message);
|
|
526
|
-
|
|
553
|
+
r.push(w);
|
|
527
554
|
}
|
|
528
555
|
}
|
|
529
|
-
return
|
|
556
|
+
return a;
|
|
530
557
|
}
|
|
531
|
-
function
|
|
558
|
+
function ye(e, t, n, i, r, s) {
|
|
532
559
|
const o = [];
|
|
533
|
-
let
|
|
534
|
-
for (;
|
|
535
|
-
if (
|
|
536
|
-
|
|
560
|
+
let a = 0;
|
|
561
|
+
for (; a < e.length; ) {
|
|
562
|
+
if (i.length >= s) {
|
|
563
|
+
i.push(u("truncated_record", `Subfield parsing halted after reaching maxWarnings limit (${s}) in field ${n}; not all subfields were processed.`, void 0, n));
|
|
537
564
|
break;
|
|
538
565
|
}
|
|
539
|
-
if (e[
|
|
540
|
-
const f =
|
|
541
|
-
if (
|
|
542
|
-
|
|
566
|
+
if (e[a] !== U) {
|
|
567
|
+
const f = u("invalid_field", `Expected subfield delimiter in field ${n} at position ${a}`, void 0, n);
|
|
568
|
+
if (r) throw new Error(f.message);
|
|
569
|
+
i.push(f);
|
|
543
570
|
break;
|
|
544
571
|
}
|
|
545
|
-
if (
|
|
546
|
-
const l = String.fromCharCode(e[
|
|
547
|
-
|
|
548
|
-
const d =
|
|
549
|
-
for (;
|
|
550
|
-
const
|
|
572
|
+
if (a++, a >= e.length) break;
|
|
573
|
+
const l = String.fromCharCode(e[a] ?? 0);
|
|
574
|
+
a++;
|
|
575
|
+
const d = a;
|
|
576
|
+
for (; a < e.length && e[a] !== U; ) a++;
|
|
577
|
+
const g = e.slice(d, a);
|
|
551
578
|
try {
|
|
552
|
-
const f = t(
|
|
579
|
+
const f = t(g);
|
|
553
580
|
o.push({
|
|
554
581
|
code: l,
|
|
555
582
|
value: f
|
|
556
583
|
});
|
|
557
584
|
} catch (f) {
|
|
558
|
-
const
|
|
559
|
-
if (
|
|
560
|
-
|
|
585
|
+
const c = u("encoding_error", `Failed to decode subfield ${n}$${l}: ${f instanceof Error ? f.message : String(f)}. Raw bytes (hex): ${J(g)}.`, void 0, n);
|
|
586
|
+
if (r) throw new Error(c.message);
|
|
587
|
+
i.push(c), o.push({
|
|
561
588
|
code: l,
|
|
562
|
-
value: H(
|
|
589
|
+
value: H(g)
|
|
563
590
|
});
|
|
564
591
|
}
|
|
565
592
|
}
|
|
566
593
|
return o;
|
|
567
594
|
}
|
|
568
|
-
function
|
|
569
|
-
return {
|
|
570
|
-
type: e,
|
|
571
|
-
message: t,
|
|
572
|
-
position: n,
|
|
573
|
-
tag: r
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
function Se(e, t, n, r) {
|
|
595
|
+
function u(e, t, n, i) {
|
|
577
596
|
return {
|
|
578
597
|
type: e,
|
|
579
598
|
message: t,
|
|
580
599
|
position: n,
|
|
581
|
-
tag:
|
|
600
|
+
tag: i
|
|
582
601
|
};
|
|
583
602
|
}
|
|
584
|
-
var
|
|
585
|
-
function
|
|
586
|
-
return
|
|
587
|
-
}
|
|
588
|
-
function
|
|
589
|
-
|
|
590
|
-
const n = [], r = t.encoding === "marc8",
|
|
591
|
-
const
|
|
592
|
-
return
|
|
593
|
-
} : (E) =>
|
|
594
|
-
let
|
|
603
|
+
var $e = 31, O = 30, Ae = 29, R = 24, Ie = 3, Ce = 4, _e = 5;
|
|
604
|
+
function Ne(e, t = {}) {
|
|
605
|
+
return Y(e, t).bytes;
|
|
606
|
+
}
|
|
607
|
+
function Y(e, t = {}) {
|
|
608
|
+
Re(e);
|
|
609
|
+
const n = [], i = t.maxWarnings ?? 100, r = t.encoding === "marc8", s = new TextEncoder(), o = r ? (E, b) => {
|
|
610
|
+
const y = k(E);
|
|
611
|
+
return y.lossyCount > 0 && n.length < i && n.push(Q("encoding_error", `MARC-8 encoding substituted ${y.lossyCount} character(s) with '?' because they have no MARC-8 equivalent.`, void 0, b)), y.bytes;
|
|
612
|
+
} : (E) => s.encode(E), a = [], l = [];
|
|
613
|
+
let d = 0;
|
|
595
614
|
for (const E of e.fields) {
|
|
596
|
-
const b =
|
|
597
|
-
|
|
598
|
-
}
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
const
|
|
602
|
-
let
|
|
603
|
-
for (const E of
|
|
604
|
-
|
|
605
|
-
const
|
|
606
|
-
return
|
|
607
|
-
bytes:
|
|
615
|
+
const b = xe(E, (X) => o(X, E.tag)), y = b.length + 1, V = E.tag.padEnd(Ie, " ") + y.toString().padStart(Ce, "0") + d.toString().padStart(_e, "0");
|
|
616
|
+
a.push(V), l.push(b), l.push(new Uint8Array([O])), d += y;
|
|
617
|
+
}
|
|
618
|
+
const g = s.encode(a.join("")), f = new Uint8Array(g.length + 1);
|
|
619
|
+
f.set(g), f[g.length] = O;
|
|
620
|
+
const c = R + f.length, w = l.reduce((E, b) => E + b.length, 0), A = new Uint8Array(w);
|
|
621
|
+
let D = 0;
|
|
622
|
+
for (const E of l)
|
|
623
|
+
A.set(E, D), D += E.length;
|
|
624
|
+
const F = c + w + 1, K = Fe(e.leader, F, c, r), $ = new Uint8Array(F);
|
|
625
|
+
return $.set(s.encode(K), 0), $.set(f, R), $.set(A, c), $[F - 1] = Ae, {
|
|
626
|
+
bytes: $,
|
|
608
627
|
warnings: n
|
|
609
628
|
};
|
|
610
629
|
}
|
|
@@ -612,7 +631,7 @@ function L(e) {
|
|
|
612
631
|
const t = e.charCodeAt(0);
|
|
613
632
|
return t >= 32 && t <= 126;
|
|
614
633
|
}
|
|
615
|
-
function
|
|
634
|
+
function Re(e) {
|
|
616
635
|
for (const t of e.fields) {
|
|
617
636
|
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
637
|
if (!S(t)) {
|
|
@@ -627,188 +646,210 @@ function _e(e) {
|
|
|
627
646
|
}
|
|
628
647
|
}
|
|
629
648
|
}
|
|
630
|
-
function
|
|
649
|
+
function xe(e, t) {
|
|
631
650
|
if (S(e)) return t(e.data);
|
|
632
651
|
const n = [new Uint8Array([e.indicator1.charCodeAt(0), e.indicator2.charCodeAt(0)])];
|
|
633
652
|
for (const o of e.subfields) {
|
|
634
|
-
const
|
|
635
|
-
n.push(
|
|
653
|
+
const a = new Uint8Array([$e, o.code.charCodeAt(0)]);
|
|
654
|
+
n.push(a, t(o.value));
|
|
636
655
|
}
|
|
637
|
-
const
|
|
656
|
+
const i = n.reduce((o, a) => o + a.length, 0), r = new Uint8Array(i);
|
|
638
657
|
let s = 0;
|
|
639
658
|
for (const o of n)
|
|
640
|
-
|
|
641
|
-
return
|
|
659
|
+
r.set(o, s), s += o.length;
|
|
660
|
+
return r;
|
|
642
661
|
}
|
|
643
|
-
function Fe(e, t, n,
|
|
644
|
-
let
|
|
662
|
+
function Fe(e, t, n, i) {
|
|
663
|
+
let r = e.padEnd(R, " ").substring(0, R);
|
|
645
664
|
const s = t.toString().padStart(5, "0");
|
|
646
665
|
if (s.length > 5) throw new Error(`Record length ${t} exceeds maximum (99999)`);
|
|
647
|
-
|
|
666
|
+
r = s + r.substring(5);
|
|
648
667
|
const o = n.toString().padStart(5, "0");
|
|
649
668
|
if (o.length > 5) throw new Error(`Base address ${n} exceeds maximum (99999)`);
|
|
650
|
-
return
|
|
669
|
+
return r = r.substring(0, 12) + o + r.substring(17), r = r.substring(0, 9) + (i ? " " : "a") + r.substring(10), r;
|
|
670
|
+
}
|
|
671
|
+
function Pe(e, t = {}) {
|
|
672
|
+
const n = e.map((o) => Ne(o, t)), i = n.reduce((o, a) => o + a.length, 0), r = new Uint8Array(i);
|
|
673
|
+
let s = 0;
|
|
674
|
+
for (const o of n)
|
|
675
|
+
r.set(o, s), s += o.length;
|
|
676
|
+
return r;
|
|
677
|
+
}
|
|
678
|
+
function We(e, t = {}) {
|
|
679
|
+
const n = [], i = [];
|
|
680
|
+
for (const a of e) {
|
|
681
|
+
const l = Y(a, t);
|
|
682
|
+
n.push(l), i.push(l.bytes);
|
|
683
|
+
}
|
|
684
|
+
const r = i.reduce((a, l) => a + l.length, 0), s = new Uint8Array(r);
|
|
685
|
+
let o = 0;
|
|
686
|
+
for (const a of i)
|
|
687
|
+
s.set(a, o), o += a.length;
|
|
688
|
+
return {
|
|
689
|
+
bytes: s,
|
|
690
|
+
results: n
|
|
691
|
+
};
|
|
651
692
|
}
|
|
652
693
|
function m(e, t) {
|
|
653
694
|
return e.fields.find((n) => n.tag === t);
|
|
654
695
|
}
|
|
655
|
-
function
|
|
696
|
+
function Ge(e, t) {
|
|
656
697
|
return e.fields.filter((n) => n.tag === t);
|
|
657
698
|
}
|
|
658
699
|
function h(e, t) {
|
|
659
700
|
return e.subfields.find((n) => n.code === t)?.value;
|
|
660
701
|
}
|
|
661
|
-
function
|
|
702
|
+
function ke(e, t) {
|
|
662
703
|
return e.subfields.filter((n) => n.code === t).map((n) => n.value);
|
|
663
704
|
}
|
|
664
|
-
function
|
|
705
|
+
function ze(e) {
|
|
665
706
|
return e.subfields.map((t) => ({
|
|
666
707
|
code: t.code,
|
|
667
708
|
value: t.value
|
|
668
709
|
}));
|
|
669
710
|
}
|
|
670
|
-
function
|
|
711
|
+
function He(e) {
|
|
671
712
|
const t = m(e, "245");
|
|
672
713
|
if (!t || !p(t)) return;
|
|
673
|
-
const n = h(t, "a") ?? "",
|
|
674
|
-
return (n + " " +
|
|
714
|
+
const n = h(t, "a") ?? "", i = h(t, "b") ?? "";
|
|
715
|
+
return (n + " " + i).trim() || void 0;
|
|
675
716
|
}
|
|
676
|
-
function
|
|
717
|
+
function Je(e) {
|
|
677
718
|
const t = m(e, "245");
|
|
678
719
|
if (!(!t || !p(t)))
|
|
679
720
|
return h(t, "a");
|
|
680
721
|
}
|
|
681
|
-
function
|
|
722
|
+
function je(e) {
|
|
682
723
|
const t = m(e, "100");
|
|
683
724
|
if (t && p(t)) return h(t, "a");
|
|
684
725
|
const n = m(e, "110");
|
|
685
726
|
if (n && p(n)) return h(n, "a");
|
|
686
727
|
}
|
|
687
|
-
function
|
|
728
|
+
function Ye(e) {
|
|
688
729
|
const t = m(e, "250");
|
|
689
730
|
if (!(!t || !p(t)))
|
|
690
731
|
return h(t, "a");
|
|
691
732
|
}
|
|
692
|
-
function
|
|
733
|
+
function qe(e) {
|
|
693
734
|
const t = m(e, "264");
|
|
694
735
|
if (t && p(t)) {
|
|
695
|
-
const
|
|
696
|
-
if (
|
|
736
|
+
const i = h(t, "b");
|
|
737
|
+
if (i) return i;
|
|
697
738
|
}
|
|
698
739
|
const n = m(e, "260");
|
|
699
740
|
if (n && p(n)) return h(n, "b");
|
|
700
741
|
}
|
|
701
|
-
function
|
|
742
|
+
function Ze(e) {
|
|
702
743
|
const t = m(e, "264");
|
|
703
744
|
if (t && p(t)) {
|
|
704
|
-
const
|
|
705
|
-
if (
|
|
745
|
+
const i = h(t, "c");
|
|
746
|
+
if (i) return i;
|
|
706
747
|
}
|
|
707
748
|
const n = m(e, "260");
|
|
708
749
|
if (n && p(n)) return h(n, "c");
|
|
709
750
|
}
|
|
710
|
-
function
|
|
751
|
+
function Ke(e) {
|
|
711
752
|
const t = [];
|
|
712
753
|
for (const n of e.fields) if (n.tag === "020" && p(n)) {
|
|
713
|
-
const
|
|
714
|
-
|
|
754
|
+
const i = h(n, "a");
|
|
755
|
+
i && t.push(i);
|
|
715
756
|
}
|
|
716
757
|
return t;
|
|
717
758
|
}
|
|
718
|
-
function
|
|
759
|
+
function Ve(e) {
|
|
719
760
|
const t = m(e, "022");
|
|
720
761
|
if (!(!t || !p(t)))
|
|
721
762
|
return h(t, "a");
|
|
722
763
|
}
|
|
723
|
-
function
|
|
764
|
+
function Xe(e) {
|
|
724
765
|
const t = m(e, "010");
|
|
725
766
|
if (!(!t || !p(t)))
|
|
726
767
|
return h(t, "a");
|
|
727
768
|
}
|
|
728
|
-
function
|
|
769
|
+
function Qe(e) {
|
|
729
770
|
const t = [];
|
|
730
771
|
for (const n of e.fields) if (n.tag.startsWith("6") && p(n)) {
|
|
731
|
-
const
|
|
732
|
-
|
|
772
|
+
const i = h(n, "a");
|
|
773
|
+
i && t.push(i);
|
|
733
774
|
}
|
|
734
775
|
return t;
|
|
735
776
|
}
|
|
736
|
-
function
|
|
777
|
+
function et(e) {
|
|
737
778
|
const t = m(e, "490");
|
|
738
779
|
if (!(!t || !p(t)))
|
|
739
780
|
return h(t, "a");
|
|
740
781
|
}
|
|
741
|
-
function
|
|
782
|
+
function q(e, t) {
|
|
742
783
|
if (e.length !== 3 || t.length !== 3) return !1;
|
|
743
784
|
for (let n = 0; n < 3; n++) {
|
|
744
|
-
const
|
|
745
|
-
if (
|
|
746
|
-
if (
|
|
785
|
+
const i = t[n], r = e[n];
|
|
786
|
+
if (i === "." || i?.toUpperCase() === "X") {
|
|
787
|
+
if (r && !/\d/.test(r)) return !1;
|
|
747
788
|
continue;
|
|
748
789
|
}
|
|
749
|
-
if (
|
|
790
|
+
if (i !== r) return !1;
|
|
750
791
|
}
|
|
751
792
|
return !0;
|
|
752
793
|
}
|
|
753
|
-
function
|
|
754
|
-
return e.fields.filter((n) =>
|
|
794
|
+
function tt(e, t) {
|
|
795
|
+
return e.fields.filter((n) => q(n.tag, t));
|
|
755
796
|
}
|
|
756
|
-
function
|
|
757
|
-
return e.fields.find((n) =>
|
|
797
|
+
function nt(e, t) {
|
|
798
|
+
return e.fields.find((n) => q(n.tag, t));
|
|
758
799
|
}
|
|
759
|
-
function
|
|
800
|
+
function Z(e, t) {
|
|
760
801
|
return {
|
|
761
802
|
...e,
|
|
762
803
|
fields: [...e.fields, t]
|
|
763
804
|
};
|
|
764
805
|
}
|
|
765
|
-
function
|
|
766
|
-
const
|
|
767
|
-
if (
|
|
768
|
-
const
|
|
769
|
-
return
|
|
806
|
+
function rt(e, t, n) {
|
|
807
|
+
const i = e.fields.findIndex((s) => s.tag === t);
|
|
808
|
+
if (i === -1) return Z(e, n);
|
|
809
|
+
const r = Array.from(e.fields);
|
|
810
|
+
return r.splice(i, 0, n), {
|
|
770
811
|
...e,
|
|
771
|
-
fields:
|
|
812
|
+
fields: r
|
|
772
813
|
};
|
|
773
814
|
}
|
|
774
|
-
function
|
|
775
|
-
const
|
|
776
|
-
if (
|
|
777
|
-
const
|
|
778
|
-
return
|
|
815
|
+
function it(e, t, n) {
|
|
816
|
+
const i = e.fields.findIndex((s) => s.tag === t);
|
|
817
|
+
if (i === -1) return Z(e, n);
|
|
818
|
+
const r = Array.from(e.fields);
|
|
819
|
+
return r.splice(i + 1, 0, n), {
|
|
779
820
|
...e,
|
|
780
|
-
fields:
|
|
821
|
+
fields: r
|
|
781
822
|
};
|
|
782
823
|
}
|
|
783
|
-
function
|
|
824
|
+
function st(e, t) {
|
|
784
825
|
const n = parseInt(t.tag, 10);
|
|
785
|
-
let
|
|
826
|
+
let i = e.fields.length;
|
|
786
827
|
for (let s = 0; s < e.fields.length; s++) {
|
|
787
828
|
const o = e.fields[s];
|
|
788
829
|
if (o && parseInt(o.tag, 10) > n) {
|
|
789
|
-
|
|
830
|
+
i = s;
|
|
790
831
|
break;
|
|
791
832
|
}
|
|
792
833
|
}
|
|
793
|
-
const
|
|
794
|
-
return
|
|
834
|
+
const r = Array.from(e.fields);
|
|
835
|
+
return r.splice(i, 0, t), {
|
|
795
836
|
...e,
|
|
796
|
-
fields:
|
|
837
|
+
fields: r
|
|
797
838
|
};
|
|
798
839
|
}
|
|
799
|
-
function
|
|
840
|
+
function ot(e, t) {
|
|
800
841
|
return {
|
|
801
842
|
...e,
|
|
802
843
|
fields: e.fields.filter((n) => n.tag !== t)
|
|
803
844
|
};
|
|
804
845
|
}
|
|
805
|
-
function
|
|
846
|
+
function at(e, t) {
|
|
806
847
|
return {
|
|
807
848
|
...e,
|
|
808
849
|
fields: e.fields.filter((n) => n !== t)
|
|
809
850
|
};
|
|
810
851
|
}
|
|
811
|
-
function
|
|
852
|
+
function Le(e, t, n) {
|
|
812
853
|
return {
|
|
813
854
|
...e,
|
|
814
855
|
subfields: [...e.subfields, {
|
|
@@ -817,46 +858,46 @@ function Re(e, t, n) {
|
|
|
817
858
|
}]
|
|
818
859
|
};
|
|
819
860
|
}
|
|
820
|
-
function
|
|
861
|
+
function ct(e, t) {
|
|
821
862
|
return {
|
|
822
863
|
...e,
|
|
823
864
|
subfields: e.subfields.filter((n) => n.code !== t)
|
|
824
865
|
};
|
|
825
866
|
}
|
|
826
|
-
function
|
|
827
|
-
const
|
|
828
|
-
if (
|
|
829
|
-
const
|
|
830
|
-
return i
|
|
867
|
+
function lt(e, t, n) {
|
|
868
|
+
const i = e.subfields.findIndex((s) => s.code === t);
|
|
869
|
+
if (i === -1) return Le(e, t, n);
|
|
870
|
+
const r = [...e.subfields];
|
|
871
|
+
return r[i] = {
|
|
831
872
|
code: t,
|
|
832
873
|
value: n
|
|
833
874
|
}, {
|
|
834
875
|
...e,
|
|
835
|
-
subfields:
|
|
876
|
+
subfields: r
|
|
836
877
|
};
|
|
837
878
|
}
|
|
838
|
-
function
|
|
879
|
+
function dt(e) {
|
|
839
880
|
const t = new Array(e.fields.length);
|
|
840
881
|
for (let n = 0; n < e.fields.length; n++) {
|
|
841
|
-
const
|
|
842
|
-
if (S(
|
|
843
|
-
tag:
|
|
844
|
-
data:
|
|
882
|
+
const i = e.fields[n];
|
|
883
|
+
if (S(i)) t[n] = {
|
|
884
|
+
tag: i.tag,
|
|
885
|
+
data: i.data
|
|
845
886
|
};
|
|
846
887
|
else {
|
|
847
|
-
const
|
|
848
|
-
for (let s = 0; s <
|
|
849
|
-
const o =
|
|
850
|
-
|
|
888
|
+
const r = new Array(i.subfields.length);
|
|
889
|
+
for (let s = 0; s < i.subfields.length; s++) {
|
|
890
|
+
const o = i.subfields[s];
|
|
891
|
+
r[s] = {
|
|
851
892
|
code: o.code,
|
|
852
893
|
value: o.value
|
|
853
894
|
};
|
|
854
895
|
}
|
|
855
896
|
t[n] = {
|
|
856
|
-
tag:
|
|
857
|
-
indicator1:
|
|
858
|
-
indicator2:
|
|
859
|
-
subfields:
|
|
897
|
+
tag: i.tag,
|
|
898
|
+
indicator1: i.indicator1,
|
|
899
|
+
indicator2: i.indicator2,
|
|
900
|
+
subfields: r
|
|
860
901
|
};
|
|
861
902
|
}
|
|
862
903
|
}
|
|
@@ -865,71 +906,71 @@ function st(e) {
|
|
|
865
906
|
fields: t
|
|
866
907
|
};
|
|
867
908
|
}
|
|
868
|
-
function
|
|
909
|
+
function ft(e, t, n = !1) {
|
|
869
910
|
if (e.leader !== t.leader || e.fields.length !== t.fields.length) return !1;
|
|
870
|
-
const
|
|
871
|
-
for (let s = 0; s <
|
|
872
|
-
const o =
|
|
873
|
-
if (!o || !
|
|
911
|
+
const i = n ? [...e.fields].sort(P) : e.fields, r = n ? [...t.fields].sort(P) : t.fields;
|
|
912
|
+
for (let s = 0; s < i.length; s++) {
|
|
913
|
+
const o = i[s], a = r[s];
|
|
914
|
+
if (!o || !a || !Me(o, a)) return !1;
|
|
874
915
|
}
|
|
875
916
|
return !0;
|
|
876
917
|
}
|
|
877
|
-
function
|
|
918
|
+
function Me(e, t) {
|
|
878
919
|
if (e.tag !== t.tag) return !1;
|
|
879
920
|
if (S(e) && S(t)) return e.data === t.data;
|
|
880
921
|
if (!S(e) && !S(t)) {
|
|
881
922
|
if (e.indicator1 !== t.indicator1 || e.indicator2 !== t.indicator2 || e.subfields.length !== t.subfields.length) return !1;
|
|
882
923
|
for (let n = 0; n < e.subfields.length; n++) {
|
|
883
|
-
const
|
|
884
|
-
if (!
|
|
924
|
+
const i = e.subfields[n], r = t.subfields[n];
|
|
925
|
+
if (!i || !r || i.code !== r.code || i.value !== r.value) return !1;
|
|
885
926
|
}
|
|
886
927
|
return !0;
|
|
887
928
|
}
|
|
888
929
|
return !1;
|
|
889
930
|
}
|
|
890
|
-
function
|
|
931
|
+
function P(e, t) {
|
|
891
932
|
return e.tag.localeCompare(t.tag);
|
|
892
933
|
}
|
|
893
934
|
export {
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
935
|
+
Le as addSubfield,
|
|
936
|
+
Z as appendField,
|
|
937
|
+
je as author,
|
|
938
|
+
dt as cloneRecord,
|
|
939
|
+
Q as createWarning,
|
|
940
|
+
Ye as edition,
|
|
941
|
+
Me as fieldsEqual,
|
|
942
|
+
ze as getAllSubfields,
|
|
902
943
|
m as getField,
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
944
|
+
Ge as getFields,
|
|
945
|
+
tt as getFieldsByPattern,
|
|
946
|
+
nt as getFirstFieldByPattern,
|
|
906
947
|
h as getSubfield,
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
948
|
+
ke as getSubfields,
|
|
949
|
+
it as insertFieldAfter,
|
|
950
|
+
rt as insertFieldBefore,
|
|
951
|
+
st as insertGroupedField,
|
|
911
952
|
S as isControlField,
|
|
912
953
|
p as isDataField,
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
954
|
+
Ke as isbn,
|
|
955
|
+
Ve as issn,
|
|
956
|
+
Xe as lccn,
|
|
957
|
+
Ee as marc8ToUnicode,
|
|
958
|
+
Be as parseMarcBinary,
|
|
959
|
+
Oe as parseMarcBinaryWithWarnings,
|
|
960
|
+
Ze as publicationDate,
|
|
961
|
+
qe as publisher,
|
|
962
|
+
ft as recordsEqual,
|
|
963
|
+
at as removeField,
|
|
964
|
+
ot as removeFields,
|
|
965
|
+
ct as removeSubfield,
|
|
966
|
+
lt as replaceSubfield,
|
|
967
|
+
Pe as serializeMarcBinary,
|
|
968
|
+
We as serializeMarcBinaryWithWarnings,
|
|
969
|
+
et as seriesStatement,
|
|
970
|
+
Qe as subjects,
|
|
971
|
+
He as title,
|
|
972
|
+
Je as titleProper,
|
|
973
|
+
Ue as unicodeToMarc8,
|
|
933
974
|
k as unicodeToMarc8WithStats
|
|
934
975
|
};
|
|
935
976
|
|