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

fuzzy-filter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fuzzy-filter

a browserify-compatible fuzzy string filtering function

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
509
increased by27.25%
Maintainers
1
Weekly downloads
 
Created
Source

Fuzzy-filter

Build Status

A browserify-compatible fuzzy string filtering function.

Used by Stratus Editor for the Snap Open plugin.

Parameters

pattern - The fuzzy String to match against.
items   - An Array of String.
options - (optional)
        * pre         - String to insert before matching text.
        * post        - String to insert after matching text.
        * limit       - Integer maximum number of results.
        * separator   - String separator. Match against the last
                        section of the String by default.
        * ignorecase  - Boolean (default: true).
        * ignorespace - Boolean (default: true).
        * separate    - Boolean (default: false). If set to true, the
                        function returns an array of an array of strings,
                        where each array is
                        [beforeLastSeparator, afterLastSeparator].
                        If set, `separator` must also be passed.

Note: If pre is passed, you also have to pass post (and vice-versa).

Examples

Simple usage

var fuzzy = require('fuzzy-filter')
fuzzy("cs", ["cheese", "pickles", "crackers", "pirate attack", "cs!!"])
// => ["cs!!", "cheese", "crackers"]

Highlight match

fuzzy("cs", ["cheese", "pickles", "crackers", "pirate attack", "cs!!"],
  { pre:  "<b>"
  , post: "</b>" })
// => ["<b>cs</b>!!", "<b>c</b>hee<b>s</b>e", "<b>c</b>racker<b>s</b>"]

Separator

fuzzy("cs", ["cookies", "cheese/pie", "fried/cheese", "cheese/cookies"],
  { pre:       "<b>"
  , post:      "</b>"
  , separator: "/" })
// => [ "<b>c</b>ookie<b>s</b>"
//    , "fried/<b>c</b>hee<b>s</b>e"
//    , "cheese/<b>c</b>ookie<b>s</b>" ]

fuzzy("cs/", ["cookies", "cheese/pie", "fried/cheese", "cheese/cookies"],
  { pre:       "<b>"
  , post:      "</b>"
  , separator: "/"})
// => [ "<b>c</b>hee<b>s</b>e/pie"
//    , "<b>c</b>hee<b>s</b>e/cookies" ]

fuzzy("cs/p", ["cookies", "cheese/pie", "fried/cheese", "cheese/cookies"],
  { pre:       "<b>"
  , post:      "</b>"
  , separator: "/"})
// => ["<b>c</b>hee<b>s</b>e/<b>p</b>ie"]

fuzzy("cs/p", ["cookies", "cheese/pie", "fried/cheese", "cheese/cookies"],
  { pre:       "<b>"
  , post:      "</b>"
  , separator: "/"
  , separate:  true })
// => [ ["<b>c</b>hee<b>s</b>e", "<b>p</b>ie"] ]

License

See LICENSE.

Keywords

FAQs

Package last updated on 09 Jul 2012

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