2024-03-19 14:05:30 +00:00
|
|
|
/**
|
2024-07-12 12:58:34 +02:00
|
|
|
* @param str
|
|
|
|
* @return {string}
|
2024-03-19 14:05:30 +00:00
|
|
|
*/
|
2024-07-12 12:58:34 +02:00
|
|
|
export const toSnakeCase = ( str ) => {
|
|
|
|
return str
|
|
|
|
.replace( /[\w]([A-Z])/g, function ( m ) {
|
|
|
|
return m[ 0 ] + '_' + m[ 1 ];
|
|
|
|
} )
|
|
|
|
.toLowerCase();
|
|
|
|
};
|
2024-03-19 14:05:30 +00:00
|
|
|
|
|
|
|
/**
|
2024-07-12 12:58:34 +02:00
|
|
|
* @param obj
|
|
|
|
* @return {{}}
|
2024-03-19 14:05:30 +00:00
|
|
|
*/
|
2024-07-12 12:58:34 +02:00
|
|
|
export const convertKeysToSnakeCase = ( obj ) => {
|
|
|
|
const newObj = {};
|
|
|
|
Object.keys( obj ).forEach( ( key ) => {
|
|
|
|
const newKey = toSnakeCase( key );
|
|
|
|
newObj[ newKey ] = obj[ key ];
|
|
|
|
} );
|
|
|
|
return newObj;
|
|
|
|
};
|