@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.
Files changed (71) hide show
  1. package/.docs/classes/Change.md +11 -11
  2. package/.docs/classes/DataUnit.md +230 -122
  3. package/.docs/classes/FieldComparator.md +6 -2
  4. package/.docs/classes/KeyboardManager.md +99 -9
  5. package/.docs/classes/LockManager.md +4 -4
  6. package/.docs/classes/ObjectUtils.md +50 -2
  7. package/.docs/classes/SelectionInfo.md +12 -12
  8. package/.docs/classes/StringUtils.md +10 -10
  9. package/.docs/enumerations/Action.md +41 -31
  10. package/.docs/enumerations/ChangeOperation.md +4 -4
  11. package/.docs/enumerations/SelectionMode.md +2 -2
  12. package/.docs/enumerations/UserInterface.md +15 -5
  13. package/.docs/interfaces/DUActionInterceptor.md +1 -1
  14. package/.docs/interfaces/PageRequest.md +3 -3
  15. package/.docs/interfaces/QuickFilter.md +3 -3
  16. package/.docs/interfaces/Record.md +4 -4
  17. package/.docs/interfaces/SavedRecord.md +5 -5
  18. package/.docs/interfaces/WaitingChange.md +3 -3
  19. package/.docs/type-aliases/DataUnitEventOptions.md +1 -1
  20. package/dist/dataunit/DataUnit.d.ts +19 -0
  21. package/dist/dataunit/DataUnit.js +43 -3
  22. package/dist/dataunit/DataUnit.js.map +1 -1
  23. package/dist/dataunit/formatting/PrettyFormatter.js +8 -3
  24. package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
  25. package/dist/dataunit/metadata/DataType.d.ts +1 -1
  26. package/dist/dataunit/metadata/DataType.js +7 -4
  27. package/dist/dataunit/metadata/DataType.js.map +1 -1
  28. package/dist/dataunit/metadata/UnitMetadata.d.ts +1 -0
  29. package/dist/dataunit/metadata/UnitMetadata.js +1 -0
  30. package/dist/dataunit/metadata/UnitMetadata.js.map +1 -1
  31. package/dist/dataunit/sorting/FieldComparator.d.ts +2 -2
  32. package/dist/dataunit/sorting/FieldComparator.js +4 -4
  33. package/dist/dataunit/sorting/FieldComparator.js.map +1 -1
  34. package/dist/dataunit/state/action/DataUnitAction.d.ts +1 -0
  35. package/dist/dataunit/state/action/DataUnitAction.js +1 -0
  36. package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
  37. package/dist/utils/KeyboardManager/index.d.ts +9 -0
  38. package/dist/utils/KeyboardManager/index.js +45 -1
  39. package/dist/utils/KeyboardManager/index.js.map +1 -1
  40. package/dist/utils/KeyboardManager/interface.d.ts +1 -0
  41. package/dist/utils/LockManager.js.map +1 -1
  42. package/dist/utils/ObjectUtils.d.ts +14 -0
  43. package/dist/utils/ObjectUtils.js +20 -0
  44. package/dist/utils/ObjectUtils.js.map +1 -1
  45. package/dist/utils/SortingUtils.js +9 -1
  46. package/dist/utils/SortingUtils.js.map +1 -1
  47. package/dist/utils/StringUtils.js +12 -6
  48. package/dist/utils/StringUtils.js.map +1 -1
  49. package/package.json +1 -1
  50. package/reports/test-report.xml +669 -124
  51. package/src/dataunit/DataUnit.ts +51 -3
  52. package/src/dataunit/formatting/PrettyFormatter.ts +8 -5
  53. package/src/dataunit/metadata/DataType.ts +8 -4
  54. package/src/dataunit/metadata/UnitMetadata.ts +1 -0
  55. package/src/dataunit/sorting/FieldComparator.ts +4 -4
  56. package/src/dataunit/state/action/DataUnitAction.ts +2 -0
  57. package/src/utils/KeyboardManager/index.ts +57 -0
  58. package/src/utils/KeyboardManager/interface.ts +1 -0
  59. package/src/utils/LockManager.ts +0 -1
  60. package/src/utils/ObjectUtils.ts +21 -0
  61. package/src/utils/SortingUtils.ts +10 -1
  62. package/src/utils/StringUtils.ts +10 -6
  63. package/test/dataunit/formatting/PrettyFormatter.spec.ts +1 -1
  64. package/test/testCases/NumberUtilsTestCases.ts +190 -0
  65. package/test/testCases/StringUtilsTestCases.ts +435 -0
  66. package/test/testCases/TimeFormatterTestUtils.ts +43 -0
  67. package/test/util/NumberUtils.spec.ts +72 -150
  68. package/test/util/ObjectUtils.spec.ts +572 -0
  69. package/test/util/StringUtils.spec.ts +260 -36
  70. package/test/util/TimeFormatter.spec.ts +65 -18
  71. package/src/utils/test/objectUtils.spec.ts +0 -109
@@ -1,182 +1,104 @@
1
1
  import { NumberUtils } from '../../src/utils/NumberUtils';
2
-
3
- describe('StringUtils', function () {
4
-
5
-
6
- // => STRING_TO_NUMBER
7
- // ----------------------------------------------------------------------------------------
8
-
9
- const arrayDataTest = [
10
- { valueInput: '100', valueOutput: 100 },
11
- { valueInput: '100,12', valueOutput: 100.12 },
12
- { valueInput: '11500,12', valueOutput: 11500.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
- // FORMAT
56
- // ----------------------------------------------------------------------------------------
15
+ describe('NumberUtils', function() {
57
16
 
17
+ describe('stringToNumber', () => {
58
18
 
59
- const casesStrValue = [
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
- { precision: 4, prettyprecision: 2, strvalue: '1.200.999,3333', strvalueOutPut: '1.200.999,3333' },
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
- { precision: 2, prettyprecision: -1, strvalue: '111,199', strvalueOutPut: '111,20' },
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
- it('format', function () {
98
- let result: string = '';
99
- casesStrValue.forEach(e => {
100
- result = NumberUtils.format(e.strvalue, e.precision, e.prettyprecision);
101
- expect(result).toBe(e.strvalueOutPut);
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
- // keepOnlyDecimalSeparator
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
- // keepOnlyDecimalSeparator
132
- // ----------------------------------------------------------------------------------------
133
- const testCasesTo_keepOnlyDecimalSeparator = [
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
- { formatnumber: 'en-US', inputValue: '1,200,999', outPutValue: '1200999' },
141
- { formatnumber: 'en-US', inputValue: '1,000.99', outPutValue: '1000.99' },
142
- { formatnumber: 'en-US', inputValue: '1200999.99', outPutValue: '1200999.99' },
143
- { formatnumber: 'en-US', inputValue: 'EUR 1,232,333.345', outPutValue: 'EUR 1232333.345' },
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
- const testCasesTo_round = [
159
- { decimal: undefined, inputValue: 100.12, outPutValue: 100.12 },
160
- { decimal: 1, inputValue: 100.12, outPutValue: 100.1 },
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
  });