@natlibfi/marc-record-validators-melinda 3.2.0 → 3.3.14-alpha.3

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,306 @@
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 _itemLanguage=require('../src/item-language');var _itemLanguage2=_interopRequireDefault(_itemLanguage);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('item-language',()=>{it('Creates a validator',_asyncToGenerator(function*(){const validator=yield(0,_itemLanguage2.default)(/^520$/);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 tagPattern is not provided',_asyncToGenerator(function*(){yield expect((0,_itemLanguage2.default)()).to.be.rejectedWith(Error,'No tagPattern provided')}));describe('#validate',()=>{it('Finds the record valid',_asyncToGenerator(function*(){const validator=yield(0,_itemLanguage2.default)(/^520$/);const record=new _marcRecord.MarcRecord({fields:[{tag:'041',ind1:' ',ind2:' ',subfields:[{code:'a',value:'fin'}]},{tag:'520',ind1:' ',ind2:'',subfields:[{code:'a',value:'Matti Yl\xF6sen Veroparatiisit on kirja siit\xE4, kuinka miljon\xE4\xE4rit ja monikansalliset yritykset ovat 20 vuoden aikana siirt\xE4neet kiihtyv\xE4ll\xE4 tahdilla tulojaan s\xE4\xE4telyn ja verottajan ulottumattomiin korkeiden pankkisalaisuuslakien suojiin. Samoihin keitaisiin, joita my\xF6s kansainv\xE4linen rikollisuus k\xE4ytt\xE4\xE4 rahanpesuun. Suomi on toistaiseksi ollut osa ongelmaa, ei sen ratkaisua.\nKirja sis\xE4lt\xE4\xE4 n\xE4k\xF6kulmia ja kiinnekohtia demokratian, hyvinvointivaltion ja kilpailullisen markkinatalouden kriiseihin. Mukana my\xF6s toimintaehdotuksia, joita Suomen tulee ajaa veroparatiisiongelman ratkaisemiseksi. Veroparatiisit on ajankohtainen tietopaketti veronkierron mekanismeista ja vaikutuksista.'}]}]});const result=yield validator.validate(record);expect(result).to.eql({valid:true})}));it('Finds the record invalid (Language code is missing and detection fails)',_asyncToGenerator(function*(){const validator=yield(0,_itemLanguage2.default)(/^520$/);const record=new _marcRecord.MarcRecord({fields:[{tag:'520',ind1:' ',ind2:'',subfields:[{code:'a',value:'.'}]}]});const result=yield validator.validate(record);expect(result).to.eql({valid:false,messages:['Language detection failed']})}));it('Finds the record invalid (Detected language differs)',_asyncToGenerator(function*(){const validator=yield(0,_itemLanguage2.default)(/^520$/);const record=new _marcRecord.MarcRecord({fields:[{tag:'008',value:'151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'},{tag:'041',ind1:' ',ind2:' ',subfields:[{code:'a',value:'fin'}]},{tag:'520',ind1:' ',ind2:'',subfields:[{code:'a',value:'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'}]}]});const result=yield validator.validate(record);expect(result).to.eql({valid:false,messages:['Item language code is invalid. Correct language code: eng']})}));it('Finds the record valid (Detected language differs and has multiple suggestions)',_asyncToGenerator(function*(){const validator=yield(0,_itemLanguage2.default)(/^520$/);const record=new _marcRecord.MarcRecord({fields:[{tag:'041',ind1:' ',ind2:' ',subfields:[{code:'a',value:'eng'}]},{tag:'520',ind1:' ',ind2:'',subfields:[{code:'a',value:'You should have received a copy of the GNU Affero General Public License along with this program. Mukana my\xF6s toimintaehdotuksia, joita Suomen tulee ajaa veroparatiisiongelman ratkaisemiseksi. Veroparatiisit on ajankohtainen tietopaketti veronkierron mekanismeista ja vaikutuksista.'}]}]});const result=yield validator.validate(record);expect(result).to.eql({valid:true,messages:['Item language code is invalid. Current code: \'eng\', suggestions: fin,eng']})}))});describe('#fix',()=>{it('Fixes the record',_asyncToGenerator(function*(){const validator=yield(0,_itemLanguage2.default)(/^520$/);const record=new _marcRecord.MarcRecord({fields:[{tag:'008',value:'151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'},{tag:'041',ind1:' ',ind2:' ',subfields:[{code:'a',value:'eng'}]},{tag:'520',ind1:' ',ind2:' ',subfields:[{code:'a',value:'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'}]}]});yield validator.fix(record);expect(record.fields).to.eql([{tag:'008',value:'151118t20162016fi^a|||^^^^^^^|0|^0|eng|^'},{tag:'041',ind1:' ',ind2:' ',subfields:[{code:'a',value:'eng'}]},{tag:'520',ind1:' ',ind2:' ',subfields:[{code:'a',value:'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'}]}])}));it('Fixes the record (Insert missing fields)',_asyncToGenerator(function*(){const validator=yield(0,_itemLanguage2.default)(/^520$/);const record=new _marcRecord.MarcRecord({fields:[{tag:'008',value:'151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'},{tag:'520',ind1:' ',ind2:' ',subfields:[{code:'a',value:'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'}]}]});yield validator.fix(record);expect(record.fields).to.eql([{tag:'008',value:'151118t20162016fi^a|||^^^^^^^|0|^0|eng|^'},{tag:'041',ind1:' ',ind2:' ',subfields:[{code:'a',value:'eng'}]},{tag:'520',ind1:' ',ind2:' ',subfields:[{code:'a',value:'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'}]}])}));it('Fixes the record (Insert missing subfields)',_asyncToGenerator(function*(){const validator=yield(0,_itemLanguage2.default)(/^520$/);const record=new _marcRecord.MarcRecord({fields:[{tag:'008',value:'151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'},{tag:'041',ind1:' ',ind2:' ',subfields:[{code:'b',value:'foo'}]},{tag:'520',ind1:' ',ind2:' ',subfields:[{code:'a',value:'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'}]}]});yield validator.fix(record);expect(record.fields).to.eql([{tag:'008',value:'151118t20162016fi^a|||^^^^^^^|0|^0|eng|^'},{tag:'041',ind1:' ',ind2:' ',subfields:[{code:'a',value:'eng'},{code:'b',value:'foo'}]},{tag:'520',ind1:' ',ind2:' ',subfields:[{code:'a',value:'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'}]}])}));it('Fails to fix the record',_asyncToGenerator(function*(){const validator=yield(0,_itemLanguage2.default)(/^520$/);const record=new _marcRecord.MarcRecord({fields:[{tag:'520',ind1:' ',ind2:'',subfields:[{code:'a',value:'.'}]}]});try{yield validator.fix(record)}catch(err){expect(err.message).to.equal('Language code is missing and detection failed')}}))})});
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 _itemLanguage = _interopRequireDefault(require("../src/item-language"));
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('item-language', () => {
13
+ it('Creates a validator', async () => {
14
+ const validator = await (0, _itemLanguage.default)(/^520$/u);
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 tagPattern is not provided', async () => {
20
+ await expect((0, _itemLanguage.default)()).to.be.rejectedWith(Error, 'No tagPattern provided');
21
+ });
22
+ describe('#validate', () => {
23
+ it('Finds the record valid', async () => {
24
+ const validator = await (0, _itemLanguage.default)(/^520$/u);
25
+ const record = new _marcRecord.MarcRecord({
26
+ fields: [{
27
+ tag: '041',
28
+ ind1: ' ',
29
+ ind2: ' ',
30
+ subfields: [{
31
+ code: 'a',
32
+ value: 'fin'
33
+ }]
34
+ }, {
35
+ tag: '520',
36
+ ind1: ' ',
37
+ ind2: '',
38
+ subfields: [{
39
+ code: 'a',
40
+ value: 'Matti Ylösen Veroparatiisit on kirja siitä, kuinka miljonäärit ja monikansalliset yritykset ovat 20 vuoden aikana siirtäneet kiihtyvällä tahdilla tulojaan säätelyn ja verottajan ulottumattomiin korkeiden pankkisalaisuuslakien suojiin. Samoihin keitaisiin, joita myös kansainvälinen rikollisuus käyttää rahanpesuun. Suomi on toistaiseksi ollut osa ongelmaa, ei sen ratkaisua.\nKirja sisältää näkökulmia ja kiinnekohtia demokratian, hyvinvointivaltion ja kilpailullisen markkinatalouden kriiseihin. Mukana myös toimintaehdotuksia, joita Suomen tulee ajaa veroparatiisiongelman ratkaisemiseksi. Veroparatiisit on ajankohtainen tietopaketti veronkierron mekanismeista ja vaikutuksista.'
41
+ }]
42
+ }]
43
+ });
44
+ const result = await validator.validate(record);
45
+ expect(result).to.eql({
46
+ valid: true
47
+ });
48
+ });
49
+ it('Finds the record invalid (Language code is missing and detection failed', async () => {
50
+ const validator = await (0, _itemLanguage.default)(/^520$/u);
51
+ const record = new _marcRecord.MarcRecord({
52
+ fields: [{
53
+ tag: '520',
54
+ ind1: ' ',
55
+ ind2: '',
56
+ subfields: [{
57
+ code: 'a',
58
+ value: '.'
59
+ }]
60
+ }]
61
+ });
62
+ const result = await validator.validate(record);
63
+ expect(result).to.eql({
64
+ valid: false,
65
+ messages: ['Language detection failed']
66
+ });
67
+ });
68
+ it('Finds the record invalid (Detected language differs)', async () => {
69
+ const validator = await (0, _itemLanguage.default)(/^520$/u);
70
+ const record = new _marcRecord.MarcRecord({
71
+ fields: [{
72
+ tag: '008',
73
+ value: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'
74
+ }, {
75
+ tag: '041',
76
+ ind1: ' ',
77
+ ind2: ' ',
78
+ subfields: [{
79
+ code: 'a',
80
+ value: 'fin'
81
+ }]
82
+ }, {
83
+ tag: '520',
84
+ ind1: ' ',
85
+ ind2: '',
86
+ subfields: [{
87
+ code: 'a',
88
+ value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'
89
+ }]
90
+ }]
91
+ });
92
+ const result = await validator.validate(record);
93
+ expect(result).to.eql({
94
+ valid: false,
95
+ messages: ['Item language code is invalid. Correct language code: eng']
96
+ });
97
+ });
98
+ it('Finds the record invalid (Probability doesn\'t meet treshold)', async () => {
99
+ const validator = await (0, _itemLanguage.default)(/^520$/u, 1);
100
+ const record = new _marcRecord.MarcRecord({
101
+ fields: [{
102
+ tag: '008',
103
+ value: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'
104
+ }, {
105
+ tag: '041',
106
+ ind1: ' ',
107
+ ind2: ' ',
108
+ subfields: [{
109
+ code: 'a',
110
+ value: 'fin'
111
+ }]
112
+ }, {
113
+ tag: '520',
114
+ ind1: ' ',
115
+ ind2: '',
116
+ subfields: [{
117
+ code: 'a',
118
+ value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'
119
+ }]
120
+ }]
121
+ });
122
+ const result = await validator.validate(record);
123
+ expect(result).to.eql({
124
+ valid: true,
125
+ messages: ['Item language code is invalid. Current code: fin, suggestions: eng']
126
+ });
127
+ });
128
+ it('Finds the record invalid (No detectable text)', async () => {
129
+ const validator = await (0, _itemLanguage.default)(/^520$/u, 1);
130
+ const record = new _marcRecord.MarcRecord({
131
+ fields: [{
132
+ tag: '008',
133
+ value: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'
134
+ }, {
135
+ tag: '041',
136
+ ind1: ' ',
137
+ ind2: ' ',
138
+ subfields: [{
139
+ code: 'a',
140
+ value: 'fin'
141
+ }]
142
+ }]
143
+ });
144
+ const result = await validator.validate(record);
145
+ expect(result).to.eql({
146
+ valid: true,
147
+ messages: ['Language detection failed']
148
+ });
149
+ });
150
+ });
151
+ describe('#fix', () => {
152
+ it('Fixes the record', async () => {
153
+ const validator = await (0, _itemLanguage.default)(/^520$/u);
154
+ const record = new _marcRecord.MarcRecord({
155
+ fields: [{
156
+ tag: '008',
157
+ value: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'
158
+ }, {
159
+ tag: '041',
160
+ ind1: ' ',
161
+ ind2: ' ',
162
+ subfields: [{
163
+ code: 'a',
164
+ value: 'eng'
165
+ }]
166
+ }, {
167
+ tag: '520',
168
+ ind1: ' ',
169
+ ind2: ' ',
170
+ subfields: [{
171
+ code: 'a',
172
+ value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'
173
+ }]
174
+ }]
175
+ });
176
+ await validator.fix(record);
177
+ expect(record.fields).to.eql([{
178
+ tag: '008',
179
+ value: '151118t20162016fi^a|||^^^^^^^|0|^0|eng|^'
180
+ }, {
181
+ tag: '041',
182
+ ind1: ' ',
183
+ ind2: ' ',
184
+ subfields: [{
185
+ code: 'a',
186
+ value: 'eng'
187
+ }]
188
+ }, {
189
+ tag: '520',
190
+ ind1: ' ',
191
+ ind2: ' ',
192
+ subfields: [{
193
+ code: 'a',
194
+ value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'
195
+ }]
196
+ }]);
197
+ });
198
+ it('Fixes the record (Insert missing fields)', async () => {
199
+ const validator = await (0, _itemLanguage.default)(/^520$/u);
200
+ const record = new _marcRecord.MarcRecord({
201
+ fields: [{
202
+ tag: '008',
203
+ value: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'
204
+ }, {
205
+ tag: '520',
206
+ ind1: ' ',
207
+ ind2: ' ',
208
+ subfields: [{
209
+ code: 'a',
210
+ value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'
211
+ }]
212
+ }]
213
+ });
214
+ await validator.fix(record);
215
+ expect(record.fields).to.eql([{
216
+ tag: '008',
217
+ value: '151118t20162016fi^a|||^^^^^^^|0|^0|eng|^'
218
+ }, {
219
+ tag: '041',
220
+ ind1: ' ',
221
+ ind2: ' ',
222
+ subfields: [{
223
+ code: 'a',
224
+ value: 'eng'
225
+ }]
226
+ }, {
227
+ tag: '520',
228
+ ind1: ' ',
229
+ ind2: ' ',
230
+ subfields: [{
231
+ code: 'a',
232
+ value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'
233
+ }]
234
+ }]);
235
+ });
236
+ it('Fixes the record (Insert missing subfields)', async () => {
237
+ const validator = await (0, _itemLanguage.default)(/^520$/u);
238
+ const record = new _marcRecord.MarcRecord({
239
+ fields: [{
240
+ tag: '008',
241
+ value: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'
242
+ }, {
243
+ tag: '041',
244
+ ind1: ' ',
245
+ ind2: ' ',
246
+ subfields: [{
247
+ code: 'b',
248
+ value: 'foo'
249
+ }]
250
+ }, {
251
+ tag: '520',
252
+ ind1: ' ',
253
+ ind2: ' ',
254
+ subfields: [{
255
+ code: 'a',
256
+ value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'
257
+ }]
258
+ }]
259
+ });
260
+ await validator.fix(record);
261
+ expect(record.fields).to.eql([{
262
+ tag: '008',
263
+ value: '151118t20162016fi^a|||^^^^^^^|0|^0|eng|^'
264
+ }, {
265
+ tag: '041',
266
+ ind1: ' ',
267
+ ind2: ' ',
268
+ subfields: [{
269
+ code: 'a',
270
+ value: 'eng'
271
+ }, {
272
+ code: 'b',
273
+ value: 'foo'
274
+ }]
275
+ }, {
276
+ tag: '520',
277
+ ind1: ' ',
278
+ ind2: ' ',
279
+ subfields: [{
280
+ code: 'a',
281
+ value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'
282
+ }]
283
+ }]);
284
+ });
285
+ it('Fails to fix the record', async () => {
286
+ const validator = await (0, _itemLanguage.default)(/^520$/u);
287
+ const record = new _marcRecord.MarcRecord({
288
+ fields: [{
289
+ tag: '520',
290
+ ind1: ' ',
291
+ ind2: '',
292
+ subfields: [{
293
+ code: 'a',
294
+ value: '.'
295
+ }]
296
+ }]
297
+ });
298
+ try {
299
+ await validator.fix(record);
300
+ } catch (err) {
301
+ expect(err.message).to.equal('Language code is missing and detection failed');
302
+ }
303
+ });
304
+ });
305
+ });
28
306
  //# sourceMappingURL=item-language.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/item-language.spec.js"],"names":["expect","chai","use","chaiAsPromised","describe","it","validator","to","be","an","that","has","any","keys","description","a","validate","rejectedWith","Error","record","MarcRecord","fields","tag","ind1","ind2","subfields","code","value","result","eql","valid","messages","fix","err","message","equal"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BA,0EAEA,aAEA,0B,yCACA,gD,6DACA,iDACA,kD,qhBAEA,KAAM,CAACA,MAAD,EAAWC,cAAjB,CACAA,eAAKC,GAAL,CAASC,wBAAT,EAEAC,SAAS,eAAT,CAA0B,IAAM,CAC/BC,GAAG,qBAAH,mBAA0B,WAAY,CACrC,KAAMC,WAAY,KAAM,2BAAiB,OAAjB,CAAxB,CAEAN,OAAOM,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-language.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/item-language';\n\nconst {expect} = chai;\nchai.use(chaiAsPromised);\n\ndescribe('item-language', () => {\n\tit('Creates a validator', async () => {\n\t\tconst validator = await validatorFactory(/^520$/);\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 tagPattern is not provided', async () => {\n\t\tawait expect(validatorFactory()).to.be.rejectedWith(Error, 'No tagPattern provided');\n\t});\n\n\tdescribe('#validate', () => {\n\t\tit('Finds the record valid', async () => {\n\t\t\tconst validator = await validatorFactory(/^520$/);\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: '041',\n\t\t\t\t\t\tind1: ' ',\n\t\t\t\t\t\tind2: ' ',\n\t\t\t\t\t\tsubfields: [{code: 'a', value: 'fin'}]\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '520',\n\t\t\t\t\t\tind1: ' ',\n\t\t\t\t\t\tind2: '',\n\t\t\t\t\t\tsubfields: [{\n\t\t\t\t\t\t\tcode: 'a',\n\t\t\t\t\t\t\tvalue: 'Matti Ylösen Veroparatiisit on kirja siitä, kuinka miljonäärit ja monikansalliset yritykset ovat 20 vuoden aikana siirtäneet kiihtyvällä tahdilla tulojaan säätelyn ja verottajan ulottumattomiin korkeiden pankkisalaisuuslakien suojiin. Samoihin keitaisiin, joita myös kansainvälinen rikollisuus käyttää rahanpesuun. Suomi on toistaiseksi ollut osa ongelmaa, ei sen ratkaisua.\\nKirja sisältää näkökulmia ja kiinnekohtia demokratian, hyvinvointivaltion ja kilpailullisen markkinatalouden kriiseihin. Mukana myös toimintaehdotuksia, joita Suomen tulee ajaa veroparatiisiongelman ratkaisemiseksi. Veroparatiisit on ajankohtainen tietopaketti veronkierron mekanismeista ja vaikutuksista.'\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});\n\t\t});\n\n\t\tit('Finds the record invalid (Language code is missing and detection fails)', async () => {\n\t\t\tconst validator = await validatorFactory(/^520$/);\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: '520',\n\t\t\t\t\t\tind1: ' ',\n\t\t\t\t\t\tind2: '',\n\t\t\t\t\t\tsubfields: [{\n\t\t\t\t\t\t\tcode: 'a',\n\t\t\t\t\t\t\tvalue: '.'\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: false, messages: [\n\t\t\t\t'Language detection failed'\n\t\t\t]});\n\t\t});\n\n\t\tit('Finds the record invalid (Detected language differs)', async () => {\n\t\t\tconst validator = await validatorFactory(/^520$/);\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: '008',\n\t\t\t\t\t\tvalue: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '041',\n\t\t\t\t\t\tind1: ' ',\n\t\t\t\t\t\tind2: ' ',\n\t\t\t\t\t\tsubfields: [{code: 'a', value: 'fin'}]\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '520',\n\t\t\t\t\t\tind1: ' ',\n\t\t\t\t\t\tind2: '',\n\t\t\t\t\t\tsubfields: [{\n\t\t\t\t\t\t\tcode: 'a',\n\t\t\t\t\t\t\tvalue: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'\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: false, messages: [\n\t\t\t\t'Item language code is invalid. Correct language code: eng'\n\t\t\t]});\n\t\t});\n\n\t\tit('Finds the record valid (Detected language differs and has multiple suggestions)', async () => {\n\t\t\tconst validator = await validatorFactory(/^520$/);\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: '041',\n\t\t\t\t\t\tind1: ' ',\n\t\t\t\t\t\tind2: ' ',\n\t\t\t\t\t\tsubfields: [{code: 'a', value: 'eng'}]\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '520',\n\t\t\t\t\t\tind1: ' ',\n\t\t\t\t\t\tind2: '',\n\t\t\t\t\t\tsubfields: [{\n\t\t\t\t\t\t\tcode: 'a',\n\t\t\t\t\t\t\tvalue: 'You should have received a copy of the GNU Affero General Public License along with this program. Mukana myös toimintaehdotuksia, joita Suomen tulee ajaa veroparatiisiongelman ratkaisemiseksi. Veroparatiisit on ajankohtainen tietopaketti veronkierron mekanismeista ja vaikutuksista.'\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\t\t'Item language code is invalid. Current code: \\'eng\\', suggestions: fin,eng'\n\n\t\t\t]});\n\t\t});\n\t});\n\n\tdescribe('#fix', () => {\n\t\tit('Fixes the record', async () => {\n\t\t\tconst validator = await validatorFactory(/^520$/);\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: '008',\n\t\t\t\t\t\tvalue: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '041',\n\t\t\t\t\t\tind1: ' ',\n\t\t\t\t\t\tind2: ' ',\n\t\t\t\t\t\tsubfields: [{code: 'a', value: 'eng'}]\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '520',\n\t\t\t\t\t\tind1: ' ',\n\t\t\t\t\t\tind2: ' ',\n\t\t\t\t\t\tsubfields: [{\n\t\t\t\t\t\t\tcode: 'a',\n\t\t\t\t\t\t\tvalue: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'\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: '008',\n\t\t\t\t\tvalue: '151118t20162016fi^a|||^^^^^^^|0|^0|eng|^'\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttag: '041',\n\t\t\t\t\tind1: ' ',\n\t\t\t\t\tind2: ' ',\n\t\t\t\t\tsubfields: [{code: 'a', value: 'eng'}]\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttag: '520',\n\t\t\t\t\tind1: ' ',\n\t\t\t\t\tind2: ' ',\n\t\t\t\t\tsubfields: [{\n\t\t\t\t\t\tcode: 'a',\n\t\t\t\t\t\tvalue: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'\n\t\t\t\t\t}]\n\t\t\t\t}\n\t\t\t]);\n\t\t});\n\n\t\tit('Fixes the record (Insert missing fields)', async () => {\n\t\t\tconst validator = await validatorFactory(/^520$/);\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: '008',\n\t\t\t\t\t\tvalue: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '520',\n\t\t\t\t\t\tind1: ' ',\n\t\t\t\t\t\tind2: ' ',\n\t\t\t\t\t\tsubfields: [{\n\t\t\t\t\t\t\tcode: 'a',\n\t\t\t\t\t\t\tvalue: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'\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: '008',\n\t\t\t\t\tvalue: '151118t20162016fi^a|||^^^^^^^|0|^0|eng|^'\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttag: '041',\n\t\t\t\t\tind1: ' ',\n\t\t\t\t\tind2: ' ',\n\t\t\t\t\tsubfields: [{code: 'a', value: 'eng'}]\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttag: '520',\n\t\t\t\t\tind1: ' ',\n\t\t\t\t\tind2: ' ',\n\t\t\t\t\tsubfields: [{\n\t\t\t\t\t\tcode: 'a',\n\t\t\t\t\t\tvalue: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'\n\t\t\t\t\t}]\n\t\t\t\t}\n\t\t\t]);\n\t\t});\n\n\t\tit('Fixes the record (Insert missing subfields)', async () => {\n\t\t\tconst validator = await validatorFactory(/^520$/);\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: '008',\n\t\t\t\t\t\tvalue: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '041',\n\t\t\t\t\t\tind1: ' ',\n\t\t\t\t\t\tind2: ' ',\n\t\t\t\t\t\tsubfields: [{code: 'b', value: 'foo'}]\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttag: '520',\n\t\t\t\t\t\tind1: ' ',\n\t\t\t\t\t\tind2: ' ',\n\t\t\t\t\t\tsubfields: [{\n\t\t\t\t\t\t\tcode: 'a',\n\t\t\t\t\t\t\tvalue: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'\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: '008',\n\t\t\t\t\tvalue: '151118t20162016fi^a|||^^^^^^^|0|^0|eng|^'\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttag: '041',\n\t\t\t\t\tind1: ' ',\n\t\t\t\t\tind2: ' ',\n\t\t\t\t\tsubfields: [{code: 'a', value: 'eng'}, {code: 'b', value: 'foo'}]\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttag: '520',\n\t\t\t\t\tind1: ' ',\n\t\t\t\t\tind2: ' ',\n\t\t\t\t\tsubfields: [{\n\t\t\t\t\t\tcode: 'a',\n\t\t\t\t\t\tvalue: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'\n\t\t\t\t\t}]\n\t\t\t\t}\n\t\t\t]);\n\t\t});\n\n\t\tit('Fails to fix the record', async () => {\n\t\t\tconst validator = await validatorFactory(/^520$/);\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: '520',\n\t\t\t\t\t\tind1: ' ',\n\t\t\t\t\t\tind2: '',\n\t\t\t\t\t\tsubfields: [{\n\t\t\t\t\t\t\tcode: 'a',\n\t\t\t\t\t\t\tvalue: '.'\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\ttry {\n\t\t\t\tawait validator.fix(record);\n\t\t\t} catch (err) {\n\t\t\t\texpect(err.message).to.equal('Language code is missing and detection failed');\n\t\t\t}\n\t\t});\n\t});\n});\n"]}
1
+ {"version":3,"file":"item-language.spec.js","names":["_chai","_interopRequireDefault","require","_chaiAsPromised","_marcRecord","_itemLanguage","obj","__esModule","default","expect","chai","use","chaiAsPromised","describe","it","validator","validatorFactory","to","be","an","that","has","any","keys","description","a","validate","rejectedWith","Error","record","MarcRecord","fields","tag","ind1","ind2","subfields","code","value","result","eql","valid","messages","fix","err","message","equal"],"sources":["../src/item-language.spec.js"],"sourcesContent":["import chai from 'chai';\nimport chaiAsPromised from 'chai-as-promised';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport validatorFactory from '../src/item-language';\n\nconst {expect} = chai;\nchai.use(chaiAsPromised);\n\ndescribe('item-language', () => {\n it('Creates a validator', async () => {\n const validator = await validatorFactory(/^520$/u);\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 tagPattern is not provided', async () => {\n await expect(validatorFactory()).to.be.rejectedWith(Error, 'No tagPattern provided');\n });\n\n describe('#validate', () => {\n it('Finds the record valid', async () => {\n const validator = await validatorFactory(/^520$/u);\n const record = new MarcRecord({\n fields: [\n {\n tag: '041',\n ind1: ' ',\n ind2: ' ',\n subfields: [{code: 'a', value: 'fin'}]\n },\n {\n tag: '520',\n ind1: ' ',\n ind2: '',\n subfields: [\n {\n code: 'a',\n value: 'Matti Ylösen Veroparatiisit on kirja siitä, kuinka miljonäärit ja monikansalliset yritykset ovat 20 vuoden aikana siirtäneet kiihtyvällä tahdilla tulojaan säätelyn ja verottajan ulottumattomiin korkeiden pankkisalaisuuslakien suojiin. Samoihin keitaisiin, joita myös kansainvälinen rikollisuus käyttää rahanpesuun. Suomi on toistaiseksi ollut osa ongelmaa, ei sen ratkaisua.\\nKirja sisältää näkökulmia ja kiinnekohtia demokratian, hyvinvointivaltion ja kilpailullisen markkinatalouden kriiseihin. Mukana myös toimintaehdotuksia, joita Suomen tulee ajaa veroparatiisiongelman ratkaisemiseksi. Veroparatiisit on ajankohtainen tietopaketti veronkierron mekanismeista ja vaikutuksista.'\n }\n ]\n }\n ]\n });\n const result = await validator.validate(record);\n\n expect(result).to.eql({valid: true});\n });\n\n it('Finds the record invalid (Language code is missing and detection failed', async () => {\n const validator = await validatorFactory(/^520$/u);\n const record = new MarcRecord({\n fields: [\n {\n tag: '520',\n ind1: ' ',\n ind2: '',\n subfields: [\n {\n code: 'a',\n value: '.'\n }\n ]\n }\n ]\n });\n const result = await validator.validate(record);\n\n expect(result).to.eql({valid: false, messages: ['Language detection failed']});\n });\n\n it('Finds the record invalid (Detected language differs)', async () => {\n const validator = await validatorFactory(/^520$/u);\n const record = new MarcRecord({\n fields: [\n {\n tag: '008',\n value: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'\n },\n {\n tag: '041',\n ind1: ' ',\n ind2: ' ',\n subfields: [{code: 'a', value: 'fin'}]\n },\n {\n tag: '520',\n ind1: ' ',\n ind2: '',\n subfields: [\n {\n code: 'a',\n value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'\n }\n ]\n }\n ]\n });\n const result = await validator.validate(record);\n\n expect(result).to.eql({valid: false, messages: ['Item language code is invalid. Correct language code: eng']});\n });\n\n it('Finds the record invalid (Probability doesn\\'t meet treshold)', async () => {\n const validator = await validatorFactory(/^520$/u, 1);\n const record = new MarcRecord({\n fields: [\n {\n tag: '008',\n value: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'\n },\n {\n tag: '041',\n ind1: ' ',\n ind2: ' ',\n subfields: [{code: 'a', value: 'fin'}]\n },\n {\n tag: '520',\n ind1: ' ',\n ind2: '',\n subfields: [\n {\n code: 'a',\n value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'\n }\n ]\n }\n ]\n });\n const result = await validator.validate(record);\n\n expect(result).to.eql({valid: true, messages: ['Item language code is invalid. Current code: fin, suggestions: eng']});\n });\n\n it('Finds the record invalid (No detectable text)', async () => {\n const validator = await validatorFactory(/^520$/u, 1);\n const record = new MarcRecord({\n fields: [\n {\n tag: '008',\n value: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'\n },\n {\n tag: '041',\n ind1: ' ',\n ind2: ' ',\n subfields: [{code: 'a', value: 'fin'}]\n }\n ]\n });\n const result = await validator.validate(record);\n\n expect(result).to.eql({valid: true, messages: ['Language detection failed']});\n });\n });\n\n describe('#fix', () => {\n it('Fixes the record', async () => {\n const validator = await validatorFactory(/^520$/u);\n const record = new MarcRecord({\n fields: [\n {\n tag: '008',\n value: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'\n },\n {\n tag: '041',\n ind1: ' ',\n ind2: ' ',\n subfields: [{code: 'a', value: 'eng'}]\n },\n {\n tag: '520',\n ind1: ' ',\n ind2: ' ',\n subfields: [\n {\n code: 'a',\n value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'\n }\n ]\n }\n ]\n });\n await validator.fix(record);\n\n expect(record.fields).to.eql([\n {\n tag: '008',\n value: '151118t20162016fi^a|||^^^^^^^|0|^0|eng|^'\n },\n {\n tag: '041',\n ind1: ' ',\n ind2: ' ',\n subfields: [{code: 'a', value: 'eng'}]\n },\n {\n tag: '520',\n ind1: ' ',\n ind2: ' ',\n subfields: [\n {\n code: 'a',\n value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'\n }\n ]\n }\n ]);\n });\n\n it('Fixes the record (Insert missing fields)', async () => {\n const validator = await validatorFactory(/^520$/u);\n const record = new MarcRecord({\n fields: [\n {\n tag: '008',\n value: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'\n },\n {\n tag: '520',\n ind1: ' ',\n ind2: ' ',\n subfields: [\n {\n code: 'a',\n value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'\n }\n ]\n }\n ]\n });\n await validator.fix(record);\n\n expect(record.fields).to.eql([\n {\n tag: '008',\n value: '151118t20162016fi^a|||^^^^^^^|0|^0|eng|^'\n },\n {\n tag: '041',\n ind1: ' ',\n ind2: ' ',\n subfields: [{code: 'a', value: 'eng'}]\n },\n {\n tag: '520',\n ind1: ' ',\n ind2: ' ',\n subfields: [\n {\n code: 'a',\n value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'\n }\n ]\n }\n ]);\n });\n\n it('Fixes the record (Insert missing subfields)', async () => {\n const validator = await validatorFactory(/^520$/u);\n const record = new MarcRecord({\n fields: [\n {\n tag: '008',\n value: '151118t20162016fi^a|||^^^^^^^|0|^0|fin|^'\n },\n {\n tag: '041',\n ind1: ' ',\n ind2: ' ',\n subfields: [{code: 'b', value: 'foo'}]\n },\n {\n tag: '520',\n ind1: ' ',\n ind2: ' ',\n subfields: [\n {\n code: 'a',\n value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'\n }\n ]\n }\n ]\n });\n await validator.fix(record);\n\n expect(record.fields).to.eql([\n {\n tag: '008',\n value: '151118t20162016fi^a|||^^^^^^^|0|^0|eng|^'\n },\n {\n tag: '041',\n ind1: ' ',\n ind2: ' ',\n subfields: [{code: 'a', value: 'eng'}, {code: 'b', value: 'foo'}]\n },\n {\n tag: '520',\n ind1: ' ',\n ind2: ' ',\n subfields: [\n {\n code: 'a',\n value: 'If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.'\n }\n ]\n }\n ]);\n });\n\n it('Fails to fix the record', async () => {\n const validator = await validatorFactory(/^520$/u);\n const record = new MarcRecord({\n fields: [\n {\n tag: '520',\n ind1: ' ',\n ind2: '',\n subfields: [\n {\n code: 'a',\n value: '.'\n }\n ]\n }\n ]\n });\n\n try {\n await validator.fix(record);\n } catch (err) {\n expect(err.message).to.equal('Language code is missing and detection failed');\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,aAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAAoD,SAAAD,uBAAAK,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEpD,MAAM;EAACG;AAAM,CAAC,GAAGC,aAAI;AACrBA,aAAI,CAACC,GAAG,CAACC,uBAAc,CAAC;AAExBC,QAAQ,CAAC,eAAe,EAAE,MAAM;EAC9BC,EAAE,CAAC,qBAAqB,EAAE,YAAY;IACpC,MAAMC,SAAS,GAAG,MAAM,IAAAC,qBAAgB,EAAC,QAAQ,CAAC;IAElDP,MAAM,CAACM,SAAS,CAAC,CACdE,EAAE,CAACC,EAAE,CAACC,EAAE,CAAC,QAAQ,CAAC,CAClBC,IAAI,CAACC,GAAG,CAACC,GAAG,CAACC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC;IAE/Cd,MAAM,CAACM,SAAS,CAACS,WAAW,CAAC,CAACP,EAAE,CAACC,EAAE,CAACO,CAAC,CAAC,QAAQ,CAAC;IAC/ChB,MAAM,CAACM,SAAS,CAACW,QAAQ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,MAAM,GAAG,IAAIC,sBAAU,CAAC;QAC5BC,MAAM,EAAE,CACN;UACEC,GAAG,EAAE,KAAK;UACVC,IAAI,EAAE,GAAG;UACTC,IAAI,EAAE,EAAE;UACRC,SAAS,EAAE,CACT;YACEC,IAAI,EAAE,GAAG;YACTC,KAAK,EAAE;UACT,CAAC;QAEL,CAAC;MAEL,CAAC,CAAC;MAEF,IAAI;QACF,MAAMtB,SAAS,CAAC2B,GAAG,CAACb,MAAM,CAAC;MAC7B,CAAC,CAAC,OAAOc,GAAG,EAAE;QACZlC,MAAM,CAACkC,GAAG,CAACC,OAAO,CAAC,CAAC3B,EAAE,CAAC4B,KAAK,CAAC,+CAA+C,CAAC;MAC/E;IACF,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+ exports.mergeLisapainokset = mergeLisapainokset;
8
+ function _default() {
9
+ return {
10
+ description: 'Merge 500 $a Lisäpainokset fields',
11
+ validate,
12
+ fix
13
+ };
14
+ function fix(record) {
15
+ const res = {
16
+ message: [],
17
+ fix: [],
18
+ valid: true
19
+ };
20
+ mergeLisapainokset(record);
21
+ return res;
22
+ }
23
+ function validate(record) {
24
+ const relevantFields = getRelevantFields(record);
25
+ if (relevantFields.length < 2) {
26
+ return {
27
+ message: [],
28
+ 'valid': true
29
+ }; // No action required
30
+ }
31
+
32
+ const printData = extractAllPrintData(relevantFields);
33
+ if (printData.length === 0) {
34
+ return {
35
+ message: ['There are issues, but the fixer can not fix them!'],
36
+ 'valid': false
37
+ }; // No action required
38
+ }
39
+
40
+ return {
41
+ message: [`Fixer can merge ${relevantFields.length} 500 $a Lisäpainokset fields into one`],
42
+ 'valid': false
43
+ };
44
+ }
45
+ }
46
+ function getRelevantFields(record) {
47
+ return record.fields.filter(field => validLisapainosField(field));
48
+ }
49
+ function validLisapainosField(field) {
50
+ // We are only interested in field 500 with a lone $a subfield.
51
+ // Especially $9 FENNI<KEEP> should not be merged!
52
+ if (field.tag !== '500' || field.subfields.length !== 1 || field.subfields[0].code !== 'a') {
53
+ return false;
54
+ }
55
+ return field.subfields[0].value.match(/^(?:Lisäpainokset|Lisäpainos): (?:[1-9][0-9]*\. (?:p\.|painos|uppl\.) [0-9]+\.)(?: - [1-9][0-9]*\. (?:p\.|painos|uppl\.) \[?[0-9]+\]?\.)*$/u);
56
+ }
57
+ function fieldToPrintsString(field) {
58
+ // Could this just be something on the lines of s/^\S+ // ?
59
+ return field.subfields[0].value.replace(/^(?:Lisäpainokset|Lisäpainos): /u, '').replace(/\.$/u, '');
60
+ }
61
+ const printPreference = ['painos', 'p.', 'upplaga', 'uppl.'];
62
+ function getPrintPreference(value) {
63
+ return printPreference.findIndex(pp => pp === value);
64
+ }
65
+ function mergePrintData(value1, value2) {
66
+ const [index1, print1, year1] = value1.split(' ');
67
+ const [index2, print2, year2] = value2.split(' ');
68
+ const betterIndex = index1 ? index1 : index2; // just to cheat eslint...
69
+
70
+ // merge print1 and print2
71
+ const betterPrint = getBetterPrint(print1, print2);
72
+ if (!betterPrint) {
73
+ return null;
74
+ }
75
+ const betterYear = getBetterYear(year1, year2);
76
+ if (!betterYear) {
77
+ return null;
78
+ }
79
+ return `${betterIndex} ${betterPrint} ${betterYear}`;
80
+ function getBetterYear(y1, y2) {
81
+ if (y1 === y2 || y2 === `[${y1}]`) {
82
+ return y1;
83
+ }
84
+ if (y1 === `[${y2}]`) {
85
+ return y2;
86
+ }
87
+ return null;
88
+ }
89
+ function getBetterPrint(print1, print2) {
90
+ if (print1 === print2) {
91
+ return print1;
92
+ }
93
+ const i1 = getPrintPreference(print1);
94
+ const i2 = getPrintPreference(print2);
95
+ if (i1 === -1 || i2 === -1) {
96
+ return null;
97
+ }
98
+ if (i1 <= i2) {
99
+ return printPreference[i1];
100
+ }
101
+ return printPreference[i2];
102
+ }
103
+ }
104
+ function extractAllPrintData(relevantFields) {
105
+ /* eslint-disable */
106
+ // Gather data about 500 $a Lisäpainokset.*
107
+ let allPrintData = [];
108
+ let i;
109
+ let j;
110
+ for (i = 0; i < relevantFields.length; i++) {
111
+ const value = fieldToPrintsString(relevantFields[i]);
112
+ const fieldsPrintData = value.split('. - ');
113
+ for (j = 0; j < fieldsPrintData.length; j++) {
114
+ let currPrintData = fieldsPrintData[j];
115
+ // Example value: "2. p. 2020"
116
+ const [printIndex] = currPrintData.split('.');
117
+ if (allPrintData[printIndex] !== undefined) {
118
+ if (allPrintData[printIndex] !== currPrintData) {
119
+ const mergedPrintData = mergePrintData(allPrintData[printIndex], currPrintData);
120
+ if (!mergedPrintData) {
121
+ return []; // reason for for-loops: exit function from within nested loops
122
+ }
123
+
124
+ currPrintData = mergedPrintData;
125
+ }
126
+ }
127
+ allPrintData[printIndex] = currPrintData;
128
+ }
129
+ }
130
+ ;
131
+ return allPrintData.filter(p => p !== undefined);
132
+ }
133
+ function mergeLisapainokset(record) {
134
+ const relevantFields = getRelevantFields(record);
135
+ if (relevantFields.length < 2) {
136
+ return;
137
+ }
138
+
139
+ /* eslint-disable */
140
+ const collapsedArray = extractAllPrintData(relevantFields);
141
+ if (collapsedArray.length === 0) {
142
+ return;
143
+ }
144
+ const content = "Lisäpainokset: " + collapsedArray.join('. - ') + ".";
145
+ relevantFields[0].subfields[0].value = content; // Keep the place
146
+
147
+ relevantFields.forEach((field, index) => {
148
+ if (index > 0) {
149
+ record.removeField(field);
150
+ return;
151
+ }
152
+ });
153
+ /* eslint-enable */
154
+ }
155
+ //# sourceMappingURL=mergeField500Lisapainokset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeField500Lisapainokset.js","names":["_default","description","validate","fix","record","res","message","valid","mergeLisapainokset","relevantFields","getRelevantFields","length","printData","extractAllPrintData","fields","filter","field","validLisapainosField","tag","subfields","code","value","match","fieldToPrintsString","replace","printPreference","getPrintPreference","findIndex","pp","mergePrintData","value1","value2","index1","print1","year1","split","index2","print2","year2","betterIndex","betterPrint","getBetterPrint","betterYear","getBetterYear","y1","y2","i1","i2","allPrintData","i","j","fieldsPrintData","currPrintData","printIndex","undefined","mergedPrintData","p","collapsedArray","content","join","forEach","index","removeField"],"sources":["../src/mergeField500Lisapainokset.js"],"sourcesContent":["export default function () {\n\n return {\n description: 'Merge 500 $a Lisäpainokset fields',\n validate, fix\n };\n\n function fix(record) {\n const res = {message: [], fix: [], valid: true};\n mergeLisapainokset(record);\n return res;\n }\n\n function validate(record) {\n const relevantFields = getRelevantFields(record);\n if (relevantFields.length < 2) {\n return {message: [], 'valid': true}; // No action required\n }\n\n const printData = extractAllPrintData(relevantFields);\n if (printData.length === 0) {\n return {message: ['There are issues, but the fixer can not fix them!'], 'valid': false}; // No action required\n }\n\n return {message: [`Fixer can merge ${relevantFields.length} 500 $a Lisäpainokset fields into one`], 'valid': false};\n }\n}\n\n\nfunction getRelevantFields(record) {\n return record.fields.filter(field => validLisapainosField(field));\n}\n\nfunction validLisapainosField(field) {\n // We are only interested in field 500 with a lone $a subfield.\n // Especially $9 FENNI<KEEP> should not be merged!\n if (field.tag !== '500' || field.subfields.length !== 1 || field.subfields[0].code !== 'a') {\n return false;\n }\n return field.subfields[0].value.match(/^(?:Lisäpainokset|Lisäpainos): (?:[1-9][0-9]*\\. (?:p\\.|painos|uppl\\.) [0-9]+\\.)(?: - [1-9][0-9]*\\. (?:p\\.|painos|uppl\\.) \\[?[0-9]+\\]?\\.)*$/u);\n}\n\nfunction fieldToPrintsString(field) {\n // Could this just be something on the lines of s/^\\S+ // ?\n return field.subfields[0].value.replace(/^(?:Lisäpainokset|Lisäpainos): /u, '').replace(/\\.$/u, '');\n}\n\nconst printPreference = ['painos', 'p.', 'upplaga', 'uppl.'];\nfunction getPrintPreference(value) {\n return printPreference.findIndex(pp => pp === value);\n}\n\nfunction mergePrintData(value1, value2) {\n const [index1, print1, year1] = value1.split(' ');\n const [index2, print2, year2] = value2.split(' ');\n\n const betterIndex = index1 ? index1 : index2; // just to cheat eslint...\n\n // merge print1 and print2\n const betterPrint = getBetterPrint(print1, print2);\n if (!betterPrint) {\n return null;\n }\n\n const betterYear = getBetterYear(year1, year2);\n if (!betterYear) {\n return null;\n }\n\n return `${betterIndex} ${betterPrint} ${betterYear}`;\n\n function getBetterYear(y1, y2) {\n if (y1 === y2 || y2 === `[${y1}]`) {\n return y1;\n }\n if (y1 === `[${y2}]`) {\n return y2;\n }\n return null;\n }\n\n function getBetterPrint(print1, print2) {\n if (print1 === print2) {\n return print1;\n }\n\n const i1 = getPrintPreference(print1);\n const i2 = getPrintPreference(print2);\n if (i1 === -1 || i2 === -1) {\n return null;\n }\n if (i1 <= i2) {\n return printPreference[i1];\n }\n return printPreference[i2];\n }\n\n}\n\n\nfunction extractAllPrintData(relevantFields) {\n /* eslint-disable */\n // Gather data about 500 $a Lisäpainokset.*\n let allPrintData = [];\n let i;\n let j;\n for (i=0; i < relevantFields.length; i++) {\n const value = fieldToPrintsString(relevantFields[i]);\n const fieldsPrintData = value.split('. - ');\n for (j=0; j < fieldsPrintData.length; j++) {\n let currPrintData = fieldsPrintData[j];\n // Example value: \"2. p. 2020\"\n const [ printIndex ] = currPrintData.split('.');\n if (allPrintData[printIndex] !== undefined) {\n if (allPrintData[printIndex] !== currPrintData ) {\n const mergedPrintData = mergePrintData(allPrintData[printIndex], currPrintData);\n if (!mergedPrintData) {\n return []; // reason for for-loops: exit function from within nested loops\n }\n currPrintData = mergedPrintData;\n }\n }\n allPrintData[printIndex] = currPrintData;\n }\n };\n return allPrintData.filter(p => p !== undefined);\n}\n\n\nexport function mergeLisapainokset(record) {\n const relevantFields = getRelevantFields(record);\n if (relevantFields.length < 2) {\n return;\n }\n\n /* eslint-disable */\n const collapsedArray = extractAllPrintData(relevantFields);\n if (collapsedArray.length === 0) {\n return;\n }\n\n const content = \"Lisäpainokset: \" + collapsedArray.join('. - ') + \".\";\n\n relevantFields[0].subfields[0].value = content; // Keep the place\n\n relevantFields.forEach((field,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