You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
14 lines
779 B
14 lines
779 B
var isObject = require('../internals/is-object');
|
|
|
|
// `ToPrimitive` abstract operation
|
|
// https://tc39.github.io/ecma262/#sec-toprimitive
|
|
// instead of the ES6 spec version, we didn't implement @@toPrimitive case
|
|
// and the second argument - flag - preferred type is a string
|
|
module.exports = function (input, PREFERRED_STRING) {
|
|
if (!isObject(input)) return input;
|
|
var fn, val;
|
|
if (PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
|
|
if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) return val;
|
|
if (!PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
|
|
throw TypeError("Can't convert object to primitive value");
|
|
};
|
|
|