UNPKG

gmx-word-counter

Version:

Fast, GMX-V compliant word and character counter. Can count both logographic and non-logographic languages correctly. Also supports generic counting for cases when language is unknown.

37 lines 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCharacterCountFactor = getCharacterCountFactor; exports.isLogographicScript = isLogographicScript; exports.isUnsupportedLogographicScript = isUnsupportedLogographicScript; /* Chinese - zh Japenese - ja Korean - ko Thai - th */ const LOGOGRAPHIC_LANGUAGES = ['zh', 'ja', 'ko', 'th']; const LOGOGRAPHIC_LANGUAGE_SET = new Set(LOGOGRAPHIC_LANGUAGES); const UNSUPPORTED_LOGOGRAPHIC_SCRIPTS = ['lo', 'km', 'my']; const UNSUPPORTED_LOGOGRAPHIC_SCRIPT_SET = new Set(UNSUPPORTED_LOGOGRAPHIC_SCRIPTS); const LANGUAGE_WORD_COUNT_FACTORS = { zh: 2.8, ja: 3.0, ko: 3.3, th: 6.0, }; function getCharacterCountFactor(locale) { const countFactor = LANGUAGE_WORD_COUNT_FACTORS[locale]; // This should never happen, as we are checking before /* c8 ignore next 3 */ if (!countFactor) { throw new Error(`Unsupported locale: ${locale}`); } return countFactor; } function isLogographicScript(locale) { return LOGOGRAPHIC_LANGUAGE_SET.has(locale); } function isUnsupportedLogographicScript(locale) { return UNSUPPORTED_LOGOGRAPHIC_SCRIPT_SET.has(locale); } //# sourceMappingURL=logographicCounter.js.map