aboutsummaryrefslogtreecommitdiff
path: root/util/wrap.ts
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-07-03 14:10:06 +0200
committerlonkaars <loek@pipeframe.xyz>2023-07-03 14:10:06 +0200
commitdab9bee4b46aaa1241cdb6b565ddbe0f19137c5e (patch)
tree7a5b22717797a08c8165bc2346f1204d90f74f31 /util/wrap.ts
parent14c31de2f166d9e6d874984cdee5a2876c1ddec5 (diff)
add utility wrap method
Diffstat (limited to 'util/wrap.ts')
-rw-r--r--util/wrap.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/util/wrap.ts b/util/wrap.ts
new file mode 100644
index 0000000..761a1f0
--- /dev/null
+++ b/util/wrap.ts
@@ -0,0 +1,41 @@
+export type Wrapper = [string, string];
+
+/** @summary make Wrapper that starts and ends with `input` */
+export function WrapWith(input: string): Wrapper {
+ return [input, input];
+}
+
+/** @summary make Wrapper that starts and ends with XML tags with name `tagName` */
+export function WrapTag(tagName: string): Wrapper {
+ return [`<${tagName}>`, `</${tagName}>`];
+}
+
+// this type is internal to this file
+type WrapType = { [K: string]: Wrapper | WrapType };
+
+export const Wrap = {
+ /** @prop (input) */
+ parenthesis: ["(", ")"],
+ /** @prop [input] */
+ bracket: ["[", "]"],
+ /** @prop \{input\} */
+ brace: ["{", "}"],
+ /** @prop HTML-specifics */
+ HTML: {
+ /** @prop \<b>input\</b> */
+ bold: WrapTag("b"),
+ /** @prop \<i>input\</i> */
+ italic: WrapTag("i"),
+ /** @prop \<span>input\</span> */
+ span: WrapTag("span"),
+ /** @prop \<ruby>input\</ruby> */
+ ruby: WrapTag("ruby"),
+ /** @prop \<rt>input\</rt> */
+ rubyText: WrapTag("rt"),
+ },
+ /** @prop \*input\* */
+ asterisk: WrapWith("*"),
+ /** @prop \_input\_ */
+ underscore: WrapWith("_"),
+} satisfies WrapType;
+