Reason
My eyes feel pain when i see:
if x+'' === x ... // if that stringif x*1 === x ... // if that number... // and many others
s-is
Let me introduce a simple way to ensure the correctness of the target data. As I see it.
Node.js
installation for npm i s-is --save
Browser
installation for bower i s-is --save
In javascript definition of data types associated with some difficulties. Due to the fact that the original methods do not always work as expected. We are forced to turn to non-standard decisions. Not always, these decisions are correct, and even rarer - code still readable. If we are interested in conditional of 10 data types.And we want them correctly and to determine.
NaN, null, undefined, infinity, number, string, boolean, function, array, object
Example
var is = ; is; // => trueis; // => false; // => true is; // => false; // => false; // => trueis; // => true
Note - This approach is implemented for all the previously identified 10 of types data.
ES6
It gives us a lot of benefits and expands our capabilities. And also adds surprises.
// try ittypeof Symbol == 'symbol'; // => true// buttypeof == 'object'; // => true// ortypeof {} == 'function'; // => true
typeof
In connection with such innovations was established method of determining the 10 data types, plus all the innovations.
var is = ; is; // => "object" is; // => "array" is; // => "nan"is; // => "infinity"is; // => "null" is; // => "number"is; // => "string"is; // => "boolean"is; // => "undefined"is; // => "function" // just more exampleis; // => "symbol"is; // => "object"is; // => "object" is;// => "object"is; // => "function"
Helpers
And in the end, we frequently need to define some specific objects. This applies mainly to proven technologies.
var is = ; // dateis; // => true; // => true; // => false // promisevar p = ;is; // => true; // => trueis; // => false; // => true// isn't nativeis; // => trueis; // => trueis; // => true; // => false; // => false;// => false // arguments { console;}1; { console;};
API documentation
Table of results that generates a test script module.termainal