@sankhyalabs/core 5.3.0 → 5.4.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.
- package/.docs/classes/ArrayUtils.md +3 -3
- package/.docs/classes/NumberUtils.md +70 -7
- package/dist/utils/ArrayUtils.js +13 -1
- package/dist/utils/ArrayUtils.js.map +1 -1
- package/dist/utils/NumberUtils.d.ts +25 -1
- package/dist/utils/NumberUtils.js +43 -3
- package/dist/utils/NumberUtils.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/ArrayUtils.ts +16 -2
- package/src/utils/NumberUtils.ts +46 -4
|
@@ -47,7 +47,7 @@ Filtra um array a partir de um critério textual.
|
|
|
47
47
|
|
|
48
48
|
#### Defined in
|
|
49
49
|
|
|
50
|
-
src/utils/ArrayUtils.ts:
|
|
50
|
+
src/utils/ArrayUtils.ts:17
|
|
51
51
|
|
|
52
52
|
___
|
|
53
53
|
|
|
@@ -71,7 +71,7 @@ Converte texto para caixa alta e substitui caracteres acentuados.
|
|
|
71
71
|
|
|
72
72
|
#### Defined in
|
|
73
73
|
|
|
74
|
-
src/utils/ArrayUtils.ts:
|
|
74
|
+
src/utils/ArrayUtils.ts:35
|
|
75
75
|
|
|
76
76
|
___
|
|
77
77
|
|
|
@@ -96,4 +96,4 @@ Ordena valores de um array alfabeticamente.
|
|
|
96
96
|
|
|
97
97
|
#### Defined in
|
|
98
98
|
|
|
99
|
-
src/utils/ArrayUtils.ts:
|
|
99
|
+
src/utils/ArrayUtils.ts:45
|
|
@@ -13,11 +13,13 @@
|
|
|
13
13
|
### Methods
|
|
14
14
|
|
|
15
15
|
- [changeFormat](NumberUtils.md#changeformat)
|
|
16
|
+
- [compare](NumberUtils.md#compare)
|
|
16
17
|
- [format](NumberUtils.md#format)
|
|
17
18
|
- [getValueOrDefault](NumberUtils.md#getvalueordefault)
|
|
18
19
|
- [getValueOrZero](NumberUtils.md#getvalueorzero)
|
|
19
20
|
- [keepOnlyDecimalSeparator](NumberUtils.md#keeponlydecimalseparator)
|
|
20
21
|
- [round](NumberUtils.md#round)
|
|
22
|
+
- [safeFormat](NumberUtils.md#safeformat)
|
|
21
23
|
- [stringToNumber](NumberUtils.md#stringtonumber)
|
|
22
24
|
|
|
23
25
|
## Constructors
|
|
@@ -60,13 +62,38 @@ Informo: "27.99" | Obtenho: "27,99"
|
|
|
60
62
|
|
|
61
63
|
#### Defined in
|
|
62
64
|
|
|
63
|
-
src/utils/NumberUtils.ts:
|
|
65
|
+
src/utils/NumberUtils.ts:186
|
|
66
|
+
|
|
67
|
+
___
|
|
68
|
+
|
|
69
|
+
### compare
|
|
70
|
+
|
|
71
|
+
▸ `Static` **compare**(`a`, `b`): `number`
|
|
72
|
+
|
|
73
|
+
Determina a ordem de umeros.
|
|
74
|
+
|
|
75
|
+
#### Parameters
|
|
76
|
+
|
|
77
|
+
| Name | Type | Description |
|
|
78
|
+
| :------ | :------ | :------ |
|
|
79
|
+
| `a` | `number` | Primeio número para comparação. |
|
|
80
|
+
| `b` | `number` | Segundo número para comparação. |
|
|
81
|
+
|
|
82
|
+
#### Returns
|
|
83
|
+
|
|
84
|
+
`number`
|
|
85
|
+
|
|
86
|
+
- 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.
|
|
87
|
+
|
|
88
|
+
#### Defined in
|
|
89
|
+
|
|
90
|
+
src/utils/NumberUtils.ts:267
|
|
64
91
|
|
|
65
92
|
___
|
|
66
93
|
|
|
67
94
|
### format
|
|
68
95
|
|
|
69
|
-
▸ `Static` **format**(`value`, `precision`, `prettyPrecision?`): `string`
|
|
96
|
+
▸ `Static` **format**(`value`, `precision`, `prettyPrecision?`, `defaultValue?`): `string`
|
|
70
97
|
|
|
71
98
|
Formata o numeral com a precisão informada.
|
|
72
99
|
|
|
@@ -74,6 +101,8 @@ Formata o numeral com a precisão informada.
|
|
|
74
101
|
|
|
75
102
|
```ts
|
|
76
103
|
Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
104
|
+
Informado: (undefined, 3, 3) | Retorna: NaN
|
|
105
|
+
Informado: (undefined, 3, 3, '0,00') | Retorna: 0,00
|
|
77
106
|
```
|
|
78
107
|
|
|
79
108
|
#### Parameters
|
|
@@ -83,6 +112,7 @@ Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
|
83
112
|
| `value` | `string` | `undefined` | Numeral em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico - sem separador de milhares: ######.##). |
|
|
84
113
|
| `precision` | `number` | `undefined` | Quantidade de casas decimais. |
|
|
85
114
|
| `prettyPrecision` | `number` | `NaN` | Quantidade de zeros nos decimais. |
|
|
115
|
+
| `defaultValue` | `string` | `undefined` | Valor padrão caso o value não seja um valor numérico válido. |
|
|
86
116
|
|
|
87
117
|
#### Returns
|
|
88
118
|
|
|
@@ -92,7 +122,7 @@ Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
|
92
122
|
|
|
93
123
|
#### Defined in
|
|
94
124
|
|
|
95
|
-
src/utils/NumberUtils.ts:
|
|
125
|
+
src/utils/NumberUtils.ts:77
|
|
96
126
|
|
|
97
127
|
___
|
|
98
128
|
|
|
@@ -135,7 +165,7 @@ Informo: value: "30abc", defaultValue: 0 | Obtenho: 0
|
|
|
135
165
|
|
|
136
166
|
#### Defined in
|
|
137
167
|
|
|
138
|
-
src/utils/NumberUtils.ts:
|
|
168
|
+
src/utils/NumberUtils.ts:208
|
|
139
169
|
|
|
140
170
|
___
|
|
141
171
|
|
|
@@ -159,7 +189,7 @@ Obtém o valor ou zero, caso o valor seja inválido(NaN/undefined).
|
|
|
159
189
|
|
|
160
190
|
#### Defined in
|
|
161
191
|
|
|
162
|
-
src/utils/NumberUtils.ts:
|
|
192
|
+
src/utils/NumberUtils.ts:227
|
|
163
193
|
|
|
164
194
|
___
|
|
165
195
|
|
|
@@ -190,7 +220,7 @@ Informado: '95.12' | Retorna: '9512'
|
|
|
190
220
|
|
|
191
221
|
#### Defined in
|
|
192
222
|
|
|
193
|
-
src/utils/NumberUtils.ts:
|
|
223
|
+
src/utils/NumberUtils.ts:158
|
|
194
224
|
|
|
195
225
|
___
|
|
196
226
|
|
|
@@ -234,7 +264,40 @@ Informo: ("100.16", 3) | 100.16
|
|
|
234
264
|
|
|
235
265
|
#### Defined in
|
|
236
266
|
|
|
237
|
-
src/utils/NumberUtils.ts:
|
|
267
|
+
src/utils/NumberUtils.ts:255
|
|
268
|
+
|
|
269
|
+
___
|
|
270
|
+
|
|
271
|
+
### safeFormat
|
|
272
|
+
|
|
273
|
+
▸ `Static` **safeFormat**(`value`, `precision`, `prettyPrecision?`): `string`
|
|
274
|
+
|
|
275
|
+
Formata o numeral com a precisão informada e o valor default 0,00 caso o value não seja um numero valido.
|
|
276
|
+
|
|
277
|
+
**`Example`**
|
|
278
|
+
|
|
279
|
+
```ts
|
|
280
|
+
Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
281
|
+
Informado: (undefined, 3, 3) | Retorna: 0,00
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
#### Parameters
|
|
285
|
+
|
|
286
|
+
| Name | Type | Default value | Description |
|
|
287
|
+
| :------ | :------ | :------ | :------ |
|
|
288
|
+
| `value` | `string` | `undefined` | Numeral em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico - sem separador de milhares: ######.##). |
|
|
289
|
+
| `precision` | `number` | `undefined` | Quantidade de casas decimais. |
|
|
290
|
+
| `prettyPrecision` | `number` | `NaN` | Quantidade de zeros nos decimais. |
|
|
291
|
+
|
|
292
|
+
#### Returns
|
|
293
|
+
|
|
294
|
+
`string`
|
|
295
|
+
|
|
296
|
+
- Numeral em formato de String formatado em PT-BR.
|
|
297
|
+
|
|
298
|
+
#### Defined in
|
|
299
|
+
|
|
300
|
+
src/utils/NumberUtils.ts:143
|
|
238
301
|
|
|
239
302
|
___
|
|
240
303
|
|
package/dist/utils/ArrayUtils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { StringUtils } from "./StringUtils.js";
|
|
2
|
+
import { NumberUtils } from './NumberUtils.js';
|
|
2
3
|
/**
|
|
3
4
|
* `ArrayUtils`: Utilitário com a responsabilidade de manipular Arrays.
|
|
4
5
|
*/
|
|
@@ -39,7 +40,18 @@ export default class ArrayUtils {
|
|
|
39
40
|
* @returns - Array ordenado alfabeticamente..
|
|
40
41
|
*/
|
|
41
42
|
static sortAlphabetically(originalArray, fieldName = "label") {
|
|
42
|
-
return originalArray.sort((fieldA, fieldB) =>
|
|
43
|
+
return originalArray.sort((fieldA, fieldB) => {
|
|
44
|
+
const valueStringA = fieldA[fieldName];
|
|
45
|
+
const valueStringB = fieldB[fieldName];
|
|
46
|
+
const valueIntA = NumberUtils.stringToNumber(valueStringA);
|
|
47
|
+
const valueIntB = NumberUtils.stringToNumber(valueStringB);
|
|
48
|
+
if (isNaN(valueIntA) || isNaN(valueIntB)) {
|
|
49
|
+
return StringUtils.compare(valueStringA, valueStringB);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return NumberUtils.compare(valueIntA, valueIntB);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
43
55
|
}
|
|
44
56
|
}
|
|
45
57
|
//# sourceMappingURL=ArrayUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArrayUtils.js","sourceRoot":"","sources":["../../src/utils/ArrayUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC3B;;;;;;;;OAQG;IACH,MAAM,CAAC,iBAAiB,CAAC,QAAgB,EAAE,aAAyB,EAAE,sBAA+B,IAAI,EAAE,YAAoB,OAAO;QACnI,IAAG,CAAC,QAAQ,EAAC;YACR,OAAO,aAAa,CAAC;SACxB;QACD,MAAM,kBAAkB,GAAG,UAAU,CAAC,qBAAqB,CAAC,QAAQ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EAAE;YAC9C,MAAM,SAAS,GAAW,UAAU,CAAC,qBAAqB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;YAC5E,OAAO,SAAS,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QACH,OAAO,mBAAmB,CAAC,CAAC,CAAC,UAAU,CAAC,kBAAkB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;IACzG,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,qBAAqB,CAAC,QAAe;QAChD,OAAO,WAAW,CAAC,kCAAkC,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;IAClF,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,kBAAkB,CAAC,aAAyB,EAAE,YAAoB,OAAO;QAC5E,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;YAE3C,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;YACvC,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;YAEvC,MAAM,SAAS,GAAG,WAAW,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;YAC3D,MAAM,SAAS,GAAG,WAAW,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;YAE3D,IAAG,KAAK,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,EAAC;gBACtC,OAAO,WAAW,CAAC,OAAO,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;aACvD;iBAAM;gBACL,OAAO,WAAW,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;aAClD;QACH,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -22,12 +22,28 @@ export declare class NumberUtils {
|
|
|
22
22
|
* @param value - Numeral em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico - sem separador de milhares: ######.##).
|
|
23
23
|
* @param precision - Quantidade de casas decimais.
|
|
24
24
|
* @param prettyPrecision - Quantidade de zeros nos decimais.
|
|
25
|
+
* @param defaultValue - Valor padrão caso o value não seja um valor numérico válido.
|
|
25
26
|
*
|
|
26
27
|
* @returns - Numeral em formato de String formatado em PT-BR.
|
|
27
28
|
* @example
|
|
28
29
|
* Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
30
|
+
* Informado: (undefined, 3, 3) | Retorna: NaN
|
|
31
|
+
* Informado: (undefined, 3, 3, '0,00') | Retorna: 0,00
|
|
29
32
|
*/
|
|
30
|
-
static format: (value: string, precision: number, prettyPrecision?: number) => string;
|
|
33
|
+
static format: (value: string, precision: number, prettyPrecision?: number, defaultValue?: string) => string;
|
|
34
|
+
/**
|
|
35
|
+
* Formata o numeral com a precisão informada e o valor default 0,00 caso o value não seja um numero valido.
|
|
36
|
+
*
|
|
37
|
+
* @param value - Numeral em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico - sem separador de milhares: ######.##).
|
|
38
|
+
* @param precision - Quantidade de casas decimais.
|
|
39
|
+
* @param prettyPrecision - Quantidade de zeros nos decimais.
|
|
40
|
+
*
|
|
41
|
+
* @returns - Numeral em formato de String formatado em PT-BR.
|
|
42
|
+
* @example
|
|
43
|
+
* Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
44
|
+
* Informado: (undefined, 3, 3) | Retorna: 0,00
|
|
45
|
+
*/
|
|
46
|
+
static safeFormat: (value: string, precision: number, prettyPrecision?: number) => string;
|
|
31
47
|
/**
|
|
32
48
|
* Retira os separadores de milhar de um numeral em formato de string.
|
|
33
49
|
*
|
|
@@ -100,4 +116,12 @@ export declare class NumberUtils {
|
|
|
100
116
|
* Informo: ("100.16", 3) | 100.16
|
|
101
117
|
*/
|
|
102
118
|
static round(value: number, decimals?: number): number;
|
|
119
|
+
/**
|
|
120
|
+
* Determina a ordem de umeros.
|
|
121
|
+
*
|
|
122
|
+
* @param a - Primeio número para comparação.
|
|
123
|
+
* @param b - Segundo número para comparação.
|
|
124
|
+
* @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.
|
|
125
|
+
*/
|
|
126
|
+
static compare(a: number, b: number): number;
|
|
103
127
|
}
|
|
@@ -32,6 +32,28 @@ export class NumberUtils {
|
|
|
32
32
|
const multiplier = Math.pow(10, decimals);
|
|
33
33
|
return Math.round(value * multiplier) / multiplier;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Determina a ordem de umeros.
|
|
37
|
+
*
|
|
38
|
+
* @param a - Primeio número para comparação.
|
|
39
|
+
* @param b - Segundo número para comparação.
|
|
40
|
+
* @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.
|
|
41
|
+
*/
|
|
42
|
+
static compare(a, b) {
|
|
43
|
+
if (a === undefined) {
|
|
44
|
+
return b === undefined ? 0 : 1;
|
|
45
|
+
}
|
|
46
|
+
else if (b === undefined) {
|
|
47
|
+
return -1;
|
|
48
|
+
}
|
|
49
|
+
if (a === null) {
|
|
50
|
+
return b === null ? 0 : 1;
|
|
51
|
+
}
|
|
52
|
+
else if (b === null) {
|
|
53
|
+
return -1;
|
|
54
|
+
}
|
|
55
|
+
return a > b ? 1 : (a < b ? -1 : 0);
|
|
56
|
+
}
|
|
35
57
|
}
|
|
36
58
|
/**
|
|
37
59
|
* Converte o dado numérico de string para number.
|
|
@@ -83,18 +105,21 @@ NumberUtils.stringToNumber = (value) => {
|
|
|
83
105
|
* @param value - Numeral em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico - sem separador de milhares: ######.##).
|
|
84
106
|
* @param precision - Quantidade de casas decimais.
|
|
85
107
|
* @param prettyPrecision - Quantidade de zeros nos decimais.
|
|
108
|
+
* @param defaultValue - Valor padrão caso o value não seja um valor numérico válido.
|
|
86
109
|
*
|
|
87
110
|
* @returns - Numeral em formato de String formatado em PT-BR.
|
|
88
111
|
* @example
|
|
89
112
|
* Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
113
|
+
* Informado: (undefined, 3, 3) | Retorna: NaN
|
|
114
|
+
* Informado: (undefined, 3, 3, '0,00') | Retorna: 0,00
|
|
90
115
|
*/
|
|
91
|
-
NumberUtils.format = (value, precision, prettyPrecision = NaN) => {
|
|
116
|
+
NumberUtils.format = (value, precision, prettyPrecision = NaN, defaultValue = NaN.toString()) => {
|
|
92
117
|
if (value === '' || value === undefined || value === "NaN") {
|
|
93
|
-
return
|
|
118
|
+
return defaultValue;
|
|
94
119
|
}
|
|
95
120
|
const newValue = NumberUtils.stringToNumber(value);
|
|
96
121
|
if (isNaN(newValue)) {
|
|
97
|
-
return
|
|
122
|
+
return defaultValue;
|
|
98
123
|
}
|
|
99
124
|
//Validation "precision":
|
|
100
125
|
// Case1: precision < 0 => does not use precision
|
|
@@ -131,6 +156,21 @@ NumberUtils.format = (value, precision, prettyPrecision = NaN) => {
|
|
|
131
156
|
return newValueStr;
|
|
132
157
|
};
|
|
133
158
|
/**
|
|
159
|
+
* Formata o numeral com a precisão informada e o valor default 0,00 caso o value não seja um numero valido.
|
|
160
|
+
*
|
|
161
|
+
* @param value - Numeral em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico - sem separador de milhares: ######.##).
|
|
162
|
+
* @param precision - Quantidade de casas decimais.
|
|
163
|
+
* @param prettyPrecision - Quantidade de zeros nos decimais.
|
|
164
|
+
*
|
|
165
|
+
* @returns - Numeral em formato de String formatado em PT-BR.
|
|
166
|
+
* @example
|
|
167
|
+
* Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
168
|
+
* Informado: (undefined, 3, 3) | Retorna: 0,00
|
|
169
|
+
*/
|
|
170
|
+
NumberUtils.safeFormat = (value, precision, prettyPrecision = NaN) => {
|
|
171
|
+
return NumberUtils.format(value, precision, prettyPrecision, "0,00");
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
134
174
|
* Retira os separadores de milhar de um numeral em formato de string.
|
|
135
175
|
*
|
|
136
176
|
* @param value - Numeral em formato de string a ser convertido.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberUtils.js","sourceRoot":"","sources":["../../src/utils/NumberUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,mCAAmC,GAAW,qCAAqC,CAAC;AAE1F;;GAEG;AACH,MAAM,OAAO,WAAW;
|
|
1
|
+
{"version":3,"file":"NumberUtils.js","sourceRoot":"","sources":["../../src/utils/NumberUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,mCAAmC,GAAW,qCAAqC,CAAC;AAE1F;;GAEG;AACH,MAAM,OAAO,WAAW;IA+NpB;;;;;;;;;;;;;;;;;;;;;;;MAuBE;IACF,MAAM,CAAC,KAAK,CAAC,KAAa,EAAE,WAAmB,CAAC;QAC5C,MAAM,UAAU,GAAG,SAAA,EAAE,EAAI,QAAQ,CAAA,CAAC;QAClC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,UAAU,CAAC;IACvD,CAAC;IAEA;;;;;;MAME;IACH,MAAM,CAAC,OAAO,CAAC,CAAS,EAAE,CAAS;QAE/B,IAAG,CAAC,KAAK,SAAS,EAAC;YACf,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAClC;aAAM,IAAG,CAAC,KAAK,SAAS,EAAC;YACtB,OAAO,CAAC,CAAC,CAAC;SACb;QAED,IAAG,CAAC,KAAK,IAAI,EAAC;YACV,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC7B;aAAM,IAAG,CAAC,KAAK,IAAI,EAAC;YACjB,OAAO,CAAC,CAAC,C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@
|
|
|
1
1
|
import { StringUtils } from "./StringUtils.js";
|
|
2
|
+
import { NumberUtils } from './NumberUtils.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* `ArrayUtils`: Utilitário com a responsabilidade de manipular Arrays.
|
|
@@ -37,11 +38,24 @@ export default class ArrayUtils {
|
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
40
|
* Ordena valores de um array alfabeticamente.
|
|
40
|
-
*
|
|
41
|
+
*
|
|
41
42
|
* @param originalArray - Array a ser ordenado.
|
|
42
43
|
* @returns - Array ordenado alfabeticamente..
|
|
43
44
|
*/
|
|
44
45
|
static sortAlphabetically(originalArray: Array<any>, fieldName: string = "label"): Array<any>{
|
|
45
|
-
return originalArray.sort((fieldA, fieldB) =>
|
|
46
|
+
return originalArray.sort((fieldA, fieldB) => {
|
|
47
|
+
|
|
48
|
+
const valueStringA = fieldA[fieldName];
|
|
49
|
+
const valueStringB = fieldB[fieldName];
|
|
50
|
+
|
|
51
|
+
const valueIntA = NumberUtils.stringToNumber(valueStringA);
|
|
52
|
+
const valueIntB = NumberUtils.stringToNumber(valueStringB);
|
|
53
|
+
|
|
54
|
+
if(isNaN(valueIntA) || isNaN(valueIntB)){
|
|
55
|
+
return StringUtils.compare(valueStringA, valueStringB)
|
|
56
|
+
} else {
|
|
57
|
+
return NumberUtils.compare(valueIntA, valueIntB);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
46
60
|
}
|
|
47
61
|
}
|
package/src/utils/NumberUtils.ts
CHANGED
|
@@ -66,21 +66,24 @@ export class NumberUtils {
|
|
|
66
66
|
* @param value - Numeral em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico - sem separador de milhares: ######.##).
|
|
67
67
|
* @param precision - Quantidade de casas decimais.
|
|
68
68
|
* @param prettyPrecision - Quantidade de zeros nos decimais.
|
|
69
|
+
* @param defaultValue - Valor padrão caso o value não seja um valor numérico válido.
|
|
69
70
|
*
|
|
70
71
|
* @returns - Numeral em formato de String formatado em PT-BR.
|
|
71
72
|
* @example
|
|
72
73
|
* Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
74
|
+
* Informado: (undefined, 3, 3) | Retorna: NaN
|
|
75
|
+
* Informado: (undefined, 3, 3, '0,00') | Retorna: 0,00
|
|
73
76
|
*/
|
|
74
|
-
static format = (value: string, precision: number, prettyPrecision: number = NaN): string => {
|
|
77
|
+
static format = (value: string, precision: number, prettyPrecision: number = NaN, defaultValue:string = NaN.toString()): string => {
|
|
75
78
|
|
|
76
79
|
if (value === '' || value === undefined || value === "NaN") {
|
|
77
|
-
return
|
|
80
|
+
return defaultValue;
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
const newValue: number = NumberUtils.stringToNumber(value);
|
|
81
84
|
|
|
82
85
|
if (isNaN(newValue)) {
|
|
83
|
-
return
|
|
86
|
+
return defaultValue;
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
//Validation "precision":
|
|
@@ -122,9 +125,24 @@ export class NumberUtils {
|
|
|
122
125
|
|
|
123
126
|
|
|
124
127
|
return newValueStr;
|
|
128
|
+
}
|
|
125
129
|
|
|
126
130
|
|
|
127
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Formata o numeral com a precisão informada e o valor default 0,00 caso o value não seja um numero valido.
|
|
133
|
+
*
|
|
134
|
+
* @param value - Numeral em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico - sem separador de milhares: ######.##).
|
|
135
|
+
* @param precision - Quantidade de casas decimais.
|
|
136
|
+
* @param prettyPrecision - Quantidade de zeros nos decimais.
|
|
137
|
+
*
|
|
138
|
+
* @returns - Numeral em formato de String formatado em PT-BR.
|
|
139
|
+
* @example
|
|
140
|
+
* Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
141
|
+
* Informado: (undefined, 3, 3) | Retorna: 0,00
|
|
142
|
+
*/
|
|
143
|
+
static safeFormat = (value: string, precision: number, prettyPrecision: number = NaN): string => {
|
|
144
|
+
return NumberUtils.format(value, precision, prettyPrecision, "0,00");
|
|
145
|
+
}
|
|
128
146
|
|
|
129
147
|
|
|
130
148
|
/**
|
|
@@ -238,4 +256,28 @@ export class NumberUtils {
|
|
|
238
256
|
const multiplier = 10 ** decimals;
|
|
239
257
|
return Math.round(value * multiplier) / multiplier;
|
|
240
258
|
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Determina a ordem de umeros.
|
|
262
|
+
*
|
|
263
|
+
* @param a - Primeio número para comparação.
|
|
264
|
+
* @param b - Segundo número para comparação.
|
|
265
|
+
* @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.
|
|
266
|
+
*/
|
|
267
|
+
static compare(a: number, b: number): number{
|
|
268
|
+
|
|
269
|
+
if(a === undefined){
|
|
270
|
+
return b === undefined ? 0 : 1;
|
|
271
|
+
} else if(b === undefined){
|
|
272
|
+
return -1;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if(a === null){
|
|
276
|
+
return b === null ? 0 : 1;
|
|
277
|
+
} else if(b === null){
|
|
278
|
+
return -1;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return a > b ? 1 : (a < b ? -1 : 0);
|
|
282
|
+
}
|
|
241
283
|
}
|