frontend/.pnpm-store/v3/files/db/fb4d78f1ca8234689843ebae594a153423c30c9f5aa50bdc95458c40231b1724a96e9ddf666b5a3063f563f9eee65c7e22fbcb53dd3e6b336ddd9e225ab094

24 lines
721 B
Plaintext

"use strict";
var isValue = require("../value/is")
, isObject = require("../object/is");
var objectToString = Object.prototype.toString;
module.exports = function (value) {
if (!isValue(value)) return null;
if (isObject(value)) {
// Reject Object.prototype.toString coercion
var valueToString = value.toString;
if (typeof valueToString !== "function") return null;
if (valueToString === objectToString) return null;
// Note: It can be object coming from other realm, still as there's no ES3 and CSP compliant
// way to resolve its realm's Object.prototype.toString it's left as not addressed edge case
}
try {
return "" + value; // Ensure implicit coercion
} catch (error) {
return null;
}
};