@natlibfi/marc-record-merge 6.0.0-beta.1 → 6.0.0-beta.11
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 +122 -2
- package/dist/index.js +56 -42
- package/dist/index.js.map +1 -1
- package/dist/index.spec.js +59 -0
- package/dist/index.spec.js.map +1 -0
- package/dist/reducers/copy.js +254 -80
- package/dist/reducers/copy.js.map +1 -1
- package/dist/reducers/copy.spec.js +57 -72
- package/dist/reducers/copy.spec.js.map +1 -1
- package/dist/reducers/copy2.spec.js +67 -0
- package/dist/reducers/copy2.spec.js.map +1 -0
- package/dist/reducers/index.js +13 -24
- package/dist/reducers/index.js.map +1 -1
- package/dist/reducers/select.js +63 -58
- package/dist/reducers/select.js.map +1 -1
- package/dist/reducers/select.spec.js +45 -92
- package/dist/reducers/select.spec.js.map +1 -1
- package/dist/reducers/select2.spec.js +58 -0
- package/dist/reducers/select2.spec.js.map +1 -0
- package/package.json +33 -32
- package/src/index.js +50 -32
- package/src/index.spec.js +45 -0
- package/src/reducers/copy.js +262 -80
- package/src/reducers/copy.spec.js +50 -48
- package/src/reducers/copy2.spec.js +55 -0
- package/src/reducers/index.js +3 -30
- package/src/reducers/select.js +53 -39
- package/src/reducers/select.spec.js +41 -56
- package/src/reducers/select2.spec.js +49 -0
- package/test-fixtures/index/01/base.json +24 -0
- package/test-fixtures/index/01/merged.json +24 -0
- package/test-fixtures/index/01/metadata.json +8 -0
- package/test-fixtures/index/01/source.json +40 -0
- package/test-fixtures/index/02/base.json +24 -0
- package/test-fixtures/index/02/merged.json +24 -0
- package/test-fixtures/index/02/metadata.json +7 -0
- package/test-fixtures/index/02/source.json +40 -0
- 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/01 - copy/05/merged.json +77 -0
- package/test-fixtures/reducers/copy/01 - copy/05/metadata.json +4 -0
- package/test-fixtures/reducers/copy/01 - copy/05/source.json +62 -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/03 - compareTagsOnly/01/base.json +24 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/01/merged.json +24 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/01/metadata.json +5 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/01/source.json +24 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/02/base.json +24 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/02/merged.json +100 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/02/metadata.json +5 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/02/source.json +100 -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/04 - compareWithoutIndicators/03/metadata.json +6 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/base.json +20 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/merged.json +31 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/metadata.json +5 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/source.json +20 -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 - excludeSubfields/01/base.json +39 -0
- package/test-fixtures/reducers/copy/07 - excludeSubfields/01/merged.json +39 -0
- package/test-fixtures/reducers/copy/07 - excludeSubfields/01/metadata.json +8 -0
- package/test-fixtures/reducers/copy/{05/source.json → 07 - excludeSubfields/01/source.json } +1 -1
- package/test-fixtures/reducers/copy/07 - excludeSubfields/02/base.json +39 -0
- package/test-fixtures/reducers/copy/{05/merged.json → 07 - excludeSubfields/02/merged.json } +5 -5
- 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 - dropSubfields/01/base.json +35 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/01/merged.json +54 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/01/metadata.json +5 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/01/source.json +43 -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/copy/11 - compareWithoutTag/01/base.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/01/merged.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/01/metadata.json +6 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/01/source.json +20 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/base.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/merged.json +39 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/metadata.json +6 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/source.json +31 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/base.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/merged.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/metadata.json +7 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/source.json +20 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/base.json +17 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/merged.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/metadata.json +7 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/source.json +31 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/base.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/merged.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/metadata.json +7 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/source.json +28 -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/base.json +4 -0
- package/test-fixtures/reducers/select/06/merged.json +4 -0
- package/test-fixtures/reducers/select/06/metadata.json +4 -0
- package/test-fixtures/reducers/select/06/source.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/base.json +24 -0
- package/test-fixtures/reducers/select/14/merged.json +24 -0
- package/test-fixtures/reducers/select/14/metadata.json +4 -0
- package/test-fixtures/reducers/select/14/source.json +24 -0
- package/.drone.yml +0 -92
- package/.nyc_output/7ecda3cd-9f84-4416-a466-fa1e5889c6a3.json +0 -1
- package/.nyc_output/processinfo/7ecda3cd-9f84-4416-a466-fa1e5889c6a3.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 -344
- 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 -344
- 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 -431
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov.info +0 -195
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/select.js.html +0 -431
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -170
- package/test-fixtures/reducers/copy/01/pattern.txt +0 -1
- package/test-fixtures/reducers/copy/02/pattern.txt +0 -1
- package/test-fixtures/reducers/copy/03/pattern.txt +0 -1
- package/test-fixtures/reducers/copy/04/pattern.txt +0 -1
- package/test-fixtures/reducers/copy/05/pattern.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/package.json
CHANGED
|
@@ -13,46 +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.11",
|
|
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
|
-
"check-deps": "npm-check;exit 0",
|
|
25
26
|
"lint": "eslint ./src",
|
|
26
27
|
"lint:dev": "eslint ./src --fix",
|
|
27
|
-
"test:base": "cross-env NODE_ENV=test
|
|
28
|
-
"test": "npm run lint && npm run test:base -- src
|
|
29
|
-
"test:dev": "npm run lint:dev && npm run
|
|
30
|
-
"coverage": "
|
|
28
|
+
"test:base": "cross-env NODE_ENV=test mocha --require @babel/register --reporter-option maxDiffSize=15000",
|
|
29
|
+
"test": "npm run lint && npm run test:base -- --recursive src",
|
|
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",
|
|
31
34
|
"build:transpile": "babel src --copy-files --source-maps --delete-dir-on-start --out-dir=dist",
|
|
32
|
-
"build": "npm run build:transpile
|
|
33
|
-
"
|
|
35
|
+
"build": "npm run build:transpile",
|
|
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'"
|
|
34
38
|
},
|
|
35
39
|
"dependencies": {
|
|
36
|
-
"@natlibfi/
|
|
37
|
-
"@natlibfi/
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
+
"@natlibfi/fixugen": "1.1.0",
|
|
41
|
+
"@natlibfi/fixura": "^2.2.5",
|
|
42
|
+
"@natlibfi/marc-record": "^7.2.2",
|
|
43
|
+
"debug": "^4.3.4",
|
|
44
|
+
"normalize-diacritics": "2.14.0"
|
|
40
45
|
},
|
|
41
46
|
"devDependencies": {
|
|
42
|
-
"@babel/cli": "^7.
|
|
43
|
-
"@babel/core": "^7.
|
|
44
|
-
"@babel/
|
|
45
|
-
"@babel/
|
|
46
|
-
"@
|
|
47
|
-
"
|
|
48
|
-
"babel-plugin-istanbul": "^6.
|
|
47
|
+
"@babel/cli": "^7.19.3",
|
|
48
|
+
"@babel/core": "^7.19.6",
|
|
49
|
+
"@babel/eslint-parser": "^7.19.1",
|
|
50
|
+
"@babel/preset-env": "^7.19.4",
|
|
51
|
+
"@babel/register": "^7.18.9",
|
|
52
|
+
"@natlibfi/eslint-config-melinda-backend": "^2.0.1",
|
|
53
|
+
"babel-plugin-istanbul": "^6.1.1",
|
|
49
54
|
"babel-plugin-rewire": "^1.2.0",
|
|
50
|
-
"chai": "^4.
|
|
51
|
-
"cross-env": "^7.0.
|
|
52
|
-
"eslint": "^
|
|
53
|
-
"mocha": "^
|
|
54
|
-
"nodemon": "^2.0.
|
|
55
|
-
"npm-check": "^5.9.0",
|
|
55
|
+
"chai": "^4.3.6",
|
|
56
|
+
"cross-env": "^7.0.3",
|
|
57
|
+
"eslint": "^8.25.0",
|
|
58
|
+
"mocha": "^10.1.0",
|
|
59
|
+
"nodemon": "^2.0.20",
|
|
56
60
|
"nyc": "^15.1.0"
|
|
57
61
|
},
|
|
58
62
|
"eslintConfig": {
|
|
@@ -65,9 +69,7 @@
|
|
|
65
69
|
[
|
|
66
70
|
"@babel/preset-env",
|
|
67
71
|
{
|
|
68
|
-
"targets":
|
|
69
|
-
"node": "12"
|
|
70
|
-
}
|
|
72
|
+
"targets": "maintained node versions"
|
|
71
73
|
}
|
|
72
74
|
]
|
|
73
75
|
],
|
|
@@ -86,8 +88,7 @@
|
|
|
86
88
|
"*/**/*.spec.js"
|
|
87
89
|
],
|
|
88
90
|
"reporter": [
|
|
89
|
-
"
|
|
90
|
-
"html"
|
|
91
|
+
"text"
|
|
91
92
|
],
|
|
92
93
|
"require": [
|
|
93
94
|
"@babel/register"
|
package/src/index.js
CHANGED
|
@@ -1,36 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 * as Reducers from './reducers';
|
|
30
|
-
import {MarcRecord} from '@natlibfi/marc-record';
|
|
1
|
+
import Reducers from './reducers';
|
|
2
|
+
import createDebugLogger from 'debug';
|
|
3
|
+
|
|
4
|
+
const debug = createDebugLogger('@natlibfi/melinda-marc-record-merge:index');
|
|
5
|
+
const debugData = debug.extend('data');
|
|
31
6
|
|
|
32
7
|
export {Reducers};
|
|
8
|
+
// export default ({base, source, reducers}) => reducers.reduce((base, reducer) => reducer(base, source), base);
|
|
9
|
+
|
|
10
|
+
// NV: Modified the reducer loop so, that not only base, but also is carried back.
|
|
11
|
+
// However, we try to be backward-compatible: normally after the reducers, only base is returned.
|
|
12
|
+
|
|
33
13
|
export default ({base, source, reducers}) => {
|
|
34
|
-
|
|
35
|
-
|
|
14
|
+
|
|
15
|
+
const combo = {base, source};
|
|
16
|
+
const resultCombo = reducers.reduce((combo, reducer) => {
|
|
17
|
+
const returnCombo = singleRound(reducer, combo.base, combo.source);
|
|
18
|
+
//debugData(`returnCombo after current reducer: ${JSON.stringify(returnCombo)}`);
|
|
19
|
+
return returnCombo;
|
|
20
|
+
}, combo);
|
|
21
|
+
|
|
22
|
+
debugData(`ResultCombo after reducers: ${JSON.stringify(resultCombo)}`);
|
|
23
|
+
|
|
24
|
+
// Hack to make my melinda-marc-record-merge-reducers single tests that expect both
|
|
25
|
+
// base and source to return them both:
|
|
26
|
+
if (reducers.length === 1 && resultCombo.base && resultCombo.source) {
|
|
27
|
+
debug('Single reducer, returning resultCombo');
|
|
28
|
+
debugData(JSON.stringify(resultCombo));
|
|
29
|
+
|
|
30
|
+
return resultCombo;
|
|
31
|
+
}
|
|
32
|
+
// All other tests return just base... Backward (compability) it is!
|
|
33
|
+
debug('Multiple reducers, returning just base');
|
|
34
|
+
debugData(JSON.stringify(resultCombo.base));
|
|
35
|
+
return resultCombo.base;
|
|
36
|
+
|
|
37
|
+
function singleRound(reducer, base, source) {
|
|
38
|
+
//debug(`SINGLE ROUND INPUT (base, source)`);
|
|
39
|
+
//debugData(base);
|
|
40
|
+
//debugData(base);
|
|
41
|
+
const reducerResult = reducer(base, source);
|
|
42
|
+
//debug(`reducerResult:`);
|
|
43
|
+
//debugData(reducerResult);
|
|
44
|
+
if (reducerResult.base !== undefined && reducerResult.source !== undefined) {
|
|
45
|
+
debug('NEW STYLE REDUCER RESULT v2');
|
|
46
|
+
const combo = reducerResult;
|
|
47
|
+
//debugData(combo);
|
|
48
|
+
return combo;
|
|
49
|
+
}
|
|
50
|
+
debug('OLD SCHOOL REDUCER RESULT v2');
|
|
51
|
+
//debugData({base: reducerResult, source});
|
|
52
|
+
return {base: reducerResult, source};
|
|
53
|
+
}
|
|
36
54
|
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import merger, {Reducers} from './index';
|
|
2
|
+
import {inspect} from 'util';
|
|
3
|
+
import createDebugLogger from 'debug';
|
|
4
|
+
import {expect} from 'chai';
|
|
5
|
+
import {MarcRecord} from '@natlibfi/marc-record';
|
|
6
|
+
import {READERS} from '@natlibfi/fixura';
|
|
7
|
+
import generateTests from '@natlibfi/fixugen';
|
|
8
|
+
|
|
9
|
+
generateTests({
|
|
10
|
+
callback,
|
|
11
|
+
path: [__dirname, '..', 'test-fixtures', 'index'],
|
|
12
|
+
recurse: false,
|
|
13
|
+
useMetadataFile: true,
|
|
14
|
+
fixura: {
|
|
15
|
+
failWhenNotFound: false,
|
|
16
|
+
reader: READERS.JSON
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function callback({getFixture, reducerConfigs = []}) {
|
|
21
|
+
const base = new MarcRecord(getFixture('base.json'), {subfieldValues: false});
|
|
22
|
+
const source = new MarcRecord(getFixture('source.json'), {subfieldValues: false});
|
|
23
|
+
const expectedRecord = getFixture('merged.json');
|
|
24
|
+
|
|
25
|
+
const debug = createDebugLogger('@natlibfi/melinda-marc-record-merge-reducers:index:test');
|
|
26
|
+
const debugData = debug.extend('data');
|
|
27
|
+
|
|
28
|
+
const testReducerConfigs = reducerConfigs;
|
|
29
|
+
const reducers = [...testReducerConfigs.map(conf => Reducers.copy(conf))];
|
|
30
|
+
|
|
31
|
+
debugData(`Reducers: ${inspect(reducers, {colors: true, maxArrayLength: 10, depth: 8})})}`);
|
|
32
|
+
|
|
33
|
+
const result = merger({base, source, reducers});
|
|
34
|
+
|
|
35
|
+
debug(`Merge result is: ${result.constructor.name}`);
|
|
36
|
+
debugData(`${JSON.stringify(result)}`);
|
|
37
|
+
|
|
38
|
+
// Use either result.base or a plain result as resultRecord
|
|
39
|
+
// It can also be a MarcRecord or a plain object
|
|
40
|
+
const resultRecord = result.base || result;
|
|
41
|
+
const resultRecordToRecord = new MarcRecord(resultRecord, {subfieldValues: false});
|
|
42
|
+
expect(resultRecordToRecord.toObject()).to.eql(expectedRecord);
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
}
|
package/src/reducers/copy.js
CHANGED
|
@@ -1,88 +1,270 @@
|
|
|
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
|
-
// Import createDebugLogger from 'debug';
|
|
29
|
-
|
|
30
|
-
export default (pattern) => (base, source) => {
|
|
31
|
-
// Const debug = createDebugLogger('@natlibfi/marc-record-merge');
|
|
32
|
-
const baseFields = base.get(pattern);
|
|
33
|
-
const sourceFields = source.get(pattern);
|
|
34
|
-
return copyFields();
|
|
35
|
-
|
|
36
|
-
function copyFields() {
|
|
37
|
-
// Test 01: If base does not contain the field at all, it is copied from source to base
|
|
38
|
-
if (baseFields.length === 0) {
|
|
39
|
-
sourceFields.forEach(f => base.insertField(f));
|
|
40
|
-
return base;
|
|
41
|
-
}
|
|
42
|
-
const filterMissing = function(sourceField) {
|
|
43
|
-
// Test 02: Identical control fields are not copied
|
|
44
|
-
if ('value' in sourceField) {
|
|
45
|
-
return baseFields.some(isIdenticalControlField) === false;
|
|
46
|
-
}
|
|
47
|
-
// Test 04: Identical data fields in base and source, not copied
|
|
48
|
-
// Test 05: Different data fields are copied from source to base
|
|
49
|
-
if ('subfields' in sourceField) {
|
|
50
|
-
return baseFields.some(isIdenticalDataField) === false;
|
|
51
|
-
}
|
|
1
|
+
/* eslint-disable max-statements */
|
|
2
|
+
/* eslint-disable no-unused-vars */
|
|
52
3
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
4
|
+
import {MarcRecord} from '@natlibfi/marc-record';
|
|
5
|
+
import createDebugLogger from 'debug';
|
|
56
6
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
7
|
+
export default ({
|
|
8
|
+
tagPattern,
|
|
9
|
+
compareTagsOnly = false,
|
|
10
|
+
compareWithoutTag = false,
|
|
11
|
+
compareWithoutIndicators = false,
|
|
12
|
+
compareWithoutIndicator1 = false,
|
|
13
|
+
compareWithoutIndicator2 = false,
|
|
14
|
+
subfieldsMustBeIdentical = true,
|
|
15
|
+
excludeSubfields = [],
|
|
16
|
+
dropSubfields = [],
|
|
17
|
+
copyUnless = [],
|
|
18
|
+
baseValidators = {subfieldValues: false},
|
|
19
|
+
sourceValidators = {subfieldValues: false},
|
|
20
|
+
swapTag = [],
|
|
21
|
+
swapSubfieldCode = [],
|
|
22
|
+
doNotCopyIfFieldPresent = false
|
|
23
|
+
}) => (base, source) => {
|
|
24
|
+
|
|
25
|
+
const debug = createDebugLogger('@natlibfi/marc-record-merge:copy');
|
|
26
|
+
const debugData = debug.extend('data');
|
|
27
|
+
const debugOptions = createDebugLogger('@natlibfi/marc-record-merge:compare-options');
|
|
28
|
+
const debugCompare = createDebugLogger('@natlibfi/marc-record-merge:compare');
|
|
29
|
+
|
|
30
|
+
debugData(`base: ${JSON.stringify(base)}`);
|
|
31
|
+
debugData(`source: ${JSON.stringify(source)}`);
|
|
32
|
+
|
|
33
|
+
const {baseRecord, sourceRecord} = getRecordsFromParameters(base, source, baseValidators, sourceValidators);
|
|
34
|
+
|
|
35
|
+
function getRecordsFromParameters(base, source, baseValidators, sourceValidators) {
|
|
36
|
+
// records if we got an object ({base, source}) as a parameter
|
|
37
|
+
if (source === undefined && base.base !== undefined && base.source !== undefined) {
|
|
38
|
+
const baseRecord = new MarcRecord(base.base, baseValidators);
|
|
39
|
+
const sourceRecord = new MarcRecord(base.source, sourceValidators);
|
|
40
|
+
return {baseRecord, sourceRecord};
|
|
41
|
+
}
|
|
42
|
+
// records if we got an non-object (base, source) as a parameter
|
|
43
|
+
const baseRecord = new MarcRecord(base, baseValidators);
|
|
44
|
+
const sourceRecord = new MarcRecord(source, sourceValidators);
|
|
45
|
+
return {baseRecord, sourceRecord};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const ignoreInd1 = compareWithoutIndicators || compareWithoutIndicator1;
|
|
49
|
+
const ignoreInd2 = compareWithoutIndicators || compareWithoutIndicator2;
|
|
50
|
+
|
|
51
|
+
debugOptions(`Tag Pattern: ${tagPattern}`);
|
|
52
|
+
debugOptions(`Compare tags only: ${compareTagsOnly}`);
|
|
53
|
+
debugOptions(`Omit indicator 1 from comparison: ${ignoreInd1}`);
|
|
54
|
+
debugOptions(`Omit indicator 2 from comparison: ${ignoreInd2}`);
|
|
55
|
+
debugOptions(`Copy if identical: ${subfieldsMustBeIdentical}`);
|
|
56
|
+
debugOptions(`Exclude subfields: [${excludeSubfields}]`);
|
|
57
|
+
debugOptions(`Drop subfields [${dropSubfields}]`);
|
|
58
|
+
debugOptions(`Copy unless contains subfields: ${JSON.stringify(copyUnless)}`);
|
|
59
|
+
|
|
60
|
+
const baseFields = baseRecord.get(tagPattern);
|
|
61
|
+
const sourceFields = sourceRecord.get(tagPattern);
|
|
62
|
+
const doNotCopy = doNotCopyIfFieldPresent ? baseRecord.get(doNotCopyIfFieldPresent).length > 0 : false;
|
|
63
|
+
|
|
64
|
+
if (doNotCopy) {
|
|
65
|
+
return baseRecord.toObject();
|
|
66
|
+
}
|
|
67
|
+
debug(`FFS: ${compareWithoutIndicator1}, ${compareWithoutIndicators}, ${ignoreInd1}`);
|
|
68
|
+
debug(`Base fields: `, baseFields);
|
|
69
|
+
debug(`Source fields: `, sourceFields);
|
|
70
|
+
|
|
71
|
+
// Logic steps
|
|
72
|
+
const baseCompareFields = baseFields.map(baseField => createCompareField(baseField));
|
|
73
|
+
const compareResultFields = compareFields(sourceFields, baseCompareFields);
|
|
74
|
+
const droppedUnwantedSubfield = checkDropSubfields(compareResultFields);
|
|
75
|
+
const droppedUnwantedFields = checkCopyUnlessFields(droppedUnwantedSubfield);
|
|
76
|
+
const swappedSubfields = checkSwapSubfieldCodes(droppedUnwantedFields);
|
|
77
|
+
const swappedTags = checkSwapTag(swappedSubfields);
|
|
78
|
+
const uniqueFields = [...new Set(swappedTags.map(field => JSON.stringify(field)))].map(field => JSON.parse(field));
|
|
79
|
+
debug('Fields to be copied');
|
|
80
|
+
debug(JSON.stringify(uniqueFields));
|
|
81
|
+
|
|
82
|
+
// Add fields to base;
|
|
83
|
+
uniqueFields.forEach(field => baseRecord.insertField(field));
|
|
84
|
+
debugData(`baseRecord before return: ${JSON.stringify(baseRecord)}`);
|
|
85
|
+
//return baseRecord;
|
|
86
|
+
return baseRecord.toObject();
|
|
87
|
+
|
|
88
|
+
function compareFields(sourceFields, baseCompareFields, uniqFields = []) {
|
|
89
|
+
const [sourceField, ...rest] = sourceFields;
|
|
90
|
+
if (sourceField === undefined) {
|
|
91
|
+
return uniqFields;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (baseCompareFields.length === 0) {
|
|
95
|
+
return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Source and base are also compared for identicalness
|
|
99
|
+
// Non-identical fields are copied from source to base as duplicates
|
|
100
|
+
const sourceCompareField = createCompareField(sourceField);
|
|
101
|
+
const unique = checkCompareFields(baseCompareFields, sourceCompareField);
|
|
102
|
+
|
|
103
|
+
debugCompare(`${JSON.stringify(sourceField)} ${unique ? 'is UNIQUE' : 'not UNIQUE'}`);
|
|
104
|
+
|
|
105
|
+
if (unique) {
|
|
106
|
+
return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return compareFields(rest, baseCompareFields, uniqFields);
|
|
110
|
+
|
|
111
|
+
function checkCompareFields(baseCompareFields, sourceCompareField) {
|
|
112
|
+
let unique = true; // eslint-disable-line functional/no-let
|
|
113
|
+
|
|
114
|
+
baseCompareFields.forEach(baseCompareField => {
|
|
115
|
+
debugCompare(`Comparing ${JSON.stringify(sourceCompareField)} to ${JSON.stringify(baseCompareField)}}`);
|
|
116
|
+
|
|
117
|
+
if (sourceCompareField.value !== baseCompareField.value) {
|
|
118
|
+
debugCompare(`Value is different ${sourceCompareField.value} !== ${baseCompareField.value}`);
|
|
119
|
+
return;
|
|
68
120
|
}
|
|
69
|
-
|
|
70
|
-
|
|
121
|
+
|
|
122
|
+
if (sourceCompareField.ind1 !== baseCompareField.ind1) {
|
|
123
|
+
debugCompare(`Ind1 is different ${sourceCompareField.ind1} !== ${baseCompareField.ind1}`);
|
|
124
|
+
return;
|
|
71
125
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return normSourceSub === normBaseSub;
|
|
77
|
-
});
|
|
126
|
+
|
|
127
|
+
if (sourceCompareField.ind2 !== baseCompareField.ind2) {
|
|
128
|
+
debugCompare(`Ind2 is different ${sourceCompareField.ind2} !== ${baseCompareField.ind2}`);
|
|
129
|
+
return;
|
|
78
130
|
}
|
|
131
|
+
|
|
132
|
+
if ('subfields' in sourceCompareField) {
|
|
133
|
+
const allFound = checkSubfields(sourceCompareField.subfields, baseCompareField.subfields);
|
|
134
|
+
debugCompare(`Subfields are different ${!allFound}`);
|
|
135
|
+
if (!allFound) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
unique = false;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
unique = false;
|
|
144
|
+
return;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
return unique;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function checkSubfields(sourceSubfields, baseSubfields) {
|
|
151
|
+
const foundSubs = sourceSubfields.filter(sSub => baseSubfields.some(bSub => sSub.code === bSub.code && sSub.value === bSub.value));
|
|
152
|
+
|
|
153
|
+
if (subfieldsMustBeIdentical) {
|
|
154
|
+
return foundSubs.length === sourceSubfields.length && foundSubs.length === baseSubfields.length;
|
|
79
155
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
156
|
+
|
|
157
|
+
return foundSubs.length === sourceSubfields.length;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// compare objects have only fields that matter in comparison
|
|
162
|
+
function createCompareField(field) {
|
|
163
|
+
if (compareTagsOnly) {
|
|
164
|
+
return {tag: field.tag};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if ('value' in field) {
|
|
168
|
+
return {tag: field.tag, value: field.value};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const [filteredField] = checkDropSubfields([field]);
|
|
172
|
+
const [foundRule] = swapTag.filter(rule => new RegExp(rule.from, 'u').test(field.tag));
|
|
173
|
+
const replacementTag = foundRule ? foundRule.to : undefined;
|
|
174
|
+
|
|
175
|
+
const params = [
|
|
176
|
+
{name: 'tag', value: compareWithoutTag ? replacementTag : field.tag},
|
|
177
|
+
{name: 'ind1', value: ignoreInd1 ? undefined : field.ind1},
|
|
178
|
+
{name: 'ind2', value: ignoreInd2 ? undefined : field.ind2},
|
|
179
|
+
{name: 'subfields', value: createCompareSubfields(filteredField.subfields)}
|
|
180
|
+
].map(param => [param.name, param.value]);
|
|
181
|
+
|
|
182
|
+
return Object.fromEntries(params);
|
|
183
|
+
|
|
184
|
+
function createCompareSubfields(subfields) {
|
|
185
|
+
const nonExcludedSubfields = subfields.filter(sub => !excludeSubfields.some(code => code === sub.code));
|
|
186
|
+
const normalizedSubfields = nonExcludedSubfields.map(sub => ({code: sub.code, value: normalizeSubfieldValue(sub.value)}));
|
|
187
|
+
|
|
188
|
+
return normalizedSubfields;
|
|
189
|
+
|
|
190
|
+
function normalizeSubfieldValue(value) {
|
|
191
|
+
return value.toLowerCase().replace(/\s+/ug, '');
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function checkSwapTag(fields) {
|
|
197
|
+
if (swapTag.length > 0) {
|
|
198
|
+
return fields.map(field => ({...field, tag: swapTagsFunc(field.tag)}));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return fields;
|
|
202
|
+
|
|
203
|
+
function swapTagsFunc(tag) {
|
|
204
|
+
const [foundRule] = swapTag.filter(rule => new RegExp(rule.from, 'u').test(tag));
|
|
205
|
+
|
|
206
|
+
if (foundRule === undefined) {
|
|
207
|
+
return tag;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return foundRule.to;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function checkSwapSubfieldCodes(fields) {
|
|
215
|
+
if (swapSubfieldCode.length > 0) {
|
|
216
|
+
return fields.map(field => ({...field, subfields: swapSubfieldCodesFunc(field.subfields)}));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return fields;
|
|
220
|
+
|
|
221
|
+
function swapSubfieldCodesFunc(subfields) {
|
|
222
|
+
return subfields.map(sub => {
|
|
223
|
+
const [foundRule] = swapSubfieldCode.filter(rule => rule.from === sub.code);
|
|
224
|
+
|
|
225
|
+
if (foundRule === undefined) {
|
|
226
|
+
return sub;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return {code: foundRule.to, value: sub.value};
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function checkDropSubfields(fields) {
|
|
235
|
+
if (dropSubfields.length > 0) {
|
|
236
|
+
return fields.map(field => ({...field, subfields: dropSubfieldsFunc(field.subfields)}))
|
|
237
|
+
.filter(field => field.subfields.length > 0);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return fields;
|
|
241
|
+
|
|
242
|
+
function dropSubfieldsFunc(subfields) {
|
|
243
|
+
return subfields.filter(sub => { // eslint-disable-line
|
|
244
|
+
return !dropSubfields.some(({code, value = false, condition = false}) => {
|
|
245
|
+
if (code !== sub.code) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (!condition && value) {
|
|
250
|
+
return value === sub.value;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (condition === 'unless' && value) {
|
|
254
|
+
return !new RegExp(value, 'u').test(sub.value);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return true;
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function checkCopyUnlessFields(fields) {
|
|
264
|
+
if (copyUnless.length > 0) {
|
|
265
|
+
return fields.filter(({subfields}) => copyUnless.some(filter => !subfields.some(sub => sub.code === filter.code && new RegExp(filter.value, 'u').test(sub.value))));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return fields;
|
|
87
269
|
}
|
|
88
270
|
};
|