@natlibfi/marc-record-validators-melinda 12.0.0-alpha.9 → 12.1.0-alpha.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 (82) hide show
  1. package/dist/access-rights.test.js +1 -1
  2. package/dist/access-rights.test.js.map +1 -1
  3. package/dist/addMissingField337.test.js +1 -1
  4. package/dist/addMissingField337.test.js.map +1 -1
  5. package/dist/addMissingField338.test.js +1 -1
  6. package/dist/addMissingField338.test.js.map +1 -1
  7. package/dist/cyrillux-usemarcon-replacement.test.js +4 -7
  8. package/dist/cyrillux-usemarcon-replacement.test.js.map +2 -2
  9. package/dist/cyrillux.test.js +1 -1
  10. package/dist/cyrillux.test.js.map +1 -1
  11. package/dist/double-commas.test.js +1 -1
  12. package/dist/double-commas.test.js.map +1 -1
  13. package/dist/empty-fields.test.js +1 -1
  14. package/dist/empty-fields.test.js.map +1 -1
  15. package/dist/ending-punctuation.test.js +39 -19
  16. package/dist/ending-punctuation.test.js.map +2 -2
  17. package/dist/field-008-18-34-character-groups.test.js +1 -1
  18. package/dist/field-008-18-34-character-groups.test.js.map +1 -1
  19. package/dist/field-exclusion.test.js +11 -8
  20. package/dist/field-exclusion.test.js.map +2 -2
  21. package/dist/field-structure.test.js +1 -1
  22. package/dist/field-structure.test.js.map +1 -1
  23. package/dist/fields-present.test.js +1 -1
  24. package/dist/fields-present.test.js.map +1 -1
  25. package/dist/fixRelatorTerms.test.js +1 -1
  26. package/dist/fixRelatorTerms.test.js.map +1 -1
  27. package/dist/fixed-fields.test.js +29 -18
  28. package/dist/fixed-fields.test.js.map +2 -2
  29. package/dist/identical-fields.test.js +1 -1
  30. package/dist/identical-fields.test.js.map +1 -1
  31. package/dist/isbn-issn.js +1 -1
  32. package/dist/isbn-issn.js.map +2 -2
  33. package/dist/isbn-issn.test.js +9 -6
  34. package/dist/isbn-issn.test.js.map +2 -2
  35. package/dist/item-language.test.js +1 -1
  36. package/dist/item-language.test.js.map +2 -2
  37. package/dist/normalizeFieldForComparison.js +24 -0
  38. package/dist/normalizeFieldForComparison.js.map +2 -2
  39. package/dist/punctuation2.test.js +1 -1
  40. package/dist/punctuation2.test.js.map +1 -1
  41. package/dist/removeDuplicateDataFields.test.js +1 -1
  42. package/dist/removeDuplicateDataFields.test.js.map +1 -1
  43. package/dist/resolvable-ext-references-melinda.test.js +1 -1
  44. package/dist/resolvable-ext-references-melinda.test.js.map +2 -2
  45. package/dist/sort-tags.test.js +1 -1
  46. package/dist/sort-tags.test.js.map +1 -1
  47. package/dist/subfield-exclusion.test.js +1 -1
  48. package/dist/subfield-exclusion.test.js.map +1 -1
  49. package/dist/unicode-decomposition.test.js +1 -1
  50. package/dist/unicode-decomposition.test.js.map +1 -1
  51. package/dist/update-field-540.test.js +1 -1
  52. package/dist/update-field-540.test.js.map +1 -1
  53. package/dist/urn.test.js +1 -1
  54. package/dist/urn.test.js.map +1 -1
  55. package/package.json +15 -15
  56. package/src/access-rights.test.js +1 -1
  57. package/src/addMissingField337.test.js +1 -1
  58. package/src/addMissingField338.test.js +1 -1
  59. package/src/cyrillux-usemarcon-replacement.test.js +4 -9
  60. package/src/cyrillux.test.js +1 -1
  61. package/src/double-commas.test.js +1 -1
  62. package/src/empty-fields.test.js +1 -1
  63. package/src/ending-punctuation.test.js +28 -20
  64. package/src/field-008-18-34-character-groups.test.js +1 -1
  65. package/src/field-exclusion.test.js +10 -8
  66. package/src/field-structure.test.js +1 -1
  67. package/src/fields-present.test.js +1 -1
  68. package/src/fixRelatorTerms.test.js +1 -1
  69. package/src/fixed-fields.test.js +24 -18
  70. package/src/identical-fields.test.js +1 -1
  71. package/src/isbn-issn.js +1 -1
  72. package/src/isbn-issn.test.js +8 -6
  73. package/src/item-language.test.js +2 -2
  74. package/src/normalizeFieldForComparison.js +26 -0
  75. package/src/punctuation2.test.js +1 -1
  76. package/src/removeDuplicateDataFields.test.js +1 -1
  77. package/src/resolvable-ext-references-melinda.test.js +5 -5
  78. package/src/sort-tags.test.js +1 -1
  79. package/src/subfield-exclusion.test.js +1 -1
  80. package/src/unicode-decomposition.test.js +1 -1
  81. package/src/update-field-540.test.js +1 -1
  82. package/src/urn.test.js +1 -1
