source: node_modules/es-toolkit/dist/object/toSnakeCaseKeys.mjs@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 718 bytes
Line 
1import { isArray } from '../compat/predicate/isArray.mjs';
2import { isPlainObject } from '../compat/predicate/isPlainObject.mjs';
3import { snakeCase } from '../string/snakeCase.mjs';
4
5function toSnakeCaseKeys(obj) {
6 if (isArray(obj)) {
7 return obj.map(item => toSnakeCaseKeys(item));
8 }
9 if (isPlainObject(obj)) {
10 const result = {};
11 const keys = Object.keys(obj);
12 for (let i = 0; i < keys.length; i++) {
13 const key = keys[i];
14 const snakeKey = snakeCase(key);
15 const convertedValue = toSnakeCaseKeys(obj[key]);
16 result[snakeKey] = convertedValue;
17 }
18 return result;
19 }
20 return obj;
21}
22
23export { toSnakeCaseKeys };
Note: See TracBrowser for help on using the repository browser.