@hybridly/utils 0.10.0-beta.14 → 0.10.0-beta.15

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.d.mts CHANGED
@@ -1,5 +1,4 @@
1
- import { debounce, throttle } from "throttle-debounce";
2
- import clone from "lodash.clonedeep";
1
+ import { Path, PathValue, SearchableObject, getByPath, setByPath } from "@clickbar/dot-diver";
3
2
  import makeDebugger from "debug";
4
3
 
5
4
  //#region src/form-data.d.ts
@@ -40,48 +39,32 @@ declare function showViewComponentErrorModal(response: string): Modal;
40
39
  declare function random(length?: number): string;
41
40
  /** Simple pattern matching util. */
42
41
  declare function match<TValue extends string | number = string, TReturnValue = unknown, TArgs extends readonly unknown[] = []>(value: TValue, lookup: Record<TValue | 'default', TReturnValue | ((...args: TArgs) => TReturnValue | Promise<TReturnValue>)>, ...args: TArgs): TReturnValue | Promise<TReturnValue>;
43
- declare function value<T>(value: T | (() => T)): T;
44
- declare function when<T, D>(condition: any, data: T, _default?: D): T | D | undefined;
42
+ declare function wrap<T>(value: undefined | T | T[]): T[];
43
+ /**
44
+ * Returns the object only if the condition is true. Useful for conditionally merging in an object using the spread operator.
45
+ */
46
+ declare function mergeObject<T extends object>(condition: any, data: T): T | object;
45
47
  interface MergeOptions {
46
48
  overwriteArray?: boolean;
47
49
  mergePlainObjects?: boolean;
48
50
  arrayMerge?: (target: any[], source: any[]) => any[];
49
51
  }
50
52
  declare function merge<T>(x: Partial<T>, y: Partial<T>, options?: MergeOptions): T;
51
- declare function removeTrailingSlash(string: string): string;
52
- /**
53
- * Sets a value at a path in an object
54
- *
55
- * This function will set a value at a path in an object, creating any missing
56
- * objects along the way. The object is modified in place.
57
- *
58
- * @param obj the object to set the value in
59
- * @param path a dot-separated path to the property to set
60
- * @param value the value to set
61
- */
62
- declare function setValueAtPath(obj: any, path: string, value: any): void;
63
- /**
64
- * Unsets a property at a path in an object
65
- *
66
- * This function will unset a property at a path in an object, deleting any
67
- * objects along the way that are empty. The object is modified in place.
68
- *
69
- * @param obj the object to unset the property in
70
- * @param path a dot-separated path to the property to unset
71
- */
72
- declare function unsetPropertyAtPath(obj: any, path: string): void;
73
53
  //#endregion
74
54
  //#region src/debug.d.ts
75
55
  declare const debug: {
76
56
  router: makeDebugger.Debugger;
57
+ queue: makeDebugger.Debugger;
77
58
  history: makeDebugger.Debugger;
78
59
  url: makeDebugger.Debugger;
79
60
  context: makeDebugger.Debugger;
80
61
  external: makeDebugger.Debugger;
81
62
  scroll: makeDebugger.Debugger;
82
63
  hook: makeDebugger.Debugger;
64
+ layout: makeDebugger.Debugger;
65
+ config: makeDebugger.Debugger;
83
66
  plugin: (name: string, ...args: any[]) => void;
84
67
  adapter: (name: string, ...args: any[]) => void;
85
68
  };
86
69
  //#endregion
87
- export { FormDataConvertible, RequestData, clone, debounce, debug, hasFiles, match, merge, objectToFormData, random, removeTrailingSlash, setValueAtPath, showResponseErrorModal, showViewComponentErrorModal, throttle, unsetPropertyAtPath, value, when };
70
+ export { FormDataConvertible, type Path, type PathValue, RequestData, type SearchableObject, debug, getByPath, hasFiles, match, merge, mergeObject, objectToFormData, random, setByPath, showResponseErrorModal, showViewComponentErrorModal, wrap };
package/dist/index.mjs CHANGED
@@ -1,7 +1,6 @@
1
1
  import baseMerge from "deepmerge";
