@mapomodule/utils 2.0.0-beta.5 → 2.0.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/README.md CHANGED
@@ -1,33 +1,37 @@
1
1
  # @mapomodule/utils
2
2
 
3
- Typed utility helpers shared across all `@mapomodule/*` packages.
4
-
5
- ## Utilities
6
-
7
- | Export | Description |
8
- | ------------------- | ---------------------------------------------------------------------------------------------------------- |
9
- | `deepMerge` | Recursively merges two plain objects |
10
- | `getNestedValue` | Reads a value from a dotted path (e.g. `"user.address.city"`) |
11
- | `setNestedValue` | Returns a new object with a value set at a dotted path |
12
- | `objectDiff` | Returns only the keys that differ between two objects — used for differential PATCH requests |
13
- | `formatDate` | Formats a `Date` or ISO string with a token-based format string (`YYYY`, `MM`, `DD`, `HH`, `mm`, `ss`) |
14
- | `debounce` | Returns a debounced version of a function |
15
- | `slotNamespace` | Filters and strips a prefix from a Vue `Slots` object — used to forward a slot subset to a child component |
16
- | `buildRouteTree` | Converts a flat `RouteRecordNormalized[]` into a nested `MenuNode[]` tree for sidebar rendering |
17
- | `normalizeEndpoint` | Ensures an API endpoint string has exactly one leading and one trailing slash — used by `useCrud` |
3
+ Plain TypeScript helpers shared by the `@mapomodule/*` packages: object and path utilities, formatting, endpoint normalization, menu trees and JSON Schema conditionals. No Vue, no Nuxt, no side effects, so they are safe in server code and tests.
18
4
 
19
- ## Installation
5
+ It is not a Nuxt module and nothing is auto-imported: import what you need.
20
6
 
21
- ```bash
22
- pnpm add @mapomodule/utils
7
+ ```ts
8
+ import { debounce, deepMerge, slugify } from "@mapomodule/utils";
9
+ import { applyConditionals } from "@mapomodule/utils/jsonSchema";
23
10
  ```
24
11
 
25
- ## Dev workflow
12
+ ## Installation
26
13
 
27
14
  ```bash
