@hkdigital/lib-sveltekit 0.0.42 → 0.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,326 @@
1
+ /**
2
+ * Returns true
3
+ * - if the object has no (iterable) key value pairs
4
+ * - if the object is an empty array
5
+ *
6
+ * @param {object} obj
7
+ *
8
+ * @return {boolean}
9
+ * true if the object has no key value pairs or the supplied object
10
+ * is `falsey`
11
+ */
12
+ export function isEmpty(obj: object): boolean;
13
+ /**
14
+ * Get the number of (iterable) key value pairs in the specified object
15
+ *
16
+ * @param {object} obj
17
+ *
18
+ * @return {number} number of iterable key value pairs
19
+ */
20
+ export function objectSize(obj: object): number;
21
+ /**
22
+ * Returns a shallow copy of the object without the properties that
23
+ * have the value [null] or [undefined]
24
+ *
25
+ * @param {object} obj
26
+ *
27
+ * @param {string[]} [onlyKeys]
28
+ * If specified, only the specified keys will be exported
29
+ *
30
+ * @returns {object} new object without the null properties
31
+ */
32
+ export function exportNotNull(obj: object, onlyKeys?: string[]): object;
33
+ /**
34
+ * Returns a shallow copy of the object without the properties that
35
+ * are `private`
36
+ * - Private properties are properties that start with an underscore
37
+ * `_`.
38
+ *
39
+ * @param {object} obj
40
+ *
41
+ * @param {string[]} [keepKeys]
42
+ * If specified, the sprecified private keys will be exported (e.g. `_id`)
43
+ *
44
+ * @returns {object} new object without the null properties
45
+ */
46
+ export function exportNotPrivate(obj: object, keepKeys?: string[]): object;
47
+ /**
48
+ * Keep only the specified keys in the object
49
+ * - deletes all other key-value pairs in the object
50
+ *
51
+ * @param {object} obj
52
+ * @param {string[]|Set} keys
53
+ * @param {boolean} [removeNullAndUndefined=true]
54
+ *
55
+ * @returns {object} object that only contains the specified keys
56
+ */
57
+ export function keep(obj: object, keys: string[] | Set<any>, removeNullAndUndefined?: boolean): object;
58
+ /**
59
+ * Freezes an object recursively
60
+ * - Allows non-objects to be passed as input parameter (non-objects are
61
+ * immutable by default).
62
+ *
63
+ * @param {mixed} value
64
+ *
65
+ * @returns {mixed}
66
+ * recursively frozen object or original input value if a non-object was
67
+ * supplied as input parameter
68
+ */
69
+ export function deepFreeze(value: mixed, _found: any): mixed;
70
+ /**
71
+ * Set a value in an object using a path and value pair.
72
+ * - Automatically creates parent objects
73
+ *
74
+ * @param {object} obj - Object to set the value in
75
+ * @param {string|Array} path - Dot separated string path or array path
76
+ * @param {mixed} value - value to set
77
+ *
78
+ * @returns {boolean} true if the value was changed
79
+ */
80
+ export function objectSet(obj: object, path: string | any[], value: mixed, ...args: any[]): boolean;
81
+ /**
82
+ * Removes a value at the specified object path from the object.
83
+ * - All parent objects that remain empty will be removed too (recursively)
84
+ *
85
+ * @param {object} obj - Object to set the value in
86
+ * @param {string|Array} path - Dot separated string path or array path
87
+ * @param {mixed} value - value to set
88
+ */
89
+ export function deletePath(obj: object, path: string | any[]): void;
90
+ /**
91
+ * Get a value from an object using a path
92
+ * - Returns a default value if not found, with is [undefined] by default
93
+ *
94
+ * @param {object} obj - Object to get the value from
95
+ * @param {string|Array} path - Dot separated string path or array path
96
+ *
97
+ * @param {mixed} [defaultValue=undefined]
98
+ * Value to return if the value does not exist
99
+ *
100
+ * @return {*} value found at path, defaultValue or undefined
101
+ */
102
+ export function objectGet(obj: object, path: string | any[], defaultValue?: mixed): any;
103
+ /**
104
+ * Get a value from an object using a path
105
+ * - Throws an exception if the path does not exist or the value is undefined
106
+ *
107
+ * @param {object} obj - Object to get the value from
108
+ * @param {string|Array} path - Dot separated string path or array path
109
+ *
110
+ * @param {function} [parseFn]
111
+ * Optional parser function that checks and converts the value
112
+ *
113
+ * @throws No value found at path
114
+ * @throws Invalid value
115
+ *
116
+ * @return {*} value found at path
117
+ */
118
+ export function objectGetWithThrow(obj: object, path: string | any[], parseFn?: Function): any;
119
+ /**
120
+ * Get an iterator that returns the value of a path for each item (object)
121
+ * in the list of objects
122
+ *
123
+ * @param {object[]} arr - Array of objects
124
+ * @param {string|string[]} path - Dot separated string path or array path
125
+ *
126
+ * @param {object} [options] - options
127
+ *
128
+ * DEPRECEATED >>> NOT COMPATIBLE WITH LIGHTWEIGHT ITERATOR
129
+ * @param {object} [options.unique=false] - Only return unique values
130
+ *
131
+ * @param {mixed} [options.defaultValue]
132
+ * Value to return if the value does not exist
133
+ *
134
+ * @returns {Iterator<mixed>} value at the specified path for each item
135
+ */
136
+ /**
137
+ * Returns a list of differences between the object before and the object
138
+ * after the changes.
139
+ * - By default, the function returns changes for added, updated and removed
140
+ * properties
141
+ *
142
+ * @param {object} objBefore
143
+ * @param {object} objAfter
144
+ *
145
+ * @param {object} options
146
+ * @param {boolean} [options.ignoreAdd=false]
147
+ * @param {boolean} [options.ignoreUpdate=false]
148
+ * @param {boolean} [options.ignoreDelete=false]
149
+ *
150
+ * @param {boolean} [options.ignorePrivate=true]
151
+ * Ignore properties that start with an underscore e.g. _id or _updatedAt
152
+ *
153
+ * @param {boolean} [options.deleteValue=null]
154
+ *
155
+ * @returns {array}
156
+ * List of changes between the object before and object after
157
+ */
158
+ export function objectDiff(objBefore: object, objAfter: object, options: {
159
+ ignoreAdd?: boolean;
160
+ ignoreUpdate?: boolean;
161
+ ignoreDelete?: boolean;
162
+ ignorePrivate?: boolean;
163
+ deleteValue?: boolean;
164
+ }, _recursion: any): any[];
165
+ /**
166
+ * Applies a list of differences to the input object
167
+ * - A list of changes can be generated by e.g. objectDiff
168
+ *
169
+ * @param {object} obj
170
+ * @param {object[]} changes
171
+ *
172
+ * @param {object} options
173
+ * @param {boolean} [options.ignoreAdd=false]
174
+ * @param {boolean} [options.ignoreUpdate=false]
175
+ * @param {boolean} [options.ignoreDelete=false]
176
+ *
177
+ * @param {boolean} [options.ignorePrivate=true]
178
+ * Ignore properties that start with an underscore e.g. _id or _updatedAt
179
+ */
180
+ export function patchObject(obj: object, changes: object[], options?: {
181
+ ignoreAdd?: boolean;
182
+ ignoreUpdate?: boolean;
183
+ ignoreDelete?: boolean;
184
+ ignorePrivate?: boolean;
185
+ }): void;
186
+ /**
187
+ * Extend the target object with methods and properties from the source
188
+ * property object
189
+ * - The target object will be extended by inserting the source property
190
+ * object into it's property chain
191
+
192
+ * - If the current target's prototype is not the same as the source
193
+ * prototype, the source prototype will be cloned
194
+ *
195
+ * @param {object} target - Target object
196
+ * @param {object} source
197
+ * object to append to the target's prototype chain. The object and it's
198
+ * prototype objects are cloned first
199
+ */
200
+ export function extend(target: object, source: object): void;
201
+ /**
202
+ * Get a list of property names of the specified object
203
+ *
204
+ * @param {object} obj
205
+ *
206
+ * @returns {string[]} List of property names
207
+ */
208
+ export function getPrototypeNames(obj: object): string[];
209
+ /**
210
+ * Get a tree of values from an object
211
+ * - Can returns default values if one or multiple values were not found
212
+ *
213
+ * @param {object} obj - Object to get the value from
214
+ * @param {object} tree
215
+ * Tree that contains the object paths to get.
216
+ *
217
+ * e.g. { path: 1 }
218
+ * { some: { path: { to: 1 }, otherPath: { to: 1 } } }
219
+ * { "some.path.to": 1, "some.otherPath.to": 1 }
220
+ * { someArray.0.name: 1 }
221
+ *
222
+ * @param {object} [options]
223
+ * @param {object} [options.shallowLeaves=false]
224
+ * If set to true, the values of the leaves of the tree will be converted
225
+ * to shallow objects if the leaves are nested objects.
226
+ *
227
+ * @return {object}
228
+ * nested object with the values that were found or defaultValues
229
+ */
230
+ export function getTree(obj: object, tree: object, options?: {
231
+ shallowLeaves?: object;
232
+ }): object;
233
+ /**
234
+ * Deep clone an object or any kind of other variable
235
+ * - Recursively clone all nested properties
236
+ * - Properties in the prototype chain are cloned too, but all copied into a
237
+ * single prototype object
238
+ * - This method works on objects, but also on any other JS variable type
239
+ * - If a value cannot be cloned, a reference is returned. o.a. for
240
+ * - Error objects
241
+ * - Browser objects
242
+ * - Functions
243
+ *
244
+ * @param {mixed} objectToBeCloned - Variable to clone
245
+ *
246
+ * @returns {mixed} cloned output
247
+ */
248
+ export function clone(objectToBeCloned: mixed, _seenObjects: any): mixed;
249
+ /**
250
+ * Set a read only property in an object
251
+ *
252
+ * @param {object} obj - Object to set the read only property in
253
+ * @param {string} propertyName - Name of the property to set
254
+ * @param {mixed} value - Value to set
255
+ */
256
+ export function setReadOnlyProperty(obj: object, propertyName: string, value: mixed): void;
257
+ /**
258
+ * Returns a clone of a (nested) object that has a maximum depth
259
+ *
260
+ * @param {object|array} obj
261
+ *
262
+ * @returns {object|array} shallow object or array
263
+ */
264
+ export function shallowClone(objectOrArray: any): object | any[];
265
+ /**
266
+ * Update an object
267
+ * - Sets the path-value pairs from the updateData in the object
268
+ * - Existing values will be overwritten
269
+ * - Existing intermediate values (objects, arrays) will be overwritten too
270
+ * (if updateData is an object, not an iterable)
271
+ *
272
+ * @param {object} [obj] - Input object
273
+ *
274
+ * @param {object|iterable} updateData - Data to update
275
+ *
276
+ * Note that if using path-value pairs, the order of the pairs is relevant:
277
+ * {
278
+ * "some": {},
279
+ * "some.path": {},
280
+ * "some.path.to": 2,
281
+ * }
282
+ *
283
+ * @returns {object} updated object
284
+ */
285
+ export function updateObject(obj?: object, updateData: object | iterable, options: any): object;
286
+ /**
287
+ * Copy own properties from an object to another object if they do not
288
+ * exist yet.
289
+ *
290
+ * @param {object} from - Object ot copy properties from
291
+ * @param {object} to - Object to copy properties to
292
+ */
293
+ export function copyOwnProperties(from: object, to: object): void;
294
+ /**
295
+ * Convert string with dot separated values to a list of values
296
+ * - Accepts that the supplied path is already an array path
297
+ *
298
+ * @param {string|string[]} path
299
+ *
300
+ * @returns {string[]} list of path values
301
+ */
302
+ export function ensureArrayPath(path: string | string[]): string[];
303
+ /**
304
+ * Create all parent objects on the object path if they do not yet exist yet
305
+ * - This method will throw an exception if there is a non-object node in
306
+ * the path
307
+ *
308
+ * @param {object} obj
309
+ * Object to create the parent objects in
310
+ *
311
+ * @param {string[]} arrPath
312
+ * The path that specified which parent oobjects to create
313
+ *
314
+ * @returns {object} the input object with the created object properties
315
+ */
316
+ export function _ensureParent(obj: object, arrPath: string[]): object;
317
+ /**
318
+ * Get parent object at the specified path
319
+ *
320
+ * @param {object} obj - Object to work in
321
+ * @param {string[]} arrPath - Path to get the parent object for
322
+ *
323
+ * @returns {object|array|null} parent object or null if not found
324
+ */
325
+ export function _getParent(obj: object, arrPath: string[]): object | any[] | null;
326
+ export const PATH_SEPARATOR: ".";