2
- import { isPlainObject } from "is-plain-object";
3
- import { debounce, throttle } from "throttle-debounce";
4
- import clone from "lodash.clonedeep";
2
+ import { isPlainObject } from "es-toolkit/predicate";
3
+ import { getByPath, setByPath } from "@clickbar/dot-diver";
5
4
  import makeDebugger from "debug";
6
5
  //#region src/form-data.ts
7
6
  /**
@@ -265,12 +264,15 @@ function match(value, lookup, ...args) {
265
264
  const handlers = Object.keys(lookup).map((key) => `"${key}"`).join(", ");
266
265
  throw new Error(`Tried to handle "${value}" but there is no handler defined. Only defined handlers are: ${handlers}.`);
267
266
  }
268
- function value(value) {
269
- if (typeof value === "function") return value?.();
270
- return value;
267
+ function wrap(value) {
268
+ if (value === void 0) return [];
269
+ return Array.isArray(value) ? value : [value];
271
270
  }
272
- function when(condition, data, _default) {
273
- if (!condition) return _default;
271
+ /**
272
+ * Returns the object only if the condition is true. Useful for conditionally merging in an object using the spread operator.
273
+ */
274
+ function mergeObject(condition, data) {
275
+ if (!condition) return {};
274
276
  return data;
275
277
  }
276
278
  function merge(x, y, options = {}) {
@@ -279,67 +281,21 @@ function merge(x, y, options = {}) {
279
281
  isMergeableObject: options?.mergePlainObjects ? isPlainObject : void 0
280
282
  });
281
283
  }
