castArrayIfExists
将非空值转换为数组
94 bytes
since v12.2.0
使用方法
castArrayIfExists 函数确保非空的输入值始终以数组形式返回。如果输入已经是数组,它返回数组的浅拷贝。如果输入不是数组,它将输入包装在新数组中。空值(null 或 undefined)会原样传递。
import * as _ from "radashi";
_.castArrayIfExists(1); // => [1]_.castArrayIfExists([1, 2, 3]); // => [1, 2, 3]_.castArrayIfExists("hello"); // => ['hello']_.castArrayIfExists(null); // => null_.castArrayIfExists(undefined); // => undefined