From 4f8bbf4733e5a36d7b336e737a39fe9099c640ca Mon Sep 17 00:00:00 2001 From: macsmac Date: Wed, 13 Dec 2017 00:33:36 +0500 Subject: [PATCH] Added getType function --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 640da6cd9..e6e38b36a 100644 --- a/README.md +++ b/README.md @@ -261,6 +261,15 @@ const arrayMin = arr => Math.min(...arr); // arrayMin([10, 1, 5]) -> 1 ``` +### Get native type of value + +Returns lower-cased constructor name of value, "undefined" or "null" if value is undefined or null + +```js +const getType = v => v === undefined ? "undefined" : v === null ? "null" : v.constructor.name.toLowerCase(); +// getType(new Set([1,2,3])) -> "set" +``` + ### Get scroll position Use `pageXOffset` and `pageYOffset` if they are defined, otherwise `scrollLeft` and `scrollTop`.