npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

filter-data

v0.6.1

Published

simple, fast data filter

Downloads

2,881

Readme

filter-data

npm version dependencies Status CircleCI codecov

Description

Simple but fast data filter.

Examples

  1. Example In Browser
  2. Example In React

Benchmark

100 Records(ms)

*The results are little different in partial search.

| | match-sorter (6.3.1) | fuse.js (6.6.2) | filter-data (0.2.0) | | :--- | :--: | :-: | :--: | | match all, 1 key | 10.947ms | 4.244ms | 1.827ms | | no match, 1 key | 0.523ms | 2.385ms | 2.958ms | | match partial, 1 key | 0.232ms | 0.318ms | 2.475ms | | match all, 2 keys | 1.472ms | 0.465ms | 2.209ms | | no match, 2 keys | 0.188ms | 0.513ms | 2.522ms | | match partial, 2 keys | 0.191ms | 0.318ms | 2.475ms | | match all, 1 key, slice(0,10) | 0.192ms | 0.206ms | 0.388ms | | no match, 1 key, slice(0,10) | 0.101ms | 0.317ms | 0.079ms | | match partial, 1 key, slice(0,10) | 0.107ms | 0.188ms | 2.807ms | | input empty | 0.114ms | 0.095ms | 0.033ms |

10000 Records(ms)

*The results are little different in partial search.

| | match-sorter (4.0.2) | fuse.js (3.4.6) | filter-data (0.2.0) | | :--- | :--: | :-: | :--: | | match all, 1 key | 21.439ms | 49.336ms | 16.884ms | | no match, 1 key | 18.239ms | 33.312ms | 6.382ms | | match partial, 1 key | 18.754ms | 22.56ms | 3.805ms | | match all, 2 keys | 22.815ms | 22.524ms | 10.416ms | | no match, 2 keys | 18.096ms | 33.232ms | 3.744ms | | match partial, 2 keys | 16.821ms | 27.052ms | 3.094ms | | match all, 1 key, slice(0,10) | 10.614ms | 12.692ms | 0.106ms | | no match, 1 key, slice(0,10) | 9.808ms | 19.709ms | 0.111ms | | match partial, 1 key, slice(0,10) | 9.593ms | 16.094ms | 0.393ms | | input empty | 10.571ms | 6.985ms | 0.03ms |

Install From Browser

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/filterdata.min.js"></script>

Installation

filter-data is available as an npm package.

npm install --save filter-data

Usage

From Browser

import from FilterData object. And others are the same with From npm

const { filterData, SearchType } = FilterData;
.
.
.

From npm

  1. search single key only.

    import { filterData, SearchType } from 'filter-data';
    
    // search firstName contains 'dan' and age < 20
    const searchConditions = [
      {
        key: 'firstName',
        value: 'dan',
        type: SearchType.LK,
      },
      {
        key: 'age',
        value: 20,
        type: SearchType.LT,
      },
    ];
    
    const result = filterData(data, searchConditions);
    // output:
    <!-- [
      { firstName: 'Daniel', age: 14 },
      { firstName: 'Dan', age: 18 },
    ] -->
  2. search multiple keys.

    import { filterData, SearchType } from 'filter-data';
    
    // search firstName&lastName contains 'dan' and age < 20
    const searchConditions = [
      {
        key: ['firstName', 'lastName'],
        value: 'dan',
        type: SearchType.LK,
      },
      {
        key: 'age',
        value: 20,
        type: SearchType.LT,
      },
    ];
    
    const result = filterData(data, searchConditions);
    // output:
    <!-- [
      { firstName: 'Daniel', lastName: 'Johnson', age: 13 },
      { firstName: 'Jack', lastName: 'Danny', age: 19 },
    ] -->
  3. caseSensitive.

    import { filterData, SearchType } from 'filter-data';
    
    // search firstName contains 'dan'
    const searchConditions = [
      {
        key: 'firstName',
        value: 'dan',
        type: SearchType.LK,
      },
    ];
    
    const result = filterData(data, searchConditions, { caseSensitive: true });
    // output:
    <!-- [
      { firstName: 'Jordan', age: 17 },
    ] -->
  4. offset & limit.

    import { filterData, SearchType } from 'filter-data';
    
    // search firstName contains 'dan'
    const searchConditions = [
      {
        key: 'firstName',
        value: 'dan',
        type: SearchType.LK,
      },
    ];
    
    const result = filterData(data, searchConditions, { caseSensitive: true, offset: 10, limit: 10 });
    // output:
    <!-- [
      { firstName: 'Jordan', age: 17 },
      .
      .
      .
      max 10 records
    ] -->
  5. search nested object.

    import { filterData, SearchType } from 'filter-data';
    
    // search firstName in father's sub object equals to 'dan'
    const searchConditions = [
      {
        key: 'father.firstName', // or key: [['father', 'firstName']]
        value: 'dan',
        type: SearchType.EQ,
      },
    ];
    
    const result = filterData(data, searchConditions);
    // output:
    <!-- [
      { firstName: 'Jordan', age: 17, father: { firstName: 'dan', age: 50 } },
    ] -->

Instructions

| No. | Parameter | required | Default | Description | |:---|:-------------:|:---------:|:--------------|:-----------| | 1 | data | 〇 | | array of object for filtering | | 2 | searchConditions | 〇 | | array of searchCondition; { key: 'search column', value: 'search value', type: 'search type' } | | 3 | options | | { caseSensitive: false, includeNull: false, offset: undefined, limit: undefined } | includeNull: include data even key is not exist or value is null |

SearchType

  • SearchType.EQ: equal
  • SearchType.GT: greater than
  • SearchType.GTE: greater than or equal
  • SearchType.LT: less than
  • SearchType.LTE: less than or equal
  • SearchType.LK: like
  • SearchType.NE: not equal
  • SearchType.NLK: not like

License

This project is licensed under the terms of the MIT license.