1.0.9 • Published 4 years ago

search-operators v1.0.9

Weekly downloads
10
License
MIT
Repository
github
Last release
4 years ago

npm npm bundle size

Search Operators

A search operators parser to filter search requests

  • Unicode support
  • Case-insensitive
  • Based on LR parser
  • No dependencies

Installation

yarn add search-operators

or

npm install search-operators --save

Basic Usage

const searchOperators = require('./search-operators');
var value = searchOperators.parse('+github.com useState useEffect');
console.log(value); 
//the parser will separate the text in terms and filters.
//{
//  "filters": [{ "type": "exact", "value": "github.com" }],
//  "terms": ["useState","useEffect"]
//}

Operators

OperatorDescriptionParser inputParser output
" "exact word or phrase"bash history file"{ filters : { type: 'exact', value: 'bash history file' } }
+exact word+github.com{ filters: { type: 'exact', value: 'github.com' } }
-exclude word-php{ filters: { type: 'exclude', value: 'php' } }
:matchin:general{ filters: { type: 'match', key:'in', value: 'general' } }
not :inverse matchnot in:random{ filters: { type: 'not-match', key:'in', value: 'random' } }

API

  • Parse
parser.parse(
  search, //string to parse
  { keys:[] } //keys used by match operator
);
  • Tokens
//populated after parse, contains token location
//useful to highlight syntax!
parser.parse("-😊");
console.log(parser.tokens);
//{
//    type: 'EXCLUDE_OP',
//    value: '😊',
//    startOffset: 0,
//    endOffset: 3,
//    startLine: 1,
//    endLine: 1,
//    startColumn: 0,
//    endColumn: 3
//}

Development

This project is intended to be extended or modified. It's uses syntax to generate the parser; in case you need to modify the grammar, syntax is very well documented. Any contribution is very appreciated.

  1. Fork search-operators repo.
  2. Make your changes
  3. Validate grammar with npm run validate
  4. Test parser with npm run test

Use npm run build to transpile and generate production build.

Licence

MIT do whatever you want to do!

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago