船员公众号
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

13 lines
469 B

2 months ago
// @ts-nocheck
/**
*
* @param item
* @returns
*/
export const toArray = <T>(item: T | T[]): T[] => Array.isArray(item) ? item : [item];
// 示例
// console.log(toArray(5)); // 输出: [5]
// console.log(toArray("hello")); // 输出: ["hello"]
// console.log(toArray([1, 2, 3])); // 输出: [1, 2, 3]
// console.log(toArray(["apple", "banana"])); // 输出: ["apple", "banana"]