UNPKG

1.13 kBJavaScriptView Raw
1import isObjectLike from './isObjectLike';
2
3/** `Object#toString` result references. */
4var numberTag = '[object Number]';
5
6/** Used for built-in method references. */
7var objectProto = Object.prototype;
8
9/**
10 * Used to resolve the
11 * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
12 * of values.
13 */
14var objectToString = objectProto.toString;
15
16/**
17 * Checks if `value` is classified as a `Number` primitive or object.
18 *
19 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
20 * classified as numbers, use the `_.isFinite` method.
21 *
22 * @static
23 * @memberOf _
24 * @since 0.1.0
25 * @category Lang
26 * @param {*} value The value to check.
27 * @returns {boolean} Returns `true` if `value` is correctly classified,
28 * else `false`.
29 * @example
30 *
31 * _.isNumber(3);
32 * // => true
33 *
34 * _.isNumber(Number.MIN_VALUE);
35 * // => true
36 *
37 * _.isNumber(Infinity);
38 * // => true
39 *
40 * _.isNumber('3');
41 * // => false
42 */
43function isNumber(value) {
44 return typeof value == 'number' ||
45 (isObjectLike(value) && objectToString.call(value) == numberTag);
46}
47
48export default isNumber;