Update src/utils/transformations.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user