UNPKG

rosaenlg-filter

Version:

Filtering feature of RosaeNLG

45 lines 1.65 kB
"use strict"; /** * @license * Copyright 2019 Ludan Stoecklé * SPDX-License-Identifier: Apache-2.0 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.specialSpacesToNormalSpaces = exports.cleanStructAfterUnprotect = exports.cleanStruct = exports.joinLines = void 0; function joinLines(input) { return input.replace(/[\n\r]/g, ' '); } exports.joinLines = joinLines; function cleanStruct(input, constants) { let res = input; const regexBetweenNewPara = new RegExp(`☚([${constants.allPunctList}\\s]+)☛`, 'g'); res = res.replace(regexBetweenNewPara, () => { return '☚☛'; }); const regexOrphanDot = new RegExp(`☚([${constants.allPunctList}\\s]+)☚`, 'g'); res = res.replace(regexOrphanDot, () => { return '☚☚'; }); const regexSpacesBeginning = /(\s*)(☞[☞\s]*)\s+/g; res = res.replace(regexSpacesBeginning, (_match, before, between) => { return `${before}${between.replace(/\s/g, '')}`; }); const regexSpacesEnd = /\s+([☜\s]*☜)(\s*)/g; res = res.replace(regexSpacesEnd, (_match, between, after) => { return `${between.replace(/\s/g, '')}${after}`; }); return res; } exports.cleanStruct = cleanStruct; function cleanStructAfterUnprotect(input) { let res = input; const emptyParas = /<p>\.<\/p>/g; res = res.replace(emptyParas, ''); return res; } exports.cleanStructAfterUnprotect = cleanStructAfterUnprotect; function specialSpacesToNormalSpaces(input) { return input.replace(/¤/g, ' '); } exports.specialSpacesToNormalSpaces = specialSpacesToNormalSpaces; //# sourceMappingURL=clean.js.map