Socket
Socket
Sign inDemoInstall

pretty-format

Package Overview
Dependencies
Maintainers
2
Versions
237
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pretty-format - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

26

index.js

@@ -167,3 +167,25 @@ var isArguments = require('lodash/isArguments');

function printWithPlugin(plugin, val, refs, opts, state) {
function boundPrint(val) {
return print(val, refs, opts, state);
}
function boundIndent(val) {
return indent(val, opts);
}
return plugin.print(val, boundPrint, boundIndent);
}
function printValue(val, refs, opts, state) {
var plugins = opts.plugins;
for (var p = 0; p < plugins.length; p++) {
var plugin = plugins[p];
if (plugin.test(val)) {
return printWithPlugin(plugin, val, refs, opts, state);
}
}
// Simple values

@@ -212,3 +234,4 @@ if ( isBoolean (val) ) return Boolean.prototype.toString.call(val);

indent: 2,
maxDepth: Infinity
maxDepth: Infinity,
plugins: []
};

@@ -238,2 +261,3 @@

opts = normalizeOptions(opts)
plugins = opts.plugins;

@@ -240,0 +264,0 @@ return print(val, [], opts, {

2

package.json
{
"name": "pretty-format",
"version": "3.0.0",
"version": "3.1.0",
"description": "Stringify any JavaScript value.",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -48,1 +48,25 @@ # pretty-format [![Travis build status](http://img.shields.io/travis/thejameskyle/pretty-format.svg?style=flat)](https://travis-ci.org/thejameskyle/pretty-format)

```
### Plugins
Pretty format also supports adding plugins:
```js
var fooPlugin = {
test: function(val) {
return val && val.hasOwnProperty('foo');
},
print: function(val, print, indent) {
return 'Foo: ' + print(val.foo);
}
};
var obj = { foo: { bar: {} } };
prettyFormat(obj, {
plugins: [fooPlugin]
});
// Foo: Object {
// "bar": Object {}
// }
```

@@ -228,2 +228,17 @@ var assert = require('assert');

});
it('should support plugins', function() {
function Foo() {};
assert.equal(prettyFormat(new Foo(), {
plugins: [{
test: function(object) {
return object.constructor.name === 'Foo';
},
print: function() {
return 'class Foo'
}
}]
}), 'class Foo');
})
});
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