Update src/utils/transformations.js

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Spicy Marinara
2026-02-25 23:58:02 +01:00
committed by GitHub
parent 4d0de8419c
commit 66a22c74d0
+10 -5
View File
@@ -1,9 +1,14 @@
const toSnake = str => str const toSnake = (str) => str
.replace(/[^a-zA-Z]/g, '_') // replace any sequence of non-alphanumeric characters with a single underscore
.replace(/([A-Z])/g, '_$1') .replace(/[^0-9A-Za-z]+/g, '_')
.toLowerCase() // insert underscore between a lower-case letter/digit and an upper-case letter (but not between consecutive uppers)
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
// collapse multiple underscores
.replace(/_+/g, '_') .replace(/_+/g, '_')
.replace(/^_|_$/g, ''); // trim leading/trailing underscores
.replace(/^_+|_+$/g, '')
// finally, lowercase the result
.toLowerCase();
export const safeToSnake = (str) => { export const safeToSnake = (str) => {
const res = toSnake(str); const res = toSnake(str);