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

search-filter-options

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

search-filter-options

Tokenize search string in groups of options for search filter

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

search-filter-options

Incremental tokenizer

Purpose

UX of project requires filter with large amount of fields (20-30), e.g. email, provider, status etc. with any combinations of theese fields.

Solution - make search string filter which transform string like :provider stripe :status pending into object like

{
    provider: 'stripe',
    status: 'pending'
}

Description

Create instance of parser and parse

Browser
var sfo = new SearchFilterOptions();
...
sfo.parse(' :provider stripe  :status  pending ');
constructor

SearchFilterOptions({ sigil = ':', keys = [], trim = true } = {})

where

  • sigil - char that starts key word, default is :
  • keys - array of expected keyword objects { name: 'name of key', flag: 'optional, true if this variable is a flag'}
  • trim - to trim keys and values, default true
return object
{
    data: {     //all found keys
        key: {
            value: 'string'
        }
    },
    expected: { //all expected keywords that matches `keys` argument in constructor
        key: {
            value: string,
            exists: boolean,
            flag: boolean
        }
    },
    extra: string //everything before first keyword
}
parsing

parse(string) - return result object. Parser saves previous state, and if next string differs by one letter, then restore previous state and increment data

Examples

see test file on github.com

Keywords

FAQs

Package last updated on 16 May 2020

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