json-query
Advanced tools
Comparing version 2.1.1 to 2.2.0
12
index.js
@@ -74,4 +74,11 @@ var State = require('./lib/state') | ||
var keys = Object.keys(state.currentItem) | ||
var values = keys.map(function (key) { | ||
return state.currentItem[key] | ||
var values = [] | ||
keys.forEach(function (key) { | ||
if (token.deep && Array.isArray(state.currentItem[key])) { | ||
state.currentItem[key].forEach(function (item) { | ||
values.push(item) | ||
}) | ||
} else { | ||
values.push(state.currentItem[key]) | ||
} | ||
}) | ||
@@ -219,2 +226,3 @@ state.setCurrent(keys, values) | ||
} else { | ||
console.log(opts.key, item) | ||
r = !!~item[opts.key].indexOf(opts.value) | ||
@@ -221,0 +229,0 @@ } |
@@ -149,2 +149,7 @@ // todo: syntax checking | ||
} | ||
} else if (selectQuery === '**') { | ||
return { | ||
values: true, | ||
deep: true | ||
} | ||
} | ||
@@ -151,0 +156,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "Retrieves values from JSON objects for data binding. Offers params, nested queries, deep queries, custom reduce/filter functions and simple boolean logic. Browserify compatible.", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"homepage": "http://github.com/mmckegg/json-query", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -18,5 +18,5 @@ json-query | ||
### jsonQuery(query, options) | ||
### `jsonQuery(query, options)` | ||
Specify a query and what to query - returns an object that describes the result of the query. | ||
Specify a query and what to query. Returns an object that describes the result of the query. | ||
@@ -38,11 +38,11 @@ ```js | ||
#### options: | ||
#### Options: | ||
- **data** or **rootContext**: The main JS object to query. | ||
- **source** or **context** (optional): The current object we're interested in. Is accessed in query by starting with `.` | ||
- **parent** (optional): An additional context for looking further up the tree. Is accessed by `..` | ||
- **locals**: Specify an object containing helper functions. Accessed by ':filterName'. Expects function(input, args...) with `this` set to original passed in options. | ||
- **globals**: Falls back to globals when no local function found. | ||
- **force** (optional): Specify an object to be returned from the query if the query fails - it will be saved into the place the query expected the object to be. | ||
- **allowRegexp** (optional): enable `~` operator. Before enabling regexp match to anyone, consider the [user defined regular expression security concerns](http://stackoverflow.com/questions/20928677/user-defined-regular-expression-security-concerns). | ||
- **`data`** or **`rootContext`**: The main object to query. | ||
- **`source`** or **`context`** (optional): The current object we're interested in. Accessed in query with `.`. | ||
- **`parent`** (optional): An additional context for looking further up the tree. Accessed by `..`. | ||
- **`locals`**: Specify an object containing helper functions. Accessed by `':filterName'`. Expects `function(input, args...)` with `this` set to original passed in options. | ||
- **`globals`**: Falls back to globals when no local function found. | ||
- **`force`** (optional): Specify an object to be returned from the query if the query fails. It will be saved into the place the query expected the object to be. | ||
- **`allowRegexp`** (optional): Enable the `~` operator. Before enabling regexp match to anyone, consider the [user defined regular expression security concerns](http://stackoverflow.com/questions/20928677/user-defined-regular-expression-security-concerns). | ||
@@ -101,3 +101,3 @@ ## Queries | ||
Search through multiple levels of Objects/Arrays | ||
Search through multiple levels of Objects/Arrays using `[**]`: | ||
@@ -117,4 +117,5 @@ ```js | ||
jsonQuery('grouped_people[][country=NZ]', {data: data}) | ||
jsonQuery('grouped_people[**][*country=NZ]', {data: data}) | ||
``` | ||
### Inner queries | ||
@@ -141,3 +142,3 @@ | ||
Allows to to hack the query system to do just about anything. | ||
Allows you to hack the query system to do just about anything. | ||
@@ -231,3 +232,3 @@ Some nicely contrived examples: | ||
Specifying context ('data', 'source', and 'parent' options) is good for databinding and working on a specific object and still keeping the big picture available. | ||
Specifying context (`data`, `source`, and `parent` options) is good for databinding and working on a specific object and still keeping the big picture available. | ||
@@ -256,3 +257,3 @@ ```js | ||
Params can be specified by passing in an array with the first param the query (with ? params) and subsequent params. | ||
Params can be specified by passing in an array with the first param the query (with `?` params) and subsequent params. | ||
@@ -259,0 +260,0 @@ ```js |
@@ -115,2 +115,8 @@ require('es5-shim') | ||
check("lookup[**]",[ | ||
{root: true}, | ||
{get: 'lookup'}, | ||
{values: true, deep: true} | ||
]) | ||
check("item.title|item.name",[ | ||
@@ -117,0 +123,0 @@ {root: true}, |
@@ -143,2 +143,12 @@ require('es5-shim') | ||
test("Deep query to list all sub arrays of lookup", function(t){ | ||
var result = jsonQuery('grouped_stuff[**]', { | ||
rootContext: rootContext, filters: filters | ||
}) | ||
t.deepEqual(result.value, rootContext.grouped_stuff.group_a.concat(rootContext.grouped_stuff.group_b), "Correct Value") | ||
t.end() | ||
}) | ||
test("Deep query with iterating key query and specified param", function(t){ | ||
@@ -145,0 +155,0 @@ var result = jsonQuery(['grouped_stuff[][id=?].name', 347], { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50063
17
1425
260