minimal-shared 0.0.2

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 (120) hide show
  1. package/README.md +3 -0
  2. package/dist/hooks/index.d.ts +20 -0
  3. package/dist/hooks/index.js +19 -0
  4. package/dist/hooks/use-back-to-top/index.d.ts +2 -0
  5. package/dist/hooks/use-back-to-top/index.js +1 -0
  6. package/dist/hooks/use-back-to-top/use-back-to-top.d.ts +33 -0
  7. package/dist/hooks/use-back-to-top/use-back-to-top.js +64 -0
  8. package/dist/hooks/use-boolean/index.d.ts +2 -0
  9. package/dist/hooks/use-boolean/index.js +1 -0
  10. package/dist/hooks/use-boolean/use-boolean.d.ts +29 -0
  11. package/dist/hooks/use-boolean/use-boolean.js +24 -0
  12. package/dist/hooks/use-client-rect/index.d.ts +2 -0
  13. package/dist/hooks/use-client-rect/index.js +1 -0
  14. package/dist/hooks/use-client-rect/use-client-rect.d.ts +29 -0
  15. package/dist/hooks/use-client-rect/use-client-rect.js +47 -0
  16. package/dist/hooks/use-cookies/index.d.ts +1 -0
  17. package/dist/hooks/use-cookies/index.js +1 -0
  18. package/dist/hooks/use-cookies/use-cookies.d.ts +39 -0
  19. package/dist/hooks/use-cookies/use-cookies.js +110 -0
  20. package/dist/hooks/use-copy-to-clipboard/index.d.ts +1 -0
  21. package/dist/hooks/use-copy-to-clipboard/index.js +1 -0
  22. package/dist/hooks/use-copy-to-clipboard/use-copy-to-clipboard.d.ts +26 -0
  23. package/dist/hooks/use-copy-to-clipboard/use-copy-to-clipboard.js +27 -0
  24. package/dist/hooks/use-countdown-date/index.d.ts +1 -0
  25. package/dist/hooks/use-countdown-date/index.js +1 -0
  26. package/dist/hooks/use-countdown-date/use-countdown-date.d.ts +29 -0
  27. package/dist/hooks/use-countdown-date/use-countdown-date.js +41 -0
  28. package/dist/hooks/use-countdown-seconds/index.d.ts +2 -0
  29. package/dist/hooks/use-countdown-seconds/index.js +1 -0
  30. package/dist/hooks/use-countdown-seconds/use-countdown-seconds.d.ts +35 -0
  31. package/dist/hooks/use-countdown-seconds/use-countdown-seconds.js +36 -0
  32. package/dist/hooks/use-debounce/index.d.ts +1 -0
  33. package/dist/hooks/use-debounce/index.js +1 -0
  34. package/dist/hooks/use-debounce/use-debounce.d.ts +21 -0
  35. package/dist/hooks/use-debounce/use-debounce.js +17 -0
  36. package/dist/hooks/use-double-click/index.d.ts +2 -0
  37. package/dist/hooks/use-double-click/index.js +1 -0
  38. package/dist/hooks/use-double-click/use-double-click.d.ts +28 -0
  39. package/dist/hooks/use-double-click/use-double-click.js +33 -0
  40. package/dist/hooks/use-event-listener/index.d.ts +2 -0
  41. package/dist/hooks/use-event-listener/index.js +1 -0
  42. package/dist/hooks/use-event-listener/use-event-listener.d.ts +7 -0
  43. package/dist/hooks/use-event-listener/use-event-listener.js +23 -0
  44. package/dist/hooks/use-is-client/index.d.ts +1 -0
  45. package/dist/hooks/use-is-client/index.js +1 -0
  46. package/dist/hooks/use-is-client/use-is-client.d.ts +18 -0
  47. package/dist/hooks/use-is-client/use-is-client.js +12 -0
  48. package/dist/hooks/use-local-storage/index.d.ts +1 -0
  49. package/dist/hooks/use-local-storage/index.js +1 -0
  50. package/dist/hooks/use-local-storage/use-local-storage.d.ts +37 -0
  51. package/dist/hooks/use-local-storage/use-local-storage.js +113 -0
  52. package/dist/hooks/use-multi-select/index.d.ts +2 -0
  53. package/dist/hooks/use-multi-select/index.js +1 -0
  54. package/dist/hooks/use-multi-select/use-multi-select.d.ts +55 -0
  55. package/dist/hooks/use-multi-select/use-multi-select.js +36 -0
  56. package/dist/hooks/use-popover/index.d.ts +2 -0
  57. package/dist/hooks/use-popover/index.js +1 -0
  58. package/dist/hooks/use-popover/use-popover.d.ts +35 -0
  59. package/dist/hooks/use-popover/use-popover.js +21 -0
  60. package/dist/hooks/use-popover-hover/index.d.ts +2 -0
  61. package/dist/hooks/use-popover-hover/index.js +1 -0
  62. package/dist/hooks/use-popover-hover/use-popover-hover.d.ts +41 -0
  63. package/dist/hooks/use-popover-hover/use-popover-hover.js +24 -0
  64. package/dist/hooks/use-scroll-offset-top/index.d.ts +2 -0
  65. package/dist/hooks/use-scroll-offset-top/index.js +1 -0
  66. package/dist/hooks/use-scroll-offset-top/use-scroll-offset-top.d.ts +28 -0
  67. package/dist/hooks/use-scroll-offset-top/use-scroll-offset-top.js +29 -0
  68. package/dist/hooks/use-set-state/index.d.ts +1 -0
  69. package/dist/hooks/use-set-state/index.js +1 -0
  70. package/dist/hooks/use-set-state/use-set-state.d.ts +32 -0
  71. package/dist/hooks/use-set-state/use-set-state.js +26 -0
  72. package/dist/hooks/use-tabs/index.d.ts +2 -0
  73. package/dist/hooks/use-tabs/index.js +1 -0
  74. package/dist/hooks/use-tabs/use-tabs.d.ts +30 -0
  75. package/dist/hooks/use-tabs/use-tabs.js +16 -0
  76. package/dist/hooks/use-text-input/index.d.ts +2 -0
  77. package/dist/hooks/use-text-input/index.js +1 -0
  78. package/dist/hooks/use-text-input/use-text-input.d.ts +16 -0
  79. package/dist/hooks/use-text-input/use-text-input.js +16 -0
  80. package/dist/index.d.ts +29 -0
  81. package/dist/index.js +2 -0
  82. package/dist/utils/active-link/active-link.d.ts +16 -0
  83. package/dist/utils/active-link/active-link.js +43 -0
  84. package/dist/utils/active-link/index.d.ts +1 -0
  85. package/dist/utils/active-link/index.js +1 -0
  86. package/dist/utils/classes/classes.d.ts +25 -0
  87. package/dist/utils/classes/classes.js +14 -0
  88. package/dist/utils/classes/index.d.ts +1 -0
  89. package/dist/utils/classes/index.js +1 -0
  90. package/dist/utils/color/color.d.ts +67 -0
  91. package/dist/utils/color/color.js +47 -0
  92. package/dist/utils/color/index.d.ts +1 -0
  93. package/dist/utils/color/index.js +1 -0
  94. package/dist/utils/cookies/cookies.d.ts +34 -0
  95. package/dist/utils/cookies/cookies.js +46 -0
  96. package/dist/utils/cookies/index.d.ts +1 -0
  97. package/dist/utils/cookies/index.js +1 -0
  98. package/dist/utils/font/font.d.ts +37 -0
  99. package/dist/utils/font/font.js +20 -0
  100. package/dist/utils/font/index.d.ts +1 -0
  101. package/dist/utils/font/index.js +1 -0
  102. package/dist/utils/index.d.ts +9 -0
  103. package/dist/utils/index.js +17 -0
  104. package/dist/utils/local-storage/index.d.ts +1 -0
  105. package/dist/utils/local-storage/index.js +1 -0
  106. package/dist/utils/local-storage/local-storage.d.ts +55 -0
  107. package/dist/utils/local-storage/local-storage.js +51 -0
  108. package/dist/utils/object/index.d.ts +1 -0
  109. package/dist/utils/object/index.js +1 -0
  110. package/dist/utils/object/object.d.ts +26 -0
  111. package/dist/utils/object/object.js +10 -0
  112. package/dist/utils/url/index.d.ts +1 -0
  113. package/dist/utils/url/index.js +1 -0
  114. package/dist/utils/url/url.d.ts +46 -0
  115. package/dist/utils/url/url.js +28 -0
  116. package/dist/utils/uuidv4/index.d.ts +1 -0
  117. package/dist/utils/uuidv4/index.js +1 -0
  118. package/dist/utils/uuidv4/uuidv4.d.ts +12 -0
  119. package/dist/utils/uuidv4/uuidv4.js +11 -0
  120. package/package.json +87 -0
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Retrieves a value from local storage by key.
3
+ *
4
+ * @param {string} key - The key of the item to retrieve.
5
+ * @returns {any | null} - The parsed value of the item, or null if not found or an error occurs.
6
+ *
7
+ * @example
8
+ * const user = getStorage('user');
9
+ * console.log(user); // { name: 'John', age: 30 }
10
+ */
11
+ declare function getStorage(key: string): any | null;
12
+ /**
13
+ * Sets a value in local storage with a specified key.
14
+ *
15
+ * @template T
16
+ * @param {string} key - The key of the item to set.
17
+ * @param {T} value - The value of the item to set.
18
+ *
19
+ * @example
20
+ * setStorage('user', { name: 'John', age: 30 });
21
+ */
22
+ declare function setStorage<T>(key: string, value: T): void;
23
+ /**
24
+ * Removes an item from local storage by key.
25
+ *
26
+ * @param {string} key - The key of the item to remove.
27
+ *
28
+ * @example
29
+ * removeStorage('user');
30
+ */
31
+ declare function removeStorage(key: string): void;
32
+ /**
33
+ * Checks if local storage is available.
34
+ *
35
+ * @returns {boolean} - True if local storage is available, false otherwise.
36
+ *
37
+ * @example
38
+ * const isAvailable = localStorageAvailable();
39
+ * console.log(isAvailable); // true or false
40
+ */
41
+ declare function localStorageAvailable(): boolean;
42
+ /**
43
+ * Retrieves a value from local storage by key, with an optional default value.
44
+ *
45
+ * @param {string} key - The key of the item to retrieve.
46
+ * @param {string} [defaultValue=''] - The default value to return if the item is not found.
47
+ * @returns {string | undefined} - The value of the item, or the default value if not found.
48
+ *
49
+ * @example
50
+ * const value = localStorageGetItem('theme', 'light');
51
+ * console.log(value); // 'dark' or 'light'
52
+ */
53
+ declare function localStorageGetItem(key: string, defaultValue?: string): string | undefined;
54
+
55
+ export { getStorage, localStorageAvailable, localStorageGetItem, removeStorage, setStorage };
@@ -0,0 +1,51 @@
1
+ // src/utils/local-storage/local-storage.ts
2
+ function getStorage(key) {
3
+ const storedValue = localStorageGetItem(key);
4
+ if (storedValue) {
5
+ try {
6
+ return JSON.parse(storedValue);
7
+ } catch {
8
+ return storedValue;
9
+ }
10
+ }
11
+ return null;
12
+ }
13
+ function setStorage(key, value) {
14
+ try {
15
+ const serializedValue = JSON.stringify(value);
16
+ window.localStorage.setItem(key, serializedValue);
17
+ } catch (error) {
18
+ console.error("Error while setting storage:", error);
19
+ }
20
+ }
21
+ function removeStorage(key) {
22
+ try {
23
+ window.localStorage.removeItem(key);
24
+ } catch (error) {
25
+ console.error("Error while removing from storage:", error);
26
+ }
27
+ }
28
+ function localStorageAvailable() {
29
+ try {
30
+ const key = "__some_random_key_you_are_not_going_to_use__";
31
+ window.localStorage.setItem(key, key);
32
+ window.localStorage.removeItem(key);
33
+ return true;
34
+ } catch {
35
+ return false;
36
+ }
37
+ }
38
+ function localStorageGetItem(key, defaultValue = "") {
39
+ if (!localStorageAvailable()) {
40
+ return defaultValue;
41
+ }
42
+ const value = localStorage.getItem(key);
43
+ return value ?? defaultValue;
44
+ }
45
+ export {
46
+ getStorage,
47
+ localStorageAvailable,
48
+ localStorageGetItem,
49
+ removeStorage,
50
+ setStorage
51
+ };
@@ -0,0 +1 @@
1
+ export { hasKeys } from './object.js';
@@ -0,0 +1 @@
1
+ export * from './object';
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Checks if the given object contains all the specified keys.
3
+ *
4
+ * @template T - The type of the object.
5
+ * @param {T} obj - The object to check.
6
+ * @param {Array<keyof T>} keys - An array of keys to check for in the object.
7
+ * @returns {boolean} - Returns true if the object contains all the specified keys, otherwise false.
8
+ *
9
+ * @example
10
+ * const settings = {
11
+ * fontFamily: 'Arial',
12
+ * compactLayout: true,
13
+ * direction: 'ltr',
14
+ * colorScheme: 'light',
15
+ * contrast: 'default',
16
+ * navColor: 'integrate',
17
+ * navLayout: 'vertical',
18
+ * primaryColor: 'blue',
19
+ *};
20
+ *
21
+ * console.log(hasKeys(settings, ['fontFamily', 'direction'])); // true
22
+ * console.log(hasKeys(settings, ['test'])); // false
23
+ */
24
+ declare function hasKeys<T>(obj: T | null | undefined, keys: (keyof T | string)[]): boolean;
25
+
26
+ export { hasKeys };
@@ -0,0 +1,10 @@
1
+ // src/utils/object/object.ts
2
+ function hasKeys(obj, keys) {
3
+ if (!obj || !keys.length || typeof obj !== "object") {
4
+ return false;
5
+ }
6
+ return keys.every((key) => key in obj);
7
+ }
8
+ export {
9
+ hasKeys
10
+ };
@@ -0,0 +1 @@
1
+ export { hasParams, isExternalLink, removeLastSlash, removeParams } from './url.js';
@@ -0,0 +1 @@
1
+ export * from './url';
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Checks if a URL has query parameters.
3
+ *
4
+ * @param {string} url - The URL to check.
5
+ * @returns {boolean} - True if the URL has query parameters, false otherwise.
6
+ *
7
+ * @example
8
+ * const hasQueryParams = hasParams('https://example.com?page=1');
9
+ * console.log(hasQueryParams); // true
10
+ */
11
+ declare const hasParams: (url: string) => boolean;
12
+ /**
13
+ * Removes the trailing slash from a pathname if it exists.
14
+ *
15
+ * @param {string} pathname - The pathname to process.
16
+ * @returns {string} - The pathname without the trailing slash.
17
+ *
18
+ * @example
19
+ * const cleanPathname = removeLastSlash('/dashboard/calendar/');
20
+ * console.log(cleanPathname); // '/dashboard/calendar'
21
+ */
22
+ declare function removeLastSlash(pathname: string): string;
23
+ /**
24
+ * Removes query parameters from a URL.
25
+ *
26
+ * @param {string} url - The URL to process.
27
+ * @returns {string} - The URL without query parameters.
28
+ *
29
+ * @example
30
+ * const cleanUrl = removeParams('https://example.com/page?param=value');
31
+ * console.log(cleanUrl); // 'https://example.com/page'
32
+ */
33
+ declare function removeParams(url: string): string;
34
+ /**
35
+ * Checks if a URL is an external link.
36
+ *
37
+ * @param {string} url - The URL to check.
38
+ * @returns {boolean} - True if the URL is an external link, false otherwise.
39
+ *
40
+ * @example
41
+ * const isExternal = isExternalLink('https://example.com');
42
+ * console.log(isExternal); // true
43
+ */
44
+ declare function isExternalLink(url: string): boolean;
45
+
46
+ export { hasParams, isExternalLink, removeLastSlash, removeParams };
@@ -0,0 +1,28 @@
1
+ // src/utils/url/url.ts
2
+ var hasParams = (url) => {
3
+ const queryString = url.split("?")[1];
4
+ return queryString ? new URLSearchParams(queryString).toString().length > 0 : false;
5
+ };
6
+ function removeLastSlash(pathname) {
7
+ if (pathname !== "/" && pathname.endsWith("/")) {
8
+ return pathname.slice(0, -1);
9
+ }
10
+ return pathname;
11
+ }
12
+ function removeParams(url) {
13
+ try {
14
+ const urlObj = new URL(url, window.location.origin);
15
+ return removeLastSlash(urlObj.pathname);
16
+ } catch {
17
+ return url;
18
+ }
19
+ }
20
+ function isExternalLink(url) {
21
+ return url.startsWith("http");
22
+ }
23
+ export {
24
+ hasParams,
25
+ isExternalLink,
26
+ removeLastSlash,
27
+ removeParams
28
+ };
@@ -0,0 +1 @@
1
+ export { uuidv4 } from './uuidv4.js';
@@ -0,0 +1 @@
1
+ export * from './uuidv4';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Generates a UUID (version 4).
3
+ *
4
+ * @returns {string} - A randomly generated UUID.
5
+ *
6
+ * @example
7
+ * const id = uuidv4();
8
+ * console.log(id); // '3b12f1df-1c3a-4f3b-8f3d-3f3b1c3a4f3b'
9
+ */
10
+ declare function uuidv4(): string;
11
+
12
+ export { uuidv4 };
@@ -0,0 +1,11 @@
1
+ // src/utils/uuidv4/uuidv4.ts
2
+ function uuidv4() {
3
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
4
+ const r = Math.random() * 16 | 0;
5
+ const v = c === "x" ? r : r & 3 | 8;
6
+ return v.toString(16);
7
+ });
8
+ }
9
+ export {
10
+ uuidv4
11
+ };
package/package.json ADDED
@@ -0,0 +1,87 @@
1
+ {
2
+ "name": "minimal-shared",
3
+ "author": "Minimals",
4
+ "version": "0.0.2",
5
+ "description": "Shared hooks and utils used by Mnimal UI and Zone UI.",
6
+ "keywords": [
7
+ "typescript",
8
+ "react",
9
+ "hooks",
10
+ "utils"
11
+ ],
12
+ "license": "MIT",
13
+ "sideEffects": false,
14
+ "type": "module",
15
+ "types": "./dist/index.d.ts",
16
+ "main": "./dist/index.js",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "typesVersions": {
21
+ "*": {
22
+ "*": [
23
+ "./dist/*",
24
+ "./dist/*/index"
25
+ ]
26
+ }
27
+ },
28
+ "exports": {
29
+ "./package.json": "./package.json",
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "default": "./dist/index.js"
33
+ },
34
+ "./hooks": {
35
+ "types": "./dist/hooks/index.d.ts",
36
+ "default": "./dist/hooks/index.js"
37
+ },
38
+ "./hooks/*": {
39
+ "types": "./dist/hooks/*/index.d.ts",
40
+ "default": "./dist/hooks/*/index.js"
41
+ },
42
+ "./utils": {
43
+ "types": "./dist/utils/index.d.ts",
44
+ "default": "./dist/utils/index.js"
45
+ },
46
+ "./utils/*": {
47
+ "types": "./dist/utils/*/index.d.ts",
48
+ "default": "./dist/utils/*/index.js"
49
+ }
50
+ },
51
+ "scripts": {
52
+ "dev": "NODE_OPTIONS='--max-old-space-size=16384' tsup --watch",
53
+ "build": "NODE_OPTIONS='--max-old-space-size=16384' tsup",
54
+ "test": "vitest run",
55
+ "test:watch": "vitest",
56
+ "lint": "eslint \"**/*.{js,jsx,ts,tsx}\"",
57
+ "lint:fix": "eslint --fix \"**/*.{js,jsx,ts,tsx}\"",
58
+ "lint:print": "npx eslint --print-config eslint.config.mjs > eslint-current-config.json",
59
+ "clean": "rm -rf node_modules .turbo .next out dist build",
60
+ "re:build": "pnpm clean && pnpm install && pnpm build",
61
+ "tsc:print": "npx tsc --showConfig"
62
+ },
63
+ "dependencies": {
64
+ "es-toolkit": "^1.26.1"
65
+ },
66
+ "devDependencies": {
67
+ "@testing-library/jest-dom": "^6.6.3",
68
+ "@testing-library/react": "^16.0.1",
69
+ "@types/fs-extra": "^11.0.4",
70
+ "@types/node": "^22.8.6",
71
+ "@types/react": "18.3.12",
72
+ "chalk": "^5.3.0",
73
+ "fast-glob": "^3.3.2",
74
+ "fs-extra": "^11.2.0",
75
+ "glob": "^11.0.0",
76
+ "internal-eslint-config": "workspace:*",
77
+ "internal-ts-config": "workspace:*",
78
+ "jsdom": "^25.0.1",
79
+ "react": "^18.3.1",
80
+ "tsup": "^8.3.5",
81
+ "typescript": "^5.5.4",
82
+ "vitest": "^2.1.4"
83
+ },
84
+ "peerDependencies": {
85
+ "react": "^17 || ^18"
86
+ }
87
+ }