# lazy-facet

> A Javascript facet filtering.

Latest version **1.1.0** (published 2017-11-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install lazy-facet
pnpm add lazy-facet
yarn add lazy-facet
bun add lazy-facet
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2017-11-28 |
| First published | 2017-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | GabrielCheung128 |
| Maintainers | gabrielcheung128 |
| Keywords | Javascript, facet, filtering |

## Links

- npm: https://www.npmjs.com/package/lazy-facet
- Repository: https://github.com/GabrielCheung128/lazy-facet
- Homepage: https://github.com/GabrielCheung128/lazy-facet#readme
- Issues: https://github.com/GabrielCheung128/lazy-facet/issues
- npm.io page: https://npm.io/package/lazy-facet

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.85

## Recent versions

- 1.1.0 (latest) — 2017-11-28
- 1.0.2 (stable) — 2017-11-23
- 1.0.1 — 2017-11-17

## README

# Introduction
This is a Javascript facet filtering based on Typescript. Easily integrated with modern Javacript Framework or any Nodejs backend project. 

## Get started

### Install

With npm:

```shell
  npm install -S lazy-facet
```

### Settings

Config passing in: {
  data: [] - require.
  execOnChange: true/false - execute on each push
  countOnly: return count only on facet result
  grouping: {
    key: [groups] - goupings
  }
};

### Example usage

Execute on every push:

```typescript
import Facet from 'lazy-facet';

const data = [{
    firstName: 'Eddard',
    lastName: 'Stark',
    gender: 'male',
    age: 45,
    house: 'Stark',
  }...];

const facet = new Facet({
  data: data,
  execOnChange: true,
    // when true, it will return result every time you push a condition.
    // when false, it will not trigger the exec only when you call it. 
  grouping: {
    house: [], // when the grouping depends on the values of the data
    gender: ['male', 'female'], // when the grouping not depending on the given data.
    age: ['1-10', '11-20', '21-30', '31-40', '41'], // when the grouping is range.
  }
});

const initResult = facet.init(); //initialize the app and return the init facet panel and result data.
const initFacet = initResult.facet;
const initResult = initResult.result;

let filterResult = facet.push({
  group: 'house',
  value: 'Stark',
  selected: true,
});

console.log(filterResult.facet);
console.log(filterResult.result);

// cancel a selection
filterResult = facet.push({
  group: 'house',
  value: 'Stark',
  selected: false,
});

console.log(filterResult.facet);
console.log(filterResult.result);

// reset to init state
filterResult = facet.reset();
console.log(filterResult.facet);
console.log(filterResult.result);
```

Execute only when called: 

```typescript
import Facet from 'lazy-facet';

const data = [{
    firstName: 'Eddard',
    lastName: 'Stark',
    gender: 'male',
    age: 45,
    house: 'Stark',
  }...];

const facet = new Facet({
  data: data,
  execOnChange: false,
  grouping: {
    house: [],
    gender: ['male', 'female'],
    age: ['1-10', '11-20', '21-30', '31-40', '41'],
  }
});


const initResult = facet.init(); //initialize the app and return the init facet panel and result data.
const initFacet = initResult.facet;
const initResult = initResult.result;

facet.push([{
  group: 'house',
  value: 'Stark',
  selected: true,
}, {
  group: 'gender',
  value: 'male',
  selected: true,
}]); // You could push serval conditions in one time.
facet.push({
  group: 'gender',
  value: 'male',
  selected: false,
})
const filterResult = facet.exec();
console.log(filterResult.facet);
console.log(filterResult.result);
```

Passing a boolean as the second variable as push to overide the `exceOnChange` setting

```typescript
const filterResult = facet.push({
  group: 'gender',
  value: 'male',
  selected: false,
}, true);
```

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