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

deep-condition

v1.0.0

Published

Simple and lightweight library for filtering arrays with predefined human-friendly conditions.

Downloads

1

Readme

deep-condition

Simple and lightweight library for filtering arrays with predefined human-friendly conditions For usage in browser use file source/index.js

Install

Node

npm install deep-condition --save

Usage

let filterFunction = require('deep-condition');

let sampleData = [
    {"rank": 1, "rating": 9.2, "year": null, "title": "The Shawshank Redemption"},
    {"rank": 2, "rating": 9.2, "year": 1972, "title": "The Godfather"},
    {"rank": 3, "rating": 9, "year": 1974, "title": "The Godfather: Part II"},
    {"rank": 4, "rating": 8.9, "year": 1966, "title": "Il buono, il brutto, il cattivo."},
    {"rank": 5, "rating": 8.9, "year": 1994, "title": "Pulp Fiction"},
    {"rank": 6, "rating": 8.9, "year": 1957, "title": "12 Angry Men"},
    {"rank": 7, "rating": 8.9, "year": 1993, "title": "Schindler's List"},
    {"rank": 8, "rating": 8.8, "year": 1975, "title": "One Flew Over the Cuckoo's Nest"},
    {"rank": 9, "rating": 8.8, "year": 2010, "title": "Inception"},
    {"rank": 0, "rating": 8.8, "year": 2008, "title": "The Dark Knight"}
];

let filter = {
    logic: 'or',
    filters: [
        {
            logic: 'and',
            filters: [
                {field: 'rating', operator: 'eq', value: 8.8},
                {field: 'year', operator: 'gt', value: 2000}
            ]
        },
        {field: 'title', operator: 'contains', value: 'Godfather'}
    ]
};

let result = filterFunction(sampleData, filter);

console.dir(result);

/** OUTPUT:
[ { rank: 2, rating: 9.2, year: 1972, title: 'The Godfather' },
  { rank: 3, rating: 9, year: 1974, title: 'The Godfather: Part II' },
  { rank: 9, rating: 8.8, year: 2010, title: 'Inception' },
  { rank: 0, rating: 8.8, year: 2008, title: 'The Dark Knight' } ]
**/

Description

Types of filter conditions (EXAMPLES)

Filter group

let filterExample = {
    logic: 'or',
    filters: [
        {
            logic: 'and',
            filters: [
                {field: 'rating', operator: 'eq', value: 8.8},
                {field: 'year', operator: 'gt', value: 2000}
            ]
        },
        {field: 'title', operator: 'contains', value: 'Godfather'}
    ]
};

Simple condition

let filterExample = {field: 'rating', operator: 'eq', value: 8.8};

Array of simple conditions

By default uses logic: AND

let filterExample = [{field: 'rating', operator: 'eq', value: 8.8}, {field: 'year', operator: 'eq', value: 2010}];
let resultFiltering = filterFunction(sampleData, filterExample);

Supported types of conditions

  • eq - equal
let filter = {field: 'rating', operator: 'eq', value: 8.8};
  • neq - not equal
let filter = {field: 'rating', operator: 'neq', value: 8.8};
  • isnull - is null
let filter = {field: 'year', operator: 'isnull'};
  • isnotnull - is not null
let filter = {field: 'year', operator: 'isnotnull'};
  • lt - less than
let filter = {field: 'rating', operator: 'lt', value: 8.9};
  • lte - less than or equal
let filter = {field: 'rating', operator: 'lte', value: 8.9};
  • gt - greater than
let filter = {field: 'rating', operator: 'gt', value: 8.9};
  • gte - greater than or equal
let filter = {field: 'rating', operator: 'gte', value: 8.9};
  • startswith - starts with
let filter = {field: 'title', operator: 'startswith', value: 'The'};
  • endswith - ends with
let filter = {field: 'title', operator: 'endswith', value: 'tion'};
  • contains - contains
let filter = {field: 'title', operator: 'contains', value: 'Godfather'};
  • doesnotcontain - does not contain
let filter = {field: 'title', operator: 'doesnotcontain', value: 'Godfather'};
  • isempty - is empty
let filter = {field: 'rank', operator: 'isempty'};
  • isnotempty - is not empty
let filter = {field: 'rank', operator: 'isnotempty'};

FOR MORE EXAMPLES SEE test/filtering.js file in package FOR JSDOC DESCRIPTIONS SEE source/index.js file in package

Test

Test

npm install
npm run test

Change list

Version 1.0.0

  • Initial commit