All Projects → gjuchault → Fuzzyjs

gjuchault / Fuzzyjs

Licence: mit
fuzzyjs is a fuzzy search algorithm in javascript

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Labels

Projects that are alternatives of or similar to Fuzzyjs

tlsh
TLSH lib in Golang
Stars: ✭ 110 (-34.91%)
Mutual labels:  fuzzy
Flexsearch
Next-Generation full text search library for Browser and Node.js
Stars: ✭ 8,108 (+4697.63%)
Mutual labels:  fuzzy
Fzy.js
A javascript port of fzy's scoring algorithm. As seen on GitHub.com!
Stars: ✭ 82 (-51.48%)
Mutual labels:  fuzzy
string-similarity-js
Lightweight string similarity function for javascript
Stars: ✭ 29 (-82.84%)
Mutual labels:  fuzzy
Fz
Cli shell plugin, the missing fuzzy tab completion feature of z jump around command.
Stars: ✭ 359 (+112.43%)
Mutual labels:  fuzzy
Fuzzy C Means
A simple python implementation of Fuzzy C-means algorithm.
Stars: ✭ 40 (-76.33%)
Mutual labels:  fuzzy
scikit-cmeans
Flexible, extensible fuzzy c-means clustering in python.
Stars: ✭ 18 (-89.35%)
Mutual labels:  fuzzy
Efll
eFLL (Embedded Fuzzy Logic Library) is a standard library for Embedded Systems
Stars: ✭ 131 (-22.49%)
Mutual labels:  fuzzy
Awgo
Go library for Alfred 3 + 4 workflows
Stars: ✭ 556 (+228.99%)
Mutual labels:  fuzzy
Alfred Fuzzy
Fuzzy search helper for Alfred 3+ workflows
Stars: ✭ 67 (-60.36%)
Mutual labels:  fuzzy
rofi-fontawesome
fontawesome icon list for rofi dmenu
Stars: ✭ 58 (-65.68%)
Mutual labels:  fuzzy
Fuzzy
Spell checking and fuzzy search suggestion written in Go
Stars: ✭ 290 (+71.6%)
Mutual labels:  fuzzy
Jump
Jump helps you navigate faster by learning your habits. ✌️
Stars: ✭ 1,024 (+505.92%)
Mutual labels:  fuzzy
svelte-typeahead
Accessible, fuzzy search typeahead component
Stars: ✭ 141 (-16.57%)
Mutual labels:  fuzzy
Mongoose Fuzzy Searching
Mongoose Fuzzy Searching Plugin
Stars: ✭ 94 (-44.38%)
Mutual labels:  fuzzy
fzfx
fzfX delivers the power of finding, previewing, editing and managing any file in few key strokes.
Stars: ✭ 71 (-57.99%)
Mutual labels:  fuzzy
Fuzzy
Go library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al.
Stars: ✭ 979 (+479.29%)
Mutual labels:  fuzzy
Z.lua
⚡ A new cd command that helps you navigate faster by learning your habits.
Stars: ✭ 2,164 (+1180.47%)
Mutual labels:  fuzzy
Leaderf
An efficient fuzzy finder that helps to locate files, buffers, mrus, gtags, etc. on the fly for both vim and neovim.
Stars: ✭ 1,733 (+925.44%)
Mutual labels:  fuzzy
Fuzzy Swift
🔍 simple and fast fuzzy string matching in Swift
Stars: ✭ 61 (-63.91%)
Mutual labels:  fuzzy

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, score: 22 }

match('ssjav', 'Set Syntax: JavaScript', { withScore: false, 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: true)
}

type MatchResult = {
  match: boolean
  score?: number
  ranges?: 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: MatchRange[]
  }
  prefix?: string // (default: '')
  suffix?: string // (default: '')
}

filter

Can be used as a Array.prototype.filter callback. You can use the sourceAccessor option if you pass an array of objects that contains the string you want to match.

import { filter as fuzzy } from 'fuzzyjs'

const sources = ['Set Syntax: JavaScript', 'Set Syntax: CSS', 'Set Syntax: HTML']

sources.filter(fuzzy('ssjs'))
[ 'Set Syntax: JavaScript' ]

const sources = [
  { name: { foo: 'Set Syntax: JavaScript' } },
  { name: { foo: 'Set Syntax: CSS' } },
  { name: { foo: 'Set Syntax: HTML' } }
]

sources.filter(fuzzy('ssjs', { sourceAccessor: source => source.name.foo }))
[ { name: { foo: 'Set Syntax: JavaScript' } } ]
const filter: (query: string, options?: FilterOptions) => (source: any) => boolean

type FilterOptions = TestOptions & {
  sourceAccessor?: (source: any) => string
}

sort

Can be used as a Array.prototype.sort callback. If you have a large array of objects, you might want to pass idAccessor as it creates a memoization table which reduces drastically how many times the fuzzy matching algorithm will be called.

import { sort as fuzzy } from 'fuzzyjs'

const sources = ['Set Syntax: CSS', 'Set Syntax: HTML', 'Set Syntax: JavaScript']

sources.sort(fuzzy('ssjs'))
[ 'Set Syntax: JavaScript', 'Set Syntax: CSS', 'Set Syntax: HTML' ]

const sources = [
  { name: { id: 0, foo: 'Set Syntax: CSS' } },
  { name: { id: 1, foo: 'Set Syntax: HTML' } },
  { name: { id: 2, foo: 'Set Syntax: JavaScript' } }
]

sources.sort(fuzzy('ssjs', { sourceAccessor: source => source.name.foo }))
[
  { name: { id: 2, foo: 'Set Syntax: JavaScript' } },
  { name: { id: 0, foo: 'Set Syntax: CSS' } },
  { name: { id: 1, foo: 'Set Syntax: HTML' } }
]

// same, but will be faster thanks to memoization
sources.sort(fuzzy('ssjs', { sourceAccessor: source => source.name.foo, idAccessor: source => source.name.id }))
[
  { name: { id: 2, foo: 'Set Syntax: JavaScript' } },
  { name: { id: 0, foo: 'Set Syntax: CSS' } },
  { name: { id: 1, foo: 'Set Syntax: HTML' } }
]
const sort: (query: string, options?: SortOptions) => (leftSource: any, rightSource: any) => 0 | 1 | -1

type SortOptions = MatchOptions & {
  sourceAccessor?: Accessor // used as an accessor if array is made of objects
  idAccessor?: Accessor // used as an accessor if you want fuzzy to be memoized
}

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].