yoastseo
Version:
Yoast client-side content analysis
63 lines (59 loc) • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _syllableCountStep = _interopRequireDefault(require("./syllableCountStep.js"));
var _lodash = require("lodash");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* A SyllableCountIterator contains individual SyllableCountSteps.
*/
class SyllableCountIterator {
/**
* Creates a syllable count iterator.
*
* @param {object} config The config object containing an array with syllable exclusions.
* @constructor
*/
constructor(config) {
this.countSteps = [];
if (!(0, _lodash.isUndefined)(config)) {
this.createSyllableCountSteps(config.deviations.vowels);
}
}
/**
* Creates a syllable count step object for each exclusion.
*
* @param {object} syllableCounts The object containing all exclusion syllables including the multipliers.
* @returns {void}
*/
createSyllableCountSteps(syllableCounts) {
(0, _lodash.forEach)(syllableCounts, function (syllableCountStep) {
this.countSteps.push(new _syllableCountStep.default(syllableCountStep));
}.bind(this));
}
/**
* Returns all available count steps.
*
* @returns {Array} All available count steps.
*/
getAvailableSyllableCountSteps() {
return this.countSteps;
}
/**
* Counts the syllables for all the steps and returns the total syllable count.
*
* @param {String} word The word to count syllables in.
* @returns {number} The number of syllables found based on exclusions.
*/
countSyllables(word) {
let syllableCount = 0;
(0, _lodash.forEach)(this.countSteps, function (step) {
syllableCount += step.countSyllables(word);
});
return syllableCount;
}
}
exports.default = SyllableCountIterator;
//# sourceMappingURL=syllableCountIterator.js.map