282
- function removeTrailingSlash(string) {
283
- return string.replace(/\/+$/, "");
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
- */
295
- function setValueAtPath(obj, path, value) {
296
- if (!path.includes(".")) {
297
- obj[path] = value;
298
- return;
299
- }
300
- const segments = path.split(".");
301
- let nestedObject = obj;
302
- for (let i = 0; i < segments.length - 1; i++) {
303
- const key = segments[i];
304
- nestedObject = nestedObject[key] = nestedObject[key] || {};
305
- }
306
- nestedObject[segments[segments.length - 1]] = value;
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
- */
317
- function unsetPropertyAtPath(obj, path) {
318
- if (!path.includes(".")) {
319
- delete obj[path];
320
- return;
321
- }
322
- const segments = path.split(".");
323
- let nestedObject = obj;
324
- for (let i = 0; i < segments.length - 1; i++) {
325
- const key = segments[i];
326
- nestedObject = nestedObject[key] = nestedObject[key] || {};
327
- }
328
- delete nestedObject[segments[segments.length - 1]];
329
- if (Object.keys(nestedObject).length === 0) unsetPropertyAtPath(obj, segments.slice(0, -1).join("."));
330
- }
331
284
  //#endregion
332
285
  //#region src/debug.ts
333
286
  const debug = {
334
287
  router: makeDebugger("hybridly:core:router"),
288
+ queue: makeDebugger("hybridly:core:router:queue"),
335
289
  history: makeDebugger("hybridly:core:history"),
336
290
  url: makeDebugger("hybridly:core:url"),
337
291
  context: makeDebugger("hybridly:core:context"),
338
292
  external: makeDebugger("hybridly:core:external"),
339
293
  scroll: makeDebugger("hybridly:core:scroll"),
340
294
  hook: makeDebugger("hybridly:core:hook"),
295
+ layout: makeDebugger("hybridly:plugin:layout"),
296
+ config: makeDebugger("hybridly:vite:config"),
341
297
  plugin: (name, ...args) => makeDebugger("hybridly:plugin").extend(name.replace("hybridly:", ""))(args.shift(), ...args),
342
298
  adapter: (name, ...args) => makeDebugger("hybridly:adapter").extend(name)(args.shift(), ...args)
343
299
  };
344
300
  //#endregion
345
- export { clone, debounce, debug, hasFiles, match, merge, objectToFormData, random, removeTrailingSlash, setValueAtPath, showResponseErrorModal, showViewComponentErrorModal, throttle, unsetPropertyAtPath, value, when };
301
+ export { debug, getByPath, hasFiles, match, merge, mergeObject, objectToFormData, random, setByPath, showResponseErrorModal, showViewComponentErrorModal, wrap };
package/package.json CHANGED
@@ -1,52 +1,48 @@
1
1
  {
2
- "name": "@hybridly/utils",
3
- "type": "module",
4
- "version": "0.10.0-beta.14",
5
- "description": "Utils used in Hybridly packages",
6
- "author": "Enzo Innocenzi <enzo@innocenzi.dev>",
7
- "license": "MIT",
8
- "funding": "https://github.com/sponsors/innocenzi",
9
- "homepage": "https://github.com/hybridly/hybridly/tree/main/packages/config#readme",
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/hybridly/hybridly.git",
13
- "directory": "packages/utils"
14
- },
15
- "bugs": {
16
- "url": "https://github.com/hybridly/hybridly/issues"
17
- },
18
- "keywords": [
19
- "hybridly"
20
- ],
21
- "publishConfig": {
22
- "provenance": true,
23
- "access": "public"
24
- },
25
- "sideEffects": false,
26
- "exports": {
27
- ".": {
28
- "types": "./dist/index.d.mts",
29
- "import": "./dist/index.mjs"
30
- }
31
- },
32
- "module": "dist/index.mjs",
33
- "types": "dist/index.d.mts",
34
- "files": [
35
- "*.d.ts",
36
- "dist"
37
- ],
38
- "scripts": {
39
- "build": "obuild",
40
- "build:stub": "obuild --stub"
41
- },
42
- "dependencies": {
43
- "debug": "^4.4.1",
44
- "deepmerge": "^4.3.1",
45
- "is-plain-object": "^5.0.0",
46
- "lodash.clonedeep": "^4.5.0",
47
- "throttle-debounce": "^5.0.2"
48
- },
49
- "devDependencies": {
50
- "@types/lodash.clonedeep": "^4.5.9"
51
- }
2
+ "name": "@hybridly/utils",
3
+ "type": "module",
4
+ "version": "0.10.0-beta.15",
5
+ "description": "Utils used in Hybridly packages",
6
+ "author": "Enzo Innocenzi <enzo@innocenzi.dev>",
7
+ "license": "MIT",
8
+ "funding": "https://github.com/sponsors/innocenzi",
9
+ "homepage": "https://github.com/hybridly/hybridly/tree/main/packages/config#readme",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/hybridly/hybridly.git",
13
+ "directory": "packages/utils"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/hybridly/hybridly/issues"
17
+ },
18
+ "keywords": [
19
+ "hybridly"
20
+ ],
21
+ "publishConfig": {
22
+ "provenance": true,
23
+ "access": "public"
24
+ },
25
+ "sideEffects": false,
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.mts",
29
+ "import": "./dist/index.mjs"
30
+ }
31
+ },
32
+ "module": "dist/index.mjs",
33
+ "types": "dist/index.d.mts",
34
+ "files": [
35
+ "*.d.ts",
36
+ "dist"
37
+ ],
38
+ "scripts": {
39
+ "build": "obuild",
40
+ "build:stub": "obuild --stub"
41
+ },
42
+ "dependencies": {
43
+ "@clickbar/dot-diver": "^1.0.7",
44
+ "debug": "^4.4.1",
45
+ "deepmerge": "^4.3.1",
46
+ "es-toolkit": "^1.45.1"
47
+ }
52
48
  }