@kopexa/shared-utils 1.1.7 → 2.0.0
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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +41 -0
- package/dist/index.mjs +37 -0
- package/dist/system.d.mts +28 -0
- package/dist/system.d.ts +28 -0
- package/dist/system.js +66 -0
- package/dist/system.mjs +38 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -4,5 +4,6 @@ export { callAllHandlers, getUniqueID } from './functions.mjs';
|
|
|
4
4
|
export { clamp } from './numbers.mjs';
|
|
5
5
|
export { compact, mapPropsVariants, objectToDeps } from './object.mjs';
|
|
6
6
|
export { chain } from './ra.mjs';
|
|
7
|
+
export { MAC_SYMBOLS, formatShortcutKey, isMac, parseShortcutKeys } from './system.mjs';
|
|
7
8
|
export { getInitials, safeText } from './text.mjs';
|
|
8
9
|
import 'clsx';
|
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ export { callAllHandlers, getUniqueID } from './functions.js';
|
|
|
4
4
|
export { clamp } from './numbers.js';
|
|
5
5
|
export { compact, mapPropsVariants, objectToDeps } from './object.js';
|
|
6
6
|
export { chain } from './ra.js';
|
|
7
|
+
export { MAC_SYMBOLS, formatShortcutKey, isMac, parseShortcutKeys } from './system.js';
|
|
7
8
|
export { getInitials, safeText } from './text.js';
|
|
8
9
|
import 'clsx';
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
MAC_SYMBOLS: () => MAC_SYMBOLS,
|
|
23
24
|
ariaAttr: () => ariaAttr,
|
|
24
25
|
callAllHandlers: () => callAllHandlers,
|
|
25
26
|
chain: () => chain,
|
|
@@ -27,15 +28,18 @@ __export(index_exports, {
|
|
|
27
28
|
cn: () => cn,
|
|
28
29
|
compact: () => compact,
|
|
29
30
|
dataAttr: () => dataAttr,
|
|
31
|
+
formatShortcutKey: () => formatShortcutKey,
|
|
30
32
|
getInitials: () => getInitials,
|
|
31
33
|
getUniqueID: () => getUniqueID,
|
|
32
34
|
isArray: () => isArray,
|
|
33
35
|
isEmpty: () => isEmpty,
|
|
34
36
|
isEmptyArray: () => isEmptyArray,
|
|
35
37
|
isEmptyObject: () => isEmptyObject,
|
|
38
|
+
isMac: () => isMac,
|
|
36
39
|
isObject: () => isObject,
|
|
37
40
|
mapPropsVariants: () => mapPropsVariants,
|
|
38
41
|
objectToDeps: () => objectToDeps,
|
|
42
|
+
parseShortcutKeys: () => parseShortcutKeys,
|
|
39
43
|
safeText: () => safeText
|
|
40
44
|
});
|
|
41
45
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -136,6 +140,39 @@ function chain(...callbacks) {
|
|
|
136
140
|
};
|
|
137
141
|
}
|
|
138
142
|
|
|
143
|
+
// src/system.ts
|
|
144
|
+
function isMac() {
|
|
145
|
+
var _a;
|
|
146
|
+
return (_a = navigator == null ? void 0 : navigator.platform) == null ? void 0 : _a.toLowerCase().includes("mac");
|
|
147
|
+
}
|
|
148
|
+
var MAC_SYMBOLS = {
|
|
149
|
+
mod: "\u2318",
|
|
150
|
+
command: "\u2318",
|
|
151
|
+
meta: "\u2318",
|
|
152
|
+
ctrl: "\u2303",
|
|
153
|
+
control: "\u2303",
|
|
154
|
+
alt: "\u2325",
|
|
155
|
+
option: "\u2325",
|
|
156
|
+
shift: "\u21E7",
|
|
157
|
+
backspace: "Del",
|
|
158
|
+
delete: "\u2326",
|
|
159
|
+
enter: "\u23CE",
|
|
160
|
+
escape: "\u238B",
|
|
161
|
+
capslock: "\u21EA"
|
|
162
|
+
};
|
|
163
|
+
var formatShortcutKey = (key, isMac2, capitalize = true) => {
|
|
164
|
+
if (isMac2) {
|
|
165
|
+
const lowerKey = key.toLowerCase();
|
|
166
|
+
return MAC_SYMBOLS[lowerKey] || (capitalize ? key.toUpperCase() : key);
|
|
167
|
+
}
|
|
168
|
+
return capitalize ? key.charAt(0).toUpperCase() + key.slice(1) : key;
|
|
169
|
+
};
|
|
170
|
+
var parseShortcutKeys = (props) => {
|
|
171
|
+
const { shortcutKeys, delimiter = "+", capitalize = true } = props;
|
|
172
|
+
if (!shortcutKeys) return [];
|
|
173
|
+
return shortcutKeys.split(delimiter).map((key) => key.trim()).map((key) => formatShortcutKey(key, isMac(), capitalize));
|
|
174
|
+
};
|
|
175
|
+
|
|
139
176
|
// src/text.ts
|
|
140
177
|
var safeText = (text) => {
|
|
141
178
|
if ((text == null ? void 0 : text.length) <= 2) return text;
|
|
@@ -155,6 +192,7 @@ var getInitials = (text) => {
|
|
|
155
192
|
};
|
|
156
193
|
// Annotate the CommonJS export names for ESM import in node:
|
|
157
194
|
0 && (module.exports = {
|
|
195
|
+
MAC_SYMBOLS,
|
|
158
196
|
ariaAttr,
|
|
159
197
|
callAllHandlers,
|
|
160
198
|
chain,
|
|
@@ -162,14 +200,17 @@ var getInitials = (text) => {
|
|
|
162
200
|
cn,
|
|
163
201
|
compact,
|
|
164
202
|
dataAttr,
|
|
203
|
+
formatShortcutKey,
|
|
165
204
|
getInitials,
|
|
166
205
|
getUniqueID,
|
|
167
206
|
isArray,
|
|
168
207
|
isEmpty,
|
|
169
208
|
isEmptyArray,
|
|
170
209
|
isEmptyObject,
|
|
210
|
+
isMac,
|
|
171
211
|
isObject,
|
|
172
212
|
mapPropsVariants,
|
|
173
213
|
objectToDeps,
|
|
214
|
+
parseShortcutKeys,
|
|
174
215
|
safeText
|
|
175
216
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -94,6 +94,39 @@ function chain(...callbacks) {
|
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
// src/system.ts
|
|
98
|
+
function isMac() {
|
|
99
|
+
var _a;
|
|
100
|
+
return (_a = navigator == null ? void 0 : navigator.platform) == null ? void 0 : _a.toLowerCase().includes("mac");
|
|
101
|
+
}
|
|
102
|
+
var MAC_SYMBOLS = {
|
|
103
|
+
mod: "\u2318",
|
|
104
|
+
command: "\u2318",
|
|
105
|
+
meta: "\u2318",
|
|
106
|
+
ctrl: "\u2303",
|
|
107
|
+
control: "\u2303",
|
|
108
|
+
alt: "\u2325",
|
|
109
|
+
option: "\u2325",
|
|
110
|
+
shift: "\u21E7",
|
|
111
|
+
backspace: "Del",
|
|
112
|
+
delete: "\u2326",
|
|
113
|
+
enter: "\u23CE",
|
|
114
|
+
escape: "\u238B",
|
|
115
|
+
capslock: "\u21EA"
|
|
116
|
+
};
|
|
117
|
+
var formatShortcutKey = (key, isMac2, capitalize = true) => {
|
|
118
|
+
if (isMac2) {
|
|
119
|
+
const lowerKey = key.toLowerCase();
|
|
120
|
+
return MAC_SYMBOLS[lowerKey] || (capitalize ? key.toUpperCase() : key);
|
|
121
|
+
}
|
|
122
|
+
return capitalize ? key.charAt(0).toUpperCase() + key.slice(1) : key;
|
|
123
|
+
};
|
|
124
|
+
var parseShortcutKeys = (props) => {
|
|
125
|
+
const { shortcutKeys, delimiter = "+", capitalize = true } = props;
|
|
126
|
+
if (!shortcutKeys) return [];
|
|
127
|
+
return shortcutKeys.split(delimiter).map((key) => key.trim()).map((key) => formatShortcutKey(key, isMac(), capitalize));
|
|
128
|
+
};
|
|
129
|
+
|
|
97
130
|
// src/text.ts
|
|
98
131
|
var safeText = (text) => {
|
|
99
132
|
if ((text == null ? void 0 : text.length) <= 2) return text;
|
|
@@ -112,6 +145,7 @@ var getInitials = (text) => {
|
|
|
112
145
|
return initials.join("");
|
|
113
146
|
};
|
|
114
147
|
export {
|
|
148
|
+
MAC_SYMBOLS,
|
|
115
149
|
ariaAttr,
|
|
116
150
|
callAllHandlers,
|
|
117
151
|
chain,
|
|
@@ -119,14 +153,17 @@ export {
|
|
|
119
153
|
cn,
|
|
120
154
|
compact,
|
|
121
155
|
dataAttr,
|
|
156
|
+
formatShortcutKey,
|
|
122
157
|
getInitials,
|
|
123
158
|
getUniqueID,
|
|
124
159
|
isArray,
|
|
125
160
|
isEmpty,
|
|
126
161
|
isEmptyArray,
|
|
127
162
|
isEmptyObject,
|
|
163
|
+
isMac,
|
|
128
164
|
isObject,
|
|
129
165
|
mapPropsVariants,
|
|
130
166
|
objectToDeps,
|
|
167
|
+
parseShortcutKeys,
|
|
131
168
|
safeText
|
|
132
169
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if the current platform is macOS
|
|
3
|
+
* @returns boolean indicating if the current platform is Mac
|
|
4
|
+
*/
|
|
5
|
+
declare function isMac(): boolean;
|
|
6
|
+
declare const MAC_SYMBOLS: Record<string, string>;
|
|
7
|
+
/**
|
|
8
|
+
* Formats a shortcut key based on the platform (Mac or non-Mac)
|
|
9
|
+
* @param key - The key to format (e.g., "ctrl", "alt", "shift")
|
|
10
|
+
* @param isMac - Boolean indicating if the platform is Mac
|
|
11
|
+
* @param capitalize - Whether to capitalize the key (default: true)
|
|
12
|
+
* @returns Formatted shortcut key symbol
|
|
13
|
+
*/
|
|
14
|
+
declare const formatShortcutKey: (key: string, isMac: boolean, capitalize?: boolean) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Parses a shortcut key string into an array of formatted key symbols
|
|
17
|
+
* @param shortcutKeys - The string of shortcut keys (e.g., "ctrl-alt-shift")
|
|
18
|
+
* @param delimiter - The delimiter used to split the keys (default: "-")
|
|
19
|
+
* @param capitalize - Whether to capitalize the keys (default: true)
|
|
20
|
+
* @returns Array of formatted shortcut key symbols
|
|
21
|
+
*/
|
|
22
|
+
declare const parseShortcutKeys: (props: {
|
|
23
|
+
shortcutKeys: string | undefined;
|
|
24
|
+
delimiter?: string;
|
|
25
|
+
capitalize?: boolean;
|
|
26
|
+
}) => string[];
|
|
27
|
+
|
|
28
|
+
export { MAC_SYMBOLS, formatShortcutKey, isMac, parseShortcutKeys };
|
package/dist/system.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if the current platform is macOS
|
|
3
|
+
* @returns boolean indicating if the current platform is Mac
|
|
4
|
+
*/
|
|
5
|
+
declare function isMac(): boolean;
|
|
6
|
+
declare const MAC_SYMBOLS: Record<string, string>;
|
|
7
|
+
/**
|
|
8
|
+
* Formats a shortcut key based on the platform (Mac or non-Mac)
|
|
9
|
+
* @param key - The key to format (e.g., "ctrl", "alt", "shift")
|
|
10
|
+
* @param isMac - Boolean indicating if the platform is Mac
|
|
11
|
+
* @param capitalize - Whether to capitalize the key (default: true)
|
|
12
|
+
* @returns Formatted shortcut key symbol
|
|
13
|
+
*/
|
|
14
|
+
declare const formatShortcutKey: (key: string, isMac: boolean, capitalize?: boolean) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Parses a shortcut key string into an array of formatted key symbols
|
|
17
|
+
* @param shortcutKeys - The string of shortcut keys (e.g., "ctrl-alt-shift")
|
|
18
|
+
* @param delimiter - The delimiter used to split the keys (default: "-")
|
|
19
|
+
* @param capitalize - Whether to capitalize the keys (default: true)
|
|
20
|
+
* @returns Array of formatted shortcut key symbols
|
|
21
|
+
*/
|
|
22
|
+
declare const parseShortcutKeys: (props: {
|
|
23
|
+
shortcutKeys: string | undefined;
|
|
24
|
+
delimiter?: string;
|
|
25
|
+
capitalize?: boolean;
|
|
26
|
+
}) => string[];
|
|
27
|
+
|
|
28
|
+
export { MAC_SYMBOLS, formatShortcutKey, isMac, parseShortcutKeys };
|
package/dist/system.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/system.ts
|
|
21
|
+
var system_exports = {};
|
|
22
|
+
__export(system_exports, {
|
|
23
|
+
MAC_SYMBOLS: () => MAC_SYMBOLS,
|
|
24
|
+
formatShortcutKey: () => formatShortcutKey,
|
|
25
|
+
isMac: () => isMac,
|
|
26
|
+
parseShortcutKeys: () => parseShortcutKeys
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(system_exports);
|
|
29
|
+
function isMac() {
|
|
30
|
+
var _a;
|
|
31
|
+
return (_a = navigator == null ? void 0 : navigator.platform) == null ? void 0 : _a.toLowerCase().includes("mac");
|
|
32
|
+
}
|
|
33
|
+
var MAC_SYMBOLS = {
|
|
34
|
+
mod: "\u2318",
|
|
35
|
+
command: "\u2318",
|
|
36
|
+
meta: "\u2318",
|
|
37
|
+
ctrl: "\u2303",
|
|
38
|
+
control: "\u2303",
|
|
39
|
+
alt: "\u2325",
|
|
40
|
+
option: "\u2325",
|
|
41
|
+
shift: "\u21E7",
|
|
42
|
+
backspace: "Del",
|
|
43
|
+
delete: "\u2326",
|
|
44
|
+
enter: "\u23CE",
|
|
45
|
+
escape: "\u238B",
|
|
46
|
+
capslock: "\u21EA"
|
|
47
|
+
};
|
|
48
|
+
var formatShortcutKey = (key, isMac2, capitalize = true) => {
|
|
49
|
+
if (isMac2) {
|
|
50
|
+
const lowerKey = key.toLowerCase();
|
|
51
|
+
return MAC_SYMBOLS[lowerKey] || (capitalize ? key.toUpperCase() : key);
|
|
52
|
+
}
|
|
53
|
+
return capitalize ? key.charAt(0).toUpperCase() + key.slice(1) : key;
|
|
54
|
+
};
|
|
55
|
+
var parseShortcutKeys = (props) => {
|
|
56
|
+
const { shortcutKeys, delimiter = "+", capitalize = true } = props;
|
|
57
|
+
if (!shortcutKeys) return [];
|
|
58
|
+
return shortcutKeys.split(delimiter).map((key) => key.trim()).map((key) => formatShortcutKey(key, isMac(), capitalize));
|
|
59
|
+
};
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
MAC_SYMBOLS,
|
|
63
|
+
formatShortcutKey,
|
|
64
|
+
isMac,
|
|
65
|
+
parseShortcutKeys
|
|
66
|
+
});
|
package/dist/system.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/system.ts
|
|
2
|
+
function isMac() {
|
|
3
|
+
var _a;
|
|
4
|
+
return (_a = navigator == null ? void 0 : navigator.platform) == null ? void 0 : _a.toLowerCase().includes("mac");
|
|
5
|
+
}
|
|
6
|
+
var MAC_SYMBOLS = {
|
|
7
|
+
mod: "\u2318",
|
|
8
|
+
command: "\u2318",
|
|
9
|
+
meta: "\u2318",
|
|
10
|
+
ctrl: "\u2303",
|
|
11
|
+
control: "\u2303",
|
|
12
|
+
alt: "\u2325",
|
|
13
|
+
option: "\u2325",
|
|
14
|
+
shift: "\u21E7",
|
|
15
|
+
backspace: "Del",
|
|
16
|
+
delete: "\u2326",
|
|
17
|
+
enter: "\u23CE",
|
|
18
|
+
escape: "\u238B",
|
|
19
|
+
capslock: "\u21EA"
|
|
20
|
+
};
|
|
21
|
+
var formatShortcutKey = (key, isMac2, capitalize = true) => {
|
|
22
|
+
if (isMac2) {
|
|
23
|
+
const lowerKey = key.toLowerCase();
|
|
24
|
+
return MAC_SYMBOLS[lowerKey] || (capitalize ? key.toUpperCase() : key);
|
|
25
|
+
}
|
|
26
|
+
return capitalize ? key.charAt(0).toUpperCase() + key.slice(1) : key;
|
|
27
|
+
};
|
|
28
|
+
var parseShortcutKeys = (props) => {
|
|
29
|
+
const { shortcutKeys, delimiter = "+", capitalize = true } = props;
|
|
30
|
+
if (!shortcutKeys) return [];
|
|
31
|
+
return shortcutKeys.split(delimiter).map((key) => key.trim()).map((key) => formatShortcutKey(key, isMac(), capitalize));
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
MAC_SYMBOLS,
|
|
35
|
+
formatShortcutKey,
|
|
36
|
+
isMac,
|
|
37
|
+
parseShortcutKeys
|
|
38
|
+
};
|