Skip to content

Commit

Permalink
generalized stringify
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Jan 4, 2022
1 parent 0d6b5ad commit 900b9a5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/view/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const stringify = (
property: Record<string, any> | string | any[] | number | boolean,
depth: number = 0
): string => {
const ret = [];
if (depth == 5) {
return "";
}
if (typeof property == "string") return property;
if (typeof property == "number") return `${property}`;
if (Array.isArray(property)) {
ret.push(`(${property.map((p) => stringify(p, depth++)).join(" ")})`);
} else if (typeof property == "object") {
for (const value of Object.values(property)) {
ret.push(stringify(value, depth++));
}
}
return ret.join(" ");
};

0 comments on commit 900b9a5

Please sign in to comment.