react-lsm
Version:
A lightweight react hook for managing localization languages. LSM stands for Localization Storage Manager.
27 lines (26 loc) • 1.13 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.flattenObject = void 0;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var flattenObject = exports.flattenObject = function flattenObject(_ref) {
var obj = _ref.obj,
_ref$parentKey = _ref.parentKey,
parentKey = _ref$parentKey === void 0 ? "" : _ref$parentKey,
_ref$result = _ref.result,
result = _ref$result === void 0 ? {} : _ref$result;
for (var key in obj) {
var newKey = parentKey ? "".concat(parentKey, "_").concat(key) : key;
if (_typeof(obj[key]) === "object" && obj[key] !== null) {
flattenObject({
obj: obj[key],
parentKey: newKey,
result: result
});
} else {
result[newKey] = "".concat(parentKey ? parentKey + "." : "").concat(key).replace(/_/g, ".");
}
}
return result;
};
;