@natlibfi/marc-record-validators-melinda 12.0.0 → 12.0.1

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 (229) hide show
  1. package/dist/disambiguateSeriesStatements.test.js +1 -7
  2. package/dist/disambiguateSeriesStatements.test.js.map +2 -2
  3. package/dist/drop-terms.js +122 -0
  4. package/dist/drop-terms.js.map +7 -0
  5. package/dist/drop-terms.test.js +56 -0
  6. package/dist/drop-terms.test.js.map +7 -0
  7. package/dist/field-008-18-34-character-groups.test.js +1 -7
  8. package/dist/field-008-18-34-character-groups.test.js.map +2 -2
  9. package/dist/field-505-separators.test.js +1 -7
  10. package/dist/field-505-separators.test.js.map +2 -2
  11. package/dist/field-521-fix.test.js +1 -7
  12. package/dist/field-521-fix.test.js.map +2 -2
  13. package/dist/fix-33X.test.js +1 -1
  14. package/dist/fix-33X.test.js.map +1 -1
  15. package/dist/fix-country-codes.test.js +1 -7
  16. package/dist/fix-country-codes.test.js.map +2 -2
  17. package/dist/fix-sami-041.js +87 -0
  18. package/dist/fix-sami-041.js.map +7 -0
  19. package/dist/fix-sami-041.test.js +40 -0
  20. package/dist/fix-sami-041.test.js.map +7 -0
  21. package/dist/fixRelatorTerms.test.js +1 -7
  22. package/dist/fixRelatorTerms.test.js.map +2 -2
  23. package/dist/index.js +7 -1
  24. package/dist/index.js.map +2 -2
  25. package/dist/indicator-fixes.js +10 -0
  26. package/dist/indicator-fixes.js.map +2 -2
  27. package/dist/indicator-fixes.test.js +1 -7
  28. package/dist/indicator-fixes.test.js.map +2 -2
  29. package/dist/merge-fields.test.js +2 -7
  30. package/dist/merge-fields.test.js.map +2 -2
  31. package/dist/mergeField500Lisapainokset.test.js +1 -7
  32. package/dist/mergeField500Lisapainokset.test.js.map +2 -2
  33. package/dist/mergeRelatorTermFields.test.js +1 -7
  34. package/dist/mergeRelatorTermFields.test.js.map +2 -2
  35. package/dist/multiple-subfield-0.test.js +1 -7
  36. package/dist/multiple-subfield-0.test.js.map +2 -2
  37. package/dist/normalize-dashes.test.js +1 -7
  38. package/dist/normalize-dashes.test.js.map +2 -2
  39. package/dist/normalize-identifiers.test.js +1 -7
  40. package/dist/normalize-identifiers.test.js.map +2 -2
  41. package/dist/normalize-qualifying-information.test.js +1 -7
  42. package/dist/normalize-qualifying-information.test.js.map +2 -2
  43. package/dist/normalize-utf8-diacritics.test.js +1 -7
  44. package/dist/normalize-utf8-diacritics.test.js.map +2 -2
  45. package/dist/punctuation.test.js +1 -7
  46. package/dist/punctuation.test.js.map +2 -2
  47. package/dist/punctuation2.test.js +1 -7
  48. package/dist/punctuation2.test.js.map +2 -2
  49. package/dist/reindexSubfield6OccurenceNumbers.test.js +1 -7
  50. package/dist/reindexSubfield6OccurenceNumbers.test.js.map +2 -2
  51. package/dist/remove-041-zxx.js +56 -0
  52. package/dist/remove-041-zxx.js.map +7 -0
  53. package/dist/remove-041-zxx.test.js +40 -0
  54. package/dist/remove-041-zxx.test.js.map +7 -0
  55. package/dist/removeDuplicateDataFields.test.js +1 -7
  56. package/dist/removeDuplicateDataFields.test.js.map +2 -2
  57. package/dist/removeInferiorDataFields.js +1 -9
  58. package/dist/removeInferiorDataFields.js.map +2 -2
  59. package/dist/removeInferiorDataFields.test.js +1 -7
  60. package/dist/removeInferiorDataFields.test.js.map +2 -2
  61. package/dist/resolveOrphanedSubfield6s.js +1 -3
  62. package/dist/resolveOrphanedSubfield6s.js.map +2 -2
  63. package/dist/resolveOrphanedSubfield6s.test.js +1 -7
  64. package/dist/resolveOrphanedSubfield6s.test.js.map +2 -2
  65. package/dist/sanitize-vocabulary-source-codes.test.js +1 -7
  66. package/dist/sanitize-vocabulary-source-codes.test.js.map +2 -2
  67. package/dist/sortFields.js +16 -1
  68. package/dist/sortFields.js.map +2 -2
  69. package/dist/sortFields.test.js +1 -7
  70. package/dist/sortFields.test.js.map +2 -2
  71. package/dist/sortRelatorTerms.test.js +1 -7
  72. package/dist/sortRelatorTerms.test.js.map +2 -2
  73. package/dist/sortSubfields.js +3 -1
  74. package/dist/sortSubfields.js.map +2 -2
  75. package/dist/sortSubfields.test.js +1 -7
  76. package/dist/sortSubfields.test.js.map +2 -2
  77. package/dist/stripPunctuation.js +7 -4
  78. package/dist/stripPunctuation.js.map +2 -2
  79. package/dist/stripPunctuation.test.js +1 -7
  80. package/dist/stripPunctuation.test.js.map +2 -2
  81. package/dist/subfield6Utils.js +1 -13
  82. package/dist/subfield6Utils.js.map +2 -2
  83. package/dist/subfieldValueNormalizations.test.js +1 -7
  84. package/dist/subfieldValueNormalizations.test.js.map +2 -2
  85. package/dist/sync-007-and-300.test.js +1 -7
  86. package/dist/sync-007-and-300.test.js.map +2 -2
  87. package/dist/sync-language.js +103 -0
  88. package/dist/sync-language.js.map +7 -0
  89. package/dist/sync-language.test.js +40 -0
  90. package/dist/sync-language.test.js.map +7 -0
  91. package/dist/translate-terms.js +121 -85
  92. package/dist/translate-terms.js.map +3 -3
  93. package/dist/translate-terms.test.js +5 -8
  94. package/dist/translate-terms.test.js.map +2 -2
  95. package/dist/update-field-540.test.js +1 -7
  96. package/dist/update-field-540.test.js.map +2 -2
  97. package/dist/urn.test.js +1 -7
  98. package/dist/urn.test.js.map +2 -2
  99. package/package.json +8 -6
  100. package/src/disambiguateSeriesStatements.test.js +3 -8
  101. package/src/drop-terms.js +162 -0
  102. package/src/drop-terms.test.js +81 -0
  103. package/src/field-008-18-34-character-groups.test.js +3 -8
  104. package/src/field-505-separators.test.js +3 -8
  105. package/src/field-521-fix.test.js +3 -8
  106. package/src/fix-33X.test.js +1 -1
  107. package/src/fix-country-codes.test.js +3 -8
  108. package/src/fix-sami-041.js +113 -0
  109. package/src/fix-sami-041.test.js +52 -0
  110. package/src/fixRelatorTerms.test.js +3 -8
  111. package/src/index.js +8 -1
  112. package/src/indicator-fixes.js +12 -0
  113. package/src/indicator-fixes.test.js +3 -8
  114. package/src/merge-fields.test.js +3 -8
  115. package/src/mergeField500Lisapainokset.test.js +3 -8
  116. package/src/mergeRelatorTermFields.test.js +3 -8
  117. package/src/multiple-subfield-0.test.js +3 -8
  118. package/src/normalize-dashes.test.js +3 -8
  119. package/src/normalize-identifiers.test.js +3 -8
  120. package/src/normalize-qualifying-information.test.js +3 -8
  121. package/src/normalize-utf8-diacritics.test.js +3 -8
  122. package/src/punctuation.test.js +3 -8
  123. package/src/punctuation2.test.js +3 -8
  124. package/src/reindexSubfield6OccurenceNumbers.test.js +3 -8
  125. package/src/remove-041-zxx.js +85 -0
  126. package/src/remove-041-zxx.test.js +52 -0
  127. package/src/removeDuplicateDataFields.test.js +3 -8
  128. package/src/removeInferiorDataFields.js +7 -7
  129. package/src/removeInferiorDataFields.test.js +3 -8
  130. package/src/resolveOrphanedSubfield6s.js +3 -3
  131. package/src/resolveOrphanedSubfield6s.test.js +3 -8
  132. package/src/sanitize-vocabulary-source-codes.test.js +3 -8
  133. package/src/sortFields.js +20 -1
  134. package/src/sortFields.test.js +3 -8
  135. package/src/sortRelatorTerms.test.js +3 -8
  136. package/src/sortSubfields.js +3 -1
  137. package/src/sortSubfields.test.js +3 -8
  138. package/src/stripPunctuation.js +9 -6
  139. package/src/stripPunctuation.test.js +3 -8
  140. package/src/subfield6Utils.js +13 -13
  141. package/src/subfieldValueNormalizations.test.js +3 -8
  142. package/src/sync-007-and-300.test.js +3 -8
  143. package/src/sync-language.js +148 -0
  144. package/src/sync-language.test.js +52 -0
  145. package/src/translate-terms.js +158 -103
  146. package/src/translate-terms.test.js +12 -16
  147. package/src/update-field-540.test.js +3 -8
  148. package/src/urn.test.js +3 -8
  149. package/test-fixtures/drop-terms/01/expectedResult.json +31 -0
  150. package/test-fixtures/drop-terms/01/metadata.json +6 -0
  151. package/test-fixtures/drop-terms/01/record.json +35 -0
  152. package/test-fixtures/drop-terms/02/expectedResult.json +7 -0
  153. package/test-fixtures/drop-terms/02/metadata.json +6 -0
  154. package/test-fixtures/drop-terms/02/record.json +40 -0
  155. package/test-fixtures/drop-terms/03/expectedResult.json +6 -0
  156. package/test-fixtures/drop-terms/03/metadata.json +18 -0
  157. package/test-fixtures/drop-terms/03/record.json +39 -0
  158. package/test-fixtures/drop-terms/04/expectedResult.json +6 -0
  159. package/test-fixtures/drop-terms/04/metadata.json +19 -0
  160. package/test-fixtures/drop-terms/04/record.json +24 -0
  161. package/test-fixtures/fix-language-codes/02/metadata.json +1 -1
  162. package/test-fixtures/fix-sami-041/01/expectedResult.json +6 -0
  163. package/test-fixtures/fix-sami-041/01/metadata.json +4 -0
  164. package/test-fixtures/fix-sami-041/01/record.json +13 -0
  165. package/test-fixtures/fix-sami-041/02/expectedResult.json +10 -0
  166. package/test-fixtures/fix-sami-041/02/metadata.json +4 -0
  167. package/test-fixtures/fix-sami-041/02/record.json +8 -0
  168. package/test-fixtures/fix-sami-041/03/expectedResult.json +5 -0
  169. package/test-fixtures/fix-sami-041/03/metadata.json +5 -0
  170. package/test-fixtures/fix-sami-041/03/record.json +8 -0
  171. package/test-fixtures/fix-sami-041/04/expectedResult.json +7 -0
  172. package/test-fixtures/fix-sami-041/04/metadata.json +4 -0
  173. package/test-fixtures/fix-sami-041/04/record.json +10 -0
  174. package/test-fixtures/fix-sami-041/05/expectedResult.json +10 -0
  175. package/test-fixtures/fix-sami-041/05/metadata.json +6 -0
  176. package/test-fixtures/fix-sami-041/05/record.json +8 -0
  177. package/test-fixtures/indicator-fixes/11/expectedResult.json +10 -0
  178. package/test-fixtures/indicator-fixes/11/metadata.json +4 -0
  179. package/test-fixtures/indicator-fixes/11/record.json +10 -0
  180. package/test-fixtures/merge-fields/f05/metadata.json +1 -1
  181. package/test-fixtures/remove-041-zxx/01/expectedResult.json +5 -0
  182. package/test-fixtures/remove-041-zxx/01/metadata.json +5 -0
  183. package/test-fixtures/remove-041-zxx/01/record.json +10 -0
  184. package/test-fixtures/remove-041-zxx/02/expectedResult.json +7 -0
  185. package/test-fixtures/remove-041-zxx/02/metadata.json +5 -0
  186. package/test-fixtures/remove-041-zxx/02/record.json +9 -0
  187. package/test-fixtures/remove-041-zxx/11/expectedResult.json +10 -0
  188. package/test-fixtures/remove-041-zxx/11/metadata.json +5 -0
  189. package/test-fixtures/remove-041-zxx/11/record.json +9 -0
  190. package/test-fixtures/remove-041-zxx/12/expectedResult.json +10 -0
  191. package/test-fixtures/remove-041-zxx/12/metadata.json +5 -0
  192. package/test-fixtures/remove-041-zxx/12/record.json +9 -0
  193. package/test-fixtures/sort-fields/15/input.json +9 -0
  194. package/test-fixtures/sort-fields/15/metadata.json +5 -0
  195. package/test-fixtures/sort-fields/15/result.json +10 -0
  196. package/test-fixtures/sync-language/01/expectedResult.json +5 -0
  197. package/test-fixtures/sync-language/01/metadata.json +5 -0
  198. package/test-fixtures/sync-language/01/record.json +7 -0
  199. package/test-fixtures/sync-language/02/expectedResult.json +6 -0
  200. package/test-fixtures/sync-language/02/metadata.json +5 -0
  201. package/test-fixtures/sync-language/02/record.json +10 -0
  202. package/test-fixtures/sync-language/03/expectedResult.json +6 -0
  203. package/test-fixtures/sync-language/03/metadata.json +5 -0
  204. package/test-fixtures/sync-language/03/record.json +6 -0
  205. package/test-fixtures/sync-language/10/expectedResult.json +10 -0
  206. package/test-fixtures/sync-language/10/metadata.json +5 -0
  207. package/test-fixtures/sync-language/10/record.json +8 -0
  208. package/test-fixtures/sync-language/11/expectedResult.json +10 -0
  209. package/test-fixtures/sync-language/11/metadata.json +5 -0
  210. package/test-fixtures/sync-language/11/record.json +7 -0
  211. package/test-fixtures/sync-language/12/expectedResult.json +9 -0
  212. package/test-fixtures/sync-language/12/metadata.json +6 -0
  213. package/test-fixtures/sync-language/12/record.json +6 -0
  214. package/test-fixtures/sync-language/13/expectedResult.json +10 -0
  215. package/test-fixtures/sync-language/13/metadata.json +5 -0
  216. package/test-fixtures/sync-language/13/record.json +8 -0
  217. package/test-fixtures/sync-language/14/expectedResult.json +9 -0
  218. package/test-fixtures/sync-language/14/metadata.json +5 -0
  219. package/test-fixtures/sync-language/14/record.json +7 -0
  220. package/test-fixtures/sync-language/15/expectedResult.json +9 -0
  221. package/test-fixtures/sync-language/15/metadata.json +5 -0
  222. package/test-fixtures/sync-language/15/record.json +7 -0
  223. package/test-fixtures/translate-terms/05/expectedResult.json +12 -0
  224. package/test-fixtures/translate-terms/05/metadata.json +7 -0
  225. package/test-fixtures/translate-terms/05/record.json +11 -0
  226. package/test-fixtures/translate-terms/06/expectedResult.json +12 -0
  227. package/test-fixtures/translate-terms/06/metadata.json +7 -0
  228. package/test-fixtures/translate-terms/06/record.json +11 -0
  229. package/test-fixtures/translate-terms-data.js +23 -0
