![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
jql-matcher
Advanced tools
Readme
JSON Query Language - Matcher. Filter a json-array based on a given query.
This library was developed and tested on Node Environment, but you can still use it for the web.
npm i -S jql-matcher
const jql = require('jql-matcher');
const data = [
{ id: 1 },
{ id: 2 },
{ id: 3 }
];
// select * from list where id === 3
const query = { id: 3 };
const result = jql(query, data);
jql-matcher
only accepts two arguments:
query
- The query object that will be used to filter the results.data
- An array
of JSON
data.JQL has standard operations
that it uses to execute this filtering process. Operation names are always prefixed with a $
sign.
const jql = require('jql-matcher');
const data = [
{
id: 1,
email: 'user1@email.com',
password: 'SSBjYW4gc2VlIHRoYXQgeW91IGxpa2Ugd29uZGVyaW5nIGRvd24gdGhlIHJhYmJpdCBob2xlLg=='
watchesAnime: false,
watchesCartoons: false,
watchesRickAndMorty: true
},
{
id: 2,
email: 'user5@email.com',
password: 'QXJlIHlvdSBwbGFubmluZyB0byBkZWNvZGUgYWxsIG9mIHRoZW0/',
watchesAnime: true,
watchesCartoons: true,
watchesRickAndMorty: true
},
{
id: 3,
email: 'user3@email.com',
password: 'UmVhbGx5Pw==',
watchesAnime: false,
watchesCartoons: true,
watchesRickAndMorty: true
},
{
id: 4,
email: 'user2@email.com',
password: 'SlNPTiBRdWVyeSBMYW5ndWFnZQ==',
watchesAnime: true,
watchesCartoons: false,
watchesRickAndMorty: true
}
];
// select * from users
// where
// email === "user1@email.com" or
// email === "user2@email.com" or
// email === "user3@email.com"
const query = {
email: {
$in: ['user1@email.com', 'user2@email.com', 'user3@email.com']
}
};
const result = jql(query, data);
Operators
are abstract, therefore, there could be different approach to achieving the same result and it's also prone to abuse. The example above is what I would call a good query
because it is short and precise. A bad counterpart would be:
const query = {
$or: [
{ email: 'user1@email.com' },
{ email: 'user2@email.com' },
{ email: 'user3@email.com' }
]
};
The query above gives you the same result but it's labeled as bad
because it's unnecessarily long and complex. JQL-Matcher
is designed and intended to be extremely performant (to a point of sacrificing a little dev experience points for the sake of keeping it performant) but it should not be abused. As a general rule of thumb ALWAYS REDUCE YOUR QUERY DOWN TO IT'S SIMPLEST FORM. Prefer the shortest and simplest code.
All queries are treated as and
, unless you explicitly use $or
.
// select * from list
// where
// watchesAnime === true and
// watchesCartoons === true and
// watchesRickAndMorty === true
{
watchesAnime: true
watchesCartoons: true
watchesRickAndMorty: true
}
PS: Rick and Morty is not a cartoon! It's a simulation.
Don't be afraid to go as deep as you need to. Given this sample data:
const sampleData = [
{
id: 1,
posts: {
id: 1,
body: 'Lorem ipsum dolor sit amet,',
comments: [
{
id: 1,
body: 'consectetur adipiscing elit.'
}
]
},
preferences: {
notifications: {
outsideNotifications: {
email: true
}
}
}
}
];
The query below will return all rows where preferences.notifications.outsideNotifications.email === true
.
// select * from list
// where
// preferences.notifications.outsideNotifications.email === true
const query = {
preferences: {
notifications: {
outsideNotifications: {
email: true
}
}
}
};
// ...
You can also filter even when a key contains an array value. The query below will return all rows if
preferences.notifications.outsideNotifications.email === true
// select * from list
// where
// posts.comments has id === 1 and
// preferences.notifications.outsideNotifications.email === true
const query = {
posts: {
comments: {
id: 1
}
},
preferences: {
notifications: {
outsideNotifications: {
email: true
}
}
}
};
// ...
You can do even further query where you query a value inside an array of an array inside another giant array.
You can also nest $or
and $and
operators together whenever it makes sense to do it. Just always keep the rule of thumb in mind, ALWAYS REDUCE YOUR QUERY DOWN TO IT'S SIMPLEST FORM. Prefer the shortest and simplest code.
docs.
FAQs
JSON Query Language - Matcher. Filter a json-array based on a given query.
The npm package jql-matcher receives a total of 4 weekly downloads. As such, jql-matcher popularity was classified as not popular.
We found that jql-matcher demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.