@natlibfi/marc-record-validators-melinda 13.0.2 → 13.0.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 (99) hide show
  1. package/dist/cyrillux-usemarcon-replacement.js +2 -3
  2. package/dist/cyrillux-usemarcon-replacement.js.map +2 -2
  3. package/dist/cyrillux.js +4 -5
  4. package/dist/cyrillux.js.map +2 -2
  5. package/dist/disambiguateSeriesStatements.js +1 -3
  6. package/dist/disambiguateSeriesStatements.js.map +2 -2
  7. package/dist/drop-terms.js +1 -2
  8. package/dist/drop-terms.js.map +2 -2
  9. package/dist/field-008-18-34-character-groups.js +1 -2
  10. package/dist/field-008-18-34-character-groups.js.map +2 -2
  11. package/dist/field-505-separators.js +1 -2
  12. package/dist/field-505-separators.js.map +2 -2
  13. package/dist/field-521-fix.js +1 -2
  14. package/dist/field-521-fix.js.map +2 -2
  15. package/dist/fix-33X.js +1 -2
  16. package/dist/fix-33X.js.map +2 -2
  17. package/dist/fix-language-codes.js +1 -2
  18. package/dist/fix-language-codes.js.map +2 -2
  19. package/dist/fix-sami-041.js +2 -3
  20. package/dist/fix-sami-041.js.map +2 -2
  21. package/dist/fixRelatorTerms.js +1 -2
  22. package/dist/fixRelatorTerms.js.map +2 -2
  23. package/dist/identical-fields.js +2 -2
  24. package/dist/identical-fields.js.map +2 -2
  25. package/dist/mergeRelatorTermFields.js +3 -4
  26. package/dist/mergeRelatorTermFields.js.map +2 -2
  27. package/dist/modernize-502.js +1 -2
  28. package/dist/modernize-502.js.map +2 -2
  29. package/dist/multiple-subfield-0.js.map +2 -2
  30. package/dist/normalize-dashes.js +1 -2
  31. package/dist/normalize-dashes.js.map +2 -2
  32. package/dist/normalize-identifiers.js +1 -2
  33. package/dist/normalize-identifiers.js.map +2 -2
  34. package/dist/normalize-qualifying-information.js +1 -2
  35. package/dist/normalize-qualifying-information.js.map +2 -2
  36. package/dist/normalize-utf8-diacritics.js +1 -2
  37. package/dist/normalize-utf8-diacritics.js.map +2 -2
  38. package/dist/normalizeFieldForComparison.js +1 -2
  39. package/dist/normalizeFieldForComparison.js.map +2 -2
  40. package/dist/punctuation/index.js +3 -8
  41. package/dist/punctuation/index.js.map +2 -2
  42. package/dist/punctuation2.js +1 -2
  43. package/dist/punctuation2.js.map +2 -2
  44. package/dist/remove-041-zxx.js +1 -2
  45. package/dist/remove-041-zxx.js.map +2 -2
  46. package/dist/sanitize-vocabulary-source-codes.js +1 -2
  47. package/dist/sanitize-vocabulary-source-codes.js.map +2 -2
  48. package/dist/sortFields.js +1 -2
  49. package/dist/sortFields.js.map +2 -2
  50. package/dist/sortRelatorTerms.js +1 -2
  51. package/dist/sortRelatorTerms.js.map +2 -2
  52. package/dist/sortSubfields.js +1 -2
  53. package/dist/sortSubfields.js.map +2 -2
  54. package/dist/subfieldValueNormalizations.js +1 -2
  55. package/dist/subfieldValueNormalizations.js.map +2 -2
  56. package/dist/sync-007-and-300.js +1 -2
  57. package/dist/sync-007-and-300.js.map +2 -2
  58. package/dist/sync-language.js +2 -3
  59. package/dist/sync-language.js.map +2 -2
  60. package/dist/translate-terms.js +1 -2
  61. package/dist/translate-terms.js.map +2 -2
  62. package/package.json +2 -2
  63. package/src/cyrillux-usemarcon-replacement.js +3 -3
  64. package/src/cyrillux.js +5 -5
  65. package/src/disambiguateSeriesStatements.js +2 -3
  66. package/src/drop-terms.js +2 -2
  67. package/src/field-008-18-34-character-groups.js +2 -2
  68. package/src/field-505-separators.js +2 -2
  69. package/src/field-521-fix.js +2 -2
  70. package/src/fix-33X.js +2 -2
  71. package/src/fix-language-codes.js +2 -2
  72. package/src/fix-sami-041.js +3 -3
  73. package/src/fixRelatorTerms.js +2 -2
  74. package/src/identical-fields.js +2 -3
  75. package/src/mergeRelatorTermFields.js +4 -4
  76. package/src/modernize-502.js +2 -2
  77. package/src/multiple-subfield-0.js +0 -1
  78. package/src/normalize-dashes.js +2 -2
  79. package/src/normalize-identifiers.js +2 -2
  80. package/src/normalize-qualifying-information.js +1 -2
  81. package/src/normalize-utf8-diacritics.js +2 -2
  82. package/src/normalizeFieldForComparison.js +3 -3
  83. package/src/punctuation/index.js +4 -9
  84. package/src/punctuation2.js +2 -2
  85. package/src/remove-041-zxx.js +2 -2
  86. package/src/sanitize-vocabulary-source-codes.js +2 -2
  87. package/src/sortFields.js +2 -2
  88. package/src/sortRelatorTerms.js +2 -2
  89. package/src/sortSubfields.js +2 -2
  90. package/src/subfieldValueNormalizations.js +2 -2
  91. package/src/sync-007-and-300.js +2 -2
  92. package/src/sync-language.js +2 -3
  93. package/src/translate-terms.js +1 -3
  94. package/dist/sort-tags.js +0 -41
  95. package/dist/sort-tags.js.map +0 -7
  96. package/dist/sort-tags.test.js +0 -261
  97. package/dist/sort-tags.test.js.map +0 -7
  98. package/src/sort-tags.js +0 -48
  99. package/src/sort-tags.test.js +0 -265
