New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

fuzzyfind

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fuzzyfind

FuzzyFind is a matching algorithm for filtering and ranking a list based on partial user input.

latest
Source
npmnpm
Version
2.1.0
Version published
Maintainers
2
Created
Source

FuzzyFind

FuzzyFind is a matching algorithm for filtering and ranking a list based on partial user input.

API

array fuzzyfind ( string $query , array $collection [, object $options ])

All Options

  • accessor function: Function that transforms your items into strings.
  • precision number: How precise you want your search to be, between 0 and 1.

Usage

var fuzzyfind = require('fuzzyfind')
var collection = [
    'migrations.py',
    'django_migrations.py',
    'django_admin_log.py',
    'api_user.doc',
    'user_group.doc',
    'users.txt',
    'accounts.txt'
]

console.log(fuzzyfind('djmi', collection))
[ 'django_migrations.py', 'django_admin_log.py' ]

If you want to pass in an array of anything other than a string you can also provide an accessor function as the third argument. This must return a string.

var fuzzyfind = require('fuzzyfind')
var collection = [
    { name: 'migrations.py', size: '12kb'},
    { name: 'django_migrations.py', size: '11kb'},
    { name: 'django_admin_log.py', size: '10kb'},
    { name: 'api_user.doc', size: '9kb'},
    { name: 'user_group.doc', size: '13kb'},
    { name: 'users.txt', size: '12kb'},
    { name: 'accounts.txt', size: '10kb'},
]

function accessorFn (obj) {
    return obj.name
}
console.log(fuzzyfind('djmi', collection, { accessor: accessorFn }))
[ 'django_migrations.py', 'django_admin_log.py' ]

Precision can also be defined in your search, if you want to be more inclusive in your results. The lower your precision the more matches you get, with a precision of 1 you want to match the full word, while a precision of 0 would be matching any letter in your query.

The size of the match is taking into account, so having less precision would just be adding more results to the end of your results.

To define precision:

var fuzzyfind = require('fuzzyfind')
var collection = [
    'migrations.py',
    'django_migrations.py',
    'django_admin_log.py',
    'api_user.doc',
    'user_group.doc',
    'users.txt',
    'accounts.txt'
]

console.log(fuzzyfind('djmi', collection, { precision: 0.5 }))
[ 'django_migrations.py', 'django_admin_log.py', 'migrations.py' ]

The algorithm was influenced by a blog post about fuzzy finding.

FAQs

Package last updated on 02 Nov 2021

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