@sankhyalabs/core 1.0.42 → 1.0.45

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 (145) hide show
  1. package/.eslintignore +1 -1
  2. package/.eslintrc.cjs +34 -34
  3. package/README.md +54 -54
  4. package/dist/dataunit/DataUnit.d.ts +87 -82
  5. package/dist/dataunit/DataUnit.js +290 -278
  6. package/dist/dataunit/DataUnit.js.map +1 -1
  7. package/dist/dataunit/metadata/DataType.d.ts +9 -9
  8. package/dist/dataunit/metadata/DataType.js +36 -36
  9. package/dist/dataunit/metadata/UnitMetadata.d.ts +71 -71
  10. package/dist/dataunit/metadata/UnitMetadata.js +31 -31
  11. package/dist/dataunit/state/HistReducer.d.ts +10 -10
  12. package/dist/dataunit/state/HistReducer.js +27 -27
  13. package/dist/dataunit/state/StateManager.d.ts +57 -57
  14. package/dist/dataunit/state/StateManager.js +96 -96
  15. package/dist/dataunit/state/action/DataUnitAction.d.ts +29 -28
  16. package/dist/dataunit/state/action/DataUnitAction.js +34 -33
  17. package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
  18. package/dist/dataunit/state/slice/AddedRecordsSlice.d.ts +11 -11
  19. package/dist/dataunit/state/slice/AddedRecordsSlice.js +25 -25
  20. package/dist/dataunit/state/slice/ChangesSlice.d.ts +12 -12
  21. package/dist/dataunit/state/slice/ChangesSlice.js +76 -72
  22. package/dist/dataunit/state/slice/ChangesSlice.js.map +1 -1
  23. package/dist/dataunit/state/slice/CurrentRecordsSlice.d.ts +11 -11
  24. package/dist/dataunit/state/slice/CurrentRecordsSlice.js +45 -45
  25. package/dist/dataunit/state/slice/RecordsSlice.d.ts +10 -10
  26. package/dist/dataunit/state/slice/RecordsSlice.js +43 -43
  27. package/dist/dataunit/state/slice/RemovedRecordsSlice.d.ts +9 -9
  28. package/dist/dataunit/state/slice/RemovedRecordsSlice.js +24 -24
  29. package/dist/dataunit/state/slice/SelectionSlice.d.ts +11 -11
  30. package/dist/dataunit/state/slice/SelectionSlice.js +111 -111
  31. package/dist/dataunit/state/slice/UnitMetadataSlice.d.ts +11 -11
  32. package/dist/dataunit/state/slice/UnitMetadataSlice.js +20 -20
  33. package/dist/dataunit/state/slice/WaitingChangesSlice.d.ts +9 -0
  34. package/dist/dataunit/state/slice/WaitingChangesSlice.js +32 -0
  35. package/dist/dataunit/state/slice/WaitingChangesSlice.js.map +1 -0
  36. package/dist/http/AuthorizedServiceCaller.d.ts +11 -11
  37. package/dist/http/AuthorizedServiceCaller.js +53 -53
  38. package/dist/http/HttpProvider.d.ts +25 -25
  39. package/dist/http/HttpProvider.js +73 -73
  40. package/dist/http/RequestMetadata.d.ts +30 -30
  41. package/dist/http/RequestMetadata.js +24 -24
  42. package/dist/http/SkwHttpProvider.d.ts +9 -9
  43. package/dist/http/SkwHttpProvider.js +66 -66
  44. package/dist/index.d.ts +16 -16
  45. package/dist/index.js +17 -17
  46. package/dist/index.js.map +1 -1
  47. package/dist/ui/FloatingManager.d.ts +25 -24
  48. package/dist/ui/FloatingManager.js +124 -122
  49. package/dist/ui/FloatingManager.js.map +1 -1
  50. package/dist/utils/ApplicationContext.d.ts +5 -5
  51. package/dist/utils/ApplicationContext.js +16 -16
  52. package/dist/utils/CriteriaModel.d.ts +109 -109
  53. package/dist/utils/CriteriaModel.js +173 -173
  54. package/dist/utils/CriteriaParameter.d.ts +69 -69
  55. package/dist/utils/CriteriaParameter.js +82 -82
  56. package/dist/utils/DateUtils.d.ts +5 -5
  57. package/dist/utils/DateUtils.js +42 -42
  58. package/dist/utils/MaskFormatter.d.ts +126 -126
  59. package/dist/utils/MaskFormatter.js +275 -275
  60. package/dist/utils/NumberUtils.d.ts +53 -53
  61. package/dist/utils/NumberUtils.js +141 -141
  62. package/dist/utils/StringUtils.d.ts +18 -18
  63. package/dist/utils/StringUtils.js +53 -53
  64. package/dist/utils/TimeFormatter.d.ts +33 -33
  65. package/dist/utils/TimeFormatter.js +97 -97
  66. package/jest.config.ts +16 -16
  67. package/mock/http/XMLHttpRequest-mock.js +25 -25
  68. package/package.json +38 -37
  69. package/scripts/runlink.bat +1 -0
  70. package/src/dataunit/DataUnit.ts +374 -356
  71. package/src/dataunit/metadata/DataType.ts +37 -37
  72. package/src/dataunit/metadata/UnitMetadata.ts +82 -82
  73. package/src/dataunit/state/HistReducer.ts +33 -33
  74. package/src/dataunit/state/StateManager.ts +141 -141
  75. package/src/dataunit/state/action/DataUnitAction.ts +52 -50
  76. package/src/dataunit/state/slice/AddedRecordsSlice.ts +32 -32
  77. package/src/dataunit/state/slice/ChangesSlice.ts +95 -90
  78. package/src/dataunit/state/slice/CurrentRecordsSlice.ts +53 -53
  79. package/src/dataunit/state/slice/RecordsSlice.ts +56 -56
  80. package/src/dataunit/state/slice/RemovedRecordsSlice.ts +29 -29
  81. package/src/dataunit/state/slice/SelectionSlice.ts +130 -130
  82. package/src/dataunit/state/slice/UnitMetadataSlice.ts +29 -29
  83. package/src/dataunit/state/slice/WaitingChangesSlice.ts +44 -0
  84. package/src/http/AuthorizedServiceCaller.ts +58 -58
  85. package/src/http/HttpProvider.ts +93 -93
  86. package/src/http/RequestMetadata.ts +41 -41
  87. package/src/http/SkwHttpProvider.ts +77 -77
  88. package/src/index.ts +45 -44
  89. package/src/ui/FloatingManager.ts +167 -165
  90. package/src/utils/ApplicationContext.ts +18 -18
  91. package/src/utils/CriteriaModel.ts +207 -207
  92. package/src/utils/CriteriaParameter.ts +107 -107
  93. package/src/utils/DateUtils.ts +52 -52
  94. package/src/utils/MaskFormatter.ts +322 -322
  95. package/src/utils/NumberUtils.ts +174 -174
  96. package/src/utils/StringUtils.ts +60 -60
  97. package/src/utils/TimeFormatter.ts +97 -97
  98. package/test/http/HttpProvider.spec.ts +34 -34
  99. package/test/http/SkwHttpProvider.ts.spec.ts +33 -33
  100. package/test/util/CriteriaModel.spec.ts +231 -231
  101. package/test/util/CriteriaParameter.spec.ts +51 -51
  102. package/test/util/MaskFormatter.spec.ts +138 -138
  103. package/test/util/NumberUtils.spec.ts +156 -156
  104. package/test/util/StringUtils.spec.ts +43 -43
  105. package/test/util/TimeFormatter.spec.ts +25 -25
  106. package/tsconfig.json +15 -15
  107. package/dist/application/Application.d.ts +0 -8
  108. package/dist/application/Application.js +0 -19
  109. package/dist/application/Application.js.map +0 -1
  110. package/dist/http/data-fetcher/HttpFetcher.d.ts +0 -14
  111. package/dist/http/data-fetcher/HttpFetcher.js +0 -164
  112. package/dist/http/data-fetcher/HttpFetcher.js.map +0 -1
  113. package/dist/http/data-fetcher/default/DefaultGraphQL.d.ts +0 -3
  114. package/dist/http/data-fetcher/default/DefaultGraphQL.js +0 -18
  115. package/dist/http/data-fetcher/default/DefaultGraphQL.js.map +0 -1
  116. package/dist/http/data-fetcher/default/application-config-fetcher.d.ts +0 -6
  117. package/dist/http/data-fetcher/default/application-config-fetcher.js +0 -21
  118. package/dist/http/data-fetcher/default/application-config-fetcher.js.map +0 -1
  119. package/dist/http/data-fetcher/default/data-unit-graphql.d.ts +0 -3
  120. package/dist/http/data-fetcher/default/data-unit-graphql.js +0 -18
  121. package/dist/http/data-fetcher/default/data-unit-graphql.js.map +0 -1
  122. package/dist/http/data-fetcher/default/dataunit-executor.d.ts +0 -10
  123. package/dist/http/data-fetcher/default/dataunit-executor.js +0 -56
  124. package/dist/http/data-fetcher/default/dataunit-executor.js.map +0 -1
  125. package/dist/http/data-fetcher/default/dataunit-fetcher.d.ts +0 -9
  126. package/dist/http/data-fetcher/default/dataunit-fetcher.js +0 -69
  127. package/dist/http/data-fetcher/default/dataunit-fetcher.js.map +0 -1
  128. package/dist/http/data-fetcher/default/form-config-fetcher.d.ts +0 -2
  129. package/dist/http/data-fetcher/default/form-config-fetcher.js +0 -3
  130. package/dist/http/data-fetcher/default/form-config-fetcher.js.map +0 -1
  131. package/dist/http/data-fetcher/default/grid-config-fetcher.d.ts +0 -2
  132. package/dist/http/data-fetcher/default/grid-config-fetcher.js +0 -3
  133. package/dist/http/data-fetcher/default/grid-config-fetcher.js.map +0 -1
  134. package/dist/http/data-fetcher/default/index.d.ts +0 -0
  135. package/dist/http/data-fetcher/default/index.js +0 -2
  136. package/dist/http/data-fetcher/default/index.js.map +0 -1
  137. package/dist/http/data-fetcher/default/sankhya-graphql.d.ts +0 -3
  138. package/dist/http/data-fetcher/default/sankhya-graphql.js +0 -8
  139. package/dist/http/data-fetcher/default/sankhya-graphql.js.map +0 -1
  140. package/dist/http/data-fetcher/graphql/DefaultGraphQl.d.ts +0 -3
  141. package/dist/http/data-fetcher/graphql/DefaultGraphQl.js +0 -18
  142. package/dist/http/data-fetcher/graphql/DefaultGraphQl.js.map +0 -1
  143. package/dist/http/data-fetcher/state/LoadStateManager.d.ts +0 -23
  144. package/dist/http/data-fetcher/state/LoadStateManager.js +0 -78
  145. package/dist/http/data-fetcher/state/LoadStateManager.js.map +0 -1
@@ -1,175 +1,175 @@
1
-
2
- const NUMBERINPUTS_REGEX_SCIENTIFIC_PARTS: RegExp = /^([+-])?(\d+).?(\d*)[eE]([-+]?\d+)$/;
3
-
4
- /**
5
- * `NumberUtils` é uma biblioteca para manipulação de números
6
- *
7
- * `Métodos`:
8
- *
9
- * @stringToNumber: converte um número em formato de string em um valor numérico nativo do javascript
10
- * @format: arredonda um número em formato de string baseado nos parâmetros "presision" e "prettyPrecision";
11
- */
12
- export class NumberUtils {
13
-
14
-
15
-
16
-
17
- /**
18
- * @stringToNumber: converte um numero em formato de string em numero
19
- *
20
- * @param value numero em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico: ######.##)
21
- *
22
- * @returns string based number
23
- *
24
- * @Exemples
25
- * @"100,12" | 100.12
26
- * @"100.12" | 100.12
27
- * @"-100,12" | -100.12
28
- * @"R$100,12" | 100.12
29
- * @"-R$100,12" | -100.12
30
- * @"string" | NaN
31
- */
32
- static stringToNumber = (value: string): number => {
33
-
34
- if (value === '' || value === null || value === undefined) {
35
- return NaN;
36
- }
37
-
38
- if (value) {
39
- value = value.toString();
40
-
41
- const negative = (value.charAt(0) === '-');
42
-
43
- if (!NUMBERINPUTS_REGEX_SCIENTIFIC_PARTS.test(value)) {
44
- value = value.replace(/[^\d.,]/g, '');
45
- } else {
46
- value = value.replace(/^-/g, '');
47
- }
48
-
49
- //In case of simple string such as: "@@@@@@@"
50
- if (value === '') {
51
- return Number(NaN);
52
- }
53
-
54
- const indexV = value.indexOf(',');
55
- const indexP = value.indexOf('.');
56
-
57
- if (indexP > indexV) {
58
- value = value.replace(',', '');
59
- } else if (indexP < indexV) {
60
- value = value.replace(/\./g, '@').replace(',', '.').replace(/@/g, '');
61
- }
62
-
63
- if (negative) {
64
- value = '-' + value;
65
- }
66
- }
67
-
68
- return Number(value);
69
-
70
- }
71
-
72
-
73
- /**
74
- * @format: converte um numero em formato de string em um numero em formato de string formatado de acordo com os parametros de "precision" e "prettyPrecision"
75
- *
76
- * @param value numero em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico<sem separadors de milhares>: ######.##)
77
- * @param precision (numero de decimais)
78
- * @param prettyPrecision (numero de zeros nos decimais)
79
- *
80
- * @returns numero em formato de string formatado em PT-BR
81
- */
82
- static format = (value: string, precision: number, prettyPrecision: number = NaN): string => {
83
-
84
- if (value === '' || value === undefined || value === "NaN") {
85
- return NaN.toString();
86
- }
87
-
88
- const newValue: number = NumberUtils.stringToNumber(value);
89
-
90
- if (isNaN(newValue)) {
91
- return NaN.toString();
92
- }
93
-
94
- //Validation "precision":
95
- // Case1: precision < 0 => does not use precision
96
- // Case2: presicion not int => does not use precision
97
- if (precision < 0 || Math.abs(Math.round(precision * 1) / 1) !== precision) {
98
- //Once stringToNumber returns number format, we need to change to pt-br
99
- return NumberUtils.changeFormat(newValue.toString());
100
- }
101
-
102
-
103
- //Validation "prettyPrecision"
104
- let prettyPrecisionInternal: number = 0;
105
- // Case1: prettyPrecision < 0 => prettyPrecision does not change de format that means: prettyPrecisionInternal = precision;
106
- // Case2: prettyPrecision not int => prettyPrecision does not change de format that means: prettyPrecisionInternal = precision;
107
- if (isNaN(prettyPrecision) || Math.abs(Math.round(prettyPrecision * 1) / 1) !== prettyPrecision) {
108
- prettyPrecisionInternal = precision;
109
- } else {
110
- prettyPrecisionInternal = prettyPrecision;
111
- }
112
-
113
- let newValueStr: string;
114
- newValueStr = (Math.round(newValue * Math.pow(10, precision)) / Math.pow(10, precision)).toLocaleString('pt-br', { minimumFractionDigits: precision });
115
-
116
- //prettyPrecision
117
- const varSettingPP: number = precision - prettyPrecisionInternal;
118
- if (varSettingPP > 0) {
119
- for (let i = 0; i < varSettingPP; i++) {
120
- if (newValueStr.substring(newValueStr.length - 1) == "0" && precision > 0) {
121
- newValueStr = newValueStr.substring(0, newValueStr.length - 1);
122
- }
123
- }
124
- }
125
-
126
- //in Case "." or "," in the end of the string
127
- if (newValueStr.substring(newValueStr.length - 1) == "." || newValueStr.substring(newValueStr.length - 1) == ",") {
128
- newValueStr = newValueStr.substring(0, newValueStr.length - 1);
129
- }
130
-
131
-
132
- return newValueStr;
133
-
134
-
135
- }
136
-
137
-
138
- /**
139
- * @keepOnlyDecimalSeparator: retira os separadores de milhar de um número em formato de string
140
- *
141
- * @param value numero em formato de string a ser convertido
142
- * @param formatnumber (formatação de ENTRADA e SAÍDA do utilitário: pt-BR="###.###,##" en-US="###,###.##"; Default: "pt-BR")
143
- *
144
- * @returns numero em formato de string formatado apenas com separador decimal
145
- */
146
- static keepOnlyDecimalSeparator = (value: string, formatnumber: string = 'pt-BR'): string => {
147
-
148
- //Formatting formatnumber to be able to get lowercases
149
- formatnumber = formatnumber.toUpperCase();
150
-
151
- //Formatting value following formatnumber parameter
152
- //keep only decimal character in order to correct format the string
153
- //This transformation is due the "stringtoNumber" method is a general method that tries to convert all formated strings
154
- if (formatnumber === 'EN-US') {
155
- value = value.replace(/\,/g, '');
156
- } else {
157
- value = value.replace(/\./g, '');
158
- }
159
-
160
- return value;
161
- }
162
-
163
- /**
164
- * @changeFormat: troca o formato do numero string de "PT-BR" para "EN-US" e vice-versa
165
- *
166
- * @param value numero em formato de string a ser convertido
167
- *
168
- * @returns numero em formato de string formatado de "PT-BR" para "EN-US" e vice-versa
169
- */
170
- static changeFormat = (value: string): string => {
171
- //Formatting output following formatnumber
172
- return value.replace(/\./g, '_').replace(/\,/g, '.').replace(/\_/g, ',');
173
- }
174
-
1
+
2
+ const NUMBERINPUTS_REGEX_SCIENTIFIC_PARTS: RegExp = /^([+-])?(\d+).?(\d*)[eE]([-+]?\d+)$/;
3
+
4
+ /**
5
+ * `NumberUtils` é uma biblioteca para manipulação de números
6
+ *
7
+ * `Métodos`:
8
+ *
9
+ * @stringToNumber: converte um número em formato de string em um valor numérico nativo do javascript
10
+ * @format: arredonda um número em formato de string baseado nos parâmetros "presision" e "prettyPrecision";
11
+ */
12
+ export class NumberUtils {
13
+
14
+
15
+
16
+
17
+ /**
18
+ * @stringToNumber: converte um numero em formato de string em numero
19
+ *
20
+ * @param value numero em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico: ######.##)
21
+ *
22
+ * @returns string based number
23
+ *
24
+ * @Exemples
25
+ * @"100,12" | 100.12
26
+ * @"100.12" | 100.12
27
+ * @"-100,12" | -100.12
28
+ * @"R$100,12" | 100.12
29
+ * @"-R$100,12" | -100.12
30
+ * @"string" | NaN
31
+ */
32
+ static stringToNumber = (value: string): number => {
33
+
34
+ if (value === '' || value === null || value === undefined) {
35
+ return NaN;
36
+ }
37
+
38
+ if (value) {
39
+ value = value.toString();
40
+
41
+ const negative = (value.charAt(0) === '-');
42
+
43
+ if (!NUMBERINPUTS_REGEX_SCIENTIFIC_PARTS.test(value)) {
44
+ value = value.replace(/[^\d.,]/g, '');
45
+ } else {
46
+ value = value.replace(/^-/g, '');
47
+ }
48
+
49
+ //In case of simple string such as: "@@@@@@@"
50
+ if (value === '') {
51
+ return Number(NaN);
52
+ }
53
+
54
+ const indexV = value.indexOf(',');
55
+ const indexP = value.indexOf('.');
56
+
57
+ if (indexP > indexV) {
58
+ value = value.replace(',', '');
59
+ } else if (indexP < indexV) {
60
+ value = value.replace(/\./g, '@').replace(',', '.').replace(/@/g, '');
61
+ }
62
+
63
+ if (negative) {
64
+ value = '-' + value;
65
+ }
66
+ }
67
+
68
+ return Number(value);
69
+
70
+ }
71
+
72
+
73
+ /**
74
+ * @format: converte um numero em formato de string em um numero em formato de string formatado de acordo com os parametros de "precision" e "prettyPrecision"
75
+ *
76
+ * @param value numero em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico<sem separadors de milhares>: ######.##)
77
+ * @param precision (numero de decimais)
78
+ * @param prettyPrecision (numero de zeros nos decimais)
79
+ *
80
+ * @returns numero em formato de string formatado em PT-BR
81
+ */
82
+ static format = (value: string, precision: number, prettyPrecision: number = NaN): string => {
83
+
84
+ if (value === '' || value === undefined || value === "NaN") {
85
+ return NaN.toString();
86
+ }
87
+
88
+ const newValue: number = NumberUtils.stringToNumber(value);
89
+
90
+ if (isNaN(newValue)) {
91
+ return NaN.toString();
92
+ }
93
+
94
+ //Validation "precision":
95
+ // Case1: precision < 0 => does not use precision
96
+ // Case2: presicion not int => does not use precision
97
+ if (precision < 0 || Math.abs(Math.round(precision * 1) / 1) !== precision) {
98
+ //Once stringToNumber returns number format, we need to change to pt-br
99
+ return NumberUtils.changeFormat(newValue.toString());
100
+ }
101
+
102
+
103
+ //Validation "prettyPrecision"
104
+ let prettyPrecisionInternal: number = 0;
105
+ // Case1: prettyPrecision < 0 => prettyPrecision does not change de format that means: prettyPrecisionInternal = precision;
106
+ // Case2: prettyPrecision not int => prettyPrecision does not change de format that means: prettyPrecisionInternal = precision;
107
+ if (isNaN(prettyPrecision) || Math.abs(Math.round(prettyPrecision * 1) / 1) !== prettyPrecision) {
108
+ prettyPrecisionInternal = precision;
109
+ } else {
110
+ prettyPrecisionInternal = prettyPrecision;
111
+ }
112
+
113
+ let newValueStr: string;
114
+ newValueStr = (Math.round(newValue * Math.pow(10, precision)) / Math.pow(10, precision)).toLocaleString('pt-br', { minimumFractionDigits: precision });
115
+
116
+ //prettyPrecision
117
+ const varSettingPP: number = precision - prettyPrecisionInternal;
118
+ if (varSettingPP > 0) {
119
+ for (let i = 0; i < varSettingPP; i++) {
120
+ if (newValueStr.substring(newValueStr.length - 1) == "0" && precision > 0) {
121
+ newValueStr = newValueStr.substring(0, newValueStr.length - 1);
122
+ }
123
+ }
124
+ }
125
+
126
+ //in Case "." or "," in the end of the string
127
+ if (newValueStr.substring(newValueStr.length - 1) == "." || newValueStr.substring(newValueStr.length - 1) == ",") {
128
+ newValueStr = newValueStr.substring(0, newValueStr.length - 1);
129
+ }
130
+
131
+
132
+ return newValueStr;
133
+
134
+
135
+ }
136
+
137
+
138
+ /**
139
+ * @keepOnlyDecimalSeparator: retira os separadores de milhar de um número em formato de string
140
+ *
141
+ * @param value numero em formato de string a ser convertido
142
+ * @param formatnumber (formatação de ENTRADA e SAÍDA do utilitário: pt-BR="###.###,##" en-US="###,###.##"; Default: "pt-BR")
143
+ *
144
+ * @returns numero em formato de string formatado apenas com separador decimal
145
+ */
146
+ static keepOnlyDecimalSeparator = (value: string, formatnumber: string = 'pt-BR'): string => {
147
+
148
+ //Formatting formatnumber to be able to get lowercases
149
+ formatnumber = formatnumber.toUpperCase();
150
+
151
+ //Formatting value following formatnumber parameter
152
+ //keep only decimal character in order to correct format the string
153
+ //This transformation is due the "stringtoNumber" method is a general method that tries to convert all formated strings
154
+ if (formatnumber === 'EN-US') {
155
+ value = value.replace(/\,/g, '');
156
+ } else {
157
+ value = value.replace(/\./g, '');
158
+ }
159
+
160
+ return value;
161
+ }
162
+
163
+ /**
164
+ * @changeFormat: troca o formato do numero string de "PT-BR" para "EN-US" e vice-versa
165
+ *
166
+ * @param value numero em formato de string a ser convertido
167
+ *
168
+ * @returns numero em formato de string formatado de "PT-BR" para "EN-US" e vice-versa
169
+ */
170
+ static changeFormat = (value: string): string => {
171
+ //Formatting output following formatnumber
172
+ return value.replace(/\./g, '_').replace(/\,/g, '.').replace(/\_/g, ',');
173
+ }
174
+
175
175
  }
@@ -1,61 +1,61 @@
1
- /**
2
- * Classe com utiliários comuns para Strings.
3
- */
4
- export class StringUtils {
5
-
6
- /**
7
- * Verifica se a string está vazia.
8
- * Valores null e undefined são considerados como vazio.
9
- *
10
- * @param value String para ser validada.
11
- */
12
- static isEmpty(value: any): Boolean {
13
-
14
- if (value == undefined || value === null) {
15
- return true;
16
- }
17
-
18
- value = value.toString();
19
- value = value.trim();
20
-
21
- if (value.length === 0) {
22
- return true;
23
- }
24
-
25
- return false;
26
- }
27
-
28
-
29
- /**
30
- * Remove acentos de vogais, substitui Ç por c e retorna a string em caixa alta.
31
- *
32
- * @param value String para ser transformada.
33
- */
34
- static replaceAccentuatedChars(text: string): string {
35
- text = text.toUpperCase();
36
- text = text.replace(/[À]/, "A");
37
- text = text.replace(/[Á]/, "A");
38
- text = text.replace(/[Â]/, "A");
39
- text = text.replace(/[Ã]/, "A");
40
- text = text.replace(/[Ä]/, "A");
41
- text = text.replace(/[È]/, "E");
42
- text = text.replace(/[É]/, "E");
43
- text = text.replace(/[Ê]/, "E");
44
- text = text.replace(/[Ë]/, "E");
45
- text = text.replace(/[Ì]/, "I");
46
- text = text.replace(/[Í]/, "I");
47
- text = text.replace(/[Î]/, "I");
48
- text = text.replace(/[Ï]/, "I");
49
- text = text.replace(/[Ò]/, "O");
50
- text = text.replace(/[Ó]/, "O");
51
- text = text.replace(/[Ô]/, "O");
52
- text = text.replace(/[Ö]/, "O");
53
- text = text.replace(/[Ù]/, "U");
54
- text = text.replace(/[Ú]/, "U");
55
- text = text.replace(/[Û]/, "U");
56
- text = text.replace(/[Ü]/, "U");
57
- text = text.replace(/[Ç]/, "C");
58
- return text.replace(/[^a-z0-9]/gi, '');
59
- }
60
-
1
+ /**
2
+ * Classe com utiliários comuns para Strings.
3
+ */
4
+ export class StringUtils {
5
+
6
+ /**
7
+ * Verifica se a string está vazia.
8
+ * Valores null e undefined são considerados como vazio.
9
+ *
10
+ * @param value String para ser validada.
11
+ */
12
+ static isEmpty(value: any): Boolean {
13
+
14
+ if (value == undefined || value === null) {
15
+ return true;
16
+ }
17
+
18
+ value = value.toString();
19
+ value = value.trim();
20
+
21
+ if (value.length === 0) {
22
+ return true;
23
+ }
24
+
25
+ return false;
26
+ }
27
+
28
+
29
+ /**
30
+ * Remove acentos de vogais, substitui Ç por c e retorna a string em caixa alta.
31
+ *
32
+ * @param value String para ser transformada.
33
+ */
34
+ static replaceAccentuatedChars(text: string): string {
35
+ text = text.toUpperCase();
36
+ text = text.replace(/[À]/, "A");
37
+ text = text.replace(/[Á]/, "A");
38
+ text = text.replace(/[Â]/, "A");
39
+ text = text.replace(/[Ã]/, "A");
40
+ text = text.replace(/[Ä]/, "A");
41
+ text = text.replace(/[È]/, "E");
42
+ text = text.replace(/[É]/, "E");
43
+ text = text.replace(/[Ê]/, "E");
44
+ text = text.replace(/[Ë]/, "E");
45
+ text = text.replace(/[Ì]/, "I");
46
+ text = text.replace(/[Í]/, "I");
47
+ text = text.replace(/[Î]/, "I");
48
+ text = text.replace(/[Ï]/, "I");
49
+ text = text.replace(/[Ò]/, "O");
50
+ text = text.replace(/[Ó]/, "O");
51
+ text = text.replace(/[Ô]/, "O");
52
+ text = text.replace(/[Ö]/, "O");
53
+ text = text.replace(/[Ù]/, "U");
54
+ text = text.replace(/[Ú]/, "U");
55
+ text = text.replace(/[Û]/, "U");
56
+ text = text.replace(/[Ü]/, "U");
57
+ text = text.replace(/[Ç]/, "C");
58
+ return text.replace(/[^a-z0-9]/gi, '');
59
+ }
60
+
61
61
  }