@sankhyalabs/core 6.0.1 → 6.1.0-dev.2
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/Change.md +11 -11
- package/.docs/classes/DataUnit.md +230 -122
- package/.docs/classes/FieldComparator.md +6 -2
- package/.docs/classes/KeyboardManager.md +99 -9
- package/.docs/classes/LockManager.md +4 -4
- package/.docs/classes/ObjectUtils.md +50 -2
- package/.docs/classes/SelectionInfo.md +12 -12
- package/.docs/classes/StringUtils.md +10 -10
- package/.docs/enumerations/Action.md +41 -31
- package/.docs/enumerations/ChangeOperation.md +4 -4
- package/.docs/enumerations/SelectionMode.md +2 -2
- package/.docs/enumerations/UserInterface.md +15 -5
- package/.docs/interfaces/DUActionInterceptor.md +1 -1
- package/.docs/interfaces/PageRequest.md +3 -3
- package/.docs/interfaces/QuickFilter.md +3 -3
- package/.docs/interfaces/Record.md +4 -4
- package/.docs/interfaces/SavedRecord.md +5 -5
- package/.docs/interfaces/WaitingChange.md +3 -3
- package/.docs/type-aliases/DataUnitEventOptions.md +1 -1
- package/dist/dataunit/DataUnit.d.ts +19 -0
- package/dist/dataunit/DataUnit.js +43 -3
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/formatting/PrettyFormatter.js +8 -3
- package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
- package/dist/dataunit/metadata/DataType.d.ts +1 -1
- package/dist/dataunit/metadata/DataType.js +7 -4
- package/dist/dataunit/metadata/DataType.js.map +1 -1
- package/dist/dataunit/metadata/UnitMetadata.d.ts +1 -0
- package/dist/dataunit/metadata/UnitMetadata.js +1 -0
- package/dist/dataunit/metadata/UnitMetadata.js.map +1 -1
- package/dist/dataunit/sorting/FieldComparator.d.ts +2 -2
- package/dist/dataunit/sorting/FieldComparator.js +4 -4
- package/dist/dataunit/sorting/FieldComparator.js.map +1 -1
- package/dist/dataunit/state/action/DataUnitAction.d.ts +1 -0
- package/dist/dataunit/state/action/DataUnitAction.js +1 -0
- package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
- package/dist/utils/KeyboardManager/index.d.ts +9 -0
- package/dist/utils/KeyboardManager/index.js +45 -1
- package/dist/utils/KeyboardManager/index.js.map +1 -1
- package/dist/utils/KeyboardManager/interface.d.ts +1 -0
- package/dist/utils/LockManager.js.map +1 -1
- package/dist/utils/ObjectUtils.d.ts +14 -0
- package/dist/utils/ObjectUtils.js +20 -0
- package/dist/utils/ObjectUtils.js.map +1 -1
- package/dist/utils/SortingUtils.js +9 -1
- package/dist/utils/SortingUtils.js.map +1 -1
- package/dist/utils/StringUtils.js +12 -6
- package/dist/utils/StringUtils.js.map +1 -1
- package/package.json +1 -1
- package/reports/test-report.xml +669 -124
- package/src/dataunit/DataUnit.ts +51 -3
- package/src/dataunit/formatting/PrettyFormatter.ts +8 -5
- package/src/dataunit/metadata/DataType.ts +8 -4
- package/src/dataunit/metadata/UnitMetadata.ts +1 -0
- package/src/dataunit/sorting/FieldComparator.ts +4 -4
- package/src/dataunit/state/action/DataUnitAction.ts +2 -0
- package/src/utils/KeyboardManager/index.ts +57 -0
- package/src/utils/KeyboardManager/interface.ts +1 -0
- package/src/utils/LockManager.ts +0 -1
- package/src/utils/ObjectUtils.ts +21 -0
- package/src/utils/SortingUtils.ts +10 -1
- package/src/utils/StringUtils.ts +10 -6
- package/test/dataunit/formatting/PrettyFormatter.spec.ts +1 -1
- package/test/testCases/NumberUtilsTestCases.ts +190 -0
- package/test/testCases/StringUtilsTestCases.ts +435 -0
- package/test/testCases/TimeFormatterTestUtils.ts +43 -0
- package/test/util/NumberUtils.spec.ts +72 -150
- package/test/util/ObjectUtils.spec.ts +572 -0
- package/test/util/StringUtils.spec.ts +260 -36
- package/test/util/TimeFormatter.spec.ts +65 -18
- package/src/utils/test/objectUtils.spec.ts +0 -109
|
@@ -1,182 +1,104 @@
|
|
|
1
1
|
import { NumberUtils } from '../../src/utils/NumberUtils';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
{ valueInput: '11500', valueOutput: 11500 },
|
|
14
|
-
{ valueInput: '1.000', valueOutput: 1 },
|
|
15
|
-
{ valueInput: '11.500,003', valueOutput: 11500.003 },
|
|
16
|
-
{ valueInput: '-100', valueOutput: -100 },
|
|
17
|
-
{ valueInput: '-100,12', valueOutput: -100.12 },
|
|
18
|
-
{ valueInput: '-11500,1', valueOutput: -11500.1 },
|
|
19
|
-
{ valueInput: '-11500', valueOutput: -11500 },
|
|
20
|
-
{ valueInput: '-11.500,003', valueOutput: -11500.003 },
|
|
21
|
-
{ valueInput: 'R$100', valueOutput: 100 },
|
|
22
|
-
{ valueInput: 'R$100,12', valueOutput: 100.12 },
|
|
23
|
-
{ valueInput: 'R$11500,12', valueOutput: 11500.12 },
|
|
24
|
-
{ valueInput: 'R$11500', valueOutput: 11500 },
|
|
25
|
-
{ valueInput: 'R$11.500,003', valueOutput: 11500.003 },
|
|
26
|
-
{ valueInput: '-R$100', valueOutput: -100 },
|
|
27
|
-
{ valueInput: '-R$100,12', valueOutput: -100.12 },
|
|
28
|
-
{ valueInput: '-R$11500,12', valueOutput: -11500.12 },
|
|
29
|
-
{ valueInput: '-R$11500', valueOutput: -11500 },
|
|
30
|
-
{ valueInput: '-R$11.500,003', valueOutput: -11500.003 },
|
|
31
|
-
{ valueInput: '', valueOutput: NaN },
|
|
32
|
-
{ valueInput: 'OrdinaryString', valueOutput: NaN },
|
|
33
|
-
{ valueInput: '100.167.80', valueOutput: NaN },
|
|
34
|
-
{ valueInput: 'uahsuhas,auhsuhasu', valueOutput: NaN },
|
|
35
|
-
{ valueInput: '100,100,100', valueOutput: NaN },
|
|
36
|
-
{ valueInput: 'OrdinaryString,.OrdinaryString', valueOutput: NaN },
|
|
37
|
-
{ valueInput: 'OrdinaryString.,OrdinaryString', valueOutput: NaN },
|
|
38
|
-
{ valueInput: '.121212', valueOutput: 0.121212 },
|
|
39
|
-
{ valueInput: ',121212', valueOutput: 0.121212 },
|
|
40
|
-
{ valueInput: '1,232,333.345', valueOutput: NaN },
|
|
41
|
-
{ valueInput: '1232333,345', valueOutput: 1232333.345 },
|
|
42
|
-
]
|
|
43
|
-
|
|
44
|
-
it('stringToNumber', function () {
|
|
45
|
-
let result: number;
|
|
46
|
-
arrayDataTest.forEach(e => {
|
|
47
|
-
result = NumberUtils.stringToNumber(e.valueInput);
|
|
48
|
-
expect(result).toBe(e.valueOutput);
|
|
49
|
-
})
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
|
|
2
|
+
import {
|
|
3
|
+
changeFormatCases,
|
|
4
|
+
formatCases,
|
|
5
|
+
safeFormatCases,
|
|
6
|
+
keepOnlyDecimalSeparatorCases,
|
|
7
|
+
roundTestCases,
|
|
8
|
+
stringToNumberCases,
|
|
9
|
+
getValueOrDefaultCases,
|
|
10
|
+
getValueOrZeroCases,
|
|
11
|
+
compareCases,
|
|
12
|
+
} from '../testCases/NumberUtilsTestCases';
|
|
53
13
|
|
|
54
14
|
|
|
55
|
-
|
|
56
|
-
// ----------------------------------------------------------------------------------------
|
|
15
|
+
describe('NumberUtils', function() {
|
|
57
16
|
|
|
17
|
+
describe('stringToNumber', () => {
|
|
58
18
|
|
|
59
|
-
|
|
19
|
+
stringToNumberCases.forEach(e => {
|
|
20
|
+
it(`should return ${e.valueOutput} when value is ${e.valueInput}`, () => {
|
|
21
|
+
expect(NumberUtils.stringToNumber(e.valueInput)).toBe(e.valueOutput);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
60
24
|
|
|
61
|
-
|
|
62
|
-
{ precision: 2, prettyprecision: 1, strvalue: '1.000', strvalueOutPut: '1,0' },
|
|
63
|
-
{ precision: 2, prettyprecision: 1, strvalue: '1200999,99', strvalueOutPut: '1.200.999,99' },
|
|
64
|
-
{ precision: 4, prettyprecision: 2, strvalue: '1,232,333.345', strvalueOutPut: 'NaN' },
|
|
65
|
-
{ precision: 2, prettyprecision: 1, strvalue: '1,23', strvalueOutPut: '1,23' },
|
|
66
|
-
{ precision: 4, prettyprecision: 2, strvalue: '1.200.999', strvalueOutPut: 'NaN' },
|
|
67
|
-
{ precision: 4, prettyprecision: 0, strvalue: '1200.00001', strvalueOutPut: '1.200' },
|
|
68
|
-
{ precision: 4, prettyprecision: 0, strvalue: 'String', strvalueOutPut: 'NaN' },
|
|
69
|
-
{ precision: 4, prettyprecision: 0, strvalue: '', strvalueOutPut: 'NaN' },
|
|
70
|
-
|
|
71
|
-
{ precision: 4, prettyprecision: undefined, strvalue: '1.200.999,3333', strvalueOutPut: '1.200.999,3333' },
|
|
72
|
-
{ precision: 2, prettyprecision: undefined, strvalue: '1.000', strvalueOutPut: '1,00' },
|
|
73
|
-
{ precision: 2, prettyprecision: undefined, strvalue: '1200999,99', strvalueOutPut: '1.200.999,99' },
|
|
74
|
-
{ precision: 4, prettyprecision: undefined, strvalue: '1,232,333.345', strvalueOutPut: 'NaN' },
|
|
75
|
-
{ precision: 2, prettyprecision: undefined, strvalue: '1,23', strvalueOutPut: '1,23' },
|
|
76
|
-
{ precision: 4, prettyprecision: undefined, strvalue: '1.200.999', strvalueOutPut: 'NaN' },
|
|
77
|
-
{ precision: 4, prettyprecision: undefined, strvalue: 'NaN', strvalueOutPut: 'NaN' },
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
{ precision: 1, prettyprecision: -1, strvalue: '111,199', strvalueOutPut: '111,2' },
|
|
81
|
-
{ precision: 1, prettyprecision: -1, strvalue: '111,1000', strvalueOutPut: '111,1' },
|
|
82
|
-
{ precision: 1, prettyprecision: 1.3, strvalue: '111,100', strvalueOutPut: '111,1' },
|
|
83
|
-
{ precision: -1, prettyprecision: 1, strvalue: '111,1009', strvalueOutPut: '111,1009' },
|
|
84
|
-
{ precision: -1, prettyprecision: 1, strvalue: '111,1000', strvalueOutPut: '111,1' },
|
|
85
|
-
{ precision: 1.2, prettyprecision: 1, strvalue: '111,1009', strvalueOutPut: '111,1009' },
|
|
25
|
+
});
|
|
86
26
|
|
|
87
27
|
|
|
88
|
-
|
|
89
|
-
{ precision: 2, prettyprecision: -1, strvalue: '111,1000', strvalueOutPut: '111,10' },
|
|
90
|
-
{ precision: -2, prettyprecision: 1, strvalue: '111,1009', strvalueOutPut: '111,1009' },
|
|
91
|
-
{ precision: -2, prettyprecision: 1, strvalue: '111,1000', strvalueOutPut: '111,1' },
|
|
28
|
+
describe('format', () => {
|
|
92
29
|
|
|
30
|
+
formatCases.forEach(e => {
|
|
31
|
+
it(`should return ${e.strvalueOutPut} when: [ value: ${e.strvalue}, precision: ${e.precision}, prettyPrecision: ${e.prettyprecision} ]`, () => {
|
|
32
|
+
expect(NumberUtils.format(e.strvalue, e.precision, e.prettyprecision)).toBe(e.strvalueOutPut);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
93
35
|
|
|
94
|
-
|
|
36
|
+
});
|
|
95
37
|
|
|
96
38
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
})
|
|
39
|
+
describe('changeFormat', () => {
|
|
40
|
+
changeFormatCases.forEach(e => {
|
|
41
|
+
it(`should return ${e.outPutValue} when value is ${e.inputValue}`, () => {
|
|
42
|
+
expect(NumberUtils.changeFormat(e.inputValue)).toBe(e.outPutValue);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
103
45
|
|
|
104
46
|
});
|
|
105
47
|
|
|
106
48
|
|
|
49
|
+
describe('keepOnlyDecimalSeparator', () => {
|
|
107
50
|
|
|
51
|
+
keepOnlyDecimalSeparatorCases.forEach(e => {
|
|
52
|
+
it(`should return ${e.outPutValue} when: [ value: ${e.inputValue}, formatNumber: ${e.formatnumber} ]`, () => {
|
|
53
|
+
expect(NumberUtils.keepOnlyDecimalSeparator(e.inputValue, e.formatnumber)).toBe(e.outPutValue);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
108
56
|
|
|
109
|
-
|
|
110
|
-
// ----------------------------------------------------------------------------------------
|
|
111
|
-
const testCasesTo_changeFormat = [
|
|
112
|
-
|
|
113
|
-
{ inputValue: '1.200.999', outPutValue: '1,200,999' },
|
|
114
|
-
{ inputValue: '1.000,99', outPutValue: '1,000.99' },
|
|
115
|
-
{ inputValue: '1200999,99', outPutValue: '1200999.99' },
|
|
116
|
-
{ inputValue: 'R$ 1,232,333.345', outPutValue: 'R$ 1.232.333,345' },
|
|
117
|
-
{ inputValue: 'R$ 1.232.333,345', outPutValue: 'R$ 1,232,333.345' },
|
|
118
|
-
|
|
119
|
-
]
|
|
57
|
+
});
|
|
120
58
|
|
|
121
|
-
it('format without formatnumber parameter', function () {
|
|
122
|
-
let result: string = '';
|
|
123
|
-
testCasesTo_changeFormat.forEach(e => {
|
|
124
|
-
result = NumberUtils.changeFormat(e.inputValue);
|
|
125
|
-
expect(result).toBe(e.outPutValue);
|
|
126
|
-
})
|
|
127
59
|
|
|
60
|
+
describe('round', () => {
|
|
61
|
+
roundTestCases.forEach(e => {
|
|
62
|
+
it(`should return ${e.outPutValue} when: [ value: ${e.inputValue}, decimal: ${e.decimal} ]`, () => {
|
|
63
|
+
expect(NumberUtils.round(e.inputValue, e.decimal)).toBe(e.outPutValue);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
128
66
|
});
|
|
129
67
|
|
|
130
68
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
69
|
+
describe('safeFormat', () => {
|
|
70
|
+
safeFormatCases.forEach(e => {
|
|
71
|
+
it(`should return ${e.strvalueOutPut} when: [ value: ${e.strvalue}, precision: ${e.precision}, prettyPrecision: ${e.prettyprecision} ]`, () => {
|
|
72
|
+
expect(NumberUtils.safeFormat(e.strvalue, e.precision, e.prettyprecision)).toBe(e.strvalueOutPut);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
134
76
|
|
|
135
|
-
{ formatnumber: 'pt-BR', inputValue: '1.200.999', outPutValue: '1200999' },
|
|
136
|
-
{ formatnumber: 'pt-BR', inputValue: '1000,99', outPutValue: '1000,99' },
|
|
137
|
-
{ formatnumber: 'pt-BR', inputValue: '1200999,99', outPutValue: '1200999,99' },
|
|
138
|
-
{ formatnumber: 'pt-BR', inputValue: 'R$ 1.232.333,345', outPutValue: 'R$ 1232333,345' },
|
|
139
77
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
78
|
+
describe('getValueOrDefault', () => {
|
|
79
|
+
getValueOrDefaultCases.forEach(e => {
|
|
80
|
+
it(`should return ${e.expected} when value is ${e.value}`, () => {
|
|
81
|
+
expect(NumberUtils.getValueOrDefault(e.value, e.defaultValue)).toBe(e.expected);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
144
85
|
|
|
145
86
|
|
|
146
|
-
|
|
87
|
+
describe('getValueOrZero', () => {
|
|
88
|
+
getValueOrZeroCases.forEach(e => {
|
|
89
|
+
it(`should return ${e.expected} when value is ${e.value}`, () => {
|
|
90
|
+
expect(NumberUtils.getValueOrZero(e.value)).toBe(e.expected);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
147
94
|
|
|
148
|
-
it('format without formatnumber parameter', function () {
|
|
149
|
-
let result: string = '';
|
|
150
|
-
testCasesTo_keepOnlyDecimalSeparator.forEach(e => {
|
|
151
|
-
result = NumberUtils.keepOnlyDecimalSeparator(e.inputValue, e.formatnumber);
|
|
152
|
-
expect(result).toBe(e.outPutValue);
|
|
153
|
-
})
|
|
154
95
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
{ decimal: 2, inputValue: 100.12, outPutValue: 100.12 },
|
|
162
|
-
{ decimal: 3, inputValue: 100.12, outPutValue: 100.12 },
|
|
163
|
-
{ decimal: 1, inputValue: 100.15, outPutValue: 100.2 },
|
|
164
|
-
{ decimal: 2, inputValue: 100.15, outPutValue: 100.15 },
|
|
165
|
-
{ decimal: 3, inputValue: 100.15, outPutValue: 100.15 },
|
|
166
|
-
{ decimal: 1, inputValue: 100.16, outPutValue: 100.2 },
|
|
167
|
-
{ decimal: 2, inputValue: 100.16, outPutValue: 100.16 },
|
|
168
|
-
{ decimal: 3, inputValue: 100.16, outPutValue: 100.16 },
|
|
169
|
-
{ decimal: 12, inputValue: 2118000000000.0002, outPutValue: 2118000000000.0002 },
|
|
170
|
-
{ decimal: 5, inputValue: 123.45, outPutValue: 123.45 },
|
|
171
|
-
{ decimal: 0, inputValue: 123.45, outPutValue: 123 },
|
|
172
|
-
]
|
|
173
|
-
|
|
174
|
-
it('format round number', function () {
|
|
175
|
-
let result: number;
|
|
176
|
-
testCasesTo_round.forEach(e => {
|
|
177
|
-
result = NumberUtils.round(e.inputValue, e.decimal);
|
|
178
|
-
expect(result).toBe(e.outPutValue);
|
|
179
|
-
})
|
|
96
|
+
describe('compare', () => {
|
|
97
|
+
compareCases.forEach(({ a, b, expected }) => {
|
|
98
|
+
it(`should return ${expected} when comparing ${a} and ${b}`, () => {
|
|
99
|
+
expect(NumberUtils.compare(a, b)).toBe(expected);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
180
102
|
});
|
|
181
103
|
|
|
182
104
|
});
|