# bparser

> A boolean expression parser

Latest version **0.1.1** (published 2021-03-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install bparser
pnpm add bparser
yarn add bparser
bun add bparser
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2021-03-29 |
| First published | 2021-03-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 53.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Thierry PAGES |
| Maintainers | thipages |
| Keywords | boolean, expression, parser |

## Links

- npm: https://www.npmjs.com/package/bparser
- Repository: https://github.com/thipages/bparser
- Homepage: https://github.com/thipages/bparser#readme
- Issues: https://github.com/thipages/bparser/issues
- npm.io page: https://npm.io/package/bparser

## 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

- 0.1.1 (latest) — 2021-03-29
- 0.1.0 — 2021-03-29

## README

# bparser

A boolean (OR, AND) expression parser

## Installation
- via npm : _npm i bparser_

```javascript
import bparser from 'bparser';
// then
bparser(expression,regExp);

```
- via HTML
```html
<script src="min.js"></script>
<script>
    // then
    bparser(expression,regExp);
</script>
```
## Usage
```javscript
const pathsObjet = bparser(expression,regExp);
```
`expression` : String containing
- comparison operator(s) : `AND,OR`
- with optional opening/closing parentheses `(,)` 
- with items to be compared
  
`regExp` : RegExp allowing to identify the items to be compared

`returns` an object with the following properties
- `isValid`, a boolean for a valid/invalid expression
- `results`, an array (`OR` list) of the different `AND` paths or an empty array of `isValid` is `false`


## Examples
RegExp: `/[a-z]/g`

Expression                    | Results
--------                      | ---------
`a AND b`                     | `[[a, b]]`
`a OR  b`                     | `[[a], [b]]`
`a AND b AND c`               | `[[a, b, c]]`
`a AND b OR  c`               | `[[a, b], [c]]`
`a AND (b OR c)`              | `[[a, b], [a, c]]`
`a AND (b OR c) AND (d OR e)` | `[[a, b, d], [a, b, e], [a, c, d], [a, c, e]]`

RegExp: `/'.+?'/g`

Expression                    | Results
--------                      | ---------
`"'a' AND 'b' OR 'c'" `         | `["'a'","'b'"],["'c'"]`


### More complex example

###### Regex : `/[a-z]/g`
###### Expression:
```
((a AND (b OR c)) AND (d AND e) AND (f OR g OR h)) OR i OR j
```

###### Results:
```
[[a,b,d,e,f],
 [a,c,d,e,f],
 [a,b,d,e,g],
 [a,c,d,e,g],
 [a,b,d,e,h],
 [a,c,d,e,h],
 [i],
 [j]]
```
## Related projects
 ###  [Boolean-parser](https://github.com/riichard/boolean-parser-js)
The majority of the examples comes from this other (and fun) implementation

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