@sinonjs/formatio
Advanced tools
Comparing version 3.2.2 to 4.0.0
@@ -14,2 +14,3 @@ "use strict"; | ||
var specialObjects = []; | ||
/* istanbul ignore else */ | ||
if (typeof global !== "undefined") { | ||
@@ -30,4 +31,3 @@ specialObjects.push({ object: global, value: "[object global]" }); | ||
var name = functionName(object && object.constructor); | ||
var excludes = f.excludeConstructors || | ||
formatio.excludeConstructors || []; | ||
var excludes = f.excludeConstructors || formatio.excludeConstructors; | ||
@@ -47,6 +47,10 @@ var i, l; | ||
function isCircular(object, objects) { | ||
if (typeof object !== "object") { return false; } | ||
if (typeof object !== "object") { | ||
return false; | ||
} | ||
var i, l; | ||
for (i = 0, l = objects.length; i < l; ++i) { | ||
if (objects[i] === object) { return true; } | ||
if (objects[i] === object) { | ||
return true; | ||
} | ||
} | ||
@@ -56,8 +60,12 @@ return false; | ||
// eslint-disable-next-line complexity | ||
function ascii(f, object, processed, indent) { | ||
if (typeof object === "string") { | ||
if (object.length === 0) { return "(empty string)"; } | ||
if (object.length === 0) { | ||
return "(empty string)"; | ||
} | ||
var qs = f.quoteStrings; | ||
var quote = typeof qs !== "boolean" || qs; | ||
return processed || quote ? "\"" + object + "\"" : object; | ||
// eslint-disable-next-line quotes | ||
return processed || quote ? '"' + object + '"' : object; | ||
} | ||
@@ -80,15 +88,23 @@ | ||
processed = processed || []; | ||
var internalProcessed = processed || []; | ||
if (isCircular(object, processed)) { return "[Circular]"; } | ||
if (isCircular(object, internalProcessed)) { | ||
return "[Circular]"; | ||
} | ||
if (typeOf(object) === "array") { | ||
return ascii.array.call(f, object, processed); | ||
return ascii.array.call(f, object, internalProcessed); | ||
} | ||
if (!object) { return String((1 / object) === -Infinity ? "-0" : object); } | ||
if (samsam.isElement(object)) { return ascii.element(object); } | ||
if (!object) { | ||
return String(1 / object === -Infinity ? "-0" : object); | ||
} | ||
if (samsam.isElement(object)) { | ||
return ascii.element(object); | ||
} | ||
if (typeof object.toString === "function" && | ||
object.toString !== Object.prototype.toString) { | ||
if ( | ||
typeof object.toString === "function" && | ||
object.toString !== Object.prototype.toString | ||
) { | ||
return object.toString(); | ||
@@ -105,9 +121,13 @@ } | ||
if (samsam.isSet(object)) { | ||
return ascii.set.call(f, object, processed); | ||
return ascii.set.call(f, object, internalProcessed); | ||
} | ||
return ascii.object.call(f, object, processed, indent); | ||
if (object instanceof Map) { | ||
return ascii.map.call(f, object, internalProcessed); | ||
} | ||
return ascii.object.call(f, object, internalProcessed, indent); | ||
} | ||
ascii.func = function (func) { | ||
ascii.func = function(func) { | ||
var funcName = functionName(func) || ""; | ||
@@ -118,13 +138,14 @@ return "function " + funcName + "() {}"; | ||
function delimit(str, delimiters) { | ||
delimiters = delimiters || ["[", "]"]; | ||
return delimiters[0] + str + delimiters[1]; | ||
var delims = delimiters || ["[", "]"]; | ||
return delims[0] + str + delims[1]; | ||
} | ||
ascii.array = function (array, processed, delimiters) { | ||
processed = processed || []; | ||
ascii.array = function(array, processed, delimiters) { | ||
processed.push(array); | ||
var pieces = []; | ||
var i, l; | ||
l = (this.limitChildrenCount > 0) ? | ||
Math.min(this.limitChildrenCount, array.length) : array.length; | ||
l = | ||
this.limitChildrenCount > 0 | ||
? Math.min(this.limitChildrenCount, array.length) | ||
: array.length; | ||
@@ -142,6 +163,10 @@ for (i = 0; i < l; ++i) { | ||
ascii.set = function (set, processed) { | ||
ascii.set = function(set, processed) { | ||
return ascii.array.call(this, Array.from(set), processed, ["Set {", "}"]); | ||
}; | ||
ascii.map = function(map, processed) { | ||
return ascii.array.call(this, Array.from(map), processed, ["Map [", "]"]); | ||
}; | ||
function getSymbols(object) { | ||
@@ -152,2 +177,3 @@ if (samsam.isArguments(object)) { | ||
/* istanbul ignore else */ | ||
if (typeof Object.getOwnPropertySymbols === "function") { | ||
@@ -157,15 +183,21 @@ return Object.getOwnPropertySymbols(object); | ||
/* istanbul ignore next: This is only for IE, since getOwnPropertySymbols | ||
* does not exist on Object there | ||
*/ | ||
return []; | ||
} | ||
ascii.object = function (object, processed, indent) { | ||
processed = processed || []; | ||
ascii.object = function(object, processed, indent) { | ||
processed.push(object); | ||
indent = indent || 0; | ||
var internalIndent = indent || 0; | ||
var pieces = []; | ||
var properties = Object.keys(object).sort().concat(getSymbols(object)); | ||
var properties = Object.keys(object) | ||
.sort() | ||
.concat(getSymbols(object)); | ||
var length = 3; | ||
var prop, str, obj, i, k, l; | ||
l = (this.limitChildrenCount > 0) ? | ||
Math.min(this.limitChildrenCount, properties.length) : properties.length; | ||
l = | ||
this.limitChildrenCount > 0 | ||
? Math.min(this.limitChildrenCount, properties.length) | ||
: properties.length; | ||
@@ -179,9 +211,12 @@ for (i = 0; i < l; ++i) { | ||
} else { | ||
str = ascii(this, obj, processed, indent + 2); | ||
str = ascii(this, obj, processed, internalIndent + 2); | ||
} | ||
str = ( | ||
typeof prop === "string" && /\s/.test(prop) ? | ||
"\"" + prop + "\"" : prop.toString() | ||
) + ": " + str; | ||
str = | ||
(typeof prop === "string" && /\s/.test(prop) | ||
? // eslint-disable-next-line quotes | ||
'"' + prop + '"' | ||
: prop.toString()) + | ||
": " + | ||
str; | ||
length += str.length; | ||
@@ -194,10 +229,14 @@ pieces.push(str); | ||
var is = ""; | ||
for (i = 0, k = indent; i < k; ++i) { is += " "; } | ||
for (i = 0, k = internalIndent; i < k; ++i) { | ||
is += " "; | ||
} | ||
if (l < properties.length) | ||
{pieces.push("[... " + (properties.length - l) + " more elements]");} | ||
if (l < properties.length) { | ||
pieces.push("[... " + (properties.length - l) + " more elements]"); | ||
} | ||
if (length + indent > 80) { | ||
return prefix + "{\n " + is + pieces.join(",\n " + is) + "\n" + | ||
is + "}"; | ||
if (length + internalIndent > 80) { | ||
return ( | ||
prefix + "{\n " + is + pieces.join(",\n " + is) + "\n" + is + "}" | ||
); | ||
} | ||
@@ -207,3 +246,3 @@ return prefix + "{ " + pieces.join(", ") + " }"; | ||
ascii.element = function (element) { | ||
ascii.element = function(element) { | ||
var tagName = element.tagName.toLowerCase(); | ||
@@ -219,3 +258,6 @@ var attrs = element.attributes; | ||
if (attrName !== "contenteditable" || val !== "inherit") { | ||
if (val) { pairs.push(attrName + "=\"" + val + "\""); } | ||
if (val) { | ||
// eslint-disable-next-line quotes | ||
pairs.push(attrName + '="' + val + '"'); | ||
} | ||
} | ||
@@ -232,4 +274,4 @@ } | ||
var res = formatted + pairs.join(" ") + ">" + content + | ||
"</" + tagName + ">"; | ||
var res = | ||
formatted + pairs.join(" ") + ">" + content + "</" + tagName + ">"; | ||
@@ -249,11 +291,11 @@ return res.replace(/ contentEditable="inherit"/, ""); | ||
configure: function (options) { | ||
configure: function(options) { | ||
return new Formatio(options); | ||
}, | ||
constructorName: function (object) { | ||
constructorName: function(object) { | ||
return constructorName(this, object); | ||
}, | ||
ascii: function (object, processed, indent) { | ||
ascii: function(object, processed, indent) { | ||
return ascii(this, object, processed, indent); | ||
@@ -260,0 +302,0 @@ } |
{ | ||
"name": "@sinonjs/formatio", | ||
"version": "3.2.2", | ||
"version": "4.0.0", | ||
"description": "Human-readable object formatting", | ||
@@ -23,19 +23,29 @@ "homepage": "https://sinonjs.github.io/formatio/", | ||
"test": "mocha 'lib/**/*.test.js'", | ||
"test-coverage": "nyc --reporter text --reporter html --reporter lcovonly npm run test" | ||
"test-check-coverage": "npm run test-coverage && nyc check-coverage --branches 100 --functions 100 --lines 100", | ||
"test-coverage": "nyc --reporter text --reporter html --reporter lcovonly npm run test", | ||
"preversion": "npm run test-check-coverage", | ||
"version": "changes --commits --footer", | ||
"postversion": "git push --follow-tags && npm publish --access public" | ||
}, | ||
"dependencies": { | ||
"@sinonjs/commons": "^1", | ||
"@sinonjs/samsam": "^3.1.0" | ||
"@sinonjs/samsam": "^4.2.0" | ||
}, | ||
"devDependencies": { | ||
"@sinonjs/referee": "^3.2.0", | ||
"eslint": "^4.19.1", | ||
"eslint-config-sinon": "^1.0.3", | ||
"@studio/changes": "^1.7.0", | ||
"eslint": "^6.5.1", | ||
"eslint-config-prettier": "^6.4.0", | ||
"eslint-config-sinon": "^3.0.1", | ||
"eslint-plugin-ie11": "^1.0.0", | ||
"eslint-plugin-mocha": "^6.1.1", | ||
"eslint-plugin-prettier": "^3.1.1", | ||
"jsdom": "^15.1.1", | ||
"jsdom-global": "^3.0.2", | ||
"mocha": "^6.2.1", | ||
"nyc": "^14.1.1", | ||
"rollup": "0.65.2", | ||
"rollup-plugin-commonjs": "9.1.6" | ||
"prettier": "^1.18.2", | ||
"rollup": "1.27.8", | ||
"rollup-plugin-commonjs": "9.3.4" | ||
} | ||
} |
21329
5
239
15
+ Added@sinonjs/samsam@4.2.2(transitive)
+ Addedlodash.get@4.4.2(transitive)
- Removed@sinonjs/samsam@3.3.3(transitive)
- Removedarray-from@2.1.1(transitive)
- Removedlodash@4.17.21(transitive)
Updated@sinonjs/samsam@^4.2.0