@biblioteksentralen/marc 0.1.0 → 0.1.1
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.cjs +42 -4
- package/dist/index.d.cts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +42 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -220,6 +220,13 @@ var MarcRecord = class _MarcRecord {
|
|
|
220
220
|
)
|
|
221
221
|
});
|
|
222
222
|
}
|
|
223
|
+
toJSON() {
|
|
224
|
+
return {
|
|
225
|
+
format: this.format,
|
|
226
|
+
leader: this.leader,
|
|
227
|
+
fields: this.fields.map((field) => field.toJSON())
|
|
228
|
+
};
|
|
229
|
+
}
|
|
223
230
|
static validateJSON(data, log) {
|
|
224
231
|
if (validator(data)) {
|
|
225
232
|
return data;
|
|
@@ -256,12 +263,43 @@ ${JSON.stringify(data)}`
|
|
|
256
263
|
getFirstSubfieldValue(tag, code, indicators) {
|
|
257
264
|
return this.getSubfieldValues(tag, code, indicators)[0];
|
|
258
265
|
}
|
|
259
|
-
|
|
260
|
-
|
|
266
|
+
/**
|
|
267
|
+
* Returns a new MarcRecord without control fields matching the given predicate, without modifying
|
|
268
|
+
* the original one.
|
|
269
|
+
*/
|
|
270
|
+
withoutControlFields(predicate) {
|
|
271
|
+
return new _MarcRecord({
|
|
261
272
|
format: this.format,
|
|
262
273
|
leader: this.leader,
|
|
263
|
-
fields: this.fields.
|
|
264
|
-
|
|
274
|
+
fields: this.fields.filter(
|
|
275
|
+
(field) => !isControlField(field) || !predicate(field)
|
|
276
|
+
)
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Returns a new MarcRecord without data fields matching the given predicate, without modifying
|
|
281
|
+
* the original one.
|
|
282
|
+
*/
|
|
283
|
+
withoutDataFields(predicate) {
|
|
284
|
+
return new _MarcRecord({
|
|
285
|
+
format: this.format,
|
|
286
|
+
leader: this.leader,
|
|
287
|
+
fields: this.fields.filter(
|
|
288
|
+
(field) => !isDataField(field) || !predicate(field)
|
|
289
|
+
)
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Returns a new MarcRecord with the given fields added without modifying the original one.
|
|
294
|
+
*/
|
|
295
|
+
withFields(fields) {
|
|
296
|
+
return new _MarcRecord({
|
|
297
|
+
format: this.format,
|
|
298
|
+
leader: this.leader,
|
|
299
|
+
fields: [...this.fields, ...fields].toSorted(
|
|
300
|
+
(a, b) => a.tag.localeCompare(b.tag)
|
|
301
|
+
)
|
|
302
|
+
});
|
|
265
303
|
}
|
|
266
304
|
};
|
|
267
305
|
|
package/dist/index.d.cts
CHANGED
|
@@ -76,6 +76,7 @@ declare class MarcRecord {
|
|
|
76
76
|
format?: string;
|
|
77
77
|
});
|
|
78
78
|
static fromJSON(data: unknown, log: Logger): MarcRecord;
|
|
79
|
+
toJSON(): SerializedMarcRecord;
|
|
79
80
|
static validateJSON(data: unknown, log: Logger): SerializedMarcRecord;
|
|
80
81
|
getControlFields(): ControlField[];
|
|
81
82
|
getControlField(tag: string): ControlField | undefined;
|
|
@@ -84,7 +85,20 @@ declare class MarcRecord {
|
|
|
84
85
|
getSubfields(tag: string | RegExp, code: string | RegExp, indicators?: Indicators): Subfield[];
|
|
85
86
|
getSubfieldValues(tag: string | RegExp, code: string | RegExp, indicators?: Indicators): string[];
|
|
86
87
|
getFirstSubfieldValue(tag: string | RegExp, code: string | RegExp, indicators?: Indicators): string | undefined;
|
|
87
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Returns a new MarcRecord without control fields matching the given predicate, without modifying
|
|
90
|
+
* the original one.
|
|
91
|
+
*/
|
|
92
|
+
withoutControlFields(predicate: (field: ControlField) => boolean): MarcRecord;
|
|
93
|
+
/**
|
|
94
|
+
* Returns a new MarcRecord without data fields matching the given predicate, without modifying
|
|
95
|
+
* the original one.
|
|
96
|
+
*/
|
|
97
|
+
withoutDataFields(predicate: (field: DataField) => boolean): MarcRecord;
|
|
98
|
+
/**
|
|
99
|
+
* Returns a new MarcRecord with the given fields added without modifying the original one.
|
|
100
|
+
*/
|
|
101
|
+
withFields(fields: MarcField[]): MarcRecord;
|
|
88
102
|
}
|
|
89
103
|
|
|
90
104
|
interface MarcXmlOptions {
|
package/dist/index.d.ts
CHANGED
|
@@ -76,6 +76,7 @@ declare class MarcRecord {
|
|
|
76
76
|
format?: string;
|
|
77
77
|
});
|
|
78
78
|
static fromJSON(data: unknown, log: Logger): MarcRecord;
|
|
79
|
+
toJSON(): SerializedMarcRecord;
|
|
79
80
|
static validateJSON(data: unknown, log: Logger): SerializedMarcRecord;
|
|
80
81
|
getControlFields(): ControlField[];
|
|
81
82
|
getControlField(tag: string): ControlField | undefined;
|
|
@@ -84,7 +85,20 @@ declare class MarcRecord {
|
|
|
84
85
|
getSubfields(tag: string | RegExp, code: string | RegExp, indicators?: Indicators): Subfield[];
|
|
85
86
|
getSubfieldValues(tag: string | RegExp, code: string | RegExp, indicators?: Indicators): string[];
|
|
86
87
|
getFirstSubfieldValue(tag: string | RegExp, code: string | RegExp, indicators?: Indicators): string | undefined;
|
|
87
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Returns a new MarcRecord without control fields matching the given predicate, without modifying
|
|
90
|
+
* the original one.
|
|
91
|
+
*/
|
|
92
|
+
withoutControlFields(predicate: (field: ControlField) => boolean): MarcRecord;
|
|
93
|
+
/**
|
|
94
|
+
* Returns a new MarcRecord without data fields matching the given predicate, without modifying
|
|
95
|
+
* the original one.
|
|
96
|
+
*/
|
|
97
|
+
withoutDataFields(predicate: (field: DataField) => boolean): MarcRecord;
|
|
98
|
+
/**
|
|
99
|
+
* Returns a new MarcRecord with the given fields added without modifying the original one.
|
|
100
|
+
*/
|
|
101
|
+
withFields(fields: MarcField[]): MarcRecord;
|
|
88
102
|
}
|
|
89
103
|
|
|
90
104
|
interface MarcXmlOptions {
|
package/dist/index.js
CHANGED
|
@@ -218,6 +218,13 @@ var MarcRecord = class _MarcRecord {
|
|
|
218
218
|
)
|
|
219
219
|
});
|
|
220
220
|
}
|
|
221
|
+
toJSON() {
|
|
222
|
+
return {
|
|
223
|
+
format: this.format,
|
|
224
|
+
leader: this.leader,
|
|
225
|
+
fields: this.fields.map((field) => field.toJSON())
|
|
226
|
+
};
|
|
227
|
+
}
|
|
221
228
|
static validateJSON(data, log) {
|
|
222
229
|
if (validator(data)) {
|
|
223
230
|
return data;
|
|
@@ -254,12 +261,43 @@ ${JSON.stringify(data)}`
|
|
|
254
261
|
getFirstSubfieldValue(tag, code, indicators) {
|
|
255
262
|
return this.getSubfieldValues(tag, code, indicators)[0];
|
|
256
263
|
}
|
|
257
|
-
|
|
258
|
-
|
|
264
|
+
/**
|
|
265
|
+
* Returns a new MarcRecord without control fields matching the given predicate, without modifying
|
|
266
|
+
* the original one.
|
|
267
|
+
*/
|
|
268
|
+
withoutControlFields(predicate) {
|
|
269
|
+
return new _MarcRecord({
|
|
259
270
|
format: this.format,
|
|
260
271
|
leader: this.leader,
|
|
261
|
-
fields: this.fields.
|
|
262
|
-
|
|
272
|
+
fields: this.fields.filter(
|
|
273
|
+
(field) => !isControlField(field) || !predicate(field)
|
|
274
|
+
)
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Returns a new MarcRecord without data fields matching the given predicate, without modifying
|
|
279
|
+
* the original one.
|
|
280
|
+
*/
|
|
281
|
+
withoutDataFields(predicate) {
|
|
282
|
+
return new _MarcRecord({
|
|
283
|
+
format: this.format,
|
|
284
|
+
leader: this.leader,
|
|
285
|
+
fields: this.fields.filter(
|
|
286
|
+
(field) => !isDataField(field) || !predicate(field)
|
|
287
|
+
)
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Returns a new MarcRecord with the given fields added without modifying the original one.
|
|
292
|
+
*/
|
|
293
|
+
withFields(fields) {
|
|
294
|
+
return new _MarcRecord({
|
|
295
|
+
format: this.format,
|
|
296
|
+
leader: this.leader,
|
|
297
|
+
fields: [...this.fields, ...fields].toSorted(
|
|
298
|
+
(a, b) => a.tag.localeCompare(b.tag)
|
|
299
|
+
)
|
|
300
|
+
});
|
|
263
301
|
}
|
|
264
302
|
};
|
|
265
303
|
|