@sankhyalabs/core 5.11.6 → 5.12.0-dev.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 (61) hide show
  1. package/.docs/classes/JSUtils.md +30 -3
  2. package/.docs/classes/KeyboardManager.md +233 -0
  3. package/.docs/classes/StringUtils.md +76 -1
  4. package/.docs/modules.md +1 -0
  5. package/dist/index.d.ts +2 -1
  6. package/dist/index.js +2 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/utils/JSUtils.d.ts +9 -0
  9. package/dist/utils/JSUtils.js +20 -0
  10. package/dist/utils/JSUtils.js.map +1 -1
  11. package/dist/utils/KeyboardManager/constants/meta-keys.d.ts +2 -0
  12. package/dist/utils/KeyboardManager/constants/meta-keys.js +7 -0
  13. package/dist/utils/KeyboardManager/constants/meta-keys.js.map +1 -0
  14. package/dist/utils/KeyboardManager/index.d.ts +69 -0
  15. package/dist/utils/KeyboardManager/index.js +156 -0
  16. package/dist/utils/KeyboardManager/index.js.map +1 -0
  17. package/dist/utils/KeyboardManager/interface.d.ts +20 -0
  18. package/dist/utils/KeyboardManager/interface.js +2 -0
  19. package/dist/utils/KeyboardManager/interface.js.map +1 -0
  20. package/dist/utils/KeyboardManager/keyCodes/android.d.ts +2 -0
  21. package/dist/utils/KeyboardManager/keyCodes/android.js +83 -0
  22. package/dist/utils/KeyboardManager/keyCodes/android.js.map +1 -0
  23. package/dist/utils/KeyboardManager/keyCodes/dead.d.ts +16 -0
  24. package/dist/utils/KeyboardManager/keyCodes/dead.js +14 -0
  25. package/dist/utils/KeyboardManager/keyCodes/dead.js.map +1 -0
  26. package/dist/utils/KeyboardManager/keyCodes/index.d.ts +1 -0
  27. package/dist/utils/KeyboardManager/keyCodes/index.js +11 -0
  28. package/dist/utils/KeyboardManager/keyCodes/index.js.map +1 -0
  29. package/dist/utils/KeyboardManager/keyCodes/meta.d.ts +16 -0
  30. package/dist/utils/KeyboardManager/keyCodes/meta.js +18 -0
  31. package/dist/utils/KeyboardManager/keyCodes/meta.js.map +1 -0
  32. package/dist/utils/KeyboardManager/keyCodes/special-characters.d.ts +5 -0
  33. package/dist/utils/KeyboardManager/keyCodes/special-characters.js +91 -0
  34. package/dist/utils/KeyboardManager/keyCodes/special-characters.js.map +1 -0
  35. package/dist/utils/KeyboardManager/keyCodes/with-events.d.ts +2 -0
  36. package/dist/utils/KeyboardManager/keyCodes/with-events.js +1691 -0
  37. package/dist/utils/KeyboardManager/keyCodes/with-events.js.map +1 -0
  38. package/dist/utils/KeyboardManager/types/key-code-events.d.ts +15 -0
  39. package/dist/utils/KeyboardManager/types/key-code-events.js +2 -0
  40. package/dist/utils/KeyboardManager/types/key-code-events.js.map +1 -0
  41. package/dist/utils/KeyboardManager/types/meta-keys.d.ts +1 -0
  42. package/dist/utils/KeyboardManager/types/meta-keys.js +2 -0
  43. package/dist/utils/KeyboardManager/types/meta-keys.js.map +1 -0
  44. package/dist/utils/StringUtils.d.ts +21 -0
  45. package/dist/utils/StringUtils.js +30 -0
  46. package/dist/utils/StringUtils.js.map +1 -1
  47. package/package.json +1 -1
  48. package/src/index.ts +3 -1
  49. package/src/utils/JSUtils.ts +33 -9
  50. package/src/utils/KeyboardManager/constants/meta-keys.ts +8 -0
  51. package/src/utils/KeyboardManager/index.ts +208 -0
  52. package/src/utils/KeyboardManager/interface.ts +23 -0
  53. package/src/utils/KeyboardManager/keyCodes/android.ts +84 -0
  54. package/src/utils/KeyboardManager/keyCodes/dead.ts +19 -0
  55. package/src/utils/KeyboardManager/keyCodes/index.ts +11 -0
  56. package/src/utils/KeyboardManager/keyCodes/meta.ts +31 -0
  57. package/src/utils/KeyboardManager/keyCodes/special-characters.ts +105 -0
  58. package/src/utils/KeyboardManager/keyCodes/with-events.ts +1692 -0
  59. package/src/utils/KeyboardManager/types/key-code-events.ts +15 -0
  60. package/src/utils/KeyboardManager/types/meta-keys.ts +1 -0
  61. package/src/utils/StringUtils.ts +72 -38