28
- pnpm dev:utils # from monorepo root — tsc --watch
15
+ pnpm add @mapomodule/utils@next
29
16
  ```
30
17
 
31
- ---
18
+ Apps already get it through `mapomodule`, but with pnpm's strict layout an app can import it only if the package is declared in its own `dependencies`. Mapo v2 is published on the `next` dist-tag while it is in beta.
19
+
20
+ ## What's inside
21
+
22
+ | Area | Exports |
23
+ | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
24
+ | Objects | `deepMerge`, `deepClone`, `objectDiff`, `filterObj`, `findPropPaths` |
25
+ | Nested paths | `getNestedValue`, `setNestedValue`, `setNestedValueMutating` |
26
+ | Files | `isFile`, `isBlob`, `isFileOrBlob`, `filesInObject` |
27
+ | Formatting | `formatDate`, `humanFileSize`, `slugify` |
28
+ | Timing | `debounce` |
29
+ | Endpoints | `normalizeEndpoint`, `splitEndpointParams` |
30
+ | Slots and menus | `slotNamespace`, `buildRouteTree`, `calcMaxMenuNestDepth`, the `MenuNode` type |
31
+ | JSON Schema (`@mapomodule/utils/jsonSchema`, also exported from the root) | `matchesSchema`, `applyConditionals`, `hasConditionals`, `resolveSchema`, `extractDefs`, `getDefaultForSchema`, the `JSONSchema` type |
32
+
33
+ ## Documentation
32
34
 
33
- > The helpers in this package are ported from the Mapo v1 legacy codebase. As v2 development progresses, individual helpers may be added, removed, or replaced — and the package itself may be dissolved if its contents are better placed elsewhere.
35
+ - [@mapomodule/utils](https://lotrekagency.github.io/mapo-new/modules/utils): every helper with examples
36
+ - [Composable & Function API Reference](https://lotrekagency.github.io/mapo-new/modules/api): signatures, including the JSON Schema helpers
37
+ - [Import Guide](https://lotrekagency.github.io/mapo-new/guide/imports)
package/dist/debounce.js CHANGED
@@ -5,15 +5,20 @@
5
5
  *
6
6
  * @param fn Function to debounce.
7
7
  * @param ms Debounce delay in milliseconds.
8
- * @returns A debounced function with the same argument signature as `fn`.
8
+ * @returns A debounced function with the same argument signature as `fn`, and a `cancel()` method.
9
9
  */
10
10
  export function debounce(fn, ms) {
11
11
  let timer;
12
- return function (...args) {
12
+ const debounced = function (...args) {
13
13
  clearTimeout(timer);
14
14
  timer = setTimeout(() => {
15
15
  fn.apply(this, args);
16
16
  }, ms);
17
17
  };
18
+ debounced.cancel = () => {
19
+ clearTimeout(timer);
20
+ timer = undefined;
21
+ };
22
+ return debounced;
18
23
  }
19
24
  //# sourceMappingURL=debounce.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"debounce.js","sourceRoot":"","sources":["../src/debounce.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CACtB,EAA2B,EAC3B,EAAU;IAEV,IAAI,KAAgD,CAAC;IACrD,OAAO,UAAyB,GAAG,IAAO;QACxC,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACvB,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"debounce.js","sourceRoot":"","sources":["../src/debounce.ts"],"names":[],"mappings":"AAUA;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CACtB,EAA2B,EAC3B,EAAU;IAEV,IAAI,KAAgD,CAAC;IACrD,MAAM,SAAS,GAAG,UAAyB,GAAG,IAAO;QACnD,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACvB,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAiB,CAAC;IAClB,SAAS,CAAC,MAAM,GAAG,GAAG,EAAE;QACtB,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,KAAK,GAAG,SAAS,CAAC;IACpB,CAAC,CAAC;IACF,OAAO,SAAS,CAAC;AACnB,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,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C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExE,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAEhF,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,WAAW,EACX,mBAAmB,GACpB,MAAM,uBAAuB,CAAC"}
@@ -1,3 +1,12 @@
1
+ /** A debounced function: called like the original, plus `cancel()`. */
2
+ export interface Debounced<A extends unknown[]> {
3
+ (...args: A): void;
4
+ /**
5
+ * Drops the pending call, if any. Call it when the owner goes away (in a
6
+ * component, `onBeforeUnmount`), so a late call cannot act on the next page.
7
+ */
8
+ cancel(): void;
9
+ }
1
10
  /**
2
11
  * Creates a debounced wrapper that delays invocation until calls stop for `ms` milliseconds.
3
12
  *
@@ -5,7 +14,7 @@
5
14
  *
6
15
  * @param fn Function to debounce.
7
16
  * @param ms Debounce delay in milliseconds.
8
- * @returns A debounced function with the same argument signature as `fn`.
17
+ * @returns A debounced function with the same argument signature as `fn`, and a `cancel()` method.
9
18
  */
10
- export declare function debounce<A extends unknown[]>(fn: (...args: A) => unknown, ms: number): (...args: A) => void;
19
+ export declare function debounce<A extends unknown[]>(fn: (...args: A) => unknown, ms: number): Debounced<A>;
11
20
  //# sourceMappingURL=debounce.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../src/debounce.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,OAAO,EAAE,EAC1C,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,EAC3B,EAAE,EAAE,MAAM,GACT,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,CAQtB"}
1
+ {"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../src/debounce.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,OAAO,EAAE;IAC5C,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACnB;;;OAGG;IACH,MAAM,IAAI,IAAI,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,OAAO,EAAE,EAC1C,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,EAC3B,EAAE,EAAE,MAAM,GACT,SAAS,CAAC,CAAC,CAAC,CAad"}
@@ -5,6 +5,7 @@ export { objectDiff } from "./objectDiff.js";
5
5
  export { formatDate } from "./formatDate.js";
6
6
  export { humanFileSize, slugify } from "./formatters.js";
7
7
  export { debounce } from "./debounce.js";
8
+ export type { Debounced } from "./debounce.js";
8
9
  export { slotNamespace } from "./slotNamespace.js";
9
10
  export { buildRouteTree, calcMaxMenuNestDepth } from "./menuHelpers.js";
10
11
  export type { MenuNode } from "./menuHelpers.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACL,SAAS,EACT,MAAM,EACN,MAAM,EACN,YAAY,EACZ,aAAa,EACb,aAAa,EACb,SAAS,GACV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,cAAc,EACd,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,o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L,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,WAAW,EACX,mBAAmB,GACpB,MAAM,uBAAuB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapomodule/utils",
3
- "version": "2.0.0-beta.5",
3
+ "version": "2.0.0-beta.6",
4
4
  "description": "Mapo typed utilities",
5
5
  "type": "module",
6
6
  "license": "MIT",