@@ -1,7 +1,7 @@
1
1
  import {describe, it} from 'node:test';
2
2
  import assert from 'node:assert';
3
3
  import {MarcRecord} from '@natlibfi/marc-record';
4
- import validatorFactory from '../src/fields-present.js';
4
+ import validatorFactory from './fields-present.js';
5
5
 
6
6
 
7
7
 
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert';
2
2
  import {MarcRecord} from '@natlibfi/marc-record';
3
- import validatorFactory from '../src/fixRelatorTerms.js';
3
+ import validatorFactory from './fixRelatorTerms.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
6
  import createDebugLogger from 'debug';
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert';
2
2
  import {MarcRecord} from '@natlibfi/marc-record';
3
- import validatorFactory from '../src/fixed-fields.js';
3
+ import validatorFactory from './fixed-fields.js';
4
4
  import {describe, it} from 'node:test';
5
5
 
6
6
 
@@ -27,11 +27,13 @@ describe('fixed-fields: language', () => {
27
27
  const validator = await validatorFactory([
28
28
  {leader: true, length: 6, rules: [{position: [0, 6], pattern: /[abcdefg]/u}]},
29
29
  {tag: /^FOO$/u, length: 12, rules: [{position: 0, pattern: /f/u}]},
30
- {tag: /^BAR$/u, length: 6, rules: [
31
- {position: 0, pattern: /[fb]/u},
32
- {position: 1, pattern: /a/u, dependencies: [{position: 0, pattern: /b/u}]},
33
- {position: [2, 3], pattern: /u/u, dependencies: [{position: 0, pattern: /[^b]/u}]}
34
- ]}
30
+ {
31
+ tag: /^BAR$/u, length: 6, rules: [
32
+ {position: 0, pattern: /[fb]/u},
33
+ {position: 1, pattern: /a/u, dependencies: [{position: 0, pattern: /b/u}]},
34
+ {position: [2, 3], pattern: /u/u, dependencies: [{position: 0, pattern: /[^b]/u}]}
35
+ ]
36
+ }
35
37
  ]);
36
38
  const record = new MarcRecord({
37
39
  leader: 'bacgfe',
@@ -56,11 +58,13 @@ describe('fixed-fields: language', () => {
56
58
  const validator = await validatorFactory([
57
59
  {leader: true, length: 6, rules: [{position: [0, 6], pattern: /[abcdefg]/u}]},
58
60
  {tag: /^FOO$/u, length: 12, rules: [{position: 0, pattern: /f/u}]},
59
- {tag: /^BAR$/u, length: 6, rules: [
60
- {position: 0, pattern: /[fb]/u},
61
- {position: 1, pattern: /a/u, dependencies: [{position: 0, pattern: /b/u}]},
62
- {position: [2, 3], pattern: /u/u, dependencies: [{position: 0, pattern: /[^a]/u}]}
63
- ]},
61
+ {
62
+ tag: /^BAR$/u, length: 6, rules: [
63
+ {position: 0, pattern: /[fb]/u},
64
+ {position: 1, pattern: /a/u, dependencies: [{position: 0, pattern: /b/u}]},
65
+ {position: [2, 3], pattern: /u/u, dependencies: [{position: 0, pattern: /[^a]/u}]}
66
+ ]
67
+ },
64
68
  {tag: /^FUB$/u, length: 5}
65
69
  ]);
66
70
  const record = new MarcRecord({
@@ -83,13 +87,15 @@ describe('fixed-fields: language', () => {
83
87
 
84
88
  const result = await validator.validate(record);
85
89
 
86
- assert.deepEqual(result, {valid: false, messages: [
87
- 'Leader has invalid values at positions: 3 (Rule index 0)',
88
- 'Field FOO has invalid values at positions: 0 (Rule index 0)',
89
- 'Field BAR has invalid values at positions: 1 (Rule index 1)',
90
- 'Field BAR has invalid values at positions: 2,3 (Rule index 2)',
91
- 'Field FUB has invalid length'
92
- ]});
90
+ assert.deepEqual(result, {
91
+ valid: false, messages: [
92
+ 'Leader has invalid values at positions: 3 (Rule index 0)',
93
+ 'Field FOO has invalid values at positions: 0 (Rule index 0)',
94
+ 'Field BAR has invalid values at positions: 1 (Rule index 1)',
95
+ 'Field BAR has invalid values at positions: 2,3 (Rule index 2)',
96
+ 'Field FUB has invalid length'
97
+ ]
98
+ });
93
99
  });
94
100
  });
95
101
  });
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert';
2
2
  import {MarcRecord} from '@natlibfi/marc-record';
3
- import validatorFactory from '../src/identical-fields.js';
3
+ import validatorFactory from './identical-fields.js';
4
4
  import {describe, it} from 'node:test';
5
5
 
6
6
  describe('identical-fields', () => {
package/src/isbn-issn.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import ISBN from 'isbn3';
2
- import validateISSN from '@natlibfi/issn-verify';
2
+ import {issn as validateISSN} from '@natlibfi/issn-verify';
3
3
 
4
4
  // handleInvalid: move invalid 020$a to 020$z, and invalid 022$a to 022$y
5
5
  export default ({hyphenateISBN = false, handleInvalid = false} = {}) => {
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert';
2
2
  import {MarcRecord} from '@natlibfi/marc-record';
3
- import validatorFactory from '../src/isbn-issn.js';
3
+ import validatorFactory from './isbn-issn.js';
4
4
  import {describe, it} from 'node:test';
5
5
 
6
6
  describe('isbn-issn', () => {
@@ -186,11 +186,13 @@ describe('isbn-issn', () => {
186
186
  });
187
187
  const result = await validator.validate(record);
188
188
 
189
- assert.deepEqual(result, {valid: false, messages: [
190
- 'ISBN (9789519155470) is not valid',
191
- 'ISBN (9068-31-372-X) is not valid',
192
- 'ISBN (386006004X) is not valid'
193
- ]});
189
+ assert.deepEqual(result, {
190
+ valid: false, messages: [
191
+ 'ISBN (9789519155470) is not valid',
192
+ 'ISBN (9068-31-372-X) is not valid',
193
+ 'ISBN (386006004X) is not valid'
194
+ ]
195
+ });
194
196
  });
195
197
 
196
198
  it.skip('Finds the record invalid (Missing ISBN)');
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert';
2
2
  import {MarcRecord} from '@natlibfi/marc-record';
3
- import validatorFactory from '../src/item-language.js';
3
+ import validatorFactory from './item-language.js';
4
4
  import {describe, it} from 'node:test';
5
5
 
6
6
  describe('item-language', () => {
@@ -17,7 +17,7 @@ describe('item-language', () => {
17
17
  assert.equal(err instanceof Error, true);
18
18
  assert.equal(err.message, 'No tagPattern provided');
19
19
  return true;
20
- });
20
+ });
21
21
  //await assert(validatorFactory()).to.be.rejectedWith(Error, 'No tagPattern provided');
22
22
  });
23
23
 
@@ -19,6 +19,9 @@ const debug = createDebugLogger('@natlibfi/melinda-marc-record-merge-reducers:no
19
19
  const debugDev = debug.extend('dev');
20
20
 
21
21
  export function isEnnakkotietoSubfieldG(subfield) {
22
+ if (valuelessSubfield(subfield)) {
23
+ return false;
24
+ }
22
25
  if (subfield.code !== 'g') {
23
26
  return false;
24
27
  }
@@ -116,6 +119,9 @@ function subfieldValueLowercase(value, subfieldCode, tag) {
116
119
  }
117
120
 
118
121
  function subfieldLowercase(sf, tag) {
122
+ if (valuelessSubfield(sf)) {
123
+ return;
124
+ }
119
125
  sf.value = subfieldValueLowercase(sf.value, sf.code, tag);
120
126
  }
121
127
 
@@ -148,6 +154,10 @@ function hack490SubfieldA(field) {
148
154
 
149
155
  // NB! This won't work, if the punctuation has not been stripped beforehand!
150
156
  function removeSarja(subfield) {
157
+ if (valuelessSubfield(subfield)) {
158
+ return;
159
+ }
160
+
151
161
  if (subfield.code !== 'a') {
152
162
  return;
153
163
  }
@@ -188,6 +198,9 @@ function normalizeISBN(field) {
188
198
  relevantSubfields.forEach(sf => normalizeIsbnSubfield(sf));
189
199
 
190
200
  function normalizeIsbnSubfield(sf) {
201
+ if (valuelessSubfield(sf)) {
202
+ return;
203
+ }
191
204
  //nvdebug(` ISBN-subfield? ${subfieldToString(sf)}`);
192
205
  sf.value = sf.value.replace(/-/ug, '');
193
206
  sf.value = sf.value.replace(/x/u, 'X');
@@ -202,6 +215,9 @@ function fieldSpecificHacks(field) {
202
215
 
203
216
  export function fieldTrimSubfieldValues(field) {
204
217
  field.subfields?.forEach((sf) => {
218
+ if (valuelessSubfield(sf)) {
219
+ return;
220
+ }
205
221
  sf.value = sf.value.replace(/^[ \t\n]+/u, '');
206
222
  sf.value = sf.value.replace(/[ \t\n]+$/u, '');
207
223
  sf.value = sf.value.replace(/[ \t\n]+/gu, ' ');
@@ -212,6 +228,9 @@ function fieldRemoveDecomposedDiacritics(field) {
212
228
  // Raison d'être/motivation: "Sirén" and diacriticless "Siren" might refer to a same surname, so this normalization
213
229
  // allows us to compare authors and avoid duplicate fields.
214
230
  field.subfields.forEach((sf) => {
231
+ if (valuelessSubfield(sf)) {
232
+ return;
233
+ }
215
234
  sf.value = removeDecomposedDiacritics(sf.value);
216
235
  });
217
236
  }
@@ -297,6 +316,9 @@ export function cloneAndNormalizeFieldForComparison(field) {
297
316
  return clonedField;
298
317
  }
299
318
  clonedField.subfields.forEach((sf) => { // Do this for all fields or some fields?
319
+ if (valuelessSubfield(sf)) {
320
+ return;
321
+ }
300
322
  sf.value = normalizeSubfieldValue(sf.value, sf.code, field.tag);
301
323
  sf.value = removeCharsThatDontCarryMeaning(sf.value, field.tag, sf.code);
302
324
  });
@@ -318,3 +340,7 @@ function fieldSkipNormalization(field) {
318
340
  }
319
341
  return false;
320
342
  }
343
+
344
+ function valuelessSubfield(sf) {
345
+ return sf.value === undefined;
346
+ }
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert';
2
2
  import {MarcRecord} from '@natlibfi/marc-record';
3
- import validatorFactory from '../src/punctuation2.js';
3
+ import validatorFactory from './punctuation2.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
6
  import createDebugLogger from 'debug';
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert';
2
2
  import {MarcRecord} from '@natlibfi/marc-record';
3
- import validatorFactory from '../src/removeDuplicateDataFields.js';
3
+ import validatorFactory from './removeDuplicateDataFields.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
6
  import createDebugLogger from 'debug';
@@ -3,7 +3,7 @@ import assert from 'node:assert';
3
3
  //import chaiAsPromised from 'chai-as-promised';
4
4
  import {MarcRecord} from '@natlibfi/marc-record';
5
5
  import fetchMock from 'fetch-mock';
6
- import * as testContext from '../src/resolvable-ext-references-melinda.js';
6
+ import * as testContext from './resolvable-ext-references-melinda.js';
7
7
  import {fixture5000, fixture9550, fixture1000} from '../test-fixtures/resolvable-ext-references-melinda.js';
8
8
  import {afterEach, beforeEach, describe, it} from 'node:test';
9
9
 
@@ -27,9 +27,9 @@ describe('resolvable-ext-references-melinda', () => {
27
27
 
28
28
  beforeEach(() => {
29
29
  fetchMock.mockGlobal(); // replace fetch with fetch-mock's implementation
30
- fetchMock.get(`${endpoint}${queryParam}5000`, { status: 200, headers: {}, body: fixture5000 })
31
- .get(`${endpoint}${queryParam}9550`, { status: 200, headers: {}, body: fixture9550 })
32
- .get(`${endpoint}${queryParam}1000`, { status: 200, headers: {}, body: fixture1000 });
30
+ fetchMock.get(`${endpoint}${queryParam}5000`, {status: 200, headers: {}, body: fixture5000})
31
+ .get(`${endpoint}${queryParam}9550`, {status: 200, headers: {}, body: fixture9550})
32
+ .get(`${endpoint}${queryParam}1000`, {status: 200, headers: {}, body: fixture1000});
33
33
 
34
34
  });
35
35
 
@@ -50,7 +50,7 @@ describe('resolvable-ext-references-melinda', () => {
50
50
  }
51
51
  catch (err) {
52
52
  assert.equal(err instanceof Error, true);
53
- assert.match(err.message, /^Cannot read propert/u) ;
53
+ assert.match(err.message, /^Cannot read propert/u);
54
54
  }
55
55
  //await assert(validator.validate()).to.be.rejectedWith(Error, /^Cannot read propert/u);
56
56
  });
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert';
2
2
  import {MarcRecord} from '@natlibfi/marc-record';
3
- import validatorFactory from '../src/sort-tags.js';
3
+ import validatorFactory from './sort-tags.js';
4
4
  import {describe, it} from 'node:test';
5
5
 
6
6
  describe('sort-tags', () => {
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert';
2
2
  import {MarcRecord} from '@natlibfi/marc-record';
3
- import validatorFactory from '../src/subfield-exclusion.js';
3
+ import validatorFactory from './subfield-exclusion.js';
4
4
  import {describe, it} from 'node:test';
5
5
 
6
6
  //chai.use(chaiAsPromised);
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert';
2
2
  import {MarcRecord} from '@natlibfi/marc-record';
3
- import validatorFactory from '../src/unicode-decomposition.js';
3
+ import validatorFactory from './unicode-decomposition.js';
4
4
  import {describe, it} from 'node:test';
5
5
 
6
6
  describe('unicode-decomposition', () => {
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert';
2
2
  import {MarcRecord} from '@natlibfi/marc-record';
3
- import validatorFactory from '../src/update-field-540.js';
3
+ import validatorFactory from './update-field-540.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
6
  import createDebugLogger from 'debug';
package/src/urn.test.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert';
2
2
  import {MarcRecord} from '@natlibfi/marc-record';
3
- import validatorFactory from '../src/urn.js';
3
+ import validatorFactory from './urn.js';
4
4
  import {READERS} from '@natlibfi/fixura';
5
5
  import generateTests from '@natlibfi/fixugen';
6
6
  import createDebugLogger from 'debug';