# search-operators

> A search operators parser to filter search requests.

Latest version **1.0.9** (published 2020-07-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install search-operators
pnpm add search-operators
yarn add search-operators
bun add search-operators
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2020-07-19 |
| First published | 2020-04-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 31 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | fedemartinm |
| Maintainers | fedemartin |
| Keywords | search, parser, commands |

## Links

- npm: https://www.npmjs.com/package/search-operators
- Repository: https://github.com/fedemartinm/search-operators
- Homepage: https://github.com/fedemartinm/search-operators#readme
- Issues: https://github.com/fedemartinm/search-operators/issues
- npm.io page: https://npm.io/package/search-operators

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.9 (latest) — 2020-07-19
- 1.0.8 — 2020-04-23
- 1.0.7 — 2020-04-23
- 1.0.6 — 2020-04-23
- 1.0.5 — 2020-04-23
- 1.0.4 — 2020-04-23
- 1.0.3 — 2020-04-23
- 1.0.2 — 2020-04-23
- 1.0.1 — 2020-04-23

## README

![npm](https://img.shields.io/npm/v/search-operators)
![npm bundle size](https://img.shields.io/bundlephobia/minzip/search-operators?color=green)

# Search Operators
A search operators parser to filter search requests

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

### Installation
```shell
yarn add search-operators
```

or

```shell
npm install search-operators --save
```

### Basic Usage
```js
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


Operator | Description  | Parser input | Parser 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' } ] }
| **:** | match | in:general  | { filters:[ { type: 'match', key:'in', value: 'general' } ] }
| **not :** | inverse match  | not in:random  | { filters:[ { type: 'not-match', key:'in', value: 'random' } ] }

### API
- Parse
```js 
parser.parse(
  search, //string to parse
  { keys:[] } //keys used by match operator
);
```
- Tokens
```js 
//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](https://github.com/DmitrySoshnikov/syntax) is very well documented. Any contribution is very appreciated.

1. Fork [search-operators](https://github.com/fedemartinm/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](https://github.com/fedemartinm/search-operators/blob/master/LICENSE) do whatever you want to do!

---
_Source: https://npm.io/package/search-operators · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
