diff options
Diffstat (limited to 'src/js/builtins/codegen/helpers.ts')
-rw-r--r-- | src/js/builtins/codegen/helpers.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/js/builtins/codegen/helpers.ts b/src/js/builtins/codegen/helpers.ts new file mode 100644 index 000000000..6345f8ffa --- /dev/null +++ b/src/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); +} |