@natlibfi/marc-record-validators-melinda 10.1.0 → 10.2.0
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.
- package/dist/ending-whitespace.js +4 -1
- package/dist/ending-whitespace.js.map +1 -1
- package/dist/ending-whitespace.spec.js +0 -7
- package/dist/ending-whitespace.spec.js.map +1 -1
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/non-breaking-space.js +13 -7
- package/dist/non-breaking-space.js.map +1 -1
- package/dist/non-breaking-space.spec.js +0 -7
- package/dist/non-breaking-space.spec.js.map +1 -1
- package/package.json +1 -1
- package/src/ending-whitespace.js +5 -1
- package/src/ending-whitespace.spec.js +1 -8
- package/src/index.js +4 -0
- package/src/non-breaking-space.js +16 -3
- package/src/non-breaking-space.spec.js +1 -8
- package/test-fixtures/ending-whitespace/01/metadata.json +2 -1
- package/test-fixtures/ending-whitespace/02/metadata.json +2 -1
- package/test-fixtures/ending-whitespace/03/metadata.json +2 -1
- package/test-fixtures/ending-whitespace/04/expectedResult.json +10 -0
- package/test-fixtures/ending-whitespace/04/metadata.json +6 -0
- package/test-fixtures/ending-whitespace/04/record.json +8 -0
- package/test-fixtures/non-breaking-space/01/metadata.json +2 -1
- package/test-fixtures/non-breaking-space/02/metadata.json +2 -1
- package/test-fixtures/non-breaking-space/03/metadata.json +2 -1
- package/test-fixtures/non-breaking-space/04/expectedResult.json +21 -0
- package/test-fixtures/non-breaking-space/04/metadata.json +6 -0
- package/test-fixtures/non-breaking-space/04/record.json +19 -0
|
@@ -17,7 +17,7 @@ function _default() {
|
|
|
17
17
|
function validate(record) {
|
|
18
18
|
const nonValidFields = record.fields.filter(({
|
|
19
19
|
subfields
|
|
20
|
-
}) => subfields.filter(valueEndsWithWhitespace).length > 0);
|
|
20
|
+
}) => subfields !== undefined && subfields.filter(valueEndsWithWhitespace).length > 0);
|
|
21
21
|
const valid = nonValidFields.length === 0;
|
|
22
22
|
const messages = nonValidFields.flatMap(({
|
|
23
23
|
tag,
|
|
@@ -37,6 +37,9 @@ function _default() {
|
|
|
37
37
|
record.fields.forEach(({
|
|
38
38
|
subfields
|
|
39
39
|
}) => {
|
|
40
|
+
if (subfields === undefined) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
40
43
|
subfields.forEach(subfield => {
|
|
41
44
|
if (valueEndsWithWhitespace(subfield)) {
|
|
42
45
|
subfield.value = subfield.value.trimEnd();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ending-whitespace.js","names":["description","validate","fix","record","nonValidFields","fields","filter","subfields","valueEndsWithWhitespace","length","valid","messages","flatMap","tag","map","sf","code","forEach","subfield","value","trimEnd","test"],"sources":["../src/ending-whitespace.js"],"sourcesContent":["/**\n * Provides interface to validate and fix record fields, which include subfields that end with whitespace character\n * @returns {Object} Object containing interfaces required by marc-record-validators-melinda package\n */\nexport default function () {\n return {\n description: 'Handles subfields that ends with whitespace character',\n validate,\n fix\n };\n\n function validate(record) {\n const nonValidFields = record.fields.filter(({subfields}) => subfields.filter(valueEndsWithWhitespace).length > 0);\n\n const valid = nonValidFields.length === 0;\n const messages = nonValidFields.flatMap(({tag, subfields}) => subfields.map(sf => `Field ${tag} subfield $${sf.code} ends with whitespace`));\n\n return valid ? {valid, messages: []} : {valid, messages};\n }\n\n /* eslint-disable functional/immutable-data,functional/no-conditional-statement */\n function fix(record) {\n record.fields.forEach(({subfields}) => {\n subfields.forEach(subfield => {\n if (valueEndsWithWhitespace(subfield)) {\n subfield.value = subfield.value.trimEnd();\n }\n });\n });\n }\n /* eslint-enable functional/immutable-data,functional/no-conditional-statement */\n\n function valueEndsWithWhitespace({value}) {\n return (/\\s$/u).test(value);\n }\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACe,oBAAY;EACzB,OAAO;IACLA,WAAW,EAAE,uDAAuD;IACpEC,QAAQ;IACRC;EACF,CAAC;EAED,SAASD,QAAQ,CAACE,MAAM,EAAE;IACxB,MAAMC,cAAc,GAAGD,MAAM,CAACE,MAAM,CAACC,MAAM,CAAC,CAAC;MAACC;IAAS,CAAC,KAAKA,SAAS,CAACD,MAAM,
|
|
1
|
+
{"version":3,"file":"ending-whitespace.js","names":["description","validate","fix","record","nonValidFields","fields","filter","subfields","undefined","valueEndsWithWhitespace","length","valid","messages","flatMap","tag","map","sf","code","forEach","subfield","value","trimEnd","test"],"sources":["../src/ending-whitespace.js"],"sourcesContent":["/**\n * Provides interface to validate and fix record fields, which include subfields that end with whitespace character\n * @returns {Object} Object containing interfaces required by marc-record-validators-melinda package\n */\nexport default function () {\n return {\n description: 'Handles subfields that ends with whitespace character',\n validate,\n fix\n };\n\n function validate(record) {\n const nonValidFields = record.fields.filter(({subfields}) => subfields !== undefined && subfields.filter(valueEndsWithWhitespace).length > 0);\n\n const valid = nonValidFields.length === 0;\n const messages = nonValidFields.flatMap(({tag, subfields}) => subfields.map(sf => `Field ${tag} subfield $${sf.code} ends with whitespace`));\n\n return valid ? {valid, messages: []} : {valid, messages};\n }\n\n /* eslint-disable functional/immutable-data,functional/no-conditional-statement */\n function fix(record) {\n record.fields.forEach(({subfields}) => {\n if (subfields === undefined) {\n return;\n }\n\n subfields.forEach(subfield => {\n if (valueEndsWithWhitespace(subfield)) {\n subfield.value = subfield.value.trimEnd();\n }\n });\n });\n }\n /* eslint-enable functional/immutable-data,functional/no-conditional-statement */\n\n function valueEndsWithWhitespace({value}) {\n return (/\\s$/u).test(value);\n }\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACe,oBAAY;EACzB,OAAO;IACLA,WAAW,EAAE,uDAAuD;IACpEC,QAAQ;IACRC;EACF,CAAC;EAED,SAASD,QAAQ,CAACE,MAAM,EAAE;IACxB,MAAMC,cAAc,GAAGD,MAAM,CAACE,MAAM,CAACC,MAAM,CAAC,CAAC;MAACC;IAAS,CAAC,KAAKA,SAAS,KAAKC,SAAS,IAAID,SAAS,CAACD,MAAM,CAACG,uBAAuB,CAAC,CAACC,MAAM,GAAG,CAAC,CAAC;IAE7I,MAAMC,KAAK,GAAGP,cAAc,CAACM,MAAM,KAAK,CAAC;IACzC,MAAME,QAAQ,GAAGR,cAAc,CAACS,OAAO,CAAC,CAAC;MAACC,GAAG;MAAEP;IAAS,CAAC,KAAKA,SAAS,CAACQ,GAAG,CAACC,EAAE,IAAK,SAAQF,GAAI,cAAaE,EAAE,CAACC,IAAK,uBAAsB,CAAC,CAAC;IAE5I,OAAON,KAAK,GAAG;MAACA,KAAK;MAAEC,QAAQ,EAAE;IAAE,CAAC,GAAG;MAACD,KAAK;MAAEC;IAAQ,CAAC;EAC1D;;EAEA;EACA,SAASV,GAAG,CAACC,MAAM,EAAE;IACnBA,MAAM,CAACE,MAAM,CAACa,OAAO,CAAC,CAAC;MAACX;IAAS,CAAC,KAAK;MACrC,IAAIA,SAAS,KAAKC,SAAS,EAAE;QAC3B;MACF;MAEAD,SAAS,CAACW,OAAO,CAACC,QAAQ,IAAI;QAC5B,IAAIV,uBAAuB,CAACU,QAAQ,CAAC,EAAE;UACrCA,QAAQ,CAACC,KAAK,GAAGD,QAAQ,CAACC,KAAK,CAACC,OAAO,EAAE;QAC3C;MACF,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;EACA;;EAEA,SAASZ,uBAAuB,CAAC;IAACW;EAAK,CAAC,EAAE;IACxC,OAAQ,MAAM,CAAEE,IAAI,CAACF,KAAK,CAAC;EAC7B;AACF"}
|
|
@@ -5,7 +5,6 @@ var _marcRecord = require("@natlibfi/marc-record");
|
|
|
5
5
|
var _endingWhitespace = _interopRequireDefault(require("./ending-whitespace"));
|
|
6
6
|
var _fixura = require("@natlibfi/fixura");
|
|
7
7
|
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
8
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
9
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
9
|
(0, _fixugen.default)({
|
|
11
10
|
callback,
|
|
@@ -19,7 +18,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
19
18
|
before: () => testValidatorFactory()
|
|
20
19
|
}
|
|
21
20
|
});
|
|
22
|
-
const debug = (0, _debug.default)('@natlibfi/marc-record-validators-melinda/ending-whitespace:test');
|
|
23
21
|
async function testValidatorFactory() {
|
|
24
22
|
const validator = await (0, _endingWhitespace.default)();
|
|
25
23
|
(0, _chai.expect)(validator).to.be.an('object').that.has.any.keys('description', 'validate');
|
|
@@ -28,13 +26,8 @@ async function testValidatorFactory() {
|
|
|
28
26
|
}
|
|
29
27
|
async function callback({
|
|
30
28
|
getFixture,
|
|
31
|
-
enabled = true,
|
|
32
29
|
fix = false
|
|
33
30
|
}) {
|
|
34
|
-
if (enabled === false) {
|
|
35
|
-
debug('TEST SKIPPED!');
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
31
|
const validator = await (0, _endingWhitespace.default)();
|
|
39
32
|
const record = new _marcRecord.MarcRecord(getFixture('record.json'));
|
|
40
33
|
const expectedResult = getFixture('expectedResult.json');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ending-whitespace.spec.js","names":["generateTests","callback","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","mocha","before","testValidatorFactory","
|
|
1
|
+
{"version":3,"file":"ending-whitespace.spec.js","names":["generateTests","callback","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","mocha","before","testValidatorFactory","validator","validatorFactory","expect","to","be","an","that","has","any","keys","description","a","validate","getFixture","fix","record","MarcRecord","expectedResult","result","eql"],"sources":["../src/ending-whitespace.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport validatorFactory from './ending-whitespace';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen';\n\ngenerateTests({\n callback,\n path: [__dirname, '..', 'test-fixtures', 'ending-whitespace'],\n useMetadataFile: true,\n recurse: false,\n fixura: {\n reader: READERS.JSON\n },\n mocha: {\n before: () => testValidatorFactory()\n }\n});\n\nasync function testValidatorFactory() {\n const validator = await validatorFactory();\n\n expect(validator)\n .to.be.an('object')\n .that.has.any.keys('description', 'validate');\n\n expect(validator.description).to.be.a('string');\n expect(validator.validate).to.be.a('function');\n}\n\nasync function callback({getFixture, fix = false}) {\n const validator = await validatorFactory();\n const record = new MarcRecord(getFixture('record.json'));\n const expectedResult = getFixture('expectedResult.json');\n\n if (!fix) {\n const result = await validator.validate(record);\n expect(result).to.eql(expectedResult);\n return;\n }\n\n await validator.fix(record);\n expect(record).to.eql(expectedResult);\n}\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAA8C;AAE9C,IAAAA,gBAAa,EAAC;EACZC,QAAQ;EACRC,IAAI,EAAE,CAACC,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,mBAAmB,CAAC;EAC7DC,eAAe,EAAE,IAAI;EACrBC,OAAO,EAAE,KAAK;EACdC,MAAM,EAAE;IACNC,MAAM,EAAEC,eAAO,CAACC;EAClB,CAAC;EACDC,KAAK,EAAE;IACLC,MAAM,EAAE,MAAMC,oBAAoB;EACpC;AACF,CAAC,CAAC;AAEF,eAAeA,oBAAoB,GAAG;EACpC,MAAMC,SAAS,GAAG,MAAM,IAAAC,yBAAgB,GAAE;EAE1C,IAAAC,YAAM,EAACF,SAAS,CAAC,CACdG,EAAE,CAACC,EAAE,CAACC,EAAE,CAAC,QAAQ,CAAC,CAClBC,IAAI,CAACC,GAAG,CAACC,GAAG,CAACC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC;EAE/C,IAAAP,YAAM,EAACF,SAAS,CAACU,WAAW,CAAC,CAACP,EAAE,CAACC,EAAE,CAACO,CAAC,CAAC,QAAQ,CAAC;EAC/C,IAAAT,YAAM,EAACF,SAAS,CAACY,QAAQ,CAAC,CAACT,EAAE,CAACC,EAAE,CAACO,CAAC,CAAC,UAAU,CAAC;AAChD;AAEA,eAAevB,QAAQ,CAAC;EAACyB,UAAU;EAAEC,GAAG,GAAG;AAAK,CAAC,EAAE;EACjD,MAAMd,SAAS,GAAG,MAAM,IAAAC,yBAAgB,GAAE;EAC1C,MAAMc,MAAM,GAAG,IAAIC,sBAAU,CAACH,UAAU,CAAC,aAAa,CAAC,CAAC;EACxD,MAAMI,cAAc,GAAGJ,UAAU,CAAC,qBAAqB,CAAC;EAExD,IAAI,CAACC,GAAG,EAAE;IACR,MAAMI,MAAM,GAAG,MAAMlB,SAAS,CAACY,QAAQ,CAACG,MAAM,CAAC;IAC/C,IAAAb,YAAM,EAACgB,MAAM,CAAC,CAACf,EAAE,CAACgB,GAAG,CAACF,cAAc,CAAC;IACrC;EACF;EAEA,MAAMjB,SAAS,CAACc,GAAG,CAACC,MAAM,CAAC;EAC3B,IAAAb,YAAM,EAACa,MAAM,CAAC,CAACZ,EAAE,CAACgB,GAAG,CAACF,cAAc,CAAC;AACvC"}
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,12 @@ Object.defineProperty(exports, "EndingPunctuation", {
|
|
|
33
33
|
return _endingPunctuation.default;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
+
Object.defineProperty(exports, "EndingWhitespace", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _endingWhitespace.default;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
36
42
|
Object.defineProperty(exports, "FieldExclusion", {
|
|
37
43
|
enumerable: true,
|
|
38
44
|
get: function () {
|
|
@@ -75,6 +81,12 @@ Object.defineProperty(exports, "ItemLanguage", {
|
|
|
75
81
|
return _itemLanguage.default;
|
|
76
82
|
}
|
|
77
83
|
});
|
|
84
|
+
Object.defineProperty(exports, "NonBreakingSpace", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return _nonBreakingSpace.default;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
78
90
|
Object.defineProperty(exports, "NormalizeUTF8Diacritics", {
|
|
79
91
|
enumerable: true,
|
|
80
92
|
get: function () {
|
|
@@ -134,6 +146,7 @@ var _doubleCommas = _interopRequireDefault(require("./double-commas"));
|
|
|
134
146
|
var _duplicatesInd = _interopRequireDefault(require("./duplicates-ind1"));
|
|
135
147
|
var _emptyFields = _interopRequireDefault(require("./empty-fields"));
|
|
136
148
|
var _endingPunctuation = _interopRequireDefault(require("./ending-punctuation"));
|
|
149
|
+
var _endingWhitespace = _interopRequireDefault(require("./ending-whitespace"));
|
|
137
150
|
var _fieldsPresent = _interopRequireDefault(require("./fields-present"));
|
|
138
151
|
var _fieldStructure = _interopRequireDefault(require("./field-structure"));
|
|
139
152
|
var _fixedFields = _interopRequireDefault(require("./fixed-fields"));
|
|
@@ -141,6 +154,7 @@ var _fieldExclusion = _interopRequireDefault(require("./field-exclusion"));
|
|
|
141
154
|
var _identicalFields = _interopRequireDefault(require("./identical-fields"));
|
|
142
155
|
var _isbnIssn = _interopRequireDefault(require("./isbn-issn"));
|
|
143
156
|
var _itemLanguage = _interopRequireDefault(require("./item-language"));
|
|
157
|
+
var _nonBreakingSpace = _interopRequireDefault(require("./non-breaking-space"));
|
|
144
158
|
var _normalizeUtf8Diacritics = _interopRequireDefault(require("./normalize-utf8-diacritics"));
|
|
145
159
|
var _punctuation = _interopRequireDefault(require("./punctuation/"));
|
|
146
160
|
var _resolveOrphanedSubfield6s = _interopRequireDefault(require("./resolveOrphanedSubfield6s"));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.js"],"sourcesContent":["import AccessRights from './access-rights';\nimport DoubleCommas from './double-commas';\nimport DuplicatesInd1 from './duplicates-ind1';\nimport EmptyFields from './empty-fields';\nimport EndingPunctuation from './ending-punctuation';\nimport FieldsPresent from './fields-present';\nimport FieldStructure from './field-structure';\nimport FixedFields from './fixed-fields';\nimport FieldExclusion from './field-exclusion';\nimport IdenticalFields from './identical-fields';\nimport IsbnIssn from './isbn-issn';\nimport ItemLanguage from './item-language';\nimport NormalizeUTF8Diacritics from './normalize-utf8-diacritics';\nimport Punctuation from './punctuation/';\nimport ResolveOrphanedSubfield6s from './resolveOrphanedSubfield6s'; // Do this before reindexing!\nimport ReindexSubfield6OccurenceNumbers from './reindexSubfield6OccurenceNumbers';\nimport ResolvableExtReferences from './resolvable-ext-references-melinda';\n\nimport SortTags from './sort-tags';\nimport SubfieldExclusion from './subfield-exclusion';\nimport UnicodeDecomposition from './unicode-decomposition';\nimport Urn from './urn';\n\nexport {\n AccessRights,\n DoubleCommas,\n DuplicatesInd1,\n EmptyFields,\n EndingPunctuation,\n FieldExclusion,\n FieldsPresent,\n FieldStructure,\n FixedFields,\n IdenticalFields,\n IsbnIssn,\n ItemLanguage,\n NormalizeUTF8Diacritics,\n Punctuation,\n ResolveOrphanedSubfield6s,\n ReindexSubfield6OccurenceNumbers,\n ResolvableExtReferences,\n SortTags,\n SubfieldExclusion,\n UnicodeDecomposition,\n Urn\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.js"],"sourcesContent":["import AccessRights from './access-rights';\nimport DoubleCommas from './double-commas';\nimport DuplicatesInd1 from './duplicates-ind1';\nimport EmptyFields from './empty-fields';\nimport EndingPunctuation from './ending-punctuation';\nimport EndingWhitespace from './ending-whitespace';\nimport FieldsPresent from './fields-present';\nimport FieldStructure from './field-structure';\nimport FixedFields from './fixed-fields';\nimport FieldExclusion from './field-exclusion';\nimport IdenticalFields from './identical-fields';\nimport IsbnIssn from './isbn-issn';\nimport ItemLanguage from './item-language';\nimport NonBreakingSpace from './non-breaking-space';\nimport NormalizeUTF8Diacritics from './normalize-utf8-diacritics';\nimport Punctuation from './punctuation/';\nimport ResolveOrphanedSubfield6s from './resolveOrphanedSubfield6s'; // Do this before reindexing!\nimport ReindexSubfield6OccurenceNumbers from './reindexSubfield6OccurenceNumbers';\nimport ResolvableExtReferences from './resolvable-ext-references-melinda';\n\nimport SortTags from './sort-tags';\nimport SubfieldExclusion from './subfield-exclusion';\nimport UnicodeDecomposition from './unicode-decomposition';\nimport Urn from './urn';\n\nexport {\n AccessRights,\n DoubleCommas,\n DuplicatesInd1,\n EmptyFields,\n EndingPunctuation,\n EndingWhitespace,\n FieldExclusion,\n FieldsPresent,\n FieldStructure,\n FixedFields,\n IdenticalFields,\n IsbnIssn,\n ItemLanguage,\n NonBreakingSpace,\n NormalizeUTF8Diacritics,\n Punctuation,\n ResolveOrphanedSubfield6s,\n ReindexSubfield6OccurenceNumbers,\n ResolvableExtReferences,\n SortTags,\n SubfieldExclusion,\n UnicodeDecomposition,\n Urn\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAAwB"}
|
|
@@ -15,9 +15,7 @@ function _default() {
|
|
|
15
15
|
fix
|
|
16
16
|
};
|
|
17
17
|
function validate(record) {
|
|
18
|
-
const nonValidFields = record.fields.filter((
|
|
19
|
-
subfields
|
|
20
|
-
}) => subfields.filter(valueContainsNonBreakingSpace).length > 0);
|
|
18
|
+
const nonValidFields = record.fields.filter(field => collectNonValidFields(field));
|
|
21
19
|
const valid = nonValidFields.length === 0;
|
|
22
20
|
const messages = nonValidFields.flatMap(({
|
|
23
21
|
tag,
|
|
@@ -30,14 +28,22 @@ function _default() {
|
|
|
30
28
|
valid,
|
|
31
29
|
messages
|
|
32
30
|
};
|
|
31
|
+
function collectNonValidFields(field) {
|
|
32
|
+
if (field.value) {
|
|
33
|
+
return /\u00A0/u.test(field.value);
|
|
34
|
+
}
|
|
35
|
+
return field.subfields.filter(valueContainsNonBreakingSpace).length > 0;
|
|
36
|
+
}
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
/* eslint-disable functional/immutable-data,functional/no-conditional-statement */
|
|
36
40
|
function fix(record) {
|
|
37
|
-
record.fields.forEach(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
record.fields.forEach(field => {
|
|
42
|
+
if (field.value) {
|
|
43
|
+
field.value = field.value.replaceAll(/\u00A0/gu, ' ');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
field.subfields.forEach(subfield => {
|
|
41
47
|
if (valueContainsNonBreakingSpace(subfield)) {
|
|
42
48
|
subfield.value = subfield.value.replaceAll(/\u00A0/gu, ' ');
|
|
43
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"non-breaking-space.js","names":["description","validate","fix","record","nonValidFields","fields","filter","
|
|
1
|
+
{"version":3,"file":"non-breaking-space.js","names":["description","validate","fix","record","nonValidFields","fields","filter","field","collectNonValidFields","valid","length","messages","flatMap","tag","subfields","map","sf","code","value","test","valueContainsNonBreakingSpace","forEach","replaceAll","subfield"],"sources":["../src/non-breaking-space.js"],"sourcesContent":["/**\n * Provides interface to validate and fix record fields, which include subfields that contain no-breaking space character\n * @returns {Object} Object containing interfaces required by marc-record-validators-melinda package\n */\nexport default function () {\n return {\n description: 'Handles subfields that contains non-breaking space character',\n validate,\n fix\n };\n\n function validate(record) {\n const nonValidFields = record.fields.filter((field) => collectNonValidFields(field));\n\n const valid = nonValidFields.length === 0;\n const messages = nonValidFields.flatMap(({tag, subfields}) => subfields.map(sf => `Field ${tag} subfield $${sf.code} contains non-breaking space character(s)`));\n\n return valid ? {valid, messages: []} : {valid, messages};\n\n function collectNonValidFields(field) {\n if (field.value) {\n return (/\\u00A0/u).test(field.value);\n }\n\n return field.subfields.filter(valueContainsNonBreakingSpace).length > 0;\n }\n }\n\n /* eslint-disable functional/immutable-data,functional/no-conditional-statement */\n function fix(record) {\n record.fields.forEach((field) => {\n if (field.value) {\n field.value = field.value.replaceAll(/\\u00A0/gu, ' ');\n return;\n }\n\n field.subfields.forEach(subfield => {\n if (valueContainsNonBreakingSpace(subfield)) {\n subfield.value = subfield.value.replaceAll(/\\u00A0/gu, ' ');\n }\n });\n });\n }\n /* eslint-enable functional/immutable-data,functional/no-conditional-statement */\n\n function valueContainsNonBreakingSpace({value}) {\n return (/\\u00A0/u).test(value);\n }\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACe,oBAAY;EACzB,OAAO;IACLA,WAAW,EAAE,8DAA8D;IAC3EC,QAAQ;IACRC;EACF,CAAC;EAED,SAASD,QAAQ,CAACE,MAAM,EAAE;IACxB,MAAMC,cAAc,GAAGD,MAAM,CAACE,MAAM,CAACC,MAAM,CAAEC,KAAK,IAAKC,qBAAqB,CAACD,KAAK,CAAC,CAAC;IAEpF,MAAME,KAAK,GAAGL,cAAc,CAACM,MAAM,KAAK,CAAC;IACzC,MAAMC,QAAQ,GAAGP,cAAc,CAACQ,OAAO,CAAC,CAAC;MAACC,GAAG;MAAEC;IAAS,CAAC,KAAKA,SAAS,CAACC,GAAG,CAACC,EAAE,IAAK,SAAQH,GAAI,cAAaG,EAAE,CAACC,IAAK,2CAA0C,CAAC,CAAC;IAEhK,OAAOR,KAAK,GAAG;MAACA,KAAK;MAAEE,QAAQ,EAAE;IAAE,CAAC,GAAG;MAACF,KAAK;MAAEE;IAAQ,CAAC;IAExD,SAASH,qBAAqB,CAACD,KAAK,EAAE;MACpC,IAAIA,KAAK,CAACW,KAAK,EAAE;QACf,OAAQ,SAAS,CAAEC,IAAI,CAACZ,KAAK,CAACW,KAAK,CAAC;MACtC;MAEA,OAAOX,KAAK,CAACO,SAAS,CAACR,MAAM,CAACc,6BAA6B,CAAC,CAACV,MAAM,GAAG,CAAC;IACzE;EACF;;EAEA;EACA,SAASR,GAAG,CAACC,MAAM,EAAE;IACnBA,MAAM,CAACE,MAAM,CAACgB,OAAO,CAAEd,KAAK,IAAK;MAC/B,IAAIA,KAAK,CAACW,KAAK,EAAE;QACfX,KAAK,CAACW,KAAK,GAAGX,KAAK,CAACW,KAAK,CAACI,UAAU,CAAC,UAAU,EAAE,GAAG,CAAC;QACrD;MACF;MAEAf,KAAK,CAACO,SAAS,CAACO,OAAO,CAACE,QAAQ,IAAI;QAClC,IAAIH,6BAA6B,CAACG,QAAQ,CAAC,EAAE;UAC3CA,QAAQ,CAACL,KAAK,GAAGK,QAAQ,CAACL,KAAK,CAACI,UAAU,CAAC,UAAU,EAAE,GAAG,CAAC;QAC7D;MACF,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;EACA;;EAEA,SAASF,6BAA6B,CAAC;IAACF;EAAK,CAAC,EAAE;IAC9C,OAAQ,SAAS,CAAEC,IAAI,CAACD,KAAK,CAAC;EAChC;AACF"}
|
|
@@ -5,7 +5,6 @@ var _marcRecord = require("@natlibfi/marc-record");
|
|
|
5
5
|
var _nonBreakingSpace = _interopRequireDefault(require("./non-breaking-space"));
|
|
6
6
|
var _fixura = require("@natlibfi/fixura");
|
|
7
7
|
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
8
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
9
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
9
|
(0, _fixugen.default)({
|
|
11
10
|
callback,
|
|
@@ -19,7 +18,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
19
18
|
before: () => testValidatorFactory()
|
|
20
19
|
}
|
|
21
20
|
});
|
|
22
|
-
const debug = (0, _debug.default)('@natlibfi/marc-record-validators-melinda/non-breaking-space:test');
|
|
23
21
|
async function testValidatorFactory() {
|
|
24
22
|
const validator = await (0, _nonBreakingSpace.default)();
|
|
25
23
|
(0, _chai.expect)(validator).to.be.an('object').that.has.any.keys('description', 'validate');
|
|
@@ -28,13 +26,8 @@ async function testValidatorFactory() {
|
|
|
28
26
|
}
|
|
29
27
|
async function callback({
|
|
30
28
|
getFixture,
|
|
31
|
-
enabled = true,
|
|
32
29
|
fix = false
|
|
33
30
|
}) {
|
|
34
|
-
if (enabled === false) {
|
|
35
|
-
debug('TEST SKIPPED!');
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
31
|
const validator = await (0, _nonBreakingSpace.default)();
|
|
39
32
|
const record = new _marcRecord.MarcRecord(getFixture('record.json'));
|
|
40
33
|
const expectedResult = getFixture('expectedResult.json');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"non-breaking-space.spec.js","names":["generateTests","callback","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","mocha","before","testValidatorFactory","
|
|
1
|
+
{"version":3,"file":"non-breaking-space.spec.js","names":["generateTests","callback","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","mocha","before","testValidatorFactory","validator","validatorFactory","expect","to","be","an","that","has","any","keys","description","a","validate","getFixture","fix","record","MarcRecord","expectedResult","result","eql"],"sources":["../src/non-breaking-space.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport validatorFactory from './non-breaking-space';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen';\n\ngenerateTests({\n callback,\n path: [__dirname, '..', 'test-fixtures', 'non-breaking-space'],\n useMetadataFile: true,\n recurse: false,\n fixura: {\n reader: READERS.JSON\n },\n mocha: {\n before: () => testValidatorFactory()\n }\n});\n\nasync function testValidatorFactory() {\n const validator = await validatorFactory();\n\n expect(validator)\n .to.be.an('object')\n .that.has.any.keys('description', 'validate');\n\n expect(validator.description).to.be.a('string');\n expect(validator.validate).to.be.a('function');\n}\n\nasync function callback({getFixture, fix = false}) {\n const validator = await validatorFactory();\n const record = new MarcRecord(getFixture('record.json'));\n const expectedResult = getFixture('expectedResult.json');\n\n if (!fix) {\n const result = await validator.validate(record);\n expect(result).to.eql(expectedResult);\n return;\n }\n\n await validator.fix(record);\n expect(record).to.eql(expectedResult);\n}\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAA8C;AAE9C,IAAAA,gBAAa,EAAC;EACZC,QAAQ;EACRC,IAAI,EAAE,CAACC,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,oBAAoB,CAAC;EAC9DC,eAAe,EAAE,IAAI;EACrBC,OAAO,EAAE,KAAK;EACdC,MAAM,EAAE;IACNC,MAAM,EAAEC,eAAO,CAACC;EAClB,CAAC;EACDC,KAAK,EAAE;IACLC,MAAM,EAAE,MAAMC,oBAAoB;EACpC;AACF,CAAC,CAAC;AAEF,eAAeA,oBAAoB,GAAG;EACpC,MAAMC,SAAS,GAAG,MAAM,IAAAC,yBAAgB,GAAE;EAE1C,IAAAC,YAAM,EAACF,SAAS,CAAC,CACdG,EAAE,CAACC,EAAE,CAACC,EAAE,CAAC,QAAQ,CAAC,CAClBC,IAAI,CAACC,GAAG,CAACC,GAAG,CAACC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC;EAE/C,IAAAP,YAAM,EAACF,SAAS,CAACU,WAAW,CAAC,CAACP,EAAE,CAACC,EAAE,CAACO,CAAC,CAAC,QAAQ,CAAC;EAC/C,IAAAT,YAAM,EAACF,SAAS,CAACY,QAAQ,CAAC,CAACT,EAAE,CAACC,EAAE,CAACO,CAAC,CAAC,UAAU,CAAC;AAChD;AAEA,eAAevB,QAAQ,CAAC;EAACyB,UAAU;EAAEC,GAAG,GAAG;AAAK,CAAC,EAAE;EACjD,MAAMd,SAAS,GAAG,MAAM,IAAAC,yBAAgB,GAAE;EAC1C,MAAMc,MAAM,GAAG,IAAIC,sBAAU,CAACH,UAAU,CAAC,aAAa,CAAC,CAAC;EACxD,MAAMI,cAAc,GAAGJ,UAAU,CAAC,qBAAqB,CAAC;EAExD,IAAI,CAACC,GAAG,EAAE;IACR,MAAMI,MAAM,GAAG,MAAMlB,SAAS,CAACY,QAAQ,CAACG,MAAM,CAAC;IAC/C,IAAAb,YAAM,EAACgB,MAAM,CAAC,CAACf,EAAE,CAACgB,GAAG,CAACF,cAAc,CAAC;IACrC;EACF;EAEA,MAAMjB,SAAS,CAACc,GAAG,CAACC,MAAM,CAAC;EAC3B,IAAAb,YAAM,EAACa,MAAM,CAAC,CAACZ,EAAE,CAACgB,GAAG,CAACF,cAAc,CAAC;AACvC"}
|
package/package.json
CHANGED
package/src/ending-whitespace.js
CHANGED
|
@@ -10,7 +10,7 @@ export default function () {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
function validate(record) {
|
|
13
|
-
const nonValidFields = record.fields.filter(({subfields}) => subfields.filter(valueEndsWithWhitespace).length > 0);
|
|
13
|
+
const nonValidFields = record.fields.filter(({subfields}) => subfields !== undefined && subfields.filter(valueEndsWithWhitespace).length > 0);
|
|
14
14
|
|
|
15
15
|
const valid = nonValidFields.length === 0;
|
|
16
16
|
const messages = nonValidFields.flatMap(({tag, subfields}) => subfields.map(sf => `Field ${tag} subfield $${sf.code} ends with whitespace`));
|
|
@@ -21,6 +21,10 @@ export default function () {
|
|
|
21
21
|
/* eslint-disable functional/immutable-data,functional/no-conditional-statement */
|
|
22
22
|
function fix(record) {
|
|
23
23
|
record.fields.forEach(({subfields}) => {
|
|
24
|
+
if (subfields === undefined) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
subfields.forEach(subfield => {
|
|
25
29
|
if (valueEndsWithWhitespace(subfield)) {
|
|
26
30
|
subfield.value = subfield.value.trimEnd();
|
|
@@ -3,7 +3,6 @@ import {MarcRecord} from '@natlibfi/marc-record';
|
|
|
3
3
|
import validatorFactory from './ending-whitespace';
|
|
4
4
|
import {READERS} from '@natlibfi/fixura';
|
|
5
5
|
import generateTests from '@natlibfi/fixugen';
|
|
6
|
-
import createDebugLogger from 'debug';
|
|
7
6
|
|
|
8
7
|
generateTests({
|
|
9
8
|
callback,
|
|
@@ -17,7 +16,6 @@ generateTests({
|
|
|
17
16
|
before: () => testValidatorFactory()
|
|
18
17
|
}
|
|
19
18
|
});
|
|
20
|
-
const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/ending-whitespace:test');
|
|
21
19
|
|
|
22
20
|
async function testValidatorFactory() {
|
|
23
21
|
const validator = await validatorFactory();
|
|
@@ -30,12 +28,7 @@ async function testValidatorFactory() {
|
|
|
30
28
|
expect(validator.validate).to.be.a('function');
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
async function callback({getFixture,
|
|
34
|
-
if (enabled === false) {
|
|
35
|
-
debug('TEST SKIPPED!');
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
31
|
+
async function callback({getFixture, fix = false}) {
|
|
39
32
|
const validator = await validatorFactory();
|
|
40
33
|
const record = new MarcRecord(getFixture('record.json'));
|
|
41
34
|
const expectedResult = getFixture('expectedResult.json');
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import DoubleCommas from './double-commas';
|
|
|
3
3
|
import DuplicatesInd1 from './duplicates-ind1';
|
|
4
4
|
import EmptyFields from './empty-fields';
|
|
5
5
|
import EndingPunctuation from './ending-punctuation';
|
|
6
|
+
import EndingWhitespace from './ending-whitespace';
|
|
6
7
|
import FieldsPresent from './fields-present';
|
|
7
8
|
import FieldStructure from './field-structure';
|
|
8
9
|
import FixedFields from './fixed-fields';
|
|
@@ -10,6 +11,7 @@ import FieldExclusion from './field-exclusion';
|
|
|
10
11
|
import IdenticalFields from './identical-fields';
|
|
11
12
|
import IsbnIssn from './isbn-issn';
|
|
12
13
|
import ItemLanguage from './item-language';
|
|
14
|
+
import NonBreakingSpace from './non-breaking-space';
|
|
13
15
|
import NormalizeUTF8Diacritics from './normalize-utf8-diacritics';
|
|
14
16
|
import Punctuation from './punctuation/';
|
|
15
17
|
import ResolveOrphanedSubfield6s from './resolveOrphanedSubfield6s'; // Do this before reindexing!
|
|
@@ -27,6 +29,7 @@ export {
|
|
|
27
29
|
DuplicatesInd1,
|
|
28
30
|
EmptyFields,
|
|
29
31
|
EndingPunctuation,
|
|
32
|
+
EndingWhitespace,
|
|
30
33
|
FieldExclusion,
|
|
31
34
|
FieldsPresent,
|
|
32
35
|
FieldStructure,
|
|
@@ -34,6 +37,7 @@ export {
|
|
|
34
37
|
IdenticalFields,
|
|
35
38
|
IsbnIssn,
|
|
36
39
|
ItemLanguage,
|
|
40
|
+
NonBreakingSpace,
|
|
37
41
|
NormalizeUTF8Diacritics,
|
|
38
42
|
Punctuation,
|
|
39
43
|
ResolveOrphanedSubfield6s,
|
|
@@ -10,18 +10,31 @@ export default function () {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
function validate(record) {
|
|
13
|
-
const nonValidFields = record.fields.filter((
|
|
13
|
+
const nonValidFields = record.fields.filter((field) => collectNonValidFields(field));
|
|
14
14
|
|
|
15
15
|
const valid = nonValidFields.length === 0;
|
|
16
16
|
const messages = nonValidFields.flatMap(({tag, subfields}) => subfields.map(sf => `Field ${tag} subfield $${sf.code} contains non-breaking space character(s)`));
|
|
17
17
|
|
|
18
18
|
return valid ? {valid, messages: []} : {valid, messages};
|
|
19
|
+
|
|
20
|
+
function collectNonValidFields(field) {
|
|
21
|
+
if (field.value) {
|
|
22
|
+
return (/\u00A0/u).test(field.value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return field.subfields.filter(valueContainsNonBreakingSpace).length > 0;
|
|
26
|
+
}
|
|
19
27
|
}
|
|
20
28
|
|
|
21
29
|
/* eslint-disable functional/immutable-data,functional/no-conditional-statement */
|
|
22
30
|
function fix(record) {
|
|
23
|
-
record.fields.forEach((
|
|
24
|
-
|
|
31
|
+
record.fields.forEach((field) => {
|
|
32
|
+
if (field.value) {
|
|
33
|
+
field.value = field.value.replaceAll(/\u00A0/gu, ' ');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
field.subfields.forEach(subfield => {
|
|
25
38
|
if (valueContainsNonBreakingSpace(subfield)) {
|
|
26
39
|
subfield.value = subfield.value.replaceAll(/\u00A0/gu, ' ');
|
|
27
40
|
}
|
|
@@ -3,7 +3,6 @@ import {MarcRecord} from '@natlibfi/marc-record';
|
|
|
3
3
|
import validatorFactory from './non-breaking-space';
|
|
4
4
|
import {READERS} from '@natlibfi/fixura';
|
|
5
5
|
import generateTests from '@natlibfi/fixugen';
|
|
6
|
-
import createDebugLogger from 'debug';
|
|
7
6
|
|
|
8
7
|
generateTests({
|
|
9
8
|
callback,
|
|
@@ -17,7 +16,6 @@ generateTests({
|
|
|
17
16
|
before: () => testValidatorFactory()
|
|
18
17
|
}
|
|
19
18
|
});
|
|
20
|
-
const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/non-breaking-space:test');
|
|
21
19
|
|
|
22
20
|
async function testValidatorFactory() {
|
|
23
21
|
const validator = await validatorFactory();
|
|
@@ -30,12 +28,7 @@ async function testValidatorFactory() {
|
|
|
30
28
|
expect(validator.validate).to.be.a('function');
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
async function callback({getFixture,
|
|
34
|
-
if (enabled === false) {
|
|
35
|
-
debug('TEST SKIPPED!');
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
31
|
+
async function callback({getFixture, fix = false}) {
|
|
39
32
|
const validator = await validatorFactory();
|
|
40
33
|
const record = new MarcRecord(getFixture('record.json'));
|
|
41
34
|
const expectedResult = getFixture('expectedResult.json');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_validationOptions": {},
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"tag": "008",
|
|
6
|
+
"value": "Foo Foo "
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"tag": "500",
|
|
10
|
+
"ind1": " ",
|
|
11
|
+
"ind2": " ",
|
|
12
|
+
"subfields": [
|
|
13
|
+
{
|
|
14
|
+
"code": "a",
|
|
15
|
+
"value": "Foo Foo "
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"leader": ""
|
|
21
|
+
}
|