Skip to content

Commit

Permalink
fix: wildcard for arrays (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rooyca committed Jul 22, 2024
1 parent 6490251 commit 7d64305
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ It's also posible to query the file directly using the `#qj-query` flag:
```
~~~

If you want to get all the elements of an array you can use the `*` wildcard:

~~~markdown
```qjson
#qj-id: 24
#qj-file: data.json
#qj-show-json
#qj-hide-id
#qj-query: pageProps.heroData[*]
```
~~~

## 🏳️ Flags

Query JSON supports various flags to enhance customization and functionality:
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "query-json",
"name": "Query JSON",
"version": "0.1.0",
"version": "0.1.1",
"minAppVersion": "0.15.0",
"description": "Read, query and work with JSON.",
"author": "rooyca",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "query-json",
"version": "0.1.0",
"version": "0.1.1",
"description": "Read, query and work with JSON.",
"main": "main.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function parseCondition(condition) {
}

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

function evaluateCondition(item, condition) {
console.log(item)
const { key, operator, value } = condition;
switch (operator) {
case '*': return true;
case '>=': return item[key] >= Number(value);
case '<=': return item[key] <= Number(value);
case '==': return item[key] == value;
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export default class QJSON extends Plugin {
const json = JSON.parse(source);

if (query) {
console.log(query);
const result = executeQuery(json, query);
console.log(result);

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

0 comments on commit 7d64305

Please sign in to comment.