From 915a5a45e7d0fcc5cc41bb2a0058b93b2fe3c61e Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Mon, 13 Jan 2020 22:18:31 -0500 Subject: [PATCH] Adds utility to convert string to snake case --- src/app/_util/snake-case.ts | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/app/_util/snake-case.ts diff --git a/src/app/_util/snake-case.ts b/src/app/_util/snake-case.ts new file mode 100644 index 0000000..0b9cb37 --- /dev/null +++ b/src/app/_util/snake-case.ts @@ -0,0 +1,6 @@ +export const toSnakeCase = (str: string) => { + return !str ? '' : String(str) + .replace(/^\W+|\W+$/gi, '') + .replace(/\W+/gi, '_') + .toLowerCase(); +};