moderndash
Advanced tools
Comparing version 0.12.4 to 0.12.5
/** | ||
* Creates an array of elements split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements. | ||
* | ||
* @returns Returns the new array of chunks. | ||
* @param chunkSize - The array to process. | ||
* @param array - The length of each chunk | ||
* @example | ||
@@ -13,2 +10,5 @@ * chunk(['a', 'b', 'c', 'd'], 2) | ||
* // => [['a', 'b', 'c'], ['d']] | ||
* @returns Returns the new array of chunks. | ||
* @param chunkSize - The array to process. | ||
* @param array - The length of each chunk | ||
*/ | ||
@@ -214,3 +214,2 @@ declare function chunk<TInput>(array: TInput[], chunkSize: number): TInput[][]; | ||
* | ||
* @returns Returns the slice of `array`. | ||
* @example | ||
@@ -227,2 +226,3 @@ * const users = [ | ||
* @param array - The array to query. | ||
* @returns Returns the slice of `array`. | ||
*/ | ||
@@ -362,3 +362,3 @@ declare function takeRightWhile<TArr>(predicate: (elem: TArr) => boolean, array: TArr[]): TArr[]; | ||
* // This is the default way to create cache keys. | ||
* const defaultResolver = (...args: unknown[]) => JSON.stringify(args); | ||
* const defaultResolver = (...args: unknown[]) => JSON.stringify(args) | ||
* ``` | ||
@@ -590,2 +590,67 @@ * @param func - The function to have its output memoized. | ||
/** | ||
* Calculates the average of an array of numbers | ||
* | ||
* Returns `NaN` if the input array is empty. | ||
* @example | ||
* average([1, 2, 3, 4, 5]) // => 3 | ||
* | ||
* @param numbers - The input array of numbers | ||
* @returns The average of the input array, or NaN if the input array is empty | ||
*/ | ||
declare function average(numbers: number[]): number; | ||
/** | ||
* Calculates the median of an array of numbers | ||
* | ||
* Returns `NaN` if the input array is empty. | ||
* @example | ||
* median([1, 2, 3, 4, 5]) // => 3 | ||
* median([1, 2, 3, 4, 5, 6]) // => 3.5 | ||
* | ||
* @param numbers - The input array of numbers | ||
* @returns The median of the input array | ||
*/ | ||
declare function median(numbers: number[]): number; | ||
/** | ||
* Generates a random float between two given numbers, including those numbers. | ||
* | ||
* It uses `crypto.getRandomValues` to generate the random number. | ||
* @example | ||
* randomFloat(1, 10) // => 1.123456789 | ||
* | ||
* @param min - The smallest float that can be generated. | ||
* @param max - The largest float that can be generated. | ||
* | ||
* @returns A random float between `min` and `max`, including `min` and `max`. | ||
*/ | ||
declare function randomFloat(min: number, max: number): number; | ||
/** | ||
* Generates a random integer between two given numbers, including those numbers. | ||
* | ||
* It uses `crypto.getRandomValues` to generate the random number. | ||
* @example | ||
* randomInt(1, 10) // => 5 | ||
* | ||
* @param min - The smallest integer that can be generated. | ||
* @param max - The largest integer that can be generated. | ||
* | ||
* @returns A random integer between `min` and `max`, including `min` and `max`. | ||
*/ | ||
declare function randomInt(min: number, max: number): number; | ||
/** | ||
* Calculates the sum of an array of numbers. | ||
* | ||
* Returns `NaN` if the input array is empty. | ||
* @example | ||
* sum([1, 2, 3, 4, 5]) // => 15 | ||
* | ||
* @param numbers - The input array of numbers | ||
* @returns The sum of the input array | ||
*/ | ||
declare function sum(numbers: number[]): number; | ||
/** | ||
* The type of a plain object. | ||
@@ -1063,2 +1128,2 @@ * | ||
export { GenericFunction, MinimumTwoArrays, PlainObject, Queue, camelCase, capitalize, chunk, count, debounce, deburr, decDebounce, decMaxCalls, decMemoize, decMinCalls, decThrottle, difference, dropRightWhile, dropWhile, escapeHtml, escapeRegExp, group, intersection, isEmpty, isEqual, isPlainObject, isUrl, kebabCase, maxCalls, memoize, merge, minCalls, omit, pascalCase, pick, races, retry, sample, set, shuffle, sleep, snakeCase, sort, stripSpecial, takeRightWhile, takeWhile, throttle, timeout, times, titleCase, toDecorator, unescapeHtml, unique }; | ||
export { GenericFunction, MinimumTwoArrays, PlainObject, Queue, average, camelCase, capitalize, chunk, count, debounce, deburr, decDebounce, decMaxCalls, decMemoize, decMinCalls, decThrottle, difference, dropRightWhile, dropWhile, escapeHtml, escapeRegExp, group, intersection, isEmpty, isEqual, isPlainObject, isUrl, kebabCase, maxCalls, median, memoize, merge, minCalls, omit, pascalCase, pick, races, randomFloat, randomInt, retry, sample, set, shuffle, sleep, snakeCase, sort, stripSpecial, sum, takeRightWhile, takeWhile, throttle, timeout, times, titleCase, toDecorator, unescapeHtml, unique }; |
@@ -340,2 +340,46 @@ // src/array/chunk.ts | ||
// src/number/sum.ts | ||
function sum(numbers) { | ||
if (numbers.length === 0) | ||
return NaN; | ||
return numbers.reduce((total, current) => total + current, 0); | ||
} | ||
// src/number/average.ts | ||
function average(numbers) { | ||
if (numbers.length === 0) | ||
return NaN; | ||
return sum(numbers) / numbers.length; | ||
} | ||
// src/number/median.ts | ||
function median(numbers) { | ||
if (numbers.length === 0) | ||
return NaN; | ||
const sortedArray = [...numbers].sort((a, b) => a - b); | ||
const mid = Math.floor(sortedArray.length / 2); | ||
return sortedArray.length % 2 === 0 ? (sortedArray[mid - 1] + sortedArray[mid]) / 2 : sortedArray[mid]; | ||
} | ||
// src/number/randomFloat.ts | ||
function randomFloat(min, max) { | ||
if (min > max) | ||
throw new Error("min must be less than or equal to max"); | ||
const range = max - min; | ||
const randomBuffer = new Uint32Array(1); | ||
crypto.getRandomValues(randomBuffer); | ||
const random = randomBuffer[0] / 4294967295; | ||
return min + random * range; | ||
} | ||
// src/number/randomInt.ts | ||
function randomInt(min, max) { | ||
if (min > max) | ||
throw new Error("min must be less than or equal to max"); | ||
const range = max - min + 1; | ||
const randomBuffer = new Uint32Array(1); | ||
crypto.getRandomValues(randomBuffer); | ||
return min + randomBuffer[0] % range; | ||
} | ||
// src/object/merge.ts | ||
@@ -661,2 +705,3 @@ function merge(target, ...sources) { | ||
Queue, | ||
average, | ||
camelCase, | ||
@@ -686,2 +731,3 @@ capitalize, | ||
maxCalls, | ||
median, | ||
memoize, | ||
@@ -694,2 +740,4 @@ merge, | ||
races, | ||
randomFloat, | ||
randomInt, | ||
retry, | ||
@@ -703,2 +751,3 @@ sample, | ||
stripSpecial, | ||
sum, | ||
takeRightWhile, | ||
@@ -705,0 +754,0 @@ takeWhile, |
@@ -5,2 +5,6 @@ { | ||
"description": "A lodash inspired utility framework for ESM/Typescript/ESNext", | ||
"engines": { | ||
"node": ">=19.x.x", | ||
"npm": ">=8.x.x" | ||
}, | ||
"sideEffects": false, | ||
@@ -55,3 +59,3 @@ "scripts": { | ||
}, | ||
"version": "0.12.4" | ||
"version": "0.12.5" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
224897
2552