@hybridly/utils 0.10.0-beta.11 → 0.10.0-beta.13

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.
Files changed (2) hide show
  1. package/dist/index.mjs +34 -0
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -3,10 +3,17 @@ 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
+ //#region src/form-data.ts
7
+ /**
8
+ * Checks if the given object has a file.
9
+ */
6
10
  function hasFiles(data) {
7
11
  if (!data) return false;
8
12
  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));
9
13
  }
14
+ /**
15
+ * Converts an object literal to a `FormData` object.
16
+ */
10
17
  function objectToFormData(source, form, parentKey) {
11
18
  source ??= {};
12
19
  form ??= new FormData();
@@ -31,6 +38,8 @@ function append(form, key, value) {
31
38
  else if (value === null || value === void 0) return form.append(key, "");
32
39
  objectToFormData(value, form, key);
33
40
  }
41
+ //#endregion
42
+ //#region src/error-modal.ts
34
43
  const stack = [];
35
44
  var Modal = class Modal {
36
45
  constructor(html, id) {
@@ -239,12 +248,15 @@ function style() {
239
248
  }
240
249
  `;
241
250
  }
251
+ //#endregion
252
+ //#region src/utils.ts
242
253
  function random(length = 10) {
243
254
  const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
244
255
  let str = "";
245
256
  for (let i = 0; i < length; i++) str += chars.charAt(Math.floor(Math.random() * 62));
246
257
  return str;
247
258
  }
259
+ /** Simple pattern matching util. */
248
260
  function match(value, lookup, ...args) {
249
261
  if (value in lookup || "default" in lookup) {
250
262
  const returnValue = value in lookup ? lookup[value] : lookup.default;
@@ -270,6 +282,16 @@ function merge(x, y, options = {}) {
270
282
  function removeTrailingSlash(string) {
271
283
  return string.replace(/\/+$/, "");
272
284
  }
285
+ /**
286
+ * Sets a value at a path in an object
287
+ *
288
+ * This function will set a value at a path in an object, creating any missing
289
+ * objects along the way. The object is modified in place.
290
+ *
291
+ * @param obj the object to set the value in
292
+ * @param path a dot-separated path to the property to set
293
+ * @param value the value to set
294
+ */
273
295
  function setValueAtPath(obj, path, value) {
274
296
  if (!path.includes(".")) {
275
297
  obj[path] = value;
@@ -283,6 +305,15 @@ function setValueAtPath(obj, path, value) {
283
305
  }
284
306
  nestedObject[segments[segments.length - 1]] = value;
285
307
  }
308
+ /**
309
+ * Unsets a property at a path in an object
310
+ *
311
+ * This function will unset a property at a path in an object, deleting any
312
+ * objects along the way that are empty. The object is modified in place.
313
+ *
314
+ * @param obj the object to unset the property in
315
+ * @param path a dot-separated path to the property to unset
316
+ */
286
317
  function unsetPropertyAtPath(obj, path) {
287
318
  if (!path.includes(".")) {
288
319
  delete obj[path];
@@ -297,6 +328,8 @@ function unsetPropertyAtPath(obj, path) {
297
328
  delete nestedObject[segments[segments.length - 1]];
298
329
  if (Object.keys(nestedObject).length === 0) unsetPropertyAtPath(obj, segments.slice(0, -1).join("."));
299
330
  }
331
+ //#endregion
332
+ //#region src/debug.ts
300
333
  const debug = {
301
334
  router: makeDebugger("hybridly:core:router"),
302
335
  history: makeDebugger("hybridly:core:history"),
@@ -308,4 +341,5 @@ const debug = {
308
341
  plugin: (name, ...args) => makeDebugger("hybridly:plugin").extend(name.replace("hybridly:", ""))(args.shift(), ...args),
309
342
  adapter: (name, ...args) => makeDebugger("hybridly:adapter").extend(name)(args.shift(), ...args)
310
343
  };
344
+ //#endregion
311
345
  export { clone, debounce, debug, hasFiles, match, merge, objectToFormData, random, removeTrailingSlash, setValueAtPath, showResponseErrorModal, showViewComponentErrorModal, throttle, unsetPropertyAtPath, value, when };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hybridly/utils",
3
3
  "type": "module",
4
- "version": "0.10.0-beta.11",
4
+ "version": "0.10.0-beta.13",
5
5
  "description": "Utils used in Hybridly packages",
6
6
  "author": "Enzo Innocenzi <enzo@innocenzi.dev>",
7
7
  "license": "MIT",