UNPKG

snakify-ts

Version:

Recursive snake casing of object property names with proper typing

22 lines 702 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const util_1 = require("util"); const lodash_1 = require("lodash"); function walk(obj) { if (!obj || typeof obj !== 'object') return obj; if (util_1.types.isDate(obj) || util_1.types.isRegExp(obj)) return obj; if (Array.isArray(obj)) return obj.map(walk); return Object.keys(obj).reduce((res, key) => { const camel = lodash_1.camelCase(key); res[camel] = walk(obj[key]); return res; }, {}); } function camelize(obj) { return (typeof obj === 'string' ? lodash_1.camelCase(obj) : walk(obj)); } exports.default = camelize; //# sourceMappingURL=index.js.map