@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.
Files changed (593) hide show
  1. package/.github/CODEOWNERS +2 -0
  2. package/.github/dependabot.yml +40 -0
  3. package/.github/workflows/melinda-node-tests.yml +61 -0
  4. package/LICENSE.txt +21 -661
  5. package/README.md +4 -5
  6. package/dist/access-rights.js +94 -0
  7. package/dist/access-rights.js.map +1 -0
  8. package/dist/access-rights.spec.js +150 -0
  9. package/dist/access-rights.spec.js.map +1 -0
  10. package/dist/double-commas.js +17 -27
  11. package/dist/double-commas.js.map +1 -1
  12. package/dist/double-commas.spec.js +72 -27
  13. package/dist/double-commas.spec.js.map +1 -1
  14. package/dist/duplicates-ind1.js +47 -27
  15. package/dist/duplicates-ind1.js.map +1 -1
  16. package/dist/duplicates-ind1.spec.js +44 -27
  17. package/dist/duplicates-ind1.spec.js.map +1 -1
  18. package/dist/empty-fields.js +79 -29
  19. package/dist/empty-fields.js.map +1 -1
  20. package/dist/empty-fields.spec.js +113 -27
  21. package/dist/empty-fields.spec.js.map +1 -1
  22. package/dist/ending-punctuation-conf.js +772 -129
  23. package/dist/ending-punctuation-conf.js.map +1 -1
  24. package/dist/ending-punctuation.js +291 -72
  25. package/dist/ending-punctuation.js.map +1 -1
  26. package/dist/ending-punctuation.spec.js +2638 -118
  27. package/dist/ending-punctuation.spec.js.map +1 -1
  28. package/dist/ending-whitespace.js +58 -0
  29. package/dist/ending-whitespace.js.map +1 -0
  30. package/dist/ending-whitespace.spec.js +42 -0
  31. package/dist/ending-whitespace.spec.js.map +1 -0
  32. package/dist/field-521-fix.js +96 -0
  33. package/dist/field-521-fix.js.map +1 -0
  34. package/dist/field-521-fix.spec.js +51 -0
  35. package/dist/field-521-fix.spec.js.map +1 -0
  36. package/dist/field-exclusion.js +214 -63
  37. package/dist/field-exclusion.js.map +1 -1
  38. package/dist/field-exclusion.spec.js +1057 -31
  39. package/dist/field-exclusion.spec.js.map +1 -1
  40. package/dist/field-structure.js +249 -78
  41. package/dist/field-structure.js.map +1 -1
  42. package/dist/field-structure.spec.js +534 -31
  43. package/dist/field-structure.spec.js.map +1 -1
  44. package/dist/fields-present.js +31 -27
  45. package/dist/fields-present.js.map +1 -1
  46. package/dist/fields-present.spec.js +120 -27
  47. package/dist/fields-present.spec.js.map +1 -1
  48. package/dist/fixed-fields.js +72 -27
  49. package/dist/fixed-fields.js.map +1 -1
  50. package/dist/fixed-fields.spec.js +139 -27
  51. package/dist/fixed-fields.spec.js.map +1 -1
  52. package/dist/identical-fields.js +42 -28
  53. package/dist/identical-fields.js.map +1 -1
  54. package/dist/identical-fields.spec.js +98 -27
  55. package/dist/identical-fields.spec.js.map +1 -1
  56. package/dist/index.js +202 -27
  57. package/dist/index.js.map +1 -1
  58. package/dist/indicator-fixes.js +191 -0
  59. package/dist/indicator-fixes.js.map +1 -0
  60. package/dist/indicator-fixes.spec.js +51 -0
  61. package/dist/indicator-fixes.spec.js.map +1 -0
  62. package/dist/isbn-issn.js +266 -27
  63. package/dist/isbn-issn.js.map +1 -1
  64. package/dist/isbn-issn.spec.js +594 -27
  65. package/dist/isbn-issn.spec.js.map +1 -1
  66. package/dist/item-language.js +171 -27
  67. package/dist/item-language.js.map +1 -1
  68. package/dist/item-language.spec.js +305 -27
  69. package/dist/item-language.spec.js.map +1 -1
  70. package/dist/mergeField500Lisapainokset.js +155 -0
  71. package/dist/mergeField500Lisapainokset.js.map +1 -0
  72. package/dist/mergeField500Lisapainokset.spec.js +51 -0
  73. package/dist/mergeField500Lisapainokset.spec.js.map +1 -0
  74. package/dist/mergeRelatorTermFields.js +140 -0
  75. package/dist/mergeRelatorTermFields.js.map +1 -0
  76. package/dist/mergeRelatorTermFields.spec.js +51 -0
  77. package/dist/mergeRelatorTermFields.spec.js.map +1 -0
  78. package/dist/multiple-subfield-0.js +120 -0
  79. package/dist/multiple-subfield-0.js.map +1 -0
  80. package/dist/multiple-subfield-0.spec.js +51 -0
  81. package/dist/multiple-subfield-0.spec.js.map +1 -0
  82. package/dist/non-breaking-space.js +61 -0
  83. package/dist/non-breaking-space.js.map +1 -0
  84. package/dist/non-breaking-space.spec.js +42 -0
  85. package/dist/non-breaking-space.spec.js.map +1 -0
  86. package/dist/normalize-identifiers.js +210 -0
  87. package/dist/normalize-identifiers.js.map +1 -0
  88. package/dist/normalize-identifiers.spec.js +51 -0
  89. package/dist/normalize-identifiers.spec.js.map +1 -0
  90. package/dist/normalize-utf8-diacritics.js +140 -0
  91. package/dist/normalize-utf8-diacritics.js.map +1 -0
  92. package/dist/normalize-utf8-diacritics.spec.js +51 -0
  93. package/dist/normalize-utf8-diacritics.spec.js.map +1 -0
  94. package/dist/punctuation/index.js +281 -0
  95. package/dist/punctuation/index.js.map +1 -0
  96. package/dist/punctuation/rules/aut.js +332 -0
  97. package/dist/punctuation/rules/aut.js.map +1 -0
  98. package/dist/punctuation/rules/bib.js +374 -0
  99. package/dist/punctuation/rules/bib.js.map +1 -0
  100. package/dist/punctuation/rules/index.js +21 -0
  101. package/dist/punctuation/rules/index.js.map +1 -0
  102. package/dist/punctuation.spec.js +51 -0
  103. package/dist/punctuation.spec.js.map +1 -0
  104. package/dist/punctuation2.js +726 -0
  105. package/dist/punctuation2.js.map +1 -0
  106. package/dist/punctuation2.spec.js +51 -0
  107. package/dist/punctuation2.spec.js.map +1 -0
  108. package/dist/reindexSubfield6OccurenceNumbers.js +199 -0
  109. package/dist/reindexSubfield6OccurenceNumbers.js.map +1 -0
  110. package/dist/reindexSubfield6OccurenceNumbers.spec.js +51 -0
  111. package/dist/reindexSubfield6OccurenceNumbers.spec.js.map +1 -0
  112. package/dist/removeDuplicateDataFields.js +405 -0
  113. package/dist/removeDuplicateDataFields.js.map +1 -0
  114. package/dist/removeDuplicateDataFields.spec.js +51 -0
  115. package/dist/removeDuplicateDataFields.spec.js.map +1 -0
  116. package/dist/removeInferiorDataFields.js +245 -0
  117. package/dist/removeInferiorDataFields.js.map +1 -0
  118. package/dist/removeInferiorDataFields.spec.js +51 -0
  119. package/dist/removeInferiorDataFields.spec.js.map +1 -0
  120. package/dist/resolvable-ext-references-melinda.js +112 -31
  121. package/dist/resolvable-ext-references-melinda.js.map +1 -1
  122. package/dist/resolvable-ext-references-melinda.spec.js +166 -27
  123. package/dist/resolvable-ext-references-melinda.spec.js.map +1 -1
  124. package/dist/resolveOrphanedSubfield6s.js +116 -0
  125. package/dist/resolveOrphanedSubfield6s.js.map +1 -0
  126. package/dist/resolveOrphanedSubfield6s.spec.js +51 -0
  127. package/dist/resolveOrphanedSubfield6s.spec.js.map +1 -0
  128. package/dist/sanitize-vocabulary-source-codes.js +93 -0
  129. package/dist/sanitize-vocabulary-source-codes.js.map +1 -0
  130. package/dist/sanitize-vocabulary-source-codes.spec.js +51 -0
  131. package/dist/sanitize-vocabulary-source-codes.spec.js.map +1 -0
  132. package/dist/sort-tags.js +53 -27
  133. package/dist/sort-tags.js.map +1 -1
  134. package/dist/sort-tags.spec.js +206 -27
  135. package/dist/sort-tags.spec.js.map +1 -1
  136. package/dist/sortRelatorTerms.js +135 -0
  137. package/dist/sortRelatorTerms.js.map +1 -0
  138. package/dist/sortRelatorTerms.spec.js +51 -0
  139. package/dist/sortRelatorTerms.spec.js.map +1 -0
  140. package/dist/sortSubfields.js +279 -0
  141. package/dist/sortSubfields.js.map +1 -0
  142. package/dist/sortSubfields.spec.js +51 -0
  143. package/dist/sortSubfields.spec.js.map +1 -0
  144. package/dist/stripPunctuation.js +49 -0
  145. package/dist/stripPunctuation.js.map +1 -0
  146. package/dist/stripPunctuation.spec.js +51 -0
  147. package/dist/stripPunctuation.spec.js.map +1 -0
  148. package/dist/subfield-exclusion.js +174 -57
  149. package/dist/subfield-exclusion.js.map +1 -1
  150. package/dist/subfield-exclusion.spec.js +521 -31
  151. package/dist/subfield-exclusion.spec.js.map +1 -1
  152. package/dist/subfield6Utils.js +457 -0
  153. package/dist/subfield6Utils.js.map +1 -0
  154. package/dist/subfield8Utils.js +99 -0
  155. package/dist/subfield8Utils.js.map +1 -0
  156. package/dist/typeOfDate-008.js +48 -0
  157. package/dist/typeOfDate-008.js.map +1 -0
  158. package/dist/typeOfDate-008.spec.js +47 -0
  159. package/dist/typeOfDate-008.spec.js.map +1 -0
  160. package/dist/unicode-decomposition.js +139 -30
  161. package/dist/unicode-decomposition.js.map +1 -1
  162. package/dist/unicode-decomposition.spec.js +90 -27
  163. package/dist/unicode-decomposition.spec.js.map +1 -1
  164. package/dist/update-field-540.js +119 -0
  165. package/dist/update-field-540.js.map +1 -0
  166. package/dist/update-field-540.spec.js +51 -0
  167. package/dist/update-field-540.spec.js.map +1 -0
  168. package/dist/urn.js +185 -0
  169. package/dist/urn.js.map +1 -0
  170. package/dist/urn.spec.js +238 -0
  171. package/dist/urn.spec.js.map +1 -0
  172. package/dist/utils.js +58 -0
  173. package/dist/utils.js.map +1 -0
  174. package/package.json +114 -124
  175. package/src/access-rights.js +84 -0
  176. package/src/access-rights.spec.js +126 -0
  177. package/src/double-commas.js +12 -49
  178. package/src/double-commas.spec.js +50 -82
  179. package/src/duplicates-ind1.js +34 -74
  180. package/src/duplicates-ind1.spec.js +39 -117
  181. package/src/empty-fields.js +62 -74
  182. package/src/empty-fields.spec.js +134 -207
  183. package/src/ending-punctuation-conf.js +679 -644
  184. package/src/ending-punctuation.js +260 -250
  185. package/src/ending-punctuation.spec.js +2545 -2322
  186. package/src/ending-whitespace.js +40 -0
  187. package/src/ending-whitespace.spec.js +44 -0
  188. package/src/field-521-fix.js +92 -0
  189. package/src/field-521-fix.spec.js +52 -0
  190. package/src/field-exclusion.js +197 -215
  191. package/src/field-exclusion.spec.js +883 -481
  192. package/src/field-structure.js +213 -271
  193. package/src/field-structure.spec.js +597 -474
  194. package/src/fields-present.js +19 -49
  195. package/src/fields-present.spec.js +90 -91
  196. package/src/fixed-fields.js +61 -94
  197. package/src/fixed-fields.spec.js +81 -125
  198. package/src/identical-fields.js +29 -48
  199. package/src/identical-fields.spec.js +114 -146
  200. package/src/index.js +41 -46
  201. package/src/indicator-fixes.js +211 -0
  202. package/src/indicator-fixes.spec.js +52 -0
  203. package/src/isbn-issn.js +254 -106
  204. package/src/isbn-issn.spec.js +399 -172
  205. package/src/item-language.js +158 -195
  206. package/src/item-language.spec.js +314 -306
  207. package/src/mergeField500Lisapainokset.js +153 -0
  208. package/src/mergeField500Lisapainokset.spec.js +52 -0
  209. package/src/mergeRelatorTermFields.js +143 -0
  210. package/src/mergeRelatorTermFields.spec.js +52 -0
  211. package/src/multiple-subfield-0.js +129 -0
  212. package/src/multiple-subfield-0.spec.js +52 -0
  213. package/src/non-breaking-space.js +49 -0
  214. package/src/non-breaking-space.spec.js +44 -0
  215. package/src/normalize-identifiers.js +197 -0
  216. package/src/normalize-identifiers.spec.js +52 -0
  217. package/src/normalize-utf8-diacritics.js +141 -0
  218. package/src/normalize-utf8-diacritics.spec.js +52 -0
  219. package/src/punctuation/index.js +292 -0
  220. package/src/punctuation/rules/aut.js +372 -0
  221. package/src/punctuation/rules/bib.js +420 -0
  222. package/src/punctuation/rules/index.js +7 -0
  223. package/src/punctuation.spec.js +52 -0
  224. package/src/punctuation2.js +441 -0
  225. package/src/punctuation2.spec.js +52 -0
  226. package/src/reindexSubfield6OccurenceNumbers.js +210 -0
  227. package/src/reindexSubfield6OccurenceNumbers.spec.js +52 -0
  228. package/src/removeDuplicateDataFields.js +447 -0
  229. package/src/removeDuplicateDataFields.spec.js +52 -0
  230. package/src/removeInferiorDataFields.js +259 -0
  231. package/src/removeInferiorDataFields.spec.js +52 -0
  232. package/src/resolvable-ext-references-melinda.js +89 -122
  233. package/src/resolvable-ext-references-melinda.spec.js +168 -198
  234. package/src/resolveOrphanedSubfield6s.js +115 -0
  235. package/src/resolveOrphanedSubfield6s.spec.js +52 -0
  236. package/src/sanitize-vocabulary-source-codes.js +99 -0
  237. package/src/sanitize-vocabulary-source-codes.spec.js +52 -0
  238. package/src/sort-tags.js +34 -60
  239. package/src/sort-tags.spec.js +256 -290
  240. package/src/sortRelatorTerms.js +142 -0
  241. package/src/sortRelatorTerms.spec.js +52 -0
  242. package/src/sortSubfields.js +176 -0
  243. package/src/sortSubfields.spec.js +52 -0
  244. package/src/stripPunctuation.js +42 -0
  245. package/src/stripPunctuation.spec.js +52 -0
  246. package/src/subfield-exclusion.js +157 -180
  247. package/src/subfield-exclusion.spec.js +507 -453
  248. package/src/subfield6Utils.js +485 -0
  249. package/src/subfield8Utils.js +102 -0
  250. package/src/typeOfDate-008.js +40 -0
  251. package/src/typeOfDate-008.spec.js +47 -0
  252. package/src/unicode-decomposition.js +130 -145
  253. package/src/unicode-decomposition.spec.js +89 -115
  254. package/src/update-field-540.js +99 -0
  255. package/src/update-field-540.spec.js +52 -0
  256. package/src/urn.js +164 -0
  257. package/src/urn.spec.js +231 -0
  258. package/src/utils.js +52 -0
  259. package/test-fixtures/duplicates-ind1/01/expectedResult.json +4 -0
  260. package/test-fixtures/duplicates-ind1/01/metadata.json +4 -0
  261. package/test-fixtures/duplicates-ind1/01/record.json +16 -0
  262. package/test-fixtures/duplicates-ind1/02/expectedResult.json +6 -0
  263. package/test-fixtures/duplicates-ind1/02/metadata.json +4 -0
  264. package/test-fixtures/duplicates-ind1/02/record.json +16 -0
  265. package/test-fixtures/duplicates-ind1/03/expectedResult.json +13 -0
  266. package/test-fixtures/duplicates-ind1/03/metadata.json +6 -0
  267. package/test-fixtures/duplicates-ind1/03/record.json +16 -0
  268. package/test-fixtures/ending-whitespace/01/expectedResult.json +4 -0
  269. package/test-fixtures/ending-whitespace/01/metadata.json +6 -0
  270. package/test-fixtures/ending-whitespace/01/record.json +15 -0
  271. package/test-fixtures/ending-whitespace/02/expectedResult.json +4 -0
  272. package/test-fixtures/ending-whitespace/02/metadata.json +6 -0
  273. package/test-fixtures/ending-whitespace/02/record.json +15 -0
  274. package/test-fixtures/ending-whitespace/03/expectedResult.json +17 -0
  275. package/test-fixtures/ending-whitespace/03/metadata.json +6 -0
  276. package/test-fixtures/ending-whitespace/03/record.json +15 -0
  277. package/test-fixtures/ending-whitespace/04/expectedResult.json +10 -0
  278. package/test-fixtures/ending-whitespace/04/metadata.json +6 -0
  279. package/test-fixtures/ending-whitespace/04/record.json +8 -0
  280. package/test-fixtures/fix521/01/expectedResult.json +6 -0
  281. package/test-fixtures/fix521/01/metadata.json +5 -0
  282. package/test-fixtures/fix521/01/record.json +13 -0
  283. package/test-fixtures/fix521/02/expectedResult.json +15 -0
  284. package/test-fixtures/fix521/02/metadata.json +5 -0
  285. package/test-fixtures/fix521/02/record.json +13 -0
  286. package/test-fixtures/fix521/03/expectedResult.json +5 -0
  287. package/test-fixtures/fix521/03/metadata.json +5 -0
  288. package/test-fixtures/fix521/03/record.json +13 -0
  289. package/test-fixtures/indicator-fixes/01/expectedResult.json +9 -0
  290. package/test-fixtures/indicator-fixes/01/metadata.json +5 -0
  291. package/test-fixtures/indicator-fixes/01/record.json +64 -0
  292. package/test-fixtures/indicator-fixes/02/expectedResult.json +66 -0
  293. package/test-fixtures/indicator-fixes/02/metadata.json +5 -0
  294. package/test-fixtures/indicator-fixes/02/record.json +64 -0
  295. package/test-fixtures/indicator-fixes/03/expectedResult.json +55 -0
  296. package/test-fixtures/indicator-fixes/03/metadata.json +5 -0
  297. package/test-fixtures/indicator-fixes/03/record.json +54 -0
  298. package/test-fixtures/indicator-fixes/04/expectedResult.json +66 -0
  299. package/test-fixtures/indicator-fixes/04/metadata.json +5 -0
  300. package/test-fixtures/indicator-fixes/04/record.json +65 -0
  301. package/test-fixtures/indicator-fixes/05/expectedResult.json +66 -0
  302. package/test-fixtures/indicator-fixes/05/metadata.json +5 -0
  303. package/test-fixtures/indicator-fixes/05/record.json +65 -0
  304. package/test-fixtures/indicator-fixes/06/expectedResult.json +75 -0
  305. package/test-fixtures/indicator-fixes/06/metadata.json +5 -0
  306. package/test-fixtures/indicator-fixes/06/record.json +74 -0
  307. package/test-fixtures/lisapainokset/fixer/01/expectedResult.json +37 -0
  308. package/test-fixtures/lisapainokset/fixer/01/metadata.json +6 -0
  309. package/test-fixtures/lisapainokset/fixer/01/record.json +61 -0
  310. package/test-fixtures/lisapainokset/fixer/02/expectedResult.json +44 -0
  311. package/test-fixtures/lisapainokset/fixer/02/metadata.json +6 -0
  312. package/test-fixtures/lisapainokset/fixer/02/record.json +45 -0
  313. package/test-fixtures/lisapainokset/fixer/03/expectedResult.json +21 -0
  314. package/test-fixtures/lisapainokset/fixer/03/metadata.json +6 -0
  315. package/test-fixtures/lisapainokset/fixer/03/record.json +45 -0
  316. package/test-fixtures/lisapainokset/validator/01/expectedResult.json +7 -0
  317. package/test-fixtures/lisapainokset/validator/01/metadata.json +6 -0
  318. package/test-fixtures/lisapainokset/validator/01/record.json +45 -0
  319. package/test-fixtures/lisapainokset/validator/02/expectedResult.json +6 -0
  320. package/test-fixtures/lisapainokset/validator/02/metadata.json +6 -0
  321. package/test-fixtures/lisapainokset/validator/02/record.json +61 -0
  322. package/test-fixtures/lisapainokset/validator/03/expectedResult.json +4 -0
  323. package/test-fixtures/lisapainokset/validator/03/metadata.json +6 -0
  324. package/test-fixtures/lisapainokset/validator/03/record.json +37 -0
  325. package/test-fixtures/mergeRelatorTermFields/fixer/01/expectedResult.json +14 -0
  326. package/test-fixtures/mergeRelatorTermFields/fixer/01/metadata.json +6 -0
  327. package/test-fixtures/mergeRelatorTermFields/fixer/01/record.json +16 -0
  328. package/test-fixtures/mergeRelatorTermFields/fixer/02/expectedResult.json +17 -0
  329. package/test-fixtures/mergeRelatorTermFields/fixer/02/metadata.json +6 -0
  330. package/test-fixtures/mergeRelatorTermFields/fixer/02/record.json +23 -0
  331. package/test-fixtures/mergeRelatorTermFields/validator/01/expectedResult.json +6 -0
  332. package/test-fixtures/mergeRelatorTermFields/validator/01/metadata.json +6 -0
  333. package/test-fixtures/mergeRelatorTermFields/validator/01/record.json +16 -0
  334. package/test-fixtures/mergeRelatorTermFields/validator/02/expectedResult.json +4 -0
  335. package/test-fixtures/mergeRelatorTermFields/validator/02/metadata.json +6 -0
  336. package/test-fixtures/mergeRelatorTermFields/validator/02/record.json +16 -0
  337. package/test-fixtures/non-breaking-space/01/expectedResult.json +4 -0
  338. package/test-fixtures/non-breaking-space/01/metadata.json +6 -0
  339. package/test-fixtures/non-breaking-space/01/record.json +15 -0
  340. package/test-fixtures/non-breaking-space/02/expectedResult.json +4 -0
  341. package/test-fixtures/non-breaking-space/02/metadata.json +6 -0
  342. package/test-fixtures/non-breaking-space/02/record.json +15 -0
  343. package/test-fixtures/non-breaking-space/03/expectedResult.json +17 -0
  344. package/test-fixtures/non-breaking-space/03/metadata.json +6 -0
  345. package/test-fixtures/non-breaking-space/03/record.json +15 -0
  346. package/test-fixtures/non-breaking-space/04/expectedResult.json +21 -0
  347. package/test-fixtures/non-breaking-space/04/metadata.json +6 -0
  348. package/test-fixtures/non-breaking-space/04/record.json +19 -0
  349. package/test-fixtures/normalize-identifiers/01/expectedResult.json +8 -0
  350. package/test-fixtures/normalize-identifiers/01/metadata.json +5 -0
  351. package/test-fixtures/normalize-identifiers/01/record.json +81 -0
  352. package/test-fixtures/normalize-identifiers/02/expectedResult.json +92 -0
  353. package/test-fixtures/normalize-identifiers/02/metadata.json +5 -0
  354. package/test-fixtures/normalize-identifiers/02/record.json +92 -0
  355. package/test-fixtures/normalize-identifiers/03/expectedResult.json +63 -0
  356. package/test-fixtures/normalize-identifiers/03/metadata.json +5 -0
  357. package/test-fixtures/normalize-identifiers/03/record.json +61 -0
  358. package/test-fixtures/normalize-identifiers/04/expectedResult.json +79 -0
  359. package/test-fixtures/normalize-identifiers/04/metadata.json +5 -0
  360. package/test-fixtures/normalize-identifiers/04/record.json +77 -0
  361. package/test-fixtures/normalize-utf8-diacritics/01/expectedResult.json +7 -0
  362. package/test-fixtures/normalize-utf8-diacritics/01/metadata.json +5 -0
  363. package/test-fixtures/normalize-utf8-diacritics/01/record.json +39 -0
  364. package/test-fixtures/normalize-utf8-diacritics/02/expectedResult.json +41 -0
  365. package/test-fixtures/normalize-utf8-diacritics/02/metadata.json +5 -0
  366. package/test-fixtures/normalize-utf8-diacritics/02/record.json +39 -0
  367. package/test-fixtures/normalize-utf8-diacritics/03/expectedResult.json +5 -0
  368. package/test-fixtures/normalize-utf8-diacritics/03/metadata.json +5 -0
  369. package/test-fixtures/normalize-utf8-diacritics/03/record.json +37 -0
  370. package/test-fixtures/normalize-utf8-diacritics/04/expectedResult.json +41 -0
  371. package/test-fixtures/normalize-utf8-diacritics/04/metadata.json +5 -0
  372. package/test-fixtures/normalize-utf8-diacritics/04/record.json +39 -0
  373. package/test-fixtures/normalize-utf8-diacritics/05/expectedResult.json +41 -0
  374. package/test-fixtures/normalize-utf8-diacritics/05/metadata.json +5 -0
  375. package/test-fixtures/normalize-utf8-diacritics/05/record.json +41 -0
  376. package/test-fixtures/punctuation/01/expectedResult.json +3 -0
  377. package/test-fixtures/punctuation/01/metadata.json +4 -0
  378. package/test-fixtures/punctuation/01/record.json +18 -0
  379. package/test-fixtures/punctuation/02/expectedResult.json +3 -0
  380. package/test-fixtures/punctuation/02/metadata.json +4 -0
  381. package/test-fixtures/punctuation/02/record.json +18 -0
  382. package/test-fixtures/punctuation/03/expectedResult.json +21 -0
  383. package/test-fixtures/punctuation/03/metadata.json +5 -0
  384. package/test-fixtures/punctuation/03/record.json +19 -0
  385. package/test-fixtures/punctuation/04/expectedResult.json +21 -0
  386. package/test-fixtures/punctuation/04/metadata.json +5 -0
  387. package/test-fixtures/punctuation/04/record.json +19 -0
  388. package/test-fixtures/punctuation/05/expectedResult.json +44 -0
  389. package/test-fixtures/punctuation/05/metadata.json +5 -0
  390. package/test-fixtures/punctuation/05/record.json +42 -0
  391. package/test-fixtures/punctuation2/01/expectedResult.json +12 -0
  392. package/test-fixtures/punctuation2/01/metadata.json +6 -0
  393. package/test-fixtures/punctuation2/01/record.json +37 -0
  394. package/test-fixtures/punctuation2/02/expectedResult.json +4 -0
  395. package/test-fixtures/punctuation2/02/metadata.json +6 -0
  396. package/test-fixtures/punctuation2/02/record.json +14 -0
  397. package/test-fixtures/punctuation2/04/expectedResult.json +7 -0
  398. package/test-fixtures/punctuation2/04/metadata.json +6 -0
  399. package/test-fixtures/punctuation2/04/record.json +22 -0
  400. package/test-fixtures/punctuation2/05/expectedResult.json +6 -0
  401. package/test-fixtures/punctuation2/05/metadata.json +6 -0
  402. package/test-fixtures/punctuation2/05/record.json +12 -0
  403. package/test-fixtures/punctuation2/98/expectedResult.json +45 -0
  404. package/test-fixtures/punctuation2/98/metadata.json +6 -0
  405. package/test-fixtures/punctuation2/98/record.json +43 -0
  406. package/test-fixtures/punctuation2/99/expectedResult.json +15 -0
  407. package/test-fixtures/punctuation2/99/metadata.json +6 -0
  408. package/test-fixtures/punctuation2/99/record.json +14 -0
  409. package/test-fixtures/reindex-sf6-occurence-numbers/f01/expectedResult.json +35 -0
  410. package/test-fixtures/reindex-sf6-occurence-numbers/f01/metadata.json +6 -0
  411. package/test-fixtures/reindex-sf6-occurence-numbers/f01/record.json +34 -0
  412. package/test-fixtures/reindex-sf6-occurence-numbers/f02/expectedResult.json +53 -0
  413. package/test-fixtures/reindex-sf6-occurence-numbers/f02/metadata.json +6 -0
  414. package/test-fixtures/reindex-sf6-occurence-numbers/f02/record.json +51 -0
  415. package/test-fixtures/reindex-sf6-occurence-numbers/f03/expectedResult.json +46 -0
  416. package/test-fixtures/reindex-sf6-occurence-numbers/f03/metadata.json +7 -0
  417. package/test-fixtures/reindex-sf6-occurence-numbers/f03/record.json +44 -0
  418. package/test-fixtures/reindex-sf6-occurence-numbers/v01/expectedResult.json +6 -0
  419. package/test-fixtures/reindex-sf6-occurence-numbers/v01/metadata.json +5 -0
  420. package/test-fixtures/reindex-sf6-occurence-numbers/v01/record.json +31 -0
  421. package/test-fixtures/reindex-sf6-occurence-numbers/v02/expectedResult.json +6 -0
  422. package/test-fixtures/reindex-sf6-occurence-numbers/v02/metadata.json +6 -0
  423. package/test-fixtures/reindex-sf6-occurence-numbers/v02/record.json +38 -0
  424. package/test-fixtures/reindex-sf6-occurence-numbers/v03/expectedResult.json +6 -0
  425. package/test-fixtures/reindex-sf6-occurence-numbers/v03/metadata.json +6 -0
  426. package/test-fixtures/reindex-sf6-occurence-numbers/v03/record.json +30 -0
  427. package/test-fixtures/remove-duplicate-datafields/f01/expectedResult.json +35 -0
  428. package/test-fixtures/remove-duplicate-datafields/f01/metadata.json +6 -0
  429. package/test-fixtures/remove-duplicate-datafields/f01/record.json +34 -0
  430. package/test-fixtures/remove-duplicate-datafields/f03/expectedResult.json +20 -0
  431. package/test-fixtures/remove-duplicate-datafields/f03/metadata.json +6 -0
  432. package/test-fixtures/remove-duplicate-datafields/f03/record.json +33 -0
  433. package/test-fixtures/remove-duplicate-datafields/f03b/expectedResult.json +20 -0
  434. package/test-fixtures/remove-duplicate-datafields/f03b/metadata.json +6 -0
  435. package/test-fixtures/remove-duplicate-datafields/f03b/record.json +35 -0
  436. package/test-fixtures/remove-duplicate-datafields/f03c/expectedResult.json +25 -0
  437. package/test-fixtures/remove-duplicate-datafields/f03c/metadata.json +6 -0
  438. package/test-fixtures/remove-duplicate-datafields/f03c/record.json +43 -0
  439. package/test-fixtures/remove-duplicate-datafields/f04/expectedResult.json +31 -0
  440. package/test-fixtures/remove-duplicate-datafields/f04/metadata.json +6 -0
  441. package/test-fixtures/remove-duplicate-datafields/f04/record.json +41 -0
  442. package/test-fixtures/remove-duplicate-datafields/f05/expectedResult.json +23 -0
  443. package/test-fixtures/remove-duplicate-datafields/f05/metadata.json +6 -0
  444. package/test-fixtures/remove-duplicate-datafields/f05/record.json +29 -0
  445. package/test-fixtures/remove-duplicate-datafields/f06/expectedResult.json +24 -0
  446. package/test-fixtures/remove-duplicate-datafields/f06/metadata.json +6 -0
  447. package/test-fixtures/remove-duplicate-datafields/f06/record.json +41 -0
  448. package/test-fixtures/remove-duplicate-datafields/f07/expectedResult.json +15 -0
  449. package/test-fixtures/remove-duplicate-datafields/f07/metadata.json +6 -0
  450. package/test-fixtures/remove-duplicate-datafields/f07/record.json +21 -0
  451. package/test-fixtures/remove-duplicate-datafields/f08/expectedResult.json +21 -0
  452. package/test-fixtures/remove-duplicate-datafields/f08/metadata.json +6 -0
  453. package/test-fixtures/remove-duplicate-datafields/f08/record.json +33 -0
  454. package/test-fixtures/remove-duplicate-datafields/f09/expectedResult.json +6 -0
  455. package/test-fixtures/remove-duplicate-datafields/f09/metadata.json +6 -0
  456. package/test-fixtures/remove-duplicate-datafields/f09/record.json +9 -0
  457. package/test-fixtures/remove-duplicate-datafields/f10/expectedResult.json +15 -0
  458. package/test-fixtures/remove-duplicate-datafields/f10/metadata.json +6 -0
  459. package/test-fixtures/remove-duplicate-datafields/f10/record.json +24 -0
  460. package/test-fixtures/remove-duplicate-datafields/f11/expectedResult.json +30 -0
  461. package/test-fixtures/remove-duplicate-datafields/f11/metadata.json +6 -0
  462. package/test-fixtures/remove-duplicate-datafields/f11/record.json +53 -0
  463. package/test-fixtures/remove-duplicate-datafields/v01/expectedResult.json +6 -0
  464. package/test-fixtures/remove-duplicate-datafields/v01/metadata.json +6 -0
  465. package/test-fixtures/remove-duplicate-datafields/v01/record.json +31 -0
  466. package/test-fixtures/remove-duplicate-datafields/v02/expectedResult.json +10 -0
  467. package/test-fixtures/remove-duplicate-datafields/v02/metadata.json +6 -0
  468. package/test-fixtures/remove-duplicate-datafields/v02/record.json +45 -0
  469. package/test-fixtures/remove-duplicate-datafields/v03/expectedResult.json +6 -0
  470. package/test-fixtures/remove-duplicate-datafields/v03/metadata.json +7 -0
  471. package/test-fixtures/remove-duplicate-datafields/v03/record.json +37 -0
  472. package/test-fixtures/remove-duplicate-datafields/v04/expectedResult.json +8 -0
  473. package/test-fixtures/remove-duplicate-datafields/v04/metadata.json +6 -0
  474. package/test-fixtures/remove-duplicate-datafields/v04/record.json +41 -0
  475. package/test-fixtures/remove-inferior-datafields/f01/expectedResult.json +21 -0
  476. package/test-fixtures/remove-inferior-datafields/f01/metadata.json +6 -0
  477. package/test-fixtures/remove-inferior-datafields/f01/record.json +31 -0
  478. package/test-fixtures/remove-inferior-datafields/f03/expectedResult.json +16 -0
  479. package/test-fixtures/remove-inferior-datafields/f03/metadata.json +6 -0
  480. package/test-fixtures/remove-inferior-datafields/f03/record.json +27 -0
  481. package/test-fixtures/remove-inferior-datafields/f04/expectedResult.json +31 -0
  482. package/test-fixtures/remove-inferior-datafields/f04/metadata.json +6 -0
  483. package/test-fixtures/remove-inferior-datafields/f04/record.json +38 -0
  484. package/test-fixtures/remove-inferior-datafields/f05/expectedResult.json +34 -0
  485. package/test-fixtures/remove-inferior-datafields/f05/metadata.json +6 -0
  486. package/test-fixtures/remove-inferior-datafields/f05/record.json +41 -0
  487. package/test-fixtures/remove-inferior-datafields/f06/expectedResult.json +16 -0
  488. package/test-fixtures/remove-inferior-datafields/f06/metadata.json +6 -0
  489. package/test-fixtures/remove-inferior-datafields/f06/record.json +20 -0
  490. package/test-fixtures/remove-inferior-datafields/v01/expectedResult.json +6 -0
  491. package/test-fixtures/remove-inferior-datafields/v01/metadata.json +6 -0
  492. package/test-fixtures/remove-inferior-datafields/v01/record.json +31 -0
  493. package/test-fixtures/remove-inferior-datafields/v02/expectedResult.json +6 -0
  494. package/test-fixtures/remove-inferior-datafields/v02/metadata.json +6 -0
  495. package/test-fixtures/remove-inferior-datafields/v02/record.json +21 -0
  496. package/test-fixtures/remove-orphanded-sf6s/f01/expectedResult.json +35 -0
  497. package/test-fixtures/remove-orphanded-sf6s/f01/metadata.json +6 -0
  498. package/test-fixtures/remove-orphanded-sf6s/f01/record.json +34 -0
  499. package/test-fixtures/remove-orphanded-sf6s/f02/expectedResult.json +40 -0
  500. package/test-fixtures/remove-orphanded-sf6s/f02/metadata.json +6 -0
  501. package/test-fixtures/remove-orphanded-sf6s/f02/record.json +43 -0
  502. package/test-fixtures/remove-orphanded-sf6s/v01/expectedResult.json +6 -0
  503. package/test-fixtures/remove-orphanded-sf6s/v01/metadata.json +6 -0
  504. package/test-fixtures/remove-orphanded-sf6s/v01/record.json +31 -0
  505. package/test-fixtures/remove-orphanded-sf6s/v02/expectedResult.json +6 -0
  506. package/test-fixtures/remove-orphanded-sf6s/v02/metadata.json +6 -0
  507. package/test-fixtures/remove-orphanded-sf6s/v02/record.json +31 -0
  508. package/test-fixtures/resolvable-ext-references-melinda.js +0 -27
  509. package/test-fixtures/sanitize-vocabulary-source-codes/f01/expectedResult.json +32 -0
  510. package/test-fixtures/sanitize-vocabulary-source-codes/f01/metadata.json +6 -0
  511. package/test-fixtures/sanitize-vocabulary-source-codes/f01/record.json +32 -0
  512. package/test-fixtures/sanitize-vocabulary-source-codes/f02/expectedResult.json +24 -0
  513. package/test-fixtures/sanitize-vocabulary-source-codes/f02/metadata.json +6 -0
  514. package/test-fixtures/sanitize-vocabulary-source-codes/f02/record.json +24 -0
  515. package/test-fixtures/sanitize-vocabulary-source-codes/v01/expectedResult.json +12 -0
  516. package/test-fixtures/sanitize-vocabulary-source-codes/v01/metadata.json +6 -0
  517. package/test-fixtures/sanitize-vocabulary-source-codes/v01/record.json +24 -0
  518. package/test-fixtures/sort-relator-terms/f01/expectedResult.json +23 -0
  519. package/test-fixtures/sort-relator-terms/f01/metadata.json +6 -0
  520. package/test-fixtures/sort-relator-terms/f01/record.json +22 -0
  521. package/test-fixtures/sort-relator-terms/f02/expectedResult.json +26 -0
  522. package/test-fixtures/sort-relator-terms/f02/metadata.json +6 -0
  523. package/test-fixtures/sort-relator-terms/f02/record.json +22 -0
  524. package/test-fixtures/sort-relator-terms/v01/expectedResult.json +5 -0
  525. package/test-fixtures/sort-relator-terms/v01/metadata.json +6 -0
  526. package/test-fixtures/sort-relator-terms/v01/record.json +22 -0
  527. package/test-fixtures/sort-relator-terms/v02/expectedResult.json +6 -0
  528. package/test-fixtures/sort-relator-terms/v02/metadata.json +6 -0
  529. package/test-fixtures/sort-relator-terms/v02/record.json +14 -0
  530. package/test-fixtures/sort-subfields/f01/expectedResult.json +24 -0
  531. package/test-fixtures/sort-subfields/f01/metadata.json +6 -0
  532. package/test-fixtures/sort-subfields/f01/record.json +20 -0
  533. package/test-fixtures/sort-subfields/v01/expectedResult.json +5 -0
  534. package/test-fixtures/sort-subfields/v01/metadata.json +6 -0
  535. package/test-fixtures/sort-subfields/v01/record.json +24 -0
  536. package/test-fixtures/sort-subfields/v02/expectedResult.json +6 -0
  537. package/test-fixtures/sort-subfields/v02/metadata.json +6 -0
  538. package/test-fixtures/sort-subfields/v02/record.json +8 -0
  539. package/test-fixtures/strip-punctuation/01/expectedResult.json +12 -0
  540. package/test-fixtures/strip-punctuation/01/metadata.json +6 -0
  541. package/test-fixtures/strip-punctuation/01/record.json +37 -0
  542. package/test-fixtures/strip-punctuation/02/expectedResult.json +4 -0
  543. package/test-fixtures/strip-punctuation/02/metadata.json +6 -0
  544. package/test-fixtures/strip-punctuation/02/record.json +14 -0
  545. package/test-fixtures/strip-punctuation/04/expectedResult.json +6 -0
  546. package/test-fixtures/strip-punctuation/04/metadata.json +6 -0
  547. package/test-fixtures/strip-punctuation/04/record.json +22 -0
  548. package/test-fixtures/strip-punctuation/05/expectedResult.json +6 -0
  549. package/test-fixtures/strip-punctuation/05/metadata.json +6 -0
  550. package/test-fixtures/strip-punctuation/05/record.json +12 -0
  551. package/test-fixtures/strip-punctuation/98/expectedResult.json +44 -0
  552. package/test-fixtures/strip-punctuation/98/metadata.json +6 -0
  553. package/test-fixtures/strip-punctuation/98/record.json +45 -0
  554. package/test-fixtures/strip-punctuation/99/expectedResult.json +16 -0
  555. package/test-fixtures/strip-punctuation/99/metadata.json +6 -0
  556. package/test-fixtures/strip-punctuation/99/record.json +16 -0
  557. package/test-fixtures/subfield0/f01/expectedResult.json +25 -0
  558. package/test-fixtures/subfield0/f01/metadata.json +6 -0
  559. package/test-fixtures/subfield0/f01/record.json +23 -0
  560. package/test-fixtures/subfield0/f02/expectedResult.json +35 -0
  561. package/test-fixtures/subfield0/f02/metadata.json +6 -0
  562. package/test-fixtures/subfield0/f02/record.json +41 -0
  563. package/test-fixtures/subfield0/f03/expectedResult.json +21 -0
  564. package/test-fixtures/subfield0/f03/metadata.json +7 -0
  565. package/test-fixtures/subfield0/f03/record.json +24 -0
  566. package/test-fixtures/subfield0/v01/expectedResult.json +4 -0
  567. package/test-fixtures/subfield0/v01/metadata.json +6 -0
  568. package/test-fixtures/subfield0/v01/record.json +23 -0
  569. package/test-fixtures/subfield0/v02/expectedResult.json +9 -0
  570. package/test-fixtures/subfield0/v02/metadata.json +6 -0
  571. package/test-fixtures/subfield0/v02/record.json +38 -0
  572. package/test-fixtures/typeOfDate-008/01/expectedResult.json +3 -0
  573. package/test-fixtures/typeOfDate-008/01/metadata.json +4 -0
  574. package/test-fixtures/typeOfDate-008/01/record.json +14 -0
  575. package/test-fixtures/typeOfDate-008/02/expectedResult.json +4 -0
  576. package/test-fixtures/typeOfDate-008/02/metadata.json +4 -0
  577. package/test-fixtures/typeOfDate-008/02/record.json +14 -0
  578. package/test-fixtures/typeOfDate-008/03/expectedResult.json +14 -0
  579. package/test-fixtures/typeOfDate-008/03/metadata.json +5 -0
  580. package/test-fixtures/typeOfDate-008/03/record.json +14 -0
  581. package/test-fixtures/typeOfDate-008/04/expectedResult.json +14 -0
  582. package/test-fixtures/typeOfDate-008/04/metadata.json +5 -0
  583. package/test-fixtures/typeOfDate-008/04/record.json +14 -0
  584. package/test-fixtures/typeOfDate-008/05/expectedResult.json +14 -0
  585. package/test-fixtures/typeOfDate-008/05/metadata.json +5 -0
  586. package/test-fixtures/typeOfDate-008/05/record.json +14 -0
  587. package/test-fixtures/update-field-540/f01/expectedResult.json +23 -0
  588. package/test-fixtures/update-field-540/f01/metadata.json +6 -0
  589. package/test-fixtures/update-field-540/f01/record.json +23 -0
  590. package/test-fixtures/update-field-540/v01/expectedResult.json +7 -0
  591. package/test-fixtures/update-field-540/v01/metadata.json +6 -0
  592. package/test-fixtures/update-field-540/v01/record.json +23 -0
  593. package/.travis.yml +0 -10
