UNPKG

keys-converter

Version:

This package provide a util function to convert snake case object keys to camel case

57 lines 1.69 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.objectKeysToCamelCaseV2 = void 0; const get_params_1 = __importDefault(require("./get_params")); const transform_camel_case_key_1 = __importDefault(require("./transform_camel_case_key")); /** * * @param obj `{ key: value }` * @returns obj `{ key: value }` * * * @argument Result type as Object interface to type the return * @argument Input type as Object interface to validate arguments type * @example * objectKeysToCamelCase<Result, Input>({}); * * @example * * interface Result { * goodMorning: string * goodAfternoon: string * } * * interface Input { * good_morning: string, * good_afternoon: string * } * * const result = objectKeysToCamelCase<Result, Input>( * { * good_morning: "Its a beautfull day", * good_afternoon: "Nice afternoon" * } * ); * */ const objectKeysToCamelCaseV2 = function (obj) { const resultsForKey = get_params_1.default(obj); if (resultsForKey.length < 1) { return {}; } let result = {}; const valuesForKeys = Object.values(obj); let index = 0; while (resultsForKey[index]) { const camelCaseKey = transform_camel_case_key_1.default(resultsForKey[index].ranges); result = Object.assign(result, { [camelCaseKey]: valuesForKeys[index] }); index++; } return result; }; exports.objectKeysToCamelCaseV2 = objectKeysToCamelCaseV2; exports.default = objectKeysToCamelCaseV2; //# sourceMappingURL=object_keys_to_camel_case_v2.js.map