Skip to content

Commit

Permalink
fix(types): mark newer array functions as public
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Feb 14, 2022
1 parent 3159b3d commit 2b72af5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/api/js-utils.ensurearray.md
Expand Up @@ -6,6 +6,7 @@

> Warning: This API is now obsolete.
>
> renamed to `toArray`
>
<b>Signature:</b>
Expand Down
2 changes: 1 addition & 1 deletion docs/api/js-utils.hasitems.md
Expand Up @@ -4,7 +4,7 @@

## hasItems() function

Test if a value is an array with some items (length &gt; 0).
Test if a value is an array with some items (`length > 0`<!-- -->).

This is not a general replacement for `.length > 0`<!-- -->, since it is also a typeguard: `if (hasItems(val)) else { val }` will complain that `val` is `never` in the `else` branch, since it was proven not to be an array by this function, even if `val` is simply empty.

Expand Down
2 changes: 1 addition & 1 deletion docs/api/js-utils.md
Expand Up @@ -49,7 +49,7 @@
| [getMethods(value)](./js-utils.getmethods.md) | Get the methods from an instance and its prototypes. |
| [getOrDefault(map, key, defaultValue)](./js-utils.getordefault.md) | Get a map key or default value when the key does not exist or is nil. |
| [getTestLogger(verbose)](./js-utils.gettestlogger.md) | Get a test logger. Returns a null logger unless <code>verbose</code> is true or run under debug mode. |
| [hasItems(val)](./js-utils.hasitems.md) | Test if a value is an array with some items (length &gt; 0).<!-- -->This is not a general replacement for <code>.length &gt; 0</code>, since it is also a typeguard: <code>if (hasItems(val)) else { val }</code> will complain that <code>val</code> is <code>never</code> in the <code>else</code> branch, since it was proven not to be an array by this function, even if <code>val</code> is simply empty. |
| [hasItems(val)](./js-utils.hasitems.md) | Test if a value is an array with some items (<code>length &gt; 0</code>).<!-- -->This is not a general replacement for <code>.length &gt; 0</code>, since it is also a typeguard: <code>if (hasItems(val)) else { val }</code> will complain that <code>val</code> is <code>never</code> in the <code>else</code> branch, since it was proven not to be an array by this function, even if <code>val</code> is simply empty. |
| [hasItems(val)](./js-utils.hasitems_1.md) | |
| [isArray(list)](./js-utils.isarray.md) | Wrapper for <code>Array.isArray</code> with better readonly type handling. |
| [isArray(list)](./js-utils.isarray_1.md) | Wrapper for <code>Array.isArray</code> with better readonly type handling. |
Expand Down
1 change: 1 addition & 0 deletions docs/api/js-utils.mergearrays.md
Expand Up @@ -6,6 +6,7 @@

> Warning: This API is now obsolete.
>
> renamed to `mergeArray`
>
<b>Signature:</b>
Expand Down
14 changes: 11 additions & 3 deletions src/Array.ts
Expand Up @@ -22,7 +22,7 @@ export function mergeArray<TItem>(...parts: ReadonlyArray<TItem | ReadonlyArray<
}

/**
* @deprecated
* @deprecated renamed to `mergeArray`
*/
export function mergeArrays<TItem>(...parts: Array<TItem | Array<TItem>>): Array<TItem>;
export function mergeArrays<TItem>(...parts: ReadonlyArray<TItem | ReadonlyArray<TItem>>): ReadonlyArray<TItem>;
Expand All @@ -31,12 +31,14 @@ export function mergeArrays<TItem>(...parts: ReadonlyArray<TItem | ReadonlyArray
}

/**
* Test if a value is an array with some items (length > 0).
* Test if a value is an array with some items (`length > 0`).
*
* This is not a general replacement for `.length > 0`, since it is also a typeguard:
* `if (hasItems(val)) else { val }` will complain that `val` is `never` in the `else`
* branch, since it was proven not to be an array by this function, even if `val` is
* simply empty.
*
* @public
*/
export function hasItems<T>(val: Maybe<Array<T>>): val is Array<T>;
export function hasItems<T>(val: Maybe<ReadonlyArray<T>>): val is ReadonlyArray<T>;
Expand All @@ -45,7 +47,7 @@ export function hasItems<T>(val: Maybe<ReadonlyArray<T>>): val is ReadonlyArray<
}

/**
* @deprecated
* @deprecated renamed to `toArray`
*/
export function ensureArray<T>(val: Maybe<Array<T>>): Array<T>;
export function ensureArray<T>(val: Maybe<ReadonlyArray<T>>): ReadonlyArray<T>;
Expand All @@ -55,10 +57,14 @@ export function ensureArray<T>(val: Maybe<ReadonlyArray<T>>): ReadonlyArray<T> {

/**
* Copy an existing array-like or convert a single value to an array.
*
* @public
*/
export function toArray<TVal>(val: Maybe<TVal | Array<TVal>>): Array<TVal>;
/**
* Copy an existing readonly array-like or convert a single value to a readonly array.
*
* @public
*/
export function toArray<TVal>(val: Maybe<TVal | ReadonlyArray<TVal>>): ReadonlyArray<TVal>;
export function toArray<TVal>(val: Maybe<TVal | ReadonlyArray<TVal>>): ReadonlyArray<TVal> {
Expand Down Expand Up @@ -100,6 +106,8 @@ export function isEmpty(val: Maybe<Array<unknown> | ReadonlyArray<unknown>>): bo

/**
* Filter and zip some arrays. The `cb` is called for each slice, which is kept if `cb` returns true.
*
* @public
*/
export function filterZip<T1>(cb: (a: T1) => boolean, l1: Array<T1>): Array<T1>;
export function filterZip<T1, T2>(cb: (a: T1, b: T2) => boolean, l1: Array<T1>, l2: Array<T2>): [Array<T1>, Array<T2>];
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Expand Up @@ -10,21 +10,21 @@ export {
mergeArrays,
hasItems,
ensureArray,
toArray,
isArray,
isEmpty,
filterZip,
lengthOf,
toArray,
} from './Array';
export {
ArrayMapper,
ArrayMapperOptions,
} from './ArrayMapper';
export {
defer,
deferUntil,
deferValue,
timeout,
deferUntil,
waitFor,
} from './Async';
export {
Expand Down

0 comments on commit 2b72af5

Please sign in to comment.