@kopexa/shared-utils 15.0.0 → 17.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.js CHANGED
@@ -184,16 +184,19 @@ var parseShortcutKeys = (props) => {
184
184
 
185
185
  // src/text.ts
186
186
  var safeText = (text) => {
187
- if ((text == null ? void 0 : text.length) <= 2) return text;
188
- return text == null ? void 0 : text.slice(0, 2);
187
+ if (!text) return "";
188
+ if (text.length <= 2) return text.toUpperCase();
189
+ return text.slice(0, 2).toUpperCase();
189
190
  };
190
191
  var getInitials = (text) => {
191
192
  if (!text) return "";
192
193
  const words = text.split(" ");
193
- if (words.length === 1) {
194
- return safeText(text);
194
+ const validWords = words.filter((w) => /^[A-Za-z0-9]/.test(w));
195
+ if (validWords.length === 0) return "";
196
+ if (validWords.length === 1) {
197
+ return safeText(validWords[0]);
195
198
  }
196
- const initials = words.map((word) => word.charAt(0).toUpperCase());
199
+ const initials = validWords.map((word) => word.charAt(0).toUpperCase());
197
200
  if (initials.length > 2) {
198
201
  initials.length = 2;
199
202
  }
package/dist/index.mjs CHANGED
@@ -137,16 +137,19 @@ var parseShortcutKeys = (props) => {
137
137
 
138
138
  // src/text.ts
139
139
  var safeText = (text) => {
140
- if ((text == null ? void 0 : text.length) <= 2) return text;
141
- return text == null ? void 0 : text.slice(0, 2);
140
+ if (!text) return "";
141
+ if (text.length <= 2) return text.toUpperCase();
142
+ return text.slice(0, 2).toUpperCase();
142
143
  };
143
144
  var getInitials = (text) => {
144
145
  if (!text) return "";
145
146
  const words = text.split(" ");
146
- if (words.length === 1) {
147
- return safeText(text);
147
+ const validWords = words.filter((w) => /^[A-Za-z0-9]/.test(w));
148
+ if (validWords.length === 0) return "";
149
+ if (validWords.length === 1) {
150
+ return safeText(validWords[0]);
148
151
  }
149
- const initials = words.map((word) => word.charAt(0).toUpperCase());
152
+ const initials = validWords.map((word) => word.charAt(0).toUpperCase());
150
153
  if (initials.length > 2) {
151
154
  initials.length = 2;
152
155
  }
package/dist/text.js CHANGED
@@ -25,16 +25,19 @@ __export(text_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(text_exports);
27
27
  var safeText = (text) => {
28
- if ((text == null ? void 0 : text.length) <= 2) return text;
29
- return text == null ? void 0 : text.slice(0, 2);
28
+ if (!text) return "";
29
+ if (text.length <= 2) return text.toUpperCase();
30
+ return text.slice(0, 2).toUpperCase();
30
31
  };
31
32
  var getInitials = (text) => {
32
33
  if (!text) return "";
33
34
  const words = text.split(" ");
34
- if (words.length === 1) {
35
- return safeText(text);
35
+ const validWords = words.filter((w) => /^[A-Za-z0-9]/.test(w));
36
+ if (validWords.length === 0) return "";
37
+ if (validWords.length === 1) {
38
+ return safeText(validWords[0]);
36
39
  }
37
- const initials = words.map((word) => word.charAt(0).toUpperCase());
40
+ const initials = validWords.map((word) => word.charAt(0).toUpperCase());
38
41
  if (initials.length > 2) {
39
42
  initials.length = 2;
40
43
  }
package/dist/text.mjs CHANGED
@@ -1,15 +1,18 @@
1
1
  // src/text.ts
2
2
  var safeText = (text) => {
3
- if ((text == null ? void 0 : text.length) <= 2) return text;
4
- return text == null ? void 0 : text.slice(0, 2);
3
+ if (!text) return "";
4
+ if (text.length <= 2) return text.toUpperCase();
5
+ return text.slice(0, 2).toUpperCase();
5
6
  };
6
7
  var getInitials = (text) => {
7
8
  if (!text) return "";
8
9
  const words = text.split(" ");
9
- if (words.length === 1) {
10
- return safeText(text);
10
+ const validWords = words.filter((w) => /^[A-Za-z0-9]/.test(w));
11
+ if (validWords.length === 0) return "";
12
+ if (validWords.length === 1) {
13
+ return safeText(validWords[0]);
11
14
  }
12
- const initials = words.map((word) => word.charAt(0).toUpperCase());
15
+ const initials = validWords.map((word) => word.charAt(0).toUpperCase());
13
16
  if (initials.length > 2) {
14
17
  initials.length = 2;
15
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kopexa/shared-utils",
3
- "version": "15.0.0",
3
+ "version": "17.0.0",
4
4
  "description": "A set of kopexa shared utilities",
5
5
  "keywords": [
6
6
  "system"