diff --git a/snippets/castArray.md b/snippets/castArray.md new file mode 100644 index 000000000..dc6d97c77 --- /dev/null +++ b/snippets/castArray.md @@ -0,0 +1,14 @@ +### castArray + +Casts the provided value as an array if it's not one. + +Use `Array.isArray()` to determine if `val` is an array and return it as-is or encapsulated in an array accordingly. + +```js +const castArray = val => Array.isArray(val) ? val : [val]; +``` + +```js +castArray('foo'); // ['foo'] +castArray([1]); // [1] +``` diff --git a/tag_database b/tag_database index a929e397c..dbaec5875 100644 --- a/tag_database +++ b/tag_database @@ -9,6 +9,7 @@ byteSize:string call:adapter,function capitalize:string,array capitalizeEveryWord:string,regexp +castArray:utility,array,type chainAsync:function chunk:array clampNumber:math