Skip to content

Commit

Permalink
added asWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
RobMayer committed Aug 8, 2023
1 parent 6561f8a commit 6bc4714
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jsx-in-ttpg",
"license": "UNLICENSE",
"version": "1.1.0",
"version": "1.1.1",
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts --no-splitting",
"clean": "rm -rf ./dist",
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ export const asTextNode = (children: JSXNode): TextNode => {
return undefined;
};

export const asWidget = (children: JSXNode): Widget => {
if (children instanceof Widget) {
return children;
}
const t = new Text();
t.setText(Array.isArray(children) ? children.filter((a) => typeof a === "string").join("") : `${typeof children === "string" || typeof children === "number" ? children : ""}`);
return t;
};

type ArrayOr<T> = T | T[];

export type JSXNode = JSX.Element;
Expand Down

0 comments on commit 6bc4714

Please sign in to comment.