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

@smartorigin/smart-filter

v1.0.4

Published

A module that allows smart filtering over js array using SQL-Like where clause.

Downloads

62

Readme

@smartorigin/smart-filter

npm version License: MIT

A module that allows smart filtering over js array using SQL-Like where clause.

Getting started

npm install @smartorigin/smart-filter

Usage

Capabilities of the mobule.

With smart-filter you can test if an object match an SLQ-Like where clause.

It could be used to expose to end user an high level language and to easily process end user expressions in JS.

You can filter/test object using the following syntax : (assuming propA and propB are properties of a js object)

propA = 1

propA = "2"

propA = true

propA = 'Hello'

propA = "Hello" OR propA = "Hi"

propA = "Hello" AND propA = "Hi"

!(propA = "Hello" AND propA = "Hi")

propA IN ["Hello","Hi"]

propA NOTIN ["Hello","Hi"]

propA <> propB

propA > 2

propA < 4

propA <= 4

propA >= 4

1=1 //means keep all

1!=1 //means keep none

You can also write operator like this :

= -> ==
AND -> && 
OR -> ||
<> -> !=

This module is build using JSEP.

ES6

see also /test/index.js

First import exposed functions :

import {filter,test} from '@smartorigin/smart-filter'

function test(obj,expr)

let input = {
    "propA":2,
    "propB":"OK",
    "propC":true,
    "propD":4,
    "propE":false,
    "propF":"KO"
}

//simple equality
test(input,'propA == propA') //return true

//simple comparison
test(input,'propA > 1') //returns true

//boolean expr
test(input,'propB == "OK" && propA == 2') //return true

function filter(arr,expr)

let input = [
    {
        "name":"obj1",
        "propA":2,
        "propB":"OK",
        "propC":true
    },
    {
        "name":"obj2",
        "propA":34,
        "propB":"KO",
        "propC":false
    }
];


filter(input,'name="obj1" OR name="obj2"') // Returns two results

filter(input,'name="test"')// Returns empty results

Non ES6

For non ES6 env just require module

var smartfilter = require("@smartorigin/smart-filter");

let input = {"a":"ok"};

smartfilter.test(input,'a="ok"'); // returns true

let arr = [{"a":"1"},{"a":"2"}];

smartfilter.filter(a,'a="1"'); // return an array that contains one object.

Contributing

Before pushing any pull request you must ensure the following points :

  • you have new test to your feature / fix and npm run test pass.
  • npm run build is passing
  • npm run prepublish is passing

About

Created by MarcAlx for Smart/Origin

Usefull links

https://github.com/flexdinesh/npm-module-boilerplate

License

MIT License