@natlibfi/marc-record-validators-melinda 9.2.0 → 9.2.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ending-whitespace.js +55 -0
- package/dist/ending-whitespace.js.map +1 -0
- package/dist/ending-whitespace.spec.js +49 -0
- package/dist/ending-whitespace.spec.js.map +1 -0
- package/dist/non-breaking-space.js +55 -0
- package/dist/non-breaking-space.js.map +1 -0
- package/dist/non-breaking-space.spec.js +49 -0
- package/dist/non-breaking-space.spec.js.map +1 -0
- package/package.json +1 -1
- package/src/ending-whitespace.js +36 -0
- package/src/ending-whitespace.spec.js +51 -0
- package/src/non-breaking-space.js +36 -0
- package/src/non-breaking-space.spec.js +51 -0
- package/test-fixtures/ending-whitespace/01/expectedResult.json +4 -0
- package/test-fixtures/ending-whitespace/01/metadata.json +5 -0
- package/test-fixtures/ending-whitespace/01/record.json +15 -0
- package/test-fixtures/ending-whitespace/02/expectedResult.json +4 -0
- package/test-fixtures/ending-whitespace/02/metadata.json +5 -0
- package/test-fixtures/ending-whitespace/02/record.json +15 -0
- package/test-fixtures/ending-whitespace/03/expectedResult.json +17 -0
- package/test-fixtures/ending-whitespace/03/metadata.json +5 -0
- package/test-fixtures/ending-whitespace/03/record.json +15 -0
- package/test-fixtures/non-breaking-space/01/expectedResult.json +4 -0
- package/test-fixtures/non-breaking-space/01/metadata.json +5 -0
- package/test-fixtures/non-breaking-space/01/record.json +15 -0
- package/test-fixtures/non-breaking-space/02/expectedResult.json +4 -0
- package/test-fixtures/non-breaking-space/02/metadata.json +5 -0
- package/test-fixtures/non-breaking-space/02/record.json +15 -0
- package/test-fixtures/non-breaking-space/03/expectedResult.json +17 -0
- package/test-fixtures/non-breaking-space/03/metadata.json +5 -0
- package/test-fixtures/non-breaking-space/03/record.json +15 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = _default;
|
|
7
|
+
/**
|
|
8
|
+
* Provides interface to validate and fix record fields, which include subfields that end with whitespace character
|
|
9
|
+
* @returns {Object} Object containing interfaces required by marc-record-validators-melinda package
|
|
10
|
+
*/
|
|
11
|
+
function _default() {
|
|
12
|
+
return {
|
|
13
|
+
description: 'Handles subfields that ends with whitespace character',
|
|
14
|
+
validate,
|
|
15
|
+
fix
|
|
16
|
+
};
|
|
17
|
+
function validate(record) {
|
|
18
|
+
const nonValidFields = record.fields.filter(({
|
|
19
|
+
subfields
|
|
20
|
+
}) => subfields.filter(valueEndsWithWhitespace).length > 0);
|
|
21
|
+
const valid = nonValidFields.length === 0;
|
|
22
|
+
const messages = nonValidFields.flatMap(({
|
|
23
|
+
tag,
|
|
24
|
+
subfields
|
|
25
|
+
}) => subfields.map(sf => `Field ${tag} subfield $${sf.code} ends with whitespace`));
|
|
26
|
+
return valid ? {
|
|
27
|
+
valid,
|
|
28
|
+
messages: []
|
|
29
|
+
} : {
|
|
30
|
+
valid,
|
|
31
|
+
messages
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* eslint-disable functional/immutable-data,functional/no-conditional-statement */
|
|
36
|
+
function fix(record) {
|
|
37
|
+
record.fields.forEach(({
|
|
38
|
+
subfields
|
|
39
|
+
}) => {
|
|
40
|
+
subfields.forEach(subfield => {
|
|
41
|
+
if (valueEndsWithWhitespace(subfield)) {
|
|
42
|
+
subfield.value = subfield.value.trimEnd();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/* eslint-enable functional/immutable-data,functional/no-conditional-statement */
|
|
48
|
+
|
|
49
|
+
function valueEndsWithWhitespace({
|
|
50
|
+
value
|
|
51
|
+
}) {
|
|
52
|
+
return /\s$/u.test(value);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=ending-whitespace.js.map
|
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _chai = require("chai");
|
|
4
|
+
var _marcRecord = require("@natlibfi/marc-record");
|
|
5
|
+
var _endingWhitespace = _interopRequireDefault(require("./ending-whitespace"));
|
|
6
|
+
var _fixura = require("@natlibfi/fixura");
|
|
7
|
+
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
8
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
(0, _fixugen.default)({
|
|
11
|
+
callback,
|
|
12
|
+
path: [__dirname, '..', 'test-fixtures', 'ending-whitespace'],
|
|
13
|
+
useMetadataFile: true,
|
|
14
|
+
recurse: false,
|
|
15
|
+
fixura: {
|
|
16
|
+
reader: _fixura.READERS.JSON
|
|
17
|
+
},
|
|
18
|
+
mocha: {
|
|
19
|
+
before: () => testValidatorFactory()
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const debug = (0, _debug.default)('@natlibfi/marc-record-validators-melinda/ending-whitespace:test');
|
|
23
|
+
async function testValidatorFactory() {
|
|
24
|
+
const validator = await (0, _endingWhitespace.default)();
|
|
25
|
+
(0, _chai.expect)(validator).to.be.an('object').that.has.any.keys('description', 'validate');
|
|
26
|
+
(0, _chai.expect)(validator.description).to.be.a('string');
|
|
27
|
+
(0, _chai.expect)(validator.validate).to.be.a('function');
|
|
28
|
+
}
|
|
29
|
+
async function callback({
|
|
30
|
+
getFixture,
|
|
31
|
+
enabled = true,
|
|
32
|
+
fix = false
|
|
33
|
+
}) {
|
|
34
|
+
if (enabled === false) {
|
|
35
|
+
debug('TEST SKIPPED!');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const validator = await (0, _endingWhitespace.default)();
|
|
39
|
+
const record = new _marcRecord.MarcRecord(getFixture('record.json'));
|
|
40
|
+
const expectedResult = getFixture('expectedResult.json');
|
|
41
|
+
if (!fix) {
|
|
42
|
+
const result = await validator.validate(record);
|
|
43
|
+
(0, _chai.expect)(result).to.eql(expectedResult);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
await validator.fix(record);
|
|
47
|
+
(0, _chai.expect)(record).to.eql(expectedResult);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=ending-whitespace.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = _default;
|
|
7
|
+
/**
|
|
8
|
+
* Provides interface to validate and fix record fields, which include subfields that contain no-breaking space character
|
|
9
|
+
* @returns {Object} Object containing interfaces required by marc-record-validators-melinda package
|
|
10
|
+
*/
|
|
11
|
+
function _default() {
|
|
12
|
+
return {
|
|
13
|
+
description: 'Handles subfields that contains non-breaking space character',
|
|
14
|
+
validate,
|
|
15
|
+
fix
|
|
16
|
+
};
|
|
17
|
+
function validate(record) {
|
|
18
|
+
const nonValidFields = record.fields.filter(({
|
|
19
|
+
subfields
|
|
20
|
+
}) => subfields.filter(valueContainsNonBreakingSpace).length > 0);
|
|
21
|
+
const valid = nonValidFields.length === 0;
|
|
22
|
+
const messages = nonValidFields.flatMap(({
|
|
23
|
+
tag,
|
|
24
|
+
subfields
|
|
25
|
+
}) => subfields.map(sf => `Field ${tag} subfield $${sf.code} contains non-breaking space character(s)`));
|
|
26
|
+
return valid ? {
|
|
27
|
+
valid,
|
|
28
|
+
messages: []
|
|
29
|
+
} : {
|
|
30
|
+
valid,
|
|
31
|
+
messages
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* eslint-disable functional/immutable-data,functional/no-conditional-statement */
|
|
36
|
+
function fix(record) {
|
|
37
|
+
record.fields.forEach(({
|
|
38
|
+
subfields
|
|
39
|
+
}) => {
|
|
40
|
+
subfields.forEach(subfield => {
|
|
41
|
+
if (valueContainsNonBreakingSpace(subfield)) {
|
|
42
|
+
subfield.value = subfield.value.replaceAll(/\u00A0/gu, ' ');
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/* eslint-enable functional/immutable-data,functional/no-conditional-statement */
|
|
48
|
+
|
|
49
|
+
function valueContainsNonBreakingSpace({
|
|
50
|
+
value
|
|
51
|
+
}) {
|
|
52
|
+
return /\u00A0/u.test(value);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=non-breaking-space.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _chai = require("chai");
|
|
4
|
+
var _marcRecord = require("@natlibfi/marc-record");
|
|
5
|
+
var _nonBreakingSpace = _interopRequireDefault(require("./non-breaking-space"));
|
|
6
|
+
var _fixura = require("@natlibfi/fixura");
|
|
7
|
+
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
8
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
(0, _fixugen.default)({
|
|
11
|
+
callback,
|
|
12
|
+
path: [__dirname, '..', 'test-fixtures', 'non-breaking-space'],
|
|
13
|
+
useMetadataFile: true,
|
|
14
|
+
recurse: false,
|
|
15
|
+
fixura: {
|
|
16
|
+
reader: _fixura.READERS.JSON
|
|
17
|
+
},
|
|
18
|
+
mocha: {
|
|
19
|
+
before: () => testValidatorFactory()
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const debug = (0, _debug.default)('@natlibfi/marc-record-validators-melinda/non-breaking-space:test');
|
|
23
|
+
async function testValidatorFactory() {
|
|
24
|
+
const validator = await (0, _nonBreakingSpace.default)();
|
|
25
|
+
(0, _chai.expect)(validator).to.be.an('object').that.has.any.keys('description', 'validate');
|
|
26
|
+
(0, _chai.expect)(validator.description).to.be.a('string');
|
|
27
|
+
(0, _chai.expect)(validator.validate).to.be.a('function');
|
|
28
|
+
}
|
|
29
|
+
async function callback({
|
|
30
|
+
getFixture,
|
|
31
|
+
enabled = true,
|
|
32
|
+
fix = false
|
|
33
|
+
}) {
|
|
34
|
+
if (enabled === false) {
|
|
35
|
+
debug('TEST SKIPPED!');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const validator = await (0, _nonBreakingSpace.default)();
|
|
39
|
+
const record = new _marcRecord.MarcRecord(getFixture('record.json'));
|
|
40
|
+
const expectedResult = getFixture('expectedResult.json');
|
|
41
|
+
if (!fix) {
|
|
42
|
+
const result = await validator.validate(record);
|
|
43
|
+
(0, _chai.expect)(result).to.eql(expectedResult);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
await validator.fix(record);
|
|
47
|
+
(0, _chai.expect)(record).to.eql(expectedResult);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=non-breaking-space.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides interface to validate and fix record fields, which include subfields that end with whitespace character
|
|
3
|
+
* @returns {Object} Object containing interfaces required by marc-record-validators-melinda package
|
|
4
|
+
*/
|
|
5
|
+
export default function () {
|
|
6
|
+
return {
|
|
7
|
+
description: 'Handles subfields that ends with whitespace character',
|
|
8
|
+
validate,
|
|
9
|
+
fix
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function validate(record) {
|
|
13
|
+
const nonValidFields = record.fields.filter(({subfields}) => subfields.filter(valueEndsWithWhitespace).length > 0);
|
|
14
|
+
|
|
15
|
+
const valid = nonValidFields.length === 0;
|
|
16
|
+
const messages = nonValidFields.flatMap(({tag, subfields}) => subfields.map(sf => `Field ${tag} subfield $${sf.code} ends with whitespace`));
|
|
17
|
+
|
|
18
|
+
return valid ? {valid, messages: []} : {valid, messages};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/* eslint-disable functional/immutable-data,functional/no-conditional-statement */
|
|
22
|
+
function fix(record) {
|
|
23
|
+
record.fields.forEach(({subfields}) => {
|
|
24
|
+
subfields.forEach(subfield => {
|
|
25
|
+
if (valueEndsWithWhitespace(subfield)) {
|
|
26
|
+
subfield.value = subfield.value.trimEnd();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/* eslint-enable functional/immutable-data,functional/no-conditional-statement */
|
|
32
|
+
|
|
33
|
+
function valueEndsWithWhitespace({value}) {
|
|
34
|
+
return (/\s$/u).test(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {expect} from 'chai';
|
|
2
|
+
import {MarcRecord} from '@natlibfi/marc-record';
|
|
3
|
+
import validatorFactory from './ending-whitespace';
|
|
4
|
+
import {READERS} from '@natlibfi/fixura';
|
|
5
|
+
import generateTests from '@natlibfi/fixugen';
|
|
6
|
+
import createDebugLogger from 'debug';
|
|
7
|
+
|
|
8
|
+
generateTests({
|
|
9
|
+
callback,
|
|
10
|
+
path: [__dirname, '..', 'test-fixtures', 'ending-whitespace'],
|
|
11
|
+
useMetadataFile: true,
|
|
12
|
+
recurse: false,
|
|
13
|
+
fixura: {
|
|
14
|
+
reader: READERS.JSON
|
|
15
|
+
},
|
|
16
|
+
mocha: {
|
|
17
|
+
before: () => testValidatorFactory()
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/ending-whitespace:test');
|
|
21
|
+
|
|
22
|
+
async function testValidatorFactory() {
|
|
23
|
+
const validator = await validatorFactory();
|
|
24
|
+
|
|
25
|
+
expect(validator)
|
|
26
|
+
.to.be.an('object')
|
|
27
|
+
.that.has.any.keys('description', 'validate');
|
|
28
|
+
|
|
29
|
+
expect(validator.description).to.be.a('string');
|
|
30
|
+
expect(validator.validate).to.be.a('function');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function callback({getFixture, enabled = true, fix = false}) {
|
|
34
|
+
if (enabled === false) {
|
|
35
|
+
debug('TEST SKIPPED!');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const validator = await validatorFactory();
|
|
40
|
+
const record = new MarcRecord(getFixture('record.json'));
|
|
41
|
+
const expectedResult = getFixture('expectedResult.json');
|
|
42
|
+
|
|
43
|
+
if (!fix) {
|
|
44
|
+
const result = await validator.validate(record);
|
|
45
|
+
expect(result).to.eql(expectedResult);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
await validator.fix(record);
|
|
50
|
+
expect(record).to.eql(expectedResult);
|
|
51
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides interface to validate and fix record fields, which include subfields that contain no-breaking space character
|
|
3
|
+
* @returns {Object} Object containing interfaces required by marc-record-validators-melinda package
|
|
4
|
+
*/
|
|
5
|
+
export default function () {
|
|
6
|
+
return {
|
|
7
|
+
description: 'Handles subfields that contains non-breaking space character',
|
|
8
|
+
validate,
|
|
9
|
+
fix
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function validate(record) {
|
|
13
|
+
const nonValidFields = record.fields.filter(({subfields}) => subfields.filter(valueContainsNonBreakingSpace).length > 0);
|
|
14
|
+
|
|
15
|
+
const valid = nonValidFields.length === 0;
|
|
16
|
+
const messages = nonValidFields.flatMap(({tag, subfields}) => subfields.map(sf => `Field ${tag} subfield $${sf.code} contains non-breaking space character(s)`));
|
|
17
|
+
|
|
18
|
+
return valid ? {valid, messages: []} : {valid, messages};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/* eslint-disable functional/immutable-data,functional/no-conditional-statement */
|
|
22
|
+
function fix(record) {
|
|
23
|
+
record.fields.forEach(({subfields}) => {
|
|
24
|
+
subfields.forEach(subfield => {
|
|
25
|
+
if (valueContainsNonBreakingSpace(subfield)) {
|
|
26
|
+
subfield.value = subfield.value.replaceAll(/\u00A0/gu, ' ');
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/* eslint-enable functional/immutable-data,functional/no-conditional-statement */
|
|
32
|
+
|
|
33
|
+
function valueContainsNonBreakingSpace({value}) {
|
|
34
|
+
return (/\u00A0/u).test(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {expect} from 'chai';
|
|
2
|
+
import {MarcRecord} from '@natlibfi/marc-record';
|
|
3
|
+
import validatorFactory from './non-breaking-space';
|
|
4
|
+
import {READERS} from '@natlibfi/fixura';
|
|
5
|
+
import generateTests from '@natlibfi/fixugen';
|
|
6
|
+
import createDebugLogger from 'debug';
|
|
7
|
+
|
|
8
|
+
generateTests({
|
|
9
|
+
callback,
|
|
10
|
+
path: [__dirname, '..', 'test-fixtures', 'non-breaking-space'],
|
|
11
|
+
useMetadataFile: true,
|
|
12
|
+
recurse: false,
|
|
13
|
+
fixura: {
|
|
14
|
+
reader: READERS.JSON
|
|
15
|
+
},
|
|
16
|
+
mocha: {
|
|
17
|
+
before: () => testValidatorFactory()
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/non-breaking-space:test');
|
|
21
|
+
|
|
22
|
+
async function testValidatorFactory() {
|
|
23
|
+
const validator = await validatorFactory();
|
|
24
|
+
|
|
25
|
+
expect(validator)
|
|
26
|
+
.to.be.an('object')
|
|
27
|
+
.that.has.any.keys('description', 'validate');
|
|
28
|
+
|
|
29
|
+
expect(validator.description).to.be.a('string');
|
|
30
|
+
expect(validator.validate).to.be.a('function');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function callback({getFixture, enabled = true, fix = false}) {
|
|
34
|
+
if (enabled === false) {
|
|
35
|
+
debug('TEST SKIPPED!');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const validator = await validatorFactory();
|
|
40
|
+
const record = new MarcRecord(getFixture('record.json'));
|
|
41
|
+
const expectedResult = getFixture('expectedResult.json');
|
|
42
|
+
|
|
43
|
+
if (!fix) {
|
|
44
|
+
const result = await validator.validate(record);
|
|
45
|
+
expect(result).to.eql(expectedResult);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
await validator.fix(record);
|
|
50
|
+
expect(record).to.eql(expectedResult);
|
|
51
|
+
}
|