From fc40c690ea30a632a8d0d9490321c50ec898d8a5 Mon Sep 17 00:00:00 2001 From: dave caruso Date: Mon, 22 May 2023 18:51:05 -0700 Subject: Write out builtins with TypeScript + Minify them (#2999) * start work drafting how builtins will work * work on ts builtin * builtins stuff so far * builtins * done for today * continue work * working on it * bindings so far * well, it builds. doesnt run * IT RUNS * still lots of ts errors but it is functional * sloppy mode --- src/bun.js/builtins/codegen/helpers.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bun.js/builtins/codegen/helpers.ts (limited to 'src/bun.js/builtins/codegen/helpers.ts') diff --git a/src/bun.js/builtins/codegen/helpers.ts b/src/bun.js/builtins/codegen/helpers.ts new file mode 100644 index 000000000..6345f8ffa --- /dev/null +++ b/src/bun.js/builtins/codegen/helpers.ts @@ -0,0 +1,25 @@ +export function fmtCPPString(str: string) { + return ( + '"' + + str + .replace(/\\/g, "\\\\") + .replace(/"/g, '\\"') + .replace(/\n/g, "\\n") + .replace(/\r/g, "\\r") + .replace(/\t/g, "\\t") + .replace(/\?/g, "\\?") + // https://stackoverflow.com/questions/1234582 + '"' + ); +} + +export function cap(str: string) { + return str[0].toUpperCase() + str.slice(1); +} + +export function low(str: string) { + if (str.startsWith("JS")) { + return "js" + str.slice(2); + } + + return str[0].toLowerCase() + str.slice(1); +} -- cgit v1.2.3