@@ -1,35 +1,3 @@
1
- /**
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-2018 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 Affero 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 Affero General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU Affero 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 no-undef, max-nested-callbacks, no-unused-expressions */
30
-
31
- 'use strict';
32
-
33
1
  import chai from 'chai';
34
2
  import chaiAsPromised from 'chai-as-promised';
35
3
  import {MarcRecord} from '@natlibfi/marc-record';
@@ -40,446 +8,601 @@ chai.use(chaiAsPromised);
40
8
 
41
9
  // Factory validation
42
10
  describe('field-structure', () => {
43
- it('Creates a validator', async () => {
44
- const config = [{
45
- tag: /^035$/,
46
- ind1: /^0$/,
47
- ind2: /^1$/
48
- }, {
49
- tag: /^100$/,
50
- subfields: {
51
- a: {maxOccurrence: 1}
52
- }
53
- }];
54
-
55
- const validator = await validatorFactory(config);
56
-
57
- expect(validator)
58
- .to.be.an('object')
59
- .that.has.any.keys('description', 'validate');
60
-
61
- expect(validator.description).to.be.a('string');
62
- expect(validator.validate).to.be.a('function');
63
- });
64
-
65
- describe('#configuration', () => {
66
- it('Throws an error when config array not provided', async () => {
67
- await expect(validatorFactory()).to.be.rejectedWith(Error, 'Configuration array not provided');
68
- });
69
-
70
- it('Throws an error when config array has unidentified field', async () => {
71
- const config = [{
72
- leader: /^035$/,
73
- tags: /^035$/
74
- }];
75
- await expect(validatorFactory(config)).to.be.rejectedWith(Error, 'Configuration not valid - unidentified value: tags');
76
- });
77
-
78
- it('Throws an error when config array has field with incorrect data type', async () => {
79
- const config = [{
80
- leader: /^035$/,
81
- tag: 35
82
- }];
83
- await expect(validatorFactory(config)).to.be.rejectedWith(Error, 'Configuration not valid - invalid data type for: tag');
84
- });
85
-
86
- it('Throws an error when config array has excluded element', async () => {
87
- const config = [{
88
- leader: /^035$/,
89
- tag: /^035$/
90
- }];
91
- await expect(validatorFactory(config)).to.be.rejectedWith(Error, 'Configuration not valid - excluded element');
92
- });
93
-
94
- it('Throws an error when config subfields not object', async () => {
95
- const config = [{
96
- tag: /^001$/,
97
- valuePattern: /\d+/
98
- }, {
99
- tag: /^245$/,
100
- strict: true,
101
- subfields: 'This should be Object'
102
- }];
103
- await expect(validatorFactory(config)).to.be.rejectedWith(Error, 'Configuration not valid - subfields not object');
104
- });
105
- });
106
-
107
- // Indicators and subfields validation
108
- describe('#validate: Indicators and subfields', () => {
109
- const config = [{
110
- tag: /^035$/,
111
- ind1: /^0$/,
112
- ind2: /^1$/
113
- }, {
114
- tag: /^100$/,
115
- subfields: {
116
- a: {maxOccurrence: 1}
117
- }
118
- }];
119
-
120
- const recordValid = new MarcRecord({
121
- leader: '',
122
- fields: [{
123
- tag: '001',
124
- value: '123456'
125
- }, {
126
- tag: '035',
127
- ind1: '0',
128
- ind2: '1',
129
- subfields: [{
130
- code: 'a',
131
- value: 'foo'
132
- }]
133
- }, {
134
- tag: '100',
135
- ind1: ' ',
136
- ind2: ' ',
137
- subfields: [{
138
- code: 'a',
139
- value: 'bar'
140
- }, {
141
- code: 'b',
142
- value: 'fubar'
143
- }]
144
- }]
145
- });
146
-
147
- const recordInvalidMany = new MarcRecord({
148
- leader: '',
149
- fields: [{
150
- tag: '001',
151
- value: '123456'
152
- }, {
153
- tag: '035',
154
- ind1: '1',
155
- ind2: '1',
156
- subfields: [{
157
- code: 'a',
158
- value: 'foo'
159
- }]
160
- }, {
161
- tag: '100',
162
- ind1: ' ',
163
- ind2: ' ',
164
- subfields: [{
165
- code: 'a',
166
- value: 'bar'
167
- }, {
168
- code: 'b',
169
- value: 'fubar'
170
- }, {
171
- code: 'a',
172
- value: 'barfoo'
173
- }]
174
- }]
175
- });
176
-
177
- it('Finds the record valid', async () => {
178
- const validator = await validatorFactory(config);
179
- const result = await validator.validate(recordValid);
180
-
181
- expect(result).to.eql({valid: true});
182
- });
183
-
184
- it('Finds the record invalid: Too many subfields', async () => {
185
- const validator = await validatorFactory(config);
186
- const result = await validator.validate(recordInvalidMany);
187
-
188
- expect(result).to.eql({valid: false});
189
- });
190
- });
191
-
192
- // Patterns and mandatory & strict subfields
193
- describe('#validate: Patterns and mandatory & strict subfields', () => {
194
- const config = [{
195
- tag: /^001$/,
196
- valuePattern: /\d+/
197
- }, {
198
- tag: /^245$/,
199
- strict: true,
200
- subfields: {
201
- a: {required: true, maxOccurrence: 1, pattern: /\w+/},
202
- b: {maxOccurrence: 1, pattern: /\w+/}
203
- }
204
- }];
205
-
206
- const recordValid = new MarcRecord({
207
- leader: '',
208
- fields: [{
209
- tag: '001',
210
- value: '123456'
211
- }, {
212
- tag: '100',
213
- ind1: ' ',
214
- ind2: ' ',
215
- subfields: [{
216
- code: 'a',
217
- value: 'bar'
218
- }]
219
- }, {
220
- tag: '245',
221
- ind1: ' ',
222
- ind2: ' ',
223
- subfields: [{
224
- code: 'a',
225
- value: 'foo'
226
- }, {
227
- code: 'b',
228
- value: 'bar'
229
- }]
230
- }]
231
- });
232
-
233
- const recordInvalidExtra = new MarcRecord({
234
- leader: '',
235
- fields: [{
236
- tag: '001',
237
- value: '123456a'
238
- }, {
239
- tag: '100',
240
- ind1: ' ',
241
- ind2: ' ',
242
- subfields: [{
243
- code: 'a',
244
- value: 'bar'
245
- }]
246
- }, {
247
- tag: '245',
248
- ind1: ' ',
249
- ind2: ' ',
250
- subfields: [{
251
- code: 'a',
252
- value: 'foo'
253
- }, {
254
- code: 'b',
255
- value: 'bar'
256
- }, {
257
- code: 'c',
258
- value: 'fubar'
259
- }]
260
- }]
261
- });
262
-
263
- const recordInvalidTooMany = new MarcRecord({
264
- leader: '',
265
- fields: [{
266
- tag: '001',
267
- value: '123456a'
268
- }, {
269
- tag: '100',
270
- ind1: ' ',
271
- ind2: ' ',
272
- subfields: [{
273
- code: 'a',
274
- value: 'bar'
275
- }]
276
- }, {
277
- tag: '245',
278
- ind1: ' ',
279
- ind2: ' ',
280
- subfields: [{
281
- code: 'a',
282
- value: 'foo'
283
- }, {
284
- code: 'b',
285
- value: 'bar'
286
- }, {
287
- code: 'a',
288
- value: 'fubar'
289
- }]
290
- }]
291
- });
292
-
293
- const recordInvalidRegExp = new MarcRecord({
294
- leader: '',
295
- fields: [{
296
- tag: '001',
297
- value: '123456a'
298
- }, {
299
- tag: '100',
300
- ind1: ' ',
301
- ind2: ' ',
302
- subfields: [{
303
- code: 'a',
304
- value: 'bar'
305
- }]
306
- }, {
307
- tag: '245',
308
- ind1: ' ',
309
- ind2: ' ',
310
- subfields: [{
311
- code: 'a',
312
- value: 'ää'
313
- }, {
314
- code: 'b',
315
- value: 'bar'
316
- }]
317
- }]
318
- });
319
-
320
- const recordInvalidMissing = new MarcRecord({
321
- leader: '',
322
- fields: [{
323
- tag: '100',
324
- ind1: ' ',
325
- ind2: ' ',
326
- subfields: [{
327
- code: 'a',
328
- value: 'bar'
329
- }]
330
- }, {
331
- tag: '245',
332
- ind1: ' ',
333
- ind2: ' ',
334
- subfields: [{
335
- code: 'a',
336
- value: 'ää'
337
- }, {
338
- code: 'b',
339
- value: 'bar'
340
- }]
341
- }]
342
- });
343
-
344
- const recordInvalidMissingSubfield = new MarcRecord({
345
- leader: '',
346
- fields: [{
347
- tag: '001',
348
- value: '123456'
349
- }, {
350
- tag: '100',
351
- ind1: ' ',
352
- ind2: ' ',
353
- subfields: [{
354
- code: 'a',
355
- value: 'bar'
356
- }]
357
- }, {
358
- tag: '245',
359
- ind1: ' ',
360
- ind2: ' ',
361
- subfields: [{
362
- code: 'b',
363
- value: 'bar'
364
- }]
365
- }]
366
- });
367
-
368
- it('Finds the record valid', async () => {
369
- const validator = await validatorFactory(config);
370
- const result = await validator.validate(recordValid);
371
-
372
- expect(result).to.eql({valid: true});
373
- });
374
-
375
- it('Finds the record invalid: Extra field in strict', async () => {
376
- const validator = await validatorFactory(config);
377
- const result = await validator.validate(recordInvalidExtra);
378
-
379
- expect(result).to.eql({valid: false});
380
- });
381
-
382
- it('Finds the record invalid: Too many occurances', async () => {
383
- const validator = await validatorFactory(config);
384
- const result = await validator.validate(recordInvalidTooMany);
385
-
386
- expect(result).to.eql({valid: false});
387
- });
388
-
389
- it('Finds the record invalid: Invalid RegExp', async () => {
390
- const validator = await validatorFactory(config);
391
- const result = await validator.validate(recordInvalidRegExp);
392
-
393
- expect(result).to.eql({valid: false});
394
- });
395
-
396
- it('Finds the record invalid: Missing field', async () => {
397
- const validator = await validatorFactory(config);
398
- const result = await validator.validate(recordInvalidMissing);
399
-
400
- expect(result).to.eql({valid: false});
401
- });
402
- it('Finds the record invalid: Missing subfield', async () => {
403
- const validator = await validatorFactory(config);
404
- const result = await validator.validate(recordInvalidMissingSubfield);
405
-
406
- expect(result).to.eql({valid: false});
407
- });
408
- });
409
-
410
- // Dependencies
411
- describe('#validate: Dependencies', () => {
412
- const config = [{
413
- leader: /^.{6}s/,
414
- dependencies: [{
415
- tag: /^773$/,
416
- subfields: {7: /^nnas$/}
417
- }]
418
- }];
419
-
420
- const recordValid = new MarcRecord({
421
- leader: '63ab75sfoo122myhgh',
422
- fields: [{
423
- tag: '001',
424
- value: '123456'
425
- }, {
426
- tag: '245',
427
- ind1: ' ',
428
- ind2: ' ',
429
- subfields: [{
430
- code: 'a',
431
- value: 'foo'
432
- }]
433
- }, {
434
- tag: '773',
435
- ind1: ' ',
436
- ind2: ' ',
437
- subfields: [{
438
- code: '7',
439
- value: 'nnas'
440
- }, {
441
- code: 'w',
442
- value: '789101112'
443
- }]
444
- }]
445
- });
446
-
447
- const recordInvalid = new MarcRecord({
448
- leader: '63ab75sfoo122myhgh',
449
- fields: [{
450
- tag: '001',
451
- value: '123456'
452
- }, {
453
- tag: '245',
454
- ind1: ' ',
455
- ind2: ' ',
456
- subfields: [{
457
- code: 'a',
458
- value: 'foo'
459
- }]
460
- }, {
461
- tag: '773',
462
- ind1: ' ',
463
- ind2: ' ',
464
- subfields: [{
465
- code: 'w',
466
- value: '789101112'
467
- }]
468
- }]
469
- });
470
-
471
- it('Finds the record valid', async () => {
472
- const validator = await validatorFactory(config);
473
- const result = await validator.validate(recordValid);
474
-
475
- expect(result).to.eql({valid: true});
476
- });
477
-
478
- it('Finds the record invalid: Subfield not there', async () => {
479
- const validator = await validatorFactory(config);
480
- const result = await validator.validate(recordInvalid);
481
-
482
- expect(result).to.eql({valid: false});
483
- });
484
- });
11
+ it('Creates a validator', async () => {
12
+ const config = [
13
+ {
14
+ tag: /^035$/u,
15
+ ind1: /^0$/u,
16
+ ind2: /^1$/u
17
+ }, {
18
+ tag: /^100$/u,
19
+ subfields: {
20
+ a: {maxOccurrence: 1}
21
+ }
22
+ }
23
+ ];
24
+
25
+ const validator = await validatorFactory(config);
26
+
27
+ expect(validator)
28
+ .to.be.an('object')
29
+ .that.has.any.keys('description', 'validate');
30
+
31
+ expect(validator.description).to.be.a('string');
32
+ expect(validator.validate).to.be.a('function');
33
+ });
34
+
35
+ describe('#configuration', () => {
36
+ it('Throws an error when config array not provided', () => {
37
+ try {
38
+ validatorFactory();
39
+ } catch (error) {
40
+ expect(error).to.be.an('error').with.property('message', 'Configuration array not provided');
41
+ }
42
+ });
43
+
44
+ it('Throws an error when config array has unidentified field', () => {
45
+ const config = [
46
+ {
47
+ leader: /^035$/u,
48
+ tags: /^035$/u
49
+ }
50
+ ];
51
+
52
+ try {
53
+ validatorFactory(config);
54
+ } catch (error) {
55
+ expect(error).to.be.an('error').with.property('message', 'Configuration not valid - unidentified value: tags');
56
+ }
57
+ });
58
+
59
+ it('Throws an error when config array has field with incorrect data type', () => {
60
+ const config = [
61
+ {
62
+ leader: /^035$/u,
63
+ tag: 35
64
+ }
65
+ ];
66
+
67
+ try {
68
+ validatorFactory(config);
69
+ } catch (error) {
70
+ expect(error).to.be.an('error').with.property('message', 'Configuration not valid - invalid data type for: tag');
71
+ }
72
+ });
73
+
74
+ it('Throws an error when config array has excluded element', () => {
75
+ const config = [
76
+ {
77
+ leader: /^035$/u,
78
+ tag: /^035$/u
79
+ }
80
+ ];
81
+
82
+ try {
83
+ validatorFactory(config);
84
+ } catch (error) {
85
+ expect(error).to.be.an('error').with.property('message', 'Configuration not valid - excluded element');
86
+ }
87
+ });
88
+
89
+ it('Throws an error when config subfields not object', () => {
90
+ const config = [
91
+ {
92
+ tag: /^001$/u,
93
+ valuePattern: /\d+/u
94
+ }, {
95
+ tag: /^245$/u,
96
+ strict: true,
97
+ subfields: 'This should be Object'
98
+ }
99
+ ];
100
+
101
+ try {
102
+ validatorFactory(config);
103
+ } catch (error) {
104
+ expect(error).to.be.an('error').with.property('message', 'Configuration not valid - subfields not object');
105
+ }
106
+ });
107
+ });
108
+
109
+ it('Should find the record valid because no fields match the config', async () => {
110
+ const config = [
111
+ {
112
+ tag: /^FOO$/u,
113
+ valuePattern: /bar/u
114
+ }
115
+ ];
116
+
117
+ const record = new MarcRecord({
118
+ leader: '',
119
+ fields: [
120
+ {
121
+ tag: '001',
122
+ value: '123456'
123
+ }
124
+ ]
125
+ });
126
+
127
+ const validator = await validatorFactory(config);
128
+ const result = await validator.validate(record);
129
+
130
+ expect(result).to.eql({valid: true});
131
+ });
132
+
133
+ // Indicators and subfields validation
134
+ describe('#validate: Indicators and subfields', () => {
135
+ const config = [
136
+ {
137
+ tag: /^035$/u,
138
+ ind1: /^0$/u,
139
+ ind2: /^1$/u
140
+ }, {
141
+ tag: /^100$/u,
142
+ subfields: {
143
+ a: {maxOccurrence: 1}
144
+ }
145
+ }
146
+ ];
147
+
148
+ const recordValid = new MarcRecord({
149
+ leader: '',
150
+ fields: [
151
+ {
152
+ tag: '001',
153
+ value: '123456'
154
+ }, {
155
+ tag: '035',
156
+ ind1: '0',
157
+ ind2: '1',
158
+ subfields: [
159
+ {
160
+ code: 'a',
161
+ value: 'foo'
162
+ }
163
+ ]
164
+ }, {
165
+ tag: '100',
166
+ ind1: ' ',
167
+ ind2: ' ',
168
+ subfields: [
169
+ {
170
+ code: 'a',
171
+ value: 'bar'
172
+ }, {
173
+ code: 'b',
174
+ value: 'fubar'
175
+ }
176
+ ]
177
+ }
178
+ ]
179
+ });
180
+
181
+ const recordInvalidMany = new MarcRecord({
182
+ leader: '',
183
+ fields: [
184
+ {
185
+ tag: '001',
186
+ value: '123456'
187
+ }, {
188
+ tag: '035',
189
+ ind1: '1',
190
+ ind2: '1',
191
+ subfields: [
192
+ {
193
+ code: 'a',
194
+ value: 'foo'
195
+ }
196
+ ]
197
+ }, {
198
+ tag: '100',
199
+ ind1: ' ',
200
+ ind2: ' ',
201
+ subfields: [
202
+ {
203
+ code: 'a',
204
+ value: 'bar'
205
+ }, {
206
+ code: 'b',
207
+ value: 'fubar'
208
+ }, {
209
+ code: 'a',
210
+ value: 'barfoo'
211
+ }
212
+ ]
213
+ }
214
+ ]
215
+ });
216
+
217
+ it('Finds the record valid', async () => {
218
+ const validator = await validatorFactory(config);
219
+ const result = await validator.validate(recordValid);
220
+
221
+ expect(result).to.eql({valid: true});
222
+ });
223
+
224
+ it('Finds the record invalid: Too many subfields', async () => {
225
+ const validator = await validatorFactory(config);
226
+ const result = await validator.validate(recordInvalidMany);
227
+
228
+ expect(result).to.eql({valid: false});
229
+ });
230
+ });
231
+
232
+ // Patterns and mandatory & strict subfields
233
+ describe('#validate: Patterns and mandatory & strict subfields', () => {
234
+ const config = [
235
+ {
236
+ tag: /^001$/u,
237
+ valuePattern: /\d+/u
238
+ }, {
239
+ tag: /^245$/u,
240
+ strict: true,
241
+ subfields: {
242
+ a: {required: true, maxOccurrence: 1, pattern: /\w+/u},
243
+ b: {maxOccurrence: 1, pattern: /\w+/u}
244
+ }
245
+ }
246
+ ];
247
+
248
+ const recordValid = new MarcRecord({
249
+ leader: '',
250
+ fields: [
251
+ {
252
+ tag: '001',
253
+ value: '123456'
254
+ }, {
255
+ tag: '100',
256
+ ind1: ' ',
257
+ ind2: ' ',
258
+ subfields: [
259
+ {
260
+ code: 'a',
261
+ value: 'bar'
262
+ }
263
+ ]
264
+ }, {
265
+ tag: '245',
266
+ ind1: ' ',
267
+ ind2: ' ',
268
+ subfields: [
269
+ {
270
+ code: 'a',
271
+ value: 'foo'
272
+ }, {
273
+ code: 'b',
274
+ value: 'bar'
275
+ }
276
+ ]
277
+ }
278
+ ]
279
+ });
280
+
281
+ const recordInvalidExtra = new MarcRecord({
282
+ leader: '',
283
+ fields: [
284
+ {
285
+ tag: '001',
286
+ value: '123456a'
287
+ }, {
288
+ tag: '100',
289
+ ind1: ' ',
290
+ ind2: ' ',
291
+ subfields: [
292
+ {
293
+ code: 'a',
294
+ value: 'bar'
295
+ }
296
+ ]
297
+ }, {
298
+ tag: '245',
299
+ ind1: ' ',
300
+ ind2: ' ',
301
+ subfields: [
302
+ {
303
+ code: 'a',
304
+ value: 'foo'
305
+ }, {
306
+ code: 'b',
307
+ value: 'bar'
308
+ }, {
309
+ code: 'c',
310
+ value: 'fubar'
311
+ }
312
+ ]
313
+ }
314
+ ]
315
+ });
316
+
317
+ const recordInvalidTooMany = new MarcRecord({
318
+ leader: '',
319
+ fields: [
320
+ {
321
+ tag: '001',
322
+ value: '123456a'
323
+ }, {
324
+ tag: '100',
325
+ ind1: ' ',
326
+ ind2: ' ',
327
+ subfields: [
328
+ {
329
+ code: 'a',
330
+ value: 'bar'
331
+ }
332
+ ]
333
+ }, {
334
+ tag: '245',
335
+ ind1: ' ',
336
+ ind2: ' ',
337
+ subfields: [
338
+ {
339
+ code: 'a',
340
+ value: 'foo'
341
+ }, {
342
+ code: 'b',
343
+ value: 'bar'
344
+ }, {
345
+ code: 'a',
346
+ value: 'fubar'
347
+ }
348
+ ]
349
+ }
350
+ ]
351
+ });
352
+
353
+ const recordInvalidRegExp = new MarcRecord({
354
+ leader: '',
355
+ fields: [
356
+ {
357
+ tag: '001',
358
+ value: '123456a'
359
+ }, {
360
+ tag: '100',
361
+ ind1: ' ',
362
+ ind2: ' ',
363
+ subfields: [
364
+ {
365
+ code: 'a',
366
+ value: 'bar'
367
+ }
368
+ ]
369
+ }, {
370
+ tag: '245',
371
+ ind1: ' ',
372
+ ind2: ' ',
373
+ subfields: [
374
+ {
375
+ code: 'a',
376
+ value: 'ää'
377
+ }, {
378
+ code: 'b',
379
+ value: 'bar'
380
+ }
381
+ ]
382
+ }
383
+ ]
384
+ });
385
+
386
+ const recordInvalidMissing = new MarcRecord({
387
+ leader: '',
388
+ fields: [
389
+ {
390
+ tag: '100',
391
+ ind1: ' ',
392
+ ind2: ' ',
393
+ subfields: [
394
+ {
395
+ code: 'a',
396
+ value: 'bar'
397
+ }
398
+ ]
399
+ }, {
400
+ tag: '245',
401
+ ind1: ' ',
402
+ ind2: ' ',
403
+ subfields: [
404
+ {
405
+ code: 'a',
406
+ value: 'ää'
407
+ }, {
408
+ code: 'b',
409
+ value: 'bar'
410
+ }
411
+ ]
412
+ }
413
+ ]
414
+ });
415
+
416
+ const recordInvalidMissingSubfield = new MarcRecord({
417
+ leader: '',
418
+ fields: [
419
+ {
420
+ tag: '001',
421
+ value: '123456'
422
+ }, {
423
+ tag: '100',
424
+ ind1: ' ',
425
+ ind2: ' ',
426
+ subfields: [
427
+ {
428
+ code: 'a',
429
+ value: 'bar'
430
+ }
431
+ ]
432
+ }, {
433
+ tag: '245',
434
+ ind1: ' ',
435
+ ind2: ' ',
436
+ subfields: [
437
+ {
438
+ code: 'b',
439
+ value: 'bar'
440
+ }
441
+ ]
442
+ }
443
+ ]
444
+ });
445
+
446
+ it('Finds the record valid', async () => {
447
+ const validator = await validatorFactory(config);
448
+ const result = await validator.validate(recordValid);
449
+
450
+ expect(result).to.eql({valid: true});
451
+ });
452
+
453
+ it('Finds the record invalid: Extra field in strict', async () => {
454
+ const validator = await validatorFactory(config);
455
+ const result = await validator.validate(recordInvalidExtra);
456
+
457
+ expect(result).to.eql({valid: false});
458
+ });
459
+
460
+ it('Finds the record invalid: Too many occurances', async () => {
461
+ const validator = await validatorFactory(config);
462
+ const result = await validator.validate(recordInvalidTooMany);
463
+
464
+ expect(result).to.eql({valid: false});
465
+ });
466
+
467
+ it('Finds the record invalid: Invalid RegExp', async () => {
468
+ const validator = await validatorFactory(config);
469
+ const result = await validator.validate(recordInvalidRegExp);
470
+
471
+ expect(result).to.eql({valid: false});
472
+ });
473
+
474
+ it('Finds the record invalid: Missing field', async () => {
475
+ const validator = await validatorFactory(config);
476
+ const result = await validator.validate(recordInvalidMissing);
477
+
478
+ expect(result).to.eql({valid: false});
479
+ });
480
+ it('Finds the record invalid: Missing subfield', async () => {
481
+ const validator = await validatorFactory(config);
482
+ const result = await validator.validate(recordInvalidMissingSubfield);
483
+
484
+ expect(result).to.eql({valid: false});
485
+ });
486
+ });
487
+
488
+ // Dependencies
489
+ describe('#validate: Dependencies', () => {
490
+ const config = [
491
+ {
492
+ leader: /^.{6}s/u,
493
+ dependencies: [
494
+ {
495
+ tag: /^773$/u,
496
+ subfields: {7: /^nnas$/u}
497
+ }
498
+ ]
499
+ }
500
+ ];
501
+
502
+ const recordValid = new MarcRecord({
503
+ leader: '63ab75sfoo122myhgh',
504
+ fields: [
505
+ {
506
+ tag: '001',
507
+ value: '123456'
508
+ }, {
509
+ tag: '245',
510
+ ind1: ' ',
511
+ ind2: ' ',
512
+ subfields: [
513
+ {
514
+ code: 'a',
515
+ value: 'foo'
516
+ }
517
+ ]
518
+ }, {
519
+ tag: '773',
520
+ ind1: ' ',
521
+ ind2: ' ',
522
+ subfields: [
523
+ {
524
+ code: '7',
525
+ value: 'nnas'
526
+ }, {
527
+ code: 'w',
528
+ value: '789101112'
529
+ }
530
+ ]
531
+ }
532
+ ]
533
+ });
534
+
535
+ const recordInvalid = new MarcRecord({
536
+ leader: '63ab75afoo122myhgh',
537
+ fields: [
538
+ {
539
+ tag: '001',
540
+ value: '123456'
541
+ }, {
542
+ tag: '245',
543
+ ind1: ' ',
544
+ ind2: ' ',
545
+ subfields: [
546
+ {
547
+ code: 'a',
548
+ value: 'foo'
549
+ }
550
+ ]
551
+ }, {
552
+ tag: '773',
553
+ ind1: ' ',
554
+ ind2: ' ',
555
+ subfields: [
556
+ {
557
+ code: '7',
558
+ value: 'nnas'
559
+ }, {
560
+ code: 'w',
561
+ value: '789101112'
562
+ }
563
+ ]
564
+ }
565
+ ]
566
+ });
567
+
568
+ it('Finds the record valid', async () => {
569
+ const validator = await validatorFactory(config);
570
+ const result = await validator.validate(recordValid);
571
+
572
+ expect(result).to.eql({valid: true});
573
+ });
574
+
575
+ it('Finds the record invalid', async () => {
576
+ const validator = await validatorFactory(config);
577
+ const result = await validator.validate(recordInvalid);
578
+
579
+ expect(result).to.eql({valid: false});
580
+ });
581
+
582
+ it('Find the record valid (Dependency on leader)', async () => {
583
+ const validator = await validatorFactory([{tag: /^007$/u, dependencies: [{leader: /^.{6}[at]/u}]}]);
584
+ const result = await validator.validate(new MarcRecord({
585
+ leader: '00000ccm^a22003372i^4500',
586
+ fields: [
587
+ {tag: '001', value: '123456'},
588
+ {tag: '245', value: 'foobar'}
589
+ ]
590
+ }));
591
+
592
+ expect(result).to.eql({valid: true});
593
+ });
594
+
595
+ it('Find the record invalid (Dependency on leader)', async () => {
596
+ const validator = await validatorFactory([{tag: /^007$/u, dependencies: [{leader: /^.{6}[at]/u}]}]);
597
+ const result = await validator.validate(new MarcRecord({
598
+ leader: '00000cam^a22003372i^4500',
599
+ fields: [
600
+ {tag: '001', value: '123456'},
601
+ {tag: '245', value: 'foobar'}
602
+ ]
603
+ }));
604
+
605
+ expect(result).to.eql({valid: false});
606
+ });
607
+ });
485
608
  });