dce-commonkit 4.4.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/.eslintrc.js +93 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/lib/constants/DAY_IN_MS.d.ts +6 -0
- package/lib/constants/DAY_IN_MS.js +9 -0
- package/lib/constants/DAY_IN_MS.js.map +1 -0
- package/lib/constants/HOUR_IN_MS.d.ts +6 -0
- package/lib/constants/HOUR_IN_MS.js +9 -0
- package/lib/constants/HOUR_IN_MS.js.map +1 -0
- package/lib/constants/LOG_REVIEW_GET_LOGS_ROUTE.d.ts +6 -0
- package/lib/constants/LOG_REVIEW_GET_LOGS_ROUTE.js +13 -0
- package/lib/constants/LOG_REVIEW_GET_LOGS_ROUTE.js.map +1 -0
- package/lib/constants/LOG_REVIEW_ROUTE_PATH_PREFIX.d.ts +6 -0
- package/lib/constants/LOG_REVIEW_ROUTE_PATH_PREFIX.js +13 -0
- package/lib/constants/LOG_REVIEW_ROUTE_PATH_PREFIX.js.map +1 -0
- package/lib/constants/LOG_REVIEW_STATUS_ROUTE.d.ts +7 -0
- package/lib/constants/LOG_REVIEW_STATUS_ROUTE.js +14 -0
- package/lib/constants/LOG_REVIEW_STATUS_ROUTE.js.map +1 -0
- package/lib/constants/LOG_ROUTE_PATH.d.ts +6 -0
- package/lib/constants/LOG_ROUTE_PATH.js +13 -0
- package/lib/constants/LOG_ROUTE_PATH.js.map +1 -0
- package/lib/constants/MINUTE_IN_MS.d.ts +6 -0
- package/lib/constants/MINUTE_IN_MS.js +9 -0
- package/lib/constants/MINUTE_IN_MS.js.map +1 -0
- package/lib/constants/ROUTE_PATH_PREFIX.d.ts +6 -0
- package/lib/constants/ROUTE_PATH_PREFIX.js +9 -0
- package/lib/constants/ROUTE_PATH_PREFIX.js.map +1 -0
- package/lib/constants/SELECT_ADMIN_CHECK_ROUTE.d.ts +6 -0
- package/lib/constants/SELECT_ADMIN_CHECK_ROUTE.js +9 -0
- package/lib/constants/SELECT_ADMIN_CHECK_ROUTE.js.map +1 -0
- package/lib/errors/ErrorWithCode.d.ts +9 -0
- package/lib/errors/ErrorWithCode.js +33 -0
- package/lib/errors/ErrorWithCode.js.map +1 -0
- package/lib/helpers/abbreviate.d.ts +10 -0
- package/lib/helpers/abbreviate.js +24 -0
- package/lib/helpers/abbreviate.js.map +1 -0
- package/lib/helpers/abbreviate.test.d.ts +5 -0
- package/lib/helpers/abbreviate.test.js +28 -0
- package/lib/helpers/abbreviate.test.js.map +1 -0
- package/lib/helpers/asyncArrayFunctions/everyAsync.d.ts +13 -0
- package/lib/helpers/asyncArrayFunctions/everyAsync.js +81 -0
- package/lib/helpers/asyncArrayFunctions/everyAsync.js.map +1 -0
- package/lib/helpers/asyncArrayFunctions/everyAsync.test.d.ts +1 -0
- package/lib/helpers/asyncArrayFunctions/everyAsync.test.js +219 -0
- package/lib/helpers/asyncArrayFunctions/everyAsync.test.js.map +1 -0
- package/lib/helpers/asyncArrayFunctions/filterAsync.d.ts +13 -0
- package/lib/helpers/asyncArrayFunctions/filterAsync.js +81 -0
- package/lib/helpers/asyncArrayFunctions/filterAsync.js.map +1 -0
- package/lib/helpers/asyncArrayFunctions/filterAsync.test.d.ts +1 -0
- package/lib/helpers/asyncArrayFunctions/filterAsync.test.js +244 -0
- package/lib/helpers/asyncArrayFunctions/filterAsync.test.js.map +1 -0
- package/lib/helpers/asyncArrayFunctions/forEachAsync.d.ts +10 -0
- package/lib/helpers/asyncArrayFunctions/forEachAsync.js +72 -0
- package/lib/helpers/asyncArrayFunctions/forEachAsync.js.map +1 -0
- package/lib/helpers/asyncArrayFunctions/forEachAsync.test.d.ts +1 -0
- package/lib/helpers/asyncArrayFunctions/forEachAsync.test.js +223 -0
- package/lib/helpers/asyncArrayFunctions/forEachAsync.test.js.map +1 -0
- package/lib/helpers/asyncArrayFunctions/mapAsync.d.ts +11 -0
- package/lib/helpers/asyncArrayFunctions/mapAsync.js +77 -0
- package/lib/helpers/asyncArrayFunctions/mapAsync.js.map +1 -0
- package/lib/helpers/asyncArrayFunctions/mapAsync.test.d.ts +1 -0
- package/lib/helpers/asyncArrayFunctions/mapAsync.test.js +219 -0
- package/lib/helpers/asyncArrayFunctions/mapAsync.test.js.map +1 -0
- package/lib/helpers/asyncArrayFunctions/someAsync.d.ts +13 -0
- package/lib/helpers/asyncArrayFunctions/someAsync.js +80 -0
- package/lib/helpers/asyncArrayFunctions/someAsync.js.map +1 -0
- package/lib/helpers/asyncArrayFunctions/someAsync.test.d.ts +1 -0
- package/lib/helpers/asyncArrayFunctions/someAsync.test.js +227 -0
- package/lib/helpers/asyncArrayFunctions/someAsync.test.js.map +1 -0
- package/lib/helpers/avg.d.ts +8 -0
- package/lib/helpers/avg.js +24 -0
- package/lib/helpers/avg.js.map +1 -0
- package/lib/helpers/avg.test.d.ts +5 -0
- package/lib/helpers/avg.test.js +25 -0
- package/lib/helpers/avg.test.js.map +1 -0
- package/lib/helpers/capitalize.d.ts +7 -0
- package/lib/helpers/capitalize.js +20 -0
- package/lib/helpers/capitalize.js.map +1 -0
- package/lib/helpers/ceilToNumDecimals.d.ts +9 -0
- package/lib/helpers/ceilToNumDecimals.js +15 -0
- package/lib/helpers/ceilToNumDecimals.js.map +1 -0
- package/lib/helpers/ceilToNumDecimals.test.d.ts +5 -0
- package/lib/helpers/ceilToNumDecimals.test.js +38 -0
- package/lib/helpers/ceilToNumDecimals.test.js.map +1 -0
- package/lib/helpers/cloneDeep.d.ts +8 -0
- package/lib/helpers/cloneDeep.js +15 -0
- package/lib/helpers/cloneDeep.js.map +1 -0
- package/lib/helpers/compareArraysByProp.d.ts +13 -0
- package/lib/helpers/compareArraysByProp.js +62 -0
- package/lib/helpers/compareArraysByProp.js.map +1 -0
- package/lib/helpers/compareArraysByProp.test.d.ts +5 -0
- package/lib/helpers/compareArraysByProp.test.js +140 -0
- package/lib/helpers/compareArraysByProp.test.js.map +1 -0
- package/lib/helpers/extractProp.d.ts +12 -0
- package/lib/helpers/extractProp.js +19 -0
- package/lib/helpers/extractProp.js.map +1 -0
- package/lib/helpers/extractProp.test.d.ts +5 -0
- package/lib/helpers/extractProp.test.js +36 -0
- package/lib/helpers/extractProp.test.js.map +1 -0
- package/lib/helpers/floorToNumDecimals.d.ts +9 -0
- package/lib/helpers/floorToNumDecimals.js +15 -0
- package/lib/helpers/floorToNumDecimals.js.map +1 -0
- package/lib/helpers/floorToNumDecimals.test.d.ts +5 -0
- package/lib/helpers/floorToNumDecimals.test.js +38 -0
- package/lib/helpers/floorToNumDecimals.test.js.map +1 -0
- package/lib/helpers/forceNumIntoBounds.d.ts +10 -0
- package/lib/helpers/forceNumIntoBounds.js +15 -0
- package/lib/helpers/forceNumIntoBounds.js.map +1 -0
- package/lib/helpers/forceNumIntoBounds.test.d.ts +5 -0
- package/lib/helpers/forceNumIntoBounds.test.js +34 -0
- package/lib/helpers/forceNumIntoBounds.test.js.map +1 -0
- package/lib/helpers/genCSV.d.ts +18 -0
- package/lib/helpers/genCSV.js +69 -0
- package/lib/helpers/genCSV.js.map +1 -0
- package/lib/helpers/genCSV.test.d.ts +5 -0
- package/lib/helpers/genCSV.test.js +75 -0
- package/lib/helpers/genCSV.test.js.map +1 -0
- package/lib/helpers/genCommaList.d.ts +12 -0
- package/lib/helpers/genCommaList.js +20 -0
- package/lib/helpers/genCommaList.js.map +1 -0
- package/lib/helpers/genCommaList.test.d.ts +1 -0
- package/lib/helpers/genCommaList.test.js +94 -0
- package/lib/helpers/genCommaList.test.js.map +1 -0
- package/lib/helpers/getHumanReadableDate.d.ts +8 -0
- package/lib/helpers/getHumanReadableDate.js +32 -0
- package/lib/helpers/getHumanReadableDate.js.map +1 -0
- package/lib/helpers/getHumanReadableDate.test.d.ts +5 -0
- package/lib/helpers/getHumanReadableDate.test.js +31 -0
- package/lib/helpers/getHumanReadableDate.test.js.map +1 -0
- package/lib/helpers/getLocalTimeInfo.d.ts +19 -0
- package/lib/helpers/getLocalTimeInfo.js +51 -0
- package/lib/helpers/getLocalTimeInfo.js.map +1 -0
- package/lib/helpers/getLocalTimeInfo.test.d.ts +6 -0
- package/lib/helpers/getLocalTimeInfo.test.js +50 -0
- package/lib/helpers/getLocalTimeInfo.test.js.map +1 -0
- package/lib/helpers/getMonthName.d.ts +14 -0
- package/lib/helpers/getMonthName.js +31 -0
- package/lib/helpers/getMonthName.js.map +1 -0
- package/lib/helpers/getMonthName.test.d.ts +5 -0
- package/lib/helpers/getMonthName.test.js +70 -0
- package/lib/helpers/getMonthName.test.js.map +1 -0
- package/lib/helpers/getOrdinal.d.ts +8 -0
- package/lib/helpers/getOrdinal.js +16 -0
- package/lib/helpers/getOrdinal.js.map +1 -0
- package/lib/helpers/getOrdinal.test.d.ts +5 -0
- package/lib/helpers/getOrdinal.test.js +74 -0
- package/lib/helpers/getOrdinal.test.js.map +1 -0
- package/lib/helpers/getPartOfDay.d.ts +7 -0
- package/lib/helpers/getPartOfDay.js +24 -0
- package/lib/helpers/getPartOfDay.js.map +1 -0
- package/lib/helpers/getPartOfDay.test.d.ts +5 -0
- package/lib/helpers/getPartOfDay.test.js +49 -0
- package/lib/helpers/getPartOfDay.test.js.map +1 -0
- package/lib/helpers/getTimeInfoInET.d.ts +21 -0
- package/lib/helpers/getTimeInfoInET.js +67 -0
- package/lib/helpers/getTimeInfoInET.js.map +1 -0
- package/lib/helpers/getTimeInfoInET.test.d.ts +5 -0
- package/lib/helpers/getTimeInfoInET.test.js +74 -0
- package/lib/helpers/getTimeInfoInET.test.js.map +1 -0
- package/lib/helpers/getTimestampFromTimeInfoInET.d.ts +20 -0
- package/lib/helpers/getTimestampFromTimeInfoInET.js +136 -0
- package/lib/helpers/getTimestampFromTimeInfoInET.js.map +1 -0
- package/lib/helpers/getWordCount.d.ts +10 -0
- package/lib/helpers/getWordCount.js +24 -0
- package/lib/helpers/getWordCount.js.map +1 -0
- package/lib/helpers/idify.d.ts +9 -0
- package/lib/helpers/idify.js +24 -0
- package/lib/helpers/idify.js.map +1 -0
- package/lib/helpers/onlyKeepLetters.d.ts +8 -0
- package/lib/helpers/onlyKeepLetters.js +13 -0
- package/lib/helpers/onlyKeepLetters.js.map +1 -0
- package/lib/helpers/padDecimalZeros.d.ts +10 -0
- package/lib/helpers/padDecimalZeros.js +30 -0
- package/lib/helpers/padDecimalZeros.js.map +1 -0
- package/lib/helpers/padZerosLeft.d.ts +9 -0
- package/lib/helpers/padZerosLeft.js +21 -0
- package/lib/helpers/padZerosLeft.js.map +1 -0
- package/lib/helpers/parallelLimit.d.ts +12 -0
- package/lib/helpers/parallelLimit.js +104 -0
- package/lib/helpers/parallelLimit.js.map +1 -0
- package/lib/helpers/prefixWithAOrAn.d.ts +10 -0
- package/lib/helpers/prefixWithAOrAn.js +28 -0
- package/lib/helpers/prefixWithAOrAn.js.map +1 -0
- package/lib/helpers/roundToNumDecimals.d.ts +9 -0
- package/lib/helpers/roundToNumDecimals.js +15 -0
- package/lib/helpers/roundToNumDecimals.js.map +1 -0
- package/lib/helpers/shuffleArray.d.ts +8 -0
- package/lib/helpers/shuffleArray.js +29 -0
- package/lib/helpers/shuffleArray.js.map +1 -0
- package/lib/helpers/startMinWait.d.ts +9 -0
- package/lib/helpers/startMinWait.js +79 -0
- package/lib/helpers/startMinWait.js.map +1 -0
- package/lib/helpers/stringsToHumanReadableList.d.ts +10 -0
- package/lib/helpers/stringsToHumanReadableList.js +37 -0
- package/lib/helpers/stringsToHumanReadableList.js.map +1 -0
- package/lib/helpers/sum.d.ts +8 -0
- package/lib/helpers/sum.js +15 -0
- package/lib/helpers/sum.js.map +1 -0
- package/lib/helpers/validators/ChicagoTitleCase.d.ts +9 -0
- package/lib/helpers/validators/ChicagoTitleCase.js +31 -0
- package/lib/helpers/validators/ChicagoTitleCase.js.map +1 -0
- package/lib/helpers/validators/ChicagoTitleCase.test.d.ts +0 -0
- package/lib/helpers/validators/ChicagoTitleCase.test.js +79 -0
- package/lib/helpers/validators/ChicagoTitleCase.test.js.map +1 -0
- package/lib/helpers/validators/findURL.d.ts +0 -0
- package/lib/helpers/validators/findURL.js +39 -0
- package/lib/helpers/validators/findURL.js.map +1 -0
- package/lib/helpers/validators/findURL.test.d.ts +0 -0
- package/lib/helpers/validators/findURL.test.js +77 -0
- package/lib/helpers/validators/findURL.test.js.map +1 -0
- package/lib/helpers/validators/shared/constants/ERROR_MESSAGES.d.ts +10 -0
- package/lib/helpers/validators/shared/constants/ERROR_MESSAGES.js +21 -0
- package/lib/helpers/validators/shared/constants/ERROR_MESSAGES.js.map +1 -0
- package/lib/helpers/validators/shared/helpers/validateRegex.d.ts +19 -0
- package/lib/helpers/validators/shared/helpers/validateRegex.js +34 -0
- package/lib/helpers/validators/shared/helpers/validateRegex.js.map +1 -0
- package/lib/helpers/validators/shared/types/ValidationResult.d.ts +12 -0
- package/lib/helpers/validators/shared/types/ValidationResult.js +3 -0
- package/lib/helpers/validators/shared/types/ValidationResult.js.map +1 -0
- package/lib/helpers/validators/validURL.d.ts +8 -0
- package/lib/helpers/validators/validURL.js +20 -0
- package/lib/helpers/validators/validURL.js.map +1 -0
- package/lib/helpers/validators/validURL.test.d.ts +0 -0
- package/lib/helpers/validators/validURL.test.js +83 -0
- package/lib/helpers/validators/validURL.test.js.map +1 -0
- package/lib/helpers/validators/validateEmail.d.ts +11 -0
- package/lib/helpers/validators/validateEmail.js +39 -0
- package/lib/helpers/validators/validateEmail.js.map +1 -0
- package/lib/helpers/validators/validateEmail.test.d.ts +1 -0
- package/lib/helpers/validators/validateEmail.test.js +140 -0
- package/lib/helpers/validators/validateEmail.test.js.map +1 -0
- package/lib/helpers/validators/validatePhoneNumber.d.ts +11 -0
- package/lib/helpers/validators/validatePhoneNumber.js +40 -0
- package/lib/helpers/validators/validatePhoneNumber.js.map +1 -0
- package/lib/helpers/validators/validatePhoneNumber.test.d.ts +1 -0
- package/lib/helpers/validators/validatePhoneNumber.test.js +123 -0
- package/lib/helpers/validators/validatePhoneNumber.test.js.map +1 -0
- package/lib/helpers/validators/validateString.d.ts +22 -0
- package/lib/helpers/validators/validateString.js +124 -0
- package/lib/helpers/validators/validateString.js.map +1 -0
- package/lib/helpers/validators/validateString.test.d.ts +1 -0
- package/lib/helpers/validators/validateString.test.js +163 -0
- package/lib/helpers/validators/validateString.test.js.map +1 -0
- package/lib/helpers/waitMs.d.ts +7 -0
- package/lib/helpers/waitMs.js +68 -0
- package/lib/helpers/waitMs.js.map +1 -0
- package/lib/index.d.ts +63 -0
- package/lib/index.js +124 -0
- package/lib/index.js.map +1 -0
- package/lib/types/CommonKitErrorCode.d.ts +10 -0
- package/lib/types/CommonKitErrorCode.js +15 -0
- package/lib/types/CommonKitErrorCode.js.map +1 -0
- package/lib/types/DayOfWeek.d.ts +14 -0
- package/lib/types/DayOfWeek.js +18 -0
- package/lib/types/DayOfWeek.js.map +1 -0
- package/lib/types/Log/LogMainInfo.d.ts +39 -0
- package/lib/types/Log/LogMainInfo.js +3 -0
- package/lib/types/Log/LogMainInfo.js.map +1 -0
- package/lib/types/Log/LogSourceSpecificInfo.d.ts +13 -0
- package/lib/types/Log/LogSourceSpecificInfo.js +3 -0
- package/lib/types/Log/LogSourceSpecificInfo.js.map +1 -0
- package/lib/types/Log/LogTypeSpecificInfo.d.ts +17 -0
- package/lib/types/Log/LogTypeSpecificInfo.js +3 -0
- package/lib/types/Log/LogTypeSpecificInfo.js.map +1 -0
- package/lib/types/Log/index.d.ts +10 -0
- package/lib/types/Log/index.js +3 -0
- package/lib/types/Log/index.js.map +1 -0
- package/lib/types/LogAction.d.ts +29 -0
- package/lib/types/LogAction.js +55 -0
- package/lib/types/LogAction.js.map +1 -0
- package/lib/types/LogBuiltInMetadata.d.ts +16 -0
- package/lib/types/LogBuiltInMetadata.js +21 -0
- package/lib/types/LogBuiltInMetadata.js.map +1 -0
- package/lib/types/LogFunction.d.ts +24 -0
- package/lib/types/LogFunction.js +3 -0
- package/lib/types/LogFunction.js.map +1 -0
- package/lib/types/LogLevel.d.ts +10 -0
- package/lib/types/LogLevel.js +14 -0
- package/lib/types/LogLevel.js.map +1 -0
- package/lib/types/LogMetadataContextMap.d.ts +11 -0
- package/lib/types/LogMetadataContextMap.js +3 -0
- package/lib/types/LogMetadataContextMap.js.map +1 -0
- package/lib/types/LogMetadataTagMap.d.ts +8 -0
- package/lib/types/LogMetadataTagMap.js +3 -0
- package/lib/types/LogMetadataTagMap.js.map +1 -0
- package/lib/types/LogMetadataTargetMap.d.ts +8 -0
- package/lib/types/LogMetadataTargetMap.js +3 -0
- package/lib/types/LogMetadataTargetMap.js.map +1 -0
- package/lib/types/LogMetadataType.d.ts +13 -0
- package/lib/types/LogMetadataType.js +3 -0
- package/lib/types/LogMetadataType.js.map +1 -0
- package/lib/types/LogSource.d.ts +9 -0
- package/lib/types/LogSource.js +15 -0
- package/lib/types/LogSource.js.map +1 -0
- package/lib/types/LogType.d.ts +9 -0
- package/lib/types/LogType.js +15 -0
- package/lib/types/LogType.js.map +1 -0
- package/lib/types/ParamType.d.ts +17 -0
- package/lib/types/ParamType.js +21 -0
- package/lib/types/ParamType.js.map +1 -0
- package/package.json +47 -0
- package/src/constants/DAY_IN_MS.ts +7 -0
- package/src/constants/HOUR_IN_MS.ts +7 -0
- package/src/constants/LOG_REVIEW_GET_LOGS_ROUTE.ts +9 -0
- package/src/constants/LOG_REVIEW_ROUTE_PATH_PREFIX.ts +9 -0
- package/src/constants/LOG_REVIEW_STATUS_ROUTE.ts +10 -0
- package/src/constants/LOG_ROUTE_PATH.ts +9 -0
- package/src/constants/MINUTE_IN_MS.ts +7 -0
- package/src/constants/ROUTE_PATH_PREFIX.ts +7 -0
- package/src/constants/SELECT_ADMIN_CHECK_ROUTE.ts +7 -0
- package/src/errors/ErrorWithCode.ts +15 -0
- package/src/helpers/abbreviate.test.ts +26 -0
- package/src/helpers/abbreviate.ts +25 -0
- package/src/helpers/asyncArrayFunctions/everyAsync.test.ts +114 -0
- package/src/helpers/asyncArrayFunctions/everyAsync.ts +51 -0
- package/src/helpers/asyncArrayFunctions/filterAsync.test.ts +126 -0
- package/src/helpers/asyncArrayFunctions/filterAsync.ts +50 -0
- package/src/helpers/asyncArrayFunctions/forEachAsync.test.ts +136 -0
- package/src/helpers/asyncArrayFunctions/forEachAsync.ts +40 -0
- package/src/helpers/asyncArrayFunctions/mapAsync.test.ts +125 -0
- package/src/helpers/asyncArrayFunctions/mapAsync.ts +46 -0
- package/src/helpers/asyncArrayFunctions/someAsync.test.ts +92 -0
- package/src/helpers/asyncArrayFunctions/someAsync.ts +49 -0
- package/src/helpers/avg.test.ts +24 -0
- package/src/helpers/avg.ts +22 -0
- package/src/helpers/capitalize.ts +20 -0
- package/src/helpers/ceilToNumDecimals.test.ts +39 -0
- package/src/helpers/ceilToNumDecimals.ts +13 -0
- package/src/helpers/cloneDeep.ts +11 -0
- package/src/helpers/compareArraysByProp.test.ts +147 -0
- package/src/helpers/compareArraysByProp.ts +56 -0
- package/src/helpers/extractProp.test.ts +34 -0
- package/src/helpers/extractProp.ts +17 -0
- package/src/helpers/floorToNumDecimals.test.ts +39 -0
- package/src/helpers/floorToNumDecimals.ts +13 -0
- package/src/helpers/forceNumIntoBounds.test.ts +34 -0
- package/src/helpers/forceNumIntoBounds.ts +19 -0
- package/src/helpers/genCSV.test.ts +77 -0
- package/src/helpers/genCSV.ts +87 -0
- package/src/helpers/genCommaList.test.ts +57 -0
- package/src/helpers/genCommaList.ts +21 -0
- package/src/helpers/getHumanReadableDate.test.ts +29 -0
- package/src/helpers/getHumanReadableDate.ts +36 -0
- package/src/helpers/getLocalTimeInfo.test.ts +48 -0
- package/src/helpers/getLocalTimeInfo.ts +58 -0
- package/src/helpers/getMonthName.test.ts +79 -0
- package/src/helpers/getMonthName.ts +29 -0
- package/src/helpers/getOrdinal.test.ts +84 -0
- package/src/helpers/getOrdinal.ts +14 -0
- package/src/helpers/getPartOfDay.test.ts +56 -0
- package/src/helpers/getPartOfDay.ts +20 -0
- package/src/helpers/getTimeInfoInET.test.ts +72 -0
- package/src/helpers/getTimeInfoInET.ts +79 -0
- package/src/helpers/getTimestampFromTimeInfoInET.ts +179 -0
- package/src/helpers/getWordCount.ts +26 -0
- package/src/helpers/idify.ts +24 -0
- package/src/helpers/onlyKeepLetters.ts +11 -0
- package/src/helpers/padDecimalZeros.ts +32 -0
- package/src/helpers/padZerosLeft.ts +21 -0
- package/src/helpers/parallelLimit.ts +63 -0
- package/src/helpers/prefixWithAOrAn.ts +29 -0
- package/src/helpers/roundToNumDecimals.ts +13 -0
- package/src/helpers/shuffleArray.ts +19 -0
- package/src/helpers/startMinWait.ts +33 -0
- package/src/helpers/stringsToHumanReadableList.ts +39 -0
- package/src/helpers/sum.ts +16 -0
- package/src/helpers/validators/ChicagoTitleCase.test.ts +85 -0
- package/src/helpers/validators/ChicagoTitleCase.ts +32 -0
- package/src/helpers/validators/findURL.test.ts +83 -0
- package/src/helpers/validators/findURL.ts +43 -0
- package/src/helpers/validators/shared/constants/ERROR_MESSAGES.ts +18 -0
- package/src/helpers/validators/shared/helpers/validateRegex.ts +47 -0
- package/src/helpers/validators/shared/types/ValidationResult.ts +20 -0
- package/src/helpers/validators/validURL.test.ts +90 -0
- package/src/helpers/validators/validURL.ts +18 -0
- package/src/helpers/validators/validateEmail.test.ts +110 -0
- package/src/helpers/validators/validateEmail.ts +47 -0
- package/src/helpers/validators/validatePhoneNumber.test.ts +94 -0
- package/src/helpers/validators/validatePhoneNumber.ts +49 -0
- package/src/helpers/validators/validateString.test.ts +173 -0
- package/src/helpers/validators/validateString.ts +171 -0
- package/src/helpers/waitMs.ts +12 -0
- package/src/index.ts +139 -0
- package/src/types/CommonKitErrorCode.ts +13 -0
- package/src/types/DayOfWeek.ts +15 -0
- package/src/types/Log/LogMainInfo.ts +69 -0
- package/src/types/Log/LogSourceSpecificInfo.ts +25 -0
- package/src/types/Log/LogTypeSpecificInfo.ts +33 -0
- package/src/types/Log/index.ts +17 -0
- package/src/types/LogAction.ts +52 -0
- package/src/types/LogBuiltInMetadata.ts +19 -0
- package/src/types/LogFunction.ts +46 -0
- package/src/types/LogLevel.ts +11 -0
- package/src/types/LogMetadataContextMap.ts +15 -0
- package/src/types/LogMetadataTagMap.ts +9 -0
- package/src/types/LogMetadataTargetMap.ts +9 -0
- package/src/types/LogMetadataType.ts +16 -0
- package/src/types/LogSource.ts +12 -0
- package/src/types/LogType.ts +12 -0
- package/src/types/ParamType.ts +18 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Import the function to be tested
|
|
2
|
+
// import findURLs from './findURL';
|
|
3
|
+
|
|
4
|
+
// // Import constants
|
|
5
|
+
// import { INVALID_STRING_ERRORS, INVALID_REGEX_ERROR } from './shared/constants/ERROR_MESSAGES';
|
|
6
|
+
|
|
7
|
+
// /*------------------------------------------------------------------------*/
|
|
8
|
+
// /* ---------------------------- Valid Tests --------------------------- */
|
|
9
|
+
// /*------------------------------------------------------------------------*/
|
|
10
|
+
|
|
11
|
+
// const validTests: { block: string, expected: { start: number, end: number }[] }[] = [
|
|
12
|
+
// {
|
|
13
|
+
// block: 'Visit http://example.com for more information.',
|
|
14
|
+
// expected: [{ start: 6, end: 23 }],
|
|
15
|
+
// },
|
|
16
|
+
// {
|
|
17
|
+
// block: 'Multiple URLs: http://one.com and http://two.com.',
|
|
18
|
+
// expected: [
|
|
19
|
+
// { start: 15, end: 29 },
|
|
20
|
+
// { start: 34, end: 48 },
|
|
21
|
+
// ],
|
|
22
|
+
// },
|
|
23
|
+
// {
|
|
24
|
+
// block: 'Localhost URLs: http://localhost and http://127.0.0.1.',
|
|
25
|
+
// expected: [
|
|
26
|
+
// { start: 16, end: 31 },
|
|
27
|
+
// { start: 36, end: 52 },
|
|
28
|
+
// ],
|
|
29
|
+
// },
|
|
30
|
+
// {
|
|
31
|
+
// block: 'Embedded URL: text https://embedded-url.com?query=1&value=2.',
|
|
32
|
+
// expected: [{ start: 13, end: 51 }],
|
|
33
|
+
// },
|
|
34
|
+
// {
|
|
35
|
+
// block: 'Secure site: https://secure-site.com/path?query=string#fragment',
|
|
36
|
+
// expected: [{ start: 13, end: 58 }],
|
|
37
|
+
// },
|
|
38
|
+
// ];
|
|
39
|
+
|
|
40
|
+
// test(
|
|
41
|
+
// 'Returns correct start and end indices for valid URLs within a string.',
|
|
42
|
+
// async () => {
|
|
43
|
+
// validTests.forEach(({ block, expected }) => {
|
|
44
|
+
// expect(findURLs(block)).toStrictEqual(expected);
|
|
45
|
+
// });
|
|
46
|
+
// },
|
|
47
|
+
// );
|
|
48
|
+
|
|
49
|
+
// /*------------------------------------------------------------------------*/
|
|
50
|
+
// /* ---------------------------- Invalid Tests --------------------------- */
|
|
51
|
+
// /*------------------------------------------------------------------------*/
|
|
52
|
+
|
|
53
|
+
// const invalidTests: { block: string, expected: { start: number, end: number }[] }[] = [
|
|
54
|
+
// {
|
|
55
|
+
// block: 'No URL.',
|
|
56
|
+
// expected: [],
|
|
57
|
+
// },
|
|
58
|
+
// {
|
|
59
|
+
// block: 'URL format is wrong: http:/example.com and htt://example.com.',
|
|
60
|
+
// expected: [],
|
|
61
|
+
// },
|
|
62
|
+
// {
|
|
63
|
+
// block: 'Any punctuation after the URL http://example.com, should not count.',
|
|
64
|
+
// expected: [{ start: 20, end: 37 }],
|
|
65
|
+
// },
|
|
66
|
+
// {
|
|
67
|
+
// block: 'Starting punctuation ,http://example.com should not count.',
|
|
68
|
+
// expected: [{ start: 22, end: 39 }],
|
|
69
|
+
// },
|
|
70
|
+
// {
|
|
71
|
+
// block: 'Spaces in the middle http://exa mple.com is invalid.',
|
|
72
|
+
// expected: [],
|
|
73
|
+
// },
|
|
74
|
+
// ];
|
|
75
|
+
|
|
76
|
+
// test(
|
|
77
|
+
// 'Returns empty array for strings without valid URLs.',
|
|
78
|
+
// async () => {
|
|
79
|
+
// invalidTests.forEach(({ block, expected }) => {
|
|
80
|
+
// expect(findURLs(block)).toStrictEqual(expected);
|
|
81
|
+
// });
|
|
82
|
+
// },
|
|
83
|
+
// );
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// /**
|
|
2
|
+
// * This function finds URLs within a given string and returns an array of
|
|
3
|
+
// * their locations.
|
|
4
|
+
// * @author Leisha Bhandari
|
|
5
|
+
// * @param block: The block of text to search for URLs
|
|
6
|
+
// * @returns Arrays where each of them contain the start and end index of the URL
|
|
7
|
+
// */
|
|
8
|
+
// function findURLs(block: string): { start: number, end: number }[] {
|
|
9
|
+
// // Expression representing the skeleton of a URL to help match and find the
|
|
10
|
+
// // URLs within the block of text (Also takes care of Unicode characters)
|
|
11
|
+
// const urlSkeleton = /(https?:\/\/[^\s\u0000-\u001F.,]+[^\s\u0000-\u001F.,]?(?:\?[^\s\u0000-\u001F]+)?(?:#[^\s\u0000-\u001F]+)?)/g;
|
|
12
|
+
// const found: { start: number, end: number }[] = [];
|
|
13
|
+
// let match: RegExpExecArray | null;
|
|
14
|
+
|
|
15
|
+
// // While loop to find the URLs in the given block of texts using the URL
|
|
16
|
+
// // skeleton
|
|
17
|
+
// while ((match === urlSkeleton.exec(block))
|
|
18
|
+
// && match !== null) {
|
|
19
|
+
// // To find the beginning index of the URL
|
|
20
|
+
// let start = match.index;
|
|
21
|
+
// // To find the last index of the URL
|
|
22
|
+
// let end = match.index + match[0].length;
|
|
23
|
+
|
|
24
|
+
// // If statements to check whether the URL is followed by some kind of
|
|
25
|
+
// // punctuation mark
|
|
26
|
+
// if (block.charAt(end) === '.' || /[,;:!?"]/.test(block.charAt(end))) {
|
|
27
|
+
// end--;
|
|
28
|
+
// }
|
|
29
|
+
|
|
30
|
+
// // While statement to make sure that the URL does not start with a
|
|
31
|
+
// // punctuation mark
|
|
32
|
+
// while (start > 0 && /[.,:;!?]/.test(block.charAt(start - 1))) {
|
|
33
|
+
// start--;
|
|
34
|
+
// }
|
|
35
|
+
|
|
36
|
+
// // The object with start and end index of the URL is found and pushed to
|
|
37
|
+
// // the found array
|
|
38
|
+
// found.push({ start, end });
|
|
39
|
+
// }
|
|
40
|
+
|
|
41
|
+
// // Returns the array of the found URLs location
|
|
42
|
+
// return found;
|
|
43
|
+
// }
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*------------------------------------------------------------------------*/
|
|
2
|
+
/* ------------------------------ Constants ----------------------------- */
|
|
3
|
+
/*------------------------------------------------------------------------*/
|
|
4
|
+
|
|
5
|
+
export const INVALID_REGEX_ERROR = 'input does not follow the requested format';
|
|
6
|
+
export const INVALID_EMAIL_ERROR = 'Please provide a valid email address.';
|
|
7
|
+
export const INVALID_PHONE_ERROR = 'Please provide a valid phone number.';
|
|
8
|
+
export const INVALID_STRING_ERRORS = {
|
|
9
|
+
MIN_LEN: (minLen: number) => {
|
|
10
|
+
return `input must not be under ${minLen} character(s)`;
|
|
11
|
+
},
|
|
12
|
+
MAX_LEN: (maxLen: number) => {
|
|
13
|
+
return `input must not be over ${maxLen} character(s)`;
|
|
14
|
+
},
|
|
15
|
+
LETTERS_ONLY: 'input must only contain letters',
|
|
16
|
+
NUMBERS_ONLY: 'input must only contain numbers',
|
|
17
|
+
MESSAGE_INTRO: 'The following error(s) occurred: ',
|
|
18
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Import types
|
|
2
|
+
import ValidationResult from '../types/ValidationResult';
|
|
3
|
+
|
|
4
|
+
// Import constants
|
|
5
|
+
import { INVALID_REGEX_ERROR } from '../constants/ERROR_MESSAGES';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Determines whether a given input string is considered valid based on
|
|
9
|
+
* the provided regex.
|
|
10
|
+
* @author Austen Money
|
|
11
|
+
* @param opts object containing all args
|
|
12
|
+
* @param opts.input user-provided input to validate
|
|
13
|
+
* @param opts.regex regular expression to check against input
|
|
14
|
+
* @param [opts.regexDescription] description of what regexString is checking
|
|
15
|
+
* for, used to customize error message
|
|
16
|
+
* @returns the unchanged input if valid, or a customized error message if
|
|
17
|
+
* invalid
|
|
18
|
+
*/
|
|
19
|
+
const validateRegex = (
|
|
20
|
+
opts: {
|
|
21
|
+
input: string,
|
|
22
|
+
regex: RegExp,
|
|
23
|
+
regexDescription?: string,
|
|
24
|
+
},
|
|
25
|
+
): ValidationResult<string> => {
|
|
26
|
+
// customize error message in case of invalid input
|
|
27
|
+
const errorMessage = `${INVALID_REGEX_ERROR}${
|
|
28
|
+
opts.regexDescription
|
|
29
|
+
? ': '
|
|
30
|
+
: ''
|
|
31
|
+
}${opts.regexDescription}`;
|
|
32
|
+
|
|
33
|
+
// return error message if test is invalid, or input string if valid
|
|
34
|
+
return (
|
|
35
|
+
opts.regex.test(opts.input)
|
|
36
|
+
? {
|
|
37
|
+
isValid: true,
|
|
38
|
+
cleanedValue: opts.input,
|
|
39
|
+
}
|
|
40
|
+
: {
|
|
41
|
+
isValid: false,
|
|
42
|
+
errorMessage,
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default validateRegex;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result of a validation function.
|
|
3
|
+
* @author Austen Money
|
|
4
|
+
*/
|
|
5
|
+
type ValidationResult<CleanedValueType> = (
|
|
6
|
+
| {
|
|
7
|
+
// if true, the validation was successful
|
|
8
|
+
isValid: true,
|
|
9
|
+
// the cleaned version of the value
|
|
10
|
+
cleanedValue: CleanedValueType,
|
|
11
|
+
}
|
|
12
|
+
| {
|
|
13
|
+
// if false, the validation was not successful
|
|
14
|
+
isValid: false,
|
|
15
|
+
// describes why the validation failed
|
|
16
|
+
errorMessage: string,
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export default ValidationResult;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
|
|
2
|
+
// Import the function to be tested
|
|
3
|
+
// import isValid from './validURL';
|
|
4
|
+
|
|
5
|
+
// // Import constants
|
|
6
|
+
// import { INVALID_STRING_ERRORS, INVALID_REGEX_ERROR } from './shared/constants/ERROR_MESSAGES';
|
|
7
|
+
|
|
8
|
+
// /*------------------------------------------------------------------------*/
|
|
9
|
+
// /* ---------------------------- Valid Tests --------------------------- */
|
|
10
|
+
// /*------------------------------------------------------------------------*/
|
|
11
|
+
|
|
12
|
+
// const validUrls: string[] = [
|
|
13
|
+
// 'http://example.com',
|
|
14
|
+
// 'https://example.com',
|
|
15
|
+
// 'http://www.example.com',
|
|
16
|
+
// 'https://www.example.com',
|
|
17
|
+
// 'https://example.com/path',
|
|
18
|
+
// 'http://example.com/path',
|
|
19
|
+
// 'https://example.com?query=string',
|
|
20
|
+
// 'http://example.com?query=string',
|
|
21
|
+
// 'https://example.com#fragment',
|
|
22
|
+
// 'http://example.com#fragment',
|
|
23
|
+
// 'http://localhost',
|
|
24
|
+
// 'https://localhost:3000',
|
|
25
|
+
// 'http://localhost:3000',
|
|
26
|
+
// 'http://127.0.0.1',
|
|
27
|
+
// 'http://127.0.0.1:3000',
|
|
28
|
+
// 'ftp://example.com/path',
|
|
29
|
+
// 'ftp://example.com',
|
|
30
|
+
// 'https://127.0.0.1:3000',
|
|
31
|
+
// 'file:///C:/path/to/file'
|
|
32
|
+
// ];
|
|
33
|
+
|
|
34
|
+
// test(
|
|
35
|
+
// 'Returns true for a given valid URL.',
|
|
36
|
+
// async () => {
|
|
37
|
+
// validUrls.forEach((url) => {
|
|
38
|
+
// expect(isValid(url)).toBe(true);
|
|
39
|
+
// });
|
|
40
|
+
// },
|
|
41
|
+
// );
|
|
42
|
+
|
|
43
|
+
// /*------------------------------------------------------------------------*/
|
|
44
|
+
// /* ---------------------------- Invalid Tests --------------------------- */
|
|
45
|
+
// /*------------------------------------------------------------------------*/
|
|
46
|
+
|
|
47
|
+
// const invalidUrls: string[] = [
|
|
48
|
+
// '',
|
|
49
|
+
// ' ',
|
|
50
|
+
// 'example',
|
|
51
|
+
// 'http://',
|
|
52
|
+
// 'http://.',
|
|
53
|
+
// 'http://..',
|
|
54
|
+
// 'http://##/',
|
|
55
|
+
// 'http://../',
|
|
56
|
+
// 'http://??/',
|
|
57
|
+
// 'http://#',
|
|
58
|
+
// 'http://##',
|
|
59
|
+
// '//',
|
|
60
|
+
// '//a',
|
|
61
|
+
// '///a',
|
|
62
|
+
// '///',
|
|
63
|
+
// 'http:///a',
|
|
64
|
+
// 'http://www.foo.bar./',
|
|
65
|
+
// 'http://foo.bar/foo(bar)baz quux',
|
|
66
|
+
// 'http://3628126748',
|
|
67
|
+
// 'http://.www.foo.bar/',
|
|
68
|
+
// 'http://.www.foo.bar./',
|
|
69
|
+
// 'http://123.123.123',
|
|
70
|
+
// 'http://1.1.1.1.1',
|
|
71
|
+
// 'http://example.com:99999',
|
|
72
|
+
// 'http://example.com:80:80',
|
|
73
|
+
// 'http://example.com::80',
|
|
74
|
+
// 'http://example.com:-80',
|
|
75
|
+
// 'http://-example.com',
|
|
76
|
+
// 'http://example.com-',
|
|
77
|
+
// 'http://example.com_',
|
|
78
|
+
// 'http://example..com',
|
|
79
|
+
// 'http://example.com.',
|
|
80
|
+
// 'http://.example.com'
|
|
81
|
+
// ];
|
|
82
|
+
|
|
83
|
+
// test(
|
|
84
|
+
// 'Returns false for a given invalid URL.',
|
|
85
|
+
// async () => {
|
|
86
|
+
// invalidUrls.forEach((url) => {
|
|
87
|
+
// expect(isValid(url)).toBe(false);
|
|
88
|
+
// });
|
|
89
|
+
// },
|
|
90
|
+
// );
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function checks if a given input string is a valid URL.
|
|
3
|
+
* @author Leisha Bhandari
|
|
4
|
+
* @param URL: The input string that needs checked as a URL or not.
|
|
5
|
+
* @returns A true boolean value if the input string is a valid URL, and a false
|
|
6
|
+
* boolean value if the input string is a invalid URL
|
|
7
|
+
*/
|
|
8
|
+
function isValid(url: string): boolean {
|
|
9
|
+
// Uses the input URL to create a URL object
|
|
10
|
+
try {
|
|
11
|
+
new URL(url);
|
|
12
|
+
// URL constructor does not throw an error, so input URL is valid
|
|
13
|
+
return true;
|
|
14
|
+
} catch (err) {
|
|
15
|
+
// URL constructor throws an error, so input URL is invalid
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Import types
|
|
2
|
+
import ValidationResult from './shared/types/ValidationResult';
|
|
3
|
+
|
|
4
|
+
// Import constants
|
|
5
|
+
import { INVALID_EMAIL_ERROR } from './shared/constants/ERROR_MESSAGES';
|
|
6
|
+
|
|
7
|
+
// Import function
|
|
8
|
+
import validateEmail from './validateEmail';
|
|
9
|
+
|
|
10
|
+
/*------------------------------------------------------------------------*/
|
|
11
|
+
/* ---------------------------- Valid Tests --------------------------- */
|
|
12
|
+
/*------------------------------------------------------------------------*/
|
|
13
|
+
|
|
14
|
+
const validEmailPairs: { input: string, cleaned: string }[] = [
|
|
15
|
+
{
|
|
16
|
+
input: 'username@gmail.com',
|
|
17
|
+
cleaned: 'username@gmail.com',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
input: 'u@hotmail.org',
|
|
21
|
+
cleaned: 'u@hotmail.org',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
input: ' username@gmail.com',
|
|
25
|
+
cleaned: 'username@gmail.com',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
input: 'username@gmail.com ',
|
|
29
|
+
cleaned: 'username@gmail.com',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
input: ' username@gmail.com ',
|
|
33
|
+
cleaned: 'username@gmail.com',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
input: 'username@harvard.edu',
|
|
37
|
+
cleaned: 'username@harvard.edu',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
input: 'username@harvard.subdomain.edu',
|
|
41
|
+
cleaned: 'username@harvard.subdomain.edu',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
input: '\nusername@harvard.subdomain.edu',
|
|
45
|
+
cleaned: 'username@harvard.subdomain.edu',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
input: '\n\tusername@harvard.subdomain.edu',
|
|
49
|
+
cleaned: 'username@harvard.subdomain.edu',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
input: 'username@harvard.subdomain.edu\n',
|
|
53
|
+
cleaned: 'username@harvard.subdomain.edu',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
input: 'username@harvard.subdomain.edu\n\t',
|
|
57
|
+
cleaned: 'username@harvard.subdomain.edu',
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
test(
|
|
62
|
+
'Returns true for a given valid email and removes any leading or trailing whitespace.',
|
|
63
|
+
async () => {
|
|
64
|
+
validEmailPairs.forEach((pair) => {
|
|
65
|
+
const validResponse: ValidationResult<string> = {
|
|
66
|
+
isValid: true,
|
|
67
|
+
cleanedValue: pair.cleaned,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
expect(validateEmail(pair.input)).toStrictEqual(validResponse);
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
/*------------------------------------------------------------------------*/
|
|
76
|
+
/* ---------------------------- Invalid Tests --------------------------- */
|
|
77
|
+
/*------------------------------------------------------------------------*/
|
|
78
|
+
|
|
79
|
+
const invalidEmails: string[] = [
|
|
80
|
+
'',
|
|
81
|
+
' ',
|
|
82
|
+
'gmail.com',
|
|
83
|
+
'@gmail.com ',
|
|
84
|
+
'username',
|
|
85
|
+
'username@.com',
|
|
86
|
+
'user name@gmail.com',
|
|
87
|
+
'username @gmail.com',
|
|
88
|
+
'username@ gmail.com',
|
|
89
|
+
'username@gmail .com',
|
|
90
|
+
'username\t@gmail.com',
|
|
91
|
+
'username\n@gmail.com',
|
|
92
|
+
'username@gmail\n.com',
|
|
93
|
+
'username@gmail.\tcom',
|
|
94
|
+
'user\nname@gmail.com',
|
|
95
|
+
'user\tname@gmail.com',
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
const invalidResponse: ValidationResult<string> = {
|
|
99
|
+
isValid: false,
|
|
100
|
+
errorMessage: INVALID_EMAIL_ERROR,
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
test(
|
|
104
|
+
'Returns false for a given invalid email.',
|
|
105
|
+
async () => {
|
|
106
|
+
invalidEmails.forEach((email) => {
|
|
107
|
+
expect(validateEmail(email)).toStrictEqual(invalidResponse);
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Import helpers
|
|
2
|
+
import validateRegex from './shared/helpers/validateRegex';
|
|
3
|
+
|
|
4
|
+
// Import constants
|
|
5
|
+
import { INVALID_EMAIL_ERROR } from './shared/constants/ERROR_MESSAGES';
|
|
6
|
+
|
|
7
|
+
// Import types
|
|
8
|
+
import ValidationResult from './shared/types/ValidationResult';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Determines whether a given email address is valid.
|
|
12
|
+
* @author Austen Money
|
|
13
|
+
* @param email email address to validate
|
|
14
|
+
* @returns whether email fulfills proper formatting requirements, includes a
|
|
15
|
+
* cleaned version of the address without leading or trailing
|
|
16
|
+
* whitespace if valid or an error message if invalid.
|
|
17
|
+
*/
|
|
18
|
+
const validateEmail = (
|
|
19
|
+
email: string,
|
|
20
|
+
): ValidationResult<string> => {
|
|
21
|
+
// validation regex, sourced from HTML living standard: http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#e-mail-state-(type=email)
|
|
22
|
+
// eslint-disable-next-line max-len
|
|
23
|
+
const emailRegex = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
24
|
+
|
|
25
|
+
// remove leading and trailing whitespace
|
|
26
|
+
const cleanedValue: string = email.replace(/^\s+|\s+$/g, '');
|
|
27
|
+
|
|
28
|
+
// validate email with regex, and return error if not valid
|
|
29
|
+
return (
|
|
30
|
+
validateRegex(
|
|
31
|
+
{
|
|
32
|
+
input: cleanedValue,
|
|
33
|
+
regex: emailRegex,
|
|
34
|
+
},
|
|
35
|
+
).isValid
|
|
36
|
+
? {
|
|
37
|
+
isValid: true,
|
|
38
|
+
cleanedValue,
|
|
39
|
+
}
|
|
40
|
+
: {
|
|
41
|
+
isValid: false,
|
|
42
|
+
errorMessage: INVALID_EMAIL_ERROR,
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default validateEmail;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Import types
|
|
2
|
+
import ValidationResult from './shared/types/ValidationResult';
|
|
3
|
+
|
|
4
|
+
// Import constants
|
|
5
|
+
import { INVALID_PHONE_ERROR } from './shared/constants/ERROR_MESSAGES';
|
|
6
|
+
|
|
7
|
+
// Import function
|
|
8
|
+
import validatePhoneNumber from './validatePhoneNumber';
|
|
9
|
+
|
|
10
|
+
/*------------------------------------------------------------------------*/
|
|
11
|
+
/* ---------------------------- Valid Tests --------------------------- */
|
|
12
|
+
/*------------------------------------------------------------------------*/
|
|
13
|
+
|
|
14
|
+
const cleanedNumber = '1234567890';
|
|
15
|
+
const cleanedNumberExt = '11234567890';
|
|
16
|
+
|
|
17
|
+
const validPhoneNumbers: { input: string, cleaned: string }[] = [
|
|
18
|
+
{
|
|
19
|
+
input: '1234567890',
|
|
20
|
+
cleaned: cleanedNumber,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
input: '(123)-456-7890',
|
|
24
|
+
cleaned: cleanedNumber,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
input: '123-456-7890',
|
|
28
|
+
cleaned: cleanedNumber,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
input: '(123)456-7890',
|
|
32
|
+
cleaned: cleanedNumber,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
input: '(123)4567890',
|
|
36
|
+
cleaned: cleanedNumber,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
input: ' 123456-7890 ',
|
|
40
|
+
cleaned: cleanedNumber,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
input: '+1 123 456 7890',
|
|
44
|
+
cleaned: cleanedNumberExt,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
input: '+1123456 7890',
|
|
48
|
+
cleaned: cleanedNumberExt,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
input: '+1(123)456-7890',
|
|
52
|
+
cleaned: cleanedNumberExt,
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
test(
|
|
57
|
+
'Returns true for a given valid phone number and removes any non-digit characters.',
|
|
58
|
+
async () => {
|
|
59
|
+
validPhoneNumbers.forEach((pair) => {
|
|
60
|
+
const validResponse: ValidationResult<string> = {
|
|
61
|
+
isValid: true,
|
|
62
|
+
cleanedValue: pair.cleaned,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
expect(validatePhoneNumber(pair.input)).toStrictEqual(validResponse);
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
/*------------------------------------------------------------------------*/
|
|
71
|
+
/* ---------------------------- Invalid Tests --------------------------- */
|
|
72
|
+
/*------------------------------------------------------------------------*/
|
|
73
|
+
|
|
74
|
+
const invalidPhoneNumbers: string[] = [
|
|
75
|
+
'123456789',
|
|
76
|
+
'1234567894567890',
|
|
77
|
+
'1234-567-890',
|
|
78
|
+
'123456m78',
|
|
79
|
+
'123 4567 890',
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const invalidResponse: ValidationResult<string> = {
|
|
83
|
+
isValid: false,
|
|
84
|
+
errorMessage: INVALID_PHONE_ERROR,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
test(
|
|
88
|
+
'Returns false for a given valid phone number.',
|
|
89
|
+
async () => {
|
|
90
|
+
invalidPhoneNumbers.forEach((phoneNumber) => {
|
|
91
|
+
expect(validatePhoneNumber(phoneNumber)).toStrictEqual(invalidResponse);
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Import helpers
|
|
2
|
+
import validateRegex from './shared/helpers/validateRegex';
|
|
3
|
+
|
|
4
|
+
// Import constants
|
|
5
|
+
import { INVALID_PHONE_ERROR } from './shared/constants/ERROR_MESSAGES';
|
|
6
|
+
|
|
7
|
+
// Import types
|
|
8
|
+
import ValidationResult from './shared/types/ValidationResult';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Determines whether a given phone number is valid.
|
|
12
|
+
* @author Austen Money
|
|
13
|
+
* @param phoneNumber phone number to validate
|
|
14
|
+
* @returns whether phone number is considered valid - if valid, also returns
|
|
15
|
+
* a cleaned version of the number without any formatting. If invalid,
|
|
16
|
+
* returns an error message.
|
|
17
|
+
*/
|
|
18
|
+
const validatePhoneNumber = (
|
|
19
|
+
phoneNumber: string,
|
|
20
|
+
): ValidationResult<string> => {
|
|
21
|
+
// regex to validate phone number
|
|
22
|
+
const validationRegex = /^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$/;
|
|
23
|
+
|
|
24
|
+
// validate phone number with regex
|
|
25
|
+
const validationResponse = validateRegex(
|
|
26
|
+
{
|
|
27
|
+
input: phoneNumber,
|
|
28
|
+
regex: validationRegex,
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
// remove all non-digits from number
|
|
33
|
+
const cleanedValue: string = phoneNumber.replace(/\D/g, '');
|
|
34
|
+
|
|
35
|
+
// return cleaned value if valid, or error message if invalid
|
|
36
|
+
return (
|
|
37
|
+
validationResponse.isValid
|
|
38
|
+
? {
|
|
39
|
+
isValid: true,
|
|
40
|
+
cleanedValue,
|
|
41
|
+
}
|
|
42
|
+
: {
|
|
43
|
+
isValid: false,
|
|
44
|
+
errorMessage: INVALID_PHONE_ERROR,
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default validatePhoneNumber;
|