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

intuitive-json-query-language

v1.0.0

Published

A human-readable query language implementation for being able to filter for specific JavaScript/JSON objects in an array.

Downloads

18

Readme

intuitive-json-query-language

A simple, human-readable query language implementation for being able to filter for specific JavaScript/JSON objects in an array.

Motivation

My main motivation was to create a JQL-like query language for JSON objects which I can use to define complex criterias for generating smart music playlist from my music library.

My plan was to enable filtering and testing JSON objects (as music metadata) against queries that are able to check for more than one criteria in metadata object.

Install

npm i intuitive-json-query-language

Usage

const ijql = require('intuitive-json-query-language');

const musicMetadata = [
    {
        ...
    }
]

// to filter elements of an array for a query
const matchingElements = ijql.filter(
    musicMetaData,
    'artist IS Bruno Mars AND comments INCLUDES favorite'
);

// to check an object against a query (if you might save on iterations)
const isMatching = ijql.testElementAgainstQuery(
    musicMetadatap[0],
    'albumArtist IS Phil Collins AND (comments INCLUDES energic OR comments INCLUDES party)'
);

Methods

filter(elements, query)

Filter those elements from the elements array which are matching to the query.

  • elements is an array of Objects
  • query is a string containing a query detailed below

Returns: an array which is subset of the elements array.

testElementAgainstQuery(element, query)

Check complience of the object in element with the query.

  • element object to check against query
  • query is a string containing a query detailed below

Returns: true / false

Query syntax

Syntax

Conditions

<propertyPathOnTestedObject> <operator> <lookupValue>
  • propertyPathOnTestedObject is a string and can describe a deep path on the object
  • operator: see below the list of operators
  • lookUp value is what we need equality/containment etc.

For example:

{
    name: {
        fistName: 'Peter'
    }
}

name.firstName IS Peter

Parens and embedded logical expressions

IJQL supports any levels of logical grouping, like (by shortening conditions into single letter)

a OR (b AND (c OR d) AND e) AND f

OR is always evaluated later than a same-level AND oeprator.

Operators

IMPORTANT: Space is always needed around operators!

  • AND - logical AND - only true if all operands are true
  • OR - logical OR - only false if all operands are false
  • NOT INCLUDES - check if an array or a string NOT contains the look-up value on its right
  • INCLUDES - check if an array or a string NOT contains the look-up value on its right
  • IS - check if the value on the property path strict equals to the look-up value on its right
  • IS NOT - check if the value on the property path not strictly equals to the look-up value on its right
  • < - check if the value on the property path is less than the given look-up value
  • > - check if the value on the property path is greater than the given look-up value