marc-ts 0.2.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 +28 -130
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +410 -387
- package/dist/index.js.map +1 -1
- package/dist/marcjson.cjs +1 -1
- package/dist/marcjson.cjs.map +1 -1
- package/dist/marcjson.js +1 -1
- package/dist/marcjson.js.map +1 -1
- package/dist/marctxt.cjs +1 -1
- package/dist/marctxt.cjs.map +1 -1
- package/dist/marctxt.js +1 -1
- 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 +8 -3
- package/dist/marcxml.js +188 -127
- package/dist/marcxml.js.map +1 -1
- package/dist/parser.d.ts +10 -1
- package/dist/serializer.d.ts +11 -1
- 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/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, "Đ"],
|
|
@@ -28,7 +29,7 @@ var V = 27, m = "�", G = /* @__PURE__ */ new Map([
|
|
|
28
29
|
[59, "ơ"],
|
|
29
30
|
[60, "ư"],
|
|
30
31
|
[63, "°"]
|
|
31
|
-
]),
|
|
32
|
+
]), G = /* @__PURE__ */ new Map([
|
|
32
33
|
[96, "̉"],
|
|
33
34
|
[97, "̀"],
|
|
34
35
|
[98, "́"],
|
|
@@ -58,7 +59,7 @@ var V = 27, m = "�", G = /* @__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 V = 27, m = "�", G = /* @__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 V = 27, m = "�", G = /* @__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 V = 27, m = "�", G = /* @__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,98 +162,98 @@ var V = 27, m = "�", G = /* @__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
|
-
char:
|
|
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
|
-
char:
|
|
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
|
-
char:
|
|
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
|
-
char:
|
|
229
|
+
char: v,
|
|
229
230
|
next: t + 2
|
|
230
231
|
};
|
|
231
232
|
if (s >= e.length) return {
|
|
232
|
-
char:
|
|
233
|
+
char: v,
|
|
233
234
|
next: e.length
|
|
234
235
|
};
|
|
235
236
|
let o = e[s];
|
|
236
237
|
if (o === 33) {
|
|
237
238
|
if (s++, s >= e.length) return {
|
|
238
|
-
char:
|
|
239
|
+
char: v,
|
|
239
240
|
next: e.length
|
|
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
|
-
char:
|
|
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,344 +281,349 @@ function ge(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
|
-
return
|
|
320
|
+
function Ue(e) {
|
|
321
|
+
return k(e).bytes;
|
|
321
322
|
}
|
|
322
|
-
function
|
|
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
|
-
function
|
|
351
|
-
return
|
|
350
|
+
var U = 31, z = 30, _ = 24, I = 12, B = 3, x = new TextDecoder("utf-8", { fatal: !1 });
|
|
351
|
+
function H(e) {
|
|
352
|
+
return x.decode(e);
|
|
352
353
|
}
|
|
353
|
-
function
|
|
354
|
-
const n = e.slice(0, t),
|
|
355
|
-
return e.length > t ? `${
|
|
354
|
+
function J(e, t = 16) {
|
|
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;
|
|
356
357
|
}
|
|
357
|
-
function
|
|
358
|
-
const n = t.strict ?? !1,
|
|
359
|
-
if (e.length <
|
|
360
|
-
const
|
|
361
|
-
if (n) throw new Error(
|
|
362
|
-
return
|
|
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
|
-
var
|
|
425
|
-
function
|
|
425
|
+
var j = 29;
|
|
426
|
+
function Be(e, t) {
|
|
426
427
|
const n = [];
|
|
427
|
-
let
|
|
428
|
-
for (let
|
|
429
|
-
const s = e.slice(
|
|
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);
|
|
430
431
|
if (s.length > 0) {
|
|
431
|
-
const o =
|
|
432
|
+
const o = N(s, t);
|
|
432
433
|
o.record && n.push(o.record);
|
|
433
434
|
}
|
|
434
|
-
|
|
435
|
+
i = r + 1;
|
|
435
436
|
}
|
|
436
|
-
if (
|
|
437
|
-
const
|
|
438
|
-
|
|
437
|
+
if (i < e.length) {
|
|
438
|
+
const r = N(e.slice(i), t);
|
|
439
|
+
r.record && n.push(r.record);
|
|
439
440
|
}
|
|
440
441
|
return n;
|
|
441
442
|
}
|
|
442
|
-
function
|
|
443
|
-
const
|
|
444
|
-
|
|
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);
|
|
445
459
|
}
|
|
446
|
-
function
|
|
447
|
-
if (e.length !==
|
|
448
|
-
const
|
|
449
|
-
if (n) throw new Error(
|
|
450
|
-
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;
|
|
451
465
|
}
|
|
452
466
|
if (e[10] !== "2") {
|
|
453
|
-
const
|
|
454
|
-
t.push(
|
|
467
|
+
const i = u("invalid_leader", `Leader position 10 (indicator count) is '${e[10]}', expected '2'`);
|
|
468
|
+
t.push(i);
|
|
455
469
|
}
|
|
456
470
|
if (e[11] !== "2") {
|
|
457
|
-
const
|
|
458
|
-
t.push(
|
|
471
|
+
const i = u("invalid_leader", `Leader position 11 (subfield code length) is '${e[11]}', expected '2'`);
|
|
472
|
+
t.push(i);
|
|
459
473
|
}
|
|
460
474
|
return !0;
|
|
461
475
|
}
|
|
462
|
-
function
|
|
463
|
-
const
|
|
464
|
-
for (let s = 0; s < e.length; s +=
|
|
465
|
-
if (t.length >=
|
|
466
|
-
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.`));
|
|
467
481
|
break;
|
|
468
482
|
}
|
|
469
|
-
if (s +
|
|
470
|
-
const o = e.slice(s, s +
|
|
471
|
-
if (isNaN(f) || isNaN(
|
|
472
|
-
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}`);
|
|
473
487
|
if (n) throw new Error(w.message);
|
|
474
488
|
t.push(w);
|
|
475
489
|
continue;
|
|
476
490
|
}
|
|
477
|
-
|
|
491
|
+
r.push({
|
|
478
492
|
tag: l,
|
|
479
493
|
fieldLength: f,
|
|
480
|
-
startingPosition:
|
|
494
|
+
startingPosition: c
|
|
481
495
|
});
|
|
482
496
|
}
|
|
483
|
-
return
|
|
497
|
+
return r;
|
|
484
498
|
}
|
|
485
|
-
function
|
|
486
|
-
const
|
|
499
|
+
function be(e, t, n, i, r, s, o) {
|
|
500
|
+
const a = [];
|
|
487
501
|
for (const l of t) {
|
|
488
|
-
if (
|
|
489
|
-
|
|
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));
|
|
490
504
|
break;
|
|
491
505
|
}
|
|
492
|
-
const d = n + l.startingPosition,
|
|
493
|
-
if (d >= e.length ||
|
|
494
|
-
const
|
|
495
|
-
if (s) throw new Error(
|
|
496
|
-
|
|
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);
|
|
497
511
|
continue;
|
|
498
512
|
}
|
|
499
513
|
let f;
|
|
500
|
-
if (e[
|
|
501
|
-
const
|
|
502
|
-
if (s) throw new Error(
|
|
503
|
-
|
|
504
|
-
} 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);
|
|
505
519
|
if (l.tag.startsWith("00")) {
|
|
506
520
|
try {
|
|
507
|
-
const
|
|
508
|
-
|
|
521
|
+
const c = i(f);
|
|
522
|
+
a.push({
|
|
509
523
|
tag: l.tag,
|
|
510
|
-
data:
|
|
524
|
+
data: c
|
|
511
525
|
});
|
|
512
|
-
} catch (
|
|
513
|
-
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);
|
|
514
528
|
if (s) throw new Error(w.message);
|
|
515
|
-
|
|
529
|
+
r.push(w), a.push({
|
|
516
530
|
tag: l.tag,
|
|
517
|
-
data:
|
|
531
|
+
data: H(f)
|
|
518
532
|
});
|
|
519
533
|
}
|
|
520
534
|
continue;
|
|
521
535
|
}
|
|
522
536
|
if (f.length < 2) {
|
|
523
|
-
const
|
|
524
|
-
if (s) throw new Error(
|
|
525
|
-
|
|
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);
|
|
526
540
|
continue;
|
|
527
541
|
}
|
|
528
542
|
try {
|
|
529
|
-
const
|
|
530
|
-
|
|
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({
|
|
531
545
|
tag: l.tag,
|
|
532
|
-
indicator1:
|
|
546
|
+
indicator1: c,
|
|
533
547
|
indicator2: w,
|
|
534
|
-
subfields:
|
|
548
|
+
subfields: A
|
|
535
549
|
});
|
|
536
|
-
} catch (
|
|
537
|
-
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);
|
|
538
552
|
if (s) throw new Error(w.message);
|
|
539
|
-
|
|
553
|
+
r.push(w);
|
|
540
554
|
}
|
|
541
555
|
}
|
|
542
|
-
return
|
|
556
|
+
return a;
|
|
543
557
|
}
|
|
544
|
-
function
|
|
558
|
+
function ye(e, t, n, i, r, s) {
|
|
545
559
|
const o = [];
|
|
546
|
-
let
|
|
547
|
-
for (;
|
|
548
|
-
if (
|
|
549
|
-
|
|
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));
|
|
550
564
|
break;
|
|
551
565
|
}
|
|
552
|
-
if (e[
|
|
553
|
-
const f =
|
|
554
|
-
if (
|
|
555
|
-
|
|
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);
|
|
556
570
|
break;
|
|
557
571
|
}
|
|
558
|
-
if (
|
|
559
|
-
const l = String.fromCharCode(e[
|
|
560
|
-
|
|
561
|
-
const d =
|
|
562
|
-
for (;
|
|
563
|
-
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);
|
|
564
578
|
try {
|
|
565
|
-
const f = t(
|
|
579
|
+
const f = t(g);
|
|
566
580
|
o.push({
|
|
567
581
|
code: l,
|
|
568
582
|
value: f
|
|
569
583
|
});
|
|
570
584
|
} catch (f) {
|
|
571
|
-
const
|
|
572
|
-
if (
|
|
573
|
-
|
|
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({
|
|
574
588
|
code: l,
|
|
575
|
-
value:
|
|
589
|
+
value: H(g)
|
|
576
590
|
});
|
|
577
591
|
}
|
|
578
592
|
}
|
|
579
593
|
return o;
|
|
580
594
|
}
|
|
581
|
-
function
|
|
582
|
-
return {
|
|
583
|
-
type: e,
|
|
584
|
-
message: t,
|
|
585
|
-
position: n,
|
|
586
|
-
tag: r
|
|
587
|
-
};
|
|
588
|
-
}
|
|
589
|
-
function be(e, t, n, r) {
|
|
595
|
+
function u(e, t, n, i) {
|
|
590
596
|
return {
|
|
591
597
|
type: e,
|
|
592
598
|
message: t,
|
|
593
599
|
position: n,
|
|
594
|
-
tag:
|
|
600
|
+
tag: i
|
|
595
601
|
};
|
|
596
602
|
}
|
|
597
|
-
var $e = 31,
|
|
598
|
-
function _e(e, t = {}) {
|
|
599
|
-
return Ne(e, t).bytes;
|
|
600
|
-
}
|
|
603
|
+
var $e = 31, O = 30, Ae = 29, R = 24, Ie = 3, Ce = 4, _e = 5;
|
|
601
604
|
function Ne(e, t = {}) {
|
|
605
|
+
return Y(e, t).bytes;
|
|
606
|
+
}
|
|
607
|
+
function Y(e, t = {}) {
|
|
602
608
|
Re(e);
|
|
603
|
-
const n = [], r = t.encoding === "marc8",
|
|
604
|
-
const
|
|
605
|
-
return
|
|
606
|
-
} : (E) =>
|
|
607
|
-
let
|
|
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;
|
|
608
614
|
for (const E of e.fields) {
|
|
609
|
-
const b =
|
|
610
|
-
|
|
611
|
-
}
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
const
|
|
615
|
-
let
|
|
616
|
-
for (const E of
|
|
617
|
-
|
|
618
|
-
const
|
|
619
|
-
return
|
|
620
|
-
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: $,
|
|
621
627
|
warnings: n
|
|
622
628
|
};
|
|
623
629
|
}
|
|
@@ -640,189 +646,204 @@ function Re(e) {
|
|
|
640
646
|
}
|
|
641
647
|
}
|
|
642
648
|
}
|
|
643
|
-
function
|
|
649
|
+
function xe(e, t) {
|
|
644
650
|
if (S(e)) return t(e.data);
|
|
645
651
|
const n = [new Uint8Array([e.indicator1.charCodeAt(0), e.indicator2.charCodeAt(0)])];
|
|
646
652
|
for (const o of e.subfields) {
|
|
647
|
-
const
|
|
648
|
-
n.push(
|
|
653
|
+
const a = new Uint8Array([$e, o.code.charCodeAt(0)]);
|
|
654
|
+
n.push(a, t(o.value));
|
|
649
655
|
}
|
|
650
|
-
const
|
|
656
|
+
const i = n.reduce((o, a) => o + a.length, 0), r = new Uint8Array(i);
|
|
651
657
|
let s = 0;
|
|
652
658
|
for (const o of n)
|
|
653
|
-
|
|
654
|
-
return
|
|
659
|
+
r.set(o, s), s += o.length;
|
|
660
|
+
return r;
|
|
655
661
|
}
|
|
656
|
-
function
|
|
657
|
-
let
|
|
662
|
+
function Fe(e, t, n, i) {
|
|
663
|
+
let r = e.padEnd(R, " ").substring(0, R);
|
|
658
664
|
const s = t.toString().padStart(5, "0");
|
|
659
665
|
if (s.length > 5) throw new Error(`Record length ${t} exceeds maximum (99999)`);
|
|
660
|
-
|
|
666
|
+
r = s + r.substring(5);
|
|
661
667
|
const o = n.toString().padStart(5, "0");
|
|
662
668
|
if (o.length > 5) throw new Error(`Base address ${n} exceeds maximum (99999)`);
|
|
663
|
-
return
|
|
669
|
+
return r = r.substring(0, 12) + o + r.substring(17), r = r.substring(0, 9) + (i ? " " : "a") + r.substring(10), r;
|
|
664
670
|
}
|
|
665
|
-
function
|
|
666
|
-
const n = e.map((o) =>
|
|
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);
|
|
667
673
|
let s = 0;
|
|
668
674
|
for (const o of n)
|
|
669
|
-
|
|
670
|
-
return
|
|
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
|
+
};
|
|
671
692
|
}
|
|
672
|
-
function
|
|
693
|
+
function m(e, t) {
|
|
673
694
|
return e.fields.find((n) => n.tag === t);
|
|
674
695
|
}
|
|
675
|
-
function
|
|
696
|
+
function Ge(e, t) {
|
|
676
697
|
return e.fields.filter((n) => n.tag === t);
|
|
677
698
|
}
|
|
678
699
|
function h(e, t) {
|
|
679
700
|
return e.subfields.find((n) => n.code === t)?.value;
|
|
680
701
|
}
|
|
681
|
-
function
|
|
702
|
+
function ke(e, t) {
|
|
682
703
|
return e.subfields.filter((n) => n.code === t).map((n) => n.value);
|
|
683
704
|
}
|
|
684
|
-
function
|
|
705
|
+
function ze(e) {
|
|
685
706
|
return e.subfields.map((t) => ({
|
|
686
707
|
code: t.code,
|
|
687
708
|
value: t.value
|
|
688
709
|
}));
|
|
689
710
|
}
|
|
690
|
-
function
|
|
691
|
-
const t =
|
|
711
|
+
function He(e) {
|
|
712
|
+
const t = m(e, "245");
|
|
692
713
|
if (!t || !p(t)) return;
|
|
693
|
-
const n = h(t, "a") ?? "",
|
|
694
|
-
return (n + " " +
|
|
714
|
+
const n = h(t, "a") ?? "", i = h(t, "b") ?? "";
|
|
715
|
+
return (n + " " + i).trim() || void 0;
|
|
695
716
|
}
|
|
696
|
-
function
|
|
697
|
-
const t =
|
|
717
|
+
function Je(e) {
|
|
718
|
+
const t = m(e, "245");
|
|
698
719
|
if (!(!t || !p(t)))
|
|
699
720
|
return h(t, "a");
|
|
700
721
|
}
|
|
701
|
-
function
|
|
702
|
-
const t =
|
|
722
|
+
function je(e) {
|
|
723
|
+
const t = m(e, "100");
|
|
703
724
|
if (t && p(t)) return h(t, "a");
|
|
704
|
-
const n =
|
|
725
|
+
const n = m(e, "110");
|
|
705
726
|
if (n && p(n)) return h(n, "a");
|
|
706
727
|
}
|
|
707
|
-
function
|
|
708
|
-
const t =
|
|
728
|
+
function Ye(e) {
|
|
729
|
+
const t = m(e, "250");
|
|
709
730
|
if (!(!t || !p(t)))
|
|
710
731
|
return h(t, "a");
|
|
711
732
|
}
|
|
712
|
-
function
|
|
713
|
-
const t =
|
|
733
|
+
function qe(e) {
|
|
734
|
+
const t = m(e, "264");
|
|
714
735
|
if (t && p(t)) {
|
|
715
|
-
const
|
|
716
|
-
if (
|
|
736
|
+
const i = h(t, "b");
|
|
737
|
+
if (i) return i;
|
|
717
738
|
}
|
|
718
|
-
const n =
|
|
739
|
+
const n = m(e, "260");
|
|
719
740
|
if (n && p(n)) return h(n, "b");
|
|
720
741
|
}
|
|
721
|
-
function
|
|
722
|
-
const t =
|
|
742
|
+
function Ze(e) {
|
|
743
|
+
const t = m(e, "264");
|
|
723
744
|
if (t && p(t)) {
|
|
724
|
-
const
|
|
725
|
-
if (
|
|
745
|
+
const i = h(t, "c");
|
|
746
|
+
if (i) return i;
|
|
726
747
|
}
|
|
727
|
-
const n =
|
|
748
|
+
const n = m(e, "260");
|
|
728
749
|
if (n && p(n)) return h(n, "c");
|
|
729
750
|
}
|
|
730
|
-
function
|
|
751
|
+
function Ke(e) {
|
|
731
752
|
const t = [];
|
|
732
753
|
for (const n of e.fields) if (n.tag === "020" && p(n)) {
|
|
733
|
-
const
|
|
734
|
-
|
|
754
|
+
const i = h(n, "a");
|
|
755
|
+
i && t.push(i);
|
|
735
756
|
}
|
|
736
757
|
return t;
|
|
737
758
|
}
|
|
738
|
-
function
|
|
739
|
-
const t =
|
|
759
|
+
function Ve(e) {
|
|
760
|
+
const t = m(e, "022");
|
|
740
761
|
if (!(!t || !p(t)))
|
|
741
762
|
return h(t, "a");
|
|
742
763
|
}
|
|
743
|
-
function
|
|
744
|
-
const t =
|
|
764
|
+
function Xe(e) {
|
|
765
|
+
const t = m(e, "010");
|
|
745
766
|
if (!(!t || !p(t)))
|
|
746
767
|
return h(t, "a");
|
|
747
768
|
}
|
|
748
|
-
function
|
|
769
|
+
function Qe(e) {
|
|
749
770
|
const t = [];
|
|
750
771
|
for (const n of e.fields) if (n.tag.startsWith("6") && p(n)) {
|
|
751
|
-
const
|
|
752
|
-
|
|
772
|
+
const i = h(n, "a");
|
|
773
|
+
i && t.push(i);
|
|
753
774
|
}
|
|
754
775
|
return t;
|
|
755
776
|
}
|
|
756
|
-
function
|
|
757
|
-
const t =
|
|
777
|
+
function et(e) {
|
|
778
|
+
const t = m(e, "490");
|
|
758
779
|
if (!(!t || !p(t)))
|
|
759
780
|
return h(t, "a");
|
|
760
781
|
}
|
|
761
|
-
function
|
|
782
|
+
function q(e, t) {
|
|
762
783
|
if (e.length !== 3 || t.length !== 3) return !1;
|
|
763
784
|
for (let n = 0; n < 3; n++) {
|
|
764
|
-
const
|
|
765
|
-
if (
|
|
766
|
-
if (
|
|
785
|
+
const i = t[n], r = e[n];
|
|
786
|
+
if (i === "." || i?.toUpperCase() === "X") {
|
|
787
|
+
if (r && !/\d/.test(r)) return !1;
|
|
767
788
|
continue;
|
|
768
789
|
}
|
|
769
|
-
if (
|
|
790
|
+
if (i !== r) return !1;
|
|
770
791
|
}
|
|
771
792
|
return !0;
|
|
772
793
|
}
|
|
773
|
-
function
|
|
774
|
-
return e.fields.filter((n) =>
|
|
794
|
+
function tt(e, t) {
|
|
795
|
+
return e.fields.filter((n) => q(n.tag, t));
|
|
775
796
|
}
|
|
776
|
-
function
|
|
777
|
-
return e.fields.find((n) =>
|
|
797
|
+
function nt(e, t) {
|
|
798
|
+
return e.fields.find((n) => q(n.tag, t));
|
|
778
799
|
}
|
|
779
|
-
function
|
|
800
|
+
function Z(e, t) {
|
|
780
801
|
return {
|
|
781
802
|
...e,
|
|
782
803
|
fields: [...e.fields, t]
|
|
783
804
|
};
|
|
784
805
|
}
|
|
785
|
-
function
|
|
786
|
-
const
|
|
787
|
-
if (
|
|
788
|
-
const
|
|
789
|
-
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), {
|
|
790
811
|
...e,
|
|
791
|
-
fields:
|
|
812
|
+
fields: r
|
|
792
813
|
};
|
|
793
814
|
}
|
|
794
|
-
function
|
|
795
|
-
const
|
|
796
|
-
if (
|
|
797
|
-
const
|
|
798
|
-
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), {
|
|
799
820
|
...e,
|
|
800
|
-
fields:
|
|
821
|
+
fields: r
|
|
801
822
|
};
|
|
802
823
|
}
|
|
803
|
-
function
|
|
824
|
+
function st(e, t) {
|
|
804
825
|
const n = parseInt(t.tag, 10);
|
|
805
|
-
let
|
|
826
|
+
let i = e.fields.length;
|
|
806
827
|
for (let s = 0; s < e.fields.length; s++) {
|
|
807
828
|
const o = e.fields[s];
|
|
808
829
|
if (o && parseInt(o.tag, 10) > n) {
|
|
809
|
-
|
|
830
|
+
i = s;
|
|
810
831
|
break;
|
|
811
832
|
}
|
|
812
833
|
}
|
|
813
|
-
const
|
|
814
|
-
return
|
|
834
|
+
const r = Array.from(e.fields);
|
|
835
|
+
return r.splice(i, 0, t), {
|
|
815
836
|
...e,
|
|
816
|
-
fields:
|
|
837
|
+
fields: r
|
|
817
838
|
};
|
|
818
839
|
}
|
|
819
|
-
function
|
|
840
|
+
function ot(e, t) {
|
|
820
841
|
return {
|
|
821
842
|
...e,
|
|
822
843
|
fields: e.fields.filter((n) => n.tag !== t)
|
|
823
844
|
};
|
|
824
845
|
}
|
|
825
|
-
function
|
|
846
|
+
function at(e, t) {
|
|
826
847
|
return {
|
|
827
848
|
...e,
|
|
828
849
|
fields: e.fields.filter((n) => n !== t)
|
|
@@ -837,46 +858,46 @@ function Le(e, t, n) {
|
|
|
837
858
|
}]
|
|
838
859
|
};
|
|
839
860
|
}
|
|
840
|
-
function
|
|
861
|
+
function ct(e, t) {
|
|
841
862
|
return {
|
|
842
863
|
...e,
|
|
843
864
|
subfields: e.subfields.filter((n) => n.code !== t)
|
|
844
865
|
};
|
|
845
866
|
}
|
|
846
|
-
function
|
|
847
|
-
const
|
|
848
|
-
if (
|
|
849
|
-
const
|
|
850
|
-
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] = {
|
|
851
872
|
code: t,
|
|
852
873
|
value: n
|
|
853
874
|
}, {
|
|
854
875
|
...e,
|
|
855
|
-
subfields:
|
|
876
|
+
subfields: r
|
|
856
877
|
};
|
|
857
878
|
}
|
|
858
|
-
function
|
|
879
|
+
function dt(e) {
|
|
859
880
|
const t = new Array(e.fields.length);
|
|
860
881
|
for (let n = 0; n < e.fields.length; n++) {
|
|
861
|
-
const
|
|
862
|
-
if (S(
|
|
863
|
-
tag:
|
|
864
|
-
data:
|
|
882
|
+
const i = e.fields[n];
|
|
883
|
+
if (S(i)) t[n] = {
|
|
884
|
+
tag: i.tag,
|
|
885
|
+
data: i.data
|
|
865
886
|
};
|
|
866
887
|
else {
|
|
867
|
-
const
|
|
868
|
-
for (let s = 0; s <
|
|
869
|
-
const o =
|
|
870
|
-
|
|
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] = {
|
|
871
892
|
code: o.code,
|
|
872
893
|
value: o.value
|
|
873
894
|
};
|
|
874
895
|
}
|
|
875
896
|
t[n] = {
|
|
876
|
-
tag:
|
|
877
|
-
indicator1:
|
|
878
|
-
indicator2:
|
|
879
|
-
subfields:
|
|
897
|
+
tag: i.tag,
|
|
898
|
+
indicator1: i.indicator1,
|
|
899
|
+
indicator2: i.indicator2,
|
|
900
|
+
subfields: r
|
|
880
901
|
};
|
|
881
902
|
}
|
|
882
903
|
}
|
|
@@ -885,23 +906,23 @@ function at(e) {
|
|
|
885
906
|
fields: t
|
|
886
907
|
};
|
|
887
908
|
}
|
|
888
|
-
function
|
|
909
|
+
function ft(e, t, n = !1) {
|
|
889
910
|
if (e.leader !== t.leader || e.fields.length !== t.fields.length) return !1;
|
|
890
|
-
const
|
|
891
|
-
for (let s = 0; s <
|
|
892
|
-
const o =
|
|
893
|
-
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;
|
|
894
915
|
}
|
|
895
916
|
return !0;
|
|
896
917
|
}
|
|
897
|
-
function
|
|
918
|
+
function Me(e, t) {
|
|
898
919
|
if (e.tag !== t.tag) return !1;
|
|
899
920
|
if (S(e) && S(t)) return e.data === t.data;
|
|
900
921
|
if (!S(e) && !S(t)) {
|
|
901
922
|
if (e.indicator1 !== t.indicator1 || e.indicator2 !== t.indicator2 || e.subfields.length !== t.subfields.length) return !1;
|
|
902
923
|
for (let n = 0; n < e.subfields.length; n++) {
|
|
903
|
-
const
|
|
904
|
-
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;
|
|
905
926
|
}
|
|
906
927
|
return !0;
|
|
907
928
|
}
|
|
@@ -912,43 +933,45 @@ function P(e, t) {
|
|
|
912
933
|
}
|
|
913
934
|
export {
|
|
914
935
|
Le as addSubfield,
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
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,
|
|
943
|
+
m as getField,
|
|
944
|
+
Ge as getFields,
|
|
945
|
+
tt as getFieldsByPattern,
|
|
946
|
+
nt as getFirstFieldByPattern,
|
|
926
947
|
h as getSubfield,
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
948
|
+
ke as getSubfields,
|
|
949
|
+
it as insertFieldAfter,
|
|
950
|
+
rt as insertFieldBefore,
|
|
951
|
+
st as insertGroupedField,
|
|
931
952
|
S as isControlField,
|
|
932
953
|
p as isDataField,
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
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,
|
|
974
|
+
k as unicodeToMarc8WithStats
|
|
952
975
|
};
|
|
953
976
|
|
|
954
977
|
//# sourceMappingURL=index.js.map
|