Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fuzzyjs

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fuzzyjs

Fuzzy matching in Javascript

  • 3.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.1K
decreased by-4.79%
Maintainers
1
Weekly downloads
 
Created
Source

fuzzyjs

Build Status Coverage Status

fuzzyjs is a fuzzy search algorithm in javascript.

Usage

test

Tests a query against a source using fuzzy matching

import { test } from 'fuzzyjs'

test('ssjs', 'Set Syntax: JavaScript')
true
const test: (query: string, source: string, opts?: TestOptions) => boolean

type TestOptions = {
  caseSensitive: boolean // (default: false)
}

match

Matches a query against a source using fuzzy matching, returns information about the result

import { match } from 'fuzzyjs'

match('ssjs', 'Set Syntax: JavaScript')
{ match: true }

match('ssjs', 'Set Syntax: JavaScript', { withScore: true })
{ match: true, score: 22 }

match('ssjav', 'Set Syntax: JavaScript', { withRanges: true })
{
  match: true,
  ranges: [
    { start: 0, stop: 1 },
    { start: 4, stop: 5 },
    { start: 12, stop: 15 }
  ]
}
const match: (query: string, source: string, opts?: MatchOptions) => MatchResult

type MatchOptions = TestOptions & {
  strategy?: ScoreStrategy // (default: see below)
  withRanges?: boolean // (default: false)
  withScore?: boolean // (default: false)
}

type MatchResult = {
  match: boolean
  score?: number
  ranges?: Array<MatchRange>
}

Utilities

surround

Surround parts of the string that matched with prefix and suffix

import { match, surround } from 'fuzzyjs'

const result = match('ssjav', 'Set Syntax: JavaScript', { withRanges: true })

surround(
  'Set Syntax: JavaScript',
  {
    result,
    prefix: '<strong>',
    suffix: '</strong>'
  }
)
'<strong>S</strong>et <strong>S</strong>yntax: <strong>Jav</strong>aScript'
const surround: (source: string, options: SurroundOptions) => string

type SurroundOptions = {
  result: {
    ranges: Array<MatchRange>
  }
  prefix?: string // (default: '')
  suffix?: string // (default: '')
}

Scoring function

A scoring function is a function that given two context, returns a number (either positive or negative) that will be added the the match score.

A leading character is a character that matters more than others. These are made of capitals and letters follwoing -_ ./\.

const pushScore: (previousContext: ScoreContext, context: ScoreContext) => number

type ScoreContext = {
  currentScore: number // the current match score
  character: string // the current character
  match: boolean // is the character matching the source string
  leading: boolean // is the character leading
}

Link to default strategy: here.

License

fuzzyjs is licensed under MIT License.

Keywords

FAQs

Package last updated on 15 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc