UNPKG

2.13 kBTypeScriptView Raw
1// Type definitions for clone 2.1
2// Project: https://github.com/pvorb/node-clone
3// Definitions by: Kieran Simpson <https://github.com/kierans>
4// DG-za <https://github.com/DG-za>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6
7/**
8 * See clone JS source for API docs
9 */
10
11/**
12 * @param val the value that you want to clone, any type allowed
13 * @param circular Call clone with circular set to false if you are certain that obj contains no circular references. This will give better performance if needed. There is no error if undefined or null is passed as obj.
14 * @param depth to which the object is to be cloned (optional, defaults to infinity)
15 * @param prototype Sets the prototype to be used when cloning an Object (optional, defaults to __proto__)
16 * @param includeNonEnumerable Set to true if the non-enumerable properties should be cloned as well (optional, defaults to false)
17 */
18declare function clone<T>(val: T, circular?: boolean, depth?: number, prototype?: any, includeNonEnumerable?: boolean): T;
19
20/**
21 * @param val the value that you want to clone, any type allowed
22 * @param opts a single object that specifies circular, depth, prototype and includeNonEnumerable.
23 * @param opts.circular Call clone with circular set to false if you are certain that obj contains no circular references. This will give better performance if needed. There is no error if undefined or null is passed as obj.
24 * @param opts.depth Sets depth to which the object is to be cloned (optional, defaults to infinity)
25 * @param opts.prototype Sets the prototype to be used when cloning an Object (optional, defaults to __proto__)
26 * @param opts.includeNonEnumerable Set to true if the non-enumerable properties should be cloned as well (optional, defaults to false)
27 */
28declare function clone<T>(val: T, opts: CloneOpts): T;
29
30interface CloneOpts {
31 circular?: boolean,
32 depth?: number,
33 prototype?: any,
34 includeNonEnumerable?: boolean
35}
36
37declare namespace clone {
38 /**
39 * @param obj the object that you want to clone
40 */
41 function clonePrototype<T>(obj: T): T;
42}
43
44export = clone