'use strict'; var feedback$8 = require('./matcher/bruteforce/feedback.cjs'); var feedback$7 = require('./matcher/date/feedback.cjs'); var feedback$6 = require('./matcher/dictionary/feedback.cjs'); var feedback$5 = require('./matcher/regex/feedback.cjs'); var feedback$4 = require('./matcher/repeat/feedback.cjs'); var feedback$3 = require('./matcher/sequence/feedback.cjs'); var feedback$2 = require('./matcher/spatial/feedback.cjs'); var feedback$1 = require('./matcher/separator/feedback.cjs'); var feedback = require('./matcher/wordSequence/feedback.cjs'); const defaultFeedback = { warning: null, suggestions: [] }; /* * ------------------------------------------------------------------------------- * Generate feedback --------------------------------------------------------------- * ------------------------------------------------------------------------------- */ class Feedback { constructor(options) { this.options = options; this.matchers = {}; this.defaultFeedback = { warning: null, suggestions: [] }; this.setDefaultSuggestions(); this.matchers = { bruteforce: feedback$8, date: feedback$7, dictionary: feedback$6, regex: feedback$5, repeat: feedback$4, sequence: feedback$3, spatial: feedback$2, separator: feedback$1, wordSequence: feedback }; Object.entries(this.options.matchers).forEach(([key, matcher]) => { if (matcher.feedback) { this.matchers[key] = matcher.feedback; } }); } setDefaultSuggestions() { this.defaultFeedback.suggestions.push(this.options.translations.suggestions.useWords, this.options.translations.suggestions.noNeed); } getFeedback(score, sequence) { if (sequence.length === 0) { return this.defaultFeedback; } if (score > 2) { return defaultFeedback; } const extraFeedback = this.options.translations.suggestions.anotherWord; const longestMatch = this.getLongestMatch(sequence); let feedback = this.getMatchFeedback(longestMatch, sequence.length === 1); if (feedback !== null && feedback !== undefined) { feedback.suggestions.unshift(extraFeedback); } else { feedback = { warning: null, suggestions: [extraFeedback] }; } return feedback; } getLongestMatch(sequence) { let longestMatch = sequence[0]; // ignore first entry for (let i = 1; i < sequence.length; i += 1) { const match = sequence[i]; if (match.token.length > longestMatch.token.length) { longestMatch = match; } } return longestMatch; } getMatchFeedback(match, isSoleMatch) { if (this.matchers[match.pattern]) { return this.matchers[match.pattern](this.options, match, isSoleMatch); } return defaultFeedback; } } module.exports = Feedback; //# sourceMappingURL=Feedback.cjs.map