moderndash
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -77,2 +77,3 @@ /** | ||
* | ||
* @example | ||
* const users = [ | ||
@@ -90,5 +91,4 @@ * { 'user': 'barney', 'active': false }, | ||
* @returns Returns the slice of `array`. | ||
* @example | ||
*/ | ||
declare function dropRightWhile<T>(array: T[], predicate: (value: T) => boolean): T[]; | ||
declare function dropRightWhile<TArr>(array: TArr[], predicate: (value: TArr) => boolean): TArr[]; | ||
@@ -113,3 +113,3 @@ /** | ||
*/ | ||
declare function dropWhile<T>(array: T[], predicate: (value: T) => boolean): T[]; | ||
declare function dropWhile<TArr>(array: TArr[], predicate: (value: TArr) => boolean): TArr[]; | ||
@@ -165,5 +165,6 @@ /** | ||
* Gets a random element an array. A single element is returned by default. | ||
* Specify the `size` parameter to get an array of multiple random elements. | ||
* Specify the `multi` parameter to get an array of multiple random elements. | ||
* | ||
* If the array is empty, `undefined` is returned. | ||
* If `multi` is defined it returns an empty array. | ||
* @example | ||
@@ -180,3 +181,3 @@ * sample([1, 2, 3, 4]) | ||
declare function sample<TArr>(array: TArr[]): TArr | undefined; | ||
declare function sample<TArr>(array: TArr[], size: number): TArr[]; | ||
declare function sample<TArr>(array: TArr[], multi: number): TArr[]; | ||
@@ -194,3 +195,3 @@ /** | ||
*/ | ||
declare function shuffle<TInput>(array: TInput[]): TInput[]; | ||
declare function shuffle<TArr>(array: TArr[]): TArr[]; | ||
@@ -216,9 +217,5 @@ /** | ||
/** | ||
* Creates a slice of `array` with elements taken from the end. Elements are | ||
* taken until `predicate` returns falsey. The predicate is invoked with | ||
* three arguments: (value, index, array). | ||
* Creates a slice of `array` with elements taken from the end. | ||
* Elements are taken until `predicate` returns falsey. | ||
* | ||
* @category Array | ||
* @param predicate - The function invoked per iteration. | ||
* @param array - The array to query. | ||
* @returns Returns the slice of `array`. | ||
@@ -234,14 +231,12 @@ * @example | ||
* // => objects for ['fred', 'pebbles'] | ||
* @category Array | ||
* @param predicate - The function invoked per iteration. | ||
* @param array - The array to query. | ||
*/ | ||
declare function takeRightWhile<T>(predicate: (elem: T) => boolean, array: T[]): T[]; | ||
declare function takeRightWhile<TArr>(predicate: (elem: TArr) => boolean, array: TArr[]): TArr[]; | ||
/** | ||
* Creates a slice of `array` with elements taken from the beginning. Elements | ||
* are taken until `predicate` returns falsey. The predicate is invoked with | ||
* three arguments: (value, index, array). | ||
* Creates a slice of `array` with elements taken from the beginning. | ||
* Elements are taken until `predicate` returns falsey. | ||
* | ||
* @category Array | ||
* @param predicate The function invoked per iteration. | ||
* @param array The array to query. | ||
* @returns Returns the slice of `array`. | ||
* @example | ||
@@ -256,4 +251,8 @@ * const users = [ | ||
* // => objects for ['barney', 'fred'] | ||
* @category Array | ||
* @param predicate The function invoked per iteration. | ||
* @param array The array to query. | ||
* @returns Returns the slice of `array`. | ||
*/ | ||
declare function takeWhile<T>(array: T[], predicate: (elem: T) => boolean): T[]; | ||
declare function takeWhile<TArr>(array: TArr[], predicate: (elem: TArr) => boolean): TArr[]; | ||
@@ -619,3 +618,5 @@ /** | ||
* | ||
* Use-case: Validating and documenting parameters. | ||
* Use-case: Validating and documenting parameters. Other usage is limited. | ||
* | ||
* *Note: Check this [writeup](https://github.com/sindresorhus/type-fest/issues/334#issuecomment-987787840) for more details.* | ||
* @example | ||
@@ -628,3 +629,3 @@ * function setYear<T extends number>(x: Integer<T>){}; | ||
*/ | ||
type Integer<T extends number> = `${T}` extends `${bigint}` ? T : never; | ||
type Int<T extends number> = `${T}` extends `${bigint}` ? T : never; | ||
@@ -634,3 +635,6 @@ /** | ||
* You can't pass a `bigint` as they are already guaranteed to be integers. | ||
* Use-case: Validating and documenting parameters. | ||
* | ||
* Use-case: Validating and documenting parameters. Other usage is limited. | ||
* | ||
* *Note: Check this [writeup](https://github.com/sindresorhus/type-fest/issues/334#issuecomment-987787840) for more details.* | ||
* @example | ||
@@ -641,6 +645,5 @@ * function setPercentage<T extends number>(x: Float<T>) {}; | ||
* setPercentage(1); // Error | ||
* | ||
* @category type | ||
*/ | ||
type Float<T extends number> = T extends Integer<T> ? never : T; | ||
type Float<T extends number> = T extends Int<T> ? never : T; | ||
@@ -650,3 +653,5 @@ /** | ||
* | ||
* Use-case: Validating and documenting parameters. | ||
* Use-case: Validating and documenting parameters. Other usage is limited. | ||
* | ||
* *Note: Check this [writeup](https://github.com/sindresorhus/type-fest/issues/334#issuecomment-987787840) for more details.* | ||
* @example | ||
@@ -658,3 +663,3 @@ * function setNegative<T extends number>(x: Negative<T>) {}; | ||
* | ||
* function setNegInt<T extends number>(x: Negative<Integer<T>>) {}; | ||
* function setNegInt<T extends number>(x: Negative<Int<T>>) {}; | ||
* | ||
@@ -671,3 +676,5 @@ * setNegInt(-1); // OK | ||
* | ||
* Use-case: Validating and documenting parameters. | ||
* Use-case: Validating and documenting parameters. Other usage is limited. | ||
* | ||
* *Note: Check this [writeup](https://github.com/sindresorhus/type-fest/issues/334#issuecomment-987787840) for more details.* | ||
* @example | ||
@@ -679,3 +686,3 @@ * function setPositive<T extends number>(x: Positive<T>) {}; | ||
* | ||
* function setPosInt<T extends number>(x: Positive<Integer<T>>) {}; | ||
* function setPosInt<T extends number>(x: Positive<Int<T>>) {}; | ||
* | ||
@@ -764,2 +771,2 @@ * setPosInt(1); // OK | ||
export { Float, Integer, Negative, Positive, after, before, camelCase, capitalize, chunk, count, debounce, deburr, difference, dropRightWhile, dropWhile, escapeHtml, escapeRegExp, group, intersection, isEmpty, isEqual, isPlainObject, isUrl, kebabCase, memoize, omit, once, pascalCase, pick, sample, shuffle, sleep, snakeCase, sort, startCase, stripSpecial, takeRightWhile, takeWhile, throttle, times, unescapeHtml, unique }; | ||
export { Float, Int, Negative, Positive, after, before, camelCase, capitalize, chunk, count, debounce, deburr, difference, dropRightWhile, dropWhile, escapeHtml, escapeRegExp, group, intersection, isEmpty, isEqual, isPlainObject, isUrl, kebabCase, memoize, omit, once, pascalCase, pick, sample, shuffle, sleep, snakeCase, sort, startCase, stripSpecial, takeRightWhile, takeWhile, throttle, times, unescapeHtml, unique }; |
@@ -124,9 +124,12 @@ // src/array/chunk.ts | ||
// src/array/sample.ts | ||
function sample(array, size) { | ||
if (array.length === 0) | ||
return void 0; | ||
if (size === void 0) | ||
function sample(array, multi) { | ||
if (multi === void 0) { | ||
if (array.length === 0) | ||
return void 0; | ||
return getSingleSample(array); | ||
const result = new Array(size); | ||
for (let i = 0; i < size; i++) { | ||
} | ||
if (multi && array.length === 0) | ||
return []; | ||
const result = new Array(multi); | ||
for (let i = 0; i < multi; i++) { | ||
result[i] = getSingleSample(array); | ||
@@ -133,0 +136,0 @@ } |
@@ -51,3 +51,3 @@ { | ||
}, | ||
"version": "0.4.0" | ||
"version": "0.5.0" | ||
} |
@@ -14,2 +14,3 @@ ![ModernDash Logo](/website/src/assets/moderndashLogo.svg) | ||
✅ Hoverable Docs | ||
✅ TS Decorators | ||
</div> | ||
@@ -16,0 +17,0 @@ |
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
155546
1818
40