yoastseo
Version:
Yoast client-side content analysis
55 lines (51 loc) • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _ScoreAggregator = _interopRequireDefault(require("./ScoreAggregator"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* The number to scale the score to.
*
* Individual scores are from 1 to 9.
* The total score should be multiplied by this number to scale up.
*
* @type {number}
* @const
*/
const ScoreScale = 100;
/**
* The factor to multiply the amount of results with.
*
* Individual scores are from 1 to 9.
* The make the total score work in the 100 scale, the amount of results needs to get multiplied by this factor.
*
* @type {number}
* @const
*/
const ScoreFactor = 9;
/**
* Aggregates SEO assessment results into a single score.
* @extends ScoreAggregator
*/
class SEOScoreAggregator extends _ScoreAggregator.default {
/**
* Aggregates the given assessment results into a single score.
*
* @param {AssessmentResult[]} results The assessment results.
*
* @returns {number} The aggregated score.
*/
aggregate(results) {
const score = results.reduce((sum, result) => sum + result.getScore(), 0);
/*
* Whenever the divide by part is 0 this can result in a `NaN` value. Then 0 should be returned as fallback.
* This seemed better than the check `results.length === 0`,
* because it also protects against ScoreFactor being 0.
*/
return Math.round(score * ScoreScale / (results.length * ScoreFactor)) || 0;
}
}
var _default = exports.default = SEOScoreAggregator;
//# sourceMappingURL=SEOScoreAggregator.js.map