Skip to content

Commit

Permalink
Merge pull request #6 from ozppupbg/master
Browse files Browse the repository at this point in the history
Improved table data display
  • Loading branch information
Rooyca authored Jan 17, 2025
2 parents d8ecba1 + ba39149 commit 390a6ff
Show file tree
Hide file tree
Showing 2 changed files with 284 additions and 28 deletions.
21 changes: 18 additions & 3 deletions src/functions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function parseQuery(query) {
const parts = query.split('.');
return parts.map(part => {
const match = part.match(/(\w+)\[(.*)\]/);
const parsed = parts.map(part => {
const match = part.match(/(\w*)\[(.*)\]/);
if (match) {
return {
type: 'filter',
Expand All @@ -14,6 +14,17 @@ export function parseQuery(query) {
name: part
};
});
let first = true;
for (const q of parsed) {
if (first) {
first = false;
} else {
if (q.type === "filter" && !q.field) {
throw Error(`Filter without field: ${query}`);
}
}
}
return parsed;
}

function parseCondition(condition) {
Expand Down Expand Up @@ -60,7 +71,11 @@ export function executeQuery(json, parsedQuery) {
result = result[part.name];
} else if (part.type === 'filter') {
const { conditions, operators } = parseCondition(part.condition);
const filteredResult = result[part.field].filter(item => {
let arr = result;
if (part.field) {
arr = result[part.field];
}
const filteredResult = arr.filter(item => {
return evaluateConditions(item, conditions, operators);
});
// Store the filtered result in finalResult
Expand Down
Loading

0 comments on commit 390a6ff

Please sign in to comment.