umt 2.3.0 → 2.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/module/Array/chunk.js +5 -3
- package/module/Array/chunk.js.map +1 -1
- package/module/Array/dualPivotQuickSort.d.ts +1 -2
- package/module/Array/dualPivotQuickSort.js +5 -26
- package/module/Array/dualPivotQuickSort.js.map +1 -1
- package/module/Array/quickSort.js +7 -25
- package/module/Array/quickSort.js.map +1 -1
- package/module/Array/sortingHelpers/applyInsertionSortIfNeeded.d.ts +13 -0
- package/module/Array/sortingHelpers/applyInsertionSortIfNeeded.js +20 -0
- package/module/Array/sortingHelpers/applyInsertionSortIfNeeded.js.map +1 -0
- package/module/Array/sortingHelpers/rangeValidator.d.ts +17 -0
- package/module/Array/sortingHelpers/rangeValidator.js +26 -0
- package/module/Array/sortingHelpers/rangeValidator.js.map +1 -0
- package/module/Validate/object/core.d.ts +2 -6
- package/module/Validate/object/core.js.map +1 -1
- package/module/Validate/type.d.ts +1 -0
- package/module/es5/Array/chunk.js +5 -3
- package/module/es5/Array/dualPivotQuickSort.d.ts +1 -2
- package/module/es5/Array/dualPivotQuickSort.js +8 -28
- package/module/es5/Array/quickSort.js +10 -25
- package/module/es5/Array/sortingHelpers/applyInsertionSortIfNeeded.d.ts +13 -0
- package/module/es5/Array/sortingHelpers/applyInsertionSortIfNeeded.js +25 -0
- package/module/es5/Array/sortingHelpers/rangeValidator.d.ts +17 -0
- package/module/es5/Array/sortingHelpers/rangeValidator.js +35 -0
- package/module/es5/Validate/object/core.d.ts +2 -6
- package/module/es5/Validate/type.d.ts +1 -0
- package/module/es5/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -17
- package/module/es5/tests/integration/Array/drop-and-first.test.d.ts +0 -1
- package/module/es5/tests/integration/Array/drop-and-first.test.js +0 -34
- package/module/es5/tests/integration/Tool/parseJson-and-Validate.test.d.ts +0 -1
- package/module/es5/tests/integration/Tool/parseJson-and-Validate.test.js +0 -80
- package/module/es5/tests/unit/Advance/rangeAdvance.test.d.ts +0 -1
- package/module/es5/tests/unit/Advance/rangeAdvance.test.js +0 -26
- package/module/es5/tests/unit/Array/arraysJoin.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/arraysJoin.test.js +0 -19
- package/module/es5/tests/unit/Array/binarySearch.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/binarySearch.test.js +0 -32
- package/module/es5/tests/unit/Array/checkFlagAlignment.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/checkFlagAlignment.test.js +0 -206
- package/module/es5/tests/unit/Array/chunk.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/chunk.test.js +0 -51
- package/module/es5/tests/unit/Array/compact.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/compact.test.js +0 -53
- package/module/es5/tests/unit/Array/compareFunctionDefault.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/compareFunctionDefault.test.js +0 -29
- package/module/es5/tests/unit/Array/drop.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/drop.test.js +0 -84
- package/module/es5/tests/unit/Array/dualPivotQuickSort.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/dualPivotQuickSort.test.js +0 -87
- package/module/es5/tests/unit/Array/first.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/first.test.js +0 -28
- package/module/es5/tests/unit/Array/generateNumberArray.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/generateNumberArray.test.js +0 -34
- package/module/es5/tests/unit/Array/getArraysCommon.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/getArraysCommon.test.js +0 -40
- package/module/es5/tests/unit/Array/getArraysDiff.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/getArraysDiff.test.js +0 -99
- package/module/es5/tests/unit/Array/groupBy.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/groupBy.test.js +0 -87
- package/module/es5/tests/unit/Array/insertionSort.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/insertionSort.test.js +0 -37
- package/module/es5/tests/unit/Array/mergeSort.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/mergeSort.test.js +0 -49
- package/module/es5/tests/unit/Array/pop.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/pop.test.js +0 -50
- package/module/es5/tests/unit/Array/quickSort.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/quickSort.test.js +0 -118
- package/module/es5/tests/unit/Array/randomSelect.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/randomSelect.test.js +0 -51
- package/module/es5/tests/unit/Array/range.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/range.test.js +0 -42
- package/module/es5/tests/unit/Array/shuffle.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/shuffle.test.js +0 -84
- package/module/es5/tests/unit/Array/shuffle2DArray.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/shuffle2DArray.test.js +0 -90
- package/module/es5/tests/unit/Array/sum.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/sum.test.js +0 -44
- package/module/es5/tests/unit/Array/timSort.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/timSort.test.js +0 -128
- package/module/es5/tests/unit/Array/zip.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/zip.test.js +0 -69
- package/module/es5/tests/unit/Array/zipLongest.test.d.ts +0 -1
- package/module/es5/tests/unit/Array/zipLongest.test.js +0 -74
- package/module/es5/tests/unit/Color/cmykToRgba.test.d.ts +0 -1
- package/module/es5/tests/unit/Color/cmykToRgba.test.js +0 -58
- package/module/es5/tests/unit/Color/hexaToRgba.test.d.ts +0 -1
- package/module/es5/tests/unit/Color/hexaToRgba.test.js +0 -115
- package/module/es5/tests/unit/Color/hslaToRgba.test.d.ts +0 -1
- package/module/es5/tests/unit/Color/hslaToRgba.test.js +0 -141
- package/module/es5/tests/unit/Color/rgbaToCmyk.test.d.ts +0 -1
- package/module/es5/tests/unit/Color/rgbaToCmyk.test.js +0 -139
- package/module/es5/tests/unit/Color/rgbaToHexA.test.d.ts +0 -1
- package/module/es5/tests/unit/Color/rgbaToHexA.test.js +0 -114
- package/module/es5/tests/unit/Color/rgbaToHsla.test.d.ts +0 -1
- package/module/es5/tests/unit/Color/rgbaToHsla.test.js +0 -190
- package/module/es5/tests/unit/Consts/clock.test.d.ts +0 -1
- package/module/es5/tests/unit/Consts/clock.test.js +0 -71
- package/module/es5/tests/unit/Consts/httpClientErrorStatus.test.d.ts +0 -1
- package/module/es5/tests/unit/Consts/httpClientErrorStatus.test.js +0 -33
- package/module/es5/tests/unit/Consts/httpInformationalStatus.test.d.ts +0 -1
- package/module/es5/tests/unit/Consts/httpInformationalStatus.test.js +0 -13
- package/module/es5/tests/unit/Consts/httpRedirectionStatus.test.d.ts +0 -1
- package/module/es5/tests/unit/Consts/httpRedirectionStatus.test.js +0 -16
- package/module/es5/tests/unit/Consts/httpServerErrorStatus.test.d.ts +0 -1
- package/module/es5/tests/unit/Consts/httpServerErrorStatus.test.js +0 -15
- package/module/es5/tests/unit/Consts/httpStatus.test.d.ts +0 -1
- package/module/es5/tests/unit/Consts/httpStatus.test.js +0 -82
- package/module/es5/tests/unit/Consts/httpSuccessStatus.test.d.ts +0 -1
- package/module/es5/tests/unit/Consts/httpSuccessStatus.test.js +0 -16
- package/module/es5/tests/unit/Date/birthday.test.d.ts +0 -1
- package/module/es5/tests/unit/Date/birthday.test.js +0 -31
- package/module/es5/tests/unit/Date/dateRange.test.d.ts +0 -1
- package/module/es5/tests/unit/Date/dateRange.test.js +0 -40
- package/module/es5/tests/unit/Date/dayOfWeek.test.d.ts +0 -1
- package/module/es5/tests/unit/Date/dayOfWeek.test.js +0 -39
- package/module/es5/tests/unit/Date/deleteSpace.test.d.ts +0 -1
- package/module/es5/tests/unit/Date/deleteSpace.test.js +0 -35
- package/module/es5/tests/unit/Date/format.test.d.ts +0 -1
- package/module/es5/tests/unit/Date/format.test.js +0 -50
- package/module/es5/tests/unit/Date/getDay.test.d.ts +0 -1
- package/module/es5/tests/unit/Date/getDay.test.js +0 -40
- package/module/es5/tests/unit/Date/getTimezoneOffsetString.test.d.ts +0 -1
- package/module/es5/tests/unit/Date/getTimezoneOffsetString.test.js +0 -26
- package/module/es5/tests/unit/Date/isLeapYear.test.d.ts +0 -1
- package/module/es5/tests/unit/Date/isLeapYear.test.js +0 -30
- package/module/es5/tests/unit/Date/new.test.d.ts +0 -1
- package/module/es5/tests/unit/Date/new.test.js +0 -39
- package/module/es5/tests/unit/Date/now.test.d.ts +0 -1
- package/module/es5/tests/unit/Date/now.test.js +0 -42
- package/module/es5/tests/unit/Error/safeExecute.test.d.ts +0 -1
- package/module/es5/tests/unit/Error/safeExecute.test.js +0 -75
- package/module/es5/tests/unit/Function/curry.test.d.ts +0 -1
- package/module/es5/tests/unit/Function/curry.test.js +0 -138
- package/module/es5/tests/unit/IP/cidrToLong.test.d.ts +0 -1
- package/module/es5/tests/unit/IP/cidrToLong.test.js +0 -32
- package/module/es5/tests/unit/IP/cidrToSubnetMask.test.d.ts +0 -1
- package/module/es5/tests/unit/IP/cidrToSubnetMask.test.js +0 -36
- package/module/es5/tests/unit/IP/getIpClass.test.d.ts +0 -1
- package/module/es5/tests/unit/IP/getIpClass.test.js +0 -36
- package/module/es5/tests/unit/IP/getNetworkAddress.test.d.ts +0 -1
- package/module/es5/tests/unit/IP/getNetworkAddress.test.js +0 -40
- package/module/es5/tests/unit/IP/ipToBinaryString.test.d.ts +0 -1
- package/module/es5/tests/unit/IP/ipToBinaryString.test.js +0 -46
- package/module/es5/tests/unit/IP/ipToLong.test.d.ts +0 -1
- package/module/es5/tests/unit/IP/ipToLong.test.js +0 -34
- package/module/es5/tests/unit/IP/isInRange.test.d.ts +0 -1
- package/module/es5/tests/unit/IP/isInRange.test.js +0 -82
- package/module/es5/tests/unit/IP/isPrivateIp.test.d.ts +0 -1
- package/module/es5/tests/unit/IP/isPrivateIp.test.js +0 -26
- package/module/es5/tests/unit/IP/longToIp.test.d.ts +0 -1
- package/module/es5/tests/unit/IP/longToIp.test.js +0 -39
- package/module/es5/tests/unit/IP/subnetMaskToCidr.test.d.ts +0 -1
- package/module/es5/tests/unit/IP/subnetMaskToCidr.test.js +0 -41
- package/module/es5/tests/unit/Math/addition.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/addition.test.js +0 -79
- package/module/es5/tests/unit/Math/average.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/average.test.js +0 -48
- package/module/es5/tests/unit/Math/bitwise.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/bitwise.test.js +0 -62
- package/module/es5/tests/unit/Math/calculator/calculator.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/calculator/calculator.test.js +0 -76
- package/module/es5/tests/unit/Math/calculator/calculatorInitialization.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/calculator/calculatorInitialization.test.js +0 -21
- package/module/es5/tests/unit/Math/calculator/convertCurrency.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/calculator/convertCurrency.test.js +0 -40
- package/module/es5/tests/unit/Math/calculator/literalExpression.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/calculator/literalExpression.test.js +0 -51
- package/module/es5/tests/unit/Math/degToRad.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/degToRad.test.js +0 -50
- package/module/es5/tests/unit/Math/deviationValue.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/deviationValue.test.js +0 -30
- package/module/es5/tests/unit/Math/division.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/division.test.js +0 -81
- package/module/es5/tests/unit/Math/factorial.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/factorial.test.js +0 -26
- package/module/es5/tests/unit/Math/factorize.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/factorize.test.js +0 -38
- package/module/es5/tests/unit/Math/flexibleNumberConversion.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/flexibleNumberConversion.test.js +0 -195
- package/module/es5/tests/unit/Math/gcd.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/gcd.test.js +0 -35
- package/module/es5/tests/unit/Math/getDecimalLength.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/getDecimalLength.test.js +0 -44
- package/module/es5/tests/unit/Math/lcm.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/lcm.test.js +0 -43
- package/module/es5/tests/unit/Math/linearCongruentialGenerator.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/linearCongruentialGenerator.test.js +0 -25
- package/module/es5/tests/unit/Math/mathConverter.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/mathConverter.test.js +0 -37
- package/module/es5/tests/unit/Math/mathSeparator.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/mathSeparator.test.js +0 -59
- package/module/es5/tests/unit/Math/max.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/max.test.js +0 -22
- package/module/es5/tests/unit/Math/median.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/median.test.js +0 -17
- package/module/es5/tests/unit/Math/min.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/min.test.js +0 -22
- package/module/es5/tests/unit/Math/multiples.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/multiples.test.js +0 -30
- package/module/es5/tests/unit/Math/multiplication.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/multiplication.test.js +0 -48
- package/module/es5/tests/unit/Math/nCr.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/nCr.test.js +0 -34
- package/module/es5/tests/unit/Math/nHr.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/nHr.test.js +0 -35
- package/module/es5/tests/unit/Math/nPr.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/nPr.test.js +0 -38
- package/module/es5/tests/unit/Math/primeFactorization.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/primeFactorization.test.js +0 -84
- package/module/es5/tests/unit/Math/quotient.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/quotient.test.js +0 -36
- package/module/es5/tests/unit/Math/radToDeg.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/radToDeg.test.js +0 -50
- package/module/es5/tests/unit/Math/random.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/random.test.js +0 -61
- package/module/es5/tests/unit/Math/reduce.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/reduce.test.js +0 -93
- package/module/es5/tests/unit/Math/repeatedTrial.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/repeatedTrial.test.js +0 -39
- package/module/es5/tests/unit/Math/roundOf.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/roundOf.test.js +0 -40
- package/module/es5/tests/unit/Math/solveEquation.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/solveEquation.test.js +0 -24
- package/module/es5/tests/unit/Math/standardDeviation.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/standardDeviation.test.js +0 -23
- package/module/es5/tests/unit/Math/subtract.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/subtract.test.js +0 -46
- package/module/es5/tests/unit/Math/toBaseN.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/toBaseN.test.js +0 -40
- package/module/es5/tests/unit/Math/toCelsius.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/toCelsius.test.js +0 -18
- package/module/es5/tests/unit/Math/toKelvin.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/toKelvin.test.js +0 -18
- package/module/es5/tests/unit/Math/uuidv7.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/uuidv7.test.js +0 -33
- package/module/es5/tests/unit/Math/valueSwap.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/valueSwap.test.js +0 -28
- package/module/es5/tests/unit/Math/xoshiro256.test.d.ts +0 -1
- package/module/es5/tests/unit/Math/xoshiro256.test.js +0 -33
- package/module/es5/tests/unit/Object/has.test.d.ts +0 -1
- package/module/es5/tests/unit/Object/has.test.js +0 -60
- package/module/es5/tests/unit/Object/keyBy.test.d.ts +0 -1
- package/module/es5/tests/unit/Object/keyBy.test.js +0 -120
- package/module/es5/tests/unit/Object/pick.test.d.ts +0 -1
- package/module/es5/tests/unit/Object/pick.test.js +0 -109
- package/module/es5/tests/unit/Object/pickDeep.test.d.ts +0 -1
- package/module/es5/tests/unit/Object/pickDeep.test.js +0 -222
- package/module/es5/tests/unit/Simple/Array/quickSortSimple.test.d.ts +0 -1
- package/module/es5/tests/unit/Simple/Array/quickSortSimple.test.js +0 -18
- package/module/es5/tests/unit/Simple/Date/dayOfWeekSimple.test.d.ts +0 -1
- package/module/es5/tests/unit/Simple/Date/dayOfWeekSimple.test.js +0 -58
- package/module/es5/tests/unit/Simple/Math/deviationValueSimple.test.d.ts +0 -1
- package/module/es5/tests/unit/Simple/Math/deviationValueSimple.test.js +0 -43
- package/module/es5/tests/unit/String/deleteSpaces.test.d.ts +0 -1
- package/module/es5/tests/unit/String/deleteSpaces.test.js +0 -22
- package/module/es5/tests/unit/String/formatString.test.d.ts +0 -1
- package/module/es5/tests/unit/String/formatString.test.js +0 -47
- package/module/es5/tests/unit/String/fromBase64.test.d.ts +0 -1
- package/module/es5/tests/unit/String/fromBase64.test.js +0 -37
- package/module/es5/tests/unit/String/hasNoLetters.test.d.ts +0 -1
- package/module/es5/tests/unit/String/hasNoLetters.test.js +0 -29
- package/module/es5/tests/unit/String/padEnd.test.d.ts +0 -1
- package/module/es5/tests/unit/String/padEnd.test.js +0 -22
- package/module/es5/tests/unit/String/padStart.test.d.ts +0 -1
- package/module/es5/tests/unit/String/padStart.test.js +0 -40
- package/module/es5/tests/unit/String/randomString.test.d.ts +0 -1
- package/module/es5/tests/unit/String/randomString.test.js +0 -21
- package/module/es5/tests/unit/String/randomStringInitialization.test.d.ts +0 -1
- package/module/es5/tests/unit/String/randomStringInitialization.test.js +0 -25
- package/module/es5/tests/unit/String/reverseString.test.d.ts +0 -1
- package/module/es5/tests/unit/String/reverseString.test.js +0 -35
- package/module/es5/tests/unit/String/toBase64.test.d.ts +0 -1
- package/module/es5/tests/unit/String/toBase64.test.js +0 -20
- package/module/es5/tests/unit/String/toHalfWidth.test.d.ts +0 -1
- package/module/es5/tests/unit/String/toHalfWidth.test.js +0 -16
- package/module/es5/tests/unit/String/trimCharacters.test.d.ts +0 -1
- package/module/es5/tests/unit/String/trimCharacters.test.js +0 -17
- package/module/es5/tests/unit/String/trimEndCharacters.test.d.ts +0 -1
- package/module/es5/tests/unit/String/trimEndCharacters.test.js +0 -33
- package/module/es5/tests/unit/String/trimStartCharacters.test.d.ts +0 -1
- package/module/es5/tests/unit/String/trimStartCharacters.test.js +0 -33
- package/module/es5/tests/unit/Time/convertTime.test.d.ts +0 -1
- package/module/es5/tests/unit/Time/convertTime.test.js +0 -135
- package/module/es5/tests/unit/Time/normalizeTimeUnit.test.d.ts +0 -1
- package/module/es5/tests/unit/Time/normalizeTimeUnit.test.js +0 -29
- package/module/es5/tests/unit/Tool/createPipeline.test.d.ts +0 -1
- package/module/es5/tests/unit/Tool/createPipeline.test.js +0 -184
- package/module/es5/tests/unit/Tool/parseJson.test.d.ts +0 -1
- package/module/es5/tests/unit/Tool/parseJson.test.js +0 -46
- package/module/es5/tests/unit/Tool/pipe.test.d.ts +0 -1
- package/module/es5/tests/unit/Tool/pipe.test.js +0 -445
- package/module/es5/tests/unit/UA/extractBrowserFromUserAgent.test.d.ts +0 -1
- package/module/es5/tests/unit/UA/extractBrowserFromUserAgent.test.js +0 -47
- package/module/es5/tests/unit/UA/extractDeviceFromUserAgent.test.d.ts +0 -1
- package/module/es5/tests/unit/UA/extractDeviceFromUserAgent.test.js +0 -55
- package/module/es5/tests/unit/UA/extractOsFromUserAgent.test.d.ts +0 -1
- package/module/es5/tests/unit/UA/extractOsFromUserAgent.test.js +0 -57
- package/module/es5/tests/unit/UA/parseUserAgent.test.d.ts +0 -1
- package/module/es5/tests/unit/UA/parseUserAgent.test.js +0 -95
- package/module/es5/tests/unit/Unit/unitConverterInitialization.test.d.ts +0 -1
- package/module/es5/tests/unit/Unit/unitConverterInitialization.test.js +0 -40
- package/module/es5/tests/unit/Validate/array/core.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/array/core.test.js +0 -86
- package/module/es5/tests/unit/Validate/boolean/core.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/boolean/core.test.js +0 -29
- package/module/es5/tests/unit/Validate/core/core.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/core/core.test.js +0 -87
- package/module/es5/tests/unit/Validate/isArray.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/isArray.test.js +0 -36
- package/module/es5/tests/unit/Validate/isDictionaryObject.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/isDictionaryObject.test.js +0 -62
- package/module/es5/tests/unit/Validate/isDouble.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/isDouble.test.js +0 -47
- package/module/es5/tests/unit/Validate/isEqual.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/isEqual.test.js +0 -74
- package/module/es5/tests/unit/Validate/isNotEmpty.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/isNotEmpty.test.js +0 -43
- package/module/es5/tests/unit/Validate/isNumber.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/isNumber.test.js +0 -77
- package/module/es5/tests/unit/Validate/isPerfectSquare.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/isPerfectSquare.test.js +0 -27
- package/module/es5/tests/unit/Validate/isPrimeNumber.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/isPrimeNumber.test.js +0 -51
- package/module/es5/tests/unit/Validate/isValueNaN.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/isValueNaN.test.js +0 -54
- package/module/es5/tests/unit/Validate/number/core.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/number/core.test.js +0 -36
- package/module/es5/tests/unit/Validate/number/double.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/number/double.test.js +0 -23
- package/module/es5/tests/unit/Validate/number/even.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/number/even.test.js +0 -23
- package/module/es5/tests/unit/Validate/number/maxValue.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/number/maxValue.test.js +0 -20
- package/module/es5/tests/unit/Validate/number/minValue.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/number/minValue.test.js +0 -20
- package/module/es5/tests/unit/Validate/number/odd.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/number/odd.test.js +0 -23
- package/module/es5/tests/unit/Validate/number/prime.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/number/prime.test.js +0 -25
- package/module/es5/tests/unit/Validate/object/core.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/object/core.test.js +0 -79
- package/module/es5/tests/unit/Validate/string/core.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/string/core.test.js +0 -27
- package/module/es5/tests/unit/Validate/string/email.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/string/email.test.js +0 -21
- package/module/es5/tests/unit/Validate/string/length.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/string/length.test.js +0 -18
- package/module/es5/tests/unit/Validate/string/maxLength.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/string/maxLength.test.js +0 -18
- package/module/es5/tests/unit/Validate/string/minLength.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/string/minLength.test.js +0 -18
- package/module/es5/tests/unit/Validate/string/numberString.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/string/numberString.test.js +0 -22
- package/module/es5/tests/unit/Validate/string/regexMatch.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/string/regexMatch.test.js +0 -29
- package/module/es5/tests/unit/Validate/string/uuid.test.d.ts +0 -1
- package/module/es5/tests/unit/Validate/string/uuid.test.js +0 -72
- package/module/es5/tests/unit/types/arrayType.test.d.ts +0 -1
- package/module/es5/tests/unit/types/arrayType.test.js +0 -11
- package/module/es5/tests/unit/types/clockType.test.d.ts +0 -1
- package/module/es5/tests/unit/types/clockType.test.js +0 -37
package/module/Array/chunk.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export const chunk = (array, n) => {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const length = array.length;
|
|
3
|
+
// eslint-disable-next-line unicorn/no-new-array
|
|
4
|
+
const result = new Array(Math.ceil(length / n));
|
|
5
|
+
for (let index = 0, k = 0; index < length; index += n, k++) {
|
|
6
|
+
result[k] = array.slice(index, index + n);
|
|
5
7
|
}
|
|
6
8
|
return result;
|
|
7
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk.js","sourceRoot":"","sources":["../../src/Array/chunk.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,KAAQ,EACR,CAAI,EACkB,EAAE;IACxB,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"chunk.js","sourceRoot":"","sources":["../../src/Array/chunk.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,KAAQ,EACR,CAAI,EACkB,EAAE;IACxB,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,gDAAgD;IAChD,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAEhD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3D,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAmB,CAAC;IAC9D,CAAC;IAED,OAAO,MAA8B,CAAC;AACxC,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type CompareFunction
|
|
1
|
+
import type { CompareFunction } from "../types/array/compareFunction";
|
|
2
2
|
/**
|
|
3
3
|
* Sort array using dual-pivot quicksort algorithm
|
|
4
4
|
* More efficient than traditional quicksort for arrays with many duplicate values
|
|
@@ -13,4 +13,3 @@ type CompareFunction<T> = (a: T, b: T) => number;
|
|
|
13
13
|
* dualPivotQuickSort(['banana', 'apple', 'orange']); // ['apple', 'banana', 'orange']
|
|
14
14
|
*/
|
|
15
15
|
export declare const dualPivotQuickSort: <T>(array: T[], compareFunction?: CompareFunction<T>, startIndex?: number, endIndex?: number, insertionSortThreshold?: number) => T[];
|
|
16
|
-
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { compareFunctionDefault } from "./compareFunctionDefault";
|
|
2
|
+
import { applyInsertionSortIfNeeded } from "./sortingHelpers/applyInsertionSortIfNeeded";
|
|
3
|
+
import { validateRange } from "./sortingHelpers/rangeValidator";
|
|
2
4
|
/**
|
|
3
5
|
* Get the median of three elements in the array
|
|
4
6
|
* @param array - The input array
|
|
@@ -83,24 +85,6 @@ const partition = (array, low, high, compareFunction) => {
|
|
|
83
85
|
[array[high], array[right]] = [array[right], array[high]];
|
|
84
86
|
return { leftPivotIndex: left, rightPivotIndex: right };
|
|
85
87
|
};
|
|
86
|
-
/**
|
|
87
|
-
* Sort small arrays using selection sort
|
|
88
|
-
* @param array - Array to be sorted
|
|
89
|
-
* @param start - Starting index
|
|
90
|
-
* @param end - Ending index
|
|
91
|
-
* @param compareFunction - Comparison function
|
|
92
|
-
*/
|
|
93
|
-
const insertionSort = (array, start, end, compareFunction) => {
|
|
94
|
-
for (let index = start + 1; index <= end; index++) {
|
|
95
|
-
const current = array[index];
|
|
96
|
-
let index_ = index - 1;
|
|
97
|
-
while (index_ >= start && compareFunction(array[index_], current) > 0) {
|
|
98
|
-
array[index_ + 1] = array[index_];
|
|
99
|
-
index_--;
|
|
100
|
-
}
|
|
101
|
-
array[index_ + 1] = current;
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
88
|
/**
|
|
105
89
|
* Internal implementation of dual-pivot quicksort
|
|
106
90
|
* @param array - Array to be sorted
|
|
@@ -110,9 +94,7 @@ const insertionSort = (array, start, end, compareFunction) => {
|
|
|
110
94
|
* @param insertionSortThreshold - Threshold for switching to insertion sort
|
|
111
95
|
*/
|
|
112
96
|
const sortRange = (array, start, end, compareFunction, insertionSortThreshold) => {
|
|
113
|
-
|
|
114
|
-
if (end - start + 1 <= insertionSortThreshold) {
|
|
115
|
-
insertionSort(array, start, end, compareFunction);
|
|
97
|
+
if (applyInsertionSortIfNeeded(array, start, end, compareFunction, insertionSortThreshold)) {
|
|
116
98
|
return;
|
|
117
99
|
}
|
|
118
100
|
// Get partition indices
|
|
@@ -140,11 +122,8 @@ const sortRange = (array, start, end, compareFunction, insertionSortThreshold) =
|
|
|
140
122
|
* dualPivotQuickSort(['banana', 'apple', 'orange']); // ['apple', 'banana', 'orange']
|
|
141
123
|
*/
|
|
142
124
|
export const dualPivotQuickSort = (array, compareFunction = (compareFunctionDefault), startIndex = 0, endIndex = array.length - 1, insertionSortThreshold = 10) => {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const validEndIndex = Math.max(validStartIndex, Math.min(endIndex, array.length - 1));
|
|
146
|
-
// Sort array if valid range exists
|
|
147
|
-
if (validEndIndex >= validStartIndex) {
|
|
125
|
+
const { startIndex: validStartIndex, endIndex: validEndIndex, shouldSort, } = validateRange(array, startIndex, endIndex);
|
|
126
|
+
if (shouldSort) {
|
|
148
127
|
sortRange(array, validStartIndex, validEndIndex, compareFunction, insertionSortThreshold);
|
|
149
128
|
}
|
|
150
129
|
return array;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dualPivotQuickSort.js","sourceRoot":"","sources":["../../src/Array/dualPivotQuickSort.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"dualPivotQuickSort.js","sourceRoot":"","sources":["../../src/Array/dualPivotQuickSort.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MA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M,EACJ,UAAU,EAAE,eAAe,EAC3B,QAAQ,EAAE,aAAa,EACvB,UAAU,GACX,GAAG,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IAE/C,IAAI,UAAU,EAAE,CAAC;QACf,SAAS,CACP,KAAK,EACL,eAAe,EACf,aAAa,EACb,eAAe,EACf,sBAAsB,CACvB,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { compareFunctionDefault } from "./compareFunctionDefault";
|
|
2
|
+
import { applyInsertionSortIfNeeded } from "./sortingHelpers/applyInsertionSortIfNeeded";
|
|
3
|
+
import { validateRange } from "./sortingHelpers/rangeValidator";
|
|
2
4
|
/**
|
|
3
5
|
* Finds the median value among three elements in the array
|
|
4
6
|
* @param array The array containing the elements
|
|
@@ -54,25 +56,6 @@ const partition = (array, low, high, compareFunction) => {
|
|
|
54
56
|
[array[left], array[right]] = [array[right], array[left]];
|
|
55
57
|
}
|
|
56
58
|
};
|
|
57
|
-
/**
|
|
58
|
-
* Sorts a portion of the array using insertion sort algorithm
|
|
59
|
-
* @param array Array to sort
|
|
60
|
-
* @param low Starting index of the range to sort
|
|
61
|
-
* @param high Ending index of the range to sort
|
|
62
|
-
* @param compareFunction Function to compare elements
|
|
63
|
-
*/
|
|
64
|
-
const insertionSort = (array, low, high, compareFunction) => {
|
|
65
|
-
for (let index = low + 1; index <= high; index++) {
|
|
66
|
-
const key = array[index];
|
|
67
|
-
let currentIndex = index - 1;
|
|
68
|
-
while (currentIndex >= low &&
|
|
69
|
-
compareFunction(array[currentIndex], key) > 0) {
|
|
70
|
-
array[currentIndex + 1] = array[currentIndex];
|
|
71
|
-
currentIndex--;
|
|
72
|
-
}
|
|
73
|
-
array[currentIndex + 1] = key;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
59
|
/**
|
|
77
60
|
* Internal implementation of the quicksort algorithm with tail-call optimization
|
|
78
61
|
* @param array Array to sort
|
|
@@ -85,8 +68,7 @@ const sortImpl = (array, lowInit, highInit, compareFunction, insertionSortThresh
|
|
|
85
68
|
let low = lowInit;
|
|
86
69
|
let high = highInit;
|
|
87
70
|
while (low < high) {
|
|
88
|
-
if (
|
|
89
|
-
insertionSort(array, low, high, compareFunction);
|
|
71
|
+
if (applyInsertionSortIfNeeded(array, low, high, compareFunction, insertionSortThreshold)) {
|
|
90
72
|
return;
|
|
91
73
|
}
|
|
92
74
|
const pivotIndex = partition(array, low, high, compareFunction);
|
|
@@ -114,10 +96,10 @@ const sortImpl = (array, lowInit, highInit, compareFunction, insertionSortThresh
|
|
|
114
96
|
* quickSort(['b', 'a', 'c']); // ['a', 'b', 'c']
|
|
115
97
|
*/
|
|
116
98
|
export const quickSort = (array, compareFunction = (compareFunctionDefault), startIndex = 0, endIndex = array.length - 1, insertionSortThreshold = 10) => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
99
|
+
const { startIndex: validStartIndex, endIndex: validEndIndex, shouldSort, } = validateRange(array, startIndex, endIndex);
|
|
100
|
+
if (shouldSort) {
|
|
101
|
+
sortImpl(array, validStartIndex, validEndIndex, compareFunction, insertionSortThreshold);
|
|
102
|
+
}
|
|
121
103
|
return array;
|
|
122
104
|
};
|
|
123
105
|
//# sourceMappingURL=quickSort.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quickSort.js","sourceRoot":"","sources":["../../src/Array/quickSort.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"quickSort.js","sourceRoot":"","sources":["../../src/Array/quickSort.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,iC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UAAU,GAAG,GAAG,GAAG,IAAI,GAAG,UAAU,EAAE,CAAC;YACzC,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,eAAe,EAAE,sBAAsB,CAAC,CAAC;YAC1E,GAAG,GAAG,UAAU,GAAG,CAAC,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,QAAQ,CACN,KAAK,EACL,UAAU,GAAG,CAAC,EACd,IAAI,EACJ,eAAe,EACf,sBAAsB,CACvB,CAAC;YACF,IAAI,GAAG,UAAU,CAAC;QACpB,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,KAAU,EACV,kBAAsC,CAAA,sBAAyB,CAAA,EAC/D,UAAU,GAAG,CAAC,EACd,QAAQ,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAC3B,sBAAsB,GAAG,EAAE,EACtB,EAAE;IACP,MAAM,EACJ,UAAU,EAAE,eAAe,EAC3B,QAAQ,EAAE,aAAa,EACvB,UAAU,GACX,GAAG,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IAE/C,IAAI,UAAU,EAAE,CAAC;QACf,QAAQ,CACN,KAAK,EACL,eAAe,EACf,aAAa,EACb,eAAe,EACf,sBAAsB,CACvB,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CompareFunction } from "../../types/array/compareFunction";
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a partition is small enough to apply insertion sort and applies it if so.
|
|
4
|
+
*
|
|
5
|
+
* @template T The type of elements in the array.
|
|
6
|
+
* @param {T[]} array The array containing the partition.
|
|
7
|
+
* @param {number} low The starting index of the partition.
|
|
8
|
+
* @param {number} high The ending index of the partition.
|
|
9
|
+
* @param {CompareFunction<T>} compareFunction The function to compare elements.
|
|
10
|
+
* @param {number} insertionSortThreshold The size threshold for switching to insertion sort.
|
|
11
|
+
* @returns {boolean} True if insertion sort was applied, false otherwise.
|
|
12
|
+
*/
|
|
13
|
+
export declare const applyInsertionSortIfNeeded: <T>(array: T[], low: number, high: number, compareFunction: CompareFunction<T>, insertionSortThreshold: number) => boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { insertionSort } from "../../Array/insertionSort";
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a partition is small enough to apply insertion sort and applies it if so.
|
|
4
|
+
*
|
|
5
|
+
* @template T The type of elements in the array.
|
|
6
|
+
* @param {T[]} array The array containing the partition.
|
|
7
|
+
* @param {number} low The starting index of the partition.
|
|
8
|
+
* @param {number} high The ending index of the partition.
|
|
9
|
+
* @param {CompareFunction<T>} compareFunction The function to compare elements.
|
|
10
|
+
* @param {number} insertionSortThreshold The size threshold for switching to insertion sort.
|
|
11
|
+
* @returns {boolean} True if insertion sort was applied, false otherwise.
|
|
12
|
+
*/
|
|
13
|
+
export const applyInsertionSortIfNeeded = (array, low, high, compareFunction, insertionSortThreshold) => {
|
|
14
|
+
if (high - low + 1 <= insertionSortThreshold) {
|
|
15
|
+
insertionSort(array, compareFunction, low, high);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=applyInsertionSortIfNeeded.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyInsertionSortIfNeeded.js","sourceRoot":"","sources":["../../../src/Array/sortingHelpers/applyInsertionSortIfNeeded.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,KAAU,EACV,GAAW,EACX,IAAY,EACZ,eAAmC,EACnC,sBAA8B,EACrB,EAAE;IACX,IAAI,IAAI,GAAG,GAAG,GAAG,CAAC,IAAI,sBAAsB,EAAE,CAAC;QAC7C,aAAa,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ValidatedSortRange {
|
|
2
|
+
startIndex: number;
|
|
3
|
+
endIndex: number;
|
|
4
|
+
shouldSort: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Validates and adjusts the start and end indices for an operation on an array.
|
|
8
|
+
* Ensures indices are within the bounds of the array.
|
|
9
|
+
*
|
|
10
|
+
* @template T The type of elements in the array.
|
|
11
|
+
* @param {T[]} array The array.
|
|
12
|
+
* @param {number} startIndex The desired starting index.
|
|
13
|
+
* @param {number} endIndex The desired ending index.
|
|
14
|
+
* @returns {ValidatedSortRange} An object containing the validated start index, end index,
|
|
15
|
+
* and a boolean indicating if the operation should proceed on the range.
|
|
16
|
+
*/
|
|
17
|
+
export declare const validateRange: <T>(array: T[], startIndex: number, endIndex: number) => ValidatedSortRange;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates and adjusts the start and end indices for an operation on an array.
|
|
3
|
+
* Ensures indices are within the bounds of the array.
|
|
4
|
+
*
|
|
5
|
+
* @template T The type of elements in the array.
|
|
6
|
+
* @param {T[]} array The array.
|
|
7
|
+
* @param {number} startIndex The desired starting index.
|
|
8
|
+
* @param {number} endIndex The desired ending index.
|
|
9
|
+
* @returns {ValidatedSortRange} An object containing the validated start index, end index,
|
|
10
|
+
* and a boolean indicating if the operation should proceed on the range.
|
|
11
|
+
*/
|
|
12
|
+
export const validateRange = (array, startIndex, endIndex) => {
|
|
13
|
+
const length = array.length;
|
|
14
|
+
// Handle empty arrays early
|
|
15
|
+
if (length === 0) {
|
|
16
|
+
return { startIndex: 0, endIndex: -1, shouldSort: false };
|
|
17
|
+
}
|
|
18
|
+
const validatedStartIndex = Math.max(0, Math.min(startIndex, length - 1));
|
|
19
|
+
const validatedEndIndex = Math.max(validatedStartIndex, Math.min(endIndex, length - 1));
|
|
20
|
+
return {
|
|
21
|
+
startIndex: validatedStartIndex,
|
|
22
|
+
endIndex: validatedEndIndex,
|
|
23
|
+
shouldSort: validatedEndIndex >= validatedStartIndex,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=rangeValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rangeValidator.js","sourceRoot":"","sources":["../../../src/Array/sortingHelpers/rangeValidator.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,KAAU,EACV,UAAkB,EAClB,QAAgB,EACI,EAAE;IACtB,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,4BAA4B;IAC5B,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC5D,CAAC;IAED,MAAM,mBAAmB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAC1E,MAAM,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAChC,mBAAmB,EACnB,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAC,CAC/B,CAAC;IAEF,OAAO;QACL,UAAU,EAAE,mBAAmB;QAC/B,QAAQ,EAAE,iBAAiB;QAC3B,UAAU,EAAE,iBAAiB,IAAI,mBAAmB;KACrD,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Object validation core module
|
|
3
3
|
* Provides validation functionality for objects with type-specific validation rules for each property
|
|
4
4
|
*/
|
|
5
|
-
import type { ValidateCoreReturnType, ValidateType } from "../../Validate/type";
|
|
5
|
+
import type { Types, ValidateCoreReturnType, ValidateType } from "../../Validate/type";
|
|
6
6
|
/**
|
|
7
7
|
* Creates an object validator with property-specific validation rules
|
|
8
8
|
* @template T - Object type containing validation functions for each property
|
|
@@ -12,8 +12,4 @@ import type { ValidateCoreReturnType, ValidateType } from "../../Validate/type";
|
|
|
12
12
|
*/
|
|
13
13
|
export declare const object: <T extends {
|
|
14
14
|
[key: string]: (value: any) => ValidateCoreReturnType<any>;
|
|
15
|
-
}>(option?: T, message?: string) => (value: { [key in keyof T]: ValidateType<ReturnType<T[key]>["type"]>; }) => {
|
|
16
|
-
validate: boolean;
|
|
17
|
-
message: string;
|
|
18
|
-
type: { [key in keyof T]: ValidateType<ReturnType<T[key]>["type"]>; };
|
|
19
|
-
};
|
|
15
|
+
}>(option?: T, message?: string) => (value: Types<{ [key in keyof T]: ValidateType<ReturnType<T[key]>["type"]>; }>) => ValidateCoreReturnType<{ [key in keyof T]: ValidateType<ReturnType<T[key]>["type"]>; }>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../src/Validate/object/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../src/Validate/object/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAOnE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAMpB,SAAY,EAAO,EACnB,OAAgB,EAChB,EAAE;IACF,OAAO,CACL,KAEE,EAGD,EAAE;QACH,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,OAAO,IAAI,EAAE;gBACtB,IAAI,EAAE,KAAK;aACZ,CAAC;QACJ,CAAC;QACD,KAAK,MAAM,QAAQ,IAAI,MAAM,EAAE,CAAC;YAC9B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;gBAChD,OAAO;oBACL,QAAQ,EAAE,KAAK;oBACf,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO;oBACxC,IAAI,EAAE,KAAK;iBACZ,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,EAAE;YACX,IAAI,EAAE,KAAK;SACZ,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -33,3 +33,4 @@ export type ValidateFunctionType<T> = (value: T) => boolean;
|
|
|
33
33
|
* @returns The corresponding TypeScript type (string, number, boolean) or the original type T
|
|
34
34
|
*/
|
|
35
35
|
export type ValidateType<T> = T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : T;
|
|
36
|
+
export type SchemaToInterface<T extends (value: any) => ValidateCoreReturnType<any>> = ReturnType<T>["type"];
|
|
@@ -12,9 +12,11 @@ exports.chunk = void 0;
|
|
|
12
12
|
* @example chunk([1, 2, 3, 4, 5, 6, 7, 8, 9], 3); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
|
|
13
13
|
*/
|
|
14
14
|
var chunk = exports.chunk = function chunk(array, n) {
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
var length = array.length;
|
|
16
|
+
// eslint-disable-next-line unicorn/no-new-array
|
|
17
|
+
var result = new Array(Math.ceil(length / n));
|
|
18
|
+
for (var index = 0, k = 0; index < length; index += n, k++) {
|
|
19
|
+
result[k] = array.slice(index, index + n);
|
|
18
20
|
}
|
|
19
21
|
return result;
|
|
20
22
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type CompareFunction
|
|
1
|
+
import type { CompareFunction } from "$/array/compareFunction";
|
|
2
2
|
/**
|
|
3
3
|
* Sort array using dual-pivot quicksort algorithm
|
|
4
4
|
* More efficient than traditional quicksort for arrays with many duplicate values
|
|
@@ -13,4 +13,3 @@ type CompareFunction<T> = (a: T, b: T) => number;
|
|
|
13
13
|
* dualPivotQuickSort(['banana', 'apple', 'orange']); // ['apple', 'banana', 'orange']
|
|
14
14
|
*/
|
|
15
15
|
export declare const dualPivotQuickSort: <T>(array: T[], compareFunction?: CompareFunction<T>, startIndex?: number, endIndex?: number, insertionSortThreshold?: number) => T[];
|
|
16
|
-
export {};
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.dualPivotQuickSort = void 0;
|
|
7
7
|
var _compareFunctionDefault = require("./compareFunctionDefault");
|
|
8
|
+
var _applyInsertionSortIfNeeded = require("./sortingHelpers/applyInsertionSortIfNeeded");
|
|
9
|
+
var _rangeValidator = require("./sortingHelpers/rangeValidator");
|
|
8
10
|
/**
|
|
9
11
|
* Get the median of three elements in the array
|
|
10
12
|
* @param array - The input array
|
|
@@ -120,25 +122,6 @@ var partition = function partition(array, low, high, compareFunction) {
|
|
|
120
122
|
};
|
|
121
123
|
};
|
|
122
124
|
|
|
123
|
-
/**
|
|
124
|
-
* Sort small arrays using selection sort
|
|
125
|
-
* @param array - Array to be sorted
|
|
126
|
-
* @param start - Starting index
|
|
127
|
-
* @param end - Ending index
|
|
128
|
-
* @param compareFunction - Comparison function
|
|
129
|
-
*/
|
|
130
|
-
var insertionSort = function insertionSort(array, start, end, compareFunction) {
|
|
131
|
-
for (var index = start + 1; index <= end; index++) {
|
|
132
|
-
var current = array[index];
|
|
133
|
-
var index_ = index - 1;
|
|
134
|
-
while (index_ >= start && compareFunction(array[index_], current) > 0) {
|
|
135
|
-
array[index_ + 1] = array[index_];
|
|
136
|
-
index_--;
|
|
137
|
-
}
|
|
138
|
-
array[index_ + 1] = current;
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
125
|
/**
|
|
143
126
|
* Internal implementation of dual-pivot quicksort
|
|
144
127
|
* @param array - Array to be sorted
|
|
@@ -148,9 +131,7 @@ var insertionSort = function insertionSort(array, start, end, compareFunction) {
|
|
|
148
131
|
* @param insertionSortThreshold - Threshold for switching to insertion sort
|
|
149
132
|
*/
|
|
150
133
|
var _sortRange = function sortRange(array, start, end, compareFunction, insertionSortThreshold) {
|
|
151
|
-
|
|
152
|
-
if (end - start + 1 <= insertionSortThreshold) {
|
|
153
|
-
insertionSort(array, start, end, compareFunction);
|
|
134
|
+
if ((0, _applyInsertionSortIfNeeded.applyInsertionSortIfNeeded)(array, start, end, compareFunction, insertionSortThreshold)) {
|
|
154
135
|
return;
|
|
155
136
|
}
|
|
156
137
|
|
|
@@ -189,12 +170,11 @@ var dualPivotQuickSort = exports.dualPivotQuickSort = function dualPivotQuickSor
|
|
|
189
170
|
var startIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
190
171
|
var endIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : array.length - 1;
|
|
191
172
|
var insertionSortThreshold = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 10;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (validEndIndex >= validStartIndex) {
|
|
173
|
+
var _validateRange = (0, _rangeValidator.validateRange)(array, startIndex, endIndex),
|
|
174
|
+
validStartIndex = _validateRange.startIndex,
|
|
175
|
+
validEndIndex = _validateRange.endIndex,
|
|
176
|
+
shouldSort = _validateRange.shouldSort;
|
|
177
|
+
if (shouldSort) {
|
|
198
178
|
_sortRange(array, validStartIndex, validEndIndex, compareFunction, insertionSortThreshold);
|
|
199
179
|
}
|
|
200
180
|
return array;
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.quickSort = void 0;
|
|
7
7
|
var _compareFunctionDefault = require("./compareFunctionDefault");
|
|
8
|
+
var _applyInsertionSortIfNeeded = require("./sortingHelpers/applyInsertionSortIfNeeded");
|
|
9
|
+
var _rangeValidator = require("./sortingHelpers/rangeValidator");
|
|
8
10
|
/**
|
|
9
11
|
* Finds the median value among three elements in the array
|
|
10
12
|
* @param array The array containing the elements
|
|
@@ -64,25 +66,6 @@ var partition = function partition(array, low, high, compareFunction) {
|
|
|
64
66
|
}
|
|
65
67
|
};
|
|
66
68
|
|
|
67
|
-
/**
|
|
68
|
-
* Sorts a portion of the array using insertion sort algorithm
|
|
69
|
-
* @param array Array to sort
|
|
70
|
-
* @param low Starting index of the range to sort
|
|
71
|
-
* @param high Ending index of the range to sort
|
|
72
|
-
* @param compareFunction Function to compare elements
|
|
73
|
-
*/
|
|
74
|
-
var insertionSort = function insertionSort(array, low, high, compareFunction) {
|
|
75
|
-
for (var index = low + 1; index <= high; index++) {
|
|
76
|
-
var key = array[index];
|
|
77
|
-
var currentIndex = index - 1;
|
|
78
|
-
while (currentIndex >= low && compareFunction(array[currentIndex], key) > 0) {
|
|
79
|
-
array[currentIndex + 1] = array[currentIndex];
|
|
80
|
-
currentIndex--;
|
|
81
|
-
}
|
|
82
|
-
array[currentIndex + 1] = key;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
69
|
/**
|
|
87
70
|
* Internal implementation of the quicksort algorithm with tail-call optimization
|
|
88
71
|
* @param array Array to sort
|
|
@@ -95,8 +78,7 @@ var _sortImpl = function sortImpl(array, lowInit, highInit, compareFunction, ins
|
|
|
95
78
|
var low = lowInit;
|
|
96
79
|
var high = highInit;
|
|
97
80
|
while (low < high) {
|
|
98
|
-
if (
|
|
99
|
-
insertionSort(array, low, high, compareFunction);
|
|
81
|
+
if ((0, _applyInsertionSortIfNeeded.applyInsertionSortIfNeeded)(array, low, high, compareFunction, insertionSortThreshold)) {
|
|
100
82
|
return;
|
|
101
83
|
}
|
|
102
84
|
var pivotIndex = partition(array, low, high, compareFunction);
|
|
@@ -128,9 +110,12 @@ var quickSort = exports.quickSort = function quickSort(array) {
|
|
|
128
110
|
var startIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
129
111
|
var endIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : array.length - 1;
|
|
130
112
|
var insertionSortThreshold = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 10;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
113
|
+
var _validateRange = (0, _rangeValidator.validateRange)(array, startIndex, endIndex),
|
|
114
|
+
validStartIndex = _validateRange.startIndex,
|
|
115
|
+
validEndIndex = _validateRange.endIndex,
|
|
116
|
+
shouldSort = _validateRange.shouldSort;
|
|
117
|
+
if (shouldSort) {
|
|
118
|
+
_sortImpl(array, validStartIndex, validEndIndex, compareFunction, insertionSortThreshold);
|
|
119
|
+
}
|
|
135
120
|
return array;
|
|
136
121
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CompareFunction } from "$/array/compareFunction";
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a partition is small enough to apply insertion sort and applies it if so.
|
|
4
|
+
*
|
|
5
|
+
* @template T The type of elements in the array.
|
|
6
|
+
* @param {T[]} array The array containing the partition.
|
|
7
|
+
* @param {number} low The starting index of the partition.
|
|
8
|
+
* @param {number} high The ending index of the partition.
|
|
9
|
+
* @param {CompareFunction<T>} compareFunction The function to compare elements.
|
|
10
|
+
* @param {number} insertionSortThreshold The size threshold for switching to insertion sort.
|
|
11
|
+
* @returns {boolean} True if insertion sort was applied, false otherwise.
|
|
12
|
+
*/
|
|
13
|
+
export declare const applyInsertionSortIfNeeded: <T>(array: T[], low: number, high: number, compareFunction: CompareFunction<T>, insertionSortThreshold: number) => boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.applyInsertionSortIfNeeded = void 0;
|
|
7
|
+
var _insertionSort = require("@/Array/insertionSort");
|
|
8
|
+
/**
|
|
9
|
+
* Checks if a partition is small enough to apply insertion sort and applies it if so.
|
|
10
|
+
*
|
|
11
|
+
* @template T The type of elements in the array.
|
|
12
|
+
* @param {T[]} array The array containing the partition.
|
|
13
|
+
* @param {number} low The starting index of the partition.
|
|
14
|
+
* @param {number} high The ending index of the partition.
|
|
15
|
+
* @param {CompareFunction<T>} compareFunction The function to compare elements.
|
|
16
|
+
* @param {number} insertionSortThreshold The size threshold for switching to insertion sort.
|
|
17
|
+
* @returns {boolean} True if insertion sort was applied, false otherwise.
|
|
18
|
+
*/
|
|
19
|
+
var applyInsertionSortIfNeeded = exports.applyInsertionSortIfNeeded = function applyInsertionSortIfNeeded(array, low, high, compareFunction, insertionSortThreshold) {
|
|
20
|
+
if (high - low + 1 <= insertionSortThreshold) {
|
|
21
|
+
(0, _insertionSort.insertionSort)(array, compareFunction, low, high);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ValidatedSortRange {
|
|
2
|
+
startIndex: number;
|
|
3
|
+
endIndex: number;
|
|
4
|
+
shouldSort: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Validates and adjusts the start and end indices for an operation on an array.
|
|
8
|
+
* Ensures indices are within the bounds of the array.
|
|
9
|
+
*
|
|
10
|
+
* @template T The type of elements in the array.
|
|
11
|
+
* @param {T[]} array The array.
|
|
12
|
+
* @param {number} startIndex The desired starting index.
|
|
13
|
+
* @param {number} endIndex The desired ending index.
|
|
14
|
+
* @returns {ValidatedSortRange} An object containing the validated start index, end index,
|
|
15
|
+
* and a boolean indicating if the operation should proceed on the range.
|
|
16
|
+
*/
|
|
17
|
+
export declare const validateRange: <T>(array: T[], startIndex: number, endIndex: number) => ValidatedSortRange;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.validateRange = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Validates and adjusts the start and end indices for an operation on an array.
|
|
9
|
+
* Ensures indices are within the bounds of the array.
|
|
10
|
+
*
|
|
11
|
+
* @template T The type of elements in the array.
|
|
12
|
+
* @param {T[]} array The array.
|
|
13
|
+
* @param {number} startIndex The desired starting index.
|
|
14
|
+
* @param {number} endIndex The desired ending index.
|
|
15
|
+
* @returns {ValidatedSortRange} An object containing the validated start index, end index,
|
|
16
|
+
* and a boolean indicating if the operation should proceed on the range.
|
|
17
|
+
*/
|
|
18
|
+
var validateRange = exports.validateRange = function validateRange(array, startIndex, endIndex) {
|
|
19
|
+
var length = array.length;
|
|
20
|
+
// Handle empty arrays early
|
|
21
|
+
if (length === 0) {
|
|
22
|
+
return {
|
|
23
|
+
startIndex: 0,
|
|
24
|
+
endIndex: -1,
|
|
25
|
+
shouldSort: false
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var validatedStartIndex = Math.max(0, Math.min(startIndex, length - 1));
|
|
29
|
+
var validatedEndIndex = Math.max(validatedStartIndex, Math.min(endIndex, length - 1));
|
|
30
|
+
return {
|
|
31
|
+
startIndex: validatedStartIndex,
|
|
32
|
+
endIndex: validatedEndIndex,
|
|
33
|
+
shouldSort: validatedEndIndex >= validatedStartIndex
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Object validation core module
|
|
3
3
|
* Provides validation functionality for objects with type-specific validation rules for each property
|
|
4
4
|
*/
|
|
5
|
-
import type { ValidateCoreReturnType, ValidateType } from "@/Validate/type";
|
|
5
|
+
import type { Types, ValidateCoreReturnType, ValidateType } from "@/Validate/type";
|
|
6
6
|
/**
|
|
7
7
|
* Creates an object validator with property-specific validation rules
|
|
8
8
|
* @template T - Object type containing validation functions for each property
|
|
@@ -12,8 +12,4 @@ import type { ValidateCoreReturnType, ValidateType } from "@/Validate/type";
|
|
|
12
12
|
*/
|
|
13
13
|
export declare const object: <T extends {
|
|
14
14
|
[key: string]: (value: any) => ValidateCoreReturnType<any>;
|
|
15
|
-
}>(option?: T, message?: string) => (value: { [key in keyof T]: ValidateType<ReturnType<T[key]>["type"]>; }) => {
|
|
16
|
-
validate: boolean;
|
|
17
|
-
message: string;
|
|
18
|
-
type: { [key in keyof T]: ValidateType<ReturnType<T[key]>["type"]>; };
|
|
19
|
-
};
|
|
15
|
+
}>(option?: T, message?: string) => (value: Types<{ [key in keyof T]: ValidateType<ReturnType<T[key]>["type"]>; }>) => ValidateCoreReturnType<{ [key in keyof T]: ValidateType<ReturnType<T[key]>["type"]>; }>;
|
|
@@ -33,3 +33,4 @@ export type ValidateFunctionType<T> = (value: T) => boolean;
|
|
|
33
33
|
* @returns The corresponding TypeScript type (string, number, boolean) or the original type T
|
|
34
34
|
*/
|
|
35
35
|
export type ValidateType<T> = T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : T;
|
|
36
|
+
export type SchemaToInterface<T extends (value: any) => ValidateCoreReturnType<any>> = ReturnType<T>["type"];
|