New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gson-query

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gson-query - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

48

lib/filter.js

@@ -38,2 +38,26 @@ var o = require("gson-conform");

var selectCurly = /(\{[^}]*\})/g;
var selectPlaceholder = /§§§\d+§§§/g;
function splitQuery(value) {
// nothing to escape
if (value.indexOf("?") === -1 || value.indexOf("{") === -1) {
return value.split("?", 2);
}
// @todo this must be simpler to solve
var map = {};
var temp = value.replace(selectCurly, function replace(match, group, index) {
var id = "§§§" + index + "§§§";
map[id] = match;
return id;
});
var result = temp.split("?", 2);
for (var i = 0; i < result.length; i += 1) {
result[i] = result[i].replace(selectPlaceholder, function revertReplacement(match) {
return map[match];
});
}
return result;
}
/**

@@ -48,16 +72,19 @@ * Filter properties by query: select|if:property

if (obj && query) {
var matches = query.split("?", 2);
var matches = splitQuery(query);
var propertyQuery = matches[0];
var filterQuery = matches[1];
var keys;
var regex;
if (matches[0] === "*" || matches[0] === "**") {
if (propertyQuery === "*" || propertyQuery === "**") {
keys = o.keys(obj);
return keys.filter(f.queryKey(obj, matches[1]));
return keys.filter(f.queryKey(obj, filterQuery));
} else if (common.rIsRegExp.test(matches[0])) {
} else if (common.rIsRegExp.test(propertyQuery)) {
keys = o.keys(obj);
regex = common.convertToRegExp(matches[0]);
return keys.filter(f.queryRegExp(obj, matches[1], regex));
regex = common.convertToRegExp(propertyQuery);
return keys.filter(f.queryRegExp(obj, filterQuery, regex));
} else if (obj[matches[0]] && valid(obj[matches[0]], matches[1])) {
return [matches[0]];
} else if (obj[propertyQuery] && valid(obj[propertyQuery], filterQuery)) {
return [propertyQuery];
}

@@ -112,5 +139,3 @@ }

if (value === "undefined") {
// undefined is unmappable
value = undefined;
value = undefined; // undefined is unmappable
} else {

@@ -120,2 +145,3 @@ value = MAP[value] === undefined ? value : MAP[value];

// perform filter test, exception undefined is not matched for negated non-undefined values
value = (truthy ? (value === obj[key]) : (value !== obj[key] && (obj[key] !== undefined || key === undefined)));

@@ -122,0 +148,0 @@

{
"name": "gson-query",
"version": "2.0.0",
"version": "2.1.0",
"description": "json-pointer utilities for querying and transforming data",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -1,2 +0,2 @@

# gson query
<h1 align="left"><img src="./docs/gson-query.png" width="256" alt="gson-query"></h1>

@@ -31,3 +31,3 @@ **Query and transform your json data using an extended glob-pattern within browsers or nodejs**

- with `v2.0.0` a negated filter (lookahead), e.g. `*?valid:!true` will not return objects where `valid === undefined`. To match object with missing properties you can still query them explicitly with `*?valid:!true||valid:undefined`
- with `v2.0.0` a negated filter (lookahead), e.g. `*?valid:!true` will not return objects where `valid === undefined`. To match objects with missing properties you can still query them explicitly with `*?valid:!true||valid:undefined`

@@ -34,0 +34,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc