@natlibfi/marc-record-validators-melinda 10.0.1-alpha.7 → 10.0.2
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 +1 -4
- package/dist/ending-whitespace.js.map +1 -1
- package/dist/ending-whitespace.spec.js +7 -0
- package/dist/ending-whitespace.spec.js.map +1 -1
- package/dist/index.js +0 -14
- package/dist/index.js.map +1 -1
- package/dist/non-breaking-space.js +7 -13
- package/dist/non-breaking-space.js.map +1 -1
- package/dist/non-breaking-space.spec.js +7 -0
- package/dist/non-breaking-space.spec.js.map +1 -1
- package/package.json +3 -3
- package/src/ending-whitespace.js +1 -5
- package/src/ending-whitespace.spec.js +8 -1
- package/src/index.js +0 -4
- package/src/non-breaking-space.js +3 -16
- package/src/non-breaking-space.spec.js +8 -1
- package/test-fixtures/ending-whitespace/01/metadata.json +1 -2
- package/test-fixtures/ending-whitespace/02/metadata.json +1 -2
- package/test-fixtures/ending-whitespace/03/metadata.json +1 -2
- package/test-fixtures/non-breaking-space/01/metadata.json +1 -2
- package/test-fixtures/non-breaking-space/02/metadata.json +1 -2
- package/test-fixtures/non-breaking-space/03/metadata.json +1 -2
- package/test-fixtures/ending-whitespace/04/expectedResult.json +0 -10
- package/test-fixtures/ending-whitespace/04/metadata.json +0 -6
- package/test-fixtures/ending-whitespace/04/record.json +0 -8
- package/test-fixtures/non-breaking-space/04/expectedResult.json +0 -21
- package/test-fixtures/non-breaking-space/04/metadata.json +0 -6
- package/test-fixtures/non-breaking-space/04/record.json +0 -19
|
@@ -17,7 +17,7 @@ function _default() {
|
|
|
17
17
|
function validate(record) {
|
|
18
18
|
const nonValidFields = record.fields.filter(({
|
|
19
19
|
subfields
|
|
20
|
-
}) => subfields
|
|
20
|
+
}) => subfields.filter(valueEndsWithWhitespace).length > 0);
|
|
21
21
|
const valid = nonValidFields.length === 0;
|
|
22
22
|
const messages = nonValidFields.flatMap(({
|
|
23
23
|
tag,
|
|
@@ -37,9 +37,6 @@ function _default() {
|
|
|
37
37
|
record.fields.forEach(({
|
|
38
38
|
subfields
|
|
39
39
|
}) => {
|
|
40
|
-
if (subfields === undefined) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
40
|
subfields.forEach(subfield => {
|
|
44
41
|
if (valueEndsWithWhitespace(subfield)) {
|
|
45
42
|
subfield.value = subfield.value.trimEnd();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ending-whitespace.js","names":["description","validate","fix","record","nonValidFields","fields","filter","subfields","
|
|
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,CAACE,uBAAuB,CAAC,CAACC,MAAM,GAAG,CAAC,CAAC;IAElH,MAAMC,KAAK,GAAGN,cAAc,CAACK,MAAM,KAAK,CAAC;IACzC,MAAME,QAAQ,GAAGP,cAAc,CAACQ,OAAO,CAAC,CAAC;MAACC,GAAG;MAAEN;IAAS,CAAC,KAAKA,SAAS,CAACO,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,SAAST,GAAG,CAACC,MAAM,EAAE;IACnBA,MAAM,CAACE,MAAM,CAACY,OAAO,CAAC,CAAC;MAACV;IAAS,CAAC,KAAK;MACrCA,SAAS,CAACU,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,6 +5,7 @@ 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"));
|
|
8
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
10
|
(0, _fixugen.default)({
|
|
10
11
|
callback,
|
|
@@ -18,6 +19,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
19
|
before: () => testValidatorFactory()
|
|
19
20
|
}
|
|
20
21
|
});
|
|
22
|
+
const debug = (0, _debug.default)('@natlibfi/marc-record-validators-melinda/ending-whitespace:test');
|
|
21
23
|
async function testValidatorFactory() {
|
|
22
24
|
const validator = await (0, _endingWhitespace.default)();
|
|
23
25
|
(0, _chai.expect)(validator).to.be.an('object').that.has.any.keys('description', 'validate');
|
|
@@ -26,8 +28,13 @@ async function testValidatorFactory() {
|
|
|
26
28
|
}
|
|
27
29
|
async function callback({
|
|
28
30
|
getFixture,
|
|
31
|
+
enabled = true,
|
|
29
32
|
fix = false
|
|
30
33
|
}) {
|
|
34
|
+
if (enabled === false) {
|
|
35
|
+
debug('TEST SKIPPED!');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
31
38
|
const validator = await (0, _endingWhitespace.default)();
|
|
32
39
|
const record = new _marcRecord.MarcRecord(getFixture('record.json'));
|
|
33
40
|
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","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;
|
|
1
|
+
{"version":3,"file":"ending-whitespace.spec.js","names":["generateTests","callback","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","mocha","before","testValidatorFactory","debug","createDebugLogger","validator","validatorFactory","expect","to","be","an","that","has","any","keys","description","a","validate","getFixture","enabled","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';\nimport createDebugLogger from 'debug';\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});\nconst debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/ending-whitespace:test');\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, enabled = true, fix = false}) {\n if (enabled === false) {\n debug('TEST SKIPPED!');\n return;\n }\n\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;AACA;AAAsC;AAEtC,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;AACF,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,iEAAiE,CAAC;AAElG,eAAeF,oBAAoB,GAAG;EACpC,MAAMG,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,eAAezB,QAAQ,CAAC;EAAC2B,UAAU;EAAEC,OAAO,GAAG,IAAI;EAAEC,GAAG,GAAG;AAAK,CAAC,EAAE;EACjE,IAAID,OAAO,KAAK,KAAK,EAAE;IACrBhB,KAAK,CAAC,eAAe,CAAC;IACtB;EACF;EAEA,MAAME,SAAS,GAAG,MAAM,IAAAC,yBAAgB,GAAE;EAC1C,MAAMe,MAAM,GAAG,IAAIC,sBAAU,CAACJ,UAAU,CAAC,aAAa,CAAC,CAAC;EACxD,MAAMK,cAAc,GAAGL,UAAU,CAAC,qBAAqB,CAAC;EAExD,IAAI,CAACE,GAAG,EAAE;IACR,MAAMI,MAAM,GAAG,MAAMnB,SAAS,CAACY,QAAQ,CAACI,MAAM,CAAC;IAC/C,IAAAd,YAAM,EAACiB,MAAM,CAAC,CAAChB,EAAE,CAACiB,GAAG,CAACF,cAAc,CAAC;IACrC;EACF;EAEA,MAAMlB,SAAS,CAACe,GAAG,CAACC,MAAM,CAAC;EAC3B,IAAAd,YAAM,EAACc,MAAM,CAAC,CAACb,EAAE,CAACiB,GAAG,CAACF,cAAc,CAAC;AACvC"}
|
package/dist/index.js
CHANGED
|
@@ -33,12 +33,6 @@ 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
|
-
});
|
|
42
36
|
Object.defineProperty(exports, "FieldExclusion", {
|
|
43
37
|
enumerable: true,
|
|
44
38
|
get: function () {
|
|
@@ -81,12 +75,6 @@ Object.defineProperty(exports, "ItemLanguage", {
|
|
|
81
75
|
return _itemLanguage.default;
|
|
82
76
|
}
|
|
83
77
|
});
|
|
84
|
-
Object.defineProperty(exports, "NonBreakingSpace", {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
get: function () {
|
|
87
|
-
return _nonBreakingSpace.default;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
78
|
Object.defineProperty(exports, "NormalizeUTF8Diacritics", {
|
|
91
79
|
enumerable: true,
|
|
92
80
|
get: function () {
|
|
@@ -134,7 +122,6 @@ var _doubleCommas = _interopRequireDefault(require("./double-commas"));
|
|
|
134
122
|
var _duplicatesInd = _interopRequireDefault(require("./duplicates-ind1"));
|
|
135
123
|
var _emptyFields = _interopRequireDefault(require("./empty-fields"));
|
|
136
124
|
var _endingPunctuation = _interopRequireDefault(require("./ending-punctuation"));
|
|
137
|
-
var _endingWhitespace = _interopRequireDefault(require("./ending-whitespace"));
|
|
138
125
|
var _fieldsPresent = _interopRequireDefault(require("./fields-present"));
|
|
139
126
|
var _fieldStructure = _interopRequireDefault(require("./field-structure"));
|
|
140
127
|
var _fixedFields = _interopRequireDefault(require("./fixed-fields"));
|
|
@@ -142,7 +129,6 @@ var _fieldExclusion = _interopRequireDefault(require("./field-exclusion"));
|
|
|
142
129
|
var _identicalFields = _interopRequireDefault(require("./identical-fields"));
|
|
143
130
|
var _isbnIssn = _interopRequireDefault(require("./isbn-issn"));
|
|
144
131
|
var _itemLanguage = _interopRequireDefault(require("./item-language"));
|
|
145
|
-
var _nonBreakingSpace = _interopRequireDefault(require("./non-breaking-space"));
|
|
146
132
|
var _normalizeUtf8Diacritics = _interopRequireDefault(require("./normalize-utf8-diacritics"));
|
|
147
133
|
var _punctuation = _interopRequireDefault(require("./punctuation/"));
|
|
148
134
|
var _resolvableExtReferencesMelinda = _interopRequireDefault(require("./resolvable-ext-references-melinda"));
|
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
|
|
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 ResolvableExtReferences from './resolvable-ext-references-melinda';\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 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;AAAwB"}
|
|
@@ -15,7 +15,9 @@ function _default() {
|
|
|
15
15
|
fix
|
|
16
16
|
};
|
|
17
17
|
function validate(record) {
|
|
18
|
-
const nonValidFields = record.fields.filter(
|
|
18
|
+
const nonValidFields = record.fields.filter(({
|
|
19
|
+
subfields
|
|
20
|
+
}) => subfields.filter(valueContainsNonBreakingSpace).length > 0);
|
|
19
21
|
const valid = nonValidFields.length === 0;
|
|
20
22
|
const messages = nonValidFields.flatMap(({
|
|
21
23
|
tag,
|
|
@@ -28,22 +30,14 @@ function _default() {
|
|
|
28
30
|
valid,
|
|
29
31
|
messages
|
|
30
32
|
};
|
|
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
|
-
}
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
/* eslint-disable functional/immutable-data,functional/no-conditional-statement */
|
|
40
36
|
function fix(record) {
|
|
41
|
-
record.fields.forEach(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
field.subfields.forEach(subfield => {
|
|
37
|
+
record.fields.forEach(({
|
|
38
|
+
subfields
|
|
39
|
+
}) => {
|
|
40
|
+
subfields.forEach(subfield => {
|
|
47
41
|
if (valueContainsNonBreakingSpace(subfield)) {
|
|
48
42
|
subfield.value = subfield.value.replaceAll(/\u00A0/gu, ' ');
|
|
49
43
|
}
|
|
@@ -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","subfields","valueContainsNonBreakingSpace","length","valid","messages","flatMap","tag","map","sf","code","forEach","subfield","value","replaceAll","test"],"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(({subfields}) => subfields.filter(valueContainsNonBreakingSpace).length > 0);\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\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 (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,CAAC,CAAC;MAACC;IAAS,CAAC,KAAKA,SAAS,CAACD,MAAM,CAACE,6BAA6B,CAAC,CAACC,MAAM,GAAG,CAAC,CAAC;IAExH,MAAMC,KAAK,GAAGN,cAAc,CAACK,MAAM,KAAK,CAAC;IACzC,MAAME,QAAQ,GAAGP,cAAc,CAACQ,OAAO,CAAC,CAAC;MAACC,GAAG;MAAEN;IAAS,CAAC,KAAKA,SAAS,CAACO,GAAG,CAACC,EAAE,IAAK,SAAQF,GAAI,cAAaE,EAAE,CAACC,IAAK,2CAA0C,CAAC,CAAC;IAEhK,OAAON,KAAK,GAAG;MAACA,KAAK;MAAEC,QAAQ,EAAE;IAAE,CAAC,GAAG;MAACD,KAAK;MAAEC;IAAQ,CAAC;EAC1D;;EAEA;EACA,SAAST,GAAG,CAACC,MAAM,EAAE;IACnBA,MAAM,CAACE,MAAM,CAACY,OAAO,CAAC,CAAC;MAACV;IAAS,CAAC,KAAK;MACrCA,SAAS,CAACU,OAAO,CAACC,QAAQ,IAAI;QAC5B,IAAIV,6BAA6B,CAACU,QAAQ,CAAC,EAAE;UAC3CA,QAAQ,CAACC,KAAK,GAAGD,QAAQ,CAACC,KAAK,CAACC,UAAU,CAAC,UAAU,EAAE,GAAG,CAAC;QAC7D;MACF,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;EACA;;EAEA,SAASZ,6BAA6B,CAAC;IAACW;EAAK,CAAC,EAAE;IAC9C,OAAQ,SAAS,CAAEE,IAAI,CAACF,KAAK,CAAC;EAChC;AACF"}
|
|
@@ -5,6 +5,7 @@ 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"));
|
|
8
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
10
|
(0, _fixugen.default)({
|
|
10
11
|
callback,
|
|
@@ -18,6 +19,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
19
|
before: () => testValidatorFactory()
|
|
19
20
|
}
|
|
20
21
|
});
|
|
22
|
+
const debug = (0, _debug.default)('@natlibfi/marc-record-validators-melinda/non-breaking-space:test');
|
|
21
23
|
async function testValidatorFactory() {
|
|
22
24
|
const validator = await (0, _nonBreakingSpace.default)();
|
|
23
25
|
(0, _chai.expect)(validator).to.be.an('object').that.has.any.keys('description', 'validate');
|
|
@@ -26,8 +28,13 @@ async function testValidatorFactory() {
|
|
|
26
28
|
}
|
|
27
29
|
async function callback({
|
|
28
30
|
getFixture,
|
|
31
|
+
enabled = true,
|
|
29
32
|
fix = false
|
|
30
33
|
}) {
|
|
34
|
+
if (enabled === false) {
|
|
35
|
+
debug('TEST SKIPPED!');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
31
38
|
const validator = await (0, _nonBreakingSpace.default)();
|
|
32
39
|
const record = new _marcRecord.MarcRecord(getFixture('record.json'));
|
|
33
40
|
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","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;
|
|
1
|
+
{"version":3,"file":"non-breaking-space.spec.js","names":["generateTests","callback","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","mocha","before","testValidatorFactory","debug","createDebugLogger","validator","validatorFactory","expect","to","be","an","that","has","any","keys","description","a","validate","getFixture","enabled","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';\nimport createDebugLogger from 'debug';\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});\nconst debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/non-breaking-space:test');\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, enabled = true, fix = false}) {\n if (enabled === false) {\n debug('TEST SKIPPED!');\n return;\n }\n\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;AACA;AAAsC;AAEtC,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;AACF,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,kEAAkE,CAAC;AAEnG,eAAeF,oBAAoB,GAAG;EACpC,MAAMG,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,eAAezB,QAAQ,CAAC;EAAC2B,UAAU;EAAEC,OAAO,GAAG,IAAI;EAAEC,GAAG,GAAG;AAAK,CAAC,EAAE;EACjE,IAAID,OAAO,KAAK,KAAK,EAAE;IACrBhB,KAAK,CAAC,eAAe,CAAC;IACtB;EACF;EAEA,MAAME,SAAS,GAAG,MAAM,IAAAC,yBAAgB,GAAE;EAC1C,MAAMe,MAAM,GAAG,IAAIC,sBAAU,CAACJ,UAAU,CAAC,aAAa,CAAC,CAAC;EACxD,MAAMK,cAAc,GAAGL,UAAU,CAAC,qBAAqB,CAAC;EAExD,IAAI,CAACE,GAAG,EAAE;IACR,MAAMI,MAAM,GAAG,MAAMnB,SAAS,CAACY,QAAQ,CAACI,MAAM,CAAC;IAC/C,IAAAd,YAAM,EAACiB,MAAM,CAAC,CAAChB,EAAE,CAACiB,GAAG,CAACF,cAAc,CAAC;IACrC;EACF;EAEA,MAAMlB,SAAS,CAACe,GAAG,CAACC,MAAM,CAAC;EAC3B,IAAAd,YAAM,EAACc,MAAM,CAAC,CAACb,EAAE,CAACiB,GAAG,CAACF,cAAc,CAAC;AACvC"}
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "git@github.com:natlibfi/marc-record-validators-melinda.git"
|
|
15
15
|
},
|
|
16
16
|
"license": "MIT",
|
|
17
|
-
"version": "10.0.
|
|
17
|
+
"version": "10.0.2",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"access": "public"
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@babel/register": "^7.18.9",
|
|
39
39
|
"@natlibfi/issn-verify": "^1.0.0",
|
|
40
40
|
"@natlibfi/marc-record": "^7.2.2",
|
|
41
|
-
"@natlibfi/marc-record-validate": "^
|
|
41
|
+
"@natlibfi/marc-record-validate": "^7.0.3",
|
|
42
42
|
"cld3-asm": "^3.1.1",
|
|
43
43
|
"debug": "^4.3.4",
|
|
44
44
|
"isbn3": "^1.1.30",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"clone": "^2.1.2"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@natlibfi/marc-record-validate": "^
|
|
51
|
+
"@natlibfi/marc-record-validate": "^7.0.3"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@babel/cli": "^7.20.7",
|
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
|
|
13
|
+
const nonValidFields = record.fields.filter(({subfields}) => 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,10 +21,6 @@ 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
|
-
|
|
28
24
|
subfields.forEach(subfield => {
|
|
29
25
|
if (valueEndsWithWhitespace(subfield)) {
|
|
30
26
|
subfield.value = subfield.value.trimEnd();
|
|
@@ -3,6 +3,7 @@ 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';
|
|
6
7
|
|
|
7
8
|
generateTests({
|
|
8
9
|
callback,
|
|
@@ -16,6 +17,7 @@ generateTests({
|
|
|
16
17
|
before: () => testValidatorFactory()
|
|
17
18
|
}
|
|
18
19
|
});
|
|
20
|
+
const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/ending-whitespace:test');
|
|
19
21
|
|
|
20
22
|
async function testValidatorFactory() {
|
|
21
23
|
const validator = await validatorFactory();
|
|
@@ -28,7 +30,12 @@ async function testValidatorFactory() {
|
|
|
28
30
|
expect(validator.validate).to.be.a('function');
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
async function callback({getFixture, fix = false}) {
|
|
33
|
+
async function callback({getFixture, enabled = true, fix = false}) {
|
|
34
|
+
if (enabled === false) {
|
|
35
|
+
debug('TEST SKIPPED!');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
const validator = await validatorFactory();
|
|
33
40
|
const record = new MarcRecord(getFixture('record.json'));
|
|
34
41
|
const expectedResult = getFixture('expectedResult.json');
|
package/src/index.js
CHANGED
|
@@ -3,7 +3,6 @@ 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';
|
|
7
6
|
import FieldsPresent from './fields-present';
|
|
8
7
|
import FieldStructure from './field-structure';
|
|
9
8
|
import FixedFields from './fixed-fields';
|
|
@@ -11,7 +10,6 @@ import FieldExclusion from './field-exclusion';
|
|
|
11
10
|
import IdenticalFields from './identical-fields';
|
|
12
11
|
import IsbnIssn from './isbn-issn';
|
|
13
12
|
import ItemLanguage from './item-language';
|
|
14
|
-
import NonBreakingSpace from './non-breaking-space';
|
|
15
13
|
import NormalizeUTF8Diacritics from './normalize-utf8-diacritics';
|
|
16
14
|
import Punctuation from './punctuation/';
|
|
17
15
|
import ResolvableExtReferences from './resolvable-ext-references-melinda';
|
|
@@ -26,7 +24,6 @@ export {
|
|
|
26
24
|
DuplicatesInd1,
|
|
27
25
|
EmptyFields,
|
|
28
26
|
EndingPunctuation,
|
|
29
|
-
EndingWhitespace,
|
|
30
27
|
FieldExclusion,
|
|
31
28
|
FieldsPresent,
|
|
32
29
|
FieldStructure,
|
|
@@ -34,7 +31,6 @@ export {
|
|
|
34
31
|
IdenticalFields,
|
|
35
32
|
IsbnIssn,
|
|
36
33
|
ItemLanguage,
|
|
37
|
-
NonBreakingSpace,
|
|
38
34
|
NormalizeUTF8Diacritics,
|
|
39
35
|
Punctuation,
|
|
40
36
|
ResolvableExtReferences,
|
|
@@ -10,31 +10,18 @@ export default function () {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
function validate(record) {
|
|
13
|
-
const nonValidFields = record.fields.filter((
|
|
13
|
+
const nonValidFields = record.fields.filter(({subfields}) => subfields.filter(valueContainsNonBreakingSpace).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} 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
|
-
}
|
|
27
19
|
}
|
|
28
20
|
|
|
29
21
|
/* eslint-disable functional/immutable-data,functional/no-conditional-statement */
|
|
30
22
|
function fix(record) {
|
|
31
|
-
record.fields.forEach((
|
|
32
|
-
|
|
33
|
-
field.value = field.value.replaceAll(/\u00A0/gu, ' ');
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
field.subfields.forEach(subfield => {
|
|
23
|
+
record.fields.forEach(({subfields}) => {
|
|
24
|
+
subfields.forEach(subfield => {
|
|
38
25
|
if (valueContainsNonBreakingSpace(subfield)) {
|
|
39
26
|
subfield.value = subfield.value.replaceAll(/\u00A0/gu, ' ');
|
|
40
27
|
}
|
|
@@ -3,6 +3,7 @@ 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';
|
|
6
7
|
|
|
7
8
|
generateTests({
|
|
8
9
|
callback,
|
|
@@ -16,6 +17,7 @@ generateTests({
|
|
|
16
17
|
before: () => testValidatorFactory()
|
|
17
18
|
}
|
|
18
19
|
});
|
|
20
|
+
const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/non-breaking-space:test');
|
|
19
21
|
|
|
20
22
|
async function testValidatorFactory() {
|
|
21
23
|
const validator = await validatorFactory();
|
|
@@ -28,7 +30,12 @@ async function testValidatorFactory() {
|
|
|
28
30
|
expect(validator.validate).to.be.a('function');
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
async function callback({getFixture, fix = false}) {
|
|
33
|
+
async function callback({getFixture, enabled = true, fix = false}) {
|
|
34
|
+
if (enabled === false) {
|
|
35
|
+
debug('TEST SKIPPED!');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
const validator = await validatorFactory();
|
|
33
40
|
const record = new MarcRecord(getFixture('record.json'));
|
|
34
41
|
const expectedResult = getFixture('expectedResult.json');
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
}
|