UNPKG

@xapp/dynamo-service

Version:

A dynamo help class which will help maintain data integrity.

26 lines (25 loc) 733 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.expandObj = void 0; function expandObj(obj) { if (typeof obj !== "object" || obj == null) { return obj; } if (Array.isArray(obj)) { for (let i = 0; i < obj.length; ++i) { obj[i] = expandObj(obj[i]); } return obj; } const newObj = {}; const keys = Object.keys(obj); for (const key of keys) { const value = expandObj(obj[key]); const splitKeys = key.split("."); newObj[splitKeys[0]] = splitKeys.length === 1 ? value : expandObj({ [splitKeys.slice(1).join(".")]: value }); } return newObj; } exports.expandObj = expandObj;