UNPKG

961 BJavaScriptView Raw
1import isArray from './isArray';
2import isObjectLike from './isObjectLike';
3
4/** `Object#toString` result references. */
5var stringTag = '[object String]';
6
7/** Used for built-in method references. */
8var objectProto = Object.prototype;
9
10/**
11 * Used to resolve the
12 * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
13 * of values.
14 */
15var objectToString = objectProto.toString;
16
17/**
18 * Checks if `value` is classified as a `String` primitive or object.
19 *
20 * @static
21 * @since 0.1.0
22 * @memberOf _
23 * @category Lang
24 * @param {*} value The value to check.
25 * @returns {boolean} Returns `true` if `value` is correctly classified,
26 * else `false`.
27 * @example
28 *
29 * _.isString('abc');
30 * // => true
31 *
32 * _.isString(1);
33 * // => false
34 */
35function isString(value) {
36 return typeof value == 'string' ||
37 (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
38}
39
40export default isString;