Skip to content

Commit 7d64305

Browse files
committed
fix: wildcard for arrays (#5)
1 parent 6490251 commit 7d64305

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

Diff for: README.md

+12
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ It's also posible to query the file directly using the `#qj-query` flag:
7575
```
7676
~~~
7777

78+
If you want to get all the elements of an array you can use the `*` wildcard:
79+
80+
~~~markdown
81+
```qjson
82+
#qj-id: 24
83+
#qj-file: data.json
84+
#qj-show-json
85+
#qj-hide-id
86+
#qj-query: pageProps.heroData[*]
87+
```
88+
~~~
89+
7890
## 🏳️ Flags
7991

8092
Query JSON supports various flags to enhance customization and functionality:

Diff for: manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "query-json",
33
"name": "Query JSON",
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"minAppVersion": "0.15.0",
66
"description": "Read, query and work with JSON.",
77
"author": "rooyca",

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "query-json",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Read, query and work with JSON.",
55
"main": "main.js",
66
"scripts": {

Diff for: src/functions.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function parseCondition(condition) {
4141
}
4242

4343
function parseSingleCondition(condition) {
44-
const comparisonOperators = ['>=', '<=', '==', '>', '<', '!='];
44+
const comparisonOperators = ['>=', '<=', '==', '>', '<', '!=', '*'];
4545
for (let operator of comparisonOperators) {
4646
if (condition.includes(operator)) {
4747
const [key, value] = condition.split(operator).map(s => s.trim());
@@ -108,8 +108,10 @@ function evaluateConditions(item, conditions, operators) {
108108
}
109109

110110
function evaluateCondition(item, condition) {
111+
console.log(item)
111112
const { key, operator, value } = condition;
112113
switch (operator) {
114+
case '*': return true;
113115
case '>=': return item[key] >= Number(value);
114116
case '<=': return item[key] <= Number(value);
115117
case '==': return item[key] == value;

Diff for: src/main.ts

+2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ export default class QJSON extends Plugin {
9393
const json = JSON.parse(source);
9494

9595
if (query) {
96+
console.log(query);
9697
const result = executeQuery(json, query);
98+
console.log(result);
9799

98100
if (format && query[query.length - 1].type === "field") {
99101
if (format === "list") {

0 commit comments

Comments
 (0)