@natlibfi/melinda-record-matching 2.2.0-alpha.4 → 2.2.1-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/.github/CODEOWNERS +10 -0
- package/.github/dependabot.yml +40 -0
- package/.github/workflows/melinda-node-tests.yml +70 -0
- package/package.json +1 -1
- package/dist/candidate-search/candidate-search-utils.js +0 -58
- package/dist/candidate-search/candidate-search-utils.js.map +0 -1
- package/dist/candidate-search/index.js +0 -273
- package/dist/candidate-search/index.js.map +0 -1
- package/dist/candidate-search/index.spec.js +0 -161
- package/dist/candidate-search/index.spec.js.map +0 -1
- package/dist/candidate-search/query-list/bib.js +0 -252
- package/dist/candidate-search/query-list/bib.js.map +0 -1
- package/dist/candidate-search/query-list/bib.spec.js +0 -72
- package/dist/candidate-search/query-list/bib.spec.js.map +0 -1
- package/dist/candidate-search/query-list/index.js +0 -67
- package/dist/candidate-search/query-list/index.js.map +0 -1
- package/dist/index.js +0 -578
- package/dist/index.js.map +0 -1
- package/dist/index.spec.js +0 -133
- package/dist/index.spec.js.map +0 -1
- package/dist/match-detection/features/bib/all-source-ids.js +0 -122
- package/dist/match-detection/features/bib/all-source-ids.js.map +0 -1
- package/dist/match-detection/features/bib/authors.js +0 -117
- package/dist/match-detection/features/bib/authors.js.map +0 -1
- package/dist/match-detection/features/bib/bibliographic-level.js +0 -42
- package/dist/match-detection/features/bib/bibliographic-level.js.map +0 -1
- package/dist/match-detection/features/bib/host-component.js +0 -42
- package/dist/match-detection/features/bib/host-component.js.map +0 -1
- package/dist/match-detection/features/bib/index.js +0 -104
- package/dist/match-detection/features/bib/index.js.map +0 -1
- package/dist/match-detection/features/bib/index.spec.js +0 -97
- package/dist/match-detection/features/bib/index.spec.js.map +0 -1
- package/dist/match-detection/features/bib/isbn.js +0 -55
- package/dist/match-detection/features/bib/isbn.js.map +0 -1
- package/dist/match-detection/features/bib/issn.js +0 -55
- package/dist/match-detection/features/bib/issn.js.map +0 -1
- package/dist/match-detection/features/bib/language.js +0 -113
- package/dist/match-detection/features/bib/language.js.map +0 -1
- package/dist/match-detection/features/bib/melinda-id.js +0 -52
- package/dist/match-detection/features/bib/melinda-id.js.map +0 -1
- package/dist/match-detection/features/bib/melinda-identifier-factory.js +0 -100
- package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +0 -1
- package/dist/match-detection/features/bib/other-standard-identifier.js +0 -55
- package/dist/match-detection/features/bib/other-standard-identifier.js.map +0 -1
- package/dist/match-detection/features/bib/publication-time.js +0 -47
- package/dist/match-detection/features/bib/publication-time.js.map +0 -1
- package/dist/match-detection/features/bib/record-type.js +0 -42
- package/dist/match-detection/features/bib/record-type.js.map +0 -1
- package/dist/match-detection/features/bib/standard-identifier-factory.js +0 -126
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +0 -1
- package/dist/match-detection/features/bib/title.js +0 -91
- package/dist/match-detection/features/bib/title.js.map +0 -1
- package/dist/match-detection/features/index.js +0 -15
- package/dist/match-detection/features/index.js.map +0 -1
- package/dist/match-detection/index.js +0 -184
- package/dist/match-detection/index.js.map +0 -1
- package/dist/match-detection/index.spec.js +0 -99
- package/dist/match-detection/index.spec.js.map +0 -1
- package/dist/matching-utils.js +0 -95
- package/dist/matching-utils.js.map +0 -1
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
4
|
-
|
|
5
|
-
var _fixura = require("@natlibfi/fixura");
|
|
6
|
-
|
|
7
|
-
var _chai = require("chai");
|
|
8
|
-
|
|
9
|
-
var _marcRecord = require("@natlibfi/marc-record");
|
|
10
|
-
|
|
11
|
-
var features = _interopRequireWildcard(require("./features"));
|
|
12
|
-
|
|
13
|
-
var _ = _interopRequireDefault(require("."));
|
|
14
|
-
|
|
15
|
-
var _util = require("util");
|
|
16
|
-
|
|
17
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
18
|
-
|
|
19
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
20
|
-
|
|
21
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
22
|
-
|
|
23
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
28
|
-
*
|
|
29
|
-
* Melinda record matching modules for Javascript
|
|
30
|
-
*
|
|
31
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
32
|
-
*
|
|
33
|
-
* This file is part of melinda-record-matching-js
|
|
34
|
-
*
|
|
35
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
36
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
37
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
38
|
-
* License, or (at your option) any later version.
|
|
39
|
-
*
|
|
40
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
41
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
42
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
43
|
-
* GNU Lesser General Public License for more details.
|
|
44
|
-
*
|
|
45
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
46
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
47
|
-
*
|
|
48
|
-
* @licend The above is the entire license notice
|
|
49
|
-
* for the JavaScript code in this file.
|
|
50
|
-
*
|
|
51
|
-
*/
|
|
52
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:test');
|
|
53
|
-
const debugData = debug.extend('data');
|
|
54
|
-
describe('match-detection', () => {
|
|
55
|
-
(0, _fixugen.default)({
|
|
56
|
-
path: [__dirname, '..', '..', 'test-fixtures', 'match-detection', 'index'],
|
|
57
|
-
useMetadataFile: true,
|
|
58
|
-
recurse: false,
|
|
59
|
-
fixura: {
|
|
60
|
-
reader: _fixura.READERS.JSON
|
|
61
|
-
},
|
|
62
|
-
callback: ({
|
|
63
|
-
getFixture,
|
|
64
|
-
options,
|
|
65
|
-
expectedResults,
|
|
66
|
-
array,
|
|
67
|
-
enabled = true
|
|
68
|
-
}) => {
|
|
69
|
-
if (!enabled) {
|
|
70
|
-
debug(`*** DISABLED TEST! ***`);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const detect = (0, _.default)(formatOptions());
|
|
75
|
-
const recordA = new _marcRecord.MarcRecord(getFixture('recordA.json'), {
|
|
76
|
-
subfieldValues: false
|
|
77
|
-
});
|
|
78
|
-
debugData((0, _util.inspect)(recordA));
|
|
79
|
-
debug(`Our recordB is an array of records: ${array}`);
|
|
80
|
-
const recordB = array ? getFixture('recordB.json').map(recordJson => new _marcRecord.MarcRecord(recordJson, {
|
|
81
|
-
subfieldValues: false
|
|
82
|
-
})) : new _marcRecord.MarcRecord(getFixture('recordB.json'), {
|
|
83
|
-
subfieldValues: false
|
|
84
|
-
});
|
|
85
|
-
debugData((0, _util.inspect)(recordB));
|
|
86
|
-
const results = detect(recordA, recordB);
|
|
87
|
-
debugData(`${JSON.stringify(results)}`);
|
|
88
|
-
(0, _chai.expect)(results).to.eql(expectedResults);
|
|
89
|
-
|
|
90
|
-
function formatOptions() {
|
|
91
|
-
const contextFeatures = features[options.strategy.type];
|
|
92
|
-
return { ...options,
|
|
93
|
-
strategy: options.strategy.features.map(v => contextFeatures[v]())
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
//# sourceMappingURL=index.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.spec.js","names":["debug","createDebugLogger","debugData","extend","describe","generateTests","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","callback","getFixture","options","expectedResults","array","enabled","detect","createDetectionInterface","formatOptions","recordA","MarcRecord","subfieldValues","inspect","recordB","map","recordJson","results","stringify","expect","to","eql","contextFeatures","features","strategy","type","v"],"sources":["../../src/match-detection/index.spec.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport generateTests from '@natlibfi/fixugen';\nimport {READERS} from '@natlibfi/fixura';\nimport {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport * as features from './features';\nimport createDetectionInterface from '.';\nimport {inspect} from 'util';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:test');\nconst debugData = debug.extend('data');\n\ndescribe('match-detection', () => {\n generateTests({\n path: [__dirname, '..', '..', 'test-fixtures', 'match-detection', 'index'],\n useMetadataFile: true,\n recurse: false,\n fixura: {\n reader: READERS.JSON\n },\n callback: ({getFixture, options, expectedResults, array, enabled = true}) => {\n\n if (!enabled) {\n debug(`*** DISABLED TEST! ***`);\n return;\n }\n\n const detect = createDetectionInterface(formatOptions());\n const recordA = new MarcRecord(getFixture('recordA.json'), {subfieldValues: false});\n debugData(inspect(recordA));\n\n debug(`Our recordB is an array of records: ${array}`);\n const recordB = array\n ? getFixture('recordB.json').map(recordJson => new MarcRecord(recordJson, {subfieldValues: false}))\n : new MarcRecord(getFixture('recordB.json'), {subfieldValues: false});\n debugData(inspect(recordB));\n\n const results = detect(recordA, recordB);\n debugData(`${JSON.stringify(results)}`);\n\n expect(results).to.eql(expectedResults);\n\n function formatOptions() {\n const contextFeatures = features[options.strategy.type];\n\n return {\n ...options,\n strategy: options.strategy.features.map(v => contextFeatures[v]())\n };\n }\n }\n });\n});\n"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAnCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAWA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAkB,wDAAlB,CAAd;AACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB;AAEAC,QAAQ,CAAC,iBAAD,EAAoB,MAAM;EAChC,IAAAC,gBAAA,EAAc;IACZC,IAAI,EAAE,CAACC,SAAD,EAAY,IAAZ,EAAkB,IAA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EA,SAASK,aAAT,GAAyB;QACvB,MAAMa,eAAe,GAAGC,QAAQ,CAACpB,OAAO,CAACqB,QAAR,CAAiBC,IAAlB,CAAhC;QAEA,OAAO,EACL,GAAGtB,OADE;UAELqB,QAAQ,EAAErB,OAAO,CAACqB,QAAR,CAAiBD,QAAjB,CAA0BR,GAA1B,CAA8BW,CAAC,IAAIJ,eAAe,CAACI,CAAD,CAAf,EAAnC;QAFL,CAAP;MAID;IACF;EArCW,CAAd;AAuCD,CAxCO,CAAR"}
|
package/dist/matching-utils.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getMelindaIdsF035 = getMelindaIdsF035;
|
|
7
|
-
exports.getSubfieldValues = getSubfieldValues;
|
|
8
|
-
exports.validateSidFieldSubfieldCounts = validateSidFieldSubfieldCounts;
|
|
9
|
-
|
|
10
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
17
|
-
*
|
|
18
|
-
* Melinda record matching modules for Javascript
|
|
19
|
-
*
|
|
20
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
21
|
-
*
|
|
22
|
-
* This file is part of melinda-record-matching-js
|
|
23
|
-
*
|
|
24
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
25
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
26
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
27
|
-
* License, or (at your option) any later version.
|
|
28
|
-
*
|
|
29
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
30
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
31
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
32
|
-
* GNU Lesser General Public License for more details.
|
|
33
|
-
*
|
|
34
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
35
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
36
|
-
*
|
|
37
|
-
* @licend The above is the entire license notice
|
|
38
|
-
* for the JavaScript code in this file.
|
|
39
|
-
*
|
|
40
|
-
*/
|
|
41
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:utils');
|
|
42
|
-
const debugData = debug.extend('data'); // eslint-disable-next-line max-statements
|
|
43
|
-
|
|
44
|
-
function getMelindaIdsF035(record) {
|
|
45
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:melinda-id');
|
|
46
|
-
const debugData = debug.extend('data');
|
|
47
|
-
const f035s = record.getFields('035');
|
|
48
|
-
|
|
49
|
-
if (f035s.length < 1) {
|
|
50
|
-
debug(`No f035s found.`);
|
|
51
|
-
return [];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const allF035MelindaIds = [].concat(...f035s.map(toMelindaIds));
|
|
55
|
-
const f035MelindaIds = [...new Set(allF035MelindaIds)];
|
|
56
|
-
debugData(`Fields (${f035s.length}): ${JSON.stringify(f035s)}`);
|
|
57
|
-
debugData(`Ids (${allF035MelindaIds.length}): ${JSON.stringify(allF035MelindaIds)}`);
|
|
58
|
-
debugData(`Unique ids (${f035MelindaIds.length}): ${JSON.stringify(f035MelindaIds)}`);
|
|
59
|
-
return f035MelindaIds;
|
|
60
|
-
|
|
61
|
-
function toMelindaIds({
|
|
62
|
-
subfields
|
|
63
|
-
}) {
|
|
64
|
-
const melindaIdRegExp = /^(?<prefix>\(FI-MELINDA\)|FCC)(?<id>\d{9})$/u;
|
|
65
|
-
return subfields.filter(sub => ['a', 'z'].includes(sub.code)).filter(sub => melindaIdRegExp.test(sub.value)).map(({
|
|
66
|
-
value
|
|
67
|
-
}) => value ? value.replace(melindaIdRegExp, '$<id>') : '');
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function validateSidFieldSubfieldCounts(field) {
|
|
72
|
-
// Valid SID-fields have just one $c and one $b
|
|
73
|
-
debugData(`Validating SID field ${JSON.stringify(field)}`);
|
|
74
|
-
const countC = countSubfields(field, 'c');
|
|
75
|
-
const countB = countSubfields(field, 'b');
|
|
76
|
-
debug(`Found ${countC} sf $cs and ${countB} sf $bs. IsValid: ${countC === 1 && countB === 1}`);
|
|
77
|
-
return countC === 1 && countB === 1;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function countSubfields(field, subfieldCode) {
|
|
81
|
-
// debug(`Counting subfields ${subfieldCode}`);
|
|
82
|
-
return field.subfields.filter(({
|
|
83
|
-
code
|
|
84
|
-
}) => code === subfieldCode).length;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function getSubfieldValues(field, subfieldCode) {
|
|
88
|
-
debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);
|
|
89
|
-
return field.subfields.filter(({
|
|
90
|
-
code
|
|
91
|
-
}) => code === subfieldCode).map(({
|
|
92
|
-
value
|
|
93
|
-
}) => value);
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=matching-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"matching-utils.js","names":["debug","createDebugLogger","debugData","extend","getMelindaIdsF035","record","f035s","getFields","length","allF035MelindaIds","concat","map","toMelindaIds","f035MelindaIds","Set","JSON","stringify","subfields","melindaIdRegExp","filter","sub","includes","code","test","value","replace","validateSidFieldSubfieldCounts","field","countC","countSubfields","countB","subfieldCode","getSubfieldValues"],"sources":["../src/matching-utils.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:utils');\nconst debugData = debug.extend('data');\n\n// eslint-disable-next-line max-statements\nexport function getMelindaIdsF035(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:melinda-id');\n const debugData = debug.extend('data');\n\n const f035s = record.getFields('035');\n\n if (f035s.length < 1) {\n debug(`No f035s found.`);\n return [];\n }\n\n const allF035MelindaIds = [].concat(...f035s.map(toMelindaIds));\n const f035MelindaIds = [...new Set(allF035MelindaIds)];\n\n debugData(`Fields (${f035s.length}): ${JSON.stringify(f035s)}`);\n debugData(`Ids (${allF035MelindaIds.length}): ${JSON.stringify(allF035MelindaIds)}`);\n debugData(`Unique ids (${f035MelindaIds.length}): ${JSON.stringify(f035MelindaIds)}`);\n\n return f035MelindaIds;\n\n function toMelindaIds({subfields}) {\n const melindaIdRegExp = /^(?<prefix>\\(FI-MELINDA\\)|FCC)(?<id>\\d{9})$/u;\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code))\n .filter(sub => melindaIdRegExp.test(sub.value))\n .map(({value}) => value ? value.replace(melindaIdRegExp, '$<id>') : '');\n\n }\n}\n\nexport function validateSidFieldSubfieldCounts(field) {\n // Valid SID-fields have just one $c and one $b\n debugData(`Validating SID field ${JSON.stringify(field)}`);\n const countC = countSubfields(field, 'c');\n const countB = countSubfields(field, 'b');\n debug(`Found ${countC} sf $cs and ${countB} sf $bs. IsValid: ${countC === 1 && countB === 1}`);\n\n return countC === 1 && countB === 1;\n}\n\nfunction countSubfields(field, subfieldCode) {\n // debug(`Counting subfields ${subfieldCode}`);\n return field.subfields.filter(({code}) => code === subfieldCode).length;\n}\n\nexport function getSubfieldValues(field, subfieldCode) {\n debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);\n return field.subfields.filter(({code}) => code === subfieldCode).map(({value}) => value);\n}\n\n"],"mappings":";;;;;;;;;AA4BA;;;;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAkB,yCAAlB,CAAd;AACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB,C,CAEA;;AACO,SAASC,iBAAT,CAA2BC,MAA3B,EAAmC;EAExC,MAAML,KAAK,GAAG,IAAAC,cAAA,EAAkB,8CAAlB,CAAd;EACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB;EAEA,MAAMG,KAAK,GAAGD,MAAM,CAACE,SAAP,CAAiB,KAAjB,CAAd;;EAEA,IAAID,KAAK,CAACE,MAAN,GAAe,CAAnB,EAAsB;IACpBR,KAAK,CAAE,iBAAF,CAAL;IACA,OAAO,EAAP;EACD;;EAED,MAAMS,iBAAiB,GAAG,GAAGC,MAAH,CAAU,GAAGJ,KAAK,CAACK,GAAN,CAAUC,YAAV,CAAb,CAA1B;EACA,MAAMC,cAAc,GAAG,CAAC,GAAG,IAAIC,GAAJ,CAAQL,iBAAR,CAAJ,CAAvB;EAEAP,SAAS,CAAE,WAAUI,KAAK,CAACE,MAAO,MAAKO,IAAI,CAACC,SAAL,CAAeV,KAAf,CAAsB,EAApD,CAAT;EACAJ,SA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