2024-04-19 14:58:19 +00:00
|
|
|
/** @since 3.9.0 */
|
2023-12-23 14:22:58 +00:00
|
|
|
export function toArray<T> (value: T | T[]): T[] {
|
|
|
|
return Array.isArray(value) ? value : [value]
|
|
|
|
}
|
2024-10-22 13:39:50 +00:00
|
|
|
|
2025-01-14 17:36:18 +00:00
|
|
|
/**
|
|
|
|
* Filter out items from an array in place. This function mutates the array.
|
|
|
|
* `predicate` get through the array from the end to the start for performance.
|
|
|
|
*
|
|
|
|
* This function should be faster than `Array.prototype.filter` on large arrays.
|
|
|
|
*/
|
|
|
|
export function filterInPlace<T> (array: T[], predicate: (item: T, index: number, arr: T[]) => unknown) {
|
|
|
|
for (let i = array.length; i--; i >= 0) {
|
|
|
|
if (!predicate(array[i]!, i, array)) {
|
|
|
|
array.splice(i, 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return array
|
|
|
|
}
|
|
|
|
|
2024-10-22 13:39:50 +00:00
|
|
|
export const MODE_RE = /\.(server|client)(\.\w+)*$/
|