Sha256: a9149fb9031c95ab73aaa55bf12b6d0174b7ae0cd6681209d8c82a88c688c6f9

Contents?: true

Size: 721 Bytes

Versions: 30

Compression:

Stored size: 721 Bytes

Contents

"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;
	}
};

Version data entries

30 entries across 29 versions & 2 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/ext/node_modules/type/string/coerce.js
optimacms-0.1.61 spec/dummy/node_modules/type/string/coerce.js
govuk_publishing_components-18.0.0 node_modules/type/string/coerce.js
govuk_publishing_components-17.21.0 node_modules/type/string/coerce.js
govuk_publishing_components-17.20.0 node_modules/type/string/coerce.js
govuk_publishing_components-17.19.1 node_modules/type/string/coerce.js
govuk_publishing_components-17.19.0 node_modules/type/string/coerce.js
govuk_publishing_components-17.18.0 node_modules/type/string/coerce.js
govuk_publishing_components-17.17.0 node_modules/type/string/coerce.js
govuk_publishing_components-17.16.0 node_modules/type/string/coerce.js
govuk_publishing_components-17.15.0 node_modules/type/string/coerce.js
govuk_publishing_components-17.14.0 node_modules/type/string/coerce.js
govuk_publishing_components-17.13.0 node_modules/type/string/coerce.js
govuk_publishing_components-17.12.2 node_modules/type/string/coerce.js
govuk_publishing_components-17.12.1 node_modules/type/string/coerce.js
govuk_publishing_components-17.12.0 node_modules/type/string/coerce.js
govuk_publishing_components-17.11.0 node_modules/type/string/coerce.js
govuk_publishing_components-17.10.0 node_modules/type/string/coerce.js
govuk_publishing_components-17.9.0 node_modules/type/string/coerce.js
govuk_publishing_components-17.8.0 node_modules/type/string/coerce.js