File: typescript.ts

package info (click to toggle)
node-deepmerge 4.3.1%2B~1.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 276 kB
  • sloc: javascript: 917; makefile: 4
file content (65 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import * as merge from '../';

const x = {
	foo: 'abc',
	bar: 'def',
	wat: 42,
}

const y = {
	foo: 'cba',
	bar: 'fed',
	wat: 42,
}

const z = {
	baz: '123',
	quux: '456',
	wat: 42,
}

let merged1 = merge(x, y);
let merged2 = merge(x, z);
let merged3 = merge.all<{wat: number}>([ x, y, z ]);

merged1.foo;
merged1.bar;
merged2.foo;
merged2.baz;
merged3.wat;


const options1: merge.Options = {
	clone: true,
	isMergeableObject (obj) {
		return false;
	},
};

const options2: merge.Options = {
	arrayMerge (target, source, options) {
		target.length;
		source.length;
		options.isMergeableObject(target);

		return [];
	},
	clone: true,
	isMergeableObject (obj) {
		return false;
	},
};

const options3: merge.Options = {
    customMerge: (key) => {
        if (key === 'foo') {
          return (target, source) => target + source;
        }
    }
}

merged1 = merge(x, y, options1);
merged2 = merge(x, z, options2);
merged3 = merge.all<{wat: number}>([x, y, z], options1);

const merged4 = merge(x, y, options3);