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

selectql.js

v3.1.2

Published

SelectQL.js is inspired by SQL like syntax for accessing and manipulating Objects.

Downloads

20

Readme

SelectQL.js

SelectQL workflow Made with love in Canada npm version

SelectQL.js is inspired by Structured Query Language (SQL) for accessing and manipulating Objects in an easy and familiar way. It supports complex Objects and Arrays using Builder Design Pattern.

Install

npm install selectql.js --save

Usage

You may use Arrays like Objects to select and manipulate in well known SQL like syntax that uses builder patterns.

First include the library by node provided require keyword like: const { SelectQL, Operators } = require('selectql.js');

Client array like object, make sure to follow the syntax of banana in the box [{}] syntactic sugar:

let cities = [
  { name: 'Los Angeles', population: 3792621, winner: 5 },
  { name: 'New York', population: 8175133, winner: 4 },
  { name: 'Chicago', population: 2695598, winner: 8 },
  { name: 'Houston', population: 2099451, winner: 9 },
  { name: 'Philadelphia', population: 1526006, winner: 1 },
];

//Default object to be returned in case empty or null result.
let denver = [{ name: 'Denver', population: 715522, winner: 8 }];

Enum should be followed in order to properly chain the functions.

| Operator| Value | |--|--| | EQUAL| == | | NOT_EQUAL| != | | GREATER_THAN| > | | GREATER_EQUAL| >= | | LESS_THEN| < | | LESS_THEN_EQUAL| <= |

enum Operators {
        EQUAL = '==',
        NOT_EQUAL = '!=',
        GREATER_THAN = '>',
        GREATER_EQUAL = '>=',
        LESS_THEN = '<',
        LESS_THEN_EQUAL = '<=',
}

Initialize the library by providing the objects of array and chain through the provided APIs

let selectQl = new SelectQL(cities)
  .where('name', Operators.NOT_EQUAL, 'New York') // Will filter to make sure 'New York' should filtered
  .and('population', Operators.LESS_THEN, '5526006') // Will filtered the population less than 5526006
  .and('winner', Operators.GREATER_EQUAL, 15) // will only return if winner value more than 15
  .ifEmptyThen(denver) // if everything is empty, client can provide default object like array
  .build();
  
  console.log(selectQl, 'sq'); // Will returned denver array

Working DEMO: https://typescript-a3w8i1.stackblitz.io

Client Chainable APIs:

  • where(key: any, operator: Operators, value: any): As per SQL definition The WHERE clause is used to filter records. It is used to extract only those records that fulfill a specified condition. (this can be used multiple time) .where('name', Operators.NOT_EQUAL, 'New York')
  • and(key: any, operator: Operators, value: any): where like function a predicate which will eventually use WHERE method (this can be used multiple time). .and('population', Operators.LESS_THEN, '5526006')
  • join(concatWith: any): Client can provide object like array to concat with the originally provided array. .join(denver)
  • ifEmptyThen(input: any): if no condition met or null then client can return it's own input/object .ifEmptyThen(denver)
  • build(): builder function which is a must in order to return properly filtered array. .build()

License

License: MIT

Free Library!