From 6bc47143a554aa2380b7a061f223ce7e09097880 Mon Sep 17 00:00:00 2001 From: Rob Mayer <5171361+RobMayer@users.noreply.github.com> Date: Tue, 8 Aug 2023 12:03:50 -0400 Subject: [PATCH] added asWidget --- package.json | 2 +- src/index.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 0498d5f..6408d80 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index 0966e14..3dd72f7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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[]; export type JSXNode = JSX.Element;