UNPKG

yoastseo

Version:

Yoast client-side content analysis

30 lines (29 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = _default; var _yoastseo = require("yoastseo"); var _removeURLs = _interopRequireDefault(require("../../../helpers/sanitize/removeURLs.js")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const { sanitizeString } = _yoastseo.languageProcessing; /** * Calculates the character count which serves as a measure of text length. * The character count includes letters and numbers. It doesn't include URLs, HTML tags, spaces, and common punctuation characters. * * @param {string} text The text to be counted. * * @returns {number} The character count of the given text. */ function _default(text) { text = (0, _removeURLs.default)(text); text = sanitizeString(text); text = text.replace(/\s/g, ""); // 1st 〜: wave dash (U+301C); 2nd ~: fullwidth tilde (U+FF5E) // The list includes a few "Western" punctuation marks, added at the end, because they pop up in online Japanese text from time to time. text = text.replace(/[。.?!…‥,、・―〜~:゠=()「」『』〝〟〔〕【】[]{}〈〉《》.?!:;()"'<>]/g, ""); return text.length; } //# sourceMappingURL=countCharacters.js.map