@natlibfi/marc-record-validators-melinda 3.2.0 → 3.3.14-alpha.2
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 +2 -0
- package/.github/dependabot.yml +40 -0
- package/.github/workflows/melinda-node-tests.yml +61 -0
- package/LICENSE.txt +21 -661
- package/README.md +4 -5
- package/dist/access-rights.js +94 -0
- package/dist/access-rights.js.map +1 -0
- package/dist/access-rights.spec.js +150 -0
- package/dist/access-rights.spec.js.map +1 -0
- package/dist/double-commas.js +17 -27
- package/dist/double-commas.js.map +1 -1
- package/dist/double-commas.spec.js +72 -27
- package/dist/double-commas.spec.js.map +1 -1
- package/dist/duplicates-ind1.js +47 -27
- package/dist/duplicates-ind1.js.map +1 -1
- package/dist/duplicates-ind1.spec.js +44 -27
- package/dist/duplicates-ind1.spec.js.map +1 -1
- package/dist/empty-fields.js +79 -29
- package/dist/empty-fields.js.map +1 -1
- package/dist/empty-fields.spec.js +113 -27
- package/dist/empty-fields.spec.js.map +1 -1
- package/dist/ending-punctuation-conf.js +772 -129
- package/dist/ending-punctuation-conf.js.map +1 -1
- package/dist/ending-punctuation.js +291 -72
- package/dist/ending-punctuation.js.map +1 -1
- package/dist/ending-punctuation.spec.js +2638 -118
- package/dist/ending-punctuation.spec.js.map +1 -1
- package/dist/ending-whitespace.js +58 -0
- package/dist/ending-whitespace.js.map +1 -0
- package/dist/ending-whitespace.spec.js +42 -0
- package/dist/ending-whitespace.spec.js.map +1 -0
- package/dist/field-521-fix.js +96 -0
- package/dist/field-521-fix.js.map +1 -0
- package/dist/field-521-fix.spec.js +51 -0
- package/dist/field-521-fix.spec.js.map +1 -0
- package/dist/field-exclusion.js +214 -63
- package/dist/field-exclusion.js.map +1 -1
- package/dist/field-exclusion.spec.js +1057 -31
- package/dist/field-exclusion.spec.js.map +1 -1
- package/dist/field-structure.js +249 -78
- package/dist/field-structure.js.map +1 -1
- package/dist/field-structure.spec.js +534 -31
- package/dist/field-structure.spec.js.map +1 -1
- package/dist/fields-present.js +31 -27
- package/dist/fields-present.js.map +1 -1
- package/dist/fields-present.spec.js +120 -27
- package/dist/fields-present.spec.js.map +1 -1
- package/dist/fixed-fields.js +72 -27
- package/dist/fixed-fields.js.map +1 -1
- package/dist/fixed-fields.spec.js +139 -27
- package/dist/fixed-fields.spec.js.map +1 -1
- package/dist/identical-fields.js +42 -28
- package/dist/identical-fields.js.map +1 -1
- package/dist/identical-fields.spec.js +98 -27
- package/dist/identical-fields.spec.js.map +1 -1
- package/dist/index.js +202 -27
- package/dist/index.js.map +1 -1
- package/dist/indicator-fixes.js +191 -0
- package/dist/indicator-fixes.js.map +1 -0
- package/dist/indicator-fixes.spec.js +51 -0
- package/dist/indicator-fixes.spec.js.map +1 -0
- package/dist/isbn-issn.js +266 -27
- package/dist/isbn-issn.js.map +1 -1
- package/dist/isbn-issn.spec.js +594 -27
- package/dist/isbn-issn.spec.js.map +1 -1
- package/dist/item-language.js +171 -27
- package/dist/item-language.js.map +1 -1
- package/dist/item-language.spec.js +305 -27
- package/dist/item-language.spec.js.map +1 -1
- package/dist/mergeField500Lisapainokset.js +155 -0
- package/dist/mergeField500Lisapainokset.js.map +1 -0
- package/dist/mergeField500Lisapainokset.spec.js +51 -0
- package/dist/mergeField500Lisapainokset.spec.js.map +1 -0
- package/dist/mergeRelatorTermFields.js +140 -0
- package/dist/mergeRelatorTermFields.js.map +1 -0
- package/dist/mergeRelatorTermFields.spec.js +51 -0
- package/dist/mergeRelatorTermFields.spec.js.map +1 -0
- package/dist/multiple-subfield-0.js +120 -0
- package/dist/multiple-subfield-0.js.map +1 -0
- package/dist/multiple-subfield-0.spec.js +51 -0
- package/dist/multiple-subfield-0.spec.js.map +1 -0
- package/dist/non-breaking-space.js +61 -0
- package/dist/non-breaking-space.js.map +1 -0
- package/dist/non-breaking-space.spec.js +42 -0
- package/dist/non-breaking-space.spec.js.map +1 -0
- package/dist/normalize-identifiers.js +210 -0
- package/dist/normalize-identifiers.js.map +1 -0
- package/dist/normalize-identifiers.spec.js +51 -0
- package/dist/normalize-identifiers.spec.js.map +1 -0
- package/dist/normalize-utf8-diacritics.js +140 -0
- package/dist/normalize-utf8-diacritics.js.map +1 -0
- package/dist/normalize-utf8-diacritics.spec.js +51 -0
- package/dist/normalize-utf8-diacritics.spec.js.map +1 -0
- package/dist/punctuation/index.js +281 -0
- package/dist/punctuation/index.js.map +1 -0
- package/dist/punctuation/rules/aut.js +332 -0
- package/dist/punctuation/rules/aut.js.map +1 -0
- package/dist/punctuation/rules/bib.js +374 -0
- package/dist/punctuation/rules/bib.js.map +1 -0
- package/dist/punctuation/rules/index.js +21 -0
- package/dist/punctuation/rules/index.js.map +1 -0
- package/dist/punctuation.spec.js +51 -0
- package/dist/punctuation.spec.js.map +1 -0
- package/dist/punctuation2.js +726 -0
- package/dist/punctuation2.js.map +1 -0
- package/dist/punctuation2.spec.js +51 -0
- package/dist/punctuation2.spec.js.map +1 -0
- package/dist/reindexSubfield6OccurenceNumbers.js +199 -0
- package/dist/reindexSubfield6OccurenceNumbers.js.map +1 -0
- package/dist/reindexSubfield6OccurenceNumbers.spec.js +51 -0
- package/dist/reindexSubfield6OccurenceNumbers.spec.js.map +1 -0
- package/dist/removeDuplicateDataFields.js +405 -0
- package/dist/removeDuplicateDataFields.js.map +1 -0
- package/dist/removeDuplicateDataFields.spec.js +51 -0
- package/dist/removeDuplicateDataFields.spec.js.map +1 -0
- package/dist/removeInferiorDataFields.js +245 -0
- package/dist/removeInferiorDataFields.js.map +1 -0
- package/dist/removeInferiorDataFields.spec.js +51 -0
- package/dist/removeInferiorDataFields.spec.js.map +1 -0
- package/dist/resolvable-ext-references-melinda.js +112 -31
- package/dist/resolvable-ext-references-melinda.js.map +1 -1
- package/dist/resolvable-ext-references-melinda.spec.js +166 -27
- package/dist/resolvable-ext-references-melinda.spec.js.map +1 -1
- package/dist/resolveOrphanedSubfield6s.js +116 -0
- package/dist/resolveOrphanedSubfield6s.js.map +1 -0
- package/dist/resolveOrphanedSubfield6s.spec.js +51 -0
- package/dist/resolveOrphanedSubfield6s.spec.js.map +1 -0
- package/dist/sanitize-vocabulary-source-codes.js +93 -0
- package/dist/sanitize-vocabulary-source-codes.js.map +1 -0
- package/dist/sanitize-vocabulary-source-codes.spec.js +51 -0
- package/dist/sanitize-vocabulary-source-codes.spec.js.map +1 -0
- package/dist/sort-tags.js +53 -27
- package/dist/sort-tags.js.map +1 -1
- package/dist/sort-tags.spec.js +206 -27
- package/dist/sort-tags.spec.js.map +1 -1
- package/dist/sortRelatorTerms.js +135 -0
- package/dist/sortRelatorTerms.js.map +1 -0
- package/dist/sortRelatorTerms.spec.js +51 -0
- package/dist/sortRelatorTerms.spec.js.map +1 -0
- package/dist/sortSubfields.js +279 -0
- package/dist/sortSubfields.js.map +1 -0
- package/dist/sortSubfields.spec.js +51 -0
- package/dist/sortSubfields.spec.js.map +1 -0
- package/dist/stripPunctuation.js +49 -0
- package/dist/stripPunctuation.js.map +1 -0
- package/dist/stripPunctuation.spec.js +51 -0
- package/dist/stripPunctuation.spec.js.map +1 -0
- package/dist/subfield-exclusion.js +174 -57
- package/dist/subfield-exclusion.js.map +1 -1
- package/dist/subfield-exclusion.spec.js +521 -31
- package/dist/subfield-exclusion.spec.js.map +1 -1
- package/dist/subfield6Utils.js +457 -0
- package/dist/subfield6Utils.js.map +1 -0
- package/dist/subfield8Utils.js +99 -0
- package/dist/subfield8Utils.js.map +1 -0
- package/dist/typeOfDate-008.js +48 -0
- package/dist/typeOfDate-008.js.map +1 -0
- package/dist/typeOfDate-008.spec.js +47 -0
- package/dist/typeOfDate-008.spec.js.map +1 -0
- package/dist/unicode-decomposition.js +139 -30
- package/dist/unicode-decomposition.js.map +1 -1
- package/dist/unicode-decomposition.spec.js +90 -27
- package/dist/unicode-decomposition.spec.js.map +1 -1
- package/dist/update-field-540.js +119 -0
- package/dist/update-field-540.js.map +1 -0
- package/dist/update-field-540.spec.js +51 -0
- package/dist/update-field-540.spec.js.map +1 -0
- package/dist/urn.js +185 -0
- package/dist/urn.js.map +1 -0
- package/dist/urn.spec.js +238 -0
- package/dist/urn.spec.js.map +1 -0
- package/dist/utils.js +58 -0
- package/dist/utils.js.map +1 -0
- package/package.json +114 -124
- package/src/access-rights.js +84 -0
- package/src/access-rights.spec.js +126 -0
- package/src/double-commas.js +12 -49
- package/src/double-commas.spec.js +50 -82
- package/src/duplicates-ind1.js +34 -74
- package/src/duplicates-ind1.spec.js +39 -117
- package/src/empty-fields.js +62 -74
- package/src/empty-fields.spec.js +134 -207
- package/src/ending-punctuation-conf.js +679 -644
- package/src/ending-punctuation.js +260 -250
- package/src/ending-punctuation.spec.js +2545 -2322
- package/src/ending-whitespace.js +40 -0
- package/src/ending-whitespace.spec.js +44 -0
- package/src/field-521-fix.js +92 -0
- package/src/field-521-fix.spec.js +52 -0
- package/src/field-exclusion.js +197 -215
- package/src/field-exclusion.spec.js +883 -481
- package/src/field-structure.js +213 -271
- package/src/field-structure.spec.js +597 -474
- package/src/fields-present.js +19 -49
- package/src/fields-present.spec.js +90 -91
- package/src/fixed-fields.js +61 -94
- package/src/fixed-fields.spec.js +81 -125
- package/src/identical-fields.js +29 -48
- package/src/identical-fields.spec.js +114 -146
- package/src/index.js +41 -46
- package/src/indicator-fixes.js +211 -0
- package/src/indicator-fixes.spec.js +52 -0
- package/src/isbn-issn.js +254 -106
- package/src/isbn-issn.spec.js +399 -172
- package/src/item-language.js +158 -195
- package/src/item-language.spec.js +314 -306
- package/src/mergeField500Lisapainokset.js +153 -0
- package/src/mergeField500Lisapainokset.spec.js +52 -0
- package/src/mergeRelatorTermFields.js +143 -0
- package/src/mergeRelatorTermFields.spec.js +52 -0
- package/src/multiple-subfield-0.js +129 -0
- package/src/multiple-subfield-0.spec.js +52 -0
- package/src/non-breaking-space.js +49 -0
- package/src/non-breaking-space.spec.js +44 -0
- package/src/normalize-identifiers.js +197 -0
- package/src/normalize-identifiers.spec.js +52 -0
- package/src/normalize-utf8-diacritics.js +141 -0
- package/src/normalize-utf8-diacritics.spec.js +52 -0
- package/src/punctuation/index.js +292 -0
- package/src/punctuation/rules/aut.js +372 -0
- package/src/punctuation/rules/bib.js +420 -0
- package/src/punctuation/rules/index.js +7 -0
- package/src/punctuation.spec.js +52 -0
- package/src/punctuation2.js +441 -0
- package/src/punctuation2.spec.js +52 -0
- package/src/reindexSubfield6OccurenceNumbers.js +210 -0
- package/src/reindexSubfield6OccurenceNumbers.spec.js +52 -0
- package/src/removeDuplicateDataFields.js +447 -0
- package/src/removeDuplicateDataFields.spec.js +52 -0
- package/src/removeInferiorDataFields.js +259 -0
- package/src/removeInferiorDataFields.spec.js +52 -0
- package/src/resolvable-ext-references-melinda.js +89 -122
- package/src/resolvable-ext-references-melinda.spec.js +168 -198
- package/src/resolveOrphanedSubfield6s.js +115 -0
- package/src/resolveOrphanedSubfield6s.spec.js +52 -0
- package/src/sanitize-vocabulary-source-codes.js +99 -0
- package/src/sanitize-vocabulary-source-codes.spec.js +52 -0
- package/src/sort-tags.js +34 -60
- package/src/sort-tags.spec.js +256 -290
- package/src/sortRelatorTerms.js +142 -0
- package/src/sortRelatorTerms.spec.js +52 -0
- package/src/sortSubfields.js +176 -0
- package/src/sortSubfields.spec.js +52 -0
- package/src/stripPunctuation.js +42 -0
- package/src/stripPunctuation.spec.js +52 -0
- package/src/subfield-exclusion.js +157 -180
- package/src/subfield-exclusion.spec.js +507 -453
- package/src/subfield6Utils.js +485 -0
- package/src/subfield8Utils.js +102 -0
- package/src/typeOfDate-008.js +40 -0
- package/src/typeOfDate-008.spec.js +47 -0
- package/src/unicode-decomposition.js +130 -145
- package/src/unicode-decomposition.spec.js +89 -115
- package/src/update-field-540.js +99 -0
- package/src/update-field-540.spec.js +52 -0
- package/src/urn.js +164 -0
- package/src/urn.spec.js +231 -0
- package/src/utils.js +52 -0
- package/test-fixtures/duplicates-ind1/01/expectedResult.json +4 -0
- package/test-fixtures/duplicates-ind1/01/metadata.json +4 -0
- package/test-fixtures/duplicates-ind1/01/record.json +16 -0
- package/test-fixtures/duplicates-ind1/02/expectedResult.json +6 -0
- package/test-fixtures/duplicates-ind1/02/metadata.json +4 -0
- package/test-fixtures/duplicates-ind1/02/record.json +16 -0
- package/test-fixtures/duplicates-ind1/03/expectedResult.json +13 -0
- package/test-fixtures/duplicates-ind1/03/metadata.json +6 -0
- package/test-fixtures/duplicates-ind1/03/record.json +16 -0
- package/test-fixtures/ending-whitespace/01/expectedResult.json +4 -0
- package/test-fixtures/ending-whitespace/01/metadata.json +6 -0
- package/test-fixtures/ending-whitespace/01/record.json +15 -0
- package/test-fixtures/ending-whitespace/02/expectedResult.json +4 -0
- package/test-fixtures/ending-whitespace/02/metadata.json +6 -0
- package/test-fixtures/ending-whitespace/02/record.json +15 -0
- package/test-fixtures/ending-whitespace/03/expectedResult.json +17 -0
- package/test-fixtures/ending-whitespace/03/metadata.json +6 -0
- package/test-fixtures/ending-whitespace/03/record.json +15 -0
- package/test-fixtures/ending-whitespace/04/expectedResult.json +10 -0
- package/test-fixtures/ending-whitespace/04/metadata.json +6 -0
- package/test-fixtures/ending-whitespace/04/record.json +8 -0
- package/test-fixtures/fix521/01/expectedResult.json +6 -0
- package/test-fixtures/fix521/01/metadata.json +5 -0
- package/test-fixtures/fix521/01/record.json +13 -0
- package/test-fixtures/fix521/02/expectedResult.json +15 -0
- package/test-fixtures/fix521/02/metadata.json +5 -0
- package/test-fixtures/fix521/02/record.json +13 -0
- package/test-fixtures/fix521/03/expectedResult.json +5 -0
- package/test-fixtures/fix521/03/metadata.json +5 -0
- package/test-fixtures/fix521/03/record.json +13 -0
- package/test-fixtures/indicator-fixes/01/expectedResult.json +9 -0
- package/test-fixtures/indicator-fixes/01/metadata.json +5 -0
- package/test-fixtures/indicator-fixes/01/record.json +64 -0
- package/test-fixtures/indicator-fixes/02/expectedResult.json +66 -0
- package/test-fixtures/indicator-fixes/02/metadata.json +5 -0
- package/test-fixtures/indicator-fixes/02/record.json +64 -0
- package/test-fixtures/indicator-fixes/03/expectedResult.json +55 -0
- package/test-fixtures/indicator-fixes/03/metadata.json +5 -0
- package/test-fixtures/indicator-fixes/03/record.json +54 -0
- package/test-fixtures/indicator-fixes/04/expectedResult.json +66 -0
- package/test-fixtures/indicator-fixes/04/metadata.json +5 -0
- package/test-fixtures/indicator-fixes/04/record.json +65 -0
- package/test-fixtures/indicator-fixes/05/expectedResult.json +66 -0
- package/test-fixtures/indicator-fixes/05/metadata.json +5 -0
- package/test-fixtures/indicator-fixes/05/record.json +65 -0
- package/test-fixtures/indicator-fixes/06/expectedResult.json +75 -0
- package/test-fixtures/indicator-fixes/06/metadata.json +5 -0
- package/test-fixtures/indicator-fixes/06/record.json +74 -0
- package/test-fixtures/lisapainokset/fixer/01/expectedResult.json +37 -0
- package/test-fixtures/lisapainokset/fixer/01/metadata.json +6 -0
- package/test-fixtures/lisapainokset/fixer/01/record.json +61 -0
- package/test-fixtures/lisapainokset/fixer/02/expectedResult.json +44 -0
- package/test-fixtures/lisapainokset/fixer/02/metadata.json +6 -0
- package/test-fixtures/lisapainokset/fixer/02/record.json +45 -0
- package/test-fixtures/lisapainokset/fixer/03/expectedResult.json +21 -0
- package/test-fixtures/lisapainokset/fixer/03/metadata.json +6 -0
- package/test-fixtures/lisapainokset/fixer/03/record.json +45 -0
- package/test-fixtures/lisapainokset/validator/01/expectedResult.json +7 -0
- package/test-fixtures/lisapainokset/validator/01/metadata.json +6 -0
- package/test-fixtures/lisapainokset/validator/01/record.json +45 -0
- package/test-fixtures/lisapainokset/validator/02/expectedResult.json +6 -0
- package/test-fixtures/lisapainokset/validator/02/metadata.json +6 -0
- package/test-fixtures/lisapainokset/validator/02/record.json +61 -0
- package/test-fixtures/lisapainokset/validator/03/expectedResult.json +4 -0
- package/test-fixtures/lisapainokset/validator/03/metadata.json +6 -0
- package/test-fixtures/lisapainokset/validator/03/record.json +37 -0
- package/test-fixtures/mergeRelatorTermFields/fixer/01/expectedResult.json +14 -0
- package/test-fixtures/mergeRelatorTermFields/fixer/01/metadata.json +6 -0
- package/test-fixtures/mergeRelatorTermFields/fixer/01/record.json +16 -0
- package/test-fixtures/mergeRelatorTermFields/fixer/02/expectedResult.json +17 -0
- package/test-fixtures/mergeRelatorTermFields/fixer/02/metadata.json +6 -0
- package/test-fixtures/mergeRelatorTermFields/fixer/02/record.json +23 -0
- package/test-fixtures/mergeRelatorTermFields/validator/01/expectedResult.json +6 -0
- package/test-fixtures/mergeRelatorTermFields/validator/01/metadata.json +6 -0
- package/test-fixtures/mergeRelatorTermFields/validator/01/record.json +16 -0
- package/test-fixtures/mergeRelatorTermFields/validator/02/expectedResult.json +4 -0
- package/test-fixtures/mergeRelatorTermFields/validator/02/metadata.json +6 -0
- package/test-fixtures/mergeRelatorTermFields/validator/02/record.json +16 -0
- package/test-fixtures/non-breaking-space/01/expectedResult.json +4 -0
- package/test-fixtures/non-breaking-space/01/metadata.json +6 -0
- package/test-fixtures/non-breaking-space/01/record.json +15 -0
- package/test-fixtures/non-breaking-space/02/expectedResult.json +4 -0
- package/test-fixtures/non-breaking-space/02/metadata.json +6 -0
- package/test-fixtures/non-breaking-space/02/record.json +15 -0
- package/test-fixtures/non-breaking-space/03/expectedResult.json +17 -0
- package/test-fixtures/non-breaking-space/03/metadata.json +6 -0
- package/test-fixtures/non-breaking-space/03/record.json +15 -0
- package/test-fixtures/non-breaking-space/04/expectedResult.json +21 -0
- package/test-fixtures/non-breaking-space/04/metadata.json +6 -0
- package/test-fixtures/non-breaking-space/04/record.json +19 -0
- package/test-fixtures/normalize-identifiers/01/expectedResult.json +8 -0
- package/test-fixtures/normalize-identifiers/01/metadata.json +5 -0
- package/test-fixtures/normalize-identifiers/01/record.json +81 -0
- package/test-fixtures/normalize-identifiers/02/expectedResult.json +92 -0
- package/test-fixtures/normalize-identifiers/02/metadata.json +5 -0
- package/test-fixtures/normalize-identifiers/02/record.json +92 -0
- package/test-fixtures/normalize-identifiers/03/expectedResult.json +63 -0
- package/test-fixtures/normalize-identifiers/03/metadata.json +5 -0
- package/test-fixtures/normalize-identifiers/03/record.json +61 -0
- package/test-fixtures/normalize-identifiers/04/expectedResult.json +79 -0
- package/test-fixtures/normalize-identifiers/04/metadata.json +5 -0
- package/test-fixtures/normalize-identifiers/04/record.json +77 -0
- package/test-fixtures/normalize-utf8-diacritics/01/expectedResult.json +7 -0
- package/test-fixtures/normalize-utf8-diacritics/01/metadata.json +5 -0
- package/test-fixtures/normalize-utf8-diacritics/01/record.json +39 -0
- package/test-fixtures/normalize-utf8-diacritics/02/expectedResult.json +41 -0
- package/test-fixtures/normalize-utf8-diacritics/02/metadata.json +5 -0
- package/test-fixtures/normalize-utf8-diacritics/02/record.json +39 -0
- package/test-fixtures/normalize-utf8-diacritics/03/expectedResult.json +5 -0
- package/test-fixtures/normalize-utf8-diacritics/03/metadata.json +5 -0
- package/test-fixtures/normalize-utf8-diacritics/03/record.json +37 -0
- package/test-fixtures/normalize-utf8-diacritics/04/expectedResult.json +41 -0
- package/test-fixtures/normalize-utf8-diacritics/04/metadata.json +5 -0
- package/test-fixtures/normalize-utf8-diacritics/04/record.json +39 -0
- package/test-fixtures/normalize-utf8-diacritics/05/expectedResult.json +41 -0
- package/test-fixtures/normalize-utf8-diacritics/05/metadata.json +5 -0
- package/test-fixtures/normalize-utf8-diacritics/05/record.json +41 -0
- package/test-fixtures/punctuation/01/expectedResult.json +3 -0
- package/test-fixtures/punctuation/01/metadata.json +4 -0
- package/test-fixtures/punctuation/01/record.json +18 -0
- package/test-fixtures/punctuation/02/expectedResult.json +3 -0
- package/test-fixtures/punctuation/02/metadata.json +4 -0
- package/test-fixtures/punctuation/02/record.json +18 -0
- package/test-fixtures/punctuation/03/expectedResult.json +21 -0
- package/test-fixtures/punctuation/03/metadata.json +5 -0
- package/test-fixtures/punctuation/03/record.json +19 -0
- package/test-fixtures/punctuation/04/expectedResult.json +21 -0
- package/test-fixtures/punctuation/04/metadata.json +5 -0
- package/test-fixtures/punctuation/04/record.json +19 -0
- package/test-fixtures/punctuation/05/expectedResult.json +44 -0
- package/test-fixtures/punctuation/05/metadata.json +5 -0
- package/test-fixtures/punctuation/05/record.json +42 -0
- package/test-fixtures/punctuation2/01/expectedResult.json +12 -0
- package/test-fixtures/punctuation2/01/metadata.json +6 -0
- package/test-fixtures/punctuation2/01/record.json +37 -0
- package/test-fixtures/punctuation2/02/expectedResult.json +4 -0
- package/test-fixtures/punctuation2/02/metadata.json +6 -0
- package/test-fixtures/punctuation2/02/record.json +14 -0
- package/test-fixtures/punctuation2/04/expectedResult.json +7 -0
- package/test-fixtures/punctuation2/04/metadata.json +6 -0
- package/test-fixtures/punctuation2/04/record.json +22 -0
- package/test-fixtures/punctuation2/05/expectedResult.json +6 -0
- package/test-fixtures/punctuation2/05/metadata.json +6 -0
- package/test-fixtures/punctuation2/05/record.json +12 -0
- package/test-fixtures/punctuation2/98/expectedResult.json +45 -0
- package/test-fixtures/punctuation2/98/metadata.json +6 -0
- package/test-fixtures/punctuation2/98/record.json +43 -0
- package/test-fixtures/punctuation2/99/expectedResult.json +15 -0
- package/test-fixtures/punctuation2/99/metadata.json +6 -0
- package/test-fixtures/punctuation2/99/record.json +14 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f01/expectedResult.json +35 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f01/metadata.json +6 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f01/record.json +34 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f02/expectedResult.json +53 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f02/metadata.json +6 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f02/record.json +51 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f03/expectedResult.json +46 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f03/metadata.json +7 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/f03/record.json +44 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v01/expectedResult.json +6 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v01/metadata.json +5 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v01/record.json +31 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v02/expectedResult.json +6 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v02/metadata.json +6 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v02/record.json +38 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v03/expectedResult.json +6 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v03/metadata.json +6 -0
- package/test-fixtures/reindex-sf6-occurence-numbers/v03/record.json +30 -0
- package/test-fixtures/remove-duplicate-datafields/f01/expectedResult.json +35 -0
- package/test-fixtures/remove-duplicate-datafields/f01/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f01/record.json +34 -0
- package/test-fixtures/remove-duplicate-datafields/f03/expectedResult.json +20 -0
- package/test-fixtures/remove-duplicate-datafields/f03/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f03/record.json +33 -0
- package/test-fixtures/remove-duplicate-datafields/f03b/expectedResult.json +20 -0
- package/test-fixtures/remove-duplicate-datafields/f03b/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f03b/record.json +35 -0
- package/test-fixtures/remove-duplicate-datafields/f03c/expectedResult.json +25 -0
- package/test-fixtures/remove-duplicate-datafields/f03c/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f03c/record.json +43 -0
- package/test-fixtures/remove-duplicate-datafields/f04/expectedResult.json +31 -0
- package/test-fixtures/remove-duplicate-datafields/f04/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f04/record.json +41 -0
- package/test-fixtures/remove-duplicate-datafields/f05/expectedResult.json +23 -0
- package/test-fixtures/remove-duplicate-datafields/f05/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f05/record.json +29 -0
- package/test-fixtures/remove-duplicate-datafields/f06/expectedResult.json +24 -0
- package/test-fixtures/remove-duplicate-datafields/f06/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f06/record.json +41 -0
- package/test-fixtures/remove-duplicate-datafields/f07/expectedResult.json +15 -0
- package/test-fixtures/remove-duplicate-datafields/f07/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f07/record.json +21 -0
- package/test-fixtures/remove-duplicate-datafields/f08/expectedResult.json +21 -0
- package/test-fixtures/remove-duplicate-datafields/f08/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f08/record.json +33 -0
- package/test-fixtures/remove-duplicate-datafields/f09/expectedResult.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f09/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f09/record.json +9 -0
- package/test-fixtures/remove-duplicate-datafields/f10/expectedResult.json +15 -0
- package/test-fixtures/remove-duplicate-datafields/f10/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f10/record.json +24 -0
- package/test-fixtures/remove-duplicate-datafields/f11/expectedResult.json +30 -0
- package/test-fixtures/remove-duplicate-datafields/f11/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/f11/record.json +53 -0
- package/test-fixtures/remove-duplicate-datafields/v01/expectedResult.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/v01/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/v01/record.json +31 -0
- package/test-fixtures/remove-duplicate-datafields/v02/expectedResult.json +10 -0
- package/test-fixtures/remove-duplicate-datafields/v02/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/v02/record.json +45 -0
- package/test-fixtures/remove-duplicate-datafields/v03/expectedResult.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/v03/metadata.json +7 -0
- package/test-fixtures/remove-duplicate-datafields/v03/record.json +37 -0
- package/test-fixtures/remove-duplicate-datafields/v04/expectedResult.json +8 -0
- package/test-fixtures/remove-duplicate-datafields/v04/metadata.json +6 -0
- package/test-fixtures/remove-duplicate-datafields/v04/record.json +41 -0
- package/test-fixtures/remove-inferior-datafields/f01/expectedResult.json +21 -0
- package/test-fixtures/remove-inferior-datafields/f01/metadata.json +6 -0
- package/test-fixtures/remove-inferior-datafields/f01/record.json +31 -0
- package/test-fixtures/remove-inferior-datafields/f03/expectedResult.json +16 -0
- package/test-fixtures/remove-inferior-datafields/f03/metadata.json +6 -0
- package/test-fixtures/remove-inferior-datafields/f03/record.json +27 -0
- package/test-fixtures/remove-inferior-datafields/f04/expectedResult.json +31 -0
- package/test-fixtures/remove-inferior-datafields/f04/metadata.json +6 -0
- package/test-fixtures/remove-inferior-datafields/f04/record.json +38 -0
- package/test-fixtures/remove-inferior-datafields/f05/expectedResult.json +34 -0
- package/test-fixtures/remove-inferior-datafields/f05/metadata.json +6 -0
- package/test-fixtures/remove-inferior-datafields/f05/record.json +41 -0
- package/test-fixtures/remove-inferior-datafields/f06/expectedResult.json +16 -0
- package/test-fixtures/remove-inferior-datafields/f06/metadata.json +6 -0
- package/test-fixtures/remove-inferior-datafields/f06/record.json +20 -0
- package/test-fixtures/remove-inferior-datafields/v01/expectedResult.json +6 -0
- package/test-fixtures/remove-inferior-datafields/v01/metadata.json +6 -0
- package/test-fixtures/remove-inferior-datafields/v01/record.json +31 -0
- package/test-fixtures/remove-inferior-datafields/v02/expectedResult.json +6 -0
- package/test-fixtures/remove-inferior-datafields/v02/metadata.json +6 -0
- package/test-fixtures/remove-inferior-datafields/v02/record.json +21 -0
- package/test-fixtures/remove-orphanded-sf6s/f01/expectedResult.json +35 -0
- package/test-fixtures/remove-orphanded-sf6s/f01/metadata.json +6 -0
- package/test-fixtures/remove-orphanded-sf6s/f01/record.json +34 -0
- package/test-fixtures/remove-orphanded-sf6s/f02/expectedResult.json +40 -0
- package/test-fixtures/remove-orphanded-sf6s/f02/metadata.json +6 -0
- package/test-fixtures/remove-orphanded-sf6s/f02/record.json +43 -0
- package/test-fixtures/remove-orphanded-sf6s/v01/expectedResult.json +6 -0
- package/test-fixtures/remove-orphanded-sf6s/v01/metadata.json +6 -0
- package/test-fixtures/remove-orphanded-sf6s/v01/record.json +31 -0
- package/test-fixtures/remove-orphanded-sf6s/v02/expectedResult.json +6 -0
- package/test-fixtures/remove-orphanded-sf6s/v02/metadata.json +6 -0
- package/test-fixtures/remove-orphanded-sf6s/v02/record.json +31 -0
- package/test-fixtures/resolvable-ext-references-melinda.js +0 -27
- package/test-fixtures/sanitize-vocabulary-source-codes/f01/expectedResult.json +32 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/f01/metadata.json +6 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/f01/record.json +32 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/f02/expectedResult.json +24 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/f02/metadata.json +6 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/f02/record.json +24 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/v01/expectedResult.json +12 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/v01/metadata.json +6 -0
- package/test-fixtures/sanitize-vocabulary-source-codes/v01/record.json +24 -0
- package/test-fixtures/sort-relator-terms/f01/expectedResult.json +23 -0
- package/test-fixtures/sort-relator-terms/f01/metadata.json +6 -0
- package/test-fixtures/sort-relator-terms/f01/record.json +22 -0
- package/test-fixtures/sort-relator-terms/f02/expectedResult.json +26 -0
- package/test-fixtures/sort-relator-terms/f02/metadata.json +6 -0
- package/test-fixtures/sort-relator-terms/f02/record.json +22 -0
- package/test-fixtures/sort-relator-terms/v01/expectedResult.json +5 -0
- package/test-fixtures/sort-relator-terms/v01/metadata.json +6 -0
- package/test-fixtures/sort-relator-terms/v01/record.json +22 -0
- package/test-fixtures/sort-relator-terms/v02/expectedResult.json +6 -0
- package/test-fixtures/sort-relator-terms/v02/metadata.json +6 -0
- package/test-fixtures/sort-relator-terms/v02/record.json +14 -0
- package/test-fixtures/sort-subfields/f01/expectedResult.json +24 -0
- package/test-fixtures/sort-subfields/f01/metadata.json +6 -0
- package/test-fixtures/sort-subfields/f01/record.json +20 -0
- package/test-fixtures/sort-subfields/v01/expectedResult.json +5 -0
- package/test-fixtures/sort-subfields/v01/metadata.json +6 -0
- package/test-fixtures/sort-subfields/v01/record.json +24 -0
- package/test-fixtures/sort-subfields/v02/expectedResult.json +6 -0
- package/test-fixtures/sort-subfields/v02/metadata.json +6 -0
- package/test-fixtures/sort-subfields/v02/record.json +8 -0
- package/test-fixtures/strip-punctuation/01/expectedResult.json +12 -0
- package/test-fixtures/strip-punctuation/01/metadata.json +6 -0
- package/test-fixtures/strip-punctuation/01/record.json +37 -0
- package/test-fixtures/strip-punctuation/02/expectedResult.json +4 -0
- package/test-fixtures/strip-punctuation/02/metadata.json +6 -0
- package/test-fixtures/strip-punctuation/02/record.json +14 -0
- package/test-fixtures/strip-punctuation/04/expectedResult.json +6 -0
- package/test-fixtures/strip-punctuation/04/metadata.json +6 -0
- package/test-fixtures/strip-punctuation/04/record.json +22 -0
- package/test-fixtures/strip-punctuation/05/expectedResult.json +6 -0
- package/test-fixtures/strip-punctuation/05/metadata.json +6 -0
- package/test-fixtures/strip-punctuation/05/record.json +12 -0
- package/test-fixtures/strip-punctuation/98/expectedResult.json +44 -0
- package/test-fixtures/strip-punctuation/98/metadata.json +6 -0
- package/test-fixtures/strip-punctuation/98/record.json +45 -0
- package/test-fixtures/strip-punctuation/99/expectedResult.json +16 -0
- package/test-fixtures/strip-punctuation/99/metadata.json +6 -0
- package/test-fixtures/strip-punctuation/99/record.json +16 -0
- package/test-fixtures/subfield0/f01/expectedResult.json +25 -0
- package/test-fixtures/subfield0/f01/metadata.json +6 -0
- package/test-fixtures/subfield0/f01/record.json +23 -0
- package/test-fixtures/subfield0/f02/expectedResult.json +35 -0
- package/test-fixtures/subfield0/f02/metadata.json +6 -0
- package/test-fixtures/subfield0/f02/record.json +41 -0
- package/test-fixtures/subfield0/f03/expectedResult.json +21 -0
- package/test-fixtures/subfield0/f03/metadata.json +7 -0
- package/test-fixtures/subfield0/f03/record.json +24 -0
- package/test-fixtures/subfield0/v01/expectedResult.json +4 -0
- package/test-fixtures/subfield0/v01/metadata.json +6 -0
- package/test-fixtures/subfield0/v01/record.json +23 -0
- package/test-fixtures/subfield0/v02/expectedResult.json +9 -0
- package/test-fixtures/subfield0/v02/metadata.json +6 -0
- package/test-fixtures/subfield0/v02/record.json +38 -0
- package/test-fixtures/typeOfDate-008/01/expectedResult.json +3 -0
- package/test-fixtures/typeOfDate-008/01/metadata.json +4 -0
- package/test-fixtures/typeOfDate-008/01/record.json +14 -0
- package/test-fixtures/typeOfDate-008/02/expectedResult.json +4 -0
- package/test-fixtures/typeOfDate-008/02/metadata.json +4 -0
- package/test-fixtures/typeOfDate-008/02/record.json +14 -0
- package/test-fixtures/typeOfDate-008/03/expectedResult.json +14 -0
- package/test-fixtures/typeOfDate-008/03/metadata.json +5 -0
- package/test-fixtures/typeOfDate-008/03/record.json +14 -0
- package/test-fixtures/typeOfDate-008/04/expectedResult.json +14 -0
- package/test-fixtures/typeOfDate-008/04/metadata.json +5 -0
- package/test-fixtures/typeOfDate-008/04/record.json +14 -0
- package/test-fixtures/typeOfDate-008/05/expectedResult.json +14 -0
- package/test-fixtures/typeOfDate-008/05/metadata.json +5 -0
- package/test-fixtures/typeOfDate-008/05/record.json +14 -0
- package/test-fixtures/update-field-540/f01/expectedResult.json +23 -0
- package/test-fixtures/update-field-540/f01/metadata.json +6 -0
- package/test-fixtures/update-field-540/f01/record.json +23 -0
- package/test-fixtures/update-field-540/v01/expectedResult.json +7 -0
- package/test-fixtures/update-field-540/v01/metadata.json +6 -0
- package/test-fixtures/update-field-540/v01/record.json +23 -0
- package/.travis.yml +0 -10
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = _default;
|
|
7
|
+
/**
|
|
8
|
+
* Provides interface to validate and fix record fields, which include subfields that end with whitespace character
|
|
9
|
+
* @returns {Object} Object containing interfaces required by marc-record-validators-melinda package
|
|
10
|
+
*/
|
|
11
|
+
function _default() {
|
|
12
|
+
return {
|
|
13
|
+
description: 'Handles subfields that ends with whitespace character',
|
|
14
|
+
validate,
|
|
15
|
+
fix
|
|
16
|
+
};
|
|
17
|
+
function validate(record) {
|
|
18
|
+
const nonValidFields = record.fields.filter(({
|
|
19
|
+
subfields
|
|
20
|
+
}) => subfields !== undefined && subfields.filter(valueEndsWithWhitespace).length > 0);
|
|
21
|
+
const valid = nonValidFields.length === 0;
|
|
22
|
+
const messages = nonValidFields.flatMap(({
|
|
23
|
+
tag,
|
|
24
|
+
subfields
|
|
25
|
+
}) => subfields.map(sf => `Field ${tag} subfield $${sf.code} ends with whitespace`));
|
|
26
|
+
return valid ? {
|
|
27
|
+
valid,
|
|
28
|
+
messages: []
|
|
29
|
+
} : {
|
|
30
|
+
valid,
|
|
31
|
+
messages
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* eslint-disable functional/immutable-data,functional/no-conditional-statements */
|
|
36
|
+
function fix(record) {
|
|
37
|
+
record.fields.forEach(({
|
|
38
|
+
subfields
|
|
39
|
+
}) => {
|
|
40
|
+
if (subfields === undefined) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
subfields.forEach(subfield => {
|
|
44
|
+
if (valueEndsWithWhitespace(subfield)) {
|
|
45
|
+
subfield.value = subfield.value.trimEnd();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/* eslint-enable functional/immutable-data,functional/no-conditional-statements */
|
|
51
|
+
|
|
52
|
+
function valueEndsWithWhitespace({
|
|
53
|
+
value
|
|
54
|
+
}) {
|
|
55
|
+
return /\s$/u.test(value);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=ending-whitespace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ending-whitespace.js","names":["_default","description","validate","fix","record","nonValidFields","fields","filter","subfields","undefined","valueEndsWithWhitespace","length","valid","messages","flatMap","tag","map","sf","code","forEach","subfield","value","trimEnd","test"],"sources":["../src/ending-whitespace.js"],"sourcesContent":["/**\n * Provides interface to validate and fix record fields, which include subfields that end with whitespace character\n * @returns {Object} Object containing interfaces required by marc-record-validators-melinda package\n */\nexport default function () {\n return {\n description: 'Handles subfields that ends with whitespace character',\n validate,\n fix\n };\n\n function validate(record) {\n const nonValidFields = record.fields.filter(({subfields}) => subfields !== undefined && subfields.filter(valueEndsWithWhitespace).length > 0);\n\n const valid = nonValidFields.length === 0;\n const messages = nonValidFields.flatMap(({tag, subfields}) => subfields.map(sf => `Field ${tag} subfield $${sf.code} ends with whitespace`));\n\n return valid ? {valid, messages: []} : {valid, messages};\n }\n\n /* eslint-disable functional/immutable-data,functional/no-conditional-statements */\n function fix(record) {\n record.fields.forEach(({subfields}) => {\n if (subfields === undefined) {\n return;\n }\n\n subfields.forEach(subfield => {\n if (valueEndsWithWhitespace(subfield)) {\n subfield.value = subfield.value.trimEnd();\n }\n });\n });\n }\n /* eslint-enable functional/immutable-data,functional/no-conditional-statements */\n\n function valueEndsWithWhitespace({value}) {\n return (/\\s$/u).test(value);\n }\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACe,SAAAA,SAAA,EAAY;EACzB,OAAO;IACLC,WAAW,EAAE,uDAAuD;IACpEC,QAAQ;IACRC;EACF,CAAC;EAED,SAASD,QAAQA,CAACE,MAAM,EAAE;IACxB,MAAMC,cAAc,GAAGD,MAAM,CAACE,MAAM,CAACC,MAAM,CAAC,CAAC;MAACC;IAAS,CAAC,KAAKA,SAAS,KAAKC,SAAS,IAAID,SAAS,CAACD,MAAM,CAACG,uBAAuB,CAAC,CAACC,MAAM,GAAG,CAAC,CAAC;IAE7I,MAAMC,KAAK,GAAGP,cAAc,CAACM,MAAM,KAAK,CAAC;IACzC,MAAME,QAAQ,GAAGR,cAAc,CAACS,OAAO,CAAC,CAAC;MAACC,GAAG;MAAEP;IAAS,CAAC,KAAKA,SAAS,CAACQ,GAAG,CAACC,EAAE,IAAK,SAAQF,GAAI,cAAaE,EAAE,CAACC,IAAK,uBAAsB,CAAC,CAAC;IAE5I,OAAON,KAAK,GAAG;MAACA,KAAK;MAAEC,QAAQ,EAAE;IAAE,CAAC,GAAG;MAACD,KAAK;MAAEC;IAAQ,CAAC;EAC1D;;EAEA;EACA,SAASV,GAAGA,CAACC,MAAM,EAAE;IACnBA,MAAM,CAACE,MAAM,CAACa,OAAO,CAAC,CAAC;MAACX;IAAS,CAAC,KAAK;MACrC,IAAIA,SAAS,KAAKC,SAAS,EAAE;QAC3B;MACF;MAEAD,SAAS,CAACW,OAAO,CAACC,QAAQ,IAAI;QAC5B,IAAIV,uBAAuB,CAACU,QAAQ,CAAC,EAAE;UACrCA,QAAQ,CAACC,KAAK,GAAGD,QAAQ,CAACC,KAAK,CAACC,OAAO,CAAC,CAAC;QAC3C;MACF,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;EACA;;EAEA,SAASZ,uBAAuBA,CAAC;IAACW;EAAK,CAAC,EAAE;IACxC,OAAQ,MAAM,CAAEE,IAAI,CAACF,KAAK,CAAC;EAC7B;AACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _chai = require("chai");
|
|
4
|
+
var _marcRecord = require("@natlibfi/marc-record");
|
|
5
|
+
var _endingWhitespace = _interopRequireDefault(require("./ending-whitespace"));
|
|
6
|
+
var _fixura = require("@natlibfi/fixura");
|
|
7
|
+
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
(0, _fixugen.default)({
|
|
10
|
+
callback,
|
|
11
|
+
path: [__dirname, '..', 'test-fixtures', 'ending-whitespace'],
|
|
12
|
+
useMetadataFile: true,
|
|
13
|
+
recurse: false,
|
|
14
|
+
fixura: {
|
|
15
|
+
reader: _fixura.READERS.JSON
|
|
16
|
+
},
|
|
17
|
+
mocha: {
|
|
18
|
+
before: () => testValidatorFactory()
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
async function testValidatorFactory() {
|
|
22
|
+
const validator = await (0, _endingWhitespace.default)();
|
|
23
|
+
(0, _chai.expect)(validator).to.be.an('object').that.has.any.keys('description', 'validate');
|
|
24
|
+
(0, _chai.expect)(validator.description).to.be.a('string');
|
|
25
|
+
(0, _chai.expect)(validator.validate).to.be.a('function');
|
|
26
|
+
}
|
|
27
|
+
async function callback({
|
|
28
|
+
getFixture,
|
|
29
|
+
fix = false
|
|
30
|
+
}) {
|
|
31
|
+
const validator = await (0, _endingWhitespace.default)();
|
|
32
|
+
const record = new _marcRecord.MarcRecord(getFixture('record.json'));
|
|
33
|
+
const expectedResult = getFixture('expectedResult.json');
|
|
34
|
+
if (!fix) {
|
|
35
|
+
const result = await validator.validate(record);
|
|
36
|
+
(0, _chai.expect)(result).to.eql(expectedResult);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
await validator.fix(record);
|
|
40
|
+
(0, _chai.expect)(record).to.eql(expectedResult);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=ending-whitespace.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ending-whitespace.spec.js","names":["_chai","require","_marcRecord","_endingWhitespace","_interopRequireDefault","_fixura","_fixugen","obj","__esModule","default","generateTests","callback","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","mocha","before","testValidatorFactory","validator","validatorFactory","expect","to","be","an","that","has","any","keys","description","a","validate","getFixture","fix","record","MarcRecord","expectedResult","result","eql"],"sources":["../src/ending-whitespace.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport validatorFactory from './ending-whitespace';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen';\n\ngenerateTests({\n callback,\n path: [__dirname, '..', 'test-fixtures', 'ending-whitespace'],\n useMetadataFile: true,\n recurse: false,\n fixura: {\n reader: READERS.JSON\n },\n mocha: {\n before: () => testValidatorFactory()\n }\n});\n\nasync function testValidatorFactory() {\n const validator = await validatorFactory();\n\n expect(validator)\n .to.be.an('object')\n .that.has.any.keys('description', 'validate');\n\n expect(validator.description).to.be.a('string');\n expect(validator.validate).to.be.a('function');\n}\n\nasync function callback({getFixture, fix = false}) {\n const validator = await validatorFactory();\n const record = new MarcRecord(getFixture('record.json'));\n const expectedResult = getFixture('expectedResult.json');\n\n if (!fix) {\n const result = await validator.validate(record);\n expect(result).to.eql(expectedResult);\n return;\n }\n\n await validator.fix(record);\n expect(record).to.eql(expectedResult);\n}\n"],"mappings":";;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAF,sBAAA,CAAAH,OAAA;AAA8C,SAAAG,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE9C,IAAAG,gBAAa,EAAC;EACZC,QAAQ;EACRC,IAAI,EAAE,CAACC,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,mBAAmB,CAAC;EAC7DC,eAAe,EAAE,IAAI;EACrBC,OAAO,EAAE,KAAK;EACdC,MAAM,EAAE;IACNC,MAAM,EAAEC,eAAO,CAACC;EAClB,CAAC;EACDC,KAAK,EAAE;IACLC,MAAM,EAAEA,CAAA,KAAMC,oBAAoB,CAAC;EACrC;AACF,CAAC,CAAC;AAEF,eAAeA,oBAAoBA,CAAA,EAAG;EACpC,MAAMC,SAAS,GAAG,MAAM,IAAAC,yBAAgB,EAAC,CAAC;EAE1C,IAAAC,YAAM,EAACF,SAAS,CAAC,CACdG,EAAE,CAACC,EAAE,CAACC,EAAE,CAAC,QAAQ,CAAC,CAClBC,IAAI,CAACC,GAAG,CAACC,GAAG,CAACC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC;EAE/C,IAAAP,YAAM,EAACF,SAAS,CAACU,WAAW,CAAC,CAACP,EAAE,CAACC,EAAE,CAACO,CAAC,CAAC,QAAQ,CAAC;EAC/C,IAAAT,YAAM,EAACF,SAAS,CAACY,QAAQ,CAAC,CAACT,EAAE,CAACC,EAAE,CAACO,CAAC,CAAC,UAAU,CAAC;AAChD;AAEA,eAAevB,QAAQA,CAAC;EAACyB,UAAU;EAAEC,GAAG,GAAG;AAAK,CAAC,EAAE;EACjD,MAAMd,SAAS,GAAG,MAAM,IAAAC,yBAAgB,EAAC,CAAC;EAC1C,MAAMc,MAAM,GAAG,IAAIC,sBAAU,CAACH,UAAU,CAAC,aAAa,CAAC,CAAC;EACxD,MAAMI,cAAc,GAAGJ,UAAU,CAAC,qBAAqB,CAAC;EAExD,IAAI,CAACC,GAAG,EAAE;IACR,MAAMI,MAAM,GAAG,MAAMlB,SAAS,CAACY,QAAQ,CAACG,MAAM,CAAC;IAC/C,IAAAb,YAAM,EAACgB,MAAM,CAAC,CAACf,EAAE,CAACgB,GAAG,CAACF,cAAc,CAAC;IACrC;EACF;EAEA,MAAMjB,SAAS,CAACc,GAAG,CAACC,MAAM,CAAC;EAC3B,IAAAb,YAAM,EAACa,MAAM,CAAC,CAACZ,EAAE,CAACgB,GAAG,CAACF,cAAc,CAAC;AACvC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = _default;
|
|
7
|
+
var _clone = _interopRequireDefault(require("clone"));
|
|
8
|
+
var _utils = require("./utils");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
//import createDebugLogger from 'debug';
|
|
11
|
+
|
|
12
|
+
// Author(s): Nicholas Volk
|
|
13
|
+
function _default() {
|
|
14
|
+
return {
|
|
15
|
+
description: 'Various fixes for field 521',
|
|
16
|
+
validate,
|
|
17
|
+
fix
|
|
18
|
+
};
|
|
19
|
+
function fix(record) {
|
|
20
|
+
record.fields.forEach(field => {
|
|
21
|
+
fix521(field);
|
|
22
|
+
});
|
|
23
|
+
// Fix always succeeds (even when it really does not):
|
|
24
|
+
const res = {
|
|
25
|
+
message: [],
|
|
26
|
+
fix: [],
|
|
27
|
+
valid: true
|
|
28
|
+
};
|
|
29
|
+
return res;
|
|
30
|
+
}
|
|
31
|
+
function validate(record) {
|
|
32
|
+
const res = {
|
|
33
|
+
message: []
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Actual parsing of all fields
|
|
37
|
+
/*
|
|
38
|
+
if (!record.fields) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
record.fields?.forEach(field => {
|
|
44
|
+
validateField(field, res);
|
|
45
|
+
});
|
|
46
|
+
res.valid = !(res.message.length >= 1); // eslint-disable-line functional/immutable-data
|
|
47
|
+
return res;
|
|
48
|
+
}
|
|
49
|
+
function validateField(field, res) {
|
|
50
|
+
const orig = (0, _utils.fieldToString)(field);
|
|
51
|
+
const normalizedField = fix521((0, _clone.default)(field));
|
|
52
|
+
const mod = (0, _utils.fieldToString)(normalizedField);
|
|
53
|
+
if (orig !== mod) {
|
|
54
|
+
// Fail as the input is "broken"/"crap"/sumthing
|
|
55
|
+
res.message.push(`'TODO: ${orig}' => '${mod}'`); // eslint-disable-line functional/immutable-data
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function fixSubfieldA(a) {
|
|
62
|
+
a.value = a.value.
|
|
63
|
+
// eslint-disable-line functional/immutable-data
|
|
64
|
+
// MET-332:
|
|
65
|
+
replace(/^(Ikäsuositus) ([0-9])/u, '$1: $2'); // eslint-disable-line prefer-named-capture-group, functional/immutable-data
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function fixSubfieldAInternalPunctuation(field) {
|
|
69
|
+
const a = field.subfields.filter(sf => sf.code === 'a');
|
|
70
|
+
a.forEach(sf => fixSubfieldA(sf));
|
|
71
|
+
}
|
|
72
|
+
function getIndicator1(field) {
|
|
73
|
+
const [a] = field.subfields.filter(sf => sf.code === 'a');
|
|
74
|
+
if (a) {
|
|
75
|
+
if (a.value.match(/^Ikäsuositus/u)) {
|
|
76
|
+
return '1';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
function fixIndicator1(field) {
|
|
82
|
+
const value = getIndicator1(field);
|
|
83
|
+
if (value) {
|
|
84
|
+
field.ind1 = value; // eslint-disable-line functional/immutable-data
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function fix521(field) {
|
|
89
|
+
if (field.tag !== '521' || !field.subfields) {
|
|
90
|
+
return field;
|
|
91
|
+
}
|
|
92
|
+
fixIndicator1(field);
|
|
93
|
+
fixSubfieldAInternalPunctuation(field);
|
|
94
|
+
return field;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=field-521-fix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-521-fix.js","names":["_clone","_interopRequireDefault","require","_utils","obj","__esModule","default","_default","description","validate","fix","record","fields","forEach","field","fix521","res","message","valid","validateField","length","orig","fieldToString","normalizedField","clone","mod","push","fixSubfieldA","a","value","replace","fixSubfieldAInternalPunctuation","subfields","filter","sf","code","getIndicator1","match","undefined","fixIndicator1","ind1","tag"],"sources":["../src/field-521-fix.js"],"sourcesContent":["//import createDebugLogger from 'debug';\nimport clone from 'clone';\nimport {fieldToString} from './utils';\n\n// Author(s): Nicholas Volk\nexport default function () {\n\n return {\n description: 'Various fixes for field 521',\n validate, fix\n };\n\n function fix(record) {\n record.fields.forEach(field => {\n fix521(field);\n });\n // Fix always succeeds (even when it really does not):\n const res = {message: [], fix: [], valid: true};\n return res;\n }\n\n function validate(record) {\n const res = {message: []};\n\n // Actual parsing of all fields\n /*\n if (!record.fields) {\n return false;\n }\n */\n\n record.fields?.forEach(field => {\n validateField(field, res);\n });\n\n res.valid = !(res.message.length >= 1); // eslint-disable-line functional/immutable-data\n return res;\n }\n\n function validateField(field, res) {\n const orig = fieldToString(field);\n\n const normalizedField = fix521(clone(field));\n const mod = fieldToString(normalizedField);\n if (orig !== mod) { // Fail as the input is \"broken\"/\"crap\"/sumthing\n res.message.push(`'TODO: ${orig}' => '${mod}'`); // eslint-disable-line functional/immutable-data\n return;\n }\n return;\n }\n}\n\nfunction fixSubfieldA(a) {\n a.value = a.value. // eslint-disable-line functional/immutable-data\n // MET-332:\n replace(/^(Ikäsuositus) ([0-9])/u, '$1: $2'); // eslint-disable-line prefer-named-capture-group, functional/immutable-data\n}\n\nfunction fixSubfieldAInternalPunctuation(field) {\n const a = field.subfields.filter(sf => sf.code === 'a');\n\n a.forEach(sf => fixSubfieldA(sf));\n}\n\nfunction getIndicator1(field) {\n const [a] = field.subfields.filter(sf => sf.code === 'a');\n if (a) {\n if (a.value.match(/^Ikäsuositus/u)) {\n return '1';\n }\n }\n return undefined;\n}\n\nfunction fixIndicator1(field) {\n const value = getIndicator1(field);\n if (value) {\n field.ind1 = value; // eslint-disable-line functional/immutable-data\n return;\n }\n\n}\n\nfunction fix521(field) {\n if (field.tag !== '521' || !field.subfields) {\n return field;\n }\n fixIndicator1(field);\n fixSubfieldAInternalPunctuation(field);\n return field;\n}\n\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAAsC,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAFtC;;AAIA;AACe,SAAAG,SAAA,EAAY;EAEzB,OAAO;IACLC,WAAW,EAAE,6BAA6B;IAC1CC,QAAQ;IAAEC;EACZ,CAAC;EAED,SAASA,GAAGA,CAACC,MAAM,EAAE;IACnBA,MAAM,CAACC,MAAM,CAACC,OAAO,CAACC,KAAK,IAAI;MAC7BC,MAAM,CAACD,KAAK,CAAC;IACf,CAAC,CAAC;IACF;IACA,MAAME,GAAG,GAAG;MAACC,OAAO,EAAE,EAAE;MAAEP,GAAG,EAAE,EAAE;MAAEQ,KAAK,EAAE;IAAI,CAAC;IAC/C,OAAOF,GAAG;EACZ;EAEA,SAASP,QAAQA,CAACE,MAAM,EAAE;IACxB,MAAMK,GAAG,GAAG;MAACC,OAAO,EAAE;IAAE,CAAC;;IAEzB;IACA;AACJ;AACA;AACA;AACA;;IAEIN,MAAM,CAACC,MAAM,EAAEC,OAAO,CAACC,KAAK,IAAI;MAC9BK,aAAa,CAACL,KAAK,EAAEE,GAAG,CAAC;IAC3B,CAAC,CAAC;IAEFA,GAAG,CAACE,KAAK,GAAG,EAAEF,GAAG,CAACC,OAAO,CAACG,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC;IACxC,OAAOJ,GAAG;EACZ;EAEA,SAASG,aAAaA,CAACL,KAAK,EAAEE,GAAG,EAAE;IACjC,MAAMK,IAAI,GAAG,IAAAC,oBAAa,EAACR,KAAK,CAAC;IAEjC,MAAMS,eAAe,GAAGR,MAAM,CAAC,IAAAS,cAAK,EAACV,KAAK,CAAC,CAAC;IAC5C,MAAMW,GAAG,GAAG,IAAAH,oBAAa,EAACC,eAAe,CAAC;IAC1C,IAAIF,IAAI,KAAKI,GAAG,EAAE;MAAE;MAClBT,GAAG,CAACC,OAAO,CAACS,IAAI,CAAE,UAASL,IAAK,SAAQI,GAAI,GAAE,CAAC,CAAC,CAAC;MACjD;IACF;IACA;EACF;AACF;AAEA,SAASE,YAAYA,CAACC,CAAC,EAAE;EACvBA,CAAC,CAACC,KAAK,GAAGD,CAAC,CAACC,KAAK;EAAE;EACjB;EACAC,OAAO,CAAC,yBAAyB,EAAE,QAAQ,CAAC,CAAC,CAAC;AAClD;;AAEA,SAASC,+BAA+BA,CAACjB,KAAK,EAAE;EAC9C,MAAMc,CAAC,GAAGd,KAAK,CAACkB,SAAS,CAACC,MAAM,CAACC,EAAE,IAAIA,EAAE,CAACC,IAAI,KAAK,GAAG,CAAC;EAEvDP,CAAC,CAACf,OAAO,CAACqB,EAAE,IAAIP,YAAY,CAACO,EAAE,CAAC,CAAC;AACnC;AAEA,SAASE,aAAaA,CAACtB,KAAK,EAAE;EAC5B,MAAM,CAACc,CAAC,CAAC,GAAGd,KAAK,CAACkB,SAAS,CAACC,MAAM,CAACC,EAAE,IAAIA,EAAE,CAACC,IAAI,KAAK,GAAG,CAAC;EACzD,IAAIP,CAAC,EAAE;IACL,IAAIA,CAAC,CAACC,KAAK,CAACQ,KAAK,CAAC,eAAe,CAAC,EAAE;MAClC,OAAO,GAAG;IACZ;EACF;EACA,OAAOC,SAAS;AAClB;AAEA,SAASC,aAAaA,CAACzB,KAAK,EAAE;EAC5B,MAAMe,KAAK,GAAGO,aAAa,CAACtB,KAAK,CAAC;EAClC,IAAIe,KAAK,EAAE;IACTf,KAAK,CAAC0B,IAAI,GAAGX,KAAK,CAAC,CAAC;IACpB;EACF;AAEF;AAEA,SAASd,MAAMA,CAACD,KAAK,EAAE;EACrB,IAAIA,KAAK,CAAC2B,GAAG,KAAK,KAAK,IAAI,CAAC3B,KAAK,CAACkB,SAAS,EAAE;IAC3C,OAAOlB,KAAK;EACd;EACAyB,aAAa,CAACzB,KAAK,CAAC;EACpBiB,+BAA+B,CAACjB,KAAK,CAAC;EACtC,OAAOA,KAAK;AACd"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _chai = require("chai");
|
|
4
|
+
var _marcRecord = require("@natlibfi/marc-record");
|
|
5
|
+
var _field521Fix = _interopRequireDefault(require("./field-521-fix"));
|
|
6
|
+
var _fixura = require("@natlibfi/fixura");
|
|
7
|
+
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
8
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
(0, _fixugen.default)({
|
|
11
|
+
callback,
|
|
12
|
+
path: [__dirname, '..', 'test-fixtures', 'fix521'],
|
|
13
|
+
useMetadataFile: true,
|
|
14
|
+
recurse: false,
|
|
15
|
+
fixura: {
|
|
16
|
+
reader: _fixura.READERS.JSON
|
|
17
|
+
},
|
|
18
|
+
mocha: {
|
|
19
|
+
before: () => testValidatorFactory()
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const debug = (0, _debug.default)('@natlibfi/marc-record-validators-melinda/fix521:test');
|
|
23
|
+
async function testValidatorFactory() {
|
|
24
|
+
const validator = await (0, _field521Fix.default)();
|
|
25
|
+
(0, _chai.expect)(validator).to.be.an('object').that.has.any.keys('description', 'validate');
|
|
26
|
+
(0, _chai.expect)(validator.description).to.be.a('string');
|
|
27
|
+
(0, _chai.expect)(validator.validate).to.be.a('function');
|
|
28
|
+
}
|
|
29
|
+
async function callback({
|
|
30
|
+
getFixture,
|
|
31
|
+
enabled = true,
|
|
32
|
+
fix = false
|
|
33
|
+
}) {
|
|
34
|
+
if (enabled === false) {
|
|
35
|
+
debug('TEST SKIPPED!');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const validator = await (0, _field521Fix.default)();
|
|
39
|
+
const record = new _marcRecord.MarcRecord(getFixture('record.json'));
|
|
40
|
+
const expectedResult = getFixture('expectedResult.json');
|
|
41
|
+
// console.log(expectedResult); // eslint-disable-line
|
|
42
|
+
|
|
43
|
+
if (!fix) {
|
|
44
|
+
const result = await validator.validate(record);
|
|
45
|
+
(0, _chai.expect)(result).to.eql(expectedResult);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
await validator.fix(record);
|
|
49
|
+
(0, _chai.expect)(record).to.eql(expectedResult);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=field-521-fix.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-521-fix.spec.js","names":["_chai","require","_marcRecord","_field521Fix","_interopRequireDefault","_fixura","_fixugen","_debug","obj","__esModule","default","generateTests","callback","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","mocha","before","testValidatorFactory","debug","createDebugLogger","validator","validatorFactory","expect","to","be","an","that","has","any","keys","description","a","validate","getFixture","enabled","fix","record","MarcRecord","expectedResult","result","eql"],"sources":["../src/field-521-fix.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport validatorFactory from './field-521-fix';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen';\nimport createDebugLogger from 'debug';\n\ngenerateTests({\n callback,\n path: [__dirname, '..', 'test-fixtures', 'fix521'],\n useMetadataFile: true,\n recurse: false,\n fixura: {\n reader: READERS.JSON\n },\n mocha: {\n before: () => testValidatorFactory()\n }\n});\nconst debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/fix521:test');\n\nasync function testValidatorFactory() {\n const validator = await validatorFactory();\n\n expect(validator)\n .to.be.an('object')\n .that.has.any.keys('description', 'validate');\n\n expect(validator.description).to.be.a('string');\n expect(validator.validate).to.be.a('function');\n}\n\nasync function callback({getFixture, enabled = true, fix = false}) {\n if (enabled === false) {\n debug('TEST SKIPPED!');\n return;\n }\n\n const validator = await validatorFactory();\n const record = new MarcRecord(getFixture('record.json'));\n const expectedResult = getFixture('expectedResult.json');\n // console.log(expectedResult); // eslint-disable-line\n\n if (!fix) {\n const result = await validator.validate(record);\n expect(result).to.eql(expectedResult);\n return;\n }\n\n await validator.fix(record);\n expect(record).to.eql(expectedResult);\n}\n"],"mappings":";;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAF,sBAAA,CAAAH,OAAA;AACA,IAAAM,MAAA,GAAAH,sBAAA,CAAAH,OAAA;AAAsC,SAAAG,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEtC,IAAAG,gBAAa,EAAC;EACZC,QAAQ;EACRC,IAAI,EAAE,CAACC,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,QAAQ,CAAC;EAClDC,eAAe,EAAE,IAAI;EACrBC,OAAO,EAAE,KAAK;EACdC,MAAM,EAAE;IACNC,MAAM,EAAEC,eAAO,CAACC;EAClB,CAAC;EACDC,KAAK,EAAE;IACLC,MAAM,EAAEA,CAAA,KAAMC,oBAAoB,CAAC;EACrC;AACF,CAAC,CAAC;AACF,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,sDAAsD,CAAC;AAEvF,eAAeF,oBAAoBA,CAAA,EAAG;EACpC,MAAMG,SAAS,GAAG,MAAM,IAAAC,oBAAgB,EAAC,CAAC;EAE1C,IAAAC,YAAM,EAACF,SAAS,CAAC,CACdG,EAAE,CAACC,EAAE,CAACC,EAAE,CAAC,QAAQ,CAAC,CAClBC,IAAI,CAACC,GAAG,CAACC,GAAG,CAACC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC;EAE/C,IAAAP,YAAM,EAACF,SAAS,CAACU,WAAW,CAAC,CAACP,EAAE,CAACC,EAAE,CAACO,CAAC,CAAC,QAAQ,CAAC;EAC/C,IAAAT,YAAM,EAACF,SAAS,CAACY,QAAQ,CAAC,CAACT,EAAE,CAACC,EAAE,CAACO,CAAC,CAAC,UAAU,CAAC;AAChD;AAEA,eAAezB,QAAQA,CAAC;EAAC2B,UAAU;EAAEC,OAAO,GAAG,IAAI;EAAEC,GAAG,GAAG;AAAK,CAAC,EAAE;EACjE,IAAID,OAAO,KAAK,KAAK,EAAE;IACrBhB,KAAK,CAAC,eAAe,CAAC;IACtB;EACF;EAEA,MAAME,SAAS,GAAG,MAAM,IAAAC,oBAAgB,EAAC,CAAC;EAC1C,MAAMe,MAAM,GAAG,IAAIC,sBAAU,CAACJ,UAAU,CAAC,aAAa,CAAC,CAAC;EACxD,MAAMK,cAAc,GAAGL,UAAU,CAAC,qBAAqB,CAAC;EACxD;;EAEA,IAAI,CAACE,GAAG,EAAE;IACR,MAAMI,MAAM,GAAG,MAAMnB,SAAS,CAACY,QAAQ,CAACI,MAAM,CAAC;IAC/C,IAAAd,YAAM,EAACiB,MAAM,CAAC,CAAChB,EAAE,CAACiB,GAAG,CAACF,cAAc,CAAC;IACrC;EACF;EAEA,MAAMlB,SAAS,CAACe,GAAG,CAACC,MAAM,CAAC;EAC3B,IAAAd,YAAM,EAACc,MAAM,CAAC,CAACb,EAAE,CAACiB,GAAG,CAACF,cAAc,CAAC;AACvC"}
|
package/dist/field-exclusion.js
CHANGED
|
@@ -1,64 +1,215 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = _default;
|
|
7
|
+
// Configuration specification
|
|
8
|
+
const confSpec = {
|
|
9
|
+
tag: {
|
|
10
|
+
// Pattern to match the field's tags
|
|
11
|
+
type: 'RegExp',
|
|
12
|
+
mandatory: true
|
|
13
|
+
},
|
|
14
|
+
value: {
|
|
15
|
+
// Regular expression object for matching a controlfields value. Mutual exclusive with
|
|
16
|
+
type: 'RegExp',
|
|
17
|
+
excl: ['subfields', 'ind1', 'ind2']
|
|
18
|
+
},
|
|
19
|
+
ind1: {
|
|
20
|
+
// Pattern to match the field's ind1 property.
|
|
21
|
+
type: 'RegExp',
|
|
22
|
+
// Array<Indicator>
|
|
23
|
+
excl: ['value']
|
|
24
|
+
},
|
|
25
|
+
ind2: {
|
|
26
|
+
// Pattern to match the field's ind2 property.
|
|
27
|
+
type: 'RegExp',
|
|
28
|
+
// Array<Indicator>
|
|
29
|
+
excl: ['value']
|
|
30
|
+
},
|
|
31
|
+
subfields: {
|
|
32
|
+
// An array of objects with the following properties
|
|
33
|
+
code: {
|
|
34
|
+
type: 'RegExp',
|
|
35
|
+
mandatory: true
|
|
36
|
+
},
|
|
37
|
+
value: {
|
|
38
|
+
type: 'RegExp',
|
|
39
|
+
mandatory: true
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
dependencies: {
|
|
43
|
+
leader: {
|
|
44
|
+
type: 'RegExp'
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
function forEach(obj, fun) {
|
|
49
|
+
Object.entries(obj).forEach(fun);
|
|
50
|
+
}
|
|
51
|
+
function isRegExp(re) {
|
|
52
|
+
const result = re instanceof RegExp;
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
function _default(config) {
|
|
56
|
+
if (!Array.isArray(config)) {
|
|
57
|
+
throw new TypeError('Configuration array not provided');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Transform RegExp-only elements to objects
|
|
61
|
+
const objOnlyConfigs = config.map(e => isRegExp(e) ? {
|
|
62
|
+
tag: e
|
|
63
|
+
} : e);
|
|
64
|
+
configValid(objOnlyConfigs);
|
|
65
|
+
return {
|
|
66
|
+
description: 'Checks that the record does not contain the configured fields',
|
|
67
|
+
validate: record => excludeFields(record, objOnlyConfigs, false),
|
|
68
|
+
fix: record => excludeFields(record, objOnlyConfigs, true)
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/// /////////////////////////////////////////
|
|
72
|
+
// These check that configuration is valid
|
|
73
|
+
function configValid(config) {
|
|
74
|
+
config.forEach(obj => {
|
|
75
|
+
const excluded = []; // Validate fields: check that they are valid to confSpec (exists, correct data type), concat excluded elements
|
|
76
|
+
|
|
77
|
+
checkMandatory(confSpec, obj);
|
|
78
|
+
forEach(obj, ([key, val]) => {
|
|
79
|
+
configMatchesSpec(val, key, confSpec);
|
|
80
|
+
// Concat all excluded elements to array
|
|
81
|
+
if (confSpec[key].excl) {
|
|
82
|
+
// eslint-disable-line functional/no-conditional-statements
|
|
83
|
+
excluded.push(...confSpec[key].excl); // eslint-disable-line functional/immutable-data
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Check that no excluded elements are in use
|
|
88
|
+
forEach(obj, ([key]) => {
|
|
89
|
+
if (excluded.includes(key)) {
|
|
90
|
+
throw new Error('Configuration not valid - excluded element');
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Recursive validator
|
|
97
|
+
function configMatchesSpec(data, key, spec) {
|
|
98
|
+
// Field not found in configuration spec
|
|
99
|
+
if (!spec[key]) {
|
|
100
|
+
throw new Error(`Configuration not valid - unidentified value: ${key}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// If configuration type does not match type in configuration spec
|
|
104
|
+
if (typeof data !== spec[key].type && spec[key].type === 'RegExp' && !isRegExp(data)) {
|
|
105
|
+
throw new Error(`Configuration not valid - invalid data type for: ${key}`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Check subfields recursively
|
|
109
|
+
if (key === 'subfields') {
|
|
110
|
+
// eslint-disable-line functional/no-conditional-statements
|
|
111
|
+
forEach(data, ([, subObj]) => {
|
|
112
|
+
// Console.log("subObj: ", subObj, " type: ", typeof subObj, !(Array.isArray(subObj)))
|
|
113
|
+
if (typeof subObj === 'object' && !Array.isArray(subObj)) {
|
|
114
|
+
// eslint-disable-line functional/no-conditional-statements
|
|
115
|
+
checkMandatory(spec[key], subObj);
|
|
116
|
+
forEach(subObj, ([subKey, subVal]) => {
|
|
117
|
+
configMatchesSpec(subVal, subKey, spec[key]);
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
throw new TypeError(`Configuration not valid - subfield: ${subObj} not object`);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
if (key === 'dependencies') {
|
|
125
|
+
// eslint-disable-line functional/no-conditional-statements
|
|
126
|
+
forEach(data, ([, subObj]) => {
|
|
127
|
+
if (!(typeof subObj === 'object' && !Array.isArray(subObj) && Object.keys(subObj).length === 1 && isRegExp(subObj.leader))) {
|
|
128
|
+
throw new TypeError('Configuration not valid - Invalid dependencies config');
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function checkMandatory(spec, obj) {
|
|
134
|
+
// Check if all mandatory fields are present
|
|
135
|
+
forEach(spec, ([key, val]) => {
|
|
136
|
+
if (val.mandatory && typeof obj[key] === 'undefined') {
|
|
137
|
+
throw new Error(`Configuration not valid - missing mandatory element: ${key}`);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/// /////////////////////////////////////////
|
|
142
|
+
|
|
143
|
+
/// /////////////////////////////////////////
|
|
144
|
+
// These check that record is valid
|
|
145
|
+
function subFieldCheck(confField, element) {
|
|
146
|
+
// Parse trough every configuration subfield, check if one matches some subobjects fields
|
|
147
|
+
return Object.values(confField).some(subField => Object.values(element.subfields)
|
|
148
|
+
// Check if subfield matches configuration spec
|
|
149
|
+
.some(elemSub => subField.code && elemSub.code && subField.code.test(elemSub.code) && subField.value && elemSub.value && subField.value.test(elemSub.value)));
|
|
150
|
+
}
|
|
151
|
+
function excludeFields(record, conf, fix) {
|
|
152
|
+
const res = {
|
|
153
|
+
message: [],
|
|
154
|
+
valid: true
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// Parse trough every element of config array
|
|
158
|
+
forEach(conf, ([, confObj]) => {
|
|
159
|
+
const found = record.get(confObj.tag); // Find matching record fields based on mandatory tag
|
|
160
|
+
const excluded = [];
|
|
161
|
+
|
|
162
|
+
// Check if some of found record fields matches all configuration fields
|
|
163
|
+
found.forEach(element => {
|
|
164
|
+
// Compare each found element against each configuration object
|
|
165
|
+
if (Object.entries(confObj).every(([confKey, confField]) => {
|
|
166
|
+
// This is already checked on .get()
|
|
167
|
+
if (confKey === 'tag') {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
if (confKey === 'dependencies') {
|
|
171
|
+
return confObj.dependencies.every(dependency => dependency.leader.test(record.leader));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Check subfield configurations
|
|
175
|
+
if (confKey === 'subfields') {
|
|
176
|
+
return subFieldCheck(confField, element);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Configuration object is RegExp and record value matches it
|
|
180
|
+
if (element[confKey] && isRegExp(confField) && confField.test(element[confKey])) {
|
|
181
|
+
return true;
|
|
182
|
+
|
|
183
|
+
// Configuration object not found from found element
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return false;
|
|
187
|
+
})) {
|
|
188
|
+
// All configuration fields match, element should be excluded.
|
|
189
|
+
if (fix) {
|
|
190
|
+
// eslint-disable-line functional/no-conditional-statements
|
|
191
|
+
excluded.push(element); // eslint-disable-line functional/immutable-data
|
|
192
|
+
} else {
|
|
193
|
+
// eslint-disable-line functional/no-conditional-statements
|
|
194
|
+
res.message.push(`Field $${element.tag} should be excluded`); // eslint-disable-line functional/immutable-data
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
excluded.forEach(field => record.removeField(field));
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// Fix does not send response
|
|
203
|
+
if (!fix) {
|
|
204
|
+
if (res.message.length > 0) {
|
|
205
|
+
// eslint-disable-line functional/no-conditional-statements
|
|
206
|
+
res.valid = false; // eslint-disable-line functional/immutable-data
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return res;
|
|
210
|
+
}
|
|
211
|
+
// Res.fix.push('Field $' + element.tag + ' excluded');
|
|
212
|
+
}
|
|
213
|
+
/// /////////////////////////////////////////
|
|
214
|
+
}
|
|
64
215
|
//# sourceMappingURL=field-exclusion.js.map
|