@mapomodule/utils 1.0.0-alpha.9 → 2.0.0-beta.1

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 (66) hide show
  1. package/README.md +33 -0
  2. package/dist/debounce.js +19 -0
  3. package/dist/debounce.js.map +1 -0
  4. package/dist/deepMerge.js +31 -0
  5. package/dist/deepMerge.js.map +1 -0
  6. package/dist/formatDate.js +23 -0
  7. package/dist/formatDate.js.map +1 -0
  8. package/dist/index.js +11 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/jsonSchema/conditionals.js +326 -0
  11. package/dist/jsonSchema/conditionals.js.map +1 -0
  12. package/dist/jsonSchema/index.js +3 -0
  13. package/dist/jsonSchema/index.js.map +1 -0
  14. package/dist/jsonSchema/resolve.js +133 -0
  15. package/dist/jsonSchema/resolve.js.map +1 -0
  16. package/dist/jsonSchema/types.js +2 -0
  17. package/dist/jsonSchema/types.js.map +1 -0
  18. package/dist/menuHelpers.js +56 -0
  19. package/dist/menuHelpers.js.map +1 -0
  20. package/dist/nestedValue.js +53 -0
  21. package/dist/nestedValue.js.map +1 -0
  22. package/dist/normalizeEndpoint.js +39 -0
  23. package/dist/normalizeEndpoint.js.map +1 -0
  24. package/dist/objectDiff.js +58 -0
  25. package/dist/objectDiff.js.map +1 -0
  26. package/dist/objectHelpers.js +93 -0
  27. package/dist/objectHelpers.js.map +1 -0
  28. package/dist/slotNamespace.js +15 -0
  29. package/dist/slotNamespace.js.map +1 -0
  30. package/dist/types/debounce.d.ts +11 -0
  31. package/dist/types/debounce.d.ts.map +1 -0
  32. package/dist/types/deepMerge.d.ts +12 -0
  33. package/dist/types/deepMerge.d.ts.map +1 -0
  34. package/dist/types/formatDate.d.ts +11 -0
  35. package/dist/types/formatDate.d.ts.map +1 -0
  36. package/dist/types/index.d.ts +13 -0
  37. package/dist/types/index.d.ts.map +1 -0
  38. package/dist/types/jsonSchema/conditionals.d.ts +40 -0
  39. package/dist/types/jsonSchema/conditionals.d.ts.map +1 -0
  40. package/dist/types/jsonSchema/index.d.ts +15 -0
  41. package/dist/types/jsonSchema/index.d.ts.map +1 -0
  42. package/dist/types/jsonSchema/resolve.d.ts +41 -0
  43. package/dist/types/jsonSchema/resolve.d.ts.map +1 -0
  44. package/dist/types/jsonSchema/types.d.ts +43 -0
  45. package/dist/types/jsonSchema/types.d.ts.map +1 -0
  46. package/dist/types/menuHelpers.d.ts +22 -0
  47. package/dist/types/menuHelpers.d.ts.map +1 -0
  48. package/dist/types/nestedValue.d.ts +25 -0
  49. package/dist/types/nestedValue.d.ts.map +1 -0
  50. package/dist/types/normalizeEndpoint.d.ts +28 -0
  51. package/dist/types/normalizeEndpoint.d.ts.map +1 -0
  52. package/dist/types/objectDiff.d.ts +12 -0
  53. package/dist/types/objectDiff.d.ts.map +1 -0
  54. package/dist/types/objectHelpers.d.ts +33 -0
  55. package/dist/types/objectHelpers.d.ts.map +1 -0
  56. package/dist/types/slotNamespace.d.ts +12 -0
  57. package/dist/types/slotNamespace.d.ts.map +1 -0
  58. package/package.json +40 -9
  59. package/CHANGELOG.md +0 -22
  60. package/LICENSE.md +0 -20
  61. package/helpers/auth.js +0 -21
  62. package/helpers/debounce.js +0 -18
  63. package/helpers/formatters.js +0 -27
  64. package/helpers/objHelpers.js +0 -53
  65. package/index.js +0 -11
  66. package/loaders/dummy-loader.js +0 -1
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Ensures an API endpoint path has exactly one leading and one trailing slash.
3
+ * Query strings are preserved unchanged — the slash is inserted before the `?`.
4
+ * Used by `useCrud` to normalize user-provided endpoint paths before making requests.
5
+ *
6
+ * @example
7
+ * normalizeEndpoint('api/articles') // '/api/articles/'
8
+ * normalizeEndpoint('/api/articles') // '/api/articles/'
9
+ * normalizeEndpoint('/api/articles/') // '/api/articles/'
10
+ * normalizeEndpoint('/api/articles/?q=1') // '/api/articles/?q=1'
11
+ */
12
+ export declare function normalizeEndpoint(endpoint: string): string;
13
+ /**
14
+ * Splits an endpoint string into its clean path and parsed query params.
15
+ * Useful when an endpoint carries baked-in params (e.g. `?fields=id,title`) that
16
+ * must be merged into request params while CRUD mutations target the bare path.
17
+ *
18
+ * @example
19
+ * splitEndpointParams('/api/articles/?fields=id,title')
20
+ * { path: '/api/articles/', params: { fields: 'id,title' } }
21
+ * splitEndpointParams('/api/articles/')
22
+ * { path: '/api/articles/', params: {} }
23
+ */
24
+ export declare function splitEndpointParams(endpoint: string): {
25
+ path: string;
26
+ params: Record<string, string>;
27
+ };
28
+ //# sourceMappingURL=normalizeEndpoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeEndpoint.d.ts","sourceRoot":"","sources":["../../src/normalizeEndpoint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAM1D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC,CAOA"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Computes a deep diff between two objects and returns only changed fields.
3
+ *
4
+ * Nested objects are diffed recursively. Arrays are compared deeply and, when changed,
5
+ * are returned as the full current array value.
6
+ *
7
+ * @param base Base object used as the comparison reference.
8
+ * @param current Current object to compare against `base`.
9
+ * @returns A partial object containing only keys whose values differ from `base`.
10
+ */
11
+ export declare function objectDiff<T extends object>(base: T, current: T): Partial<T>;
12
+ //# sourceMappingURL=objectDiff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectDiff.d.ts","sourceRoot":"","sources":["../../src/objectDiff.ts"],"names":[],"mappings":"AAsBA;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CA2B5E"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Deep-clones a value and returns a detached copy.
3
+ *
4
+ * The function first unwraps Vue reactive proxies (when present), then:
5
+ * - uses `structuredClone` when available
6
+ * - falls back to recursive cloning for plain objects/arrays
7
+ *
8
+ * The recursive fallback does not support circular references.
9
+ */
10
+ export declare function deepClone<T>(value: T): T;
11
+ /**
12
+ * Type guard that returns true when `value` is a browser `File`.
13
+ */
14
+ export declare function isFile(value: unknown): value is File;
15
+ /**
16
+ * Type guard that returns true when `value` is a browser `Blob`.
17
+ */
18
+ export declare function isBlob(value: unknown): value is Blob;
19
+ /**
20
+ * Type guard that returns true when `value` is either a `File` or a `Blob`.
21
+ */
22
+ export declare function isFileOrBlob(value: unknown): value is File | Blob;
23
+ /**
24
+ * Return all dot-notation paths in `obj` where the predicate is truthy.
25
+ */
26
+ export declare function findPropPaths(obj: unknown, predicate: (val: unknown) => boolean, _prefix?: string): string[];
27
+ /** Return all paths in `obj` that hold a File or Blob. */
28
+ export declare function filesInObject(obj: unknown): string[];
29
+ /**
30
+ * Return a shallow copy of `obj` containing only the listed top-level keys.
31
+ */
32
+ export declare function filterObj<T extends Record<string, unknown>>(obj: T, keys: (keyof T)[]): Partial<T>;
33
+ //# sourceMappingURL=objectHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectHelpers.d.ts","sourceRoot":"","sources":["../../src/objectHelpers.ts"],"names":[],"mappings":"AAWA;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAkBxC;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAEpD;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAEpD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,IAAI,CAEjE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,EACpC,OAAO,SAAK,GACX,MAAM,EAAE,CAaV;AAED,0DAA0D;AAC1D,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,EAAE,CAEpD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzD,GAAG,EAAE,CAAC,EACN,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,GAChB,OAAO,CAAC,CAAC,CAAC,CAQZ"}
@@ -0,0 +1,12 @@
1
+ import type { Slots } from "vue";
2
+ /**
3
+ * Creates a namespaced view of slots, including only those that start with the given prefix.
4
+ *
5
+ * Filtered slot names are normalized by removing the prefix from the slot key.
6
+ *
7
+ * @param slots Source Vue slots object.
8
+ * @param prefix Prefix used to select which slots to include.
9
+ * @returns A new `Slots` object containing only prefixed slots, renamed without the prefix.
10
+ */
11
+ export declare function slotNamespace(slots: Slots, prefix: string): Slots;
12
+ //# sourceMappingURL=slotNamespace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slotNamespace.d.ts","sourceRoot":"","sources":["../../src/slotNamespace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC;AAEjC;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,CAMjE"}
package/package.json CHANGED
@@ -1,16 +1,47 @@
1
1
  {
2
2
  "name": "@mapomodule/utils",
3
- "version": "1.0.0-alpha.9",
3
+ "version": "2.0.0-beta.1",
4
+ "description": "Mapo typed utilities",
5
+ "type": "module",
4
6
  "license": "MIT",
5
- "description": "This is part of Mapo nuxt module. Provides a set of utils for the project.",
6
- "author": "bnznamco <gabriele.baldi.01@gmail.com>",
7
- "repository": "https://github.com/lotrekagency/mapo",
8
- "main": "./index.js",
9
- "dependencies": {
10
- "js-cookie": "^2.2.1"
7
+ "author": "Lotrek Agency (https://lotrek.it)",
8
+ "homepage": "https://lotrekagency.github.io/mapo-new/",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/lotrekagency/mapo-new.git",
12
+ "directory": "packages/@mapomodule/utils"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/lotrekagency/mapo-new/issues"
11
16
  },
12
17
  "publishConfig": {
13
- "access": "public"
18
+ "access": "public",
19
+ "tag": "next"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/types/index.d.ts",
24
+ "import": "./dist/index.js"
25
+ },
26
+ "./jsonSchema": {
27
+ "types": "./dist/types/jsonSchema/index.d.ts",
28
+ "import": "./dist/jsonSchema/index.js"
29
+ }
30
+ },
31
+ "main": "./dist/index.js",
32
+ "types": "./dist/types/index.d.ts",
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "scripts": {
37
+ "dev": "tsc -p tsconfig.json --watch",
38
+ "build": "tsc -p tsconfig.json",
39
+ "typecheck": "tsc --noEmit",
40
+ "lint": "eslint src",
41
+ "test": "vitest run"
14
42
  },
