@legalplace/wizardx-core 2.6.4 → 2.7.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/CHANGELOG.md +35 -0
- package/dist/App.js +13 -4
- package/dist/PluginLoader.d.ts +3 -1
- package/dist/PluginLoader.js +12 -0
- package/dist/ThemeLoader.d.ts +2 -2
- package/dist/componentsConnectors/connectBox.d.ts +3 -1
- package/dist/componentsConnectors/connectDocument.d.ts +3 -1
- package/dist/componentsConnectors/connectHeader.d.ts +3 -1
- package/dist/componentsConnectors/connectMetaTitle.d.ts +3 -1
- package/dist/componentsConnectors/connectOption.d.ts +6 -2
- package/dist/componentsConnectors/connectOption.js +1 -1
- package/dist/componentsConnectors/connectPagination.d.ts +3 -1
- package/dist/componentsConnectors/connectPreview.d.ts +3 -1
- package/dist/componentsConnectors/connectProgress.d.ts +3 -1
- package/dist/componentsConnectors/connectRootOption.d.ts +3 -1
- package/dist/componentsConnectors/connectSection.d.ts +3 -1
- package/dist/componentsConnectors/connectSection.js +7 -10
- package/dist/componentsConnectors/connectSummary.d.ts +3 -1
- package/dist/componentsConnectors/connectSummaryItem.d.ts +3 -1
- package/dist/componentsConnectors/connectVariable.d.ts +6 -2
- package/dist/componentsConnectors/connectVariable.js +1 -1
- package/dist/componentsConnectors/connectWizardWrapper.d.ts +3 -1
- package/dist/componentsConnectors/connector/componentConnector.d.ts +5 -1
- package/dist/componentsConnectors/connector/componentConnector.js +44 -4
- package/dist/componentsConnectors/connector/index.d.ts +1 -0
- package/dist/componentsConnectors/connector/index.js +1 -0
- package/dist/componentsConnectors/index.d.ts +17 -0
- package/dist/componentsConnectors/index.js +17 -0
- package/dist/componentsConnectors/library.d.ts +43 -15
- package/dist/helpers/apiEndpoint.d.ts +1 -0
- package/dist/helpers/apiEndpoint.js +4 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/propsEqualityCheck.d.ts +1 -0
- package/dist/helpers/propsEqualityCheck.js +9 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/useActions.d.ts +2 -0
- package/dist/hooks/useActions.js +4 -0
- package/dist/hooks/useDispatch.d.ts +1 -0
- package/dist/hooks/useDispatch.js +4 -0
- package/dist/hooks/useSelectors.d.ts +2 -0
- package/dist/hooks/useSelectors.js +4 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/libs/PathReader.d.ts +10 -6
- package/dist/libs/PathReader.js +47 -28
- package/dist/libs/index.d.ts +5 -0
- package/dist/libs/index.js +5 -0
- package/dist/redux/actions/index.d.ts +9 -0
- package/dist/redux/actions/index.js +9 -0
- package/dist/redux/actions/library.d.ts +59 -63
- package/dist/redux/actions/sagas/index.d.ts +3 -0
- package/dist/redux/actions/sagas/index.js +3 -0
- package/dist/redux/actions/sagas/model.d.ts +1 -5
- package/dist/redux/constants/app.d.ts +2 -0
- package/dist/redux/constants/app.js +2 -0
- package/dist/redux/constants/index.d.ts +8 -0
- package/dist/redux/constants/index.js +8 -0
- package/dist/redux/constants/sagas/index.d.ts +3 -0
- package/dist/redux/constants/sagas/index.js +3 -0
- package/dist/redux/index.d.ts +5 -0
- package/dist/redux/index.js +5 -0
- package/dist/redux/middlewares/conditionsWatcherMiddleware.js +11 -5
- package/dist/redux/middlewares/conditionsWatcherMiddleware.test.js +120 -113
- package/dist/redux/middlewares/paginationWatcherMiddleware.js +2 -2
- package/dist/redux/middlewares/smartscriptMiddleware.js +8 -0
- package/dist/redux/reducers/pluginsStore.d.ts +3 -0
- package/dist/redux/reducers/pluginsStore.js +12 -0
- package/dist/redux/routerHistory.js +2 -2
- package/dist/redux/sagas/fetchModel.js +22 -6
- package/dist/redux/sagas/initInputs.js +6 -7
- package/dist/redux/sagas/saveData.js +2 -0
- package/dist/redux/selectors/app.js +13 -18
- package/dist/redux/selectors/cache.d.ts +17 -0
- package/dist/redux/selectors/cache.js +35 -0
- package/dist/redux/selectors/conditions.js +7 -7
- package/dist/redux/selectors/index.d.ts +8 -0
- package/dist/redux/selectors/index.js +8 -0
- package/dist/redux/selectors/inputs.js +3 -3
- package/dist/redux/selectors/library.d.ts +2 -2
- package/dist/redux/selectors/references.js +26 -26
- package/dist/redux/selectors/selectors.d.ts +2 -2
- package/dist/redux/selectors/selectors.js +19 -8
- package/dist/redux/selectors/selectors.test.js +6 -6
- package/dist/redux/selectors/user.js +5 -5
- package/dist/redux/store.d.ts +1 -1
- package/dist/redux/store.js +12 -4
- package/dist/service/api.manager.d.ts +1 -6
- package/dist/service/index.d.ts +3 -0
- package/dist/service/index.js +3 -0
- package/dist/types/PluginConfig.type.d.ts +57 -0
- package/dist/types/PluginConfig.type.js +1 -0
- package/dist/types/State.type.d.ts +6 -0
- package/dist/types/config.type.d.ts +3 -1
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.js +11 -0
- package/package.json +11 -11
- package/.depcheckrc +0 -1
- package/.eslintignore +0 -2
- package/.eslintrc +0 -5
- package/__mocks__/fileMock.js +0 -1
- package/babel.config.json +0 -3
- package/jest.config.ts +0 -193
- package/setupJest.ts +0 -8
- package/src/App.test.tsx +0 -41
- package/src/App.tsx +0 -152
- package/src/Globals.ts +0 -69
- package/src/Loader.tsx +0 -8
- package/src/PluginLoader.test.tsx +0 -70
- package/src/PluginLoader.tsx +0 -407
- package/src/Shimmer.tsx +0 -108
- package/src/ThemeLoader.test.tsx +0 -82
- package/src/ThemeLoader.tsx +0 -95
- package/src/components/PluginRoute.tsx +0 -48
- package/src/components/SmartScript.tsx +0 -166
- package/src/components/UserLocked/UserLockedComponent.tsx +0 -33
- package/src/components/View.test.tsx +0 -110
- package/src/components/View.tsx +0 -114
- package/src/componentsConnectors/connectBox.test.tsx +0 -226
- package/src/componentsConnectors/connectBox.tsx +0 -70
- package/src/componentsConnectors/connectDocument.test.tsx +0 -108
- package/src/componentsConnectors/connectDocument.tsx +0 -64
- package/src/componentsConnectors/connectHeader.tsx +0 -21
- package/src/componentsConnectors/connectMetaTitle.test.tsx +0 -40
- package/src/componentsConnectors/connectMetaTitle.tsx +0 -8
- package/src/componentsConnectors/connectOption.tsx +0 -222
- package/src/componentsConnectors/connectPagination.tsx +0 -102
- package/src/componentsConnectors/connectPreview.tsx +0 -5
- package/src/componentsConnectors/connectProgress.tsx +0 -59
- package/src/componentsConnectors/connectRootOption.tsx +0 -95
- package/src/componentsConnectors/connectSection.tsx +0 -79
- package/src/componentsConnectors/connectSummary.tsx +0 -21
- package/src/componentsConnectors/connectSummaryItem.tsx +0 -102
- package/src/componentsConnectors/connectTermsheet.tsx +0 -359
- package/src/componentsConnectors/connectVariable.tsx +0 -191
- package/src/componentsConnectors/connectWizardWrapper.tsx +0 -30
- package/src/componentsConnectors/connector/componentConnector.tsx +0 -219
- package/src/componentsConnectors/library.ts +0 -35
- package/src/config.test.ts +0 -63
- package/src/config.ts +0 -11
- package/src/constants/emailValidation.ts +0 -2
- package/src/constants/phoneValidation.ts +0 -4
- package/src/definitions/path.join.d.ts +0 -4
- package/src/helpers/outputsParsing.ts +0 -412
- package/src/helpers/preloadTheme.ts +0 -17
- package/src/helpers/scriptsLoader.ts +0 -20
- package/src/hooks/usePrevious.ts +0 -9
- package/src/libs/ConditionsInitiator.ts +0 -164
- package/src/libs/ConditionsRunner/DataPopulator.ts +0 -266
- package/src/libs/ConditionsRunner.ts +0 -454
- package/src/libs/DocumentsOutputs.ts +0 -171
- package/src/libs/Eval/EvalBase.ts +0 -116
- package/src/libs/Eval/EvalFunctions.ts +0 -724
- package/src/libs/Eval/NumbersToLetters.ts +0 -185
- package/src/libs/EvalVariable.ts +0 -265
- package/src/libs/EventsTracking.ts +0 -250
- package/src/libs/InputsInitiator.ts +0 -136
- package/src/libs/NumAuto.test.ts +0 -55
- package/src/libs/NumAuto.ts +0 -56
- package/src/libs/OvcConverter.ts +0 -285
- package/src/libs/PathReader.ts +0 -272
- package/src/libs/SectionValidity.test.ts +0 -146
- package/src/libs/SectionValidity.ts +0 -110
- package/src/libs/SmartScriptStore.ts +0 -492
- package/src/misc/test_model.ts +0 -14603
- package/src/misc/test_models/connectDocumen.testmodel.json +0 -178
- package/src/misc/test_models/setDefaults.testmodel.json +0 -279
- package/src/misc/test_models/testmodel.json +0 -1
- package/src/polyfills/index.ts +0 -5
- package/src/polyfills/objectValues.ts +0 -4
- package/src/polyfills/prepend.ts +0 -31
- package/src/polyfills/stringRepeat.ts +0 -44
- package/src/redux/actions/app.test.ts +0 -123
- package/src/redux/actions/app.ts +0 -249
- package/src/redux/actions/conditions.test.ts +0 -84
- package/src/redux/actions/conditions.ts +0 -135
- package/src/redux/actions/inputs.test.ts +0 -85
- package/src/redux/actions/inputs.ts +0 -111
- package/src/redux/actions/library.ts +0 -23
- package/src/redux/actions/mandatories.ts +0 -98
- package/src/redux/actions/references.test.ts +0 -48
- package/src/redux/actions/references.ts +0 -37
- package/src/redux/actions/sagas/data.test.ts +0 -11
- package/src/redux/actions/sagas/data.ts +0 -18
- package/src/redux/actions/sagas/model.test.ts +0 -14
- package/src/redux/actions/sagas/model.ts +0 -48
- package/src/redux/actions/sagas/user.ts +0 -25
- package/src/redux/actions/smartscript.ts +0 -55
- package/src/redux/actions/user.test.ts +0 -18
- package/src/redux/actions/user.ts +0 -41
- package/src/redux/constants/app.ts +0 -36
- package/src/redux/constants/conditions.ts +0 -25
- package/src/redux/constants/inputs.ts +0 -15
- package/src/redux/constants/mandatories.ts +0 -11
- package/src/redux/constants/references.ts +0 -7
- package/src/redux/constants/sagas/data.ts +0 -1
- package/src/redux/constants/sagas/model.ts +0 -2
- package/src/redux/constants/sagas/user.ts +0 -2
- package/src/redux/constants/smartscript.ts +0 -9
- package/src/redux/constants/user.ts +0 -6
- package/src/redux/listeners/subscriber.test.ts +0 -45
- package/src/redux/listeners/subscriber.ts +0 -29
- package/src/redux/middlewares/conditionsWatcherMiddleware.test.ts +0 -370
- package/src/redux/middlewares/conditionsWatcherMiddleware.ts +0 -321
- package/src/redux/middlewares/evaluationsWatcherMiddleware.test.ts +0 -323
- package/src/redux/middlewares/evaluationsWatcherMiddleware.ts +0 -250
- package/src/redux/middlewares/mandatoriesWatcherMiddleware.ts +0 -473
- package/src/redux/middlewares/multiplesActionsMiddleware.test.ts +0 -230
- package/src/redux/middlewares/multiplesActionsMiddleware.ts +0 -121
- package/src/redux/middlewares/paginationWatcherMiddleware.ts +0 -251
- package/src/redux/middlewares/pluginsHookMiddleware.ts +0 -24
- package/src/redux/middlewares/prefillerWatcherMiddleware.test.ts +0 -118
- package/src/redux/middlewares/prefillerWatcherMiddleware.ts +0 -462
- package/src/redux/middlewares/smartscriptMiddleware.ts +0 -228
- package/src/redux/middlewares/thirdpartyScriptsMiddleware.ts +0 -41
- package/src/redux/reducers/app/customizations/initCustomizationAutoDefault.ts +0 -16
- package/src/redux/reducers/app/customizations/initCustomizationMeta.ts +0 -16
- package/src/redux/reducers/app/instance/initInstance.ts +0 -29
- package/src/redux/reducers/app/instance/setDataStatus.ts +0 -16
- package/src/redux/reducers/app/instance/updateInstance.ts +0 -30
- package/src/redux/reducers/app/instance/updateInstancePaid.ts +0 -20
- package/src/redux/reducers/app/instance.test.ts +0 -106
- package/src/redux/reducers/app/meta/fetchModelFailed.ts +0 -11
- package/src/redux/reducers/app/meta/fetchModelNonBlocking.ts +0 -11
- package/src/redux/reducers/app/meta/fetchModelSucceeded.ts +0 -11
- package/src/redux/reducers/app/meta/fetchModelUnhealthy.ts +0 -18
- package/src/redux/reducers/app/meta/fetchModelUserLocked.ts +0 -11
- package/src/redux/reducers/app/meta/initMeta.ts +0 -22
- package/src/redux/reducers/app/meta/setModelUuid.ts +0 -17
- package/src/redux/reducers/app/meta.test.ts +0 -90
- package/src/redux/reducers/app/pagination/goNextPage.ts +0 -69
- package/src/redux/reducers/app/pagination/goPage.ts +0 -81
- package/src/redux/reducers/app/pagination/goPreviousPage.ts +0 -60
- package/src/redux/reducers/app/pagination/initPagination.ts +0 -46
- package/src/redux/reducers/app/pagination/updateAvailableAppStates.ts +0 -77
- package/src/redux/reducers/app/pagination.test.ts +0 -363
- package/src/redux/reducers/app/wizard/updateAvailableSections.ts +0 -40
- package/src/redux/reducers/app/wizard.test.ts +0 -84
- package/src/redux/reducers/app.test.ts +0 -336
- package/src/redux/reducers/app.ts +0 -150
- package/src/redux/reducers/conditions/addMultipleOccurency.test.ts +0 -131
- package/src/redux/reducers/conditions/addMultipleOccurency.ts +0 -155
- package/src/redux/reducers/conditions/deleteMultipleOccurency.test.ts +0 -95
- package/src/redux/reducers/conditions/deleteMultipleOccurency.ts +0 -141
- package/src/redux/reducers/conditions/initConditions.ts +0 -18
- package/src/redux/reducers/conditions/updateDocumentConditions.test.ts +0 -47
- package/src/redux/reducers/conditions/updateDocumentConditions.ts +0 -21
- package/src/redux/reducers/conditions/updateOptionConditions.ts +0 -24
- package/src/redux/reducers/conditions/updateOptionValidatorCondition.test.ts +0 -50
- package/src/redux/reducers/conditions/updateOptionValidatorCondition.ts +0 -28
- package/src/redux/reducers/conditions/updatePrefillerConditions.ts +0 -29
- package/src/redux/reducers/conditions/updateSectionConditions.ts +0 -28
- package/src/redux/reducers/conditions/updateVariableConditions.ts +0 -25
- package/src/redux/reducers/conditions/updateVariableValidatorCondition.test.ts +0 -50
- package/src/redux/reducers/conditions/updateVariableValidatorCondition.ts +0 -28
- package/src/redux/reducers/conditions.test.ts +0 -241
- package/src/redux/reducers/conditions.ts +0 -68
- package/src/redux/reducers/inputs/addMultipleOccurency.test.ts +0 -117
- package/src/redux/reducers/inputs/addMultipleOccurency.ts +0 -50
- package/src/redux/reducers/inputs/deleteMultipleOccurency.test.ts +0 -70
- package/src/redux/reducers/inputs/deleteMultipleOccurency.ts +0 -50
- package/src/redux/reducers/inputs/initOption.ts +0 -16
- package/src/redux/reducers/inputs/initVariable.ts +0 -16
- package/src/redux/reducers/inputs/updateOptionInput.ts +0 -24
- package/src/redux/reducers/inputs/updateVariableInput.ts +0 -24
- package/src/redux/reducers/inputs.test.ts +0 -221
- package/src/redux/reducers/inputs.ts +0 -51
- package/src/redux/reducers/mandatories/addMultipleOccurency.ts +0 -52
- package/src/redux/reducers/mandatories/deleteMultipleOccurency.ts +0 -55
- package/src/redux/reducers/mandatories/initMandatoryOption.ts +0 -17
- package/src/redux/reducers/mandatories/initMandatoryVariable.ts +0 -17
- package/src/redux/reducers/mandatories/setMandatoryIgnore.ts +0 -17
- package/src/redux/reducers/mandatories/setMandatoryOption.ts +0 -25
- package/src/redux/reducers/mandatories/setMandatorySection.ts +0 -20
- package/src/redux/reducers/mandatories/setMandatoryVariable.ts +0 -24
- package/src/redux/reducers/mandatories.ts +0 -56
- package/src/redux/reducers/references/initReferences.ts +0 -37
- package/src/redux/reducers/references/updateOptionMeta.ts +0 -73
- package/src/redux/reducers/references/updateVariableMeta.ts +0 -72
- package/src/redux/reducers/references.ts +0 -59
- package/src/redux/reducers/smartscript/enableSmartScript.ts +0 -13
- package/src/redux/reducers/smartscript/initSmartScriptTriggers.ts +0 -14
- package/src/redux/reducers/smartscript/updateSmartscriptOptionHidden.ts +0 -30
- package/src/redux/reducers/smartscript/updateSmartscriptVariableHidden.ts +0 -30
- package/src/redux/reducers/smartscript.ts +0 -47
- package/src/redux/reducers/user/initUser.ts +0 -15
- package/src/redux/reducers/user/setUserStatus.ts +0 -13
- package/src/redux/reducers/user/setUserValidToken.ts +0 -13
- package/src/redux/reducers/user.test.ts +0 -51
- package/src/redux/reducers/user.ts +0 -40
- package/src/redux/routerHistore.test.ts +0 -19
- package/src/redux/routerHistory.ts +0 -26
- package/src/redux/sagas/fetchModel.test.ts +0 -76
- package/src/redux/sagas/fetchModel.ts +0 -683
- package/src/redux/sagas/homogeneousRadioInputsSaga.ts +0 -42
- package/src/redux/sagas/initInputs.ts +0 -110
- package/src/redux/sagas/runner.test.ts +0 -12
- package/src/redux/sagas/runner.ts +0 -26
- package/src/redux/sagas/saveData.test.ts +0 -125
- package/src/redux/sagas/saveData.ts +0 -55
- package/src/redux/sagas/setDefaults.test.ts +0 -100
- package/src/redux/sagas/setDefaults.ts +0 -167
- package/src/redux/sagas/setUserEmail.ts +0 -175
- package/src/redux/selectors/app.test.ts +0 -162
- package/src/redux/selectors/app.ts +0 -331
- package/src/redux/selectors/conditions.test.ts +0 -92
- package/src/redux/selectors/conditions.ts +0 -293
- package/src/redux/selectors/inputs.test.ts +0 -72
- package/src/redux/selectors/inputs.ts +0 -76
- package/src/redux/selectors/library.ts +0 -17
- package/src/redux/selectors/mandatories.ts +0 -83
- package/src/redux/selectors/references.test.ts +0 -660
- package/src/redux/selectors/references.ts +0 -413
- package/src/redux/selectors/selectors.test.ts +0 -21
- package/src/redux/selectors/selectors.ts +0 -87
- package/src/redux/selectors/smartscript.ts +0 -30
- package/src/redux/selectors/user.test.ts +0 -39
- package/src/redux/selectors/user.ts +0 -45
- package/src/redux/store.test.ts +0 -22
- package/src/redux/store.ts +0 -100
- package/src/service/api.manager.ts +0 -261
- package/src/service/auth.service.ts +0 -5
- package/src/service/pardot.service.ts +0 -10
- package/src/tests-misc/plugins/jestTestPlugin/after.tsx +0 -5
- package/src/tests-misc/plugins/jestTestPlugin/before.tsx +0 -11
- package/src/tests-misc/plugins/jestTestPlugin/index.ts +0 -11
- package/src/tests-misc/plugins/jestTestPlugin/title.tsx +0 -8
- package/src/tests-misc/themes/jestTestTheme/components/EmailComponent.tsx +0 -5
- package/src/tests-misc/themes/jestTestTheme/components/TermsheetComponent.tsx +0 -5
- package/src/tests-misc/themes/jestTestTheme/components/WizardComponent.tsx +0 -5
- package/src/tests-misc/themes/jestTestTheme/faltyIndex.ts +0 -3
- package/src/tests-misc/themes/jestTestTheme/faltyIndexLoader.ts +0 -1
- package/src/tests-misc/themes/jestTestTheme/index.ts +0 -13
- package/src/types/Actions.type.ts +0 -612
- package/src/types/Components.type.ts +0 -181
- package/src/types/State.type.ts +0 -323
- package/src/types/Termsheet.type.ts +0 -28
- package/src/types/api.type.ts +0 -37
- package/src/types/config.type.ts +0 -55
- package/src/types/env.type.ts +0 -5
- package/src/types/getActions.type.ts +0 -3
- package/src/types/getConnectors.type.ts +0 -5
- package/src/types/getSelectors.type.ts +0 -3
- package/src/wizard-params.ts +0 -56
- package/tsconfig.json +0 -43
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NumberToLetter
|
|
3
|
-
* --------------
|
|
4
|
-
* Converts numbers to letters, original code was written by GALA OUSSE Brice
|
|
5
|
-
* https://github.com/hbendalibraham/number-to-letters/blob/master/nombre_en_lettre.js
|
|
6
|
-
* --------------
|
|
7
|
-
* Library was rewritten in order to add typescript support and to handle errors with
|
|
8
|
-
* throws instead of simple string returns
|
|
9
|
-
*/
|
|
10
|
-
export class NumberToLetter {
|
|
11
|
-
static French(
|
|
12
|
-
number: string | number,
|
|
13
|
-
units: string | false = false,
|
|
14
|
-
decimals: string | false = false
|
|
15
|
-
): string {
|
|
16
|
-
const letter: Record<number, string> = {
|
|
17
|
-
0: "zéro",
|
|
18
|
-
1: "un",
|
|
19
|
-
2: "deux",
|
|
20
|
-
3: "trois",
|
|
21
|
-
4: "quatre",
|
|
22
|
-
5: "cinq",
|
|
23
|
-
6: "six",
|
|
24
|
-
7: "sept",
|
|
25
|
-
8: "huit",
|
|
26
|
-
9: "neuf",
|
|
27
|
-
10: "dix",
|
|
28
|
-
11: "onze",
|
|
29
|
-
12: "douze",
|
|
30
|
-
13: "treize",
|
|
31
|
-
14: "quatorze",
|
|
32
|
-
15: "quinze",
|
|
33
|
-
16: "seize",
|
|
34
|
-
17: "dix-sept",
|
|
35
|
-
18: "dix-huit",
|
|
36
|
-
19: "dix-neuf",
|
|
37
|
-
20: "vingt",
|
|
38
|
-
30: "trente",
|
|
39
|
-
40: "quarante",
|
|
40
|
-
50: "cinquante",
|
|
41
|
-
60: "soixante",
|
|
42
|
-
70: "soixante-dix",
|
|
43
|
-
80: "quatre-vingt",
|
|
44
|
-
90: "quatre-vingt-dix",
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
let quotient;
|
|
48
|
-
let left;
|
|
49
|
-
let numberToLetter = "";
|
|
50
|
-
|
|
51
|
-
// Validating number before proceeding
|
|
52
|
-
if (number.toString().replace(/ /gi, "").length > 15)
|
|
53
|
-
throw new Error("Capacity overrun");
|
|
54
|
-
if (Number.isNaN(number.toString().replace(/ /gi, "")))
|
|
55
|
-
throw new Error("Unvalid number");
|
|
56
|
-
|
|
57
|
-
// Parsing number
|
|
58
|
-
const nb = parseFloat(number.toString().replace(/ /gi, ""));
|
|
59
|
-
|
|
60
|
-
// Handling commas
|
|
61
|
-
if (Math.ceil(nb) !== nb) {
|
|
62
|
-
const [wholeNumberPart, decimalPart] = number.toString().split(".");
|
|
63
|
-
const decimalNumber = decimalPart?.startsWith("0")
|
|
64
|
-
? Array.from(decimalPart)
|
|
65
|
-
.map((decimal) => this.French(decimal))
|
|
66
|
-
.join(" ")
|
|
67
|
-
: this.French(decimalPart);
|
|
68
|
-
return (
|
|
69
|
-
this.French(wholeNumberPart) +
|
|
70
|
-
(units ? ` ${units} et ` : " virgule ") +
|
|
71
|
-
decimalNumber +
|
|
72
|
-
(decimals ? ` ${decimals}` : "")
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Converting number to letters
|
|
78
|
-
*/
|
|
79
|
-
const numberLength = nb.toString().length;
|
|
80
|
-
switch (numberLength) {
|
|
81
|
-
case 1:
|
|
82
|
-
numberToLetter = letter[nb];
|
|
83
|
-
break;
|
|
84
|
-
case 2:
|
|
85
|
-
if (nb > 19) {
|
|
86
|
-
quotient = Math.floor(nb / 10);
|
|
87
|
-
left = nb % 10;
|
|
88
|
-
if (nb < 71 || (nb > 79 && nb < 91)) {
|
|
89
|
-
if (left === 0) numberToLetter = letter[quotient * 10];
|
|
90
|
-
if (left === 1)
|
|
91
|
-
numberToLetter = `${letter[quotient * 10]}-et-${letter[left]}`;
|
|
92
|
-
if (left > 1)
|
|
93
|
-
numberToLetter = `${letter[quotient * 10]}-${letter[left]}`;
|
|
94
|
-
} else
|
|
95
|
-
numberToLetter = `${letter[(quotient - 1) * 10]}-${
|
|
96
|
-
letter[10 + left]
|
|
97
|
-
}`;
|
|
98
|
-
} else numberToLetter = letter[nb];
|
|
99
|
-
break;
|
|
100
|
-
case 3:
|
|
101
|
-
quotient = Math.floor(nb / 100);
|
|
102
|
-
left = nb % 100;
|
|
103
|
-
if (quotient === 1 && left === 0) numberToLetter = "cent";
|
|
104
|
-
if (quotient === 1 && left !== 0)
|
|
105
|
-
numberToLetter = `cent ${this.French(left)}`;
|
|
106
|
-
if (quotient > 1 && left === 0)
|
|
107
|
-
numberToLetter = `${letter[quotient]} cents`;
|
|
108
|
-
if (quotient > 1 && left !== 0)
|
|
109
|
-
numberToLetter = `${letter[quotient]} cent ${this.French(left)}`;
|
|
110
|
-
break;
|
|
111
|
-
case 4:
|
|
112
|
-
case 5:
|
|
113
|
-
case 6:
|
|
114
|
-
quotient = Math.floor(nb / 1000);
|
|
115
|
-
left = nb - quotient * 1000;
|
|
116
|
-
if (quotient === 1 && left === 0) numberToLetter = "mille";
|
|
117
|
-
if (quotient === 1 && left !== 0)
|
|
118
|
-
numberToLetter = `mille ${this.French(left)}`;
|
|
119
|
-
if (quotient > 1 && left === 0)
|
|
120
|
-
numberToLetter = `${this.French(quotient)} mille`;
|
|
121
|
-
if (quotient > 1 && left !== 0)
|
|
122
|
-
numberToLetter = `${this.French(quotient)} mille ${this.French(
|
|
123
|
-
left
|
|
124
|
-
)}`;
|
|
125
|
-
break;
|
|
126
|
-
case 7:
|
|
127
|
-
case 8:
|
|
128
|
-
case 9:
|
|
129
|
-
quotient = Math.floor(nb / 1000000);
|
|
130
|
-
left = nb % 1000000;
|
|
131
|
-
if (quotient === 1 && left === 0) numberToLetter = "un million";
|
|
132
|
-
if (quotient === 1 && left !== 0)
|
|
133
|
-
numberToLetter = `un million ${this.French(left)}`;
|
|
134
|
-
if (quotient > 1 && left === 0)
|
|
135
|
-
numberToLetter = `${this.French(quotient)} millions`;
|
|
136
|
-
if (quotient > 1 && left !== 0)
|
|
137
|
-
numberToLetter = `${this.French(quotient)} millions ${this.French(
|
|
138
|
-
left
|
|
139
|
-
)}`;
|
|
140
|
-
break;
|
|
141
|
-
case 10:
|
|
142
|
-
case 11:
|
|
143
|
-
case 12:
|
|
144
|
-
quotient = Math.floor(nb / 1000000000);
|
|
145
|
-
left = nb - quotient * 1000000000;
|
|
146
|
-
if (quotient === 1 && left === 0) numberToLetter = "un milliard";
|
|
147
|
-
if (quotient === 1 && left !== 0)
|
|
148
|
-
numberToLetter = `un milliard ${this.French(left)}`;
|
|
149
|
-
if (quotient > 1 && left === 0)
|
|
150
|
-
numberToLetter = `${this.French(quotient)} milliards`;
|
|
151
|
-
if (quotient > 1 && left !== 0)
|
|
152
|
-
numberToLetter = `${this.French(quotient)} milliards ${this.French(
|
|
153
|
-
left
|
|
154
|
-
)}`;
|
|
155
|
-
break;
|
|
156
|
-
case 13:
|
|
157
|
-
case 14:
|
|
158
|
-
case 15:
|
|
159
|
-
quotient = Math.floor(nb / 1000000000000);
|
|
160
|
-
left = nb - quotient * 1000000000000;
|
|
161
|
-
if (quotient === 1 && left === 0) numberToLetter = "un billion";
|
|
162
|
-
if (quotient === 1 && left !== 0)
|
|
163
|
-
numberToLetter = `un billion ${this.French(left)}`;
|
|
164
|
-
if (quotient > 1 && left === 0)
|
|
165
|
-
numberToLetter = `${this.French(quotient)} billions`;
|
|
166
|
-
if (quotient > 1 && left !== 0)
|
|
167
|
-
numberToLetter = `${this.French(quotient)} billions ${this.French(
|
|
168
|
-
left
|
|
169
|
-
)}`;
|
|
170
|
-
break;
|
|
171
|
-
default:
|
|
172
|
-
throw new Error(`Capacity overrun`);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (
|
|
176
|
-
numberToLetter.substr(
|
|
177
|
-
numberToLetter.length - "quatre-vingt".length,
|
|
178
|
-
"quatre-vingt".length
|
|
179
|
-
) === "quatre-vingt"
|
|
180
|
-
)
|
|
181
|
-
numberToLetter += "s";
|
|
182
|
-
|
|
183
|
-
return numberToLetter;
|
|
184
|
-
}
|
|
185
|
-
}
|
package/src/libs/EvalVariable.ts
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-await-in-loop */
|
|
2
|
-
import type { VariableV3 } from "@legalplace/models-v3-types";
|
|
3
|
-
import { selectVariableReference } from "../redux/selectors/references";
|
|
4
|
-
import { EvalFunctions } from "./Eval/EvalFunctions";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* EvalVariable class
|
|
8
|
-
* ------------------
|
|
9
|
-
* Parses an eval variable's
|
|
10
|
-
* evaluation
|
|
11
|
-
*/
|
|
12
|
-
export class EvalVariable extends EvalFunctions {
|
|
13
|
-
variablesValues: Record<string, string | number> = {};
|
|
14
|
-
|
|
15
|
-
evaluation: string;
|
|
16
|
-
|
|
17
|
-
rawEvaluation: string;
|
|
18
|
-
|
|
19
|
-
result: string | number | null = null;
|
|
20
|
-
|
|
21
|
-
index: number;
|
|
22
|
-
|
|
23
|
-
hasFunctions = false;
|
|
24
|
-
|
|
25
|
-
abortEvaluation = false;
|
|
26
|
-
|
|
27
|
-
constructor(variable: VariableV3, index: number) {
|
|
28
|
-
super(variable.id, index);
|
|
29
|
-
|
|
30
|
-
this.evaluation =
|
|
31
|
-
typeof variable.eval?.formula === "string" ? variable.eval?.formula : "0";
|
|
32
|
-
this.rawEvaluation = this.evaluation;
|
|
33
|
-
this.index = index;
|
|
34
|
-
|
|
35
|
-
// Setting isDisplay
|
|
36
|
-
if (/^D=(.*)/i.test(this.evaluation)) {
|
|
37
|
-
this.isDisplay = true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Compiling & executing functions
|
|
41
|
-
this.executeFunctions();
|
|
42
|
-
|
|
43
|
-
// Populating value
|
|
44
|
-
this.populateValues();
|
|
45
|
-
|
|
46
|
-
// Evaluating
|
|
47
|
-
this.evaluate();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Populates evaluation with the required variables
|
|
52
|
-
*/
|
|
53
|
-
populateValues(): void {
|
|
54
|
-
let evalVariables = {};
|
|
55
|
-
|
|
56
|
-
// Extracting eval variables tags
|
|
57
|
-
const match = this.evaluation.match(/\[var:([0-9]+)\]/gi);
|
|
58
|
-
if (match !== null) {
|
|
59
|
-
// Tranforming tags into integer ids
|
|
60
|
-
const evalVariablesTags: string[] = [...match];
|
|
61
|
-
const evalVariablesIds = evalVariablesTags.map((current) => {
|
|
62
|
-
const matchId = current.match(/([0-9]+)/);
|
|
63
|
-
if (matchId === null) return 0;
|
|
64
|
-
return parseInt(matchId[0], 10);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// Getting values
|
|
68
|
-
evalVariablesIds.forEach((variableId) => {
|
|
69
|
-
let value = this.getVariableValue(variableId, false);
|
|
70
|
-
if (typeof value === "string" && value.trim().length === 0) {
|
|
71
|
-
value = "___EMPTY___";
|
|
72
|
-
|
|
73
|
-
if (this.isVariableEditable(variableId)) this.abortEvaluation = true;
|
|
74
|
-
}
|
|
75
|
-
evalVariables = {
|
|
76
|
-
...evalVariables,
|
|
77
|
-
[variableId]: value,
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
this.variablesValues = evalVariables;
|
|
83
|
-
|
|
84
|
-
let operation = `${this.evaluation}`;
|
|
85
|
-
Object.keys(this.variablesValues).forEach((variableId) => {
|
|
86
|
-
let value = this.variablesValues[variableId];
|
|
87
|
-
value = typeof value === "number" ? value.toString() : value;
|
|
88
|
-
operation = operation.replace(
|
|
89
|
-
new RegExp(`\\[var:${variableId}\\]`, "g"),
|
|
90
|
-
value
|
|
91
|
-
);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
this.evaluation = operation;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Executes evaluation functions
|
|
99
|
-
*/
|
|
100
|
-
executeFunctions(): void {
|
|
101
|
-
/**
|
|
102
|
-
* Functions list
|
|
103
|
-
*/
|
|
104
|
-
const functionsList: Record<string, (...args: any[]) => string | number> = {
|
|
105
|
-
AFFICHER_DATE: this.afficherDate,
|
|
106
|
-
AFFICHER_ANNEE: this.afficherAnnee,
|
|
107
|
-
JOUR_OUVRE: this.jourOuvre,
|
|
108
|
-
JOUR_OUVRABLE: this.jourOuvrable,
|
|
109
|
-
DATE: this.date,
|
|
110
|
-
AJOUTER_JOURS_OUVRABLES: this.ajouterJoursOuvrables,
|
|
111
|
-
AJOUTER_JOURS_OUVRES: this.ajouterJoursOuvres,
|
|
112
|
-
AJOUTER_JOURS: this.ajouterJours,
|
|
113
|
-
AJOUTER_MOIS: this.ajouterMois,
|
|
114
|
-
AJOUTER_ANNEES: this.ajouterAnnees,
|
|
115
|
-
ENLEVER_JOURS_OUVRABLES: this.enleverJoursOuvrables,
|
|
116
|
-
ENLEVER_JOURS_OUVRES: this.enleverJoursOuvres,
|
|
117
|
-
ENLEVER_JOURS: this.enleverJours,
|
|
118
|
-
ENLEVER_MOIS: this.enleverMois,
|
|
119
|
-
ENLEVER_ANNEES: this.enleverAnnees,
|
|
120
|
-
DUREE_JOURS: this.dureeJours,
|
|
121
|
-
DUREE_MOIS: this.dureeMois,
|
|
122
|
-
DUREE_ANNEES: this.dureeAnnees,
|
|
123
|
-
TODAY: this.today,
|
|
124
|
-
SOMME: this.somme,
|
|
125
|
-
LETTRES: this.lettres,
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Extracting and executing functions
|
|
130
|
-
*/
|
|
131
|
-
const regex = /([a-z_]+)\(([^()]*)\)/gi;
|
|
132
|
-
let formulas = this.evaluation.match(regex);
|
|
133
|
-
|
|
134
|
-
// Keep the loop running until we detect no more functions
|
|
135
|
-
while (formulas && this.doNotEvaluate === false) {
|
|
136
|
-
for (let i = 0; i < formulas.length; i += 1) {
|
|
137
|
-
const formula = formulas[i];
|
|
138
|
-
|
|
139
|
-
const reg = new RegExp(regex, "gi");
|
|
140
|
-
const extract = reg.exec(formula);
|
|
141
|
-
if (extract === null) return;
|
|
142
|
-
|
|
143
|
-
// Stopping evaluation right after a function detects an error
|
|
144
|
-
if (this.doNotEvaluate === true) return;
|
|
145
|
-
|
|
146
|
-
const functionName = extract[1];
|
|
147
|
-
const args = extract[2]
|
|
148
|
-
.split(extract[2].indexOf(";") > -1 ? ";" : ",")
|
|
149
|
-
.map((v) => v.trim());
|
|
150
|
-
|
|
151
|
-
let result = "";
|
|
152
|
-
if (Object.keys(functionsList).includes(functionName)) {
|
|
153
|
-
result = functionsList[functionName].apply(this, args).toString();
|
|
154
|
-
this.hasFunctions = true;
|
|
155
|
-
} else {
|
|
156
|
-
// eslint-disable-next-line no-console
|
|
157
|
-
console.error(
|
|
158
|
-
`Erreur de modélisation: la fonction %c"${functionName}" %cest inconnue dans la formule: ${this.rawEvaluation}`,
|
|
159
|
-
"font-weight: bold;",
|
|
160
|
-
"font-weight: initial"
|
|
161
|
-
);
|
|
162
|
-
this.doNotEvaluate = true;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
this.evaluation = this.evaluation.replace(formula, result);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
formulas = this.evaluation.match(regex);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Evaluates current evaluation
|
|
174
|
-
*/
|
|
175
|
-
evaluate(): string | number {
|
|
176
|
-
// Stoping evaluation in case the functions processing decided so
|
|
177
|
-
if (this.doNotEvaluate === true) {
|
|
178
|
-
this.result = "";
|
|
179
|
-
return "";
|
|
180
|
-
}
|
|
181
|
-
if (
|
|
182
|
-
typeof this.evaluation !== "string" ||
|
|
183
|
-
this.evaluation.trim().length === 0
|
|
184
|
-
) {
|
|
185
|
-
this.result = "";
|
|
186
|
-
return "";
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
let result;
|
|
190
|
-
try {
|
|
191
|
-
// If result is a date returning it
|
|
192
|
-
if (/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/.test(this.evaluation)) {
|
|
193
|
-
result = this.evaluation;
|
|
194
|
-
} else if (/^D=(.*)/i.test(this.evaluation)) {
|
|
195
|
-
result = this.setEmpty(this.evaluation.replace(/^D=/i, ""), "");
|
|
196
|
-
} else if (this.abortEvaluation === true) {
|
|
197
|
-
result = "";
|
|
198
|
-
} else {
|
|
199
|
-
const cleanEvaluation = this.setEmpty(this.evaluation, 0);
|
|
200
|
-
// eslint-disable-next-line no-eval
|
|
201
|
-
result = eval(
|
|
202
|
-
typeof cleanEvaluation === "string"
|
|
203
|
-
? cleanEvaluation
|
|
204
|
-
: cleanEvaluation.toString()
|
|
205
|
-
);
|
|
206
|
-
if (result === Infinity || Number.isNaN(result)) {
|
|
207
|
-
result = this.hasFunctions === true ? "" : 0;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
} catch (e) {
|
|
211
|
-
result =
|
|
212
|
-
this.hasFunctions === true || this.abortEvaluation === true ? "" : 0;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// Rounding
|
|
216
|
-
if (typeof result === "number") {
|
|
217
|
-
const variableReference = selectVariableReference(this.id);
|
|
218
|
-
if (variableReference?.eval === undefined)
|
|
219
|
-
throw new Error(`Variable ${this.id} does not exist`);
|
|
220
|
-
const { decimals, round } = variableReference.eval;
|
|
221
|
-
const evalDecimal =
|
|
222
|
-
(typeof decimals === "number" && !Number.isNaN(decimals)) ||
|
|
223
|
-
typeof decimals === "string"
|
|
224
|
-
? decimals
|
|
225
|
-
: undefined;
|
|
226
|
-
|
|
227
|
-
// Decimals
|
|
228
|
-
let numberOfDecimals = 0;
|
|
229
|
-
if (evalDecimal !== undefined) {
|
|
230
|
-
numberOfDecimals =
|
|
231
|
-
typeof evalDecimal === "string"
|
|
232
|
-
? parseInt(evalDecimal, 10)
|
|
233
|
-
: evalDecimal;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// Decimals
|
|
237
|
-
let decma = 1;
|
|
238
|
-
for (let i = 0; i < numberOfDecimals; i += 1) decma *= 10;
|
|
239
|
-
|
|
240
|
-
// Rounding strategy
|
|
241
|
-
const rounders = {
|
|
242
|
-
round: Math.round,
|
|
243
|
-
ceil: Math.ceil,
|
|
244
|
-
floor: Math.floor,
|
|
245
|
-
};
|
|
246
|
-
if (round !== undefined && rounders[round]) {
|
|
247
|
-
if (evalDecimal !== undefined) {
|
|
248
|
-
result = rounders[round](result * decma) / decma;
|
|
249
|
-
} else {
|
|
250
|
-
result = rounders[round](result);
|
|
251
|
-
}
|
|
252
|
-
} else if (evalDecimal !== undefined) {
|
|
253
|
-
result = Math.round(result * decma) / decma;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (result === undefined) {
|
|
258
|
-
this.result = "";
|
|
259
|
-
return "";
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
this.result = result.toString();
|
|
263
|
-
return result;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import Cookies from "universal-cookie";
|
|
2
|
-
import Globals from "../Globals";
|
|
3
|
-
|
|
4
|
-
export type EventsPropsType = Record<
|
|
5
|
-
string,
|
|
6
|
-
string | number | boolean | Record<string, string | number | boolean>
|
|
7
|
-
>;
|
|
8
|
-
|
|
9
|
-
const cookie = new Cookies();
|
|
10
|
-
|
|
11
|
-
class _EventsTracking {
|
|
12
|
-
private initiated = false;
|
|
13
|
-
|
|
14
|
-
private queue: [string, any[]][] = [];
|
|
15
|
-
|
|
16
|
-
private queueTimer: ReturnType<typeof setTimeout> | null = null;
|
|
17
|
-
|
|
18
|
-
public track(eventName: string, eventProps?: EventsPropsType) {
|
|
19
|
-
if (!this.initiated) this.init();
|
|
20
|
-
|
|
21
|
-
// Mixpanel
|
|
22
|
-
this.trackMix(eventName, { ...eventProps });
|
|
23
|
-
|
|
24
|
-
// Facebook Pixel
|
|
25
|
-
this.trackFB(eventName, { ...eventProps });
|
|
26
|
-
|
|
27
|
-
// Google Analytics
|
|
28
|
-
this.trackGA(eventName, { ...eventProps });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public register(props: EventsPropsType) {
|
|
32
|
-
if (!this.initiated) this.init();
|
|
33
|
-
|
|
34
|
-
// Mixpanel
|
|
35
|
-
this.registerMix(props);
|
|
36
|
-
|
|
37
|
-
// Facebook Pixel
|
|
38
|
-
this.registerFB(props);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public trigger(name: string) {
|
|
42
|
-
if (!this.initiated) this.init();
|
|
43
|
-
|
|
44
|
-
// Hotjar
|
|
45
|
-
this.triggerHj(name);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private init() {
|
|
49
|
-
this.initiated = true;
|
|
50
|
-
this.register({
|
|
51
|
-
"WizardX Build Commit":
|
|
52
|
-
process.env.REACT_APP_COMMIT || "Unkown build commit",
|
|
53
|
-
Environement: Globals.appEnv,
|
|
54
|
-
"Powered By": "WizardX",
|
|
55
|
-
...this.getXSource(),
|
|
56
|
-
...this.getXAbTests(),
|
|
57
|
-
});
|
|
58
|
-
this.trigger("wizardx");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private getXSource(): Record<string, string> {
|
|
62
|
-
const xSource = cookie.get("X-Source");
|
|
63
|
-
|
|
64
|
-
return typeof xSource === "string" && xSource.trim().length > 0
|
|
65
|
-
? {
|
|
66
|
-
"X-Source": xSource,
|
|
67
|
-
}
|
|
68
|
-
: {};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private getXAbTests(): Record<string, string> {
|
|
72
|
-
const xAbTests = cookie.get("X-AbTests");
|
|
73
|
-
|
|
74
|
-
if (typeof xAbTests === "object") {
|
|
75
|
-
const xAbTestsFlattened: Record<string, string> = {};
|
|
76
|
-
|
|
77
|
-
Object.keys(xAbTests).forEach((abTestName) => {
|
|
78
|
-
xAbTestsFlattened[`X-AbTests[${abTestName}]`] = xAbTests[abTestName];
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return xAbTestsFlattened;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return typeof xAbTests === "string" && xAbTests.trim().length > 0
|
|
85
|
-
? {
|
|
86
|
-
"X-AbTests": xAbTests,
|
|
87
|
-
}
|
|
88
|
-
: {};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Executes events tracking queue
|
|
93
|
-
*/
|
|
94
|
-
private executeQueue() {
|
|
95
|
-
for (let i = 0; i < this.queue.length; i += 1) {
|
|
96
|
-
const currentEvent = this.queue[i];
|
|
97
|
-
const args = [];
|
|
98
|
-
const [fnName] = currentEvent;
|
|
99
|
-
if (currentEvent.length > 1) {
|
|
100
|
-
for (let x = 0; x < currentEvent[1].length; x += 1)
|
|
101
|
-
args.push(currentEvent[1][x]);
|
|
102
|
-
|
|
103
|
-
args.push(true);
|
|
104
|
-
|
|
105
|
-
let fn: (...a: any) => any;
|
|
106
|
-
|
|
107
|
-
switch (fnName) {
|
|
108
|
-
case "trackMix":
|
|
109
|
-
fn = this.trackMix.bind(this);
|
|
110
|
-
break;
|
|
111
|
-
case "trackFB":
|
|
112
|
-
fn = this.trackFB.bind(this);
|
|
113
|
-
break;
|
|
114
|
-
case "trackGA":
|
|
115
|
-
fn = this.trackGA.bind(this);
|
|
116
|
-
break;
|
|
117
|
-
case "registerMix":
|
|
118
|
-
fn = this.registerMix.bind(this);
|
|
119
|
-
break;
|
|
120
|
-
case "registerFB":
|
|
121
|
-
fn = this.registerFB.bind(this);
|
|
122
|
-
break;
|
|
123
|
-
case "triggerHj":
|
|
124
|
-
fn = this.triggerHj.bind(this);
|
|
125
|
-
break;
|
|
126
|
-
default:
|
|
127
|
-
throw new Error(
|
|
128
|
-
`Unkown function "${fnName}" found on events tracking queue`
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Getting function
|
|
133
|
-
const result = fn(...args);
|
|
134
|
-
if (result === true) {
|
|
135
|
-
this.queue.splice(i, 1);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
private queueTimeout() {
|
|
142
|
-
if (this.queueTimer !== null) clearTimeout(this.queueTimer);
|
|
143
|
-
|
|
144
|
-
this.queueTimer = setTimeout(() => {
|
|
145
|
-
this.executeQueue();
|
|
146
|
-
}, 50);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
public trackMix(
|
|
150
|
-
eventName: string,
|
|
151
|
-
eventProps?: EventsPropsType,
|
|
152
|
-
doNotPushToQueue = false
|
|
153
|
-
) {
|
|
154
|
-
if (!this.initiated) this.init();
|
|
155
|
-
|
|
156
|
-
if (typeof window.mixpanel !== "undefined") {
|
|
157
|
-
if (this.queue.length > 0 && !doNotPushToQueue) this.executeQueue();
|
|
158
|
-
window.mixpanel.track(eventName, eventProps);
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (doNotPushToQueue === false)
|
|
163
|
-
this.queue.push(["trackMix", [eventName, eventProps]]);
|
|
164
|
-
|
|
165
|
-
this.queueTimeout();
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
private trackFB(
|
|
170
|
-
eventName: string,
|
|
171
|
-
eventProps?: EventsPropsType,
|
|
172
|
-
doNotPushToQueue = false
|
|
173
|
-
) {
|
|
174
|
-
if (typeof window.fbq !== "undefined") {
|
|
175
|
-
if (this.queue.length > 0 && !doNotPushToQueue) this.executeQueue();
|
|
176
|
-
window.fbq("trackCustom", eventName, eventProps);
|
|
177
|
-
return true;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (doNotPushToQueue === false)
|
|
181
|
-
this.queue.push(["trackFB", [eventName, eventProps]]);
|
|
182
|
-
|
|
183
|
-
this.queueTimeout();
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
private trackGA(
|
|
188
|
-
eventName: string,
|
|
189
|
-
eventProps?: EventsPropsType,
|
|
190
|
-
doNotPushToQueue = false
|
|
191
|
-
) {
|
|
192
|
-
if (typeof window.ga !== "undefined") {
|
|
193
|
-
if (this.queue.length > 0 && !doNotPushToQueue) this.executeQueue();
|
|
194
|
-
window.ga(
|
|
195
|
-
"send",
|
|
196
|
-
"event",
|
|
197
|
-
"lpTracking",
|
|
198
|
-
"track",
|
|
199
|
-
eventName,
|
|
200
|
-
1,
|
|
201
|
-
eventProps
|
|
202
|
-
);
|
|
203
|
-
return true;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (doNotPushToQueue === false)
|
|
207
|
-
this.queue.push(["trackGA", [eventName, eventProps]]);
|
|
208
|
-
|
|
209
|
-
this.queueTimeout();
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
private registerMix(props: EventsPropsType, doNotPushToQueue = false) {
|
|
214
|
-
if (typeof window.mixpanel !== "undefined") {
|
|
215
|
-
if (this.queue.length > 0 && !doNotPushToQueue) this.executeQueue();
|
|
216
|
-
window.mixpanel.register(props);
|
|
217
|
-
return true;
|
|
218
|
-
}
|
|
219
|
-
if (doNotPushToQueue === false) this.queue.push(["registerMix", [props]]);
|
|
220
|
-
|
|
221
|
-
this.queueTimeout();
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
private registerFB(props: EventsPropsType, doNotPushToQueue = false) {
|
|
226
|
-
if (typeof window.fbq !== "undefined") {
|
|
227
|
-
if (this.queue.length > 0 && !doNotPushToQueue) this.executeQueue();
|
|
228
|
-
window.fbq("trackCustom", "GeneralProps", props);
|
|
229
|
-
return true;
|
|
230
|
-
}
|
|
231
|
-
if (doNotPushToQueue === false) this.queue.push(["registerFB", [props]]);
|
|
232
|
-
|
|
233
|
-
this.queueTimeout();
|
|
234
|
-
return false;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
private triggerHj(name: string, doNotPushToQueue = false) {
|
|
238
|
-
if (typeof window.hj !== "undefined") {
|
|
239
|
-
if (this.queue.length > 0 && !doNotPushToQueue) this.executeQueue();
|
|
240
|
-
window.hj("trigger", name);
|
|
241
|
-
return true;
|
|
242
|
-
}
|
|
243
|
-
if (doNotPushToQueue === false) this.queue.push(["triggerHj", [name]]);
|
|
244
|
-
|
|
245
|
-
this.queueTimeout();
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export const EventsTracking = new _EventsTracking();
|