UNPKG

yoastseo

Version:

Yoast client-side content analysis

44 lines (42 loc) 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = _default; var _keyphraseLengthFactor = _interopRequireDefault(require("./keyphraseLengthFactor.js")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * Calculates a recommended keyphrase count for a paper's text. The formula to calculate this number is based on the * keyphrase density formula. * * @param {number} keyphraseLength The length of the focus keyphrase in words. * @param {number} recommendedKeyphraseDensity The recommended keyphrase density (either maximum or minimum). * @param {string} maxOrMin Whether it's a maximum or minimum recommended keyphrase density. * @param {number} wordCount The length of the text in words. * * @returns {number} The recommended keyphrase count. */ function _default(keyphraseLength, recommendedKeyphraseDensity, maxOrMin, wordCount) { if (wordCount === 0) { return 0; } const lengthKeyphraseFactor = (0, _keyphraseLengthFactor.default)(keyphraseLength); const recommendedKeyphraseCount = recommendedKeyphraseDensity * wordCount / (100 * lengthKeyphraseFactor); /* The recommended keyphrase count should always be at least 2, regardless of the keyphrase density, the word count, or the keyphrase length. */ if (recommendedKeyphraseCount < 2) { return 2; } switch (maxOrMin) { case "min": // Round up for the recommended minimum count. return Math.ceil(recommendedKeyphraseCount); default: case "max": // Round down for the recommended maximum count. return Math.floor(recommendedKeyphraseCount); } } //# sourceMappingURL=recommendedKeywordCount.js.map