MCPcopy
hub / github.com/hybridgroup/cylon / extend

Function extend

lib/utils/helpers.js:13–45  ·  view source on GitHub ↗
(base, source)

Source from the content-addressed store, hash-verified

11}
12
13function extend(base, source) {
14 var isArray = Array.isArray(source);
15
16 if (base == null) {
17 base = isArray ? [] : {};
18 }
19
20 if (isArray) {
21 source.forEach(function(e, i) {
22 if (typeof base[i] === "undefined") {
23 base[i] = e;
24 } else if (typeof e === "object") {
25 base[i] = extend(base[i], e);
26 } else if (!~base.indexOf(e)) {
27 base.push(e);
28 }
29 });
30 } else {
31 var key;
32
33 for (key in source) {
34 if (typeof source[key] !== "object" || !source[key]) {
35 base[key] = source[key];
36 } else if (base[key]) {
37 extend(base[key], source[key]);
38 } else {
39 base[key] = source[key];
40 }
41 }
42 }
43
44 return base;
45}
46
47extend(H, {
48 identity: identity,

Callers 2

helpers.jsFile · 0.85
helpers.spec.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected