@talkohavy/filters
TypeScript icon, indicating that this package has built-in type declarations

1.0.27 • Public • Published

@talkohavy/filters

Easy & intuitive way to apply complex filters.

NPM Version

Features

This package exposes the class object of Filter.
Filter holds 2 powerful methods for you to utilize:

  • applyFilters
  • changeSchema

Installation

Using npm:

npm install @talkohavy/filters

Using pnpm:

pnpm add @talkohavy/filters

Using yarn:

yarn add @talkohavy/filters

How to use

Here's a code example of how to use the package:

import { Filterer } from '@talkohavy/filters';

const dummyData = [
  {
    id: 1,
    name: 'Dander Mente',
    type: 'customer',
    orders: { amount: 10 },
    address: 'NY USA',
    order: 'A4BC',
    tax: 145.2,
    total: 13.9,
  },
  {
    id: 2,
    name: 'Tracey Bill',
    type: 'customer',
    orders: { amount: 10, isVIP: null },
    address: 'NJ USA',
    order: 'A8O7X',
    tax: 1.2,
    total: 93.46,
  },
  {
    id: 3,
    name: 'Gina Doe',
    type: 'worker',
    address: 'CA USA',
    order: 'B3KL',
    tax: 75.6,
    total: 30.1,
  },
];

/** @type {Filter} */
const filterScheme = [
  { fieldName: 'name', value: 'Dan', operator: 'startsWith' },
  { fieldName: 'total', value: 13.8, operator: 'gte' },
];

const filterer = new Filterer({ filterScheme });
const filteredData = filterer.applyFilters({ data: dummyData });

console.log(filteredData);

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @talkohavy/filters

Weekly Downloads

1

Version

1.0.27

License

MIT

Unpacked Size

10.3 kB

Total Files

4

Last publish

Collaborators

  • talkohavy