@enonic/js-utils
Version:
Enonic XP JavaScript Utils
29 lines (26 loc) • 632 B
JavaScript
// value/isObject.ts
var isObject = (value) => Object.prototype.toString.call(value).slice(8, -1) === "Object";
// value/toStr.ts
function toStr(value, replacer, space = 4) {
return JSON.stringify(value, replacer, space);
}
// object/mapKeys.ts
function mapKeys(obj, fn) {
if (!isObject(obj)) {
throw new TypeError(`mapKeys: First param must be an object! got:${toStr(obj)}`);
}
const result = {};
const keys = Object.keys(obj);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
fn({
key,
result,
value: obj[key]
});
}
return result;
}
export {
mapKeys as default
};