util-ex
Version:
Browser-friendly enhanced util fully compatible with standard node.js
37 lines (36 loc) • 1.33 kB
TypeScript
/**
* A filter function used to determine which properties to copy.
* @callback FilterFn
* @param {any} key
* @param {any} value
* @returns {boolean} returns `true` for properties to be copied.
*/
/**
* Extends an object with properties from one or more source objects.
* @param {Object} dest - The object to be extended.
* @param {Object|Object[]} sources - The source object(s) from which to extend the `dest` object.
* @param {function=} filter - An optional function to filter which properties to extend. It should take two arguments (`key` and `value`) and return `true` if the property should be extended, `false` otherwise.
* @returns {Object} - The extended `dest` object.
* @example
* var dest = { a: 1 };
* var src1 = { b: 2 };
* var src2 = { c: 3 };
* extend(dest, src1, src2);
* // dest => { a: 1, b: 2, c: 3 }
*
* @example
* var dest = { a: 1 };
* var src1 = { b: 2 };
* var src2 = { c: 3 };
* var filter = function(key, value) {
* return key !== 'b.js';
* };
* extend(dest, [src1, src2], filter);
* // dest => { a: 1, c: 3 }
*/
export function extend(dest: any, sources: any | any[], filter?: Function | undefined): any;
export default extend;
/**
* A filter function used to determine which properties to copy.
*/
export type FilterFn = (key: any, value: any) => boolean;