Merge pull request #830 from liuhanqu/master

Another primitive assert function
This commit is contained in:
Angelos Chalaris
2018-10-16 11:35:20 +03:00
committed by GitHub

View File

@ -2,12 +2,10 @@
Returns a boolean determining if the passed value is primitive or not.
Use `Array.prototype.includes()` on an array of type strings which are not primitive,
supplying the type using `typeof`.
Since `typeof null` evaluates to `'object'`, it needs to be directly compared.
Create an object from `val` and compare it with `val` to determine if the passed value is primitive (i.e. not equal to the created object).
```js
const isPrimitive = val => !['object', 'function'].includes(typeof val) || val === null;
const isPrimitive = val => Object(val) !== val;
```
```js