How to use fast-levenshtein - 9 common examples

To help you get started, we’ve selected a few fast-levenshtein examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GilbertGobbels / GAwesomeBot / Internals / Events / message / GAB.SpamHandler.js View on Github external
const timedServerDocument = await Servers.findOne(msg.guild.id).catch(err => {
						winston.debug(`Failed to get server document for spam filter..`, err);
					});
					if (serverDocument) {
						const timedChannelDocument = timedServerDocument.query.id("channels", msg.channel.id);
						spamDocument = timedChannelDocument.id("spam_filter_data", msg.author.id);
						if (spamDocument.val) {
							spamDocument.remove();
							timedServerDocument.save().catch(err => {
								winston.debug("Failed to save server data for spam filter", { svrid: msg.guild.id }, err);
							});
						}
					}
				}, 45000);
				// Add this message to spamDocument if similar to the last one
			} else if (levenshtein.get(spamDocument.val.last_message_content, msg.cleanContent) < 3) {
				spamDocument.inc("message_count").set("last_message_content", msg.cleanContent);

				// First-time spam filter violation
				if (spamDocument.val.message_count === serverDocument.config.moderation.filters.spam_filter.message_sensitivity) {
					// eslint-disable-next-line max-len
					winston.verbose(`Handling first-time spam from member "${msg.author.tag}" in channel "${msg.channel.name}" on server "${msg.guild}" `, { svrid: msg.guild.id, chid: msg.channel.id, usrid: msg.author.id });
					this.client.logMessage(serverDocument, LoggingLevels.INFO,
						`Handling first-time spam from member "${msg.author.tag}" in channel "${msg.channel.name}".`, msg.channel.id, msg.author.id);
					// Message user and tell them to stop
					msg.author.send({
						embed: {
							color: Colors.RED,
							title: `⚠️ Stop Spamming! ⚠️`,
							description: `Stop spamming in #${msg.channel.name} (${msg.channel}) on ${msg.guild}.\nThe chat moderators have been notified about this.`,
						},
					});
github gooddata / gooddata-js / test / helpers / execution.ts View on Github external
return Object.keys(candidate).reduce((sum, prop: string) => {
            const definitionString: string = definition[prop] || "";
            return sum + levenshtein.get(definitionString, candidate[prop]);
        }, 0);
    });
github gooddata / gooddata-js / test / helpers / execution.ts View on Github external
return getClosestMatch(candidates, candidate => {
        return levenshtein.get(column, candidate);
    });
}
github electrode-io / electrode-native / ern-orchestrator / src / Ensure.ts View on Github external
availablePlatformKeys().reduce((acc, cur) =>
          levenshtein.get(acc, k) > levenshtein.get(cur, k) ? cur : acc
        )
github arestivo / splurt / src / scraper / data / ScholarDataScraper.ts View on Github external
public async getData(article: Article): Promise<article> {
    await delay(Math.random() * (this.throttle * 1000))

    article.cites = 0
    article.abstract = ''

    const $ = await this.getCheerio(article)
    const articles = $('.gs_r')

    for (const element of articles.toArray()) {
      const title = $(element).find('h3 a').text()
      if (levenshtein.get(article.title.toLowerCase(), title.toLowerCase(), { useCollator: true }) &lt; 3) {
        const citeText = $(element).find('.gs_or_cit').next().text()
        if (citeText.startsWith('Cited by')) {
          const matches = citeText.match(/\d+/)
          if (matches !== null) article.cites = parseInt(matches[0])
        } else article.cites = 0

        article.link = $(element).find('h3 a').attr('href')
        article.abstract = await AbstractScraper.getAbstract(article.link)
        if (article.abstract === '') article.abstract = 'ASKED FOR ABSTRACT AND ALL I GET WAS THIS LOUSY T-SHIRT'
      }
    }

    return article
  }
</article>
github 4Catalyzer / astroturf / src / loader.js View on Github external
idents.forEach(ident =&gt; {
    const d = levenshtein.get(ident, identifier);
    if (d &lt; minDistance) {
      minDistance = d;
      closest = ident;
    }
  });
  const isDefaultImport = type === 'ImportDefaultSpecifier';
github phylogeny-explorer / explorer / common / databases / public / models / clade.js View on Github external
    .reduce((previous, current) => Math.min(previous, Levenshtein.get(query, current, {useCollator: true})), 9999);
}
github kiwicom / monorepo-shipit / src / requireAndValidateConfig.js View on Github external
return alternativeNames.sort((firstEl, secondEl) => {
    const firstScore = levenshtein.get(name, firstEl);
    const secondScore = levenshtein.get(name, secondEl);
    return firstScore - secondScore;
  })[0];
}

fast-levenshtein

Efficient implementation of Levenshtein algorithm with locale-specific collator support.

MIT
Latest version published 4 years ago

Package Health Score

70 / 100
Full package analysis

Popular fast-levenshtein functions