@@ -0,0 +1,52 @@
1
+ import assert from 'node:assert/strict';
2
+ //import createDebugLogger from 'debug';
3
+
4
+ import validatorFactory from './fix-sami-041.js';
5
+
6
+ import {MarcRecord} from '@natlibfi/marc-record';
7
+ import {READERS} from '@natlibfi/fixura';
8
+ import generateTests from '@natlibfi/fixugen';
9
+
10
+ generateTests({
11
+ callback,
12
+ path: [import.meta.dirname, '..', 'test-fixtures', 'fix-sami-041'],
13
+ useMetadataFile: true,
14
+ recurse: false,
15
+ fixura: {
16
+ reader: READERS.JSON
17
+ },
18
+ hooks: {
19
+ before: async () => {
20
+ testValidatorFactory();
21
+ }
22
+ }
23
+ });
24
+
25
+ //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/drop-terms:test');
26
+
27
+ async function testValidatorFactory() {
28
+ const validator = await validatorFactory();
29
+
30
+ assert.equal(typeof validator, 'object');
31
+ assert.equal(typeof validator.description, 'string');
32
+ assert.equal(typeof validator.validate, 'function');
33
+ }
34
+
35
+ async function callback({getFixture, fix = false}) {
36
+ const validator = await validatorFactory();
37
+ const record = new MarcRecord(getFixture('record.json'));
38
+ const expectedResult = getFixture('expectedResult.json');
39
+ //const expectedResult = new MarcRecord(getFixture('expectedResult.json'));
40
+ // console.log(expectedResult); // eslint-disable-line
41
+
42
+ if (!fix) {
43
+ const result = await validator.validate(record);
44
+ assert.deepEqual(result, expectedResult);
45
+ const originalRecord = new MarcRecord(getFixture('record.json'));
46
+ assert.deepEqual(record, originalRecord); // The record should now change in validation-only
47
+ return;
48
+ }
49
+
50
+ await validator.fix(record);
51
+ assert.deepEqual(record, new MarcRecord(expectedResult));
52
+ }
@@ -3,7 +3,7 @@ import {MarcRecord} from '@natlibfi/marc-record';
3
3
  import validatorFactory from './fixRelatorTerms.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
