-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhomefront.d.ts
191 lines (170 loc) · 3.85 KB
/
homefront.d.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/**
* Expands flat object to nested object.
*
* @param {{}} source
*
* @return {{}}
*/
export declare function expand(source?:{}):{};
/**
* Flattens nested object (dot separated keys).
*
* @param {{}} source
* @param {String} [basePath]
* @param {{}} [target]
*
* @return {{}}
*/
export declare function flatten(source?:{}, basePath?:string, target?:{}):{};
/**
* Object wrapping class.
*/
export declare class Homefront {
/**
* @return {string}
*/
static MODE_NESTED:string;
/**
* @return {string}
*/
static MODE_FLAT:string;
/**
* Constructs a new instance of Homefront.
*
* @param {{}} [data] Defaults to empty object.
* @param {String} [mode] Defaults to nested
*/
constructor(data?:{}, mode?:string);
/**
* Recursively merges given sources into data.
*
* @param {{}[]} sources One or more, or array of, objects to merge into data (left to right).
*
* @return {Homefront}
*/
merge(...sources:Array<{}|Homefront>):Homefront;
/**
* Static version of merge, allowing you to merge objects together.
*
* @param {...Object} sources One or more, or array of, objects to merge into data (left to right).
*
* @return {{}}
*/
static merge(...sources:Array<{}|Homefront>):{};
/**
* Sets the mode.
*
* @param {String} [mode] Defaults to nested.
*
* @returns {Homefront} Fluent interface
*
* @throws {Error}
*/
setMode(mode?:string):Homefront;
/**
* Gets the mode.
*
* @return {String}
*/
getMode():string;
/**
* Get data object.
*
* @return {Object}
*/
getData(): {};
/**
* Expands flat object to nested object.
*
* @return {{}}
*/
expand(source?:{}):{};
/**
* Flattens nested object (dot separated keys).
*
* @return {{}}
*/
flatten(source?:{}, basePath?:string, target?:{}):{};
/**
* Returns whether or not mode is flat.
*
* @return {boolean}
*/
isModeFlat():boolean;
/**
* Returns whether or not mode is nested.
*
* @return {boolean}
*/
isModeNested():boolean;
/**
* Convenience method. Calls .fetch(), and on null result calls .put() using provided toPut.
*
* @param {String|Array} key
* @param {*} toPut
*
* @return {*}
*/
fetchOrPut(key:string, toPut:any):any;
/**
* Method allowing you to set missing keys (backwards-applied defaults) nested.
*
* @param {String|Array} key
* @param {*} defaults
*
* @returns {Homefront}
*/
applyDefaults(key?:string, defaults?:any):any;
/**
* Fetches value of given key.
*
* @param {String|Array} key
* @param {*} [defaultValue] Value to return if key was not found
*
* @returns {*}
*/
fetch(key?:string, defaultValue?:any):any;
/**
* Sets value for a key.
*
* @param {String|Array} key Array of key parts, or dot separated key.
* @param {*} value
*
* @returns {Homefront}
*/
put(key?:string | Array<string>, value?:any):Homefront;
/**
* Removes value by key.
*
* @param {String} key
*
* @returns {Homefront}
*/
remove(key?:string):Homefront;
/**
* Search and return keys and values that match given string.
*
* @param {String|Number} phrase
*
* @returns {Array}
*/
search(phrase?:string | number):Array<any>;
}
export declare class Utils {
/**
* Used to normalize keys of mixed array and dot-separated string to a single array of undotted strings.
*
* @param {string|Array} rest (dot-separated) string(s) or array of keys
*
* @return {Array} The key normalized to an array of simple strings
*/
static normalizeKey(...rest:Array<string|Array<any>>):Array<string>;
/**
* Check if `target` is a Plain ol' Javascript Object.
*
* @param {*} target
*
* @return {boolean}
*/
static isPojo(target:any):boolean;
}