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 1.1.0 to 1.2.0

13

lib/get.js

@@ -8,3 +8,3 @@ "use strict";

/**
* Returns the query results as an array
* Returns the query results as an array or object, depending on its callback
*

@@ -16,2 +16,3 @@ * ## return type

* - get.VALUE = 'value' Default. Returns only the matched value
* - get.MAP = Returns an object with all available pointers and their data, like { pointer: value }
*

@@ -21,3 +22,3 @@ * @param {Mixed} obj

* @param {String} type - type of return value. Defaults to "value"
* @return {Array} containing result in specified format
* @return {Array|Object} containing result in specified format
*/

@@ -38,2 +39,8 @@ function queryGet(obj, jsonPointer, type) {

function getCbFactory(type, matches) {
if (typeof type === "function") {
return function cb(value, key, obj, pointer) {
matches.push(type(obj[key], key, obj, pointer));
};
}
switch (type) {

@@ -46,3 +53,3 @@ case queryGet.ALL:

case queryGet.MAP:
return function cbGetAll(value, key, obj, pointer) {
return function cbGetMap(value, key, obj, pointer) {
matches[pointer] = value;

@@ -49,0 +56,0 @@ };

{
"name": "gson-query",
"version": "1.1.0",
"version": "1.2.0",
"description": "json-pointer utilities for querying data",

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

@@ -15,17 +15,17 @@ # Json Query

```js
const query = require("gson-query");
const data = {
"parent": {
"child": {"id": "child-1"}
}
};
query.run(data, "#/parent/child/id", (value, key, object, jsonPointer) => {
// value = "child-1"
// key = "id"
// object = {"id": "child-1"}
// jsonPointer = "#/parent/child/id"
});
// or get the result in an array
var match = query.get(data, "#/parent/child/id");
// [ ["child-1", "id", {"id":"child-1"}, "#/parent/child/id"] ]
const query = require("gson-query");
const data = {
"parent": {
"child": {"id": "child-1"}
}
};
query.run(data, "#/parent/child/id", (value, key, object, jsonPointer) => {
// value = "child-1"
// key = "id"
// object = {"id": "child-1"}
// jsonPointer = "#/parent/child/id"
});
// or get the result in an array
var match = query.get(data, "#/parent/child/id");
// [ ["child-1", "id", {"id":"child-1"}, "#/parent/child/id"] ]
```

@@ -37,17 +37,17 @@

```js
const query = require("gson-query");
const data = {
"parent": {
"child": {"id": "child-1"}
},
"neighbour": {
"child": {"id": "child-2"}
}
};
query.run(data, "#/*/child/id", function (value, key, object, jsonPointer) {
// will be called with value: "child-1" and "child-2"
});
// or get the result in an array
var match = query.get(data, "#/parent/child/id");
// [ ["child-1", ...], ["child-2", ...] ]
const query = require("gson-query");
const data = {
"parent": {
"child": {"id": "child-1"}
},
"neighbour": {
"child": {"id": "child-2"}
}
};
query.run(data, "#/*/child/id", function (value, key, object, jsonPointer) {
// will be called with value: "child-1" and "child-2"
});
// or get the result in an array
var match = query.get(data, "#/parent/child/id");
// [ ["child-1", ...], ["child-2", ...] ]
```

@@ -58,14 +58,14 @@

```js
var query = require("gson-query");
var data = {
"parent": {
"child": {"id": "child-1"}
},
"neighbour": {
"child": {"id": "child-2"}
}
};
query.run(data, "#/**/id", function (value, key, object, jsonPointer) {
// will be called with value: "parent" "child-1" and "child-2"
});
var query = require("gson-query");
var data = {
"parent": {
"child": {"id": "child-1"}
},
"neighbour": {
"child": {"id": "child-2"}
}
};
query.run(data, "#/**/id", function (value, key, object, jsonPointer) {
// will be called with value: "parent" "child-1" and "child-2"
});
```

@@ -79,21 +79,21 @@

```js
var query = require("gson-query");
var data = {
"parent": {
"valid": true,
"child": {"id": "child-1"}
},
"neighbour": {
"valid": false,
"child": {"id": "child-2"}
},
"dungeons": {
"child": {"id": "child-3"}
}
};
query.run(data, "#/**?valid:true&&ignore:undefined/child", function (value, key, object, jsonPointer) {
// will be called with value: {"id": "child-1"} only
});
// same result with
query.run(data, "#/**?valid:!false/child", function (value, key, object, jsonPointer) { // ...
var query = require("gson-query");
var data = {
"parent": {
"valid": true,
"child": {"id": "child-1"}
},
"neighbour": {
"valid": false,
"child": {"id": "child-2"}
},
"dungeons": {
"child": {"id": "child-3"}
}
};
query.run(data, "#/**?valid:true&&ignore:undefined/child", function (value, key, object, jsonPointer) {
// will be called with value: {"id": "child-1"} only
});
// same result with
query.run(data, "#/**?valid:!false/child", function (value, key, object, jsonPointer) { // ...
```

@@ -108,11 +108,11 @@

```js
var query = require("gson-query");
var data = {
"albert": {valid: true},
"alfred": {valid: false},
"alfons": {valid: true}
};
query.run(data, "#/{al[^b]}?valid:true", function (value, key, object, jsonPointer) {
// will be executed with value: alfons
});
var query = require("gson-query");
var data = {
"albert": {valid: true},
"alfred": {valid: false},
"alfons": {valid: true}
};
query.run(data, "#/{al[^b]}?valid:true", function (value, key, object, jsonPointer) {
// will be executed with value: alfons
});
```

@@ -126,12 +126,12 @@

```js
var queryGet = require("gson-query").get;
var queryGet = require("gson-query").get;
// default: queryGet.VALUES
var arrayOfValues = queryGet(data, "#/**/id", queryGet.VALUE);
// ["#/..", "#/..", ...]
var arrayOfJsonPointers = queryGet(data, "#/**/id", queryGet.POINTER);
// [arguments, arguments], where arguments = 0:value 1:object 2:key 3:jsonPointer
var arrayOfAllFourArguments = queryGet(data, "#/**/id", queryGet.ALL);
// {"#/..": value, "#/..": value}
var mapOfPointersAndData = queryGet(data, "#/**/id", queryGet.MAP);
// default: queryGet.VALUES
var arrayOfValues = queryGet(data, "#/**/id", queryGet.VALUE);
// ["#/..", "#/..", ...]
var arrayOfJsonPointers = queryGet(data, "#/**/id", queryGet.POINTER);
// [arguments, arguments], where arguments = 0:value 1:object 2:key 3:jsonPointer
var arrayOfAllFourArguments = queryGet(data, "#/**/id", queryGet.ALL);
// {"#/..": value, "#/..": value}
var mapOfPointersAndData = queryGet(data, "#/**/id", queryGet.MAP);
```

@@ -145,5 +145,5 @@

```js
var queryDelete = require("gson-query").delete;
var queryDelete = require("gson-query").delete;
queryDelete(data, "#/**/*/data");
queryDelete(data, "#/**/*/data");
```

@@ -150,0 +150,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