1 1
export function parsePath(path: string): string[] {
2 1
	return path
3
		.replace(/\[([^[\]]*)\]/g, '.$1.')
4
		.split('.')
5 1
		.filter(t => t !== '')
6
}
7 1
export function get(obj: object, path: string): any {
8 1
	return parsePath(path).reduce((prev, cur) => prev && prev[cur], obj)
9
}
10 1
export function set(obj: object, path: string, value: any): void {
11 1
	const paths = parsePath(path)
12 1
	let cur = obj
13 1
	for (let i = 0; i < paths.length - 1; i++) {
14 1
		const pname = paths[i]
15 1
		if (!cur.hasOwnProperty(pname)) cur[pname] = {}
16 1
		cur = cur[pname]
17
	}
18 1
	cur[paths[paths.length - 1]] = value
19
}
20 1
export function copy(dest: object, source: object, path: string): void {
21 1
	set(dest, path, get(source, path))
22
}

Read our documentation on viewing source code .

Loading