diff options
Diffstat (limited to 'node_modules/core-js/internals/to-primitive.js')
| -rw-r--r-- | node_modules/core-js/internals/to-primitive.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/node_modules/core-js/internals/to-primitive.js b/node_modules/core-js/internals/to-primitive.js new file mode 100644 index 0000000..00a4031 --- /dev/null +++ b/node_modules/core-js/internals/to-primitive.js @@ -0,0 +1,14 @@ +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"); +}; |
