# json-cnf

> Functions for filtering SQL-like json with conjunctive normal form filters

Latest version **0.0.8** (published 2019-02-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-cnf
pnpm add json-cnf
yarn add json-cnf
bun add json-cnf
```

## 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.0.8 |
| Published | 2019-02-10 |
| First published | 2018-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 26 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sumner Magruder |
| Maintainers | sumneuron |
| Keywords | json, sql, cnf, conjunctive, normal, form, filter |

## Links

- npm: https://www.npmjs.com/package/json-cnf
- Repository: https://gitlab.com/SumNeuron/json-cnf
- Homepage: https://gitlab.com/SumNeuron/json-cnf#README
- Issues: https://gitlab.com/SumNeuron/json-cnf/issues
- npm.io page: https://npm.io/package/json-cnf

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.0.8 (latest) — 2019-02-10
- 0.0.7 — 2019-02-10
- 0.0.6 — 2019-02-10
- 0.0.5 — 2019-02-10
- 0.0.4 — 2019-01-03
- 0.0.3 — 2019-01-03
- 0.0.2 — 2019-01-03
- 0.0.1 — 2018-12-19
- 0.0.0 — 2018-12-19

## README

# JSON-CNF
What is CNF?

CNF is short for Conjunctive Normal Form, which is a way of arranging logical arguments into groups of logical OR statements between AND statements, e.g.

```
(statement_{1,1} OR, .... statement_{1,i})
AND
(statement_{2,1} OR, .... statement_{2,j})
AND
...
AND
(statement_{x,1} OR, .... statement_{x,k})
```

Assuming your JSON data is in an SQL-like format:

```
{
  recordID_1: {
    column1: value,
    column2: value,
    ...,
    columnN: value
  },

  ...,

  recordID_M: {
    column1: value,
    column2: value,
    ...,
    columnN: value
  }
}
```

This library allows you to easily apply a list of filters
in CNF to your JSON to find which records pass the filters.



There are two main functions:
- groupByConjunctiveNormalForm: takes a list of filters and returns arranges them in CNF
- filterJSON: takes your JSON and a list of filters and applies the CNF grouping of those filters to the JSON



## What's a filter

A filter consists of five parts:

1. logic: AND or OR (defaults to AND)
2. function: applied to the value of the field prior to the comparisons (defaults to the identity function)
3. conditional: a logical test (defaults to equality)
4. field: a field in your records
5. input: what the value should be compared to


thus a filter is applied to a record as so:

```
conditional(function(record[field]), input)
```

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