@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,28 +1,140 @@
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
- *//* eslint-disable no-undef, max-nested-callbacks, no-unused-expressions */'use strict';var _chai=require('chai');var _chai2=_interopRequireDefault(_chai);var _chaiAsPromised=require('chai-as-promised');var _chaiAsPromised2=_interopRequireDefault(_chaiAsPromised);var _marcRecord=require('@natlibfi/marc-record');var _fixedFields=require('../src/fixed-fields');var _fixedFields2=_interopRequireDefault(_fixedFields);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _asyncToGenerator(fn){return function(){var gen=fn.apply(this,arguments);return new Promise(function(resolve,reject){function step(key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{return Promise.resolve(value).then(function(value){step('next',value)},function(err){step('throw',err)})}}return step('next')})}}const{expect}=_chai2.default;_chai2.default.use(_chaiAsPromised2.default);describe('language',()=>{it('Creates a validator',_asyncToGenerator(function*(){const validator=yield(0,_fixedFields2.default)([]);expect(validator).to.be.an('object').that.has.any.keys('description','validate');expect(validator.description).to.be.a('string');expect(validator.validate).to.be.a('function')}));it('Throws an error when configuration is not provided',_asyncToGenerator(function*(){yield expect((0,_fixedFields2.default)()).to.be.rejectedWith(Error,'No configuration provided')}));describe('#validate',()=>{it('Finds the record valid',_asyncToGenerator(function*(){const validator=yield(0,_fixedFields2.default)([{leader:true,length:6,rules:[{position:[0,6],pattern:/[abcdefg]/}]},{tag:/^FOO$/,length:12,rules:[{position:0,pattern:/f/}]},{tag:/^BAR$/,length:6,rules:[{position:0,pattern:/[fb]/},{position:1,pattern:/a/,dependencies:[{position:0,pattern:/b/}]},{position:[2,3],pattern:/u/,dependencies:[{position:0,pattern:/[^b]/}]}]}]);const record=new _marcRecord.MarcRecord({leader:'bacgfe',fields:[{tag:'FOO',value:'foobarfoobar'},{tag:'BAR',value:'bauuoo'}]});const result=yield validator.validate(record);expect(result).to.be.an('object').and.to.include({valid:true})}));it('Finds the record invalid',_asyncToGenerator(function*(){const validator=yield(0,_fixedFields2.default)([{leader:true,length:6,rules:[{position:[0,6],pattern:/[abcdefg]/}]},{tag:/^FOO$/,length:12,rules:[{position:0,pattern:/f/}]},{tag:/^BAR$/,length:6,rules:[{position:0,pattern:/[fb]/},{position:1,pattern:/a/,dependencies:[{position:0,pattern:/b/}]},{position:[2,3],pattern:/u/,dependencies:[{position:0,pattern:/[^a]/}]}]},{tag:/^FUBAR$/,length:5}]);const record=new _marcRecord.MarcRecord({leader:'bacxfe',fields:[{tag:'FOO',value:'barfoofoobar'},{tag:'BAR',value:'burfoo'},{tag:'FUBAR',value:'foo'}]});const result=yield validator.validate(record);expect(result).to.eql({valid:false,messages:['Leader has invalid values at positions: 3 (Rule index 0)','Field FOO has invalid values at positions: 0 (Rule index 0)','Field BAR has invalid values at positions: 1 (Rule index 1)','Field BAR has invalid values at positions: 2,3 (Rule index 2)','Field FUBAR has invalid length']})}))})});
1
+ "use strict";
2
+
3
+ var _chai = _interopRequireDefault(require("chai"));
4
+ var _chaiAsPromised = _interopRequireDefault(require("chai-as-promised"));
5
+ var _marcRecord = require("@natlibfi/marc-record");
6
+ var _fixedFields = _interopRequireDefault(require("../src/fixed-fields"));
7
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+ const {
9
+ expect
10
+ } = _chai.default;
11
+ _chai.default.use(_chaiAsPromised.default);
12
+ describe('fixed-fields: language', () => {
13
+ it('Creates a validator', async () => {
14
+ const validator = await (0, _fixedFields.default)([]);
15
+ expect(validator).to.be.an('object').that.has.any.keys('description', 'validate');
16
+ expect(validator.description).to.be.a('string');
17
+ expect(validator.validate).to.be.a('function');
18
+ });
19
+ it('Throws an error when configuration is not provided', () => {
20
+ try {
21
+ (0, _fixedFields.default)();
22
+ } catch (error) {
23
+ expect(error).to.be.an('error').with.property('message', 'No configuration provided');
24
+ }
25
+ });
26
+ describe('#validate', () => {
27
+ it('Finds the record valid', async () => {
28
+ const validator = await (0, _fixedFields.default)([{
29
+ leader: true,
30
+ length: 6,
31
+ rules: [{
32
+ position: [0, 6],
33
+ pattern: /[abcdefg]/u
34
+ }]
35
+ }, {
36
+ tag: /^FOO$/u,
37
+ length: 12,
38
+ rules: [{
39
+ position: 0,
40
+ pattern: /f/u
41
+ }]
42
+ }, {
43
+ tag: /^BAR$/u,
44
+ length: 6,
45
+ rules: [{
46
+ position: 0,
47
+ pattern: /[fb]/u
48
+ }, {
49
+ position: 1,
50
+ pattern: /a/u,
51
+ dependencies: [{
52
+ position: 0,
53
+ pattern: /b/u
54
+ }]
55
+ }, {
56
+ position: [2, 3],
57
+ pattern: /u/u,
58
+ dependencies: [{
59
+ position: 0,
60
+ pattern: /[^b]/u
61
+ }]
62
+ }]
63
+ }]);
64
+ const record = new _marcRecord.MarcRecord({
65
+ leader: 'bacgfe',
66
+ fields: [{
67
+ tag: 'FOO',
68
+ value: 'foobarfoobar'
69
+ }, {
70
+ tag: 'BAR',
71
+ value: 'bauuoo'
72
+ }]
73
+ });
74
+ const result = await validator.validate(record);
75
+ expect(result).to.be.an('object').and.to.include({
76
+ valid: true
77
+ });
78
+ });
79
+ it('Finds the record invalid', async () => {
80
+ const validator = await (0, _fixedFields.default)([{
81
+ leader: true,
82
+ length: 6,
83
+ rules: [{
84
+ position: [0, 6],
85
+ pattern: /[abcdefg]/u
86
+ }]
87
+ }, {
88
+ tag: /^FOO$/u,
89
+ length: 12,
90
+ rules: [{
91
+ position: 0,
92
+ pattern: /f/u
93
+ }]
94
+ }, {
95
+ tag: /^BAR$/u,
96
+ length: 6,
97
+ rules: [{
98
+ position: 0,
99
+ pattern: /[fb]/u
100
+ }, {
101
+ position: 1,
102
+ pattern: /a/u,
103
+ dependencies: [{
104
+ position: 0,
105
+ pattern: /b/u
106
+ }]
107
+ }, {
108
+ position: [2, 3],
109
+ pattern: /u/u,
110
+ dependencies: [{
111
+ position: 0,
112
+ pattern: /[^a]/u
113
+ }]
114
+ }]
115
+ }, {
116
+ tag: /^FUBAR$/u,
117
+ length: 5
118
+ }]);
119
+ const record = new _marcRecord.MarcRecord({
120
+ leader: 'bacxfe',
121
+ fields: [{
122
+ tag: 'FOO',
123
+ value: 'barfoofoobar'
124
+ }, {
125
+ tag: 'BAR',
126
+ value: 'burfoo'
127
+ }, {
128
+ tag: 'FUBAR',
129
+ value: 'foo'
130
+ }]
131
+ });
132
+ const result = await validator.validate(record);
133
+ expect(result).to.eql({
134
+ valid: false,
135
+ messages: ['Leader has invalid values at positions: 3 (Rule index 0)', 'Field FOO has invalid values at positions: 0 (Rule index 0)', 'Field BAR has invalid values at positions: 1 (Rule index 1)', 'Field BAR has invalid values at positions: 2,3 (Rule index 2)', 'Field FUBAR has invalid length']
136
+ });
137
+ });
138
+ });
139
+ });
28
140
  //# sourceMappingURL=fixed-fields.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/fixed-fields.spec.js"],"names":["expect","chai","use","chaiAsPromised","describe","it","validator","to","be","an","that","has","any","keys","description","a","validate","rejectedWith","Error","leader","length","rules","position","pattern","tag","dependencies","record","MarcRecord","fields","value","result","and","include","valid","eql","messages"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BA,0EAEA,aAE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AACH,SAAU,CAAX,CAAcC,QAAS,GAAvB,CADyC,CAA1C,CAFgC,CAKhC,CAACD,SAAU,CAAC,CAAD,CAAI,CAAJ,CAAX,CAAmBC,QAAS,GAA5B,CAAiCE,aAAc,CAC9C,CAACH,SAAU,CAAX,CAAcC,QAAS,MAAvB,CAD8C,CAA/C,CALgC,CAAjC,CAPwC,CAgBxC,CAACC,IAAK,SAAN,CAAiBJ,OAAQ,CAAzB,CAhBwC,CAAjB,CAAxB,CAkBA,KAAMM,QAAS,GAAIC,uBAAJ,CAAe,CAC7BR,OAAQ,QADqB,CAE7BS,OAAQ,CACP,CACCJ,IAAK,KADN,CAECK,MAAO,cAFR,CADO,CAKP,CACCL,IAAK,KADN,CAECK,MAAO,QAFR,CALO,CASP,CACCL,IAAK,OADN,CAECK,MAAO,KAFR,CATO,CAFqB,CAAf,CAAf,CAkBA,KAAMC,QAAS,KAAMxB,WAAUU,QAAV,CAAmBU,MAAnB,CAArB,CAEA1B,OAAO8B,MAAP,EAAevB,EAAf,CAAkB2B,GAAlB,CAAsB,CAACD,MAAO,KAAR,CAAeE,SAAU,CAC9C,0DAD8C,CAE9C,6DAF8C,CAG9C,6DAH8C,CAI9C,+DAJ8C,CAK9C,gCAL8C,CAAzB,CAAtB,CAOA,CA9CD,EA+CA,CApFD,CAqFA,CArGD","file":"fixed-fields.spec.js","sourcesContent":["/**\n *\n * @licstart The following is the entire license notice for the JavaScript code in this file.\n *\n * MARC record validators used in Melinda\n *\n * Copyright (C) 2014-2018 University Of Helsinki (The National Library Of Finland)\n *\n * This file is part of marc-record-validators-melinda\n *\n * marc-record-validators-melinda program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * marc-record-validators-melinda is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n *\n * @licend The above is the entire license notice\n * for the JavaScript code in this file.\n *\n */\n\n/* eslint-disable no-undef, max-nested-callbacks, no-unused-expressions */\n\n'use strict';\n\nimport chai from 'chai';\nimport chaiAsPromised from 'chai-as-promised';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport validatorFactory from '../src/fixed-fields';\n\nconst {expect} = chai;\nchai.use(chaiAsPromised);\n\ndescribe('language', () => {\n\tit('Creates a validator', async () => {\n\t\tconst validator = await validatorFactory([]);\n\n\t\texpect(validator)\n\t\t\t.to.be.an('object')\n\t\t\t.that.has.any.keys('description', 'validate');\n\n\t\texpect(validator.description).to.be.a('string');\n\t\texpect(validator.validate).to.be.a('function');\n\t});\n\n\tit('Throws an error when configuration is not provided', async () => {\n\t\tawait expect(validatorFactory()).to.be.rejectedWith(Error, 'No configuration provided');\n\t});\n\n\tdescribe('#validate', () => {\n\t\tit('Finds the record valid', async () => {\n\t\t\tconst validator = await validatorFactory([\n\t\t\t\t{leader: true, length: 6, rules: [\n\t\t\t\t\t{position: [0, 6], pattern: /[abcdefg]/}\n\t\t\t\t]},\n\t\t\t\t{tag: /^FOO$/, length: 12, rules: [\n\t\t\t\t\t{position: 0, pattern: /f/}\n\t\t\t\t]},\n\t\t\t\t{tag: /^BAR$/, length: 6, rules: [\n\t\t\t\t\t{position: 0, pattern: /[fb]/},\n\t\t\t\t\t{position: 1, pattern: /a/, dependencies: [\n\t\t\t\t\t\t{position: 0, pattern: /b/}\n\t\t\t\t\t]},\n\t\t\t\t\t{position: [2, 3], pattern: /u/, dependencies: [\n\t\t\t\t\t\t{position: 0, pattern: /[^b]/}\n\t\t\t\t\t]}\n\t\t\t\t]}\n\t\t\t]);\n\t\t\tconst record = new MarcRecord({\n\t\t\t\tleader: 'bacgfe',\n\t\t\t\tfields: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: 'FOO',\n\t\t\t\t\t\tvalue: 'foobarfoobar'\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: 'BAR',\n\t\t\t\t\t\tvalue: 'bauuoo'\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t});\n\t\t\tconst result = await validator.validate(record);\n\n\t\t\texpect(result).to.be.an('object').and.to.include({valid: true});\n\t\t});\n\n\t\tit('Finds the record invalid', async () => {\n\t\t\tconst validator = await validatorFactory([\n\t\t\t\t{leader: true, length: 6, rules: [\n\t\t\t\t\t{position: [0, 6], pattern: /[abcdefg]/}\n\t\t\t\t]},\n\t\t\t\t{tag: /^FOO$/, length: 12, rules: [\n\t\t\t\t\t{position: 0, pattern: /f/}\n\t\t\t\t]},\n\t\t\t\t{tag: /^BAR$/, length: 6, rules: [\n\t\t\t\t\t{position: 0, pattern: /[fb]/},\n\t\t\t\t\t{position: 1, pattern: /a/, dependencies: [\n\t\t\t\t\t\t{position: 0, pattern: /b/}\n\t\t\t\t\t]},\n\t\t\t\t\t{position: [2, 3], pattern: /u/, dependencies: [\n\t\t\t\t\t\t{position: 0, pattern: /[^a]/}\n\t\t\t\t\t]}\n\t\t\t\t]},\n\t\t\t\t{tag: /^FUBAR$/, length: 5}\n\t\t\t]);\n\t\t\tconst record = new MarcRecord({\n\t\t\t\tleader: 'bacxfe',\n\t\t\t\tfields: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: 'FOO',\n\t\t\t\t\t\tvalue: 'barfoofoobar'\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: 'BAR',\n\t\t\t\t\t\tvalue: 'burfoo'\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: 'FUBAR',\n\t\t\t\t\t\tvalue: 'foo'\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t});\n\n\t\t\tconst result = await validator.validate(record);\n\n\t\t\texpect(result).to.eql({valid: false, messages: [\n\t\t\t\t'Leader has invalid values at positions: 3 (Rule index 0)',\n\t\t\t\t'Field FOO has invalid values at positions: 0 (Rule index 0)',\n\t\t\t\t'Field BAR has invalid values at positions: 1 (Rule index 1)',\n\t\t\t\t'Field BAR has invalid values at positions: 2,3 (Rule index 2)',\n\t\t\t\t'Field FUBAR has invalid length'\n\t\t\t]});\n\t\t});\n\t});\n});\n"]}