@@ -1,4 +1,4 @@
1
- import clone from 'clone';
1
+
2
2
  import {fieldToString, nvdebug} from './utils.js';
3
3
  import createDebugLogger from 'debug';
4
4
 
@@ -73,7 +73,7 @@ export default function () {
73
73
 
74
74
  function validateField041(field, res) {
75
75
 
76
- const clonedField = clone(field);
76
+ const clonedField = structuredClone(field);
77
77
  fixField041(clonedField);
78
78
 
79
79
  const originalString = fieldToString(field);
@@ -1,7 +1,7 @@
1
1
  // Author(s): Nicholas Volk
2
2
 
3
3
  import createDebugLogger from 'debug';
4
- import clone from 'clone';
4
+
5
5
 
6
6
  import {fieldToString, nvdebug} from './utils.js';
7
7
 
@@ -39,7 +39,7 @@ export default function () {
39
39
  nvdebug(`Start ${validateMode ? 'validator' : 'fixer'}`, debugDev);
40
40
  const relevantSubfieldCodes = getRelevantSubfieldCodes(record);
41
41
  nvdebug(` Relevant subfield codes are '${relevantSubfieldCodes.join("', '")}'`, debugDev);
42
- const relevantFields = record.fields.filter(f => isRelevantField(f, relevantSubfieldCodes)).map(f => validateMode ? clone(f) : f); // NV! relevant fields are cloned in validation mode!
42
+ const relevantFields = record.fields.filter(f => isRelevantField(f, relevantSubfieldCodes)).map(f => validateMode ? structuredClone(f) : f); // NV! relevant fields are cloned in validation mode!
43
43
  // Nothing to do:
44
44
  if (relevantFields.length === 0) {
45
45
  nvdebug(` No relevant f041 fields found`, debugDev);
@@ -62,7 +62,7 @@ export default function () {
62
62
  return {message: [], fix: report, valid: true};
63
63
 
64
64
  function updateAndReport008() { // Update 008/35-37 if necessary + report it
65
- const [f008] = record.get('008').map(f => validateMode ? clone(f) : f);
65
+ const [f008] = record.get('008').map(f => validateMode ? structuredClone(f) : f);
66
66
 
67
67
  if (!f008) {
68
68
  nvdebug(' WARNING: no f008 found'), debugDev;
@@ -1,4 +1,4 @@
1
- import clone from 'clone';
1
+
2
2
  import {fieldFixPunctuation} from './punctuation2.js';
3
3
  import {fieldToString, getCatalogingLanguage, nvdebug, subfieldToString} from './utils.js';
4
4
  import createDebugLogger from 'debug';
@@ -35,7 +35,7 @@ export default function () {
35
35
  const language = getCatalogingLanguage(record);
36
36
 
37
37
  record.fields.forEach(field => {
38
- const clonedField = clone(field);
38
+ const clonedField = structuredClone(field);
39
39
  // Rather hackily/abnormally use language as both fromLanguage and toLanguage.
40
40
  // fromLanguage is used to expand "esitt." => "esittäjä".
41
41
  // toLanguage is used by translations (fixes "författere" to "kirjoittaja", if 040$b is "fin")
@@ -2,8 +2,6 @@
2
2
  * This validator de-duplicates identical fields in a record.
3
3
  */
4
4
 
5
- import {MarcRecord} from '@natlibfi/marc-record';
6
-
7
5
  export default function () {
8
6
  return {
9
7
  description: 'Handles identical duplicate in record fields',
@@ -28,7 +26,8 @@ export default function () {
28
26
 
29
27
  function uniqWith(fields) {
30
28
  return fields.reduce((uniq, field) => {
31
- if (!uniq.some(f => MarcRecord.isEqual(f, field))) {
29
+ const fieldAsString = JSON.stringify(field);
30
+ if (!uniq.some(f => JSON.stringify(f) === fieldAsString)) {
32
31
  uniq.push(field);
33
32
  }
34
33
 
@@ -6,7 +6,7 @@
6
6
  // Author(s): Nicholas Volk
7
7
 
8
8
 
9
- import clone from 'clone';
9
+
10
10
  import {fieldFixPunctuation, fieldStripPunctuation} from './punctuation2.js';
11
11
  import {fieldToString, nvdebug} from './utils.js';
12
12
  import {sortAdjacentSubfields} from './sortSubfields.js';
@@ -40,15 +40,15 @@ export default function () {
40
40
  }
41
41
  }
42
42
 
43
- function createNormalizedClone(field) {
44
- const clonedField = clone(field);
43
+ function createNormalizedstructuredClone(field) {
44
+ const clonedField = structuredClone(field);
45
45
  // Normalize
46
46
  fieldStripPunctuation(clonedField);
47
47
  return clonedField;
48
48
  }
49
49
 
50
50
  function createNormalizedCloneWithoutRelatorTerms(field) {
51
- const clonedField = createNormalizedClone(field);
51
+ const clonedField = createNormalizedstructuredClone(field);
52
52
  // Remove relator terms $e subfi:
53
53
  clonedField.subfields = clonedField.subfields.filter(sf => sf.code !== 'e');
54
54
  return clonedField;
@@ -1,5 +1,5 @@
1
1
  //import createDebugLogger from 'debug';
2
- import clone from 'clone';
2
+
3
3
  import {fieldToString} from './utils.js';
4
4
 
5
5
  //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/modernize-502');
@@ -40,7 +40,7 @@ export default function () {
40
40
  }
41
41
  const orig = fieldToString(field);
42
42
 
43
- const normalizedField = normalizeField502(clone(field));
43
+ const normalizedField = normalizeField502(structuredClone(field));
44
44
  const mod = fieldToString(normalizedField);
45
45
  if (orig !== mod) { // Fail as the input is "broken"/"crap"/sumthing
46
46
  res.message.push(`Fix '${orig}' => '${mod}'`);
@@ -1,5 +1,4 @@
1
1
  // import createDebugLogger from 'debug';
2
- // import clone from 'clone';
3
2
  // const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda:multiple-subfield-0');
4
3
 
5
4
  import {fieldHasSubfield, fieldToString} from './utils.js';
@@ -1,4 +1,4 @@
1
- import clone from 'clone';
1
+
2
2
  import {fieldToString, isContentSubfieldCode, nvdebug} from './utils.js';
3
3
 
4
4
  import createDebugLogger from 'debug';
@@ -42,7 +42,7 @@ export default function () {
42
42
  const orig = fieldToString(field);
43
43
  nvdebug(` VALIDATE FIELD '${orig}'`, debugDev);
44
44
 
45
- const normalizedField = fixDashes(clone(field));
45
+ const normalizedField = fixDashes(structuredClone(field));
46
46
  const mod = fieldToString(normalizedField);
47
47
  if (orig === mod) { // Fail as the input is "broken"/"crap"/sumthing
48
48
  return;
@@ -1,5 +1,5 @@
1
1
  // Relocated from melinda-marc-record-merge-reducers (and renamed)
2
- import clone from 'clone';
2
+
3
3
  import {fieldToString, /*nvdebug*/} from './utils.js';
4
4
 
5
5
  //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda:normalize-identifiers');
@@ -61,7 +61,7 @@ export default function () {
61
61
  return;
62
62
  }
63
63
 
64
- const normalizedField = clone(field);
64
+ const normalizedField = structuredClone(field);
65
65
  fieldNormalizeControlNumbers(normalizedField);
66
66
 
67
67
  const orig = fieldToString(field);
@@ -1,5 +1,4 @@
1
1
  //import createDebugLogger from 'debug';
2
- import clone from 'clone';
3
2
  import {fieldToString} from './utils.js';
4
3
 
5
4
  // Author(s): Nicholas Volk
@@ -34,7 +33,7 @@ export default function () {
34
33
  function validateField(field, res) {
35
34
  const orig = fieldToString(field);
36
35
 
37
- const normalizedField = clone(field);
36
+ const normalizedField = structuredClone(field);
38
37
  normalizeQualifyingInformationField(normalizedField);
39
38
  const mod = fieldToString(normalizedField);
40
39
  if (orig !== mod) { // Fail as the input is "broken"/"crap"/sumthing
@@ -1,5 +1,5 @@
1
1
  //import createDebugLogger from 'debug';
2
- import clone from 'clone';
2
+
3
3
  import {convert as nongenericNormalization} from './unicode-decomposition.js';
4
4
  import {fieldToString /*, nvdebug */} from './utils.js';
5
5
 
@@ -68,7 +68,7 @@ export default function () {
68
68
  }
69
69
  const orig = fieldToString(field);
70
70
 
71
- const normalizedField = fieldFixComposition(clone(field));
71
+ const normalizedField = fieldFixComposition(structuredClone(field));
72
72
  const mod = fieldToString(normalizedField);
73
73
  if (orig !== mod) { // Fail as the input is "broken"/"crap"/sumthing
74
74
  res.message.push(`'${orig}' requires normalization`);
@@ -6,7 +6,7 @@
6
6
  This is mainly used by melinda-marc-record-merge-reducers. However, also removeInferiorDataFields fixer also used this.
7
7
  Thus it is here. However, most of the testing is done via merge-reducers...
8
8
  */
9
- import clone from 'clone';
9
+
10
10
  import {fieldStripPunctuation} from './punctuation2.js';
11
11
  import {fieldToString, isContentSubfieldCode} from './utils.js';
12
12
 
@@ -284,7 +284,7 @@ function normalizeSubfieldValue(value, subfieldCode, tag) {
284
284
  }
285
285
 
286
286
  export function cloneAndRemovePunctuation(field) {
287
- const clonedField = clone(field);
287
+ const clonedField = structuredClone(field);
288
288
  if (fieldSkipNormalization(field)) {
289
289
  return clonedField;
290
290
  }
@@ -324,7 +324,7 @@ function normalizeField(field) {
324
324
  export function cloneAndNormalizeFieldForComparison(field) {
325
325
  // NB! This new field is for comparison purposes only.
326
326
  // Some of the normalizations might be considered a bit overkill for other purposes.
327
- const clonedField = cloneAndRemovePunctuation(field); // was only clone(field)
327
+ const clonedField = cloneAndRemovePunctuation(field); // was only structuredClone(field)
328
328
 
329
329
  if (fieldSkipNormalization(field)) {
330
330
  return clonedField;
@@ -1,14 +1,9 @@
1
- import {MarcRecord} from '@natlibfi/marc-record';
2
1
  import createDebug from 'debug';
2
+ import {MarcRecord} from '@natlibfi/marc-record';
3
3
  import {autRules, bibRules} from './rules/index.js';
4
4
 
5
- const debug = createDebug('@natlibfi/marc-record-validator-melinda/punctuation:dev');
6
5
 
7
- function cloneDeep(field) {
8
- const r = new MarcRecord();
9
- r.appendField(field);
10
- return r.get(field.tag)?.[0];
11
- }
6
+ const debug = createDebug('@natlibfi/marc-record-validator-melinda/punctuation:dev');
12
7
 
13
8
  export default function () {
14
9
  function readPunctuationRulesFromJSON(recordType) {
@@ -46,7 +41,7 @@ export default function () {
46
41
 
47
42
  function validateField(recordType = 'a') {
48
43
  return function (element) {
49
- const testField = cloneDeep(element);
44
+ const testField = structuredClone(element);
50
45
  debug(`Original field: ${JSON.stringify(element)}`);
51
46
  const punctuated = punctuateField(testField, recordType);
52
47
  debug(`Punctuation result: ${JSON.stringify(punctuated)}`);
@@ -55,7 +50,7 @@ export default function () {
55
50
  return true;
56
51
  }
57
52
 
58
- if (MarcRecord.isEqual(punctuated, element)) {
53
+ if (JSON.stringify(punctuated) === JSON.stringify(element)) {
59
54
  debug(`Original field (element): ${JSON.stringify(element)}`);
60
55
  debug('Punctuation result equals original field');
61
56
  return true;
@@ -15,7 +15,7 @@ import {tagToDataProvenanceSubfieldCode} from './dataProvenanceUtils.js';
15
15
  import {fieldGetUnambiguousTag} from './subfield6Utils.js';
16
16
  import createDebugLogger from 'debug';
17
17
  import {fieldToString, isContentSubfieldCode, nvdebug} from './utils.js';
18
- import clone from 'clone';
18
+
19
19
 
20
20
  const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda:punctuation2');
21
21
  //const debugData = debug.extend('data');
@@ -69,7 +69,7 @@ function getNextRelevantSubfield(field, currSubfieldIndex) {
69
69
  }
70
70
 
71
71
  export function fieldGetFixedString(field, add = true) {
72
- const cloneField = clone(field);
72
+ const cloneField = structuredClone(field);
73
73
  const operation = add ? subfieldFixPunctuation : subfieldStripPunctuation;
74
74
  cloneField.subfields.forEach((sf, i) => {
75
75
  // NB! instead of next subfield, we should actually get next *non-control-subfield*!!!
@@ -9,7 +9,7 @@
9
9
  */
10
10
 
11
11
  //import createDebugLogger from 'debug';
12
- import clone from 'clone';
12
+
13
13
 
14
14
  import {fieldToString} from './utils.js';
15
15
 
@@ -55,7 +55,7 @@ export default function () {
55
55
  // Some subfields are removed:
56
56
  if (validateMode) {
57
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);
58
+ const clonedField = structuredClone(currField);
59
59
  clonedField.subfields = otherSubfields;
60
60
  const modifiedString = fieldToString(clonedField);
61
61
  const message = `Modify '${originalString}' => '${modifiedString}`;
@@ -1,6 +1,6 @@
1
1
  //import createDebugLogger from 'debug';
2
+
2
3
  import {fieldToString} from './utils.js';
3
- import clone from 'clone';
4
4
 
5
5
  //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/sanitize-vocabulary-source-codes);
6
6
 
@@ -36,7 +36,7 @@ export default function () {
36
36
  function validateField(field, res) {
37
37
  const orig = fieldToString(field);
38
38
 
39
- const normalizedField = fieldSanitizeVocabularySourceCode(clone(field));
39
+ const normalizedField = fieldSanitizeVocabularySourceCode(structuredClone(field));
40
40
  const mod = fieldToString(normalizedField);
41
41
  if (orig !== mod) { // Fail as the input is "broken"/"crap"/sumthing
42
42
  res.message.push(`FIXABLE: '${orig}' => '${mod}'`);
package/src/sortFields.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Taken from project marc-record-js, file marcSortFields.js as this contains more and more Melinda-specific rules.
2
2
 
3
- import clone from 'clone';
3
+
4
4
  //import createDebugLogger from 'debug';
5
5
  import {fieldHasSubfield, fieldToString} from './utils.js';
6
6
  import {sortByTag, sortAlphabetically, fieldOrderComparator as globalFieldOrderComparator} from '@natlibfi/marc-record/dist/marcFieldSort.js';
@@ -30,7 +30,7 @@ export default function () {
30
30
  function validate(record) {
31
31
  const res = {message: []};
32
32
 
33
- const fields = record.fields.map(f => clone(f));
33
+ const fields = record.fields.map(f => structuredClone(f));
34
34
  fields.sort(fieldOrderComparator);
35
35
 
36
36
 
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // Author(s): Nicholas Volk
4
4
 
5
- import clone from 'clone';
5
+
6
6
  //import createDebugLogger from 'debug';
7
7
  import {fieldToString} from './utils.js';
8
8
  import {fieldFixPunctuation} from './punctuation2.js';
@@ -37,7 +37,7 @@ export default function () {
37
37
  const typeOfMaterial = recordToTypeOfMaterial(record);
38
38
 
39
39
  record.fields.forEach(field => {
40
- const clonedField = clone(field);
40
+ const clonedField = structuredClone(field);
41
41
  sortAdjacentRelatorTerms(clonedField, typeOfMaterial);
42
42
  const clonedFieldAsString = fieldToString(clonedField);
43
43
  const fieldAsString = fieldToString(field);
@@ -1,6 +1,6 @@
1
1
  // Author(s): Nicholas Volk
2
2
 
3
- import clone from 'clone';
3
+
4
4
  import createDebugLogger from 'debug';
5
5
  import {fieldToString, nvdebug} from './utils.js';
6
6
 
@@ -50,7 +50,7 @@ export default function (defaultTagPattern) {
50
50
  const relevantFields = getRelevantFields(record, tagPattern);
51
51
 
52
52
  relevantFields.forEach(field => {
53
- const clonedField = clone(field);
53
+ const clonedField = structuredClone(field);
54
54
  sortAdjacentSubfields(clonedField);
55
55
  const clonedFieldAsString = fieldToString(clonedField);
56
56
  const fieldAsString = fieldToString(field);
@@ -1,5 +1,5 @@
1
1
  //import createDebugLogger from 'debug';
2
- import clone from 'clone';
2
+
3
3
  import {fieldHasSubfield, fieldToString, getCatalogingLanguage} from './utils.js';
4
4
  import {fieldFixPunctuation} from './punctuation2.js';
5
5
  import {fieldGetUnambiguousTag} from './subfield6Utils.js';
@@ -44,7 +44,7 @@ export default function () {
44
44
  }
45
45
  const orig = fieldToString(field);
46
46
 
47
- const normalizedField = normalizeSubfieldValues(clone(field), catLang);
47
+ const normalizedField = normalizeSubfieldValues(structuredClone(field), catLang);
48
48
  const mod = fieldToString(normalizedField);
49
49
  if (orig !== mod) { // Fail as the input is "broken"/"crap"/sumthing
50
50
  res.message.push(`'${orig}' requires subfield internal mods/normalization`);
@@ -1,6 +1,6 @@
1
1
  //import createDebugLogger from 'debug';
2
+
2
3
  import {fieldToString} from './utils.js';
3
- import clone from 'clone';
4
4
 
5
5
  //const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/sanitize-vocabulary-source-codes);
6
6
 
@@ -35,7 +35,7 @@ export default function () {
35
35
  }
36
36
  const orig = fieldToString(field);
37
37
 
38
- const normalizedField = fixField(clone(field), record);
38
+ const normalizedField = fixField(structuredClone(field), record);
39
39
  const mod = fieldToString(normalizedField);
40
40
  if (orig !== mod) { // Fail as the input is "broken"/"crap"/sumthing
41
41
  res.message.push(`FIXABLE: '${orig}' => '${mod}'`);
@@ -1,7 +1,6 @@
1
1
  // Author(s): Nicholas Volk
2
2
 
3
3
  //import createDebugLogger from 'debug';
4
- import clone from 'clone';
5
4
 
6
5
  import {fieldToString} from './utils.js';
7
6
 
@@ -69,7 +68,7 @@ export default function () {
69
68
  // Some subfields are removed:
70
69
  if (validateMode) {
71
70
  // 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
72
- const clonedField = clone(field);
71
+ const clonedField = structuredClone(field);
73
72
  clonedField.subfields = otherSubfields;
74
73
  const modifiedString = fieldToString(clonedField);
75
74
  const message = `Modify '${originalString}' => '${modifiedString}`;
@@ -117,7 +116,7 @@ export default function () {
117
116
  }
118
117
 
119
118
  // Update 008/35-37:
120
- const cloned008 = clone(f008);
119
+ const cloned008 = structuredClone(f008);
121
120
  cloned008.value = `${f008.value.substring(0, 35)}${firstRelevantSubfield.value}${f008.value.substring(38)}`;
122
121
 
123
122
 
@@ -1,8 +1,6 @@
1
- import clone from 'clone';
2
1
  import createDebugLogger from 'debug';
3
2
  import {fieldHasSubfield, fieldToString, nvdebug} from './utils.js';
4
3
 
5
-
6
4
  const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda:translate-terms');
7
5
  //const debugData = debug.extend('data');
8
6
  const debugDev = debug.extend('dev');
@@ -104,7 +102,7 @@ export default function () {
104
102
  const prefLabel = prefLabels.find(l => l.lang === twoLetterOtherLang);
105
103
  //nvdebug(`pairField() WP 4: ${JSON.stringify(prefLabel)}`, debugDev);
106
104
  const sfA = {'code': 'a', 'value': prefLabel.value}; // field.subfields.field(sf => sf.code === 'a');
107
- const sf0 = clone(field.subfields.find(sf => sf.code === '0'));
105
+ const sf0 = structuredClone(field.subfields.find(sf => sf.code === '0'));
108
106
  const sf2 = {'code': '2', 'value': `${lexAndLang.lex}/${lexAndLang.lang === 'fin' ? 'swe' : 'fin'}`}; // swap fin <=> swe
109
107
  const newField = {tag: field.tag, ind1: field.ind1, ind2: field.ind2, subfields: [sfA, sf2, sf0]};
110
108
  return newField;
package/dist/sort-tags.js DELETED
@@ -1,41 +0,0 @@
1
- import { MarcRecord } from "@natlibfi/marc-record";
2
- export default function(tagPattern) {
3
- return {
4
- description: "Handles field ordering",
5
- validate,
6
- fix: async (record) => ({
7
- fix: await sort(record, tagPattern)
8
- })
9
- };
10
- function validate(record, tagPattern2) {
11
- return MarcRecord.isEqual(record.fields, sort(record.fields, tagPattern2)) ? { valid: true, messages: [] } : { valid: false, messages: ["Fields are in incorrect order"] };
12
- }
13
- function sort(record, tagPattern2) {
14
- if (tagPattern2) {
15
- return sortPatternFields(record, tagPattern2);
16
- }
17
- return sortFields(record);
18
- }
19
- }
20
- function sortPatternFields(record, tagPattern) {
21
- const matchingTags = record.fields.map((field) => tagPattern.some((pattern) => pattern.test(field.tag)) ? field : null).filter((tag) => tag);
22
- const sortedArray = sortFields(record.fields);
23
- const fixedArray = sortedArray.filter((field) => !tagPattern.some((pattern) => pattern.test(field.tag)));
24
- fixedArray.splice(index(sortedArray, tagPattern), 0, ...matchingTags);
25
- record.fields = fixedArray;
26
- }
27
- function sortFields(fields) {
28
- return [...fields].sort((a, b) => {
29
- if (a.tag > b.tag) {
30
- return 1;
31
- }
32
- if (b.tag > a.tag) {
33
- return -1;
34
- }
35
- return 0;
36
- });
37
- }
38
- function index(fields, tagPattern) {
39
- return fields.findIndex((field) => tagPattern.some((pattern) => pattern.test(field.tag)));
40
- }
41
- //# sourceMappingURL=sort-tags.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/sort-tags.js"],
4
- "sourcesContent": ["import {MarcRecord} from '@natlibfi/marc-record';\n\nexport default function (tagPattern) {\n return {\n description:\n 'Handles field ordering',\n validate,\n fix: async record => ({\n fix: await sort(record, tagPattern)\n })\n };\n\n function validate(record, tagPattern) {\n return MarcRecord.isEqual(record.fields, sort(record.fields, tagPattern)) ? {valid: true, messages: []} : {valid: false, messages: ['Fields are in incorrect order']};\n }\n\n function sort(record, tagPattern) {\n if (tagPattern) {\n return sortPatternFields(record, tagPattern);\n }\n\n return sortFields(record);\n }\n}\n\nfunction sortPatternFields(record, tagPattern) {\n const matchingTags = record.fields.map(field => tagPattern.some(pattern => pattern.test(field.tag)) ? field : null).filter(tag => tag);\n const sortedArray = sortFields(record.fields);\n const fixedArray = sortedArray.filter(field => !tagPattern.some(pattern => pattern.test(field.tag)));\n fixedArray.splice(index(sortedArray, tagPattern), 0, ...matchingTags);\n record.fields = fixedArray;\n}\n\nfunction sortFields(fields) {\n return [...fields].sort((a, b) => {\n if (a.tag > b.tag) {\n return 1;\n }\n if (b.tag > a.tag) {\n return -1;\n }\n return 0;\n });\n}\n\nfunction index(fields, tagPattern) {\n return fields.findIndex(field => tagPattern.some(pattern => pattern.test(field.tag)));\n}\n"],
5
- "mappings": "AAAA,SAAQ,kBAAiB;AAEzB,wBAAyB,YAAY;AACnC,SAAO;AAAA,IACL,aACE;AAAA,IACF;AAAA,IACA,KAAK,OAAM,YAAW;AAAA,MACpB,KAAK,MAAM,KAAK,QAAQ,UAAU;AAAA,IACpC;AAAA,EACF;AAEA,WAAS,SAAS,QAAQA,aAAY;AACpC,WAAO,WAAW,QAAQ,OAAO,QAAQ,KAAK,OAAO,QAAQA,WAAU,CAAC,IAAI,EAAC,OAAO,MAAM,UAAU,CAAC,EAAC,IAAI,EAAC,OAAO,OAAO,UAAU,CAAC,+BAA+B,EAAC;AAAA,EACtK;AAEA,WAAS,KAAK,QAAQA,aAAY;AAChC,QAAIA,aAAY;AACd,aAAO,kBAAkB,QAAQA,WAAU;AAAA,IAC7C;AAEA,WAAO,WAAW,MAAM;AAAA,EAC1B;AACF;AAEA,SAAS,kBAAkB,QAAQ,YAAY;AAC7C,QAAM,eAAe,OAAO,OAAO,IAAI,WAAS,WAAW,KAAK,aAAW,QAAQ,KAAK,MAAM,GAAG,CAAC,IAAI,QAAQ,IAAI,EAAE,OAAO,SAAO,GAAG;AACrI,QAAM,cAAc,WAAW,OAAO,MAAM;AAC5C,QAAM,aAAa,YAAY,OAAO,WAAS,CAAC,WAAW,KAAK,aAAW,QAAQ,KAAK,MAAM,GAAG,CAAC,CAAC;AACnG,aAAW,OAAO,MAAM,aAAa,UAAU,GAAG,GAAG,GAAG,YAAY;AACpE,SAAO,SAAS;AAClB;AAEA,SAAS,WAAW,QAAQ;AAC1B,SAAO,CAAC,GAAG,MAAM,EAAE,KAAK,CAAC,GAAG,MAAM;AAChC,QAAI,EAAE,MAAM,EAAE,KAAK;AACjB,aAAO;AAAA,IACT;AACA,QAAI,EAAE,MAAM,EAAE,KAAK;AACjB,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT,CAAC;AACH;AAEA,SAAS,MAAM,QAAQ,YAAY;AACjC,SAAO,OAAO,UAAU,WAAS,WAAW,KAAK,aAAW,QAAQ,KAAK,MAAM,GAAG,CAAC,CAAC;AACtF;",
6
- "names": ["tagPattern"]
7
- }