15
- "gitHead": "a75142247a9371981aea57b76828bd354b375aea"
43
+ "devDependencies": {
44
+ "vue": "^3.5.32",
45
+ "vue-router": "^5.0.4"
46
+ }
16
47
  }
package/CHANGELOG.md DELETED
@@ -1,22 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [1.0.0-alpha.9](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2022-02-08)
7
-
8
-
9
- ### Bug Fixes
10
-
11
- * **core:** fix object setPointed to create missing nesting ([7a26510](https://github.com/lotrekagency/mapo/commit/7a26510d6c1648156bd5a8f18d3851e4fe195d29))
12
-
13
-
14
-
15
-
16
-
17
- # [1.0.0-alpha.8](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.7...v1.0.0-alpha.8) (2022-01-23)
18
-
19
-
20
- ### Features
21
-
22
- * **quickedit:** merge detail component logics in to quickedit ([691f610](https://github.com/lotrekagency/mapo/commit/691f610b156f58a5d30598d89bf06425d90451d8))
package/LICENSE.md DELETED
@@ -1,20 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) Lotrek 2021
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
package/helpers/auth.js DELETED
@@ -1,21 +0,0 @@
1
- const Cookies = require('js-cookie')
2
-
3
- const TokenKey = '__mapo_session'
4
-
5
- function getToken() {
6
- return Cookies.get(TokenKey)
7
- }
8
-
9
- function setToken(token) {
10
- return Cookies.set(TokenKey, token)
11
- }
12
-
13
- function removeToken() {
14
- return Cookies.remove(TokenKey)
15
- }
16
-
17
- module.exports = {
18
- getToken,
19
- setToken,
20
- removeToken
21
- }
@@ -1,18 +0,0 @@
1
- function debounce(func, wait, immediate) {
2
- var timeout;
3
- return function () {
4
- var context = this, args = arguments;
5
- var later = function () {
6
- timeout = null;
7
- if (!immediate) func.apply(context, args);
8
- };
9
- var callNow = immediate && !timeout;
10
- clearTimeout(timeout);
11
- timeout = setTimeout(later, wait);
12
- if (callNow) func.apply(context, args);
13
- };
14
- };
15
-
16
- module.exports = {
17
- debounce
18
- }
@@ -1,27 +0,0 @@
1
- function humanFileSize(bytes, si = false, dp = 1) {
2
- const thresh = si ? 1000 : 1024;
3
-
4
- if (Math.abs(bytes) < thresh) {
5
- return bytes + " B";
6
- }
7
-
8
- const units = si
9
- ? ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
10
- : ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
11
- let u = -1;
12
- const r = 10 ** dp;
13
-
14
- do {
15
- bytes /= thresh;
16
- ++u;
17
- } while (
18
- Math.round(Math.abs(bytes) * r) / r >= thresh &&
19
- u < units.length - 1
20
- );
21
-
22
- return bytes.toFixed(dp) + " " + units[u];
23
- }
24
-
25
- module.exports = {
26
- humanFileSize
27
- }
@@ -1,53 +0,0 @@
1
- function deepClone(obj) {
2
- const clone = obj instanceof Array ? Object.assign([]) : Object.assign({});
3
- for (const i in obj) {
4
- if (obj[i] != null && typeof (obj[i]) == 'object' && !(obj[i] instanceof File) && !(obj[i] instanceof Date)) {
5
- clone[i] = deepClone(obj[i]);
6
- } else {
7
- clone[i] = obj[i];
8
- }
9
- }
10
- return clone;
11
- }
12
-
13
- function getPointed(obj, kpointed, def) {
14
- const result = kpointed.split(".").reduce((o, k) => typeof (o) == 'object' ? o[k] : o, obj)
15
- return result === undefined ? def : result
16
- }
17
-
18
- function setPointed(obj, kpointed, val) {
19
- const arr = typeof kpointed == 'string' ? kpointed.split(".") : kpointed
20
- if (arr.length == 1) {
21
- obj[arr[0]] = val
22
- return obj
23
- }
24
- obj[arr[0]] = obj[arr[0]] || {}
25
- return setPointed(obj[arr[0]], arr.slice(1), val)
26
- }
27
-
28
- function filterObj(obj, kpointedArr) {
29
- return (kpointedArr || []).reduce((acc, kpointed) => {
30
- setPointed(acc, kpointed, getPointed(obj, kpointed))
31
- return acc
32
- }, {})
33
- }
34
- function diffObjs(obj1, obj2) {
35
- const a = deepClone(obj1)
36
- const b = deepClone(obj2)
37
- for (const i in b){
38
- if (JSON.stringify(a[i]) === JSON.stringify(b[i])){
39
- delete b[i]
40
- } else if (!Array.isArray(b[i]) && typeof b[i] == 'object') {
41
- b[i] = diffObjs(a[i], b[i])
42
- }
43
- }
44
- return b;
45
- }
46
-
47
- module.exports = {
48
- deepClone,
49
- getPointed,
50
- setPointed,
51
- filterObj,
52
- diffObjs
53
- }
package/index.js DELETED
@@ -1,11 +0,0 @@
1
- const auth = require('./helpers/auth');
2
- const debounce = require('./helpers/debounce');
3
- const formatters = require('./helpers/formatters');
4
- const objHelpers = require('./helpers/objHelpers');
5
-
6
- module.exports = {
7
- auth,
8
- debounce,
9
- formatters,
10
- objHelpers
11
- }
@@ -1 +0,0 @@
1
- module.exports = function (source, map) { this.callback(null, "export default function (Component) {}", map) }