|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
718 bytes
|
| Line | |
|---|
| 1 | import { isArray } from '../compat/predicate/isArray.mjs';
|
|---|
| 2 | import { isPlainObject } from '../compat/predicate/isPlainObject.mjs';
|
|---|
| 3 | import { snakeCase } from '../string/snakeCase.mjs';
|
|---|
| 4 |
|
|---|
| 5 | function 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 |
|
|---|
| 23 | export { toSnakeCaseKeys };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.