@sankhyalabs/core 0.0.0-bugfix-dev-KB-6165.0
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/.nojekyll +1 -0
- package/.docs/README.md +63 -0
- package/.docs/classes/ApplicationContext.md +90 -0
- package/.docs/classes/ArrayUtils.md +99 -0
- package/.docs/classes/AuthorizedServiceCaller.md +76 -0
- package/.docs/classes/Change.md +190 -0
- package/.docs/classes/DataUnit.md +2453 -0
- package/.docs/classes/DataUnitAction.md +96 -0
- package/.docs/classes/DataUnitStorage.md +116 -0
- package/.docs/classes/DateUtils.md +327 -0
- package/.docs/classes/ElementIDUtils.md +308 -0
- package/.docs/classes/ErrorException.md +214 -0
- package/.docs/classes/ErrorTracking.md +62 -0
- package/.docs/classes/FloatingManager.md +530 -0
- package/.docs/classes/HTMLBuilder.md +45 -0
- package/.docs/classes/HttpProvider.md +96 -0
- package/.docs/classes/JSUtils.md +115 -0
- package/.docs/classes/MaskFormatter-1.md +347 -0
- package/.docs/classes/NumberUtils.md +335 -0
- package/.docs/classes/ObjectUtils.md +160 -0
- package/.docs/classes/OnboardingUtils.md +126 -0
- package/.docs/classes/PromiseSync.md +91 -0
- package/.docs/classes/ReadyUtil.md +115 -0
- package/.docs/classes/RequestMetadata.md +84 -0
- package/.docs/classes/SelectionInfo.md +168 -0
- package/.docs/classes/SkwHttpProvider.md +109 -0
- package/.docs/classes/StringUtils.md +562 -0
- package/.docs/classes/TimeFormatter.md +98 -0
- package/.docs/classes/UserAgentUtils.md +58 -0
- package/.docs/classes/VersionUtils.md +42 -0
- package/.docs/classes/WaitingChangeException.md +200 -0
- package/.docs/classes/WarningException.md +214 -0
- package/.docs/enums/Action.md +294 -0
- package/.docs/enums/ChangeOperation.md +52 -0
- package/.docs/enums/DataType.md +63 -0
- package/.docs/enums/DependencyType.md +41 -0
- package/.docs/enums/SelectionMode.md +30 -0
- package/.docs/enums/SortMode.md +30 -0
- package/.docs/enums/UserInterface.md +195 -0
- package/.docs/interfaces/ChildDescriptor.md +41 -0
- package/.docs/interfaces/ChildLink.md +30 -0
- package/.docs/interfaces/DUActionInterceptor.md +29 -0
- package/.docs/interfaces/ExecutionContext.md +58 -0
- package/.docs/interfaces/FieldDescriptor.md +140 -0
- package/.docs/interfaces/Filter.md +41 -0
- package/.docs/interfaces/IElementIDInfo.md +30 -0
- package/.docs/interfaces/LoadDataRequest.md +101 -0
- package/.docs/interfaces/LoadDataResponse.md +36 -0
- package/.docs/interfaces/PageRequest.md +41 -0
- package/.docs/interfaces/PaginationInfo.md +75 -0
- package/.docs/interfaces/PromiseSyncCallback.md +39 -0
- package/.docs/interfaces/QuickFilter.md +41 -0
- package/.docs/interfaces/Record.md +62 -0
- package/.docs/interfaces/SavedRecord.md +85 -0
- package/.docs/interfaces/Sort.md +41 -0
- package/.docs/interfaces/SortingProvider.md +29 -0
- package/.docs/interfaces/UnitMetadata.md +52 -0
- package/.docs/interfaces/WaitingChange.md +41 -0
- package/.docs/modules/MaskFormatter.md +37 -0
- package/.docs/modules.md +74 -0
- package/.docs/package.json +15 -0
- package/.eslintignore +2 -0
- package/.eslintrc.cjs +35 -0
- package/.husky/commit-msg +4 -0
- package/.releaserc +58 -0
- package/README.md +62 -0
- package/commitlint.config.cjs +14 -0
- package/dist/async/PromiseSync.d.ts +29 -0
- package/dist/async/PromiseSync.js +31 -0
- package/dist/async/PromiseSync.js.map +1 -0
- package/dist/dataunit/DataUnit.d.ts +924 -0
- package/dist/dataunit/DataUnit.js +1621 -0
- package/dist/dataunit/DataUnit.js.map +1 -0
- package/dist/dataunit/DataUnitStorage.d.ts +24 -0
- package/dist/dataunit/DataUnitStorage.js +39 -0
- package/dist/dataunit/DataUnitStorage.js.map +1 -0
- package/dist/dataunit/formatting/PrettyFormatter.d.ts +2 -0
- package/dist/dataunit/formatting/PrettyFormatter.js +94 -0
- package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -0
- package/dist/dataunit/loading/LoadDataRequest.d.ts +19 -0
- package/dist/dataunit/loading/LoadDataRequest.js +2 -0
- package/dist/dataunit/loading/LoadDataRequest.js.map +1 -0
- package/dist/dataunit/loading/LoadDataResponse.d.ts +9 -0
- package/dist/dataunit/loading/LoadDataResponse.js +2 -0
- package/dist/dataunit/loading/LoadDataResponse.js.map +1 -0
- package/dist/dataunit/loading/PaginationInfo.d.ts +13 -0
- package/dist/dataunit/loading/PaginationInfo.js +2 -0
- package/dist/dataunit/loading/PaginationInfo.js.map +1 -0
- package/dist/dataunit/metadata/DataType.d.ts +54 -0
- package/dist/dataunit/metadata/DataType.js +124 -0
- package/dist/dataunit/metadata/DataType.js.map +1 -0
- package/dist/dataunit/metadata/UnitMetadata.d.ts +88 -0
- package/dist/dataunit/metadata/UnitMetadata.js +36 -0
- package/dist/dataunit/metadata/UnitMetadata.js.map +1 -0
- package/dist/dataunit/state/HistReducer.d.ts +10 -0
- package/dist/dataunit/state/HistReducer.js +28 -0
- package/dist/dataunit/state/HistReducer.js.map +1 -0
- package/dist/dataunit/state/StateManager.d.ts +57 -0
- package/dist/dataunit/state/StateManager.js +97 -0
- package/dist/dataunit/state/StateManager.js.map +1 -0
- package/dist/dataunit/state/action/DataUnitAction.d.ts +40 -0
- package/dist/dataunit/state/action/DataUnitAction.js +42 -0
- package/dist/dataunit/state/action/DataUnitAction.js.map +1 -0
- package/dist/dataunit/state/slice/AddedRecordsSlice.d.ts +12 -0
- package/dist/dataunit/state/slice/AddedRecordsSlice.js +30 -0
- package/dist/dataunit/state/slice/AddedRecordsSlice.js.map +1 -0
- package/dist/dataunit/state/slice/ChangesSlice.d.ts +13 -0
- package/dist/dataunit/state/slice/ChangesSlice.js +105 -0
- package/dist/dataunit/state/slice/ChangesSlice.js.map +1 -0
- package/dist/dataunit/state/slice/InvalidFieldsSlice.d.ts +10 -0
- package/dist/dataunit/state/slice/InvalidFieldsSlice.js +66 -0
- package/dist/dataunit/state/slice/InvalidFieldsSlice.js.map +1 -0
- package/dist/dataunit/state/slice/LoadingControlSlice.d.ts +19 -0
- package/dist/dataunit/state/slice/LoadingControlSlice.js +45 -0
- package/dist/dataunit/state/slice/LoadingControlSlice.js.map +1 -0
- package/dist/dataunit/state/slice/RecordsSlice.d.ts +11 -0
- package/dist/dataunit/state/slice/RecordsSlice.js +62 -0
- package/dist/dataunit/state/slice/RecordsSlice.js.map +1 -0
- package/dist/dataunit/state/slice/RemovedRecordsSlice.d.ts +9 -0
- package/dist/dataunit/state/slice/RemovedRecordsSlice.js +25 -0
- package/dist/dataunit/state/slice/RemovedRecordsSlice.js.map +1 -0
- package/dist/dataunit/state/slice/SelectionSlice.d.ts +19 -0
- package/dist/dataunit/state/slice/SelectionSlice.js +155 -0
- package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -0
- package/dist/dataunit/state/slice/SnapshotSlice.d.ts +19 -0
- package/dist/dataunit/state/slice/SnapshotSlice.js +106 -0
- package/dist/dataunit/state/slice/SnapshotSlice.js.map +1 -0
- package/dist/dataunit/state/slice/UnitMetadataSlice.d.ts +11 -0
- package/dist/dataunit/state/slice/UnitMetadataSlice.js +21 -0
- package/dist/dataunit/state/slice/UnitMetadataSlice.js.map +1 -0
- package/dist/dataunit/state/slice/WaitingChangesSlice.d.ts +12 -0
- package/dist/dataunit/state/slice/WaitingChangesSlice.js +56 -0
- package/dist/dataunit/state/slice/WaitingChangesSlice.js.map +1 -0
- package/dist/exceptions/ErrorException.d.ts +14 -0
- package/dist/exceptions/ErrorException.js +13 -0
- package/dist/exceptions/ErrorException.js.map +1 -0
- package/dist/exceptions/WaitingChangeException.d.ts +12 -0
- package/dist/exceptions/WaitingChangeException.js +12 -0
- package/dist/exceptions/WaitingChangeException.js.map +1 -0
- package/dist/exceptions/WarningException.d.ts +14 -0
- package/dist/exceptions/WarningException.js +13 -0
- package/dist/exceptions/WarningException.js.map +1 -0
- package/dist/html/HTMLBuilder.d.ts +3 -0
- package/dist/html/HTMLBuilder.js +9 -0
- package/dist/html/HTMLBuilder.js.map +1 -0
- package/dist/http/AuthorizedServiceCaller.d.ts +11 -0
- package/dist/http/AuthorizedServiceCaller.js +54 -0
- package/dist/http/AuthorizedServiceCaller.js.map +1 -0
- package/dist/http/HttpProvider.d.ts +25 -0
- package/dist/http/HttpProvider.js +74 -0
- package/dist/http/HttpProvider.js.map +1 -0
- package/dist/http/RequestMetadata.d.ts +30 -0
- package/dist/http/RequestMetadata.js +25 -0
- package/dist/http/RequestMetadata.js.map +1 -0
- package/dist/http/SkwHttpProvider.d.ts +9 -0
- package/dist/http/SkwHttpProvider.js +67 -0
- package/dist/http/SkwHttpProvider.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/traking/ErrorTraking.d.ts +19 -0
- package/dist/traking/ErrorTraking.js +34 -0
- package/dist/traking/ErrorTraking.js.map +1 -0
- package/dist/ui/FloatingManager.d.ts +164 -0
- package/dist/ui/FloatingManager.js +358 -0
- package/dist/ui/FloatingManager.js.map +1 -0
- package/dist/utils/ApplicationContext.d.ts +26 -0
- package/dist/utils/ApplicationContext.js +38 -0
- package/dist/utils/ApplicationContext.js.map +1 -0
- package/dist/utils/ArrayUtils.d.ts +29 -0
- package/dist/utils/ArrayUtils.js +57 -0
- package/dist/utils/ArrayUtils.js.map +1 -0
- package/dist/utils/CriteriaModel.d.ts +107 -0
- package/dist/utils/CriteriaModel.js +172 -0
- package/dist/utils/CriteriaModel.js.map +1 -0
- package/dist/utils/CriteriaParameter.d.ts +69 -0
- package/dist/utils/CriteriaParameter.js +83 -0
- package/dist/utils/CriteriaParameter.js.map +1 -0
- package/dist/utils/DateUtils.d.ts +97 -0
- package/dist/utils/DateUtils.js +171 -0
- package/dist/utils/DateUtils.js.map +1 -0
- package/dist/utils/ElementIDUtils.d.ts +72 -0
- package/dist/utils/ElementIDUtils.js +161 -0
- package/dist/utils/ElementIDUtils.js.map +1 -0
- package/dist/utils/JSUtils.d.ts +36 -0
- package/dist/utils/JSUtils.js +66 -0
- package/dist/utils/JSUtils.js.map +1 -0
- package/dist/utils/MaskFormatter.d.ts +148 -0
- package/dist/utils/MaskFormatter.js +356 -0
- package/dist/utils/MaskFormatter.js.map +1 -0
- package/dist/utils/NumberUtils.d.ts +127 -0
- package/dist/utils/NumberUtils.js +245 -0
- package/dist/utils/NumberUtils.js.map +1 -0
- package/dist/utils/ObjectUtils.d.ts +47 -0
- package/dist/utils/ObjectUtils.js +68 -0
- package/dist/utils/ObjectUtils.js.map +1 -0
- package/dist/utils/OnboardingUtils.d.ts +17 -0
- package/dist/utils/OnboardingUtils.js +41 -0
- package/dist/utils/OnboardingUtils.js.map +1 -0
- package/dist/utils/ReadyUtil.d.ts +24 -0
- package/dist/utils/ReadyUtil.js +41 -0
- package/dist/utils/ReadyUtil.js.map +1 -0
- package/dist/utils/StringUtils.d.ts +167 -0
- package/dist/utils/StringUtils.js +328 -0
- package/dist/utils/StringUtils.js.map +1 -0
- package/dist/utils/TimeFormatter.d.ts +33 -0
- package/dist/utils/TimeFormatter.js +98 -0
- package/dist/utils/TimeFormatter.js.map +1 -0
- package/dist/utils/UserAgentUtils/index.d.ts +15 -0
- package/dist/utils/UserAgentUtils/index.js +48 -0
- package/dist/utils/UserAgentUtils/index.js.map +1 -0
- package/dist/utils/UserAgentUtils/navigatorAgentList.d.ts +17 -0
- package/dist/utils/UserAgentUtils/navigatorAgentList.js +40 -0
- package/dist/utils/UserAgentUtils/navigatorAgentList.js.map +1 -0
- package/dist/utils/VersionUtils.d.ts +7 -0
- package/dist/utils/VersionUtils.js +31 -0
- package/dist/utils/VersionUtils.js.map +1 -0
- package/jest.config.ts +17 -0
- package/mock/http/XMLHttpRequest-mock.js +26 -0
- package/package.json +52 -0
- package/scripts/runlink.bat +1 -0
- package/scripts/runlink.sh +1 -0
- package/src/async/PromiseSync.ts +49 -0
- package/src/dataunit/DataUnit.ts +1835 -0
- package/src/dataunit/DataUnitStorage.ts +43 -0
- package/src/dataunit/formatting/PrettyFormatter.ts +113 -0
- package/src/dataunit/loading/LoadDataRequest.ts +26 -0
- package/src/dataunit/loading/LoadDataResponse.ts +11 -0
- package/src/dataunit/loading/PaginationInfo.ts +18 -0
- package/src/dataunit/metadata/DataType.ts +127 -0
- package/src/dataunit/metadata/UnitMetadata.ts +102 -0
- package/src/dataunit/state/HistReducer.ts +34 -0
- package/src/dataunit/state/StateManager.ts +142 -0
- package/src/dataunit/state/action/DataUnitAction.ts +67 -0
- package/src/dataunit/state/slice/AddedRecordsSlice.ts +48 -0
- package/src/dataunit/state/slice/ChangesSlice.ts +125 -0
- package/src/dataunit/state/slice/InvalidFieldsSlice.ts +85 -0
- package/src/dataunit/state/slice/LoadingControlSlice.ts +60 -0
- package/src/dataunit/state/slice/RecordsSlice.ts +74 -0
- package/src/dataunit/state/slice/RemovedRecordsSlice.ts +30 -0
- package/src/dataunit/state/slice/SelectionSlice.ts +193 -0
- package/src/dataunit/state/slice/SnapshotSlice.ts +139 -0
- package/src/dataunit/state/slice/UnitMetadataSlice.ts +30 -0
- package/src/dataunit/state/slice/WaitingChangesSlice.ts +74 -0
- package/src/exceptions/ErrorException.ts +25 -0
- package/src/exceptions/WaitingChangeException.ts +21 -0
- package/src/exceptions/WarningException.ts +26 -0
- package/src/html/HTMLBuilder.ts +8 -0
- package/src/http/AuthorizedServiceCaller.ts +58 -0
- package/src/http/HttpProvider.ts +94 -0
- package/src/http/RequestMetadata.ts +42 -0
- package/src/http/SkwHttpProvider.ts +78 -0
- package/src/index.ts +93 -0
- package/src/traking/ErrorTraking.ts +37 -0
- package/src/ui/FloatingManager.ts +417 -0
- package/src/utils/ApplicationContext.ts +42 -0
- package/src/utils/ArrayUtils.ts +61 -0
- package/src/utils/CriteriaModel.ts +205 -0
- package/src/utils/CriteriaParameter.ts +108 -0
- package/src/utils/DateUtils.ts +195 -0
- package/src/utils/ElementIDUtils.ts +184 -0
- package/src/utils/JSUtils.ts +69 -0
- package/src/utils/MaskFormatter.ts +407 -0
- package/src/utils/NumberUtils.ts +283 -0
- package/src/utils/ObjectUtils.ts +76 -0
- package/src/utils/OnboardingUtils.ts +46 -0
- package/src/utils/ReadyUtil.ts +45 -0
- package/src/utils/StringUtils.ts +359 -0
- package/src/utils/TimeFormatter.ts +98 -0
- package/src/utils/UserAgentUtils/index.ts +62 -0
- package/src/utils/UserAgentUtils/navigatorAgentList.ts +39 -0
- package/src/utils/VersionUtils.ts +37 -0
- package/test/http/HttpProvider.spec.ts +35 -0
- package/test/http/SkwHttpProvider.ts.spec.ts +34 -0
- package/test/util/CriteriaModel.spec.ts +232 -0
- package/test/util/CriteriaParameter.spec.ts +52 -0
- package/test/util/DataUnitStorage.spec.ts +63 -0
- package/test/util/ElementIDUtils.spec.ts +272 -0
- package/test/util/MaskFormatter.spec.ts +138 -0
- package/test/util/NumberUtils.spec.ts +182 -0
- package/test/util/StringUtils.spec.ts +51 -0
- package/test/util/TimeFormatter.spec.ts +26 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { StringUtils } from "./StringUtils.js";
|
|
2
|
+
|
|
3
|
+
const NUMBERINPUTS_REGEX_SCIENTIFIC_PARTS: RegExp = /^([+-])?(\d+).?(\d*)[eE]([-+]?\d+)$/;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `NumberUtils`: Utilizado para manipulação de numerais.
|
|
7
|
+
*/
|
|
8
|
+
export class NumberUtils {
|
|
9
|
+
/**
|
|
10
|
+
* Converte o dado numérico de string para number.
|
|
11
|
+
*
|
|
12
|
+
* @param value Numeral em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico: ######.##).
|
|
13
|
+
* @returns - Numeral passado.
|
|
14
|
+
* @example
|
|
15
|
+
* @"100,12" | 100.12
|
|
16
|
+
* @"100.12" | 100.12
|
|
17
|
+
* @"-100,12" | -100.12
|
|
18
|
+
* @"R$100,12" | 100.12
|
|
19
|
+
* @"-R$100,12" | -100.12
|
|
20
|
+
* @"string" | NaN
|
|
21
|
+
*/
|
|
22
|
+
static stringToNumber = (value: string): number => {
|
|
23
|
+
|
|
24
|
+
if (value === '' || value === null || value === undefined) {
|
|
25
|
+
return NaN;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (value) {
|
|
29
|
+
value = value.toString();
|
|
30
|
+
|
|
31
|
+
const negative = (value.charAt(0) === '-');
|
|
32
|
+
|
|
33
|
+
if (!NUMBERINPUTS_REGEX_SCIENTIFIC_PARTS.test(value)) {
|
|
34
|
+
value = value.replace(/[^\d.,]/g, '');
|
|
35
|
+
} else {
|
|
36
|
+
value = value.replace(/^-/g, '');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//In case of simple string such as: "@@@@@@@"
|
|
40
|
+
if (value === '') {
|
|
41
|
+
return Number(NaN);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const indexV = value.indexOf(',');
|
|
45
|
+
const indexP = value.indexOf('.');
|
|
46
|
+
|
|
47
|
+
if (indexP > indexV) {
|
|
48
|
+
value = value.replace(',', '');
|
|
49
|
+
} else if (indexP < indexV) {
|
|
50
|
+
value = value.replace(/\./g, '@').replace(',', '.').replace(/@/g, '');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (negative) {
|
|
54
|
+
value = '-' + value;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return Number(value);
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Formata o numeral com a precisão informada.
|
|
65
|
+
*
|
|
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
|
+
* @param precision - Quantidade de casas decimais.
|
|
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.
|
|
70
|
+
*
|
|
71
|
+
* @returns - Numeral em formato de String formatado em PT-BR.
|
|
72
|
+
* @example
|
|
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
|
|
76
|
+
*/
|
|
77
|
+
static format = (value: string, precision: number, prettyPrecision: number = NaN, defaultValue:string = NaN.toString()): string => {
|
|
78
|
+
|
|
79
|
+
if (value === '' || value === undefined || value === "NaN") {
|
|
80
|
+
return defaultValue;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const newValue: number = NumberUtils.stringToNumber(value);
|
|
84
|
+
|
|
85
|
+
if (isNaN(newValue)) {
|
|
86
|
+
return defaultValue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//Validation "precision":
|
|
90
|
+
// Case1: precision < 0 => does not use precision
|
|
91
|
+
// Case2: presicion not int => does not use precision
|
|
92
|
+
if (precision < 0 || Math.abs(Math.round(precision * 1) / 1) !== precision) {
|
|
93
|
+
//Once stringToNumber returns number format, we need to change to pt-br
|
|
94
|
+
return NumberUtils.changeFormat(newValue.toString());
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
//Validation "prettyPrecision"
|
|
99
|
+
let prettyPrecisionInternal: number = 0;
|
|
100
|
+
// Case1: prettyPrecision < 0 => prettyPrecision does not change de format that means: prettyPrecisionInternal = precision;
|
|
101
|
+
// Case2: prettyPrecision not int => prettyPrecision does not change de format that means: prettyPrecisionInternal = precision;
|
|
102
|
+
if (isNaN(prettyPrecision) || Math.abs(Math.round(prettyPrecision * 1) / 1) !== prettyPrecision) {
|
|
103
|
+
prettyPrecisionInternal = precision;
|
|
104
|
+
} else {
|
|
105
|
+
prettyPrecisionInternal = prettyPrecision;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let newValueStr: string;
|
|
109
|
+
newValueStr = (Math.round(newValue * Math.pow(10, precision)) / Math.pow(10, precision)).toLocaleString('pt-br', { minimumFractionDigits: precision });
|
|
110
|
+
|
|
111
|
+
//prettyPrecision
|
|
112
|
+
const varSettingPP: number = precision - prettyPrecisionInternal;
|
|
113
|
+
if (varSettingPP > 0) {
|
|
114
|
+
for (let i = 0; i < varSettingPP; i++) {
|
|
115
|
+
if (newValueStr.substring(newValueStr.length - 1) == "0" && precision > 0) {
|
|
116
|
+
newValueStr = newValueStr.substring(0, newValueStr.length - 1);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
//in Case "." or "," in the end of the string
|
|
122
|
+
if (newValueStr.substring(newValueStr.length - 1) == "." || newValueStr.substring(newValueStr.length - 1) == ",") {
|
|
123
|
+
newValueStr = newValueStr.substring(0, newValueStr.length - 1);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
return newValueStr;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
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
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Retira os separadores de milhar de um numeral em formato de string.
|
|
150
|
+
*
|
|
151
|
+
* @param value - Numeral em formato de string a ser convertido.
|
|
152
|
+
* @param formatnumber - Formatação de ENTRADA e SAÍDA do utilitário: pt-BR="###.###,##" en-US="###,###.##"; Default: "pt-BR".
|
|
153
|
+
*
|
|
154
|
+
* @returns - Numeral em formato de string formatado apenas com separador decimal.
|
|
155
|
+
* @example
|
|
156
|
+
* Informado: '95.12' | Retorna: '9512'
|
|
157
|
+
*/
|
|
158
|
+
static keepOnlyDecimalSeparator = (value: string, formatnumber: string = 'pt-BR'): string => {
|
|
159
|
+
|
|
160
|
+
//Formatting formatnumber to be able to get lowercases
|
|
161
|
+
formatnumber = formatnumber.toUpperCase();
|
|
162
|
+
|
|
163
|
+
//Formatting value following formatnumber parameter
|
|
164
|
+
//keep only decimal character in order to correct format the string
|
|
165
|
+
//This transformation is due the "stringtoNumber" method is a general method that tries to convert all formated strings
|
|
166
|
+
if (formatnumber === 'EN-US') {
|
|
167
|
+
value = value.replace(/\,/g, '');
|
|
168
|
+
} else {
|
|
169
|
+
value = value.replace(/\./g, '');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return value;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Troca o formato do numeral(string) de "PT-BR" para "EN-US" e vice-versa.
|
|
177
|
+
*
|
|
178
|
+
* @param value - Numeral em formato de string a ser convertido.
|
|
179
|
+
*
|
|
180
|
+
* @returns - Numeral em formato de string formatado de "PT-BR" para "EN-US" e vice-versa.
|
|
181
|
+
* @example
|
|
182
|
+
* Informo: "15,55" | Obtenho: "15.55"
|
|
183
|
+
* @example
|
|
184
|
+
* Informo: "27.99" | Obtenho: "27,99"
|
|
185
|
+
*/
|
|
186
|
+
static changeFormat = (value: string): string => {
|
|
187
|
+
//Formatting output following formatnumber
|
|
188
|
+
return value.replace(/\./g, '_').replace(/\,/g, '.').replace(/\_/g, ',');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Obtém o valor ou o valor padrão, caso o valor seja inválido(NaN/undefined).
|
|
195
|
+
*
|
|
196
|
+
* @param value - Valor a ser validado.
|
|
197
|
+
* @param defaultValue - Valor padrão a ser retornado caso o value seja inválido.
|
|
198
|
+
*
|
|
199
|
+
* @returns - O próprio numeral passado ou zero.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* Informo: value: 30, defaultValue: 0 | Obtenho: 30
|
|
203
|
+
* @example
|
|
204
|
+
* Informo: value: "30", defaultValue: 0 | Obtenho: 30
|
|
205
|
+
* @example
|
|
206
|
+
* Informo: value: "30abc", defaultValue: 0 | Obtenho: 0
|
|
207
|
+
*/
|
|
208
|
+
static getValueOrDefault = (value: any, defaultValue: number): number => {
|
|
209
|
+
value = StringUtils.isEmpty(value) ? undefined : value;
|
|
210
|
+
value = Number(value);
|
|
211
|
+
|
|
212
|
+
if (isNaN(value)){
|
|
213
|
+
return Number(defaultValue);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return value;
|
|
217
|
+
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Obtém o valor ou zero, caso o valor seja inválido(NaN/undefined).
|
|
222
|
+
*
|
|
223
|
+
* @param value - Numeral a ser validado.
|
|
224
|
+
*
|
|
225
|
+
* @returns - O próprio numeral passado. Caso esse seja inválido retorna zero.
|
|
226
|
+
*/
|
|
227
|
+
static getValueOrZero = (value: any): number => {
|
|
228
|
+
return NumberUtils.getValueOrDefault(value, 0);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Realiza o arredondamento de casas decimais de um numero.
|
|
233
|
+
*
|
|
234
|
+
* @param value - Numeral a ser arredondado.
|
|
235
|
+
* @param decimals - Quantidade de casas decimais ussada no arredondamento.
|
|
236
|
+
*
|
|
237
|
+
* @returns - O próprio numeral arredondado com a quantidade de casas decimais do argumento decimals.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* Informo: (100.12) | 100.12
|
|
241
|
+
* Informo: (100,12) | NaN
|
|
242
|
+
|
|
243
|
+
* Informo: ("100.12", 1) | 100.1
|
|
244
|
+
* Informo: ("100.12", 2) | 100.12
|
|
245
|
+
* Informo: ("100.12", 3) | 100.12
|
|
246
|
+
|
|
247
|
+
* Informo: ("100.15", 1) | 100.2
|
|
248
|
+
* Informo: ("100.15", 2) | 100.15
|
|
249
|
+
* Informo: ("100.15", 3) | 100.15
|
|
250
|
+
|
|
251
|
+
* Informo: ("100.16", 1) | 100.2
|
|
252
|
+
* Informo: ("100.16", 2) | 100.16
|
|
253
|
+
* Informo: ("100.16", 3) | 100.16
|
|
254
|
+
*/
|
|
255
|
+
static round(value: number, decimals: number = 2):number {
|
|
256
|
+
const multiplier = 10 ** decimals;
|
|
257
|
+
return Math.round(value * multiplier) / multiplier;
|
|
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
|
+
}
|
|
283
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ObjectUtils`: Utilizado para manipulação de objetos.
|
|
3
|
+
*/
|
|
4
|
+
export default class ObjectUtils{
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Faz a cópia do objeto.
|
|
9
|
+
*
|
|
10
|
+
* @param data - Objeto a ser copiado.
|
|
11
|
+
* @returns - A cópia do objeto válido.
|
|
12
|
+
*/
|
|
13
|
+
public static copy<T>(data:Object | Array<Object>): T {
|
|
14
|
+
return this.stringToObject(this.objectToString(data)) as T;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Converte um objeto em string/JSON.
|
|
19
|
+
*
|
|
20
|
+
* @param data - Objeto a ser convertido.
|
|
21
|
+
* @returns - Uma string JSON.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* @Informado: ```{nome : "Sankhya", cidade: "Uberlandia"}``` | Obtenho: ```"{"nome" : "Sankhya", "cidade":"Uberlandia"}"```
|
|
25
|
+
*/
|
|
26
|
+
public static objectToString(data:Object | Array<Object>):string{
|
|
27
|
+
return JSON.stringify(data);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Converte uma string/JSON em objeto.
|
|
32
|
+
*
|
|
33
|
+
* @param data - String a ser convertida.
|
|
34
|
+
* @returns - Um objeto válido.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* Informado: ```"{"nome" : "Sankhya", "cidade":"Uberlandia"}"``` | Obtenho: ```{nome : "Sankhya", cidade: "Uberlandia"}```
|
|
38
|
+
*/
|
|
39
|
+
public static stringToObject(data:string):Object | Array<Object>{
|
|
40
|
+
return JSON.parse(data)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Faz a ordenação de um objeto por uma propriedade.
|
|
45
|
+
*
|
|
46
|
+
* @param data - Objeto a ser ordenado.
|
|
47
|
+
* @param property - Nome da propriedade a ser ordenada.
|
|
48
|
+
* @returns - O objeto ordenado pela propriedade.
|
|
49
|
+
*/
|
|
50
|
+
public static sortByProperty(data: any, property: string): any {
|
|
51
|
+
return Object.keys(data)
|
|
52
|
+
.sort(function(keyA: string, keyB: string) { // Ordenação pela `property`
|
|
53
|
+
const x = data[keyA][property];
|
|
54
|
+
const y = data[keyB][property];
|
|
55
|
+
return x < y ? -1 : x > y ? 1 : 0;
|
|
56
|
+
}).reduce((obj: any, key: string) => { // Reconstrução do Objeto de retorno
|
|
57
|
+
obj[key] = data[key];
|
|
58
|
+
return obj;
|
|
59
|
+
}, {});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Remove atributos nulos e indefinidos de um objeto.
|
|
64
|
+
*
|
|
65
|
+
* @param data - Objeto a ser filtrado.
|
|
66
|
+
* @returns - O objeto com as propriedades válidas.
|
|
67
|
+
*/
|
|
68
|
+
public static removeEmptyValues(obj: object): object {
|
|
69
|
+
return Object.fromEntries(
|
|
70
|
+
Object.entries(obj)
|
|
71
|
+
.filter(([, v]) => v != null)
|
|
72
|
+
.map(([k, v]) => [k, v === Object(v) ? ObjectUtils.removeEmptyValues(v) : v])
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export class OnboardingUtils {
|
|
2
|
+
private static readonly USER_GUIDE_TAG_ID = "userGuideSnippet";
|
|
3
|
+
private static instance: OnboardingUtils;
|
|
4
|
+
|
|
5
|
+
private constructor(){}
|
|
6
|
+
|
|
7
|
+
public static getInstance(): OnboardingUtils {
|
|
8
|
+
if(this.instance == null){
|
|
9
|
+
this.instance = new OnboardingUtils();
|
|
10
|
+
}
|
|
11
|
+
return this.instance;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public init(apiKey: string, ctx: EnvironmentContext): Promise<void> {
|
|
15
|
+
if(!apiKey){
|
|
16
|
+
return Promise.resolve();
|
|
17
|
+
}
|
|
18
|
+
this.injectScript(apiKey);
|
|
19
|
+
this.register(ctx);
|
|
20
|
+
return Promise.resolve();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private injectScript(apiKey: string){
|
|
24
|
+
if(window.document.head.querySelector(`script#${OnboardingUtils.USER_GUIDE_TAG_ID}`)){
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const scriptEl = document.createElement('script');
|
|
29
|
+
scriptEl.setAttribute("id", OnboardingUtils.USER_GUIDE_TAG_ID);
|
|
30
|
+
scriptEl.innerText = `(function(g,u,i,d,e,s){g[e]=g[e]||[];var f=u.getElementsByTagName(i)[0];var k=u.createElement(i);k.async=true;k.src='https://static.userguiding.com/media/user-guiding-'+s+'-embedded.js';f.parentNode.insertBefore(k,f);if(g[d])return;var ug=g[d]={q:[]};ug.c=function(n){return function(){ug.q.push([n,arguments])};};var m=['previewGuide','finishPreview','track','identify','hideChecklist','launchChecklist'];for(var j=0;j<m.length;j+=1){ug[m[j]]=ug.c(m[j]);}})(window,document,'script','userGuiding','userGuidingLayer','${apiKey}');`;
|
|
31
|
+
window.document.head.appendChild(scriptEl);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private register(ctx: EnvironmentContext){
|
|
35
|
+
(window as any).userGuiding.identify(`${ctx.userID}-${ctx.userName}-${ctx.clientGaId}`, ctx);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class EnvironmentContext {
|
|
40
|
+
userID: string = "";
|
|
41
|
+
userName: string = "";
|
|
42
|
+
partnerName: string = "";
|
|
43
|
+
sysVersion: string = "";
|
|
44
|
+
environment: string = "";
|
|
45
|
+
clientGaId: string = "";
|
|
46
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ReadyUtil`: Registra processos que serão invocados após a conclusão de operações.
|
|
3
|
+
*/
|
|
4
|
+
export default class ReadyUtil{
|
|
5
|
+
private resolve:any;
|
|
6
|
+
private promise:any;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Limpa o estado da instancia ao finalizar a execução do processo registrado.
|
|
10
|
+
*/
|
|
11
|
+
private clean() {
|
|
12
|
+
this.resolve = undefined;
|
|
13
|
+
this.promise = undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Inicializa o estado da instancia ao registrar processo.
|
|
18
|
+
*/
|
|
19
|
+
private start() {
|
|
20
|
+
if(!this.promise) this.promise = new Promise((accept) => {
|
|
21
|
+
this.resolve = () => accept(true);
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Executa processo atribuído.
|
|
27
|
+
*/
|
|
28
|
+
end(){
|
|
29
|
+
this.resolve && this.resolve();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Atribui processo que será executado por operações que o invocarem no método 'end'.
|
|
34
|
+
* @returns Promise que deve conter o código do processo.
|
|
35
|
+
*/
|
|
36
|
+
whenReady(){
|
|
37
|
+
this.start();
|
|
38
|
+
return new Promise((accept) => {
|
|
39
|
+
this.promise.then(() => {
|
|
40
|
+
accept(true);
|
|
41
|
+
this.clean();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|