@kopexa/shared-utils 1.1.6 → 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 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;
@@ -148,10 +185,14 @@ var getInitials = (text) => {
148
185
  return safeText(text);
149
186
  }
150
187
  const initials = words.map((word) => word.charAt(0).toUpperCase());
188
+ if (initials.length > 2) {
189
+ initials.length = 2;
190
+ }
151
191
  return initials.join("");
152
192
  };
153
193
  // Annotate the CommonJS export names for ESM import in node:
154
194
  0 && (module.exports = {
195
+ MAC_SYMBOLS,
155
196
  ariaAttr,
156
197
  callAllHandlers,
157
198
  chain,
@@ -159,14 +200,17 @@ var getInitials = (text) => {
159
200
  cn,
160
201
  compact,
161
202
  dataAttr,
203
+ formatShortcutKey,
162
204
  getInitials,
163
205
  getUniqueID,
164
206
  isArray,
165
207
  isEmpty,
166
208
  isEmptyArray,
167
209
  isEmptyObject,
210
+ isMac,
168
211
  isObject,
169
212
  mapPropsVariants,
170
213
  objectToDeps,
214
+ parseShortcutKeys,
171
215
  safeText
172
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;
@@ -106,9 +139,13 @@ var getInitials = (text) => {
106
139
  return safeText(text);
107
140
  }
108
141
  const initials = words.map((word) => word.charAt(0).toUpperCase());
142
+ if (initials.length > 2) {
143
+ initials.length = 2;
144
+ }
109
145
  return initials.join("");
110
146
  };
111
147
  export {
148
+ MAC_SYMBOLS,
112
149
  ariaAttr,
113
150
  callAllHandlers,
114
151
  chain,
@@ -116,14 +153,17 @@ export {
116
153
  cn,
117
154
  compact,
118
155
  dataAttr,
156
+ formatShortcutKey,
119
157
  getInitials,
120
158
  getUniqueID,
121
159
  isArray,
122
160
  isEmpty,
123
161
  isEmptyArray,
124
162
  isEmptyObject,
163
+ isMac,
125
164
  isObject,
126
165
  mapPropsVariants,
127
166
  objectToDeps,
167
+ parseShortcutKeys,
128
168
  safeText
129
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 };
@@ -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
+ });
@@ -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
+ };
package/dist/text.js CHANGED
@@ -35,6 +35,9 @@ var getInitials = (text) => {
35
35
  return safeText(text);
36
36
  }
37
37
  const initials = words.map((word) => word.charAt(0).toUpperCase());
38
+ if (initials.length > 2) {
39
+ initials.length = 2;
40
+ }
38
41
  return initials.join("");
39
42
  };
40
43
  // Annotate the CommonJS export names for ESM import in node:
package/dist/text.mjs CHANGED
@@ -10,6 +10,9 @@ var getInitials = (text) => {
10
10
  return safeText(text);
11
11
  }
12
12
  const initials = words.map((word) => word.charAt(0).toUpperCase());
13
+ if (initials.length > 2) {
14
+ initials.length = 2;
15
+ }
13
16
  return initials.join("");
14
17
  };
15
18
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kopexa/shared-utils",
3
- "version": "1.1.6",
3
+ "version": "2.0.0",
4
4
  "description": "A set of kopexa shared utilities",
5
5
  "keywords": [
6
6
  "system"