@hybridly/utils 0.10.0-beta.4 → 0.10.0-beta.6
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.
- package/dist/index.mjs +1 -40
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3,18 +3,10 @@ import { isPlainObject } from "is-plain-object";
|
|
|
3
3
|
import { debounce, throttle } from "throttle-debounce";
|
|
4
4
|
import clone from "lodash.clonedeep";
|
|
5
5
|
import makeDebugger from "debug";
|
|
6
|
-
|
|
7
|
-
//#region src/form-data.ts
|
|
8
|
-
/**
|
|
9
|
-
* Checks if the given object has a file.
|
|
10
|
-
*/
|
|
11
6
|
function hasFiles(data) {
|
|
12
7
|
if (!data) return false;
|
|
13
8
|
return data instanceof File || data instanceof Blob || data instanceof FileList && data.length > 0 || data instanceof FormData && Array.from(data.values()).some((value) => hasFiles(value)) || typeof data === "object" && data !== null && Object.values(data).some((value) => hasFiles(value));
|
|
14
9
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Converts an object literal to a `FormData` object.
|
|
17
|
-
*/
|
|
18
10
|
function objectToFormData(source, form, parentKey) {
|
|
19
11
|
source ??= {};
|
|
20
12
|
form ??= new FormData();
|
|
@@ -39,9 +31,6 @@ function append(form, key, value) {
|
|
|
39
31
|
else if (value === null || value === void 0) return form.append(key, "");
|
|
40
32
|
objectToFormData(value, form, key);
|
|
41
33
|
}
|
|
42
|
-
|
|
43
|
-
//#endregion
|
|
44
|
-
//#region src/error-modal.ts
|
|
45
34
|
const stack = [];
|
|
46
35
|
var Modal = class Modal {
|
|
47
36
|
constructor(html, id) {
|
|
@@ -250,16 +239,12 @@ function style() {
|
|
|
250
239
|
}
|
|
251
240
|
`;
|
|
252
241
|
}
|
|
253
|
-
|
|
254
|
-
//#endregion
|
|
255
|
-
//#region src/utils.ts
|
|
256
242
|
function random(length = 10) {
|
|
257
243
|
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
258
244
|
let str = "";
|
|
259
245
|
for (let i = 0; i < length; i++) str += chars.charAt(Math.floor(Math.random() * 62));
|
|
260
246
|
return str;
|
|
261
247
|
}
|
|
262
|
-
/** Simple pattern matching util. */
|
|
263
248
|
function match(value, lookup, ...args) {
|
|
264
249
|
if (value in lookup || "default" in lookup) {
|
|
265
250
|
const returnValue = value in lookup ? lookup[value] : lookup.default;
|
|
@@ -285,16 +270,6 @@ function merge(x, y, options = {}) {
|
|
|
285
270
|
function removeTrailingSlash(string) {
|
|
286
271
|
return string.replace(/\/+$/, "");
|
|
287
272
|
}
|
|
288
|
-
/**
|
|
289
|
-
* Sets a value at a path in an object
|
|
290
|
-
*
|
|
291
|
-
* This function will set a value at a path in an object, creating any missing
|
|
292
|
-
* objects along the way. The object is modified in place.
|
|
293
|
-
*
|
|
294
|
-
* @param obj the object to set the value in
|
|
295
|
-
* @param path a dot-separated path to the property to set
|
|
296
|
-
* @param value the value to set
|
|
297
|
-
*/
|
|
298
273
|
function setValueAtPath(obj, path, value) {
|
|
299
274
|
if (!path.includes(".")) {
|
|
300
275
|
obj[path] = value;
|
|
@@ -308,15 +283,6 @@ function setValueAtPath(obj, path, value) {
|
|
|
308
283
|
}
|
|
309
284
|
nestedObject[segments[segments.length - 1]] = value;
|
|
310
285
|
}
|
|
311
|
-
/**
|
|
312
|
-
* Unsets a property at a path in an object
|
|
313
|
-
*
|
|
314
|
-
* This function will unset a property at a path in an object, deleting any
|
|
315
|
-
* objects along the way that are empty. The object is modified in place.
|
|
316
|
-
*
|
|
317
|
-
* @param obj the object to unset the property in
|
|
318
|
-
* @param path a dot-separated path to the property to unset
|
|
319
|
-
*/
|
|
320
286
|
function unsetPropertyAtPath(obj, path) {
|
|
321
287
|
if (!path.includes(".")) {
|
|
322
288
|
delete obj[path];
|
|
@@ -331,9 +297,6 @@ function unsetPropertyAtPath(obj, path) {
|
|
|
331
297
|
delete nestedObject[segments[segments.length - 1]];
|
|
332
298
|
if (Object.keys(nestedObject).length === 0) unsetPropertyAtPath(obj, segments.slice(0, -1).join("."));
|
|
333
299
|
}
|
|
334
|
-
|
|
335
|
-
//#endregion
|
|
336
|
-
//#region src/debug.ts
|
|
337
300
|
const debug = {
|
|
338
301
|
router: makeDebugger("hybridly:core:router"),
|
|
339
302
|
history: makeDebugger("hybridly:core:history"),
|
|
@@ -345,6 +308,4 @@ const debug = {
|
|
|
345
308
|
plugin: (name, ...args) => makeDebugger("hybridly:plugin").extend(name.replace("hybridly:", ""))(args.shift(), ...args),
|
|
346
309
|
adapter: (name, ...args) => makeDebugger("hybridly:adapter").extend(name)(args.shift(), ...args)
|
|
347
310
|
};
|
|
348
|
-
|
|
349
|
-
//#endregion
|
|
350
|
-
export { clone, debounce, debug, hasFiles, match, merge, objectToFormData, random, removeTrailingSlash, setValueAtPath, showResponseErrorModal, showViewComponentErrorModal, throttle, unsetPropertyAtPath, value, when };
|
|
311
|
+
export { clone, debounce, debug, hasFiles, match, merge, objectToFormData, random, removeTrailingSlash, setValueAtPath, showResponseErrorModal, showViewComponentErrorModal, throttle, unsetPropertyAtPath, value, when };
|