@@ -0,0 +1,15 @@
1
+ export type KeyCodeEvent = {
2
+ key: string
3
+ keyCode: number
4
+ which: number
5
+ code?: string
6
+ location?: number
7
+ description?: string
8
+ unicode?: string
9
+ altKey?: boolean
10
+ ctrlKey?: boolean
11
+ metaKey?: boolean
12
+ shiftKey?: boolean
13
+ repeat?: boolean
14
+ path?: string
15
+ }
@@ -0,0 +1 @@
1
+ export type MetaKeys = 'meta' | 'shift' | 'alt' | 'ctrl'
@@ -8,10 +8,10 @@ export class StringUtils {
8
8
  /**
9
9
  * Retorna se a string está vazia.
10
10
  * Valores null e undefined são considerados como vazio.
11
- *
11
+ *
12
12
  * @param value - String para ser validada.
13
13
  * @returns - Verdadeiro caso a string não contenha informação.
14
- *
14
+ *
15
15
  */
16
16
  static isEmpty(value: any): Boolean {
17
17
 
@@ -28,10 +28,10 @@ export class StringUtils {
28
28
 
29
29
  return false;
30
30
  }
31
-
31
+
32
32
  /**
33
33
  * Remove acentos de vogais maiúsculas
34
- *
34
+ *
35
35
  * @param text String para ser transformada.
36
36
  * @example entrada: "ÁÊÇÒ" // retorno: "AECO"
37
37
  */
@@ -53,7 +53,7 @@ export class StringUtils {
53
53
 
54
54
  /**
55
55
  * Converte todas as entidades HTML de um texto
56
- *
56
+ *
57
57
  * @param text String para ser transformada.
58
58
  * @example entrada: "&lt;Teste&gt;" // retorno: "<Teste>"
59
59
  */
@@ -77,20 +77,20 @@ export class StringUtils {
77
77
  for(const entity of entities) {
78
78
  text = text.replace(new RegExp(`&${entity[0]};`), entity[1]);
79
79
  }
80
-
80
+
81
81
  return text;
82
82
  }
83
83
 
84
84
  /**
85
85
  * Remove acentos de vogais minúsculas.
86
- *
86
+ *
87
87
  * @param text String para ser transformada.
88
88
  * @example entrada: "áêçò" // retorno: "aeco"
89
- */
89
+ */
90
90
  static replaceAccentuatedCharsLower(text: string): string {
91
91
  if(!text.replace){
92
92
  return text;
93
- }
93
+ }
94
94
  return text.replace(/[àáâãäåæ]/g, 'a')
95
95
  .replace(/[èéêë]/g, 'e')
96
96
  .replace(/[ìíîï]/g, 'i')
@@ -103,10 +103,10 @@ export class StringUtils {
103
103
 
104
104
  /**
105
105
  * Remove acentuação de vogais e de caracteres especiais que não sejam letras ou numeral.
106
- *
106
+ *
107
107
  * @param text String para ser transformada.
108
108
  * @param removeSpecialChars Remove outros caracteres especiais que não sejam letras e números.
109
- * @example
109
+ * @example
110
110
  * entrada: "á@Êç#Ò", false // retorno: "a@Ec#O"
111
111
  * entrada: "á@Êç#Ò", true // retorno: "aEcO"
112
112
  */
@@ -114,7 +114,7 @@ export class StringUtils {
114
114
  if(!text.replace){
115
115
  return text;
116
116
  }
117
-
117
+
118
118
  text = StringUtils.replaceAccentuatedCharsLower(text);
119
119
  text = StringUtils.replaceAccentuatedCharsUpper(text);
120
120
 
@@ -151,9 +151,9 @@ export class StringUtils {
151
151
  return hash.toString();
152
152
  }
153
153
 
154
- /**
154
+ /**
155
155
  * Converte um texto do tipo string para um booleano.
156
- *
156
+ *
157
157
  * @param value Valor a ser convertido.
158
158
  * @param defaultValue Valor padrão.
159
159
  * @returns - Texto convertido.
@@ -174,21 +174,21 @@ export class StringUtils {
174
174
  }
175
175
 
176
176
  /**
177
- *
177
+ *
178
178
  * Adiciona caracteres à esquerda caso texto seja menor que o valor do parâmetro len passado.
179
- *
179
+ *
180
180
  * @param str - Texto para ser ajustado.
181
181
  * @param len - Tamanho desejado do texto.
182
182
  * @param pad - Caractere a ser adicionado a esquerda caso o texto menor que o tamanho passado.
183
183
  * @returns - Texto passado se este for maior que o len.
184
184
  * Ou retorna o texto com os caracteres adicionados na esquerda.
185
- *
185
+ *
186
186
  * @example
187
187
  * padStart('SANKHYA', 8,'.') | Retorna: '...SANKHYA'
188
188
  * @example
189
189
  * padStart('SANKHYA', 5,'A') | Retorna: 'SANKHYA'
190
- *
191
- *
190
+ *
191
+ *
192
192
  */
193
193
  static padStart(str: string, len: number, pad: string = " "): string {
194
194
  str = str != undefined ? str : "";
@@ -199,21 +199,21 @@ export class StringUtils {
199
199
  }
200
200
 
201
201
  /**
202
- *
202
+ *
203
203
  * Adiciona caracteres à direita caso texto seja menor que o valor do parâmetro len passado.
204
- *
204
+ *
205
205
  * @param str - Texto para ser ajustado.
206
206
  * @param len - Tamanho desejado do texto.
207
207
  * @param pad - Caractere a ser adicionado a direita caso o texto menor que o tamanho passado.
208
208
  * @returns - Texto passado se este for maior que o len.
209
209
  * Ou retorna o texto com os caracteres adicionados na direita.
210
- *
210
+ *
211
211
  * @example
212
212
  * padStart('SANKHYA', 8,'.') | Retorna: 'SANKHYA...'
213
213
  * @example
214
214
  * padStart('SANKHYA', 5,'A') | Retorna: 'SANKHYA'
215
- *
216
- *
215
+ *
216
+ *
217
217
  */
218
218
  static padEnd(str: string, len: number, pad: string = " "): string {
219
219
  str = str != undefined ? str : "";
@@ -232,7 +232,7 @@ export class StringUtils {
232
232
  * @returns - Um numeral negativo se o primeiro argumento é menor que o segundo, zero se os dois são iguais e um numeral positivo quando o primeiro é maior que o segundo.
233
233
  */
234
234
  static compare(a: string, b: string): number{
235
-
235
+
236
236
  if(a === undefined){
237
237
  return b === undefined ? 0 : 1;
238
238
  } else if(b === undefined){
@@ -247,24 +247,24 @@ export class StringUtils {
247
247
 
248
248
  return a.localeCompare(b);
249
249
  }
250
-
250
+
251
251
  /**
252
252
  * Converte string em camelCase.
253
253
  * Combina palavras compostas ou frases, alterando a inicial de cada uma, a partir da primeira, para maiúscula e unidas sem espaços.
254
254
  * @param value String a ser convertida.
255
- * @returns String convertida em camelCase.
256
- *
255
+ * @returns String convertida em camelCase.
256
+ *
257
257
  * @example
258
258
  * toCamelCase('Exemplo de uso') | Retorna: 'exemploDeUso'
259
259
  */
260
260
  static toCamelCase(value: string): string {
261
261
  if(!value) return "";
262
- if (value.match(/^[a-z]+[A-Z]/) || value.includes(".")) {
262
+ if (value.match(/^[a-z]+[A-Z]/) || value.includes(".")) {
263
263
  return value;
264
- }
264
+ }
265
265
  return value
266
266
  .toLowerCase()
267
- .replace(/^([A-Z])|[\s-_](\w)/g, (_, p1, p2) => p2?.toUpperCase() || p1.toLowerCase());
267
+ .replace(/^([A-Z])|[\s-_](\w)/g, (_, p1, p2) => p2?.toUpperCase() || p1.toLowerCase());
268
268
  }
269
269
 
270
270
  /**
@@ -300,7 +300,7 @@ export class StringUtils {
300
300
  static toKebabCase(value: string): string{
301
301
  return value.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/[\s_]+/g, '-').toLowerCase();
302
302
  }
303
-
303
+
304
304
  /**
305
305
  * Utilitário para remover caracteres em branco da string.
306
306
  * @param value String a ser removido os espaços.
@@ -311,30 +311,30 @@ export class StringUtils {
311
311
  }
312
312
 
313
313
  /**
314
- * Utilitário para formatar bytes em string legível, convertendo para
314
+ * Utilitário para formatar bytes em string legível, convertendo para
315
315
  * múltiplos maiores caso necessário.
316
316
  * @param byte quantidade de bytes a serem representados.
317
317
  * @returns string formatada de acordo com a unidade.
318
318
  */
319
319
  static formatBytes(bytes: number): string {
320
320
  const units = ["B", "KB", "MB", "GB"];
321
-
321
+
322
322
  if (bytes < 1024) {
323
323
  return `${bytes.toString()}B`;
324
324
  }
325
-
325
+
326
326
  const base = Math.log(bytes) / Math.log(1024);
327
327
  const offSet = Math.floor(base);
328
328
  if (offSet >= units.length) {
329
329
  return `${bytes.toString()}B`;
330
330
  }
331
-
331
+
332
332
  const value = this.prettyPrecision(Math.pow(1024, base - offSet).toFixed(2).toString());
333
333
  const unit = units[offSet];
334
-
334
+
335
335
  return `${value}${unit}`;
336
336
  }
337
-
337
+
338
338
  /**
339
339
  * Método interno. Remove zeros depois da vírgula diminuindo o tamanho
340
340
  * da string.
@@ -366,4 +366,38 @@ export class StringUtils {
366
366
  return uuid();
367
367
  }
368
368
 
369
+ /**
370
+ * Checa se uma string pode ser convertida para letras maiúsculas ou minúsculas
371
+ *
372
+ * @param {string} original - A string a ser verificada
373
+ * @return {boolean} Se a string pode ser convertida
374
+ */
375
+ static isCaseable(original: string): boolean {
376
+ const uppercase = original.toUpperCase()
377
+ const lowercase = original.toLowerCase()
378
+
379
+ return original !== uppercase || original !== lowercase
380
+ }
381
+
382
+ /**
383
+ * Checa se uma string é minúscula
384
+ *
385
+ * @param {string} original - A string a ser verificada
386
+ * @return {boolean} Se a string é minúscula
387
+ */
388
+ static isLowerCase(original: string): boolean {
389
+ const uppercase = original.toUpperCase()
390
+
391
+ return this.isCaseable(original) && uppercase !== original
392
+ }
393
+
394
+ /**
395
+ * Inverte uma string de minúsculas para maiúsculas e vice-versa
396
+ *
397
+ * @param {string} original - A string a ser invertida
398
+ * @return {string} A string invertida
399
+ */
400
+ static getOppositeCase(original: string): string {
401
+ return this.isLowerCase(original) ? original.toUpperCase() : original.toLowerCase()
402
+ }
369
403
  }