1
+ {"version":3,"file":"fixed-fields.spec.js","names":["_chai","_interopRequireDefault","require","_chaiAsPromised","_marcRecord","_fixedFields","obj","__esModule","default","expect","chai","use","chaiAsPromised","describe","it","validator","validatorFactory","to","be","an","that","has","any","keys","description","a","validate","error","with","property","leader","length","rules","position","pattern","tag","dependencies","record","MarcRecord","fields","value","result","and","include","valid","eql","messages"],"sources":["../src/fixed-fields.spec.js"],"sourcesContent":["import chai from 'chai';\nimport chaiAsPromised from 'chai-as-promised';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport validatorFactory from '../src/fixed-fields';\n\nconst {expect} = chai;\nchai.use(chaiAsPromised);\n\ndescribe('fixed-fields: language', () => {\n it('Creates a validator', async () => {\n const validator = await validatorFactory([]);\n\n expect(validator)\n .to.be.an('object')\n .that.has.any.keys('description', 'validate');\n\n expect(validator.description).to.be.a('string');\n expect(validator.validate).to.be.a('function');\n });\n\n it('Throws an error when configuration is not provided', () => {\n try {\n validatorFactory();\n } catch (error) {\n expect(error).to.be.an('error').with.property('message', 'No configuration provided');\n }\n });\n\n describe('#validate', () => {\n it('Finds the record valid', async () => {\n const validator = await validatorFactory([\n {leader: true, length: 6, rules: [{position: [0, 6], pattern: /[abcdefg]/u}]},\n {tag: /^FOO$/u, length: 12, rules: [{position: 0, pattern: /f/u}]},\n {tag: /^BAR$/u, length: 6, rules: [\n {position: 0, pattern: /[fb]/u},\n {position: 1, pattern: /a/u, dependencies: [{position: 0, pattern: /b/u}]},\n {position: [2, 3], pattern: /u/u, dependencies: [{position: 0, pattern: /[^b]/u}]}\n ]}\n ]);\n const record = new MarcRecord({\n leader: 'bacgfe',\n fields: [\n {\n tag: 'FOO',\n value: 'foobarfoobar'\n },\n {\n tag: 'BAR',\n value: 'bauuoo'\n }\n ]\n });\n const result = await validator.validate(record);\n\n expect(result).to.be.an('object').and.to.include({valid: true});\n });\n\n it('Finds the record invalid', async () => {\n const validator = await validatorFactory([\n {leader: true, length: 6, rules: [{position: [0, 6], pattern: /[abcdefg]/u}]},\n {tag: /^FOO$/u, length: 12, rules: [{position: 0, pattern: /f/u}]},\n {tag: /^BAR$/u, length: 6, rules: [\n {position: 0, pattern: /[fb]/u},\n {position: 1, pattern: /a/u, dependencies: [{position: 0, pattern: /b/u}]},\n {position: [2, 3], pattern: /u/u, dependencies: [{position: 0, pattern: /[^a]/u}]}\n ]},\n {tag: /^FUBAR$/u, length: 5}\n ]);\n const record = new MarcRecord({\n leader: 'bacxfe',\n fields: [\n {\n tag: 'FOO',\n value: 'barfoofoobar'\n },\n {\n tag: 'BAR',\n value: 'burfoo'\n },\n {\n tag: 'FUBAR',\n value: 'foo'\n }\n ]\n });\n\n const result = await validator.validate(record);\n\n expect(result).to.eql({valid: false, messages: [\n 'Leader has invalid values at positions: 3 (Rule index 0)',\n 'Field FOO has invalid values at positions: 0 (Rule index 0)',\n 'Field BAR has invalid values at positions: 1 (Rule index 1)',\n 'Field BAR has invalid values at positions: 2,3 (Rule index 2)',\n 'Field FUBAR has invalid length'\n ]});\n });\n });\n});\n"],"mappings":";;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,eAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAAmD,SAAAD,uBAAAK,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEnD,MAAM;EAACG;AAAM,CAAC,GAAGC,aAAI;AACrBA,aAAI,CAACC,GAAG,CAACC,uBAAc,CAAC;AAExBC,Q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C7C,0DAA0D,EAC1D,6DAA6D,EAC7D,6DAA6D,EAC7D,+DAA+D,EAC/D,gCAAgC;MACjC,CAAC,CAAC;IACL,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -1,30 +1,44 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var _lodash=require('lodash');function _asyncToGenerator(fn){return function(){var gen=fn.apply(this,arguments);return new Promise(function(resolve,reject){function step(key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{return Promise.resolve(value).then(function(value){step('next',value)},function(err){step('throw',err)})}}return step('next')})}}/**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * Melinda-related validators for @natlibfi/marc-record-validate
6
- *
7
- * Copyright (c) 2014-2017 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 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
- * This program 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
- **//**
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+ var _marcRecord = require("@natlibfi/marc-record");
8
+ /**
28
9
  * This validator de-duplicates identical fields in a record.
29
- *//* eslint-disable require-await */exports.default=_asyncToGenerator(function*(){let validate=(()=>{var _ref2=_asyncToGenerator(function*(record){const uniq=(0,_lodash.uniqWith)(record.fields,_lodash.isEqual);const valid=uniq.length===record.fields.length;const messages=record.fields.filter(function(tag){return!uniq.includes(tag)}).map(function(obj){return`Field ${obj.tag} has duplicates`});return valid?{valid,messages:[]}:{valid,messages}});return function validate(_x){return _ref2.apply(this,arguments)}})();let fix=(()=>{var _ref3=_asyncToGenerator(function*(record){record.fields.filter(function(tag){return!(0,_lodash.uniqWith)(record.fields,_lodash.isEqual).includes(tag)}).forEach(function(tag){return record.removeField(tag)})});return function fix(_x2){return _ref3.apply(this,arguments)}})();return{description:'Handles identical duplicate in record fields',validate,fix}});
10
+ */
11
+
12
+ function _default() {
13
+ return {
14
+ description: 'Handles identical duplicate in record fields',
15
+ validate,
16
+ fix
17
+ };
18
+ function validate(record) {
19
+ const uniq = uniqWith(record.fields);
20
+ const valid = uniq.length === record.fields.length;
21
+ const messages = record.fields.filter(tag => !uniq.includes(tag)).map(obj => `Field ${obj.tag} has duplicates`);
22
+ return valid ? {
23
+ valid,
24
+ messages: []
25
+ } : {
26
+ valid,
27
+ messages
28
+ };
29
+ }
30
+ function fix(record) {
31
+ record.fields.filter(tag => !uniqWith(record.fields).includes(tag)).forEach(tag => record.removeField(tag));
32
+ }
33
+ function uniqWith(fields) {
34
+ return fields.reduce((uniq, field) => {
35
+ if (!uniq.some(f => _marcRecord.MarcRecord.isEqual(f, field))) {
36
+ // eslint-disable-line functional/no-conditional-statements
37
+ uniq.push(field); // eslint-disable-line functional/immutable-data
38
+ }
39
+
40
+ return uniq;
41
+ }, []);
42
+ }
43
+ }
30
44
  //# sourceMappingURL=identical-fields.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/identical-fields.js"],"names":["record","uniq","fields","isEqual","valid","length","messages","filter","includes","tag","map","obj","validate","forEach","removeField","fix","description"],"mappings":"sEAiCA,8B,0YAjCA;;;;;;;;;;;;;;;;;;;;;;;;;;IA4BA;;GAIA,kC,kCAGe,WAAkB,gDAOhC,UAAwBA,MAAxB,CAAgC,CAC/B,KAAMC,MAAO,qBAASD,OAAOE,MAAhB,CAAwBC,eAAxB,CAAb,CACA,KAAMC,OAAQH,KAAKI,MAAL,GAAgBL,OAAOE,MAAP,CAAcG,MAA5C,CACA,KAAMC,UAAWN,OAAOE,MAAP,CAAcK,MAAd,CAAqB,oBAAO,CAACN,KAAKO,QAAL,CAAcC,GAAd,CAAR,CAArB,EACfC,GADe,CACX,oBAAQ,SAAQC,IAAIF,GAAI,iBAAxB,CADW,CAAjB,CAGA,MAAOL,OAAQ,CAACA,KAAD,CAAQE,SAAU,EAAlB,CAAR,CAAgC,CAACF,KAAD,CAAQE,QAAR,CACvC,CAd+B,iBAOjBM,SAPiB,uFAgBhC,UAAmBZ,MAAnB,CAA2B,CAC1BA,OAAOE,MAAP,CACEK,MADF,CACS,oBAAO,CAAC,qBAASP,OAAOE,MAAhB,CAAwBC,eAAxB,EAAiCK,QAAjC,CAA0CC,GAA1C,CAAR,CADT,EAEEI,OAFF,CAEU,oBAAOb,QAAOc,WAAP,CAAmBL,GAAnB,CAAP,CAFV,CAGA,CApB+B,iBAgBjBM,IAhBiB,8CAChC,MAAO,CACNC,YAAa,8CADP,CAENJ,QAFM,CAGNG,GAHM,CAoBP,C","file":"identical-fields.js","sourcesContent":["/**\n *\n * @licstart The following is the entire license notice for the JavaScript code in this file.\n *\n * Melinda-related validators for @natlibfi/marc-record-validate\n *\n * Copyright (c) 2014-2017 University Of Helsinki (The National Library Of Finland)\n *\n * This file is part of marc-record-validators-melinda\n *\n * marc-record-validators-melinda is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n *\n * @licend The above is the entire license notice\n * for the JavaScript code in this file.\n *\n **/\n\n/**\n * This validator de-duplicates identical fields in a record.\n */\n\n/* eslint-disable require-await */\nimport {isEqual, uniqWith} from 'lodash';\n\nexport default async function () {\n\treturn {\n\t\tdescription: 'Handles identical duplicate in record fields',\n\t\tvalidate,\n\t\tfix\n\t};\n\n\tasync function validate(record) {\n\t\tconst uniq = uniqWith(record.fields, isEqual);\n\t\tconst valid = uniq.length === record.fields.length;\n\t\tconst messages = record.fields.filter(tag => !uniq.includes(tag))\n\t\t\t.map(obj => `Field ${obj.tag} has duplicates`);\n\n\t\treturn valid ? {valid, messages: []} : {valid, messages};\n\t}\n\n\tasync function fix(record) {\n\t\trecord.fields\n\t\t\t.filter(tag => !uniqWith(record.fields, isEqual).includes(tag))\n\t\t\t.forEach(tag => record.removeField(tag));\n\t}\n}\n"]}
1
+ {"version":3,"file":"identical-fields.js","names":["_marcRecord","require","_default","description","validate","fix","record","uniq","uniqWith","fields","valid","length","messages","filter","tag","includes","map","obj","forEach","removeField","reduce","field","some","f","MarcRecord","isEqual","push"],"sources":["../src/identical-fields.js"],"sourcesContent":["/**\n * This validator de-duplicates identical fields in a record.\n */\n\nimport {MarcRecord} from '@natlibfi/marc-record';\n\nexport default function () {\n return {\n description: 'Handles identical duplicate in record fields',\n validate,\n fix\n };\n\n function validate(record) {\n const uniq = uniqWith(record.fields);\n const valid = uniq.length === record.fields.length;\n const messages = record.fields.filter(tag => !uniq.includes(tag))\n .map(obj => `Field ${obj.tag} has duplicates`);\n\n return valid ? {valid, messages: []} : {valid, messages};\n }\n\n function fix(record) {\n record.fields\n .filter(tag => !uniqWith(record.fields).includes(tag))\n .forEach(tag => record.removeField(tag));\n }\n\n function uniqWith(fields) {\n return fields.reduce((uniq, field) => {\n if (!uniq.some(f => MarcRecord.isEqual(f, field))) { // eslint-disable-line functional/no-conditional-statements\n uniq.push(field); // eslint-disable-line functional/immutable-data\n }\n\n return uniq;\n }, []);\n }\n}\n"],"mappings":";;;;;;AAIA,IAAAA,WAAA,GAAAC,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1,28 +1,99 @@
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
- *//* eslint-disable no-undef, max-nested-callbacks, no-unused-expressions */'use strict';var _chai=require('chai');var _marcRecord=require('@natlibfi/marc-record');var _identicalFields=require('../src/identical-fields');var _identicalFields2=_interopRequireDefault(_identicalFields);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _asyncToGenerator(fn){return function(){var gen=fn.apply(this,arguments);return new Promise(function(resolve,reject){function step(key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{return Promise.resolve(value).then(function(value){step('next',value)},function(err){step('throw',err)})}}return step('next')})}}describe('identical-fields',()=>{it('Creates a validator',_asyncToGenerator(function*(){const validator=yield(0,_identicalFields2.default)();(0,_chai.expect)(validator).to.be.an('object').that.has.any.keys('description','validate');(0,_chai.expect)(validator.description).to.be.a('string');(0,_chai.expect)(validator.validate).to.be.a('function')}));describe('#validate',()=>{it('Finds the record valid',_asyncToGenerator(function*(){const validator=yield(0,_identicalFields2.default)();const record=new _marcRecord.MarcRecord({fields:[{tag:'700',subfields:[{code:'e',value:'foo'}]}]});const result=yield validator.validate(record);(0,_chai.expect)(result).to.eql({valid:true,messages:[]})}));it('Finds the record invalid',_asyncToGenerator(function*(){const validator=yield(0,_identicalFields2.default)();const record=new _marcRecord.MarcRecord({fields:[{tag:'700',subfields:[{code:'e',value:'foo'}]},{tag:'800',subfields:[{code:'e',value:'foo'}]},{tag:'800',subfields:[{code:'e',value:'foo'}]},{tag:'700',subfields:[{code:'e',value:'foo'}]}]});const result=yield validator.validate(record);(0,_chai.expect)(result).to.eql({valid:false,messages:['Field 800 has duplicates','Field 700 has duplicates']})}))});describe('#fix',()=>{it('Fixes the record',_asyncToGenerator(function*(){const validator=yield(0,_identicalFields2.default)();const record=new _marcRecord.MarcRecord({fields:[{tag:'700',subfields:[{code:'e',value:'dest'}]},{tag:'700',subfields:[{code:'e',value:'dest'}]}]});yield validator.fix(record);(0,_chai.expect)(record.fields).to.eql([{tag:'700',ind1:' ',ind2:' ',subfields:[{code:'e',value:'dest'}]}])}))})});
1
+ "use strict";
2
+
3
+ var _chai = require("chai");
4
+ var _marcRecord = require("@natlibfi/marc-record");
5
+ var _identicalFields = _interopRequireDefault(require("../src/identical-fields"));
6
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
+ describe('identical-fields', () => {
8
+ it('Creates a validator', async () => {
9
+ const validator = await (0, _identicalFields.default)();
10
+ (0, _chai.expect)(validator).to.be.an('object').that.has.any.keys('description', 'validate');
11
+ (0, _chai.expect)(validator.description).to.be.a('string');
12
+ (0, _chai.expect)(validator.validate).to.be.a('function');
13
+ });
14
+ describe('#validate', () => {
15
+ it('Finds the record valid', async () => {
16
+ const validator = await (0, _identicalFields.default)();
17
+ const record = new _marcRecord.MarcRecord({
18
+ fields: [{
19
+ tag: '700',
20
+ subfields: [{
21
+ code: 'e',
22
+ value: 'foo'
23
+ }]
24
+ }]
25
+ });
26
+ const result = await validator.validate(record);
27
+ (0, _chai.expect)(result).to.eql({
28
+ valid: true,
29
+ messages: []
30
+ });
31
+ });
32
+ it('Finds the record invalid', async () => {
33
+ const validator = await (0, _identicalFields.default)();
34
+ const record = new _marcRecord.MarcRecord({
35
+ fields: [{
36
+ tag: '700',
37
+ subfields: [{
38
+ code: 'e',
39
+ value: 'foo'
40
+ }]
41
+ }, {
42
+ tag: '800',
43
+ subfields: [{
44
+ code: 'e',
45
+ value: 'foo'
46
+ }]
47
+ }, {
48
+ tag: '800',
49
+ subfields: [{
50
+ code: 'e',
51
+ value: 'foo'
52
+ }]
53
+ }, {
54
+ tag: '700',
55
+ subfields: [{
56
+ code: 'e',
57
+ value: 'foo'
58
+ }]
59
+ }]
60
+ });
61
+ const result = await validator.validate(record);
62
+ (0, _chai.expect)(result).to.eql({
63
+ valid: false,
64
+ messages: ['Field 800 has duplicates', 'Field 700 has duplicates']
65
+ });
66
+ });
67
+ });
68
+ describe('#fix', () => {
69
+ it('Fixes the record', async () => {
70
+ const validator = await (0, _identicalFields.default)();
71
+ const record = new _marcRecord.MarcRecord({
72
+ fields: [{
73
+ tag: '700',
74
+ subfields: [{
75
+ code: 'e',
76
+ value: 'dest'
77
+ }]
78
+ }, {
79
+ tag: '700',
80
+ subfields: [{
81
+ code: 'e',
82
+ value: 'dest'
83
+ }]
84
+ }]
85
+ });
86
+ await validator.fix(record);
87
+ (0, _chai.expect)(record.fields).to.eql([{
88
+ tag: '700',
89
+ ind1: ' ',
90
+ ind2: ' ',
91
+ subfields: [{
92
+ code: 'e',
93
+ value: 'dest'
94
+ }]
95
+ }]);
96
+ });
97
+ });
98
+ });
28
99
  //# sourceMappingURL=identical-fields.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/identical-fields.spec.js"],"names":["describe","it","validator","to","be","an","that","has","any","keys","description","a","validate","record","MarcRecord","fields","tag","subfields","code","value","result","eql","valid","messages","fix","ind1","ind2"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BA,0EAEA,aAEA,0BACA,iDACA,wD,2hBAEAA,SAAS,kBAAT,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,MAAO,KAFR,CADU,CAFZ,CAnBO,CA4BP,CACCH,IAAK,KADN,CAECC,UAAW,CACV,CACCC,KAAM,GADP,CAECC,MAAO,KAFR,CADU,CAFZ,CA5BO,CAFqB,CAAf,CAAf,CA0CA,KAAMC,QAAS,KAAMlB,WAAUU,QAAV,CAAmBC,MAAnB,CAArB,CAEA,iBAAOO,MAAP,EAAejB,EAAf,CAAkBkB,GAAlB,CAAsB,CAACC,MAAO,KAAR,CAAeC,SAAU,CAAC,0BAAD,CAA6B,0BAA7B,CAAzB,CAAtB,CACA,CA/CD,EAgDA,CApED,EAsEAvB,SAAS,MAAT,CAAiB,IAAM,CACtBC,GAAG,kBAAH,mBAAuB,WAAY,CAClC,KAAMC,WAAY,KAAM,+BAAxB,CACA,KAAMW,QAAS,GAAIC,uBAAJ,CAAe,CAC7BC,OAAQ,CACP,CACCC,IAAK,KADN,CAECC,UAAW,CACV,CACCC,KAAM,GADP,CAECC,MAAO,MAFR,CADU,CAFZ,CADO,CAUP,CACCH,IAAK,KADN,CAECC,UAAW,CACV,CACCC,KAAM,GADP,CAECC,MAAO,MAFR,CADU,CAFZ,CAVO,CADqB,CAAf,CAAf,CAsBA,KAAMjB,WAAUsB,GAAV,CAAcX,MAAd,CAAN,CAEA,iBAAOA,OAAOE,MAAd,EAAsBZ,EAAtB,CAAyBkB,GAAzB,CAA6B,CAC5B,CACCL,IAAK,KADN,CAECS,KAAM,GAFP,CAGCC,KAAM,GAHP,CAICT,UAAW,CACV,CACCC,KAAM,GADP,CAECC,MAAO,MAFR,CADU,CAJZ,CAD4B,CAA7B,CAaA,CAvCD,EAwCA,CAzCD,CA0CA,CA5HD","file":"identical-fields.spec.js","sourcesContent":["/**\n *\n * @licstart The following is the entire license notice for the JavaScript code in this file.\n *\n * MARC record validators used in Melinda\n *\n * Copyright (C) 2014-2018 University Of Helsinki (The National Library Of Finland)\n *\n * This file is part of marc-record-validators-melinda\n *\n * marc-record-validators-melinda program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * marc-record-validators-melinda is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n *\n * @licend The above is the entire license notice\n * for the JavaScript code in this file.\n *\n */\n\n/* eslint-disable no-undef, max-nested-callbacks, no-unused-expressions */\n\n'use strict';\n\nimport {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport validatorFactory from '../src/identical-fields';\n\ndescribe('identical-fields', () => {\n\tit('Creates a validator', async () => {\n\t\tconst validator = await validatorFactory();\n\n\t\texpect(validator)\n\t\t\t.to.be.an('object')\n\t\t\t.that.has.any.keys('description', 'validate');\n\n\t\texpect(validator.description).to.be.a('string');\n\t\texpect(validator.validate).to.be.a('function');\n\t});\n\n\tdescribe('#validate', () => {\n\t\tit('Finds the record valid', async () => {\n\t\t\tconst validator = await validatorFactory();\n\t\t\tconst record = new MarcRecord({\n\t\t\t\tfields: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '700',\n\t\t\t\t\t\tsubfields: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcode: 'e',\n\t\t\t\t\t\t\t\tvalue: 'foo'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t});\n\t\t\tconst result = await validator.validate(record);\n\n\t\t\texpect(result).to.eql({valid: true, messages: []});\n\t\t});\n\t\tit('Finds the record invalid', async () => {\n\t\t\tconst validator = await validatorFactory();\n\t\t\tconst record = new MarcRecord({\n\n\t\t\t\tfields: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '700',\n\t\t\t\t\t\tsubfields: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcode: 'e',\n\t\t\t\t\t\t\t\tvalue: 'foo'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t]\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '800',\n\t\t\t\t\t\tsubfields: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcode: 'e',\n\t\t\t\t\t\t\t\tvalue: 'foo'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t]\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '800',\n\t\t\t\t\t\tsubfields: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcode: 'e',\n\t\t\t\t\t\t\t\tvalue: 'foo'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t]\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '700',\n\t\t\t\t\t\tsubfields: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcode: 'e',\n\t\t\t\t\t\t\t\tvalue: 'foo'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t});\n\n\t\t\tconst result = await validator.validate(record);\n\n\t\t\texpect(result).to.eql({valid: false, messages: ['Field 800 has duplicates', 'Field 700 has duplicates']});\n\t\t});\n\t});\n\n\tdescribe('#fix', () => {\n\t\tit('Fixes the record', async () => {\n\t\t\tconst validator = await validatorFactory();\n\t\t\tconst record = new MarcRecord({\n\t\t\t\tfields: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '700',\n\t\t\t\t\t\tsubfields: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcode: 'e',\n\t\t\t\t\t\t\t\tvalue: 'dest'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t]\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '700',\n\t\t\t\t\t\tsubfields: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcode: 'e',\n\t\t\t\t\t\t\t\tvalue: 'dest'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t});\n\t\t\tawait validator.fix(record);\n\n\t\t\texpect(record.fields).to.eql([\n\t\t\t\t{\n\t\t\t\t\ttag: '700',\n\t\t\t\t\tind1: ' ',\n\t\t\t\t\tind2: ' ',\n\t\t\t\t\tsubfields: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcode: 'e',\n\t\t\t\t\t\t\tvalue: 'dest'\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t]);\n\t\t});\n\t});\n});\n"]}
1
+ {"version":3,"file":"identical-fields.spec.js","names":["_chai","require","_marcRecord","_identicalFields","_interopRequireDefault","obj","__esModule","default","describe","it","validator","validatorFactory","expect","to","be","an","that","has","any","keys","description","a","validate","record","MarcRecord","fields","tag","subfields","code","value","result","eql","valid","messages","fix","ind1","ind2"],"sources":["../src/identical-fields.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport validatorFactory from '../src/identical-fields';\n\ndescribe('identical-fields', () => {\n it('Creates a validator', async () => {\n const validator = await validatorFactory();\n\n expect(validator)\n .to.be.an('object')\n .that.has.any.keys('description', 'validate');\n\n expect(validator.description).to.be.a('string');\n expect(validator.validate).to.be.a('function');\n });\n\n describe('#validate', () => {\n it('Finds the record valid', async () => {\n const validator = await validatorFactory();\n const record = new MarcRecord({\n fields: [\n {\n tag: '700',\n subfields: [\n {\n code: 'e',\n value: 'foo'\n }\n ]\n }\n ]\n });\n const result = await validator.validate(record);\n\n expect(result).to.eql({valid: true, messages: []});\n });\n it('Finds the record invalid', async () => {\n const validator = await validatorFactory();\n const record = new MarcRecord({\n\n fields: [\n {\n tag: '700',\n subfields: [\n {\n code: 'e',\n value: 'foo'\n }\n ]\n },\n {\n tag: '800',\n subfields: [\n {\n code: 'e',\n value: 'foo'\n }\n ]\n },\n {\n tag: '800',\n subfields: [\n {\n code: 'e',\n value: 'foo'\n }\n ]\n },\n {\n tag: '700',\n subfields: [\n {\n code: 'e',\n value: 'foo'\n }\n ]\n }\n ]\n });\n\n const result = await validator.validate(record);\n\n expect(result).to.eql({valid: false, messages: ['Field 800 has duplicates', 'Field 700 has duplicates']});\n });\n });\n\n describe('#fix', () => {\n it('Fixes the record', async () => {\n const validator = await validatorFactory();\n const record = new MarcRecord({\n fields: [\n {\n tag: '700',\n subfields: [\n {\n code: 'e',\n value: 'dest'\n }\n ]\n },\n {\n tag: '700',\n subfields: [\n {\n code: 'e',\n value: 'dest'\n }\n ]\n }\n ]\n });\n await validator.fix(record);\n\n expect(record.fields).to.eql([\n {\n tag: '700',\n ind1: ' ',\n ind2: ' ',\n subfields: [\n {\n code: 'e',\n value: 'dest'\n }\n ]\n }\n ]);\n });\n });\n});\n"],"mappings":";;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAuD,SAAAG,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEvDG,QAAQ,CAAC,kBAAkB,EAAE,MAAM;EACjCC,EAAE,CAAC,qBAAqB,EAAE,YAAY;IACpC,MAAMC,SAAS,GAAG,MAAM,IAAAC,wBAAgB,EAAC,CAAC;IAE1C,IAAAC,YAAM,EAACF,SAAS,CAAC,CACdG,EAAE,CAACC,EAAE,CAACC,EAAE,CAAC,QAAQ,CAAC,CAClBC,IAAI,CAACC,GAAG,CAACC,GAAG,CAACC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC;IAE/C,IAAAP,YAAM,EAACF,SAAS,CAACU,WAAW,CAAC,CAACP,EAAE,CAACC,EAAE,CAACO,CAAC,CAAC,QAAQ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