Skip to content

Commit

Permalink
HC: add object path in expression
Browse files Browse the repository at this point in the history
  • Loading branch information
le-jeu committed Aug 24, 2024
1 parent 579239a commit 79b2a48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/highlight-customize/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ function mathExpr(expr, portal) {
return null;
}

function pathExpr(expr, portal) {
const path = expr[0];
const obj = evaluateExpr(expr[1], portal);

if (typeof(obj) === 'object')
return obj[path];

return null;
}


/** Retrieve the value of the property `prop` of the portal */
function getExpr(expr, portal) {
const prop = expr[1];
Expand Down Expand Up @@ -257,6 +268,8 @@ const operators = {
rgb: rgbExpr,
// array
slice: sliceExpr,
// obj/array
path: pathExpr,
};

export function evaluateExpr(expr, portal) {
Expand Down
2 changes: 1 addition & 1 deletion src/highlight-customize/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"author": "jaiperdu",
"name": "Customized highlighter",
"category": "Highlighter",
"version": "0.2.2",
"version": "0.2.3",
"description": "Configure you own highlighter"
}

0 comments on commit 79b2a48

Please sign in to comment.