From 84a3fa1a8b178f17aa3860c9829362739bf0bdab Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 23 Jan 2018 20:54:12 +0200 Subject: [PATCH] Add castArray --- snippets/castArray.md | 14 ++++++++++++++ tag_database | 1 + 2 files changed, 15 insertions(+) create mode 100644 snippets/castArray.md 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