All files / src/utils array.ts

100% Statements 2/2
100% Branches 4/4
100% Functions 1/1
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14                    16x 16x    
import type { Arrayable } from 'type-fest';
import type { Nullable } from './type';
 
/**
 * Convert `Arrayable<T>` to `Array<T>`
 *
 * @category Array
 * @link https://github.com/antfu/utils/blob/929fdd7e70f2b5095f51218be48362901923d62e/src/array.ts
 */
export function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T> {
	const _array = array ?? [];
	return Array.isArray(_array) ? _array : [_array];
}