@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
|
@@ -1,255 +1,265 @@
|
|
|
1
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
|
-
/* eslint-disable
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
*
|
|
3
|
+
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
4
|
+
*
|
|
5
|
+
* MARC record validators used in Melinda
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2014-2021 University Of Helsinki (The National Library Of Finland)
|
|
8
|
+
*
|
|
9
|
+
* This file is part of marc-record-validators-melinda
|
|
10
|
+
*
|
|
11
|
+
* marc-record-validators-melinda 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-validators-melinda 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
|
+
/* eslint-disable complexity, max-params */
|
|
30
|
+
|
|
31
|
+
|
|
32
32
|
// Import {validPuncMarks, finnishTerms, confSpec} from './ending-punctuation-conf.js';
|
|
33
33
|
import {validPuncMarks, finnishTerms, confSpec} from './ending-punctuation-conf';
|
|
34
|
+
import createDebugLogger from 'debug';
|
|
35
|
+
|
|
36
|
+
const debug = createDebugLogger('@natlibfi/marc-record-validator-melinda/ending-punctuation');
|
|
37
|
+
|
|
38
|
+
export default function () {
|
|
39
|
+
return {
|
|
40
|
+
description:
|
|
41
|
+
'Handles invalid ending punctuation',
|
|
42
|
+
validate: record => validatePunc(record, false), // Record (Object), fix (boolean)
|
|
43
|
+
fix: record => validatePunc(record, true) // Record (Object), fix (boolean)
|
|
44
|
+
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// This is used to validate record against configuration
|
|
48
|
+
function validatePunc(record, fix) {
|
|
49
|
+
const message = {message: []};
|
|
50
|
+
|
|
51
|
+
if (fix) { // eslint-disable-line functional/no-conditional-statements
|
|
52
|
+
message.fix = []; // eslint-disable-line functional/immutable-data
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Actual parsing of all fields
|
|
56
|
+
if (!record.fields) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
record.fields.forEach(field => {
|
|
61
|
+
validateField(field, false, fix, message);
|
|
62
|
+
});
|
|
34
63
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
'Checks whether punctuation is valid',
|
|
39
|
-
validate: async record => (
|
|
40
|
-
validatePunc(record, false) // Record (Object), fix (boolean)
|
|
41
|
-
),
|
|
42
|
-
fix: async record => (
|
|
43
|
-
validatePunc(record, true) // Record (Object), fix (boolean)
|
|
44
|
-
)
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// This is used to validate record against configuration
|
|
48
|
-
function validatePunc(record, fix) {
|
|
49
|
-
const message = {};
|
|
50
|
-
|
|
51
|
-
message.message = [];
|
|
52
|
-
if (fix) {
|
|
53
|
-
message.fix = [];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Function introduction before use; actual parsing and calling after these
|
|
57
|
-
let lastField = null;
|
|
58
|
-
|
|
59
|
-
// This is used to find last subfield that should have punctuation
|
|
60
|
-
const findLastSubfield = function (field) {
|
|
61
|
-
lastField = null;
|
|
62
|
-
field.subfields.forEach(subField => { // Check that each field has required fields and save last data field
|
|
63
|
-
if (!subField.code || !subField.value) {
|
|
64
|
-
throw new Error('Missing code or value for subfield: ' + subField);
|
|
65
|
-
} // Does not have code or value
|
|
66
|
-
if (isNaN(subField.code)) {
|
|
67
|
-
lastField = subField;
|
|
68
|
-
} // Not control field
|
|
69
|
-
});
|
|
70
|
-
return lastField;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
let lastPuncMark = null;
|
|
74
|
-
|
|
75
|
-
let lastPuncDot = null;
|
|
76
|
-
|
|
77
|
-
// Punctuation rule (Boolean), Check no ending dot strict (Boolean)
|
|
78
|
-
const normalPuncRules = function (subfield, punc, tag, checkEnd) {
|
|
79
|
-
lastPuncMark = validPuncMarks.includes(subfield.value.slice(-1)); // If string ends to punctuation char
|
|
80
|
-
lastPuncDot = '.'.includes(subfield.value.slice(-1)); // If string ends to dot
|
|
81
|
-
|
|
82
|
-
// Last char should be punc, but its not either one of marks nor dot
|
|
83
|
-
if (punc && !(lastPuncMark || lastPuncDot)) {
|
|
84
|
-
// Console.log("1. Invalid punctuation - missing")
|
|
85
|
-
message.message.push('Field ' + tag + ' has invalid ending punctuation');
|
|
86
|
-
if (fix) {
|
|
87
|
-
subfield.value = subfield.value.concat('.');
|
|
88
|
-
message.fix.push('Field ' + tag + ' - Added punctuation to $' + subfield.code);
|
|
89
|
-
}
|
|
90
|
-
// Last char is dot, but previous char is one of punc marks, like 'Question?.'
|
|
91
|
-
} else if (lastPuncDot && validPuncMarks.includes(subfield.value.charAt(subfield.value.length - 2))) {
|
|
92
|
-
// Console.log("2. Invalid punctuation - duplicate, like '?.'")
|
|
93
|
-
message.message.push('Field ' + tag + ' has invalid ending punctuation');
|
|
94
|
-
if (fix) {
|
|
95
|
-
subfield.value = subfield.value.slice(0, -1);
|
|
96
|
-
message.fix.push('Field ' + tag + ' - Removed double punctuation from $' + subfield.code);
|
|
97
|
-
}
|
|
98
|
-
// Last char shouldn't be dot !! This is behind checkEnd boolean, because of dots at end of abbreviations, so this is checked only in special cases !!//
|
|
99
|
-
} else if (checkEnd && (!punc && lastPuncDot)) {
|
|
100
|
-
// Console.log("3. Invalid punctuation - Shouldn't be dot, is")
|
|
101
|
-
message.message.push('Field ' + tag + ' has invalid ending punctuation');
|
|
102
|
-
if (fix) {
|
|
103
|
-
subfield.value = subfield.value.slice(0, -1);
|
|
104
|
-
message.fix.push('Field ' + tag + ' - Removed punctuation from $' + subfield.code);
|
|
105
|
-
}
|
|
106
|
-
} else {
|
|
107
|
-
// Console.log("Valid punctuation")
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// Special cases from here on
|
|
112
|
-
const specialCases = function (res, field, tag) {
|
|
113
|
-
let lastSubField = null;
|
|
114
|
-
// Punctuation should be only after specific field
|
|
115
|
-
if (res.special.afterOnly) {
|
|
116
|
-
lastSubField = findLastSubfield(field);
|
|
117
|
-
if (typeof (res.special.strict) === 'undefined') { // Just to be safe
|
|
118
|
-
res.special.strict = true;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (lastSubField.code === res.special.afterOnly) {
|
|
122
|
-
normalPuncRules(lastSubField, res.punc, tag, res.special.strict);
|
|
123
|
-
} else {
|
|
124
|
-
normalPuncRules(lastSubField, !res.punc, tag, true);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Rules if last, some subrules
|
|
128
|
-
} else if (res.special.ifLast) {
|
|
129
|
-
lastSubField = findLastSubfield(field);
|
|
130
|
-
|
|
131
|
-
// IF `ind2 === '4'` check punc at $b, $c should not have punc if it has ©
|
|
132
|
-
if (res.special.ind && field.ind2 === res.special.ind) {
|
|
133
|
-
// Extra dot at the end of $c ('© 1974.'), which should be only copyright year
|
|
134
|
-
lastPuncDot = '.'.includes(lastSubField.value.slice(-1)); // If string ends to dot
|
|
135
|
-
if (lastSubField.value.includes('©') && lastPuncDot) {
|
|
136
|
-
message.message.push('Field ' + tag + ' has invalid ending punctuation');
|
|
137
|
-
if (fix) {
|
|
138
|
-
lastSubField.value = lastSubField.value.slice(0, -1);
|
|
139
|
-
message.fix.push('Field ' + tag + ' - Removed punctuation from $' + lastSubField.code);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Checked field is actually $b
|
|
144
|
-
lastSubField = find(field.subfields, {code: 'b'});
|
|
145
|
-
normalPuncRules(lastSubField, res.punc, tag, false); // Punctuation rule (Boolean), Check no ending dot strict (Boolean)
|
|
146
|
-
|
|
147
|
-
// Otherwise normal punc rules
|
|
148
|
-
} else {
|
|
149
|
-
normalPuncRules(lastSubField, res.punc, tag, false);
|
|
150
|
-
} // Punctuation rule (Boolean), Check no ending dot strict (Boolean)
|
|
151
|
-
|
|
152
|
-
// Second last
|
|
153
|
-
} else if (res.special.secondLastIfLast) {
|
|
154
|
-
field.subfields.forEach(subField => {
|
|
155
|
-
if (isNaN(subField.code) && res.special.secondLastIfLast !== subField.code) {
|
|
156
|
-
lastSubField = subField;
|
|
157
|
-
} // Not control field
|
|
158
|
-
if (typeof (res.special.last) !== 'undefined' && res.special.secondLastIfLast === subField.code) {
|
|
159
|
-
normalPuncRules(subField, res.special.last, tag, true);
|
|
160
|
-
} // Strict because this field should not be abbreviation
|
|
161
|
-
});
|
|
162
|
-
normalPuncRules(lastSubField, res.punc, tag, false);
|
|
163
|
-
|
|
164
|
-
// Search for Finnish terms
|
|
165
|
-
} else if (res.special.termField) {
|
|
166
|
-
lastSubField = findLastSubfield(field);
|
|
167
|
-
const languageField = find(field.subfields, {code: res.special.termField});
|
|
168
|
-
if (languageField && languageField.value && finnishTerms.indexOf(languageField.value) > -1) {
|
|
169
|
-
normalPuncRules(lastSubField, res.punc, tag, true);
|
|
170
|
-
} else {
|
|
171
|
-
normalPuncRules(lastSubField, res.special.else, tag, false); // Strict because of years etc (648, 650)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Search last of array in subfields and check if it has punc
|
|
175
|
-
} else if (res.special.lastOf) {
|
|
176
|
-
lastSubField = null;
|
|
177
|
-
field.subfields.forEach(subField => {
|
|
178
|
-
if (isNaN(subField.code) && res.special.lastOf.indexOf(subField.code) > -1) {
|
|
179
|
-
lastSubField = subField;
|
|
180
|
-
} // Not control field
|
|
181
|
-
if (res.special.mandatory && res.special.mandatory.indexOf(subField.code) > -1) {
|
|
182
|
-
normalPuncRules(subField, res.punc, tag, true);
|
|
183
|
-
} // Strict because of mandatory
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
if (lastSubField) {
|
|
187
|
-
normalPuncRules(lastSubField, res.punc, tag, false);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// If field has linked rules (tag: 880), find rules and re-validate
|
|
191
|
-
} else if (res.special.linked) {
|
|
192
|
-
let linkedTag = null;
|
|
193
|
-
try {
|
|
194
|
-
linkedTag = parseInt(find(field.subfields, {code: res.special.linked}).value.substr(0, 3), 10); // Substring feels stupid, but is used in MarcRecord to extract tag.
|
|
195
|
-
} catch (e) {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
validateField(field, linkedTag);
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
// Field validation with punctuation rules for normal and special cases in subfunction (to reduce complexity to please travisci)
|
|
203
|
-
function validateField(field, linkedTag) {
|
|
204
|
-
let res = null;
|
|
205
|
-
|
|
206
|
-
let tag = null;
|
|
207
|
-
|
|
208
|
-
let lastSubField = null;
|
|
209
|
-
|
|
210
|
-
if (linkedTag) {
|
|
211
|
-
tag = linkedTag;
|
|
212
|
-
} else {
|
|
213
|
-
try {
|
|
214
|
-
tag = parseInt(field.tag, 10);
|
|
215
|
-
} catch (e) {
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// Find configuration object matching tag:
|
|
221
|
-
res = find(confSpec, o => {
|
|
222
|
-
return o.index === tag || (o.rangeStart <= tag && o.rangeEnd >= tag);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
if (!res) {
|
|
226
|
-
return;
|
|
227
|
-
} // Configuration not found, pass field without error
|
|
228
|
-
|
|
229
|
-
// Field does not have subfields; invalid
|
|
230
|
-
if (typeof (field.subfields) === 'undefined' || field.subfields === null) {
|
|
231
|
-
message.message.push('Field ' + field.tag + ' has invalid ending punctuation');
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// Normal rules
|
|
236
|
-
if (typeof (res.special) === 'undefined' || res.special === null) {
|
|
237
|
-
lastSubField = findLastSubfield(field);
|
|
238
|
-
normalPuncRules(lastSubField, res.punc, field.tag, false);
|
|
239
|
-
} else {
|
|
240
|
-
specialCases(res, field, field.tag);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// Actual parsing of all fields
|
|
245
|
-
if (!record.fields) {
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
record.fields.forEach(field => {
|
|
249
|
-
validateField(field);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
message.valid = !(message.message.length >= 1);
|
|
253
|
-
return message;
|
|
254
|
-
}
|
|
64
|
+
message.valid = !(message.message.length >= 1); // eslint-disable-line functional/immutable-data
|
|
65
|
+
return message;
|
|
66
|
+
}
|
|
255
67
|
}
|
|
68
|
+
|
|
69
|
+
// Field validation with punctuation rules for normal and special cases in subfunction (to reduce complexity to please travisci)
|
|
70
|
+
function validateField(field, linkedTag, fix, message) {
|
|
71
|
+
// This is used to find last subfield that should have punctuation
|
|
72
|
+
function findLastSubfield(field) {
|
|
73
|
+
const subfields = field.subfields.filter(sf => isNaN(sf.code) && 'value' in sf);
|
|
74
|
+
return subfields.slice(-1).shift();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Punctuation rule (Boolean), Check no ending dot strict (Boolean)
|
|
78
|
+
function normalPuncRules(subfield, punc, tag, checkEnd, overrideValidPuncMarks) {
|
|
79
|
+
const puncMarks = overrideValidPuncMarks || validPuncMarks;
|
|
80
|
+
const lastPuncMark = puncMarks.includes(subfield.value.slice(-1)); // If string ends to punctuation char
|
|
81
|
+
const lastPuncDot = '.'.includes(subfield.value.slice(-1)); // If string ends to dot
|
|
82
|
+
|
|
83
|
+
// Last char should be punc, but its not one of marks nor dot
|
|
84
|
+
if (punc && !(lastPuncMark || lastPuncDot)) {
|
|
85
|
+
// Console.log("1. Invalid punctuation - missing")
|
|
86
|
+
message.message.push(`Field ${tag} has invalid ending punctuation`); // eslint-disable-line functional/immutable-data
|
|
87
|
+
if (fix) { // eslint-disable-line functional/no-conditional-statements
|
|
88
|
+
subfield.value = subfield.value.concat('.'); // eslint-disable-line functional/immutable-data
|
|
89
|
+
message.fix.push(`Field ${tag} - Added punctuation to $${subfield.code}`); // eslint-disable-line functional/immutable-data
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Last char is dot, but previous char is one of punc marks, like 'Question?.'
|
|
93
|
+
} else if (lastPuncDot && subfield.value.length > 1 && puncMarks.includes(subfield.value.charAt(subfield.value.length - 2))) {
|
|
94
|
+
// Console.log("2. Invalid punctuation - duplicate, like '?.'")
|
|
95
|
+
message.message.push(`Field ${tag} has invalid ending punctuation`); // eslint-disable-line functional/immutable-data
|
|
96
|
+
if (fix) { // eslint-disable-line functional/no-conditional-statements
|
|
97
|
+
subfield.value = subfield.value.slice(0, -1); // eslint-disable-line functional/immutable-data
|
|
98
|
+
message.fix.push(`Field ${tag} - Removed double punctuation from $${subfield.code}`); // eslint-disable-line functional/immutable-data
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Last char shouldn't be dot !! This is behind checkEnd boolean, because of dots at end of abbreviations, so this is checked only in special cases !!//
|
|
102
|
+
} else if (checkEnd && (!punc && lastPuncDot)) {
|
|
103
|
+
// Console.log("3. Invalid punctuation - Shouldn't be dot, is")
|
|
104
|
+
message.message.push(`Field ${tag} has invalid ending punctuation`); // eslint-disable-line functional/immutable-data
|
|
105
|
+
if (fix) { // eslint-disable-line functional/no-conditional-statements
|
|
106
|
+
subfield.value = subfield.value.slice(0, -1); // eslint-disable-line functional/immutable-data
|
|
107
|
+
message.fix.push(`Field ${tag} - Removed punctuation from $${subfield.code}`); // eslint-disable-line functional/immutable-data
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Special cases from here on
|
|
113
|
+
function specialCases(res, field, tag) {
|
|
114
|
+
let lastSubField = null; // eslint-disable-line functional/no-let
|
|
115
|
+
// Punctuation should be only after specific field
|
|
116
|
+
if (res.special.afterOnly) {
|
|
117
|
+
lastSubField = findLastSubfield(field);
|
|
118
|
+
|
|
119
|
+
if (lastSubField) {
|
|
120
|
+
if (typeof res.special.strict === 'undefined') { // eslint-disable-line functional/no-conditional-statements
|
|
121
|
+
res.special.strict = true; // eslint-disable-line functional/immutable-data
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (lastSubField.code === res.special.afterOnly) { // eslint-disable-line functional/no-conditional-statements
|
|
125
|
+
normalPuncRules(lastSubField, res.punc, tag, res.special.strict, false);
|
|
126
|
+
} else { // eslint-disable-line functional/no-conditional-statements
|
|
127
|
+
normalPuncRules(lastSubField, !res.punc, tag, true, false);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
} else if (res.special.noPuncIfField) {
|
|
131
|
+
if (field.subfields.some(subField => subField.code === res.special.noPuncIfField) === false) { // eslint-disable-line functional/no-conditional-statements
|
|
132
|
+
lastSubField = findLastSubfield(field);
|
|
133
|
+
normalPuncRules(lastSubField, res.punc, tag, true, false);
|
|
134
|
+
}
|
|
135
|
+
} else if (res.special.ifBoth) {
|
|
136
|
+
lastSubField = findLastSubfield(field);
|
|
137
|
+
if (lastSubField && lastSubField.code === res.special.puncSubField) {
|
|
138
|
+
// Ind2 match, check second if at punc rules with special punc char override
|
|
139
|
+
if (res.special.ifInd2 && res.special.ifInd2.includes(field.ind2)) { // eslint-disable-line functional/no-conditional-statements
|
|
140
|
+
normalPuncRules(lastSubField, res.special.ifBoth, tag, true, res.special.ifLastCharNot);
|
|
141
|
+
|
|
142
|
+
// Matches execption to special rule, noPuncIfInd2 (likely with value 4, that indicates copyright mark)
|
|
143
|
+
} else if (res.special.noPuncIfInd2 && field.ind2 && res.special.noPuncIfInd2.includes(field.ind2)) { // eslint-disable-line functional/no-conditional-statements
|
|
144
|
+
normalPuncRules(lastSubField, !res.special.ifBoth, tag, true, res.special.ifLastCharNot);
|
|
145
|
+
|
|
146
|
+
// Does not match rules -> shouldn't have punc
|
|
147
|
+
} else { // eslint-disable-line functional/no-conditional-statements
|
|
148
|
+
normalPuncRules(lastSubField, !res.special.ifBoth, tag, true, res.special.ifLastCharNot);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} else if (res.special.secondLastIfLast) { // eslint-disable-line functional/no-conditional-statements
|
|
152
|
+
field.subfields.forEach(subField => {
|
|
153
|
+
if (isNaN(subField.code) && res.special.secondLastIfLast !== subField.code) { // eslint-disable-line functional/no-conditional-statements
|
|
154
|
+
lastSubField = subField;
|
|
155
|
+
} // Not control field
|
|
156
|
+
|
|
157
|
+
if (typeof res.special.last !== 'undefined' && res.special.secondLastIfLast === subField.code) { // eslint-disable-line functional/no-conditional-statements
|
|
158
|
+
normalPuncRules(subField, res.special.last, tag, true, false);
|
|
159
|
+
} // Strict because this field should not be abbreviation
|
|
160
|
+
});
|
|
161
|
+
normalPuncRules(lastSubField, res.punc, tag, false, false);
|
|
162
|
+
|
|
163
|
+
// Search for Finnish terms
|
|
164
|
+
} else if (res.special.termField) {
|
|
165
|
+
lastSubField = findLastSubfield(field);
|
|
166
|
+
|
|
167
|
+
if (lastSubField) {
|
|
168
|
+
const languageField = field.subfields.find(({code}) => code === res.special.termField);
|
|
169
|
+
if (languageField && languageField.value && finnishTerms.some(p => p.test(languageField.value))) { // eslint-disable-line functional/no-conditional-statements
|
|
170
|
+
// If (languageField && languageField.value && finnishTerms.indexOf(languageField.value) > -1) {
|
|
171
|
+
normalPuncRules(lastSubField, res.punc, tag, true, false);
|
|
172
|
+
} else { // eslint-disable-line functional/no-conditional-statements
|
|
173
|
+
normalPuncRules(lastSubField, res.special.else, tag, false, false); // Strict because of years etc (648, 650)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// Search last of array in subfields and check if it has punc
|
|
177
|
+
} else if (res.special.lastOf) {
|
|
178
|
+
lastSubField = null;
|
|
179
|
+
field.subfields.filter(subField => 'value' in subField).forEach(subField => {
|
|
180
|
+
if (isNaN(subField.code) && res.special.lastOf.indexOf(subField.code) > -1) { // eslint-disable-line functional/no-conditional-statements
|
|
181
|
+
lastSubField = subField;
|
|
182
|
+
} // Not control field
|
|
183
|
+
|
|
184
|
+
if (res.special.mandatory && res.special.mandatory.indexOf(subField.code) > -1) { // eslint-disable-line functional/no-conditional-statements
|
|
185
|
+
normalPuncRules(subField, res.punc, tag, true, false);
|
|
186
|
+
} // Strict because of mandatory
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
if (lastSubField) { // eslint-disable-line functional/no-conditional-statements
|
|
190
|
+
normalPuncRules(lastSubField, res.punc, tag, false, false);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// If field has linked rules (tag: 880), find rules and re-validate
|
|
194
|
+
} else if (res.special.linked) { // eslint-disable-line functional/no-conditional-statements
|
|
195
|
+
let linkedTag = null; // eslint-disable-line functional/no-let
|
|
196
|
+
try {
|
|
197
|
+
linkedTag = parseInt(field.subfields.find(({code}) => code === res.special.linked).value.substr(0, 3), 10); // Substring feels stupid, but is used in MarcRecord to extract tag.
|
|
198
|
+
} catch (err) {
|
|
199
|
+
debug(`Got error while parsing tag: ${err instanceof Error ? err.stack : err}`);
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
validateField(field, linkedTag, fix, message);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
let res = null; // eslint-disable-line functional/no-let
|
|
208
|
+
let tag = null; // eslint-disable-line functional/no-let
|
|
209
|
+
let lastSubField = null; // eslint-disable-line functional/no-let
|
|
210
|
+
|
|
211
|
+
if (linkedTag) { // eslint-disable-line functional/no-conditional-statements
|
|
212
|
+
tag = linkedTag;
|
|
213
|
+
} else { // eslint-disable-line functional/no-conditional-statements
|
|
214
|
+
try {
|
|
215
|
+
tag = parseInt(field.tag, 10);
|
|
216
|
+
} catch (err) {
|
|
217
|
+
debug(`Got error while parsing tag: ${err instanceof Error ? err.stack : err}`);
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Find configuration object matching tag:
|
|
223
|
+
res = Object.values(confSpec).find(o => {
|
|
224
|
+
const rangeFine = o.rangeStart <= tag && o.rangeEnd >= tag;
|
|
225
|
+
return o.index === tag || rangeFine;
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
if (!res) {
|
|
229
|
+
return;
|
|
230
|
+
} // Configuration not found, pass field without error
|
|
231
|
+
|
|
232
|
+
// Field does not have subfields; invalid
|
|
233
|
+
if (typeof field.subfields === 'undefined' || field.subfields === null) {
|
|
234
|
+
message.message.push(`Field ${field.tag} has invalid ending punctuation`); // eslint-disable-line functional/immutable-data
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Normal rules
|
|
239
|
+
if (typeof res.special === 'undefined' || res.special === null) {
|
|
240
|
+
lastSubField = findLastSubfield(field);
|
|
241
|
+
|
|
242
|
+
if (lastSubField) { // eslint-disable-line functional/no-conditional-statements
|
|
243
|
+
normalPuncRules(lastSubField, res.punc, field.tag, false, false, fix, message);
|
|
244
|
+
}
|
|
245
|
+
} else { // eslint-disable-line functional/no-conditional-statements
|
|
246
|
+
try {
|
|
247
|
+
specialCases(res, field, field.tag);
|
|
248
|
+
} catch (e) {
|
|
249
|
+
console.error('Catched error from special case: ', e); // eslint-disable-line no-console
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function validateSingleField(field, linkedTag, fix) {
|
|
255
|
+
const message = {};
|
|
256
|
+
message.message = []; // eslint-disable-line functional/immutable-data
|
|
257
|
+
if (fix) { // eslint-disable-line functional/no-conditional-statements
|
|
258
|
+
message.fix = []; // eslint-disable-line functional/immutable-data
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
validateField(field, linkedTag, fix, message);
|
|
262
|
+
message.valid = !(message.message.length >= 1); // eslint-disable-line functional/immutable-data
|
|
263
|
+
return message;
|
|
264
|
+
}
|
|
265
|
+
|