/* * © Copyright 2022 HP Development Company, L.P. * SPDX-License-Identifier: MIT */ export function mapObject( obj: T, iteratee: (value: T[keyof T], key: keyof T) => TResult ): { [P in keyof T]: TResult } { const keys = Object.keys(obj) as Array; return keys.reduce((acc, key) => { const value = obj[key]; acc[key] = iteratee(value, key); return acc; }, {} as { [P in keyof T]: TResult }); } export function omit(obj: undefined, keys: Array): undefined; export function omit(obj: null, keys: Array): null; export function omit(obj: T, keys: Array): Partial; export function omit(obj: T | null | undefined, keys: Array): Partial | null | undefined { if (typeof obj !== 'object' || typeof obj === 'undefined' || obj === null) return obj; if (!keys.length) return obj; const objKeys = Object.keys(obj) as Array; return objKeys.reduce((acc, key) => { if (keys.indexOf(key) === -1) { acc[key] = obj[key]; } return acc; }, {} as Partial); } /*! * is-plain-object * * Copyright (c) 2014-2017, Jon Schlinkert. * Released under the MIT License. */ function isObject(o: unknown) { return Object.prototype.toString.call(o) === '[object Object]'; } export function isPlainObject(o: unknown) { if (isObject(o) === false) return false; const obj = o as object; // If it has modified constructor const ctor = obj.constructor; if (ctor === undefined) return true; // If it has modified prototype const prot = ctor.prototype; if (isObject(prot) === false) return false; // if constructor does not have an Object-specific method // eslint-disable-next-line no-prototype-builtins if (prot.hasOwnProperty('isPrototypeOf') === false) { return false; } // Most likely a plain Object return true; }