Closed EvaLok closed 6 years ago
@MaikelH thinking about this again, a namespace is better than a class with static methods i think, similar to how there is isNullOrUndefined
and so exported as functions in node's util
let me know if this looks OK to you
@MaikelH also, this by default has the second object not override preexisting properties of the first object; this seems unconventional (i would expect the second object's properties to override those of the first). maybe we could add an optional override or noOverride parameter to the extend function in order to address this
I like the idea of an namespace, makes a lot of sense. We can then use it the same way as isNullOrUndefined
like you say.
Adding an extra property is good I think, by default we can set it to false.
so.. i actually started doing this (tried out yarn and it's great btw, so it wasn't at total waste of time), and got to thinking.. "maybe i'll have one last look around for something pre-existing and decent".. and as it turns out.. there is a good solution, that has @types
with generics.. so.. think we're good :)
not only that, it's deep as opposed to shallow
https://www.npmjs.com/package/deep-extend
// Type definitions for open 0.4.1
// Project: https://github.com/unclechu/node-deep-extend
// Definitions by: rhysd <https://github.com/rhysd>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/*
* Recursive object extending.
*/
declare function deepExtend<T, U>(target: T, source: U): T & U;
declare function deepExtend<T, U, V>(target: T, source1: U, source2: V): T & U & V;
declare function deepExtend<T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
declare function deepExtend(target: any, ...sources: any[]): any;
declare namespace deepExtend {}
export = deepExtend;
Nice, it had 9+ million downloads last month so it is probably decent 😏
also apparently yarn's lockfile is more reliable than npm's.. nice how everything sort of came together hehehe
starting simple..