- import createDebugLogger from 'debug';
6
+ //import createDebugLogger from 'debug';
7
7
 
8
8
  generateTests({
9
9
  callback,
@@ -20,7 +20,7 @@ generateTests({
20
20
  }
21
21
  });
22
22
 
23
- const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/fixRelatorTerms:test');
23
+ //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/fixRelatorTerms:test');
24
24
 
25
25
  async function testValidatorFactory() {
26
26
  const validator = await validatorFactory();
@@ -30,12 +30,7 @@ async function testValidatorFactory() {
30
30
  assert.equal(typeof validator.validate, 'function');
31
31
  }
32
32
 
33
- async function callback({getFixture, enabled = true, fix = false}) {
34
- if (enabled === false) {
35
- debug('TEST SKIPPED!');
36
- return;
37
- }
38
-
33
+ async function callback({getFixture, fix = false}) {
39
34
  const validator = await validatorFactory();
40
35
  const record = new MarcRecord(getFixture('record.json'));
41
36
  const expectedResult = getFixture('expectedResult.json');
package/src/index.js CHANGED
@@ -21,6 +21,7 @@ import Fix33X from './fix-33X.js';
21
21
  import FixCountryCodes from './fix-country-codes.js';
22
22
  import FixLanguageCodes from './fix-language-codes.js';
23
23
  import FixRelatorTerms from './fixRelatorTerms.js';
24
+ import FixSami041 from './fix-sami-041.js';
24
25
  import FixedFields from './fixed-fields.js';
25
26
  import IdenticalFields from './identical-fields.js';
26
27
  import IndicatorFixes from './indicator-fixes.js';
@@ -39,6 +40,7 @@ import NormalizeUTF8Diacritics from './normalize-utf8-diacritics.js';
39
40
  import Punctuation from './punctuation/index.js';
40
41
  import Punctuation2 from './punctuation2.js';
41
42
  import ReindexSubfield6OccurenceNumbers from './reindexSubfield6OccurenceNumbers.js';
43
+ import Remove041zxx from './remove-041-zxx.js';
42
44
  import RemoveDuplicateDataFields from './removeDuplicateDataFields.js';
43
45
  import RemoveInferiorDataFields from './removeInferiorDataFields.js';
44
46
  import ResolvableExtReferences from './resolvable-ext-references-melinda.js';
@@ -52,6 +54,7 @@ import SortTags from './sort-tags.js';
52
54
  import SubfieldValueNormalizations from './subfieldValueNormalizations.js';
53
55
  import SubfieldExclusion from './subfield-exclusion.js';
54
56
  import Sync007And300 from './sync-007-and-300.js';
57
+ import SyncLanguage from './sync-language.js';
55
58
  import TranslateTerms from './translate-terms.js';
56
59
  import TypeOfDateF008 from './typeOfDate-008.js';
57
60
  import UnicodeDecomposition from './unicode-decomposition.js';
@@ -105,11 +108,13 @@ export {
105
108
  FixCountryCodes,
106
109
  FixLanguageCodes,
107
110
  FixRelatorTerms,
111
+ FixSami041,
108
112
  FixedFields,
109
113
  IdenticalFields,
110
114
  IndicatorFixes,
111
115
  IsbnIssn,
112
116
  ItemLanguage,
117
+
113
118
  MergeField500Lisapainokset,
114
119
  MergeRelatorTermFields,
115
120
  Modernize502, //
@@ -123,6 +128,7 @@ export {
123
128
  Punctuation2,
124
129
  ResolveOrphanedSubfield6s, // Do this before reindexing! (thus I'm not sticking with alphabetical order here)
125
130
  ReindexSubfield6OccurenceNumbers,
131
+ Remove041zxx,
126
132
  RemoveDuplicateDataFields,
127
133
  RemoveInferiorDataFields,
128
134
  ResolvableExtReferences,
@@ -133,8 +139,9 @@ export {
133
139
  SubfieldExclusion,
134
140
  SubfieldValueNormalizations,
135
141
  Sync007And300,
136
- TypeOfDateF008,
142
+ SyncLanguage,
137
143
  TranslateTerms,
144
+ TypeOfDateF008,
138
145
  UnicodeDecomposition,
139
146
  UpdateField540,
140
147
  Urn,
@@ -241,6 +241,17 @@ function getLanguages(record) {
241
241
 
242
242
  }
243
243
 
244
+ function translated041Indicator1(field){
245
+ if (field.tag !== '041' || !field.subfields) {
246
+ return;
247
+ }
248
+ if (field.ind1 !== '1' && field.subfields.some(sf => ['h', 'k', 'm', 'n'].includes(sf.code))) {
249
+ field.ind1 = '1';
250
+ return;
251
+ }
252
+
253
+ }
254
+
244
255
  function recordNormalizeIndicators(record) {
245
256
  recordNormalize490(record);
246
257
 
@@ -252,6 +263,7 @@ function recordNormalizeIndicators(record) {
252
263
  }
253
264
 
254
265
  function fieldNormalizeIndicators(field, record, languages) {
266
+ translated041Indicator1(field);
255
267
  normalize084Indicator1(field);
256
268
  normalize245Indicator1(field, record);
257
269
  noDisplayConstantGenerated520Indicator1(field);
@@ -3,7 +3,7 @@ import {MarcRecord} from '@natlibfi/marc-record';
3
3
  import validatorFactory from './indicator-fixes.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
- import createDebugLogger from 'debug';
6
+ //import createDebugLogger from 'debug';
7
7
 
8
8
  generateTests({
9
9
  callback,
@@ -17,7 +17,7 @@ generateTests({
17
17
  before: () => testValidatorFactory()
18
18
  }
19
19
  });
20
- const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/indicator-fixes:test');
20
+ //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/indicator-fixes:test');
21
21
 
22
22
  async function testValidatorFactory() {
23
23
  const validator = await validatorFactory();
@@ -27,12 +27,7 @@ async function testValidatorFactory() {
27
27
  assert.equal(typeof validator.validate, 'function');
28
28
  }
29
29
 
30
- async function callback({getFixture, enabled = true, fix = false}) {
31
- if (enabled === false) {
32
- debug('TEST SKIPPED!');
33
- return;
34
- }
35
-
30
+ async function callback({getFixture, fix = false}) {
36
31
  const validator = await validatorFactory();
37
32
  const record = new MarcRecord(getFixture('record.json'));
38
33
  const expectedResult = getFixture('expectedResult.json');
@@ -4,7 +4,7 @@ import validatorFactory from './merge-fields/index.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
6
  import createDebugLogger from 'debug';
7
- import { nvdebug } from './utils.js';
7
+
8
8
 
9
9
  generateTests({
10
10
  callback,
@@ -30,13 +30,8 @@ async function testValidatorFactory() {
30
30
  assert.equal(typeof validator.validate, 'function');
31
31
  }
32
32
 
33
- async function callback({getFixture, enabled = true, fix = false, tagPattern = false}) {
34
- if (enabled === false) {
35
- debug('TEST SKIPPED!');
36
- return;
37
- }
38
-
39
- nvdebug(`TAG PATTERN: ${tagPattern}`);
33
+ async function callback({getFixture, fix = false, tagPattern = false}) {
34
+ debug(`Run test using tag pattern ${tagPattern}`);
40
35
 
41
36
  const validator = await validatorFactory(tagPattern);
42
37
  const record = new MarcRecord(getFixture('record.json'));
@@ -3,7 +3,7 @@ import {MarcRecord} from '@natlibfi/marc-record';
3
3
  import validatorFactory from './mergeField500Lisapainokset.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
- import createDebugLogger from 'debug';
6
+ //import createDebugLogger from 'debug';
7
7
 
8
8
  generateTests({
9
9
  callback,
@@ -19,7 +19,7 @@ generateTests({
19
19
  }
20
20
  }
21
21
  });
22
- const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/mergeField500Lisapainokset:test');
22
+ //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/mergeField500Lisapainokset:test');
23
23
 
24
24
  async function testValidatorFactory() {
25
25
  const validator = await validatorFactory();
@@ -29,12 +29,7 @@ async function testValidatorFactory() {
29
29
  assert.equal(typeof validator.validate, 'function');
30
30
  }
31
31
 
32
- async function callback({getFixture, enabled = true, fix = false}) {
33
- if (enabled === false) {
34
- debug('TEST SKIPPED!');
35
- return;
36
- }
37
-
32
+ async function callback({getFixture, fix = false}) {
38
33
  const validator = await validatorFactory();
39
34
  const record = new MarcRecord(getFixture('record.json'));
40
35
  const expectedResult = getFixture('expectedResult.json');
@@ -3,7 +3,7 @@ import {MarcRecord} from '@natlibfi/marc-record';
3
3
  import validatorFactory from './mergeRelatorTermFields.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
- import createDebugLogger from 'debug';
6
+ //import createDebugLogger from 'debug';
7
7
 
8
8
  generateTests({
9
9
  callback,
@@ -19,7 +19,7 @@ generateTests({
19
19
  }
20
20
  }
21
21
  });
22
- const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/mergeRelatorTermFields:test');
22
+ //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/mergeRelatorTermFields:test');
23
23
 
24
24
  async function testValidatorFactory() {
25
25
  const validator = await validatorFactory();
@@ -29,12 +29,7 @@ async function testValidatorFactory() {
29
29
  assert.equal(typeof validator.validate, 'function');
30
30
  }
31
31
 
32
- async function callback({getFixture, enabled = true, fix = false}) {
33
- if (enabled === false) {
34
- debug('TEST SKIPPED!');
35
- return;
36
- }
37
-
32
+ async function callback({getFixture, fix = false}) {
38
33
  const validator = await validatorFactory();
39
34
  const record = new MarcRecord(getFixture('record.json'));
40
35
  const expectedResult = getFixture('expectedResult.json');
@@ -3,7 +3,7 @@ import {MarcRecord} from '@natlibfi/marc-record';
3
3
  import validatorFactory from './multiple-subfield-0.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
- import createDebugLogger from 'debug';
6
+ //import createDebugLogger from 'debug';
7
7
 
8
8
  generateTests({
9
9
  callback,
@@ -20,7 +20,7 @@ generateTests({
20
20
  }
21
21
  });
22
22
 
23
- const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/multiple-subfield-0:test');
23
+ //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/multiple-subfield-0:test');
24
24
 
25
25
  async function testValidatorFactory() {
26
26
  const validator = await validatorFactory();
@@ -30,12 +30,7 @@ async function testValidatorFactory() {
30
30
  assert.equal(typeof validator.validate, 'function');
31
31
  }
32
32
 
33
- async function callback({getFixture, enabled = true, fix = false}) {
34
- if (enabled === false) {
35
- debug('TEST SKIPPED!');
36
- return;
37
- }
38
-
33
+ async function callback({getFixture, fix = false}) {
39
34
  const validator = await validatorFactory();
40
35
  const record = new MarcRecord(getFixture('record.json'));
41
36
  const expectedResult = getFixture('expectedResult.json');
@@ -3,7 +3,7 @@ import {MarcRecord} from '@natlibfi/marc-record';
3
3
  import validatorFactory from './normalize-dashes.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
- import createDebugLogger from 'debug';
6
+ //import createDebugLogger from 'debug';
7
7
 
8
8
  generateTests({
9
9
  callback,
@@ -19,7 +19,7 @@ generateTests({
19
19
  }
20
20
  }
21
21
  });
22
- const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/normalize-dashes:test');
22
+ //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/normalize-dashes:test');
23
23
 
24
24
  async function testValidatorFactory() {
25
25
  const validator = await validatorFactory();
@@ -29,12 +29,7 @@ async function testValidatorFactory() {
29
29
  assert.equal(typeof validator.validate, 'function');
30
30
  }
31
31
 
32
- async function callback({getFixture, enabled = true, fix = false}) {
33
- if (enabled === false) {
34
- debug('TEST SKIPPED!');
35
- return;
36
- }
37
-
32
+ async function callback({getFixture, fix = false}) {
38
33
  const validator = await validatorFactory();
39
34
  const record = new MarcRecord(getFixture('record.json'));
40
35
  const expectedResult = getFixture('expectedResult.json');
@@ -3,7 +3,7 @@ import {MarcRecord} from '@natlibfi/marc-record';
3
3
  import validatorFactory from './normalize-identifiers.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
- import createDebugLogger from 'debug';
6
+ //import createDebugLogger from 'debug';
7
7
 
8
8
  generateTests({
9
9
  callback,
@@ -19,7 +19,7 @@ generateTests({
19
19
  }
20
20
  }
21
21
  });
22
- const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/normalize-identifiers:test');
22
+ //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/normalize-identifiers:test');
23
23
 
24
24
  async function testValidatorFactory() {
25
25
  const validator = await validatorFactory();
@@ -29,12 +29,7 @@ async function testValidatorFactory() {
29
29
  assert.equal(typeof validator.validate, 'function');
30
30
  }
31
31
 
32
- async function callback({getFixture, enabled = true, fix = false}) {
33
- if (enabled === false) {
34
- debug('TEST SKIPPED!');
35
- return;
36
- }
37
-
32
+ async function callback({getFixture, fix = false}) {
38
33
  const validator = await validatorFactory();
39
34
  const record = new MarcRecord(getFixture('record.json'));
40
35
  const expectedResult = getFixture('expectedResult.json');
@@ -3,7 +3,7 @@ import {MarcRecord} from '@natlibfi/marc-record';
3
3
  import validatorFactory from './normalize-qualifying-information.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
- import createDebugLogger from 'debug';
6
+ //import createDebugLogger from 'debug';
7
7
 
8
8
  generateTests({
9
9
  callback,
@@ -19,7 +19,7 @@ generateTests({
19
19
  }
20
20
  }
21
21
  });
22
- const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/normalize-qualifying-information:test');
22
+ //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/normalize-qualifying-information:test');
23
23
 
24
24
  async function testValidatorFactory() {
25
25
  const validator = await validatorFactory();
@@ -29,12 +29,7 @@ async function testValidatorFactory() {
29
29
  assert.equal(typeof validator.validate, 'function');
30
30
  }
31
31
 
32
- async function callback({getFixture, enabled = true, fix = false}) {
33
- if (enabled === false) {
34
- debug('TEST SKIPPED!');
35
- return;
36
- }
37
-
32
+ async function callback({getFixture, fix = false}) {
38
33
  const validator = await validatorFactory();
39
34
  const record = new MarcRecord(getFixture('record.json'));
40
35
  const expectedResult = getFixture('expectedResult.json');
@@ -3,7 +3,7 @@ import {MarcRecord} from '@natlibfi/marc-record';
3
3
  import validatorFactory from './normalize-utf8-diacritics.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
- import createDebugLogger from 'debug';
6
+ //import createDebugLogger from 'debug';
7
7
 
8
8
  generateTests({
9
9
  callback,
@@ -20,7 +20,7 @@ generateTests({
20
20
  }
21
21
  });
22
22
 
23
- const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/normalize-utf8-diacritics:test');
23
+ //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/normalize-utf8-diacritics:test');
24
24
 
25
25
  async function testValidatorFactory() {
26
26
  const validator = await validatorFactory();
@@ -30,12 +30,7 @@ async function testValidatorFactory() {
30
30
  assert.equal(typeof validator.validate, 'function');
31
31
  }
32
32
 
33
- async function callback({getFixture, enabled = true, fix = false}) {
34
- if (enabled === false) {
35
- debug('TEST SKIPPED!');
36
- return;
37
- }
38
-
33
+ async function callback({getFixture, fix = false}) {
39
34
  const validator = await validatorFactory();
40
35
  const record = new MarcRecord(getFixture('record.json'));
41
36
  const expectedResult = getFixture('expectedResult.json');
@@ -3,7 +3,7 @@ import {MarcRecord} from '@natlibfi/marc-record';
3
3
  import validatorFactory from './punctuation/index.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
- import createDebugLogger from 'debug';
6
+ //import createDebugLogger from 'debug';
7
7
 
8
8
  generateTests({
9
9
  callback,
@@ -19,7 +19,7 @@ generateTests({
19
19
  }
20
20
  }
21
21
  });
22
- const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/punctuation:test');
22
+ //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/punctuation:test');
23
23
 
24
24
  async function testValidatorFactory() {
25
25
  const validator = await validatorFactory();
@@ -29,12 +29,7 @@ async function testValidatorFactory() {
29
29
  assert.equal(typeof validator.validate, 'function');
30
30
  }
31
31
 
32
- async function callback({getFixture, enabled = true, fix = false}) {
33
- if (enabled === false) {
34
- debug('TEST SKIPPED!');
35
- return;
36
- }
37
-
32
+ async function callback({getFixture, fix = false}) {
38
33
  const validator = await validatorFactory();
39
34
  const record = new MarcRecord(getFixture('record.json'));
40
35
  const expectedResult = getFixture('expectedResult.json');
@@ -3,7 +3,7 @@ import {MarcRecord} from '@natlibfi/marc-record';
3
3
  import validatorFactory from './punctuation2.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
- import createDebugLogger from 'debug';
6
+ //import createDebugLogger from 'debug';
7
7
 
8
8
  generateTests({
9
9
  callback,
@@ -19,7 +19,7 @@ generateTests({
19
19
  }
20
20
  }
21
21
  });
22
- const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/punctuation2:test');
22
+ //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/punctuation2:test');
23
23
 
24
24
  async function testValidatorFactory() {
25
25
  const validator = await validatorFactory();
@@ -29,12 +29,7 @@ async function testValidatorFactory() {
29
29
  assert.equal(typeof validator.validate, 'function');
30
30
  }
31
31
 
32
- async function callback({getFixture, enabled = true, fix = false}) {
33
- if (enabled === false) {
34
- debug('TEST SKIPPED!');
35
- return;
36
- }
37
-
32
+ async function callback({getFixture, fix = false}) {
38
33
  const validator = await validatorFactory();
39
34
  const record = new MarcRecord(getFixture('record.json'));
40
35
  const expectedResult = getFixture('expectedResult.json');
@@ -3,7 +3,7 @@ import {MarcRecord} from '@natlibfi/marc-record';
3
3
  import validatorFactory from './reindexSubfield6OccurenceNumbers.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
- import createDebugLogger from 'debug';
6
+ //import createDebugLogger from 'debug';
7
7
 
8
8
  generateTests({
9
9
  callback,
@@ -19,7 +19,7 @@ generateTests({
19
19
  }
20
20
  }
21
21
  });
22
- const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/reindexSubfield6OccurrenceNumbers:test');
22
+ //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/reindexSubfield6OccurrenceNumbers:test');
23
23
 
24
24
  async function testValidatorFactory() {
25
25
  const validator = await validatorFactory();
@@ -29,12 +29,7 @@ async function testValidatorFactory() {
29
29
  assert.equal(typeof validator.validate, 'function');
30
30
  }
31
31
 
32
- async function callback({getFixture, enabled = true, fix = false}) {
33
- if (enabled === false) {
34
- debug('TEST SKIPPED!');
35
- return;
36
- }
37
-
32
+ async function callback({getFixture, fix = false}) {
38
33
  const validator = await validatorFactory();
39
34
  const record = new MarcRecord(getFixture('record.json'));
40
35
  const expectedResult = getFixture('expectedResult.json');
@@ -0,0 +1,85 @@
1
+ /*
2
+ // remove-041-zxx.js
3
+ //
4
+ // https://wiki.helsinki.fi/xwiki/bin/view/rdasovellusohje/RDA-kuvailu%20MARC%2021%20-formaatilla/RDA-sovellusohje/008%20Kontrollikentt%C3%A4/#Hmp.35-37Kieli
5
+ // "008-kielikoodi on sama kuin ensimmäinen 041-kentän a- (tai d-) osakenttä. Poikkeuksen muodostaa koodi zxx:
6
+ // jos tietueen 008ssa on kielikoodi zxx (ei kielellistä sisältöä, esim. soitinmusiikki), tietueessa ei voi olla 041 a- eikä d-osakenttää."
7
+ // Effectively this means, that 'zxx' does not appear in 041!
8
+ // Author(s): Nicholas Volk
9
+ */
10
+
11
+ //import createDebugLogger from 'debug';
12
+ import clone from 'clone';
13
+
14
+ import {fieldToString} from './utils.js';
15
+
16
+ // const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda:remove-041-zxx');
17
+
18
+
19
+
20
+
21
+ export default function () {
22
+
23
+ return {
24
+ description: "Remove 'zxx' from f041",
25
+ validate, fix
26
+ };
27
+
28
+ function zxxRemoval041(record, validateMode) {
29
+ const fields041 = record.fields.filter(f => f.tag === '041');
30
+
31
+ return handleZxx(fields041);
32
+
33
+ function handleZxx(fields, result = []) {
34
+ const [currField, ...remainingFields] = fields;
35
+ if ( !currField) {
36
+ return result;
37
+ }
38
+ // Theoretically 'zxx' might mean something in ISO-639-3 or some other language code list:
39
+ if (!currField.subfields || currField.subfields.some(sf => sf.code === '2')) {
40
+ return handleZxx(remainingFields, result);
41
+ }
42
+ // Presumable 'zxx' is bad in any data subfield, not just 'a' and 'd':
43
+ const otherSubfields = currField.subfields.filter(sf => (!sf.code.match(/^[a-z]$/u) || sf.value !== 'zxx'));
44
+ if (otherSubfields.length === currField.subfields.length) {
45
+ return handleZxx(remainingFields, result);
46
+ }
47
+ const originalString = fieldToString(currField);
48
+ if (otherSubfields.length === 0) {
49
+ const message = `Remove '${originalString}'`;
50
+ if (!validateMode) {
51
+ record.removeField(currField);
52
+ }
53
+ return handleZxx(remainingFields, [...result, message]);
54
+ }
55
+ // Some subfields are removed:
56
+ if (validateMode) {
57
+ // NB! In validation field is not really deleted, and the non-deleted field might trigger other fixes (than won't be done to a deleted field) later on
58
+ const clonedField = clone(currField);
59
+ clonedField.subfields = otherSubfields;
60
+ const modifiedString = fieldToString(clonedField);
61
+ const message = `Modify '${originalString}' => '${modifiedString}`;
62
+ return handleZxx(remainingFields, [...result, message]);
63
+ }
64
+ currField.subfields = otherSubfields;
65
+ const modifiedString = fieldToString(currField);
66
+ const message = `Modify '${originalString}' => '${modifiedString}`;
67
+ return handleZxx(remainingFields, [...result, message]);
68
+ }
69
+ }
70
+
71
+ function fix(record, validateMode = false) {
72
+ const messages = zxxRemoval041(record, validateMode);
73
+
74
+ if (validateMode) {
75
+ return {message: messages, valid: messages.length === 0};
76
+ }
77
+ return {message: [], fix: messages, valid: true};
78
+ }
79
+
80
+
81
+ function validate(record) {
82
+ return fix(record, true);
83
+ }
84
+ }
85
+