@natlibfi/melinda-commons 13.1.0-alpha.1 → 13.2.0-alpha.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/utils.js +40 -0
- package/dist/utils.js.map +1 -1
- package/dist/utils.spec.js +42 -0
- package/dist/utils.spec.js.map +1 -1
- package/package.json +1 -1
- package/src/utils.js +43 -0
- package/src/utils.spec.js +55 -1
- package/test-fixtures/utils/isComponentRecord/record1.json +35 -0
- package/test-fixtures/utils/isComponentRecord/record2.json +35 -0
- package/test-fixtures/utils/isComponentRecord/record3.json +20 -0
- package/test-fixtures/utils/isComponentRecord/record4.json +20 -0
- package/test-fixtures/utils/isComponentRecord/record5.json +20 -0
- package/test-fixtures/utils/isComponentRecord/record6.json +35 -0
- package/test-fixtures/utils/isComponentRecord/record7.json +35 -0
package/dist/utils.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.fromAlephId = fromAlephId;
|
|
|
8
8
|
exports.generateAuthorizationHeader = generateAuthorizationHeader;
|
|
9
9
|
exports.getRecordStandardIdentifiers = getRecordStandardIdentifiers;
|
|
10
10
|
exports.getRecordTitle = getRecordTitle;
|
|
11
|
+
exports.isComponentRecord = isComponentRecord;
|
|
11
12
|
exports.isDeletedRecord = isDeletedRecord;
|
|
12
13
|
exports.parseBoolean = parseBoolean;
|
|
13
14
|
exports.toAlephId = toAlephId;
|
|
@@ -44,6 +45,45 @@ function isDeletedRecord(record) {
|
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
}
|
|
48
|
+
function isComponentRecord(record, ignoreCollections = false, additionalHostFields = []) {
|
|
49
|
+
// Record is a component record if it has bibliografic level of a component in leader
|
|
50
|
+
// and/or has at least one host link field (f773)
|
|
51
|
+
|
|
52
|
+
// Ignore collections - optionally do not handle collections (LDR/07 'c')
|
|
53
|
+
// or collection subUnits (LDR/07 'd') as components, even if they do have f773
|
|
54
|
+
|
|
55
|
+
// https://www.loc.gov/marc/bibliographic/bdleader.html
|
|
56
|
+
// LDR/07
|
|
57
|
+
// c - Collection
|
|
58
|
+
// d - Subunit (in a collection)
|
|
59
|
+
|
|
60
|
+
if (ignoreCollections && ['c', 'd'].includes(record.leader[7])) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// https://www.loc.gov/marc/bibliographic/bdleader.html
|
|
65
|
+
// LDR/07
|
|
66
|
+
// a - Monographic component part
|
|
67
|
+
// b - Serial component part
|
|
68
|
+
// d - Subunit (in a collection)
|
|
69
|
+
|
|
70
|
+
if (['a', 'b', 'd'].includes(record.leader[7])) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// https://www.loc.gov/marc/bibliographic/bd773.html
|
|
75
|
+
// 773 - Host Item Entry (R)
|
|
76
|
+
|
|
77
|
+
// additionalHostFields (for example f973 for Viola's multihost componenets)
|
|
78
|
+
// optionally recognize fields given in additionalHostFields array as hostFields
|
|
79
|
+
|
|
80
|
+
const hostFields = additionalHostFields.concat('773');
|
|
81
|
+
const hostFieldPatternString = `^(${hostFields.join('|')})$`;
|
|
82
|
+
const hostFieldRegex = new RegExp(hostFieldPatternString, 'u');
|
|
83
|
+
const recordHasHostFields = record.get(hostFieldRegex).length > 0;
|
|
84
|
+
return recordHasHostFields;
|
|
85
|
+
//return record.get(/^773$/u).length > 0;
|
|
86
|
+
}
|
|
47
87
|
function parseBoolean(value) {
|
|
48
88
|
if (value === undefined) {
|
|
49
89
|
return false;
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["generateAuthorizationHeader","username","password","encoded","Buffer","from","toString","isDeletedRecord","record","includes","leader","checkDel","checkSta","get","some","check","subfields","code","value","values","parseBoolean","undefined","Number","isNaN","
|
|
1
|
+
{"version":3,"file":"utils.js","names":["generateAuthorizationHeader","username","password","encoded","Buffer","from","toString","isDeletedRecord","record","includes","leader","checkDel","checkSta","get","some","check","subfields","code","value","values","isComponentRecord","ignoreCollections","additionalHostFields","hostFields","concat","hostFieldPatternString","join","hostFieldRegex","RegExp","recordHasHostFields","length","parseBoolean","undefined","Number","isNaN","test","Boolean","getRecordTitle","TRIM_PATTERN","field","find","f","sf","replace","getRecordStandardIdentifiers","filter","map","subfield","clone","o","JSON","parse","stringify","toAlephId","id","padStart","fromAlephId"],"sources":["../src/utils.js"],"sourcesContent":["export function generateAuthorizationHeader(username, password = '') {\n const encoded = Buffer.from(`${username}:${password}`).toString('base64');\n return `Basic ${encoded}`;\n}\n\nexport function isDeletedRecord(record) {\n if (['d', 's', 'x'].includes(record.leader[5])) {\n return true;\n }\n\n return checkDel() || checkSta();\n\n function checkDel() {\n return record.get(/^DEL$/u).some(check);\n\n function check({subfields}) {\n return subfields.some(({code, value}) => code === 'a' && value === 'Y');\n }\n }\n\n function checkSta() {\n return record.get(/^STA$/u).some(check);\n\n function check({subfields}) {\n const values = ['DELETED', 'DELETED-SPLIT', 'DELETED-DEPRECATED'];\n return subfields.some(({code, value}) => code === 'a' && values.includes(value));\n }\n }\n}\n\nexport function isComponentRecord(record, ignoreCollections = false, additionalHostFields = []) {\n\n // Record is a component record if it has bibliografic level of a component in leader\n // and/or has at least one host link field (f773)\n\n\n // Ignore collections - optionally do not handle collections (LDR/07 'c')\n // or collection subUnits (LDR/07 'd') as components, even if they do have f773\n\n // https://www.loc.gov/marc/bibliographic/bdleader.html\n // LDR/07\n // c - Collection\n // d - Subunit (in a collection)\n\n if (ignoreCollections && ['c', 'd'].includes(record.leader[7])) {\n return false;\n }\n\n // https://www.loc.gov/marc/bibliographic/bdleader.html\n // LDR/07\n // a - Monographic component part\n // b - Serial component part\n // d - Subunit (in a collection)\n\n if (['a', 'b', 'd'].includes(record.leader[7])) {\n return true;\n }\n\n // https://www.loc.gov/marc/bibliographic/bd773.html\n // 773 - Host Item Entry (R)\n\n // additionalHostFields (for example f973 for Viola's multihost componenets)\n // optionally recognize fields given in additionalHostFields array as hostFields\n\n const hostFields = additionalHostFields.concat('773');\n const hostFieldPatternString = `^(${hostFields.join('|')})$`;\n const hostFieldRegex = new RegExp(hostFieldPatternString, 'u');\n\n const recordHasHostFields = record.get(hostFieldRegex).length > 0;\n return recordHasHostFields;\n //return record.get(/^773$/u).length > 0;\n}\n\nexport function parseBoolean(value) {\n if (value === undefined) {\n return false;\n }\n\n if (Number.isNaN(Number(value))) {\n return value.length > 0 && !(/^(?:false)$/ui).test(value);\n }\n\n return Boolean(Number(value));\n}\n\nexport function getRecordTitle(record) {\n const TRIM_PATTERN = '[?!.,(){}:;/ ]*';\n // DEVELOP: get mainHeadings for aut records\n const field = record\n .get(/^245$/u)\n .find(f => f.subfields.some(sf => sf.code === 'a'));\n\n if (field) {\n return field.subfields.find(sf => sf.code === 'a').value\n .replace(new RegExp(`^${TRIM_PATTERN}`, 'u'), '')\n .replace(new RegExp(`${TRIM_PATTERN}$`, 'u'), '');\n }\n\n return '';\n}\n\nexport function getRecordStandardIdentifiers(record) {\n return record.get(/^(?<def>020|022|024)$/u)\n .filter(f => f.subfields.some(sf => ['a', 'z'].includes(sf.code)))\n .map(field => {\n const subfield = field.subfields.find(sf => ['a', 'z'].includes(sf.code));\n return subfield.value;\n });\n}\n\nexport function clone(o) {\n return JSON.parse(JSON.stringify(o));\n}\n\nexport function toAlephId(id) {\n return id.padStart(9, '0');\n}\n\nexport function fromAlephId(id) {\n return id.replace(/^0+/u, '');\n}\n"],"mappings":";;;;;;;;;;;;;;AAAO,SAASA,2BAA2BA,CAACC,QAAQ,EAAEC,QAAQ,GAAG,EAAE,EAAE;EACnE,MAAMC,OAAO,GAAGC,MAAM,CAACC,IAAI,CAAC,GAAGJ,QAAQ,IAAIC,QAAQ,EAAE,CAAC,CAACI,QAAQ,CAAC,QAAQ,CAAC;EACzE,OAAO,SAASH,OAAO,EAAE;AAC3B;AAEO,SAASI,eAAeA,CAACC,MAAM,EAAE;EACtC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,C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C,IAAIf,MAAM,CAAC,IAAIU,YAAY,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAChDK,OAAO,CAAC,IAAIf,MAAM,CAAC,GAAGU,YAAY,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC;EACrD;EAEA,OAAO,EAAE;AACX;AAEO,SAASM,4BAA4BA,CAACpC,MAAM,EAAE;EACnD,OAAOA,MAAM,CAACK,GAAG,CAAC,wBAAwB,CAAC,CACxCgC,MAAM,CAACJ,CAAC,IAAIA,CAAC,CAACzB,SAAS,CAACF,IAAI,CAAC4B,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAACjC,QAAQ,CAACiC,EAAE,CAACzB,IAAI,CAAC,CAAC,CAAC,CACjE6B,GAAG,CAACP,KAAK,IAAI;IACZ,MAAMQ,QAAQ,GAAGR,KAAK,CAACvB,SAAS,CAACwB,IAAI,CAACE,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAACjC,QAAQ,CAACiC,EAAE,CAACzB,IAAI,CAAC,CAAC;IACzE,OAAO8B,QAAQ,CAAC7B,KAAK;EACvB,CAAC,CAAC;AACN;AAEO,SAAS8B,KAAKA,CAACC,CAAC,EAAE;EACvB,OAAOC,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,SAAS,CAACH,CAAC,CAAC,CAAC;AACtC;AAEO,SAASI,SAASA,CAACC,EAAE,EAAE;EAC5B,OAAOA,EAAE,CAACC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;AAC5B;AAEO,SAASC,WAAWA,CAACF,EAAE,EAAE;EAC9B,OAAOA,EAAE,CAACX,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;AAC/B","ignoreList":[]}
|
package/dist/utils.spec.js
CHANGED
|
@@ -85,6 +85,48 @@ describe('utils', () => {
|
|
|
85
85
|
(0, _chai.expect)((0, _utils.parseBoolean)('FAlsE')).to.equal(false);
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
|
+
describe('isComponentRecord', () => {
|
|
89
|
+
it('Should find out that the record is a component record (f773)', () => {
|
|
90
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isComponentRecord/record1.json'), 'utf8');
|
|
91
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
92
|
+
(0, _chai.expect)((0, _utils.isComponentRecord)(record)).to.equal(true);
|
|
93
|
+
});
|
|
94
|
+
it('Should find out that the record is a component record (f773 + LDR/07 "a")', () => {
|
|
95
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isComponentRecord/record2.json'), 'utf8');
|
|
96
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
97
|
+
(0, _chai.expect)((0, _utils.isComponentRecord)(record)).to.equal(true);
|
|
98
|
+
});
|
|
99
|
+
it('Should find out that the record is a component (LDR/07 "d")', () => {
|
|
100
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isComponentRecord/record3.json'), 'utf8');
|
|
101
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
102
|
+
(0, _chai.expect)((0, _utils.isComponentRecord)(record)).to.equal(true);
|
|
103
|
+
});
|
|
104
|
+
it('Should find out that the record is not a component record', () => {
|
|
105
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isComponentRecord/record4.json'), 'utf8');
|
|
106
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
107
|
+
(0, _chai.expect)((0, _utils.isComponentRecord)(record)).to.equal(false);
|
|
108
|
+
});
|
|
109
|
+
it('Should find out that the record is not a component record when ignoring collections', () => {
|
|
110
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isComponentRecord/record4.json'), 'utf8');
|
|
111
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
112
|
+
(0, _chai.expect)((0, _utils.isComponentRecord)(record, true)).to.equal(false);
|
|
113
|
+
});
|
|
114
|
+
it('Should find out that the record is not a component record when ignoring collections (LDR/07 "d")', () => {
|
|
115
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isComponentRecord/record5.json'), 'utf8');
|
|
116
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
117
|
+
(0, _chai.expect)((0, _utils.isComponentRecord)(record, true)).to.equal(false);
|
|
118
|
+
});
|
|
119
|
+
it('Should find out that the record is not a component record when ignoring collections (LDR/07 "c" and f773)', () => {
|
|
120
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isComponentRecord/record6.json'), 'utf8');
|
|
121
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
122
|
+
(0, _chai.expect)((0, _utils.isComponentRecord)(record, true)).to.equal(false);
|
|
123
|
+
});
|
|
124
|
+
it('Should find out that the record is a component record when using additional host fields (f973)', () => {
|
|
125
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isComponentRecord/record7.json'), 'utf8');
|
|
126
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
127
|
+
(0, _chai.expect)((0, _utils.isComponentRecord)(record, false, ['973'])).to.equal(true);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
88
130
|
describe('getRecordTitle', () => {
|
|
89
131
|
['Should find a title', 'Should not find a title'].forEach((descr, index) => {
|
|
90
132
|
it(descr, () => {
|
package/dist/utils.spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.spec.js","names":["_fs","_interopRequireDefault","require","_path","_chai","_marcRecord","_utils","MarcRecord","setValidationOptions","subfieldValues","FIXTURES_PATH","path","join","__dirname","describe","it","value","generateAuthorizationHeader","expect","to","equal","data","fs","readFileSync","record","JSON","parse","isDeletedRecord","parseBoolean","undefined","forEach","descr","index","title","recordData","getRecordTitle","identifiers","getRecordStandardIdentifiers","eql","obj","cloned","clone","not"],"sources":["../src/utils.spec.js"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {\n generateAuthorizationHeader, isDeletedRecord, parseBoolean, clone,\n getRecordTitle, getRecordStandardIdentifiers\n} from './utils';\n\nMarcRecord.setValidationOptions({subfieldValues: false});\n\nconst FIXTURES_PATH = path.join(__dirname, '../test-fixtures/utils');\n\ndescribe('utils', () => {\n describe('generateAuthorizationHeader', () => {\n it('Should create a proper Authorization header', () => {\n const value = generateAuthorizationHeader('foo', 'bar');\n expect(value).to.equal('Basic Zm9vOmJhcg==');\n });\n });\n\n describe('isDeletedRecord', () => {\n it('Should find the record deleted (Leader)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record1.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (DEL)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record2.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (STA)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record3.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record not deleted', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record4.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(false);\n });\n\n it('Should find the record deleted (Split)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record5.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (Deprecated)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record6.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (Split (Aleph))', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record7.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (Deprecated (Aleph))', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record8.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n });\n\n describe('parseBoolean', () => {\n it('Should parse undefined as false', () => {\n expect(parseBoolean(undefined)).to.equal(false);\n });\n\n it('Should parse zero-length string as false', () => {\n expect(parseBoolean('')).to.equal(false);\n });\n\n it('Should parse numericish value as true', () => {\n expect(parseBoolean('1')).to.equal(true);\n });\n\n it('Should parse numericush value as false', () => {\n expect(parseBoolean('0')).to.equal(false);\n });\n\n it('Should parse literal \\'false\\' value as false', () => {\n expect(parseBoolean('false')).to.equal(false);\n });\n\n it('Should parse non-numericish value as true', () => {\n expect(parseBoolean('foo')).to.equal(true);\n });\n\n it('Should parse literal \\'FALSE\\' value as false', () => {\n expect(parseBoolean('FALSE')).to.equal(false);\n });\n\n it('Should parse literal \\'FAlsE\\' value as false', () => {\n expect(parseBoolean('FAlsE')).to.equal(false);\n });\n\n });\n\n describe('getRecordTitle', () => {\n [\n 'Should find a title',\n 'Should not find a title'\n ].forEach((descr, index) => {\n it(descr, () => {\n const title = fs.readFileSync(path.join(FIXTURES_PATH, `getRecordTitle/title${index}.txt`), 'utf8');\n const recordData = fs.readFileSync(path.join(FIXTURES_PATH, `getRecordTitle/record${index}.json`), 'utf8');\n const record = new MarcRecord(JSON.parse(recordData));\n\n expect(getRecordTitle(record)).to.equal(title);\n });\n });\n });\n\n describe('getRecordStandardIdentifiers', () => {\n [\n 'Should find identifiers',\n 'Should not find an identifier'\n ].forEach((descr, index) => {\n it(descr, () => {\n const identifiers = JSON.parse(fs.readFileSync(path.join(FIXTURES_PATH, `getRecordStandardIdentifiers/identifiers${index}.json`), 'utf8'));\n const recordData = fs.readFileSync(path.join(FIXTURES_PATH, `getRecordStandardIdentifiers/record${index}.json`), 'utf8');\n const record = new MarcRecord(JSON.parse(recordData));\n\n expect(getRecordStandardIdentifiers(record)).to.eql(identifiers);\n });\n });\n });\n\n describe('clone', () => {\n it('Should clone an object', (index = '1') => {\n const obj = JSON.parse(fs.readFileSync(path.join(FIXTURES_PATH, `clone/${index}/obj.json`), 'utf8'));\n const cloned = clone(obj);\n\n expect(obj).to.not.equal(cloned);\n expect(cloned).to.eql(obj);\n });\n });\n});\n"],"mappings":";;;AAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAKAK,sBAAU,CAACC,oBAAoB,CAAC;EAACC,cAAc,EAAE;AAAK,CAAC,CAAC;AAExD,MAAMC,aAAa,GAAGC,aAAI,CAACC,IAAI,CAACC,SAAS,EAAE,wBAAwB,CAAC;AAEpEC,QAAQ,CAAC,OAAO,EAAE,MAAM;EACtBA,QAAQ,CAAC,6BAA6B,EAAE,MAAM;IAC5CC,EAAE,CAAC,6CAA6C,EAAE,MAAM;MACtD,MAAMC,KAAK,GAAG,IAAAC,kCAA2B,EAAC,KAAK,EAAE,KAAK,CAAC;MACvD,IAAAC,YAAM,EAACF,KAAK,CAAC,CAACG,EAAE,CAACC,KAAK,CAAC,oBAAoB,CAAC;IAC9C,CAAC,CAAC;EACJ,CAAC,CAAC;EAEFN,QAAQ,CAAC,iBAAiB,EAAE,MAAM;IAChCC,EAAE,CAAC,yCAAyC,EAAE,MAAM;MAClD,MAAMM,IAAI,GAAGC,WAAE,CAACC,YAAY,CAACZ,aAAI,CAACC,IAAI,CAACF,aA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B,YAAM,EAACsB,MAAM,CAAC,CAACrB,EAAE,CAACmB,GAAG,CAACC,GAAG,CAAC;IAC5B,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"utils.spec.js","names":["_fs","_interopRequireDefault","require","_path","_chai","_marcRecord","_utils","MarcRecord","setValidationOptions","subfieldValues","FIXTURES_PATH","path","join","__dirname","describe","it","value","generateAuthorizationHeader","expect","to","equal","data","fs","readFileSync","record","JSON","parse","isDeletedRecord","parseBoolean","undefined","isComponentRecord","forEach","descr","index","title","recordData","getRecordTitle","identifiers","getRecordStandardIdentifiers","eql","obj","cloned","clone","not"],"sources":["../src/utils.spec.js"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {\n generateAuthorizationHeader, isDeletedRecord, parseBoolean, clone,\n getRecordTitle, getRecordStandardIdentifiers, isComponentRecord\n} from './utils';\n\nMarcRecord.setValidationOptions({subfieldValues: false});\n\nconst FIXTURES_PATH = path.join(__dirname, '../test-fixtures/utils');\n\ndescribe('utils', () => {\n describe('generateAuthorizationHeader', () => {\n it('Should create a proper Authorization header', () => {\n const value = generateAuthorizationHeader('foo', 'bar');\n expect(value).to.equal('Basic Zm9vOmJhcg==');\n });\n });\n\n describe('isDeletedRecord', () => {\n it('Should find the record deleted (Leader)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record1.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (DEL)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record2.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (STA)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record3.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record not deleted', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record4.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(false);\n });\n\n it('Should find the record deleted (Split)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record5.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (Deprecated)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record6.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (Split (Aleph))', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record7.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (Deprecated (Aleph))', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record8.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n });\n\n describe('parseBoolean', () => {\n it('Should parse undefined as false', () => {\n expect(parseBoolean(undefined)).to.equal(false);\n });\n\n it('Should parse zero-length string as false', () => {\n expect(parseBoolean('')).to.equal(false);\n });\n\n it('Should parse numericish value as true', () => {\n expect(parseBoolean('1')).to.equal(true);\n });\n\n it('Should parse numericush value as false', () => {\n expect(parseBoolean('0')).to.equal(false);\n });\n\n it('Should parse literal \\'false\\' value as false', () => {\n expect(parseBoolean('false')).to.equal(false);\n });\n\n it('Should parse non-numericish value as true', () => {\n expect(parseBoolean('foo')).to.equal(true);\n });\n\n it('Should parse literal \\'FALSE\\' value as false', () => {\n expect(parseBoolean('FALSE')).to.equal(false);\n });\n\n it('Should parse literal \\'FAlsE\\' value as false', () => {\n expect(parseBoolean('FAlsE')).to.equal(false);\n });\n\n });\n\n describe('isComponentRecord', () => {\n it('Should find out that the record is a component record (f773)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record1.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isComponentRecord(record)).to.equal(true);\n });\n\n it('Should find out that the record is a component record (f773 + LDR/07 \"a\")', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record2.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isComponentRecord(record)).to.equal(true);\n });\n\n it('Should find out that the record is a component (LDR/07 \"d\")', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record3.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isComponentRecord(record)).to.equal(true);\n });\n\n it('Should find out that the record is not a component record', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record4.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isComponentRecord(record)).to.equal(false);\n });\n\n it('Should find out that the record is not a component record when ignoring collections', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record4.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isComponentRecord(record, true)).to.equal(false);\n });\n\n\n it('Should find out that the record is not a component record when ignoring collections (LDR/07 \"d\")', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record5.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isComponentRecord(record, true)).to.equal(false);\n });\n\n\n it('Should find out that the record is not a component record when ignoring collections (LDR/07 \"c\" and f773)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record6.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isComponentRecord(record, true)).to.equal(false);\n });\n\n it('Should find out that the record is a component record when using additional host fields (f973)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record7.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isComponentRecord(record, false, ['973'])).to.equal(true);\n });\n\n });\n\n\n describe('getRecordTitle', () => {\n [\n 'Should find a title',\n 'Should not find a title'\n ].forEach((descr, index) => {\n it(descr, () => {\n const title = fs.readFileSync(path.join(FIXTURES_PATH, `getRecordTitle/title${index}.txt`), 'utf8');\n const recordData = fs.readFileSync(path.join(FIXTURES_PATH, `getRecordTitle/record${index}.json`), 'utf8');\n const record = new MarcRecord(JSON.parse(recordData));\n\n expect(getRecordTitle(record)).to.equal(title);\n });\n });\n });\n\n describe('getRecordStandardIdentifiers', () => {\n [\n 'Should find identifiers',\n 'Should not find an identifier'\n ].forEach((descr, index) => {\n it(descr, () => {\n const identifiers = JSON.parse(fs.readFileSync(path.join(FIXTURES_PATH, `getRecordStandardIdentifiers/identifiers${index}.json`), 'utf8'));\n const recordData = fs.readFileSync(path.join(FIXTURES_PATH, `getRecordStandardIdentifiers/record${index}.json`), 'utf8');\n const record = new MarcRecord(JSON.parse(recordData));\n\n expect(getRecordStandardIdentifiers(record)).to.eql(identifiers);\n });\n });\n });\n\n describe('clone', () => {\n it('Should clone an object', (index = '1') => {\n const obj = JSON.parse(fs.readFileSync(path.join(FIXTURES_PATH, `clone/${index}/obj.json`), 'utf8'));\n const cloned = clone(obj);\n\n expect(obj).to.not.equal(cloned);\n expect(cloned).to.eql(obj);\n });\n });\n});\n"],"mappings":";;;AAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAKAK,sBAAU,CAACC,oBAAoB,CAAC;EAACC,cAAc,EAAE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CAAC;MAChC,IAAAvB,YAAM,EAACuB,MAAM,CAAC,CAACtB,EAAE,CAACoB,GAAG,CAACC,GAAG,CAAC;IAC5B,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
package/src/utils.js
CHANGED
|
@@ -28,6 +28,49 @@ export function isDeletedRecord(record) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
export function isComponentRecord(record, ignoreCollections = false, additionalHostFields = []) {
|
|
32
|
+
|
|
33
|
+
// Record is a component record if it has bibliografic level of a component in leader
|
|
34
|
+
// and/or has at least one host link field (f773)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// Ignore collections - optionally do not handle collections (LDR/07 'c')
|
|
38
|
+
// or collection subUnits (LDR/07 'd') as components, even if they do have f773
|
|
39
|
+
|
|
40
|
+
// https://www.loc.gov/marc/bibliographic/bdleader.html
|
|
41
|
+
// LDR/07
|
|
42
|
+
// c - Collection
|
|
43
|
+
// d - Subunit (in a collection)
|
|
44
|
+
|
|
45
|
+
if (ignoreCollections && ['c', 'd'].includes(record.leader[7])) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// https://www.loc.gov/marc/bibliographic/bdleader.html
|
|
50
|
+
// LDR/07
|
|
51
|
+
// a - Monographic component part
|
|
52
|
+
// b - Serial component part
|
|
53
|
+
// d - Subunit (in a collection)
|
|
54
|
+
|
|
55
|
+
if (['a', 'b', 'd'].includes(record.leader[7])) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// https://www.loc.gov/marc/bibliographic/bd773.html
|
|
60
|
+
// 773 - Host Item Entry (R)
|
|
61
|
+
|
|
62
|
+
// additionalHostFields (for example f973 for Viola's multihost componenets)
|
|
63
|
+
// optionally recognize fields given in additionalHostFields array as hostFields
|
|
64
|
+
|
|
65
|
+
const hostFields = additionalHostFields.concat('773');
|
|
66
|
+
const hostFieldPatternString = `^(${hostFields.join('|')})$`;
|
|
67
|
+
const hostFieldRegex = new RegExp(hostFieldPatternString, 'u');
|
|
68
|
+
|
|
69
|
+
const recordHasHostFields = record.get(hostFieldRegex).length > 0;
|
|
70
|
+
return recordHasHostFields;
|
|
71
|
+
//return record.get(/^773$/u).length > 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
31
74
|
export function parseBoolean(value) {
|
|
32
75
|
if (value === undefined) {
|
|
33
76
|
return false;
|
package/src/utils.spec.js
CHANGED
|
@@ -4,7 +4,7 @@ import {expect} from 'chai';
|
|
|
4
4
|
import {MarcRecord} from '@natlibfi/marc-record';
|
|
5
5
|
import {
|
|
6
6
|
generateAuthorizationHeader, isDeletedRecord, parseBoolean, clone,
|
|
7
|
-
getRecordTitle, getRecordStandardIdentifiers
|
|
7
|
+
getRecordTitle, getRecordStandardIdentifiers, isComponentRecord
|
|
8
8
|
} from './utils';
|
|
9
9
|
|
|
10
10
|
MarcRecord.setValidationOptions({subfieldValues: false});
|
|
@@ -104,6 +104,60 @@ describe('utils', () => {
|
|
|
104
104
|
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
+
describe('isComponentRecord', () => {
|
|
108
|
+
it('Should find out that the record is a component record (f773)', () => {
|
|
109
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record1.json'), 'utf8');
|
|
110
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
111
|
+
expect(isComponentRecord(record)).to.equal(true);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('Should find out that the record is a component record (f773 + LDR/07 "a")', () => {
|
|
115
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record2.json'), 'utf8');
|
|
116
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
117
|
+
expect(isComponentRecord(record)).to.equal(true);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('Should find out that the record is a component (LDR/07 "d")', () => {
|
|
121
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record3.json'), 'utf8');
|
|
122
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
123
|
+
expect(isComponentRecord(record)).to.equal(true);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('Should find out that the record is not a component record', () => {
|
|
127
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record4.json'), 'utf8');
|
|
128
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
129
|
+
expect(isComponentRecord(record)).to.equal(false);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('Should find out that the record is not a component record when ignoring collections', () => {
|
|
133
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record4.json'), 'utf8');
|
|
134
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
135
|
+
expect(isComponentRecord(record, true)).to.equal(false);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
it('Should find out that the record is not a component record when ignoring collections (LDR/07 "d")', () => {
|
|
140
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record5.json'), 'utf8');
|
|
141
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
142
|
+
expect(isComponentRecord(record, true)).to.equal(false);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
it('Should find out that the record is not a component record when ignoring collections (LDR/07 "c" and f773)', () => {
|
|
147
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record6.json'), 'utf8');
|
|
148
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
149
|
+
expect(isComponentRecord(record, true)).to.equal(false);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('Should find out that the record is a component record when using additional host fields (f973)', () => {
|
|
153
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record7.json'), 'utf8');
|
|
154
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
155
|
+
expect(isComponentRecord(record, false, ['973'])).to.equal(true);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
|
|
107
161
|
describe('getRecordTitle', () => {
|
|
108
162
|
[
|
|
109
163
|
'Should find a title',
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"leader": "01864cam a2200529zi 4500",
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"tag": "001",
|
|
6
|
+
"value": "000001234"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"tag": "245",
|
|
10
|
+
"ind1": " ",
|
|
11
|
+
"ind2": " ",
|
|
12
|
+
"subfields": [
|
|
13
|
+
{
|
|
14
|
+
"code": "a",
|
|
15
|
+
"value": "foobar"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"tag": "773",
|
|
21
|
+
"ind1": " ",
|
|
22
|
+
"ind2": " ",
|
|
23
|
+
"subfields": [
|
|
24
|
+
{
|
|
25
|
+
"code": "a",
|
|
26
|
+
"value": "foobar"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"code": "w",
|
|
30
|
+
"value": "[hostID]"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"leader": "01864caa a2200529zi 4500",
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"tag": "001",
|
|
6
|
+
"value": "000001234"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"tag": "245",
|
|
10
|
+
"ind1": " ",
|
|
11
|
+
"ind2": " ",
|
|
12
|
+
"subfields": [
|
|
13
|
+
{
|
|
14
|
+
"code": "a",
|
|
15
|
+
"value": "foobar"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"tag": "773",
|
|
21
|
+
"ind1": " ",
|
|
22
|
+
"ind2": " ",
|
|
23
|
+
"subfields": [
|
|
24
|
+
{
|
|
25
|
+
"code": "a",
|
|
26
|
+
"value": "foobar"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"code": "w",
|
|
30
|
+
"value": "[hostID]"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"leader": "01864cac a2200529zi 4500",
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"tag": "001",
|
|
6
|
+
"value": "000001234"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"tag": "245",
|
|
10
|
+
"ind1": " ",
|
|
11
|
+
"ind2": " ",
|
|
12
|
+
"subfields": [
|
|
13
|
+
{
|
|
14
|
+
"code": "a",
|
|
15
|
+
"value": "foobar"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"tag": "773",
|
|
21
|
+
"ind1": " ",
|
|
22
|
+
"ind2": " ",
|
|
23
|
+
"subfields": [
|
|
24
|
+
{
|
|
25
|
+
"code": "a",
|
|
26
|
+
"value": "foobar"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"code": "w",
|
|
30
|
+
"value": "[hostID]"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"leader": "01864cam a2200529zi 4500",
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"tag": "001",
|
|
6
|
+
"value": "000001234"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"tag": "245",
|
|
10
|
+
"ind1": " ",
|
|
11
|
+
"ind2": " ",
|
|
12
|
+
"subfields": [
|
|
13
|
+
{
|
|
14
|
+
"code": "a",
|
|
15
|
+
"value": "foobar"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"tag": "973",
|
|
21
|
+
"ind1": " ",
|
|
22
|
+
"ind2": " ",
|
|
23
|
+
"subfields": [
|
|
24
|
+
{
|
|
25
|
+
"code": "a",
|
|
26
|
+
"value": "foobar"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"code": "w",
|
|
30
|
+
"value": "[hostID]"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|