1 | ;
|
2 |
|
3 | var isString = require('./string'),
|
4 | isNumber = require('./number'),
|
5 | isBoolean = require('./boolean'),
|
6 | isUndefined = require('./undefined'),
|
7 | isNull = require('./null'),
|
8 | isObject = require('./object');
|
9 |
|
10 | /**
|
11 | * Checks whether a value is a primitive.
|
12 | *
|
13 | * Helpful links:
|
14 | * * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures
|
15 | * * http://javascriptweblog.wordpress.com/2010/09/27/the-secret-life-of-javascript-primitives/
|
16 | *
|
17 | * NOTE! A primitive value wrapped by a corresponding object is not a primitive anymore
|
18 | * ```js
|
19 | * var a = 'test' // this is a primitive
|
20 | * a = new String('test'); // and this is not a primitive
|
21 | * ```
|
22 | *
|
23 | * @function primitive
|
24 | *
|
25 | * @example
|
26 | * var is = require('predicates');
|
27 | *
|
28 | * is.primitive('test'); // true
|
29 | * is.primitive(undefined); // true
|
30 | * is.primitive(10); // true
|
31 | * is.primitive(null); // true
|
32 | * is.primitive(false); // true
|
33 | *
|
34 | * is.primitive(new Number(10)); // false
|
35 | * is.primitive(new String('test')); // false
|
36 | * is.primitive(new Boolean(true)); // false
|
37 | * is.primitive({}); // false
|
38 | *
|
39 | * @param {*} value
|
40 | * @returns {Boolean}
|
41 | */
|
42 | module.exports = function isPrimitive(value) {
|
43 | return !isObject(value) && (isString(value) || isNumber(value) || isBoolean(value) || isUndefined(value) || isNull(value));
|
44 | }; |
\ | No newline at end of file |