mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-25 09:55:15 +00:00
23 lines
872 B
JavaScript
23 lines
872 B
JavaScript
var isObject = require('../internals/is-object');
|
|
var isSymbol = require('../internals/is-symbol');
|
|
var ordinaryToPrimitive = require('../internals/ordinary-to-primitive');
|
|
var wellKnownSymbol = require('../internals/well-known-symbol');
|
|
|
|
var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
|
|
|
|
// `ToPrimitive` abstract operation
|
|
// https://tc39.es/ecma262/#sec-toprimitive
|
|
module.exports = function (input, pref) {
|
|
if (!isObject(input) || isSymbol(input)) return input;
|
|
var exoticToPrim = input[TO_PRIMITIVE];
|
|
var result;
|
|
if (exoticToPrim !== undefined) {
|
|
if (pref === undefined) pref = 'default';
|
|
result = exoticToPrim.call(input, pref);
|
|
if (!isObject(result) || isSymbol(result)) return result;
|
|
throw TypeError("Can't convert object to primitive value");
|
|
}
|
|
if (pref === undefined) pref = 'number';
|
|
return ordinaryToPrimitive(input, pref);
|
|
};
|