MARC record implementation in JavaScript. A JSON schema file specifies the data format.
This a fork of the original marc-record-js. The new implementation uses ES6 syntax and adds validation of the record structure.
import {MarcRecord} from '@natlibfi/marc-record';
const record = new MarcRecord();
const record = new MarcRecord({leader: 'foo', fields: [
{tag: '001', value: 'bar'}
]})
MarcRecord.getValidationOptions(); // {fields: true, subfields: true, subfieldValues: true }
MarcRecord.setValidationOptions({fields: false});
const record = new MarcRecord({leader: 'foo', fields: []}); // This is ok because setting strict field validation to false
try {
const record = new MarcRecord({leader: 'foo', fields: []}, {fields: true); // No longer ok
} catch (err) {
MarcRecord.setValidationOptions({}); // Reset to default
}
record.leader = "00000cam^a22001817i^4500";
// Insert field to the record. Proper ordering is handled automatically.
record.insertField({
tag: "001"
value: "007045872"
});
// Append fields to the end of the record
record.appendField({
tag: '245',
ind2: '1',
subfields: [
{
code: "a"
value: "The title of the book"
},
{
code: "c",
value: "Some author"
}
]
});
record.getControlfields();
record.getDatafields();
record.get(/^001$/)
record.fields;
record.getFields('245', [{code: 'a', value: 'foo'}]);
record.getFields('001', 'foo');
const recordB = MarcRecord.clone(recordA)
MarcRecord.isEqual(recordA, recordB);
recordA.equalsTo(recordB);
record.containsFieldWithValue('245', [{code: 'a', value: 'foo'}]);
record.containsFieldWithValue('001', 'foo');
To serialize and unserialize MARC records, see marc-record-serializers
Copyright (c) 2014-2017 Pasi Tuominen [email protected]
Copyright (c) 2018 University Of Helsinki (The National Library Of Finland)
This project's source code is licensed under the terms of MIT License or any later version.