UNPKG

yoastseo

Version:

Yoast client-side content analysis

41 lines (38 loc) 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = _default; var _matchTextWithWord = _interopRequireDefault(require("./matchTextWithWord")); var _lodash = require("lodash"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** @module stringProcessing/matchTextWithArray */ /** * Matches strings from an array against a given text. * * @param {String} text The text to match. * @param {Array} array The array with strings to match. * @param {String} [locale = "en_EN"] The locale of the text to get transliterations. * @param {function} matchWordCustomHelper The language-specific helper function to match word in text. * * @returns {Object} An array with all matches of the text, the number of the matches, and the lowest number of positions of the matches. */ function _default(text, array, locale = "en_EN", matchWordCustomHelper) { let count = 0; let matches = []; let positions = []; (0, _lodash.uniq)(array).forEach(function (wordToMatch) { const occurrence = (0, _matchTextWithWord.default)(text, wordToMatch, locale, matchWordCustomHelper); count += occurrence.count; matches = matches.concat(occurrence.matches); positions.push(occurrence.position); }); // Filtered out negative number, i.e. -1. positions = positions.filter(position => position >= 0); return { count: count, matches: matches, position: positions.length === 0 ? -1 : Math.min(...positions) }; } //# sourceMappingURL=matchTextWithArray.js.map