dce-reactkit 4.3.4 → 5.0.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/dist/cjs/index.js +338 -2316
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/LogReviewer.d.ts +1 -1
- package/dist/cjs/types/helpers/logClientEvent.d.ts +1 -1
- package/dist/cjs/types/html/genErrorPage.d.ts +1 -1
- package/dist/cjs/types/index.d.ts +2 -64
- package/dist/cjs/types/types/IntelliTableColumn.d.ts +1 -1
- package/dist/esm/index.js +78 -2223
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/LogReviewer.d.ts +1 -1
- package/dist/esm/types/helpers/logClientEvent.d.ts +1 -1
- package/dist/esm/types/html/genErrorPage.d.ts +1 -1
- package/dist/esm/types/index.d.ts +2 -64
- package/dist/esm/types/types/IntelliTableColumn.d.ts +1 -1
- package/dist/index.d.ts +3 -835
- package/package.json +4 -3
- package/src/components/AppWrapper.tsx +12 -10
- package/src/components/AutoscrollToBottomContainer.tsx +5 -3
- package/src/components/CopiableBox.tsx +5 -1
- package/src/components/DBEntryManagerPanel/helpers/generateEndpointPath.ts +2 -2
- package/src/components/ErrorBox.tsx +6 -2
- package/src/components/IntelliTable.tsx +7 -5
- package/src/components/LogReviewer.tsx +23 -21
- package/src/components/Modal/index.tsx +5 -3
- package/src/components/MultiSwitch.tsx +5 -1
- package/src/components/Shimmer.tsx +4 -2
- package/src/components/SimpleDateChooser.tsx +11 -13
- package/src/components/SimpleTimeChooser.tsx +4 -2
- package/src/helpers/canReviewLogs.test.ts +5 -3
- package/src/helpers/canReviewLogs.ts +5 -3
- package/src/helpers/initClient.tsx +8 -8
- package/src/helpers/isMobileOrTablet.tsx +2 -1
- package/src/helpers/isSelectAdmin.ts +4 -2
- package/src/helpers/logClientEvent.tsx +7 -5
- package/src/helpers/stubServerEndpoint.tsx +1 -1
- package/src/helpers/visitServerEndpoint.tsx +10 -7
- package/src/html/genErrorPage.ts +6 -4
- package/src/index.ts +105 -98
- package/src/types/IntelliTableColumn.ts +4 -1
- package/dist/cjs/types/constants/DAY_IN_MS.d.ts +0 -6
- package/dist/cjs/types/constants/HOUR_IN_MS.d.ts +0 -6
- package/dist/cjs/types/constants/LOG_REVIEW_GET_LOGS_ROUTE.d.ts +0 -6
- package/dist/cjs/types/constants/LOG_REVIEW_ROUTE_PATH_PREFIX.d.ts +0 -6
- package/dist/cjs/types/constants/LOG_REVIEW_STATUS_ROUTE.d.ts +0 -7
- package/dist/cjs/types/constants/LOG_ROUTE_PATH.d.ts +0 -6
- package/dist/cjs/types/constants/MINUTE_IN_MS.d.ts +0 -6
- package/dist/cjs/types/constants/ROUTE_PATH_PREFIX.d.ts +0 -6
- package/dist/cjs/types/constants/SELECT_ADMIN_CHECK_ROUTE.d.ts +0 -6
- package/dist/cjs/types/errors/ErrorWithCode.d.ts +0 -9
- package/dist/cjs/types/helpers/abbreviate.d.ts +0 -10
- package/dist/cjs/types/helpers/abbreviate.test.d.ts +0 -5
- package/dist/cjs/types/helpers/asyncArrayFunctions/everyAsync.d.ts +0 -13
- package/dist/cjs/types/helpers/asyncArrayFunctions/everyAsync.test.d.ts +0 -1
- package/dist/cjs/types/helpers/asyncArrayFunctions/filterAsync.d.ts +0 -13
- package/dist/cjs/types/helpers/asyncArrayFunctions/filterAsync.test.d.ts +0 -1
- package/dist/cjs/types/helpers/asyncArrayFunctions/forEachAsync.d.ts +0 -10
- package/dist/cjs/types/helpers/asyncArrayFunctions/forEachAsync.test.d.ts +0 -1
- package/dist/cjs/types/helpers/asyncArrayFunctions/mapAsync.d.ts +0 -11
- package/dist/cjs/types/helpers/asyncArrayFunctions/mapAsync.test.d.ts +0 -1
- package/dist/cjs/types/helpers/asyncArrayFunctions/someAsync.d.ts +0 -13
- package/dist/cjs/types/helpers/asyncArrayFunctions/someAsync.test.d.ts +0 -1
- package/dist/cjs/types/helpers/avg.d.ts +0 -8
- package/dist/cjs/types/helpers/avg.test.d.ts +0 -5
- package/dist/cjs/types/helpers/capitalize.d.ts +0 -7
- package/dist/cjs/types/helpers/ceilToNumDecimals.d.ts +0 -9
- package/dist/cjs/types/helpers/ceilToNumDecimals.test.d.ts +0 -5
- package/dist/cjs/types/helpers/cloneDeep.d.ts +0 -8
- package/dist/cjs/types/helpers/compareArraysByProp.d.ts +0 -13
- package/dist/cjs/types/helpers/compareArraysByProp.test.d.ts +0 -5
- package/dist/cjs/types/helpers/extractProp.d.ts +0 -12
- package/dist/cjs/types/helpers/extractProp.test.d.ts +0 -5
- package/dist/cjs/types/helpers/floorToNumDecimals.d.ts +0 -9
- package/dist/cjs/types/helpers/floorToNumDecimals.test.d.ts +0 -5
- package/dist/cjs/types/helpers/forceNumIntoBounds.d.ts +0 -10
- package/dist/cjs/types/helpers/forceNumIntoBounds.test.d.ts +0 -5
- package/dist/cjs/types/helpers/genCSV.d.ts +0 -18
- package/dist/cjs/types/helpers/genCSV.test.d.ts +0 -5
- package/dist/cjs/types/helpers/genCommaList.d.ts +0 -12
- package/dist/cjs/types/helpers/genCommaList.test.d.ts +0 -1
- package/dist/cjs/types/helpers/getHumanReadableDate.d.ts +0 -8
- package/dist/cjs/types/helpers/getHumanReadableDate.test.d.ts +0 -5
- package/dist/cjs/types/helpers/getLocalTimeInfo.d.ts +0 -19
- package/dist/cjs/types/helpers/getLocalTimeInfo.test.d.ts +0 -6
- package/dist/cjs/types/helpers/getMonthName.d.ts +0 -14
- package/dist/cjs/types/helpers/getMonthName.test.d.ts +0 -5
- package/dist/cjs/types/helpers/getOrdinal.d.ts +0 -8
- package/dist/cjs/types/helpers/getOrdinal.test.d.ts +0 -5
- package/dist/cjs/types/helpers/getPartOfDay.d.ts +0 -7
- package/dist/cjs/types/helpers/getPartOfDay.test.d.ts +0 -5
- package/dist/cjs/types/helpers/getTimeInfoInET.d.ts +0 -21
- package/dist/cjs/types/helpers/getTimeInfoInET.test.d.ts +0 -5
- package/dist/cjs/types/helpers/getTimestampFromTimeInfoInET.d.ts +0 -20
- package/dist/cjs/types/helpers/getWordCount.d.ts +0 -10
- package/dist/cjs/types/helpers/idify.d.ts +0 -9
- package/dist/cjs/types/helpers/onlyKeepLetters.d.ts +0 -8
- package/dist/cjs/types/helpers/padDecimalZeros.d.ts +0 -10
- package/dist/cjs/types/helpers/padZerosLeft.d.ts +0 -9
- package/dist/cjs/types/helpers/parallelLimit.d.ts +0 -12
- package/dist/cjs/types/helpers/prefixWithAOrAn.d.ts +0 -10
- package/dist/cjs/types/helpers/roundToNumDecimals.d.ts +0 -9
- package/dist/cjs/types/helpers/shuffleArray.d.ts +0 -8
- package/dist/cjs/types/helpers/startMinWait.d.ts +0 -9
- package/dist/cjs/types/helpers/stringsToHumanReadableList.d.ts +0 -10
- package/dist/cjs/types/helpers/sum.d.ts +0 -8
- package/dist/cjs/types/helpers/validators/ChicagoTitleCase.d.ts +0 -9
- package/dist/cjs/types/helpers/validators/shared/constants/ERROR_MESSAGES.d.ts +0 -10
- package/dist/cjs/types/helpers/validators/shared/helpers/validateRegex.d.ts +0 -19
- package/dist/cjs/types/helpers/validators/shared/types/ValidationResult.d.ts +0 -12
- package/dist/cjs/types/helpers/validators/validURL.d.ts +0 -8
- package/dist/cjs/types/helpers/validators/validateEmail.d.ts +0 -11
- package/dist/cjs/types/helpers/validators/validateEmail.test.d.ts +0 -1
- package/dist/cjs/types/helpers/validators/validatePhoneNumber.d.ts +0 -11
- package/dist/cjs/types/helpers/validators/validatePhoneNumber.test.d.ts +0 -1
- package/dist/cjs/types/helpers/validators/validateString.d.ts +0 -22
- package/dist/cjs/types/helpers/validators/validateString.test.d.ts +0 -1
- package/dist/cjs/types/helpers/waitMs.d.ts +0 -7
- package/dist/cjs/types/types/DayOfWeek.d.ts +0 -14
- package/dist/cjs/types/types/Log/LogMainInfo.d.ts +0 -39
- package/dist/cjs/types/types/Log/LogSourceSpecificInfo.d.ts +0 -13
- package/dist/cjs/types/types/Log/LogTypeSpecificInfo.d.ts +0 -17
- package/dist/cjs/types/types/Log/index.d.ts +0 -10
- package/dist/cjs/types/types/LogAction.d.ts +0 -29
- package/dist/cjs/types/types/LogBuiltInMetadata.d.ts +0 -16
- package/dist/cjs/types/types/LogFunction.d.ts +0 -24
- package/dist/cjs/types/types/LogLevel.d.ts +0 -10
- package/dist/cjs/types/types/LogMetadataContextMap.d.ts +0 -11
- package/dist/cjs/types/types/LogMetadataTagMap.d.ts +0 -8
- package/dist/cjs/types/types/LogMetadataTargetMap.d.ts +0 -8
- package/dist/cjs/types/types/LogMetadataType.d.ts +0 -13
- package/dist/cjs/types/types/LogReviewerFilterState/ActionErrorFilterState.d.ts +0 -17
- package/dist/cjs/types/types/LogReviewerFilterState/AdvancedFilterState.d.ts +0 -21
- package/dist/cjs/types/types/LogReviewerFilterState/ContextFilterState.d.ts +0 -10
- package/dist/cjs/types/types/LogReviewerFilterState/DateFilterState.d.ts +0 -17
- package/dist/cjs/types/types/LogReviewerFilterState/TagFilterState.d.ts +0 -8
- package/dist/cjs/types/types/LogReviewerFilterState/index.d.ts +0 -17
- package/dist/cjs/types/types/LogSource.d.ts +0 -9
- package/dist/cjs/types/types/LogType.d.ts +0 -9
- package/dist/cjs/types/types/ParamType.d.ts +0 -17
- package/dist/cjs/types/types/ReactKitErrorCode.d.ts +0 -14
- package/dist/esm/types/constants/DAY_IN_MS.d.ts +0 -6
- package/dist/esm/types/constants/HOUR_IN_MS.d.ts +0 -6
- package/dist/esm/types/constants/LOG_REVIEW_GET_LOGS_ROUTE.d.ts +0 -6
- package/dist/esm/types/constants/LOG_REVIEW_ROUTE_PATH_PREFIX.d.ts +0 -6
- package/dist/esm/types/constants/LOG_REVIEW_STATUS_ROUTE.d.ts +0 -7
- package/dist/esm/types/constants/LOG_ROUTE_PATH.d.ts +0 -6
- package/dist/esm/types/constants/MINUTE_IN_MS.d.ts +0 -6
- package/dist/esm/types/constants/ROUTE_PATH_PREFIX.d.ts +0 -6
- package/dist/esm/types/constants/SELECT_ADMIN_CHECK_ROUTE.d.ts +0 -6
- package/dist/esm/types/errors/ErrorWithCode.d.ts +0 -9
- package/dist/esm/types/helpers/abbreviate.d.ts +0 -10
- package/dist/esm/types/helpers/abbreviate.test.d.ts +0 -5
- package/dist/esm/types/helpers/asyncArrayFunctions/everyAsync.d.ts +0 -13
- package/dist/esm/types/helpers/asyncArrayFunctions/everyAsync.test.d.ts +0 -1
- package/dist/esm/types/helpers/asyncArrayFunctions/filterAsync.d.ts +0 -13
- package/dist/esm/types/helpers/asyncArrayFunctions/filterAsync.test.d.ts +0 -1
- package/dist/esm/types/helpers/asyncArrayFunctions/forEachAsync.d.ts +0 -10
- package/dist/esm/types/helpers/asyncArrayFunctions/forEachAsync.test.d.ts +0 -1
- package/dist/esm/types/helpers/asyncArrayFunctions/mapAsync.d.ts +0 -11
- package/dist/esm/types/helpers/asyncArrayFunctions/mapAsync.test.d.ts +0 -1
- package/dist/esm/types/helpers/asyncArrayFunctions/someAsync.d.ts +0 -13
- package/dist/esm/types/helpers/asyncArrayFunctions/someAsync.test.d.ts +0 -1
- package/dist/esm/types/helpers/avg.d.ts +0 -8
- package/dist/esm/types/helpers/avg.test.d.ts +0 -5
- package/dist/esm/types/helpers/capitalize.d.ts +0 -7
- package/dist/esm/types/helpers/ceilToNumDecimals.d.ts +0 -9
- package/dist/esm/types/helpers/ceilToNumDecimals.test.d.ts +0 -5
- package/dist/esm/types/helpers/cloneDeep.d.ts +0 -8
- package/dist/esm/types/helpers/compareArraysByProp.d.ts +0 -13
- package/dist/esm/types/helpers/compareArraysByProp.test.d.ts +0 -5
- package/dist/esm/types/helpers/extractProp.d.ts +0 -12
- package/dist/esm/types/helpers/extractProp.test.d.ts +0 -5
- package/dist/esm/types/helpers/floorToNumDecimals.d.ts +0 -9
- package/dist/esm/types/helpers/floorToNumDecimals.test.d.ts +0 -5
- package/dist/esm/types/helpers/forceNumIntoBounds.d.ts +0 -10
- package/dist/esm/types/helpers/forceNumIntoBounds.test.d.ts +0 -5
- package/dist/esm/types/helpers/genCSV.d.ts +0 -18
- package/dist/esm/types/helpers/genCSV.test.d.ts +0 -5
- package/dist/esm/types/helpers/genCommaList.d.ts +0 -12
- package/dist/esm/types/helpers/genCommaList.test.d.ts +0 -1
- package/dist/esm/types/helpers/getHumanReadableDate.d.ts +0 -8
- package/dist/esm/types/helpers/getHumanReadableDate.test.d.ts +0 -5
- package/dist/esm/types/helpers/getLocalTimeInfo.d.ts +0 -19
- package/dist/esm/types/helpers/getLocalTimeInfo.test.d.ts +0 -6
- package/dist/esm/types/helpers/getMonthName.d.ts +0 -14
- package/dist/esm/types/helpers/getMonthName.test.d.ts +0 -5
- package/dist/esm/types/helpers/getOrdinal.d.ts +0 -8
- package/dist/esm/types/helpers/getOrdinal.test.d.ts +0 -5
- package/dist/esm/types/helpers/getPartOfDay.d.ts +0 -7
- package/dist/esm/types/helpers/getPartOfDay.test.d.ts +0 -5
- package/dist/esm/types/helpers/getTimeInfoInET.d.ts +0 -21
- package/dist/esm/types/helpers/getTimeInfoInET.test.d.ts +0 -5
- package/dist/esm/types/helpers/getTimestampFromTimeInfoInET.d.ts +0 -20
- package/dist/esm/types/helpers/getWordCount.d.ts +0 -10
- package/dist/esm/types/helpers/idify.d.ts +0 -9
- package/dist/esm/types/helpers/onlyKeepLetters.d.ts +0 -8
- package/dist/esm/types/helpers/padDecimalZeros.d.ts +0 -10
- package/dist/esm/types/helpers/padZerosLeft.d.ts +0 -9
- package/dist/esm/types/helpers/parallelLimit.d.ts +0 -12
- package/dist/esm/types/helpers/prefixWithAOrAn.d.ts +0 -10
- package/dist/esm/types/helpers/roundToNumDecimals.d.ts +0 -9
- package/dist/esm/types/helpers/shuffleArray.d.ts +0 -8
- package/dist/esm/types/helpers/startMinWait.d.ts +0 -9
- package/dist/esm/types/helpers/stringsToHumanReadableList.d.ts +0 -10
- package/dist/esm/types/helpers/sum.d.ts +0 -8
- package/dist/esm/types/helpers/validators/ChicagoTitleCase.d.ts +0 -9
- package/dist/esm/types/helpers/validators/shared/constants/ERROR_MESSAGES.d.ts +0 -10
- package/dist/esm/types/helpers/validators/shared/helpers/validateRegex.d.ts +0 -19
- package/dist/esm/types/helpers/validators/shared/types/ValidationResult.d.ts +0 -12
- package/dist/esm/types/helpers/validators/validURL.d.ts +0 -8
- package/dist/esm/types/helpers/validators/validateEmail.d.ts +0 -11
- package/dist/esm/types/helpers/validators/validateEmail.test.d.ts +0 -1
- package/dist/esm/types/helpers/validators/validatePhoneNumber.d.ts +0 -11
- package/dist/esm/types/helpers/validators/validatePhoneNumber.test.d.ts +0 -1
- package/dist/esm/types/helpers/validators/validateString.d.ts +0 -22
- package/dist/esm/types/helpers/validators/validateString.test.d.ts +0 -1
- package/dist/esm/types/helpers/waitMs.d.ts +0 -7
- package/dist/esm/types/types/DayOfWeek.d.ts +0 -14
- package/dist/esm/types/types/Log/LogMainInfo.d.ts +0 -39
- package/dist/esm/types/types/Log/LogSourceSpecificInfo.d.ts +0 -13
- package/dist/esm/types/types/Log/LogTypeSpecificInfo.d.ts +0 -17
- package/dist/esm/types/types/Log/index.d.ts +0 -10
- package/dist/esm/types/types/LogAction.d.ts +0 -29
- package/dist/esm/types/types/LogBuiltInMetadata.d.ts +0 -16
- package/dist/esm/types/types/LogFunction.d.ts +0 -24
- package/dist/esm/types/types/LogLevel.d.ts +0 -10
- package/dist/esm/types/types/LogMetadataContextMap.d.ts +0 -11
- package/dist/esm/types/types/LogMetadataTagMap.d.ts +0 -8
- package/dist/esm/types/types/LogMetadataTargetMap.d.ts +0 -8
- package/dist/esm/types/types/LogMetadataType.d.ts +0 -13
- package/dist/esm/types/types/LogReviewerFilterState/ActionErrorFilterState.d.ts +0 -17
- package/dist/esm/types/types/LogReviewerFilterState/AdvancedFilterState.d.ts +0 -21
- package/dist/esm/types/types/LogReviewerFilterState/ContextFilterState.d.ts +0 -10
- package/dist/esm/types/types/LogReviewerFilterState/DateFilterState.d.ts +0 -17
- package/dist/esm/types/types/LogReviewerFilterState/TagFilterState.d.ts +0 -8
- package/dist/esm/types/types/LogReviewerFilterState/index.d.ts +0 -17
- package/dist/esm/types/types/LogSource.d.ts +0 -9
- package/dist/esm/types/types/LogType.d.ts +0 -9
- package/dist/esm/types/types/ParamType.d.ts +0 -17
- package/dist/esm/types/types/ReactKitErrorCode.d.ts +0 -14
- package/src/constants/DAY_IN_MS.ts +0 -7
- package/src/constants/HOUR_IN_MS.ts +0 -7
- package/src/constants/LOG_REVIEW_GET_LOGS_ROUTE.ts +0 -9
- package/src/constants/LOG_REVIEW_ROUTE_PATH_PREFIX.ts +0 -9
- package/src/constants/LOG_REVIEW_STATUS_ROUTE.ts +0 -10
- package/src/constants/LOG_ROUTE_PATH.ts +0 -9
- package/src/constants/MINUTE_IN_MS.ts +0 -7
- package/src/constants/ROUTE_PATH_PREFIX.ts +0 -7
- package/src/constants/SELECT_ADMIN_CHECK_ROUTE.ts +0 -7
- package/src/errors/ErrorWithCode.tsx +0 -15
- package/src/helpers/abbreviate.test.ts +0 -26
- package/src/helpers/abbreviate.ts +0 -25
- package/src/helpers/asyncArrayFunctions/everyAsync.test.ts +0 -114
- package/src/helpers/asyncArrayFunctions/everyAsync.ts +0 -51
- package/src/helpers/asyncArrayFunctions/filterAsync.test.ts +0 -126
- package/src/helpers/asyncArrayFunctions/filterAsync.ts +0 -50
- package/src/helpers/asyncArrayFunctions/forEachAsync.test.ts +0 -136
- package/src/helpers/asyncArrayFunctions/forEachAsync.ts +0 -40
- package/src/helpers/asyncArrayFunctions/mapAsync.test.ts +0 -125
- package/src/helpers/asyncArrayFunctions/mapAsync.ts +0 -46
- package/src/helpers/asyncArrayFunctions/someAsync.test.ts +0 -92
- package/src/helpers/asyncArrayFunctions/someAsync.ts +0 -49
- package/src/helpers/avg.test.ts +0 -24
- package/src/helpers/avg.ts +0 -22
- package/src/helpers/capitalize.ts +0 -20
- package/src/helpers/ceilToNumDecimals.test.ts +0 -39
- package/src/helpers/ceilToNumDecimals.ts +0 -13
- package/src/helpers/cloneDeep.ts +0 -11
- package/src/helpers/compareArraysByProp.test.ts +0 -147
- package/src/helpers/compareArraysByProp.ts +0 -56
- package/src/helpers/extractProp.test.ts +0 -34
- package/src/helpers/extractProp.ts +0 -17
- package/src/helpers/floorToNumDecimals.test.ts +0 -39
- package/src/helpers/floorToNumDecimals.ts +0 -13
- package/src/helpers/forceNumIntoBounds.test.ts +0 -34
- package/src/helpers/forceNumIntoBounds.ts +0 -19
- package/src/helpers/genCSV.test.ts +0 -75
- package/src/helpers/genCSV.ts +0 -87
- package/src/helpers/genCommaList.test.ts +0 -57
- package/src/helpers/genCommaList.ts +0 -21
- package/src/helpers/getHumanReadableDate.test.ts +0 -29
- package/src/helpers/getHumanReadableDate.ts +0 -36
- package/src/helpers/getLocalTimeInfo.test.ts +0 -48
- package/src/helpers/getLocalTimeInfo.ts +0 -58
- package/src/helpers/getMonthName.test.ts +0 -79
- package/src/helpers/getMonthName.ts +0 -29
- package/src/helpers/getOrdinal.test.ts +0 -84
- package/src/helpers/getOrdinal.ts +0 -14
- package/src/helpers/getPartOfDay.test.ts +0 -56
- package/src/helpers/getPartOfDay.ts +0 -20
- package/src/helpers/getTimeInfoInET.test.ts +0 -72
- package/src/helpers/getTimeInfoInET.ts +0 -79
- package/src/helpers/getTimestampFromTimeInfoInET.ts +0 -179
- package/src/helpers/getWordCount.ts +0 -26
- package/src/helpers/idify.ts +0 -24
- package/src/helpers/onlyKeepLetters.ts +0 -11
- package/src/helpers/padDecimalZeros.tsx +0 -32
- package/src/helpers/padZerosLeft.tsx +0 -21
- package/src/helpers/parallelLimit.ts +0 -63
- package/src/helpers/prefixWithAOrAn.ts +0 -29
- package/src/helpers/roundToNumDecimals.tsx +0 -13
- package/src/helpers/shuffleArray.ts +0 -19
- package/src/helpers/startMinWait.ts +0 -33
- package/src/helpers/stringsToHumanReadableList.ts +0 -39
- package/src/helpers/sum.tsx +0 -16
- package/src/helpers/validators/ChicagoTitleCase.test.ts +0 -85
- package/src/helpers/validators/ChicagoTitleCase.ts +0 -32
- package/src/helpers/validators/findURL.test.ts +0 -83
- package/src/helpers/validators/findURL.ts +0 -43
- package/src/helpers/validators/shared/constants/ERROR_MESSAGES.ts +0 -18
- package/src/helpers/validators/shared/helpers/validateRegex.ts +0 -47
- package/src/helpers/validators/shared/types/ValidationResult.ts +0 -20
- package/src/helpers/validators/validURL.test.ts +0 -90
- package/src/helpers/validators/validURL.ts +0 -18
- package/src/helpers/validators/validateEmail.test.ts +0 -110
- package/src/helpers/validators/validateEmail.ts +0 -47
- package/src/helpers/validators/validatePhoneNumber.test.ts +0 -94
- package/src/helpers/validators/validatePhoneNumber.ts +0 -49
- package/src/helpers/validators/validateString.test.ts +0 -173
- package/src/helpers/validators/validateString.ts +0 -171
- package/src/helpers/waitMs.tsx +0 -12
- package/src/types/DayOfWeek.ts +0 -15
- package/src/types/Log/LogMainInfo.ts +0 -69
- package/src/types/Log/LogSourceSpecificInfo.ts +0 -25
- package/src/types/Log/LogTypeSpecificInfo.ts +0 -33
- package/src/types/Log/index.ts +0 -17
- package/src/types/LogAction.ts +0 -52
- package/src/types/LogBuiltInMetadata.ts +0 -19
- package/src/types/LogFunction.ts +0 -46
- package/src/types/LogLevel.ts +0 -11
- package/src/types/LogMetadataContextMap.ts +0 -15
- package/src/types/LogMetadataTagMap.ts +0 -9
- package/src/types/LogMetadataTargetMap.ts +0 -9
- package/src/types/LogMetadataType.ts +0 -16
- package/src/types/LogReviewerFilterState/ActionErrorFilterState.ts +0 -24
- package/src/types/LogReviewerFilterState/AdvancedFilterState.ts +0 -36
- package/src/types/LogReviewerFilterState/ContextFilterState.ts +0 -16
- package/src/types/LogReviewerFilterState/DateFilterState.ts +0 -26
- package/src/types/LogReviewerFilterState/TagFilterState.ts +0 -9
- package/src/types/LogReviewerFilterState/index.ts +0 -24
- package/src/types/LogSource.ts +0 -12
- package/src/types/LogType.ts +0 -12
- package/src/types/ParamType.ts +0 -18
- package/src/types/ReactKitErrorCode.tsx +0 -17
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Run the operator function on each item in the array
|
|
3
|
-
* @author Gabe Abrams
|
|
4
|
-
* @param operatorFunction the operator function to apply
|
|
5
|
-
*/
|
|
6
|
-
const forEachAsync = async <T>(
|
|
7
|
-
array: T[],
|
|
8
|
-
operatorFunction: (
|
|
9
|
-
item: T,
|
|
10
|
-
index: number,
|
|
11
|
-
opts: {
|
|
12
|
-
breakNow: () => void,
|
|
13
|
-
array: Array<T>,
|
|
14
|
-
},
|
|
15
|
-
) => void,
|
|
16
|
-
) => {
|
|
17
|
-
// Create break logic
|
|
18
|
-
let done = false;
|
|
19
|
-
/**
|
|
20
|
-
* Break the loop
|
|
21
|
-
* @author Gabe Abrams
|
|
22
|
-
*/
|
|
23
|
-
const breakNow = () => {
|
|
24
|
-
done = true;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// Loop through each item
|
|
28
|
-
for (let i = 0; i < array.length && !done; i++) {
|
|
29
|
-
await operatorFunction(
|
|
30
|
-
array[i],
|
|
31
|
-
i,
|
|
32
|
-
{
|
|
33
|
-
breakNow,
|
|
34
|
-
array,
|
|
35
|
-
},
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export default forEachAsync;
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import waitMs from '../waitMs';
|
|
2
|
-
import mapAsync from './mapAsync';
|
|
3
|
-
|
|
4
|
-
describe('mapAsync', () => {
|
|
5
|
-
it('should return an empty array when given an empty array', async () => {
|
|
6
|
-
const result = await mapAsync([], async () => {
|
|
7
|
-
// Operator function logic goes here
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
expect(result).toEqual([]);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should apply the operator function to each item in the array', async () => {
|
|
14
|
-
const array = [1, 2, 3];
|
|
15
|
-
const operatorFunction = jest.fn();
|
|
16
|
-
|
|
17
|
-
await mapAsync(array, operatorFunction);
|
|
18
|
-
|
|
19
|
-
expect(operatorFunction).toHaveBeenCalledTimes(3);
|
|
20
|
-
expect(operatorFunction).toHaveBeenCalledWith(1, 0, expect.any(Object));
|
|
21
|
-
expect(operatorFunction).toHaveBeenCalledWith(2, 1, expect.any(Object));
|
|
22
|
-
expect(operatorFunction).toHaveBeenCalledWith(3, 2, expect.any(Object));
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should collect and return the results of the operator function', async () => {
|
|
26
|
-
const array = [1, 2, 3];
|
|
27
|
-
const operatorFunction = async (item: number) => {
|
|
28
|
-
return item * 2;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const result = await mapAsync(array, operatorFunction);
|
|
32
|
-
|
|
33
|
-
expect(result).toEqual([2, 4, 6]);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should pass the correct index to the operator function', async () => {
|
|
37
|
-
const array = [1, 2, 3];
|
|
38
|
-
const operatorFunction = jest.fn();
|
|
39
|
-
|
|
40
|
-
await mapAsync(array, operatorFunction);
|
|
41
|
-
|
|
42
|
-
expect(operatorFunction).toHaveBeenCalledWith(expect.anything(), 0, expect.any(Object));
|
|
43
|
-
expect(operatorFunction).toHaveBeenCalledWith(expect.anything(), 1, expect.any(Object));
|
|
44
|
-
expect(operatorFunction).toHaveBeenCalledWith(expect.anything(), 2, expect.any(Object));
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should pass the correct options object to the operator function', async () => {
|
|
48
|
-
const array = [1, 2, 3];
|
|
49
|
-
const operatorFunction = jest.fn();
|
|
50
|
-
|
|
51
|
-
await mapAsync(array, operatorFunction);
|
|
52
|
-
|
|
53
|
-
expect(operatorFunction).toHaveBeenCalledWith(expect.anything(), expect.anything(), {
|
|
54
|
-
breakNow: expect.any(Function),
|
|
55
|
-
array: expect.any(Array),
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should allow the operator function to break the loop', async () => {
|
|
60
|
-
const array = [1, 2, 3];
|
|
61
|
-
|
|
62
|
-
const result = await mapAsync(
|
|
63
|
-
array,
|
|
64
|
-
async (
|
|
65
|
-
item,
|
|
66
|
-
index,
|
|
67
|
-
{ breakNow },
|
|
68
|
-
) => {
|
|
69
|
-
if (item === 2) {
|
|
70
|
-
breakNow();
|
|
71
|
-
}
|
|
72
|
-
return item;
|
|
73
|
-
},
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
expect(result).toEqual([1]);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should handle asynchronous operator function', async () => {
|
|
80
|
-
const array = [1, 2, 3];
|
|
81
|
-
const result = await mapAsync(
|
|
82
|
-
array,
|
|
83
|
-
async (item) => {
|
|
84
|
-
await waitMs(1000);
|
|
85
|
-
return item * 2;
|
|
86
|
-
},
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
expect(result).toEqual([2, 4, 6]);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should handle errors thrown by the operator function', async () => {
|
|
93
|
-
const array = [1, 2, 3];
|
|
94
|
-
|
|
95
|
-
await expect(
|
|
96
|
-
mapAsync(
|
|
97
|
-
array,
|
|
98
|
-
async (item) => {
|
|
99
|
-
if (item === 2) {
|
|
100
|
-
throw new Error('Error processing item');
|
|
101
|
-
}
|
|
102
|
-
return item * 2;
|
|
103
|
-
},
|
|
104
|
-
),
|
|
105
|
-
).rejects.toThrow('Error processing item');
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should handle empty array with breakNow called', async () => {
|
|
109
|
-
const array: number[] = [];
|
|
110
|
-
|
|
111
|
-
const result = await mapAsync(
|
|
112
|
-
array,
|
|
113
|
-
async (
|
|
114
|
-
item,
|
|
115
|
-
index,
|
|
116
|
-
{ breakNow },
|
|
117
|
-
) => {
|
|
118
|
-
breakNow();
|
|
119
|
-
return item;
|
|
120
|
-
},
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
expect(result).toEqual([]);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Run the operator function on each item in the array, collecting all results
|
|
3
|
-
* @author Gabe Abrams
|
|
4
|
-
* @param operatorFunction the operator function to apply
|
|
5
|
-
* @returns the array of results
|
|
6
|
-
*/
|
|
7
|
-
const mapAsync = async <T, U>(
|
|
8
|
-
array: T[],
|
|
9
|
-
operatorFunction: (
|
|
10
|
-
item: T,
|
|
11
|
-
index: number,
|
|
12
|
-
opts: {
|
|
13
|
-
breakNow: () => void,
|
|
14
|
-
array: Array<T>,
|
|
15
|
-
},
|
|
16
|
-
) => Promise<U>,
|
|
17
|
-
): Promise<U[]> => {
|
|
18
|
-
// Create break logic
|
|
19
|
-
let done = false;
|
|
20
|
-
/**
|
|
21
|
-
* Break the loop
|
|
22
|
-
* @author Gabe Abrams
|
|
23
|
-
*/
|
|
24
|
-
const breakNow = () => {
|
|
25
|
-
done = true;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// Loop through each item, collecting results
|
|
29
|
-
const results: U[] = [];
|
|
30
|
-
for (let i = 0; i < array.length && !done; i++) {
|
|
31
|
-
const result = await operatorFunction(
|
|
32
|
-
array[i],
|
|
33
|
-
i,
|
|
34
|
-
{
|
|
35
|
-
breakNow,
|
|
36
|
-
array,
|
|
37
|
-
},
|
|
38
|
-
);
|
|
39
|
-
results.push(result);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Return results
|
|
43
|
-
return results;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export default mapAsync;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import waitMs from '../waitMs';
|
|
2
|
-
import someAsync from './someAsync';
|
|
3
|
-
|
|
4
|
-
describe('someAsync', () => {
|
|
5
|
-
it('should return false if the array is empty', async () => {
|
|
6
|
-
const result = await someAsync([], () => {
|
|
7
|
-
return Promise.resolve(true);
|
|
8
|
-
});
|
|
9
|
-
expect(result).toBe(false);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should return false if the operator function returns false for all items', async () => {
|
|
13
|
-
const array = [1, 2, 3, 4, 5];
|
|
14
|
-
const result = await someAsync(array, () => {
|
|
15
|
-
return Promise.resolve(false);
|
|
16
|
-
});
|
|
17
|
-
expect(result).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should return true if the operator function returns true for any item', async () => {
|
|
21
|
-
const array = [1, 2, 3, 4, 5];
|
|
22
|
-
const result = await someAsync(array, (item) => {
|
|
23
|
-
return Promise.resolve(item === 3);
|
|
24
|
-
});
|
|
25
|
-
expect(result).toBe(true);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should pass the correct index to the operator function', async () => {
|
|
29
|
-
const array = [1, 2, 3, 4, 5];
|
|
30
|
-
const result = await someAsync(array, (item, index) => {
|
|
31
|
-
expect(index).toBeGreaterThanOrEqual(0);
|
|
32
|
-
expect(index).toBeLessThan(array.length);
|
|
33
|
-
return Promise.resolve(false);
|
|
34
|
-
});
|
|
35
|
-
expect(result).toBe(false);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('should pass the correct array to the operator function', async () => {
|
|
39
|
-
const array = [1, 2, 3, 4, 5];
|
|
40
|
-
const result = await someAsync(array, (item, index, { array: arr }) => {
|
|
41
|
-
expect(arr).toBe(array);
|
|
42
|
-
return Promise.resolve(false);
|
|
43
|
-
});
|
|
44
|
-
expect(result).toBe(false);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should stop iterating and return true if the operator function returns true for an item and breakNow is called', async () => {
|
|
48
|
-
const array = [1, 2, 3, 4, 5];
|
|
49
|
-
const result = await someAsync(array, (item, index, { breakNow }) => {
|
|
50
|
-
if (item === 3) {
|
|
51
|
-
breakNow();
|
|
52
|
-
return Promise.resolve(true);
|
|
53
|
-
}
|
|
54
|
-
return Promise.resolve(false);
|
|
55
|
-
});
|
|
56
|
-
expect(result).toBe(true);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should handle asynchronous operator function', async () => {
|
|
60
|
-
const array = [1, 2, 3, 4, 5];
|
|
61
|
-
const result = await someAsync(array, async (item) => {
|
|
62
|
-
await waitMs(100);
|
|
63
|
-
return Promise.resolve(item === 3);
|
|
64
|
-
});
|
|
65
|
-
expect(result).toBe(true);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should handle rejected promises from the operator function', async () => {
|
|
69
|
-
const array = [1, 2, 3, 4, 5];
|
|
70
|
-
const result = await someAsync(array, () => {
|
|
71
|
-
return Promise.reject(new Error('Test error'));
|
|
72
|
-
});
|
|
73
|
-
expect(result).toBe(false);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should handle thrown errors from the operator function', async () => {
|
|
77
|
-
const array = [1, 2, 3, 4, 5];
|
|
78
|
-
const result = await someAsync(array, () => {
|
|
79
|
-
throw new Error('Test error');
|
|
80
|
-
});
|
|
81
|
-
expect(result).toBe(false);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should handle empty array and asynchronous operator function', async () => {
|
|
85
|
-
const array: number[] = [];
|
|
86
|
-
const result = await someAsync(array, async () => {
|
|
87
|
-
await waitMs(100);
|
|
88
|
-
return Promise.resolve(false);
|
|
89
|
-
});
|
|
90
|
-
expect(result).toBe(false);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Run the operator function on each item in the array, returning true if
|
|
3
|
-
* the operator function returns true for any item in the array
|
|
4
|
-
* @author Gabe Abrams
|
|
5
|
-
* @param operatorFunction the operator function to apply. If it returns true
|
|
6
|
-
* for any item, this function will return true
|
|
7
|
-
* @returns true if the operator function returns true for any item in the array
|
|
8
|
-
*/
|
|
9
|
-
const someAsync = async <T>(
|
|
10
|
-
array: T[],
|
|
11
|
-
operatorFunction: (
|
|
12
|
-
item: T,
|
|
13
|
-
index: number,
|
|
14
|
-
opts: {
|
|
15
|
-
breakNow: () => void,
|
|
16
|
-
array: Array<T>,
|
|
17
|
-
},
|
|
18
|
-
) => Promise<any>,
|
|
19
|
-
): Promise<boolean> => {
|
|
20
|
-
// Create break logic
|
|
21
|
-
let done = false;
|
|
22
|
-
/**
|
|
23
|
-
* Break the loop (checking stops here)
|
|
24
|
-
* @author Gabe Abrams
|
|
25
|
-
*/
|
|
26
|
-
const breakNow = () => {
|
|
27
|
-
done = true;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// Loop through each item, checking
|
|
31
|
-
for (let i = 0; i < array.length && !done; i++) {
|
|
32
|
-
const passed = await operatorFunction(
|
|
33
|
-
array[i],
|
|
34
|
-
i,
|
|
35
|
-
{
|
|
36
|
-
breakNow,
|
|
37
|
-
array,
|
|
38
|
-
},
|
|
39
|
-
);
|
|
40
|
-
if (passed && !done) {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Return false because none returned true
|
|
46
|
-
return false;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export default someAsync;
|
package/src/helpers/avg.test.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for avg helper
|
|
3
|
-
* @author Gabe Abrams
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import avg from './avg';
|
|
7
|
-
|
|
8
|
-
describe('helpers > avg', () => {
|
|
9
|
-
it('should return 0 for an empty array', () => {
|
|
10
|
-
expect(avg([])).toEqual(0);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should return the correct average for an array of numbers', () => {
|
|
14
|
-
expect(avg([1, 2, 3, 4, 5])).toEqual(3);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('should handle negative numbers', () => {
|
|
18
|
-
expect(avg([-1, 0, 1])).toEqual(0);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should handle decimal numbers', () => {
|
|
22
|
-
expect(avg([1.5, 2.5, 3.5])).toEqual(2.5);
|
|
23
|
-
});
|
|
24
|
-
});
|
package/src/helpers/avg.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import sum from './sum';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Get the average of a set of numbers
|
|
5
|
-
* @author Gabe Abrams
|
|
6
|
-
* @param nums the numbers to average
|
|
7
|
-
* @returns average value or 0 if no numbers
|
|
8
|
-
*/
|
|
9
|
-
const avg = (nums: number[]) => {
|
|
10
|
-
// Handle empty array case
|
|
11
|
-
if (nums.length === 0) {
|
|
12
|
-
return 0;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Get the total value
|
|
16
|
-
const total = sum(nums);
|
|
17
|
-
|
|
18
|
-
// Get average
|
|
19
|
-
return (total / nums.length);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export default avg;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Capitalize every word in a string (just the first letter)
|
|
3
|
-
* @param str string to capitalize
|
|
4
|
-
* @returns string with every word capitalized
|
|
5
|
-
*/
|
|
6
|
-
const capitalize = (str: string): string => {
|
|
7
|
-
return (
|
|
8
|
-
str
|
|
9
|
-
// Split into words
|
|
10
|
-
.split(' ')
|
|
11
|
-
// Capitalize first letter of each word
|
|
12
|
-
.map((word) => {
|
|
13
|
-
return word.charAt(0).toUpperCase() + word.substring(1);
|
|
14
|
-
})
|
|
15
|
-
// Join back together
|
|
16
|
-
.join(' ')
|
|
17
|
-
);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default capitalize;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Test file for the ceilToNumDecimals helper
|
|
3
|
-
* @author Gabe Abrams
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Import main function
|
|
7
|
-
import ceilToNumDecimals from './ceilToNumDecimals';
|
|
8
|
-
|
|
9
|
-
describe('ceilToNumDecimals', () => {
|
|
10
|
-
it('should return 0 for 0 with 0 decimals', () => {
|
|
11
|
-
const result = ceilToNumDecimals(0, 0);
|
|
12
|
-
expect(result).toEqual(0);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should return 1 for 1 with 0 decimals', () => {
|
|
16
|
-
const result = ceilToNumDecimals(1, 0);
|
|
17
|
-
expect(result).toEqual(1);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should return 1.24 for 1.234 with 2 decimals', () => {
|
|
21
|
-
const result = ceilToNumDecimals(1.234, 2);
|
|
22
|
-
expect(result).toEqual(1.24);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should return -1.23 for -1.234 with 2 decimals', () => {
|
|
26
|
-
const result = ceilToNumDecimals(-1.234, 2);
|
|
27
|
-
expect(result).toEqual(-1.23);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should return 1234 for 1234 with 0 decimals', () => {
|
|
31
|
-
const result = ceilToNumDecimals(1234, 0);
|
|
32
|
-
expect(result).toEqual(1234);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should return 0.002 for 0.00123 with 3 decimals', () => {
|
|
36
|
-
const result = ceilToNumDecimals(0.00123, 3);
|
|
37
|
-
expect(result).toEqual(0.002);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Round a number (ceiling) to a certain number of decimals
|
|
3
|
-
* @author Gabe Abrams
|
|
4
|
-
* @param num the number to round
|
|
5
|
-
* @param numDecimals the number of decimals to round to
|
|
6
|
-
* @returns rounded number
|
|
7
|
-
*/
|
|
8
|
-
const ceilToNumDecimals = (num: number, numDecimals: number): number => {
|
|
9
|
-
const rounder = 10 ** numDecimals;
|
|
10
|
-
return (Math.ceil(num * rounder) / rounder);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default ceilToNumDecimals;
|
package/src/helpers/cloneDeep.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Test file for the compareArraysByProp helper
|
|
3
|
-
* @author Gabe Abrams
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Import main helper
|
|
7
|
-
import compareArraysByProp from './compareArraysByProp';
|
|
8
|
-
|
|
9
|
-
describe('compareArraysByProp', () => {
|
|
10
|
-
it('should return true for two empty arrays', () => {
|
|
11
|
-
const result = compareArraysByProp([], [], 'id');
|
|
12
|
-
expect(result).toEqual(true);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should return true for two arrays with the same objects in the same order', () => {
|
|
16
|
-
const a = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' }];
|
|
17
|
-
const b = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' }];
|
|
18
|
-
const result = compareArraysByProp(a, b, 'id');
|
|
19
|
-
expect(result).toEqual(true);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should return true for two arrays with the same objects in a different order', () => {
|
|
23
|
-
const a = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' }];
|
|
24
|
-
const b = [{ id: 3, name: 'Charlie' }, { id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
25
|
-
const result = compareArraysByProp(a, b, 'id');
|
|
26
|
-
expect(result).toEqual(true);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should return false for two arrays with different objects', () => {
|
|
30
|
-
const a = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' }];
|
|
31
|
-
const b = [{ id: 4, name: 'Dave' }, { id: 5, name: 'Eve' }, { id: 6, name: 'Frank' }];
|
|
32
|
-
const result = compareArraysByProp(a, b, 'id');
|
|
33
|
-
expect(result).toEqual(false);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should return false for two arrays with different objects and some shared objects', () => {
|
|
37
|
-
const a = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' }];
|
|
38
|
-
const b = [{ id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' }, { id: 4, name: 'Dave' }];
|
|
39
|
-
const result = compareArraysByProp(a, b, 'id');
|
|
40
|
-
expect(result).toEqual(false);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should return true for two arrays with the same objects with multiple properties', () => {
|
|
44
|
-
const a = [
|
|
45
|
-
{ id: 1, name: 'Alice', age: 25 },
|
|
46
|
-
{ id: 2, name: 'Bob', age: 30 },
|
|
47
|
-
{ id: 3, name: 'Charlie', age: 35 },
|
|
48
|
-
];
|
|
49
|
-
const b = [
|
|
50
|
-
{ id: 1, name: 'Alice', age: 25 },
|
|
51
|
-
{ id: 2, name: 'Bob', age: 30 },
|
|
52
|
-
{ id: 3, name: 'Charlie', age: 35 },
|
|
53
|
-
];
|
|
54
|
-
const result = compareArraysByProp(a, b, 'id');
|
|
55
|
-
expect(result).toEqual(true);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should return true for two arrays with the same objects with multiple properties in a different order', () => {
|
|
59
|
-
const a = [
|
|
60
|
-
{ id: 1, name: 'Alice', age: 25 },
|
|
61
|
-
{ id: 2, name: 'Bob', age: 30 },
|
|
62
|
-
{ id: 3, name: 'Charlie', age: 35 },
|
|
63
|
-
];
|
|
64
|
-
const b = [
|
|
65
|
-
{ id: 3, name: 'Charlie', age: 35 },
|
|
66
|
-
{ id: 1, name: 'Alice', age: 25 },
|
|
67
|
-
{ id: 2, name: 'Bob', age: 30 },
|
|
68
|
-
];
|
|
69
|
-
const result = compareArraysByProp(a, b, 'id');
|
|
70
|
-
expect(result).toEqual(true);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should return false for two arrays with different objects with multiple properties', () => {
|
|
74
|
-
const a = [
|
|
75
|
-
{ id: 1, name: 'Alice', age: 25 },
|
|
76
|
-
{ id: 2, name: 'Bob', age: 30 },
|
|
77
|
-
{ id: 3, name: 'Charlie', age: 35 },
|
|
78
|
-
];
|
|
79
|
-
const b = [
|
|
80
|
-
{ id: 4, name: 'Dave', age: 40 },
|
|
81
|
-
{ id: 5, name: 'Eve', age: 45 },
|
|
82
|
-
{ id: 6, name: 'Frank', age: 50 },
|
|
83
|
-
];
|
|
84
|
-
const result = compareArraysByProp(a, b, 'id');
|
|
85
|
-
expect(result).toEqual(false);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should return false for two arrays with different objects with multiple properties and some shared objects', () => {
|
|
89
|
-
const a = [
|
|
90
|
-
{ id: 1, name: 'Alice', age: 25 },
|
|
91
|
-
{ id: 2, name: 'Bob', age: 30 },
|
|
92
|
-
{ id: 3, name: 'Charlie', age: 35 },
|
|
93
|
-
];
|
|
94
|
-
const b = [
|
|
95
|
-
{ id: 2, name: 'Bob', age: 30 },
|
|
96
|
-
{ id: 3, name: 'Charlie', age: 35 },
|
|
97
|
-
{ id: 4, name: 'Dave', age: 40 },
|
|
98
|
-
];
|
|
99
|
-
const result = compareArraysByProp(a, b, 'id');
|
|
100
|
-
expect(result).toEqual(false);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should return true for two arrays with the same objects with multiple properties and multiple props', () => {
|
|
104
|
-
const a = [
|
|
105
|
-
{ id: 1, name: 'Alice', age: 25 },
|
|
106
|
-
{ id: 2, name: 'Bob', age: 30 },
|
|
107
|
-
{ id: 3, name: 'Charlie', age: 35 },
|
|
108
|
-
];
|
|
109
|
-
const b = [
|
|
110
|
-
{ id: 1, name: 'Alice', age: 25 },
|
|
111
|
-
{ id: 2, name: 'Bob', age: 30 },
|
|
112
|
-
{ id: 3, name: 'Charlie', age: 35 },
|
|
113
|
-
];
|
|
114
|
-
const result = compareArraysByProp(a, b, ['id', 'name']);
|
|
115
|
-
expect(result).toEqual(true);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('should return true for two arrays with the same objects with multiple properties and multiple props in a different order', () => {
|
|
119
|
-
const a = [
|
|
120
|
-
{ id: 1, name: 'Alice', age: 25 },
|
|
121
|
-
{ id: 2, name: 'Bob', age: 30 },
|
|
122
|
-
{ id: 3, name: 'Charlie', age: 35 },
|
|
123
|
-
];
|
|
124
|
-
const b = [
|
|
125
|
-
{ id: 3, name: 'Charlie', age: 35 },
|
|
126
|
-
{ id: 1, name: 'Alice', age: 25 },
|
|
127
|
-
{ id: 2, name: 'Bob', age: 30 },
|
|
128
|
-
];
|
|
129
|
-
const result = compareArraysByProp(a, b, ['id', 'name']);
|
|
130
|
-
expect(result).toEqual(true);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('should return false for two arrays with different objects with multiple properties and multiple props', () => {
|
|
134
|
-
const a = [
|
|
135
|
-
{ id: 1, name: 'Alice', age: 25 },
|
|
136
|
-
{ id: 2, name: 'Bob', age: 30 },
|
|
137
|
-
{ id: 3, name: 'Charlie', age: 35 },
|
|
138
|
-
];
|
|
139
|
-
const b = [
|
|
140
|
-
{ id: 1, name: 'Bob', age: 40 },
|
|
141
|
-
{ id: 2, name: 'Alice', age: 45 },
|
|
142
|
-
{ id: 3, name: 'Charlie', age: 50 },
|
|
143
|
-
];
|
|
144
|
-
const result = compareArraysByProp(a, b, ['id', 'name']);
|
|
145
|
-
expect(result).toEqual(false);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compare two arrays of objects by only comparing the values in a specific
|
|
3
|
-
* property (e.g. compare user arrays by comparing their user.id values)
|
|
4
|
-
* @author Gabe Abrams
|
|
5
|
-
* @param a the first array
|
|
6
|
-
* @param b the second array
|
|
7
|
-
* @param prop the property to compare with, or an array of props to compare
|
|
8
|
-
* with (if array, all values associated with those props must match)
|
|
9
|
-
* @returns true if the arrays contain the same objects as determined by
|
|
10
|
-
* the values associated with each object's prop
|
|
11
|
-
*/
|
|
12
|
-
const compareArraysByProp = (
|
|
13
|
-
a: any[],
|
|
14
|
-
b: any[],
|
|
15
|
-
prop: string | string[],
|
|
16
|
-
): boolean => {
|
|
17
|
-
// Immediately return if size of arrays is different
|
|
18
|
-
if (a.length !== b.length) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Get all props
|
|
23
|
-
const props = (Array.isArray(prop) ? prop : [prop]);
|
|
24
|
-
|
|
25
|
-
// Clone second array so we can work on it
|
|
26
|
-
const bCloned = [...b];
|
|
27
|
-
|
|
28
|
-
// Remove elements from b as we find them in a
|
|
29
|
-
for (let i = 0; i < a.length; i++) {
|
|
30
|
-
// Find matching element in b
|
|
31
|
-
const matchingIndex = bCloned.findIndex((bItem) => {
|
|
32
|
-
// Compare based on all props
|
|
33
|
-
return props.every((propToCompareBy) => {
|
|
34
|
-
const aVal = (a[i] ?? {})[propToCompareBy];
|
|
35
|
-
const bVal = (bItem ?? {})[propToCompareBy];
|
|
36
|
-
return aVal === bVal;
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Check if no match
|
|
41
|
-
const noMatch = (matchingIndex < 0);
|
|
42
|
-
|
|
43
|
-
// If no match, there's no corresponding element in b
|
|
44
|
-
if (noMatch) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Remove the matching element
|
|
49
|
-
bCloned.splice(matchingIndex, 1);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// If we made it here, all elements in a have a corresponding element in b
|
|
53
|
-
return true;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export default compareArraysByProp;
|