UNPKG

@bianic-ui/utils

Version:

Common utilties and types for Bianic UI

82 lines (68 loc) 2.1 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import merge from "lodash.merge"; export function omit(object, keys) { var result = {}; for (var key in object) { if (keys.includes(key)) continue; result[key] = object[key]; } return result; } export function pick(object, keys) { var result = {}; for (var key of keys) { if (key in object) { result[key] = object[key]; } } return result; } export function split(object, keys) { var picked = {}; var omitted = {}; for (var key in object) { if (keys.includes(key)) { picked[key] = object[key]; } else { omitted[key] = object[key]; } } return [picked, omitted]; } /** * Get value from a deeply nested object using a string path * @param obj - the object * @param path - the string path * @param def - the fallback value */ export function get(obj, path, fallback, index) { var _path$split, _path; //@ts-ignore path = (_path$split = (_path = path) == null ? void 0 : _path.split == null ? void 0 : _path.split(".")) != null ? _path$split : [path]; for (index = 0; index < path.length; index++) { obj = obj ? obj[path[index]] : undefined; } return obj === undefined ? fallback : obj; } /** * Get value from deeply nested object, based on path * It returns the path value if not found in object * * @param path - the string path or value * @param scale - the string path or value */ export function getWithDefault(path, scale) { return get(scale, path, path); } export { merge }; export function filterUndefined(object) { var result = _extends({}, object); for (var key in result) { if (result[key] == null) { delete result[key]; } } return result; } export var objectKeys = obj => Object.keys(obj); //# sourceMappingURL=object.js.map