@natlibfi/marc-record-merge 6.0.0-beta.2 → 6.0.0-beta.6
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 +9 -0
- package/.github/dependabot.yml +41 -0
- package/.github/workflows/melinda-node-tests.yml +60 -0
- package/LICENSE +21 -0
- package/README.md +106 -2
- package/dist/index.js +2 -37
- package/dist/index.js.map +1 -1
- package/dist/reducers/copy.js +310 -109
- package/dist/reducers/copy.js.map +1 -1
- package/dist/reducers/copy.spec.js +52 -99
- package/dist/reducers/copy.spec.js.map +1 -1
- package/dist/reducers/index.js +0 -27
- package/dist/reducers/index.js.map +1 -1
- package/dist/reducers/select.js +12 -50
- package/dist/reducers/select.js.map +1 -1
- package/dist/reducers/select.spec.js +49 -83
- package/dist/reducers/select.spec.js.map +1 -1
- package/package.json +30 -27
- package/src/index.js +1 -33
- package/src/reducers/copy.js +306 -115
- package/src/reducers/copy.spec.js +44 -66
- package/src/reducers/index.js +0 -27
- package/src/reducers/select.js +8 -51
- package/src/reducers/select.spec.js +37 -58
- package/test-fixtures/reducers/copy/{01/base.json → 01 - copy/01/base.json } +1 -1
- package/test-fixtures/reducers/copy/{01 → 01 - copy/01}/merged.json +0 -0
- package/test-fixtures/reducers/copy/01 - copy/01/metadata.json +4 -0
- package/test-fixtures/reducers/copy/{01 → 01 - copy/01}/source.json +0 -0
- package/test-fixtures/reducers/copy/{02/source.json → 01 - copy/02/base.json} +0 -0
- package/test-fixtures/reducers/copy/{02 → 01 - copy/02}/merged.json +0 -0
- package/test-fixtures/reducers/copy/01 - copy/02/metadata.json +4 -0
- package/test-fixtures/reducers/copy/{02/base.json → 01 - copy/02/source.json } +1 -1
- package/test-fixtures/reducers/copy/{03/base.json → 01 - copy/03/base.json } +1 -1
- package/test-fixtures/reducers/copy/{03 → 01 - copy/03}/merged.json +0 -0
- package/test-fixtures/reducers/copy/01 - copy/03/metadata.json +4 -0
- package/test-fixtures/reducers/copy/{03 → 01 - copy/03}/source.json +0 -0
- package/test-fixtures/reducers/copy/{05/base.json → 01 - copy/04/base.json } +1 -1
- package/test-fixtures/reducers/copy/{04/merged.json → 01 - copy/04/merged.json } +1 -1
- package/test-fixtures/reducers/copy/01 - copy/04/metadata.json +4 -0
- package/test-fixtures/reducers/copy/{04/source.json → 01 - copy/04/source.json } +1 -1
- package/test-fixtures/reducers/copy/{04/base.json → 01 - copy/05/base.json } +1 -1
- package/test-fixtures/reducers/copy/{05 → 01 - copy/05}/merged.json +0 -0
- package/test-fixtures/reducers/copy/01 - copy/05/metadata.json +4 -0
- package/test-fixtures/reducers/copy/{05 → 01 - copy/05}/source.json +0 -0
- package/test-fixtures/reducers/copy/01 - copy/06/base.json +24 -0
- package/test-fixtures/reducers/copy/01 - copy/06/merged.json +39 -0
- package/test-fixtures/reducers/copy/01 - copy/06/metadata.json +4 -0
- package/test-fixtures/reducers/copy/01 - copy/06/source.json +24 -0
- package/test-fixtures/reducers/copy/01 - copy/07/base.json +39 -0
- package/test-fixtures/reducers/copy/01 - copy/07/merged.json +39 -0
- package/test-fixtures/reducers/copy/01 - copy/07/metadata.json +5 -0
- package/test-fixtures/reducers/copy/01 - copy/07/source.json +24 -0
- package/test-fixtures/reducers/copy/01 - copy/08/base.json +28 -0
- package/test-fixtures/reducers/copy/01 - copy/08/merged.json +28 -0
- package/test-fixtures/reducers/copy/01 - copy/08/metadata.json +4 -0
- package/test-fixtures/reducers/copy/01 - copy/08/source.json +24 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/base.json +17 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/merged.json +20 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/metadata.json +6 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/source.json +20 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/base.json +9 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/merged.json +20 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/metadata.json +6 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/source.json +20 -0
- package/test-fixtures/reducers/copy/{06 → 03 - compareTagsOnly/01}/base.json +0 -0
- package/test-fixtures/reducers/copy/{06 → 03 - compareTagsOnly/01}/merged.json +0 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/01/metadata.json +5 -0
- package/test-fixtures/reducers/copy/{06 → 03 - compareTagsOnly/01}/source.json +0 -0
- package/test-fixtures/reducers/copy/{09 → 03 - compareTagsOnly/02}/base.json +0 -0
- package/test-fixtures/reducers/copy/{09 → 03 - compareTagsOnly/02}/merged.json +0 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/02/metadata.json +5 -0
- package/test-fixtures/reducers/copy/{09 → 03 - compareTagsOnly/02}/source.json +0 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/base.json +24 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/merged.json +24 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/metadata.json +5 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/source.json +24 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/base.json +24 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/merged.json +39 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/metadata.json +5 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/source.json +24 -0
- package/test-fixtures/reducers/copy/05 - copyUnless/01/base.json +9 -0
- package/test-fixtures/reducers/copy/05 - copyUnless/01/merged.json +24 -0
- package/test-fixtures/reducers/copy/05 - copyUnless/01/metadata.json +5 -0
- package/test-fixtures/reducers/copy/05 - copyUnless/01/source.json +47 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/base.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/merged.json +39 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/metadata.json +5 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/source.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/base.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/merged.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/metadata.json +5 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/source.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/base.json +28 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/merged.json +43 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/metadata.json +5 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/source.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/base.json +28 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/merged.json +28 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/metadata.json +5 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/source.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/base.json +20 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/merged.json +35 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/metadata.json +5 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/source.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/base.json +20 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/merged.json +35 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/metadata.json +5 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/source.json +24 -0
- package/test-fixtures/reducers/copy/{07 → 07 - excludeSubfields/01}/base.json +0 -0
- package/test-fixtures/reducers/copy/{07 → 07 - excludeSubfields/01}/merged.json +0 -0
- package/test-fixtures/reducers/copy/07 - excludeSubfields/01/metadata.json +8 -0
- package/test-fixtures/reducers/copy/{07 → 07 - excludeSubfields/01}/source.json +0 -0
- package/test-fixtures/reducers/copy/07 - excludeSubfields/02/base.json +39 -0
- package/test-fixtures/reducers/copy/07 - excludeSubfields/02/merged.json +58 -0
- package/test-fixtures/reducers/copy/07 - excludeSubfields/02/metadata.json +5 -0
- package/test-fixtures/reducers/copy/07 - excludeSubfields/02/source.json +43 -0
- package/test-fixtures/reducers/copy/{08 → 08 - dropSubfields/01}/base.json +0 -0
- package/test-fixtures/reducers/copy/{08/merged.json → 08 - dropSubfields/01/merged.json } +8 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/01/metadata.json +5 -0
- package/test-fixtures/reducers/copy/{08 → 08 - dropSubfields/01}/source.json +0 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/02/base.json +43 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/02/merged.json +58 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/02/metadata.json +5 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/02/source.json +32 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/03/base.json +43 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/03/merged.json +58 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/03/metadata.json +5 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/03/source.json +32 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/04/base.json +43 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/04/merged.json +43 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/04/metadata.json +5 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/04/source.json +32 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/base.json +9 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/merged.json +20 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/metadata.json +6 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/source.json +20 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/base.json +9 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/merged.json +20 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/metadata.json +6 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/source.json +20 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/base.json +9 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/merged.json +31 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/metadata.json +6 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/source.json +31 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/base.json +9 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/merged.json +42 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/metadata.json +6 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/source.json +42 -0
- package/test-fixtures/reducers/copy/10 - swapTag/01/base.json +17 -0
- package/test-fixtures/reducers/copy/10 - swapTag/01/merged.json +28 -0
- package/test-fixtures/reducers/copy/10 - swapTag/01/metadata.json +6 -0
- package/test-fixtures/reducers/copy/10 - swapTag/01/source.json +20 -0
- package/test-fixtures/reducers/metadata.json +4 -0
- package/test-fixtures/reducers/select/01/metadata.json +5 -0
- package/test-fixtures/reducers/select/02/metadata.json +4 -0
- package/test-fixtures/reducers/select/03/metadata.json +4 -0
- package/test-fixtures/reducers/select/04/metadata.json +5 -0
- package/test-fixtures/reducers/select/05/metadata.json +4 -0
- package/test-fixtures/reducers/select/06/metadata.json +4 -0
- package/test-fixtures/reducers/select/07/metadata.json +5 -0
- package/test-fixtures/reducers/select/08/metadata.json +4 -0
- package/test-fixtures/reducers/select/09/metadata.json +4 -0
- package/test-fixtures/reducers/select/10/metadata.json +5 -0
- package/test-fixtures/reducers/select/11/metadata.json +4 -0
- package/test-fixtures/reducers/select/12/metadata.json +5 -0
- package/test-fixtures/reducers/select/13/metadata.json +4 -0
- package/test-fixtures/reducers/select/14/metadata.json +4 -0
- package/.drone.yml +0 -92
- package/.nyc_output/72717fff-b4ac-4aef-a145-37cae88e07f8.json +0 -1
- package/.nyc_output/processinfo/72717fff-b4ac-4aef-a145-37cae88e07f8.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/LICENSE.txt +0 -165
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -79
- package/coverage/copy.js.html +0 -500
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -126
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -79
- package/coverage/lcov-report/copy.js.html +0 -500
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -126
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/select.js.html +0 -539
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov.info +0 -274
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/select.js.html +0 -539
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -170
- package/test-fixtures/reducers/copy/01/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/02/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/03/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/04/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/05/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/06/compareTagsOnly.txt +0 -1
- package/test-fixtures/reducers/copy/06/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/07/excludeSubfields.json +0 -1
- package/test-fixtures/reducers/copy/07/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/08/dropSubfields.json +0 -1
- package/test-fixtures/reducers/copy/08/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/09/compareTagsOnly.txt +0 -1
- package/test-fixtures/reducers/copy/09/tagPattern.txt +0 -1
- package/test-fixtures/reducers/select/01/expected-error.txt +0 -1
- package/test-fixtures/reducers/select/01/pattern.txt +0 -1
- package/test-fixtures/reducers/select/02/pattern.txt +0 -1
- package/test-fixtures/reducers/select/03/pattern.txt +0 -1
- package/test-fixtures/reducers/select/04/pattern.txt +0 -1
- package/test-fixtures/reducers/select/05/pattern.txt +0 -1
- package/test-fixtures/reducers/select/06/pattern.txt +0 -1
- package/test-fixtures/reducers/select/07/equalityFunction.txt +0 -1
- package/test-fixtures/reducers/select/07/pattern.txt +0 -1
- package/test-fixtures/reducers/select/08/pattern.txt +0 -1
- package/test-fixtures/reducers/select/09/pattern.txt +0 -1
- package/test-fixtures/reducers/select/10/equalityFunction.txt +0 -1
- package/test-fixtures/reducers/select/10/pattern.txt +0 -1
- package/test-fixtures/reducers/select/11/pattern.txt +0 -1
- package/test-fixtures/reducers/select/12/equalityFunction.txt +0 -1
- package/test-fixtures/reducers/select/12/pattern.txt +0 -1
- package/test-fixtures/reducers/select/13/pattern.txt +0 -1
- package/test-fixtures/reducers/select/14/pattern.txt +0 -1
package/package.json
CHANGED
|
@@ -13,44 +13,50 @@
|
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "git@github.com:natlibfi/marc-record-merge-js.git"
|
|
15
15
|
},
|
|
16
|
-
"license": "
|
|
17
|
-
"version": "6.0.0-beta.
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"version": "6.0.0-beta.6",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"engines": {
|
|
20
|
-
"node": ">=
|
|
20
|
+
"node": ">=14"
|
|
21
21
|
},
|
|
22
|
+
"type": "commonjs",
|
|
22
23
|
"scripts": {
|
|
24
|
+
"prepare": "npm run build",
|
|
23
25
|
"prepublishOnly": "npm run build:transpile",
|
|
24
26
|
"lint": "eslint ./src",
|
|
25
27
|
"lint:dev": "eslint ./src --fix",
|
|
26
|
-
"test:base": "cross-env NODE_ENV=test
|
|
27
|
-
"test": "npm run lint && npm run test:base
|
|
28
|
-
"test:dev": "npm run lint:dev && npm run
|
|
29
|
-
"coverage": "
|
|
28
|
+
"test:base": "cross-env NODE_ENV=test mocha --require @babel/register --reporter-option maxDiffSize=15000 src/reducers/*.spec.js",
|
|
29
|
+
"test": "npm run lint && npm run test:base",
|
|
30
|
+
"test:dev": "npm run lint:dev && npm run coverage",
|
|
31
|
+
"coverage": "npm run coverage:unit && npm run coverage:report",
|
|
32
|
+
"coverage:unit": "nyc --silent npm run test:base",
|
|
33
|
+
"coverage:report": "nyc report",
|
|
30
34
|
"build:transpile": "babel src --copy-files --source-maps --delete-dir-on-start --out-dir=dist",
|
|
31
35
|
"build": "npm run build:transpile",
|
|
32
|
-
"
|
|
36
|
+
"dev:test": "cross-env NODE_ENV=test nodemon -w src -w test-fixtures --exec 'clear && npm run test:dev'",
|
|
37
|
+
"dev:test:debug": "cross-env DEBUG=@natlibfi/* NODE_ENV=test nodemon -w src -w test-fixtures --exec 'clear && npm run test:dev'"
|
|
33
38
|
},
|
|
34
39
|
"dependencies": {
|
|
35
|
-
"@natlibfi/
|
|
36
|
-
"@natlibfi/
|
|
37
|
-
"
|
|
38
|
-
"
|
|
40
|
+
"@natlibfi/fixugen": "1.1.0",
|
|
41
|
+
"@natlibfi/fixura": "^2.2.1",
|
|
42
|
+
"@natlibfi/marc-record": "^7.1.0-alpha.2",
|
|
43
|
+
"debug": "^4.3.4",
|
|
44
|
+
"normalize-diacritics": "2.14.0"
|
|
39
45
|
},
|
|
40
46
|
"devDependencies": {
|
|
41
|
-
"@babel/cli": "^7.
|
|
42
|
-
"@babel/core": "^7.
|
|
43
|
-
"@babel/eslint-parser": "^7.
|
|
44
|
-
"@babel/preset-env": "^7.
|
|
45
|
-
"@babel/register": "^7.
|
|
46
|
-
"@natlibfi/eslint-config-melinda-backend": "^
|
|
47
|
-
"babel-plugin-istanbul": "^6.
|
|
47
|
+
"@babel/cli": "^7.17.10",
|
|
48
|
+
"@babel/core": "^7.18.0",
|
|
49
|
+
"@babel/eslint-parser": "^7.17.0",
|
|
50
|
+
"@babel/preset-env": "^7.18.0",
|
|
51
|
+
"@babel/register": "^7.17.7",
|
|
52
|
+
"@natlibfi/eslint-config-melinda-backend": "^2.0.0",
|
|
53
|
+
"babel-plugin-istanbul": "^6.1.1",
|
|
48
54
|
"babel-plugin-rewire": "^1.2.0",
|
|
49
55
|
"chai": "^4.3.4",
|
|
50
56
|
"cross-env": "^7.0.3",
|
|
51
|
-
"eslint": "^
|
|
52
|
-
"mocha": "^
|
|
53
|
-
"nodemon": "^2.0.
|
|
57
|
+
"eslint": "^8.16.0",
|
|
58
|
+
"mocha": "^10.0.0",
|
|
59
|
+
"nodemon": "^2.0.16",
|
|
54
60
|
"nyc": "^15.1.0"
|
|
55
61
|
},
|
|
56
62
|
"eslintConfig": {
|
|
@@ -63,9 +69,7 @@
|
|
|
63
69
|
[
|
|
64
70
|
"@babel/preset-env",
|
|
65
71
|
{
|
|
66
|
-
"targets":
|
|
67
|
-
"node": "12"
|
|
68
|
-
}
|
|
72
|
+
"targets": "maintained node versions"
|
|
69
73
|
}
|
|
70
74
|
]
|
|
71
75
|
],
|
|
@@ -84,8 +88,7 @@
|
|
|
84
88
|
"*/**/*.spec.js"
|
|
85
89
|
],
|
|
86
90
|
"reporter": [
|
|
87
|
-
"
|
|
88
|
-
"html"
|
|
91
|
+
"text"
|
|
89
92
|
],
|
|
90
93
|
"require": [
|
|
91
94
|
"@babel/register"
|
package/src/index.js
CHANGED
|
@@ -1,36 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
4
|
-
*
|
|
5
|
-
* Merge MARC records
|
|
6
|
-
*
|
|
7
|
-
* Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
|
|
8
|
-
*
|
|
9
|
-
* This file is part of marc-record-merge-js
|
|
10
|
-
|
|
11
|
-
* marc-record-merge-js program is free software: you can redistribute it and/or modify
|
|
12
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
13
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
14
|
-
* License, or (at your option) any later version.
|
|
15
|
-
*
|
|
16
|
-
* marc-record-merge-js is distributed in the hope that it will be useful,
|
|
17
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
-
* GNU Lesser General Public License for more details.
|
|
20
|
-
*
|
|
21
|
-
* You should have received a copy of the GNU Lesser General Public License
|
|
22
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
-
*
|
|
24
|
-
* @licend The above is the entire license notice
|
|
25
|
-
* for the JavaScript code in this file.
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
import {MarcRecord} from '@natlibfi/marc-record';
|
|
30
1
|
import Reducers from './reducers';
|
|
31
2
|
|
|
32
3
|
export {Reducers};
|
|
33
|
-
export default ({base, source, reducers,
|
|
34
|
-
const sourceRecord = MarcRecord.clone(source, sourceValidators);
|
|
35
|
-
return reducers.reduce((baseRecord, reducer) => reducer(baseRecord, sourceRecord), MarcRecord.clone(base, baseValidators));
|
|
36
|
-
};
|
|
4
|
+
export default ({base, source, reducers}) => reducers.reduce((base, reducer) => reducer(base, source), base);
|
package/src/reducers/copy.js
CHANGED
|
@@ -1,140 +1,331 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Merge MARC records
|
|
6
|
-
*
|
|
7
|
-
* Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
|
|
8
|
-
*
|
|
9
|
-
* This file is part of marc-record-merge-js
|
|
10
|
-
|
|
11
|
-
* marc-record-merge-js program is free software: you can redistribute it and/or modify
|
|
12
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
13
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
14
|
-
* License, or (at your option) any later version.
|
|
15
|
-
*
|
|
16
|
-
* marc-record-merge-js is distributed in the hope that it will be useful,
|
|
17
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
-
* GNU Lesser General Public License for more details.
|
|
20
|
-
*
|
|
21
|
-
* You should have received a copy of the GNU Lesser General Public License
|
|
22
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
-
*
|
|
24
|
-
* @licend The above is the entire license notice
|
|
25
|
-
* for the JavaScript code in this file.
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Test 01: If base does not contain the field at all, it is copied from source to base
|
|
31
|
-
* Test 02: Identical control fields are not copied
|
|
32
|
-
* Test 03: Add missing control field to base
|
|
33
|
-
* Test 04: Identical data fields in base and source, not copied
|
|
34
|
-
* Test 05: Different data fields are copied from source to base (multiple fields)
|
|
35
|
-
* Test 06: compareTagsOnly: Field is copied from source only if it is missing in base, a different instance is not copied
|
|
36
|
-
* Test 07: excludeSubfields: Ignore excluded subfields in comparing identicalness
|
|
37
|
-
* Test 08: dropSubfields: Drop subfields from source before copying
|
|
38
|
-
* Test 09: compareTagsOnly for repeatable fields, 2x each 260/264
|
|
39
|
-
* */
|
|
1
|
+
/* eslint-disable max-statements */
|
|
2
|
+
/* eslint-disable no-unused-vars */
|
|
3
|
+
|
|
4
|
+
import {MarcRecord} from '@natlibfi/marc-record';
|
|
40
5
|
import createDebugLogger from 'debug';
|
|
41
6
|
|
|
42
|
-
export default ({
|
|
7
|
+
export default ({
|
|
8
|
+
tagPattern,
|
|
9
|
+
compareTagsOnly = false,
|
|
10
|
+
compareWithoutIndicators = false,
|
|
11
|
+
subfieldsMustBeIdentical = true,
|
|
12
|
+
excludeSubfields = [],
|
|
13
|
+
dropSubfields = [],
|
|
14
|
+
copyUnless = [],
|
|
15
|
+
baseValidators = {subfieldValues: false},
|
|
16
|
+
sourceValidators = {subfieldValues: false},
|
|
17
|
+
swapTag = [],
|
|
18
|
+
swapSubfieldCode = [],
|
|
19
|
+
doNotCopyIfFieldPresent = false
|
|
20
|
+
}) => (base, source) => {
|
|
21
|
+
const baseRecord = new MarcRecord(base, baseValidators);
|
|
22
|
+
const sourceRecord = new MarcRecord(source, sourceValidators);
|
|
23
|
+
|
|
43
24
|
const debug = createDebugLogger('@natlibfi/marc-record-merge');
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
25
|
+
const debugOptions = createDebugLogger('@natlibfi/marc-record-merge:compare-options');
|
|
26
|
+
const debugCompare = createDebugLogger('@natlibfi/marc-record-merge:compare');
|
|
27
|
+
debugOptions(`Tag Pattern: ${tagPattern}`);
|
|
28
|
+
debugOptions(`Compare tags only: ${compareTagsOnly}`);
|
|
29
|
+
debugOptions(`Compare without indicators ${compareWithoutIndicators}`);
|
|
30
|
+
debugOptions(`Copy if identical: ${subfieldsMustBeIdentical}`);
|
|
31
|
+
debugOptions(`Exclude subfields: [${excludeSubfields}]`);
|
|
32
|
+
debugOptions(`Drop subfields [${dropSubfields}]`);
|
|
33
|
+
debugOptions(`Copy unless contains subfields: ${JSON.stringify(copyUnless)}`);
|
|
34
|
+
|
|
35
|
+
const baseFields = baseRecord.get(tagPattern);
|
|
36
|
+
const sourceFields = sourceRecord.get(tagPattern);
|
|
37
|
+
const doNotCopy = doNotCopyIfFieldPresent ? baseRecord.get(doNotCopyIfFieldPresent).length > 0 : false;
|
|
38
|
+
|
|
39
|
+
if (doNotCopy) {
|
|
40
|
+
return baseRecord.toObject();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
debug(`Base fields: `, baseFields);
|
|
44
|
+
debug(`Source fields: `, sourceFields);
|
|
45
|
+
|
|
46
|
+
const baseCompareFields = baseFields.map(baseField => createCompareField(baseField));
|
|
47
|
+
const compareResultFields = compareFields(sourceFields, baseCompareFields);
|
|
48
|
+
const droppedUnwantedSubfield = checkDropSubfields(compareResultFields);
|
|
49
|
+
const droppedUnwantedFields = checkCopyUnlessFields(droppedUnwantedSubfield);
|
|
50
|
+
const swappedSubfields = checkSwapSubfieldCodes(droppedUnwantedFields);
|
|
51
|
+
const swappedTags = checkSwapTag(swappedSubfields);
|
|
52
|
+
debug('Fields to be copied');
|
|
53
|
+
debug(JSON.stringify(swappedTags));
|
|
54
|
+
|
|
55
|
+
// Add fields to base;
|
|
56
|
+
swappedTags.forEach(field => baseRecord.insertField(field));
|
|
57
|
+
return baseRecord.toObject();
|
|
58
|
+
//return copyFields(baseFields, sourceFields);
|
|
59
|
+
|
|
60
|
+
function compareFields(sourceFields, baseCompareFields, uniqFields = []) {
|
|
61
|
+
const [sourceField, ...rest] = sourceFields;
|
|
62
|
+
if (sourceField === undefined) {
|
|
63
|
+
return uniqFields;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (baseCompareFields.length === 0) {
|
|
67
|
+
return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);
|
|
59
68
|
}
|
|
60
69
|
|
|
61
|
-
// If compareTagsOnly = false (default)
|
|
62
70
|
// Source and base are also compared for identicalness
|
|
63
71
|
// Non-identical fields are copied from source to base as duplicates
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
const sourceCompareField = createCompareField(sourceField);
|
|
73
|
+
const unique = checkCompareFields(baseCompareFields, sourceCompareField);
|
|
74
|
+
|
|
75
|
+
debugCompare(`${JSON.stringify(sourceField)} ${unique ? 'is UNIQUE' : 'not UNIQUE'}`);
|
|
76
|
+
|
|
77
|
+
if (unique) {
|
|
78
|
+
return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return compareFields(rest, baseCompareFields, uniqFields);
|
|
82
|
+
|
|
83
|
+
function checkCompareFields(baseCompareFields, sourceCompareField) {
|
|
84
|
+
let unique = true; // eslint-disable-line functional/no-let
|
|
85
|
+
|
|
86
|
+
baseCompareFields.forEach(baseCompareField => {
|
|
87
|
+
debugCompare(`Comparing ${JSON.stringify(sourceCompareField)} to ${JSON.stringify(baseCompareField)}}`);
|
|
88
|
+
|
|
89
|
+
if (sourceCompareField.value !== baseCompareField.value) {
|
|
90
|
+
debugCompare(`Value is different ${sourceCompareField.value} !== ${baseCompareField.value}`);
|
|
91
|
+
return;
|
|
73
92
|
}
|
|
74
93
|
|
|
75
|
-
|
|
76
|
-
|
|
94
|
+
if (sourceCompareField.ind1 !== baseCompareField.ind1) {
|
|
95
|
+
debugCompare(`Ind1 is different ${sourceCompareField.ind1} !== ${baseCompareField.ind1}`);
|
|
96
|
+
return;
|
|
77
97
|
}
|
|
78
98
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return normalizedSourceField === normalizedBaseField;
|
|
99
|
+
if (sourceCompareField.ind2 !== baseCompareField.ind2) {
|
|
100
|
+
debugCompare(`Ind2 is different ${sourceCompareField.ind2} !== ${baseCompareField.ind2}`);
|
|
101
|
+
return;
|
|
83
102
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
sourceField.ind2 === baseField.ind2) {
|
|
91
|
-
excludeSubfields.forEach(sub => debug(`Subfield ${sub} excluded from identicalness comparison`));
|
|
92
|
-
// Compare only those subfields that are not excluded
|
|
93
|
-
const baseSubsToCompare = baseField.subfields.filter(subfield => excludeSubfields.indexOf(subfield.code) === -1);
|
|
94
|
-
return baseSubsToCompare.every(isIdenticalSubfield);
|
|
95
|
-
}
|
|
96
|
-
// If there are no excluded subfields (default case)
|
|
97
|
-
if (sourceField.tag === baseField.tag &&
|
|
98
|
-
sourceField.ind1 === baseField.ind1 &&
|
|
99
|
-
sourceField.ind2 === baseField.ind2 &&
|
|
100
|
-
sourceField.subfields.length === baseField.subfields.length) {
|
|
101
|
-
return baseField.subfields.every(isIdenticalSubfield);
|
|
102
|
-
}
|
|
103
|
-
function normalizeSubfield(subfield) {
|
|
104
|
-
return subfield.value.toLowerCase().replace(/\s+/u, '');
|
|
105
|
-
}
|
|
106
|
-
function isIdenticalSubfield(baseSub) {
|
|
107
|
-
const normBaseSub = normalizeSubfield(baseSub);
|
|
108
|
-
return sourceField.subfields.some(sourceSub => {
|
|
109
|
-
const normSourceSub = normalizeSubfield(sourceSub);
|
|
110
|
-
return normSourceSub === normBaseSub;
|
|
111
|
-
});
|
|
103
|
+
|
|
104
|
+
if ('subfields' in sourceCompareField) {
|
|
105
|
+
const allFound = checkSubfields(sourceCompareField.subfields, baseCompareField.subfields);
|
|
106
|
+
debugCompare(`Subfields are different ${!allFound}`);
|
|
107
|
+
if (!allFound) {
|
|
108
|
+
return;
|
|
112
109
|
}
|
|
110
|
+
|
|
111
|
+
unique = false;
|
|
112
|
+
return;
|
|
113
113
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
114
|
+
|
|
115
|
+
unique = false;
|
|
116
|
+
return;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return unique;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function checkSubfields(sourceSubfields, baseSubfields) {
|
|
123
|
+
const foundSubs = sourceSubfields.filter(sSub => baseSubfields.some(bSub => sSub.code === bSub.code && sSub.value === bSub.value));
|
|
124
|
+
|
|
125
|
+
if (subfieldsMustBeIdentical) {
|
|
126
|
+
return foundSubs.length === sourceSubfields.length && foundSubs.length === baseSubfields.length;
|
|
122
127
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
128
|
+
|
|
129
|
+
return foundSubs.length === sourceSubfields.length;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function createCompareField(field) {
|
|
134
|
+
if (compareTagsOnly) {
|
|
135
|
+
return {tag: field.tag};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if ('value' in field) {
|
|
139
|
+
return {tag: field.tag, value: field.value};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const [filteredField] = checkDropSubfields([field]);
|
|
143
|
+
|
|
144
|
+
const params = [
|
|
145
|
+
{name: 'tag', value: field.tag},
|
|
146
|
+
{name: 'ind1', value: compareWithoutIndicators ? undefined : field.ind1},
|
|
147
|
+
{name: 'ind2', value: compareWithoutIndicators ? undefined : field.ind2},
|
|
148
|
+
{name: 'subfields', value: createCompareSubfields(filteredField.subfields)}
|
|
149
|
+
].map(param => [param.name, param.value]);
|
|
150
|
+
|
|
151
|
+
return Object.fromEntries(params);
|
|
152
|
+
|
|
153
|
+
function createCompareSubfields(subfields) {
|
|
154
|
+
const nonExcludedSubfields = subfields.filter(sub => !excludeSubfields.some(code => code === sub.code));
|
|
155
|
+
const normalizedSubfields = nonExcludedSubfields.map(sub => ({code: sub.code, value: normalizeSubfieldValue(sub.value)}));
|
|
156
|
+
|
|
157
|
+
return normalizedSubfields;
|
|
158
|
+
|
|
159
|
+
function normalizeSubfieldValue(value) {
|
|
160
|
+
return value.toLowerCase().replace(/\s+/ug, '');
|
|
126
161
|
}
|
|
127
162
|
}
|
|
128
|
-
|
|
129
|
-
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function checkSwapTag(fields) {
|
|
166
|
+
if (swapTag.length > 0) {
|
|
167
|
+
return fields.map(field => ({...field, tag: swapTagsFunc(field.tag)}));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return fields;
|
|
171
|
+
|
|
172
|
+
function swapTagsFunc(tag) {
|
|
173
|
+
const [foundRule] = swapTag.filter(rule => new RegExp(rule.from, 'u').test(tag));
|
|
174
|
+
|
|
175
|
+
if (foundRule === undefined) {
|
|
176
|
+
return tag;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return foundRule.to;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function checkSwapSubfieldCodes(fields) {
|
|
184
|
+
if (swapSubfieldCode.length > 0) {
|
|
185
|
+
return fields.map(field => ({...field, subfields: swapSubfieldCodesFunc(field.subfields)}));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return fields;
|
|
189
|
+
|
|
190
|
+
function swapSubfieldCodesFunc(subfields) {
|
|
191
|
+
return subfields.map(sub => {
|
|
192
|
+
const [foundRule] = swapSubfieldCode.filter(rule => rule.from === sub.code);
|
|
193
|
+
|
|
194
|
+
if (foundRule === undefined) {
|
|
195
|
+
return sub;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return {code: foundRule.to, value: sub.value};
|
|
199
|
+
});
|
|
200
|
+
}
|
|
130
201
|
}
|
|
131
202
|
|
|
132
203
|
function checkDropSubfields(fields) {
|
|
133
204
|
if (dropSubfields.length > 0) {
|
|
134
|
-
|
|
135
|
-
|
|
205
|
+
return fields.map(field => ({...field, subfields: dropSubfieldsFunc(field.subfields)}))
|
|
206
|
+
.filter(field => field.subfields.length > 0);
|
|
136
207
|
}
|
|
137
|
-
|
|
208
|
+
|
|
209
|
+
return fields;
|
|
210
|
+
|
|
211
|
+
function dropSubfieldsFunc(subfields) {
|
|
212
|
+
return subfields.filter(sub => { // eslint-disable-line
|
|
213
|
+
return !dropSubfields.some(({code, value = false, condition = false}) => {
|
|
214
|
+
if (code !== sub.code) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (!condition && value) {
|
|
219
|
+
return value === sub.value;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (condition === 'unless' && value) {
|
|
223
|
+
return !new RegExp(value, 'u').test(sub.value);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return true;
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function checkCopyUnlessFields(fields) {
|
|
233
|
+
if (copyUnless.length > 0) {
|
|
234
|
+
return fields.filter(({subfields}) => copyUnless.some(filter => !subfields.some(sub => sub.code === filter.code && new RegExp(filter.value, 'u').test(sub.value))));
|
|
235
|
+
}
|
|
236
|
+
|
|
138
237
|
return fields;
|
|
139
238
|
}
|
|
140
239
|
};
|
|
240
|
+
|
|
241
|
+
// function copyFields() { //eslint-disable-line no-unused-vars
|
|
242
|
+
// const sourceTags = sourceFields.map(field => field.tag);
|
|
243
|
+
// sourceTags.forEach(tag => debug(`Comparing field ${tag}`));
|
|
244
|
+
|
|
245
|
+
// /*
|
|
246
|
+
// if (combine.length > 0) {
|
|
247
|
+
// debug(`*** NOW Copy options: ${tagPattern}, ${compareTagsOnly}, ${compareWithoutIndicators}, ${subfieldsMustBeIdentical}, [${combine}], [${excludeSubfields}], [${dropSubfields}]`);
|
|
248
|
+
// combine.forEach(row => debug(` ### combine ${row} <- `));
|
|
249
|
+
// return [];
|
|
250
|
+
// }
|
|
251
|
+
// */
|
|
252
|
+
|
|
253
|
+
// // If compareTagsOnly = true, only this part is run
|
|
254
|
+
// // The field is copied from source only if it is missing completely from base
|
|
255
|
+
// if (compareTagsOnly && baseFields.length === 0) {
|
|
256
|
+
// sourceTags.forEach(tag => debug(`Missing field ${tag} copied from source to base`));
|
|
257
|
+
// sourceFields.forEach(f => base.insertField(f));
|
|
258
|
+
// return true;
|
|
259
|
+
// }
|
|
260
|
+
|
|
261
|
+
// // If compareTagsOnly = false (default)
|
|
262
|
+
// // Source and base are also compared for identicalness
|
|
263
|
+
// // Non-identical fields are copied from source to base as duplicates
|
|
264
|
+
// if (!compareTagsOnly) {
|
|
265
|
+
// const filterMissing = function (sourceField) {
|
|
266
|
+
// if ('value' in sourceField) {
|
|
267
|
+
// debug(`Checking control field ${sourceField.tag} for identicalness`);
|
|
268
|
+
// return baseFields.some(isIdenticalControlField) === false;
|
|
269
|
+
// }
|
|
270
|
+
// if ('subfields' in sourceField) {
|
|
271
|
+
// debug(`Checking data field ${sourceField.tag} for identicalness`);
|
|
272
|
+
// return baseFields.some(isIdenticalDataField) === false;
|
|
273
|
+
// }
|
|
274
|
+
|
|
275
|
+
// function normalizeControlField(field) {
|
|
276
|
+
// return field.value.toLowerCase().replace(/\s+/u, '');
|
|
277
|
+
// }
|
|
278
|
+
|
|
279
|
+
// function isIdenticalControlField(baseField) {
|
|
280
|
+
// const normalizedBaseField = normalizeControlField(baseField);
|
|
281
|
+
// const normalizedSourceField = normalizeControlField(sourceField);
|
|
282
|
+
// return normalizedSourceField === normalizedBaseField;
|
|
283
|
+
// }
|
|
284
|
+
|
|
285
|
+
// function isIdenticalDataField(baseField) {
|
|
286
|
+
// // If excluded subfields have been defined for this field, they must be ignored first
|
|
287
|
+
// // (i.e. source and base fields are considered identical if all non-excluded subfields are identical)
|
|
288
|
+
// if (excludeSubfields.length > 0 &&
|
|
289
|
+
// sourceField.tag === baseField.tag &&
|
|
290
|
+
// sourceField.ind1 === baseField.ind1 &&
|
|
291
|
+
// sourceField.ind2 === baseField.ind2) {
|
|
292
|
+
// excludeSubfields.forEach(sub => debug(`Subfield ${sub} excluded from identicalness comparison`));
|
|
293
|
+
// // Compare only those subfields that are not excluded
|
|
294
|
+
// const baseSubsToCompare = baseField.subfields.filter(subfield => excludeSubfields.indexOf(subfield.code) === -1);
|
|
295
|
+
// return baseSubsToCompare.every(isIdenticalSubfield);
|
|
296
|
+
// }
|
|
297
|
+
// // If there are no excluded subfields (default case)
|
|
298
|
+
// if (sourceField.tag === baseField.tag &&
|
|
299
|
+
// sourceField.ind1 === baseField.ind1 &&
|
|
300
|
+
// sourceField.ind2 === baseField.ind2 &&
|
|
301
|
+
// sourceField.subfields.length === baseField.subfields.length) {
|
|
302
|
+
// return baseField.subfields.every(isIdenticalSubfield);
|
|
303
|
+
// }
|
|
304
|
+
// function normalizeSubfield(subfield) {
|
|
305
|
+
// return subfield.value.toLowerCase().replace(/\s+/u, '');
|
|
306
|
+
// }
|
|
307
|
+
// function isIdenticalSubfield(baseSub) {
|
|
308
|
+
// const normBaseSub = normalizeSubfield(baseSub);
|
|
309
|
+
// return sourceField.subfields.some(sourceSub => {
|
|
310
|
+
// const normSourceSub = normalizeSubfield(sourceSub);
|
|
311
|
+
// return normSourceSub === normBaseSub;
|
|
312
|
+
// });
|
|
313
|
+
// }
|
|
314
|
+
// }
|
|
315
|
+
// };
|
|
316
|
+
// // Search for fields missing from base
|
|
317
|
+
// const missingFields = sourceFields.filter(filterMissing);
|
|
318
|
+
// missingFields.forEach(f => base.insertField(f));
|
|
319
|
+
// if (missingFields.length > 0) {
|
|
320
|
+
// const missingTags = missingFields.map(field => field.tag);
|
|
321
|
+
// missingTags.forEach(tag => debug(`Field ${tag} copied from source to base`));
|
|
322
|
+
// return base;
|
|
323
|
+
// }
|
|
324
|
+
// if (missingFields.length === 0) {
|
|
325
|
+
// debug(`No missing fields found`);
|
|
326
|
+
// return base;
|
|
327
|
+
// }
|
|
328
|
+
// }
|
|
329
|
+
// debug(`No missing fields found`);
|
|
330
|
+
// return base;
|
|
331
|
+
// }
|