1 | var isObject = require('../internals/is-object');
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | module.exports = function (input, PREFERRED_STRING) {
|
8 | if (!isObject(input)) return input;
|
9 | var fn, val;
|
10 | if (PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
|
11 | if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) return val;
|
12 | if (!PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
|
13 | throw TypeError("Can't convert object to primitive value");
|
14 | };
|