Socket
Socket
Sign inDemoInstall

@sinonjs/formatio

Package Overview
Dependencies
Maintainers
5
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sinonjs/formatio - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

368

lib/formatio.js

@@ -1,241 +0,225 @@

(function (root, factory) {
"use strict";
"use strict";
if (typeof define === "function" && define.amd) {
// AMD. Register as an anonymous module.
define(["samsam"], factory);
} else if (typeof module === "object" && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require("samsam"));
} else {
// Browser globals (root is window)
root.formatio = factory(root.samsam);
}
}(typeof self !== "undefined" ? self : this, function (samsam) {
"use strict";
var samsam = require("@sinonjs/samsam");
var formatio = {
excludeConstructors: ["Object", /^.$/],
quoteStrings: true,
limitChildrenCount: 0
};
var formatio = {
excludeConstructors: ["Object", /^.$/],
quoteStrings: true,
limitChildrenCount: 0
};
var specialObjects = [];
if (typeof global !== "undefined") {
specialObjects.push({ object: global, value: "[object global]" });
}
if (typeof document !== "undefined") {
specialObjects.push({
object: document,
value: "[object HTMLDocument]"
});
}
if (typeof window !== "undefined") {
specialObjects.push({ object: window, value: "[object Window]" });
}
var specialObjects = [];
if (typeof global !== "undefined") {
specialObjects.push({ object: global, value: "[object global]" });
}
if (typeof document !== "undefined") {
specialObjects.push({
object: document,
value: "[object HTMLDocument]"
});
}
if (typeof window !== "undefined") {
specialObjects.push({ object: window, value: "[object Window]" });
}
function functionName(func) {
if (!func) { return ""; }
if (func.displayName) { return func.displayName; }
if (func.name) { return func.name; }
var matches = func.toString().match(/function\s+([^\(]+)/m);
return (matches && matches[1]) || "";
}
function functionName(func) {
if (!func) { return ""; }
if (func.displayName) { return func.displayName; }
if (func.name) { return func.name; }
var matches = func.toString().match(/function\s+([^\(]+)/m);
return (matches && matches[1]) || "";
function constructorName(f, object) {
var name = functionName(object && object.constructor);
var excludes = f.excludeConstructors ||
formatio.excludeConstructors || [];
var i, l;
for (i = 0, l = excludes.length; i < l; ++i) {
if (typeof excludes[i] === "string" && excludes[i] === name) {
return "";
} else if (excludes[i].test && excludes[i].test(name)) {
return "";
}
}
function constructorName(f, object) {
var name = functionName(object && object.constructor);
var excludes = f.excludeConstructors ||
formatio.excludeConstructors || [];
return name;
}
var i, l;
for (i = 0, l = excludes.length; i < l; ++i) {
if (typeof excludes[i] === "string" && excludes[i] === name) {
return "";
} else if (excludes[i].test && excludes[i].test(name)) {
return "";
}
}
function isCircular(object, objects) {
if (typeof object !== "object") { return false; }
var i, l;
for (i = 0, l = objects.length; i < l; ++i) {
if (objects[i] === object) { return true; }
}
return false;
}
return name;
function ascii(f, object, processed, indent) {
if (typeof object === "string") {
if (object.length === 0) { return "(empty string)"; }
var qs = f.quoteStrings;
var quote = typeof qs !== "boolean" || qs;
return processed || quote ? "\"" + object + "\"" : object;
}
function isCircular(object, objects) {
if (typeof object !== "object") { return false; }
var i, l;
for (i = 0, l = objects.length; i < l; ++i) {
if (objects[i] === object) { return true; }
}
return false;
if (typeof object === "function" && !(object instanceof RegExp)) {
return ascii.func(object);
}
function ascii(f, object, processed, indent) {
if (typeof object === "string") {
if (object.length === 0) { return "(empty string)"; }
var qs = f.quoteStrings;
var quote = typeof qs !== "boolean" || qs;
return processed || quote ? "\"" + object + "\"" : object;
}
processed = processed || [];
if (typeof object === "function" && !(object instanceof RegExp)) {
return ascii.func(object);
}
if (isCircular(object, processed)) { return "[Circular]"; }
processed = processed || [];
if (Object.prototype.toString.call(object) === "[object Array]") {
return ascii.array.call(f, object, processed);
}
if (isCircular(object, processed)) { return "[Circular]"; }
if (!object) { return String((1 / object) === -Infinity ? "-0" : object); }
if (samsam.isElement(object)) { return ascii.element(object); }
if (Object.prototype.toString.call(object) === "[object Array]") {
return ascii.array.call(f, object, processed);
}
if (typeof object.toString === "function" &&
object.toString !== Object.prototype.toString) {
return object.toString();
}
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) {
return object.toString();
var i, l;
for (i = 0, l = specialObjects.length; i < l; i++) {
if (object === specialObjects[i].object) {
return specialObjects[i].value;
}
}
var i, l;
for (i = 0, l = specialObjects.length; i < l; i++) {
if (object === specialObjects[i].object) {
return specialObjects[i].value;
}
}
if (typeof Set !== "undefined" && object instanceof Set) {
return ascii.set.call(f, object, processed);
}
return ascii.object.call(f, object, processed, indent);
if (typeof Set !== "undefined" && object instanceof Set) {
return ascii.set.call(f, object, processed);
}
ascii.func = function (func) {
return "function " + functionName(func) + "() {}";
};
return ascii.object.call(f, object, processed, indent);
}
function delimit(str, delimiters) {
delimiters = delimiters || ["[", "]"];
return delimiters[0] + str + delimiters[1];
}
ascii.func = function (func) {
return "function " + functionName(func) + "() {}";
};
ascii.array = function (array, processed, delimiters) {
processed = processed || [];
processed.push(array);
var pieces = [];
var i, l;
l = (this.limitChildrenCount > 0) ?
Math.min(this.limitChildrenCount, array.length) : array.length;
function delimit(str, delimiters) {
delimiters = delimiters || ["[", "]"];
return delimiters[0] + str + delimiters[1];
}
for (i = 0; i < l; ++i) {
pieces.push(ascii(this, array[i], processed));
}
ascii.array = function (array, processed, delimiters) {
processed = processed || [];
processed.push(array);
var pieces = [];
var i, l;
l = (this.limitChildrenCount > 0) ?
Math.min(this.limitChildrenCount, array.length) : array.length;
if (l < array.length) {
pieces.push("[... " + (array.length - l) + " more elements]");
}
for (i = 0; i < l; ++i) {
pieces.push(ascii(this, array[i], processed));
}
return delimit(pieces.join(", "), delimiters);
};
if (l < array.length) {
pieces.push("[... " + (array.length - l) + " more elements]");
}
ascii.set = function (set, processed) {
return ascii.array.call(this, Array.from(set), processed, ["Set {", "}"]);
};
return delimit(pieces.join(", "), delimiters);
};
ascii.object = function (object, processed, indent) {
processed = processed || [];
processed.push(object);
indent = indent || 0;
var pieces = [];
var properties = samsam.keys(object).sort();
var length = 3;
var prop, str, obj, i, k, l;
l = (this.limitChildrenCount > 0) ?
Math.min(this.limitChildrenCount, properties.length) : properties.length;
ascii.set = function (set, processed) {
return ascii.array.call(this, Array.from(set), processed, ["Set {", "}"]);
};
for (i = 0; i < l; ++i) {
prop = properties[i];
obj = object[prop];
ascii.object = function (object, processed, indent) {
processed = processed || [];
processed.push(object);
indent = indent || 0;
var pieces = [];
var properties = Object.keys(object).sort();
var length = 3;
var prop, str, obj, i, k, l;
l = (this.limitChildrenCount > 0) ?
Math.min(this.limitChildrenCount, properties.length) : properties.length;
if (isCircular(obj, processed)) {
str = "[Circular]";
} else {
str = ascii(this, obj, processed, indent + 2);
}
for (i = 0; i < l; ++i) {
prop = properties[i];
obj = object[prop];
str = (/\s/.test(prop) ? "\"" + prop + "\"" : prop) + ": " + str;
length += str.length;
pieces.push(str);
if (isCircular(obj, processed)) {
str = "[Circular]";
} else {
str = ascii(this, obj, processed, indent + 2);
}
var cons = constructorName(this, object);
var prefix = cons ? "[" + cons + "] " : "";
var is = "";
for (i = 0, k = indent; i < k; ++i) { is += " "; }
str = (/\s/.test(prop) ? "\"" + prop + "\"" : prop) + ": " + str;
length += str.length;
pieces.push(str);
}
if (l < properties.length)
{pieces.push("[... " + (properties.length - l) + " more elements]");}
var cons = constructorName(this, object);
var prefix = cons ? "[" + cons + "] " : "";
var is = "";
for (i = 0, k = indent; i < k; ++i) { is += " "; }
if (length + indent > 80) {
return prefix + "{\n " + is + pieces.join(",\n " + is) + "\n" +
is + "}";
}
return prefix + "{ " + pieces.join(", ") + " }";
};
if (l < properties.length)
{pieces.push("[... " + (properties.length - l) + " more elements]");}
ascii.element = function (element) {
var tagName = element.tagName.toLowerCase();
var attrs = element.attributes;
var pairs = [];
var attr, attrName, i, l, val;
if (length + indent > 80) {
return prefix + "{\n " + is + pieces.join(",\n " + is) + "\n" +
is + "}";
}
return prefix + "{ " + pieces.join(", ") + " }";
};
for (i = 0, l = attrs.length; i < l; ++i) {
attr = attrs.item(i);
attrName = attr.nodeName.toLowerCase().replace("html:", "");
val = attr.nodeValue;
if (attrName !== "contenteditable" || val !== "inherit") {
if (val) { pairs.push(attrName + "=\"" + val + "\""); }
}
ascii.element = function (element) {
var tagName = element.tagName.toLowerCase();
var attrs = element.attributes;
var pairs = [];
var attr, attrName, i, l, val;
for (i = 0, l = attrs.length; i < l; ++i) {
attr = attrs.item(i);
attrName = attr.nodeName.toLowerCase().replace("html:", "");
val = attr.nodeValue;
if (attrName !== "contenteditable" || val !== "inherit") {
if (val) { pairs.push(attrName + "=\"" + val + "\""); }
}
}
var formatted = "<" + tagName + (pairs.length > 0 ? " " : "");
// SVG elements have undefined innerHTML
var content = element.innerHTML || "";
var formatted = "<" + tagName + (pairs.length > 0 ? " " : "");
// SVG elements have undefined innerHTML
var content = element.innerHTML || "";
if (content.length > 20) {
content = content.substr(0, 20) + "[...]";
}
if (content.length > 20) {
content = content.substr(0, 20) + "[...]";
}
var res = formatted + pairs.join(" ") + ">" + content +
"</" + tagName + ">";
var res = formatted + pairs.join(" ") + ">" + content +
"</" + tagName + ">";
return res.replace(/ contentEditable="inherit"/, "");
};
return res.replace(/ contentEditable="inherit"/, "");
};
function Formatio(options) {
// eslint-disable-next-line guard-for-in
for (var opt in options) {
this[opt] = options[opt];
}
function Formatio(options) {
// eslint-disable-next-line guard-for-in
for (var opt in options) {
this[opt] = options[opt];
}
}
Formatio.prototype = {
functionName: functionName,
Formatio.prototype = {
functionName: functionName,
configure: function (options) {
return new Formatio(options);
},
configure: function (options) {
return new Formatio(options);
},
constructorName: function (object) {
return constructorName(this, object);
},
constructorName: function (object) {
return constructorName(this, object);
},
ascii: function (object, processed, indent) {
return ascii(this, object, processed, indent);
}
};
ascii: function (object, processed, indent) {
return ascii(this, object, processed, indent);
}
};
return Formatio.prototype;
}));
module.exports = Formatio.prototype;
{
"name": "@sinonjs/formatio",
"version": "2.0.0",
"version": "3.0.0",
"description": "Human-readable object formatting",

@@ -17,3 +17,7 @@ "homepage": "http://busterjs.org/docs/formatio/",

"scripts": {
"build": "run-s build:dist-folder build:bundle",
"build:bundle": "rollup -c > dist/formatio.js",
"build:dist-folder": "mkdirp dist",
"lint": "eslint .",
"prepublishOnly": "npm run build && mkdocs gh-deploy -r upstream || mkdocs gh-deploy -r origin",
"test": "mocha 'lib/**/*.test.js'",

@@ -23,13 +27,16 @@ "test-coverage": "nyc --reporter text --reporter html --reporter lcovonly npm run test"

"dependencies": {
"samsam": "1.3.0"
"@sinonjs/samsam": "2.1.0"
},
"devDependencies": {
"eslint": "4.16.0",
"eslint-config-sinon": "1.0.3",
"eslint-plugin-ie11": "1.0.0",
"eslint-plugin-mocha": "4.11.0",
"mocha": "5.0.0",
"nyc": "11.4.1",
"referee": "1.2.0"
"@sinonjs/referee": "^2.5.0",
"eslint": "^4.19.1",
"eslint-config-sinon": "^1.0.3",
"eslint-plugin-ie11": "^1.0.0",
"eslint-plugin-mocha": "^4.11.0",
"mocha": "^5.0.0",
"npm-run-all": "4.1.3",
"nyc": "^11.7.3",
"rollup": "0.65.2",
"rollup-plugin-commonjs": "9.1.6"
}
}

@@ -17,4 +17,13 @@ # formatio

Documentation: https://sinonjs.github.io/formatio/
## Installation
```shell
npm install @sinonjs/formatio
```
## Documentation
https://sinonjs.github.io/formatio/
## Backers

@@ -93,2 +102,2 @@

samsam was released under [BSD-3](LICENSE)
formatio was released under [BSD-3](LICENSE)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc