Skip to content

Commit

Permalink
feat(element): attributes can accept JSON stringified strings
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed Jun 23, 2023
1 parent a6f8a0f commit 5b93954
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/element/get-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ const formatValue = (val) => {
if (val === 'false') return false;
if (val === 'null') return null;
if (val === 'undefined') return undefined;
if (typeof val === 'string' && val.includes('{') && val.includes('}') && val.includes('"')) {
let v;
try {
v = JSON.parse(val);
} catch (err) {
v = val;
}
return v;
}
return val;
};

Expand Down

0 comments on commit 5b93954

Please sign in to comment.