yoastseo
Version:
Yoast client-side content analysis
64 lines (59 loc) • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.unifyWhiteSpace = exports.unifyNonBreakingSpace = exports.unifyEmDash = exports.unifyAllSpaces = exports.default = void 0;
/** @module stringProcessing/unifyWhitespace */
/**
* Replaces a non-breaking space with a normal space.
*
* @param {string} text The string to replace the non-breaking space in.
*
* @returns {string} The text with unified spaces.
*/
const unifyNonBreakingSpace = function (text) {
return text.replace(/ /g, " ");
};
/**
* Replaces an em dash with a normal space.
*
* @param {string} text The string to replace the em dash in.
*
* @returns {string} The text with unified spaces.
*/
exports.unifyNonBreakingSpace = unifyNonBreakingSpace;
const unifyEmDash = function (text) {
return text.replace(/\u2014/g, " ");
};
/**
* Replaces all whitespace characters with a normal space.
*
* @param {string} text The string to replace the whitespace characters in.
*
* @returns {string} The text with unified spaces.
*/
exports.unifyEmDash = unifyEmDash;
const unifyWhiteSpace = function (text) {
return text.replace(/\s/g, " ");
};
/**
* Converts all whitespace to spaces.
*
* @param {string} text The text to replace spaces.
*
* @returns {string} The text with unified spaces.
*/
exports.unifyWhiteSpace = unifyWhiteSpace;
const unifyAllSpaces = function (text) {
text = unifyNonBreakingSpace(text);
text = unifyEmDash(text);
return unifyWhiteSpace(text);
};
exports.unifyAllSpaces = unifyAllSpaces;
var _default = exports.default = {
unifyNonBreakingSpace: unifyNonBreakingSpace,
unifyEmDash: unifyEmDash,
unifyWhiteSpace: unifyWhiteSpace,
unifyAllSpaces: unifyAllSpaces
};
//# sourceMappingURL=unifyWhitespace.js.map