Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

object-inspect

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-inspect - npm Package Compare versions

Comparing version 1.4.1 to 1.5.0

test/quoteStyle.js

22

index.js

@@ -16,2 +16,8 @@ var hasMap = typeof Map === 'function' && Map.prototype;

module.exports = function inspect_ (obj, opts, depth, seen) {
if (!opts) opts = {};
if (has(opts, 'quoteStyle') && (opts.quoteStyle !== 'single' && opts.quoteStyle !== 'double')) {
throw new TypeError('option "quoteStyle" must be "single" or "double"');
}
if (typeof obj === 'undefined') {

@@ -26,4 +32,5 @@ return 'undefined';

}
if (typeof obj === 'string') {
return inspectString(obj);
return inspectString(obj, opts);
}

@@ -37,4 +44,2 @@ if (typeof obj === 'number') {

if (!opts) opts = {};
var maxDepth = typeof opts.depth === 'undefined' ? 5 : opts.depth;

@@ -71,3 +76,3 @@ if (typeof depth === 'undefined') depth = 0;

for (var i = 0; i < attrs.length; i++) {
s += ' ' + attrs[i].name + '="' + quote(attrs[i].value) + '"';
s += ' ' + attrs[i].name + '=' + wrapQuotes(quote(attrs[i].value), 'double', opts);
}

@@ -126,2 +131,7 @@ s += '>';

function wrapQuotes (s, defaultStyle, opts) {
var quoteChar = (opts.quoteStyle || defaultStyle) === 'double' ? '"' : "'";
return quoteChar + s + quoteChar;
}
function quote (s) {

@@ -205,5 +215,5 @@ return String(s).replace(/"/g, '&quot;');

function inspectString (str) {
function inspectString (str, opts) {
var s = str.replace(/(['\\])/g, '\\$1').replace(/[\x00-\x1f]/g, lowbyte);
return "'" + s + "'";
return wrapQuotes(s, 'single', opts);
}

@@ -210,0 +220,0 @@

{
"name": "object-inspect",
"version": "1.4.1",
"version": "1.5.0",
"description": "string representations of objects in node and the browser",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,3 +5,3 @@ var inspect = require('../');

test('element', function (t) {
t.plan(1);
t.plan(3);
var elem = {

@@ -15,2 +15,4 @@ nodeName: 'div',

t.deepEqual(inspect(obj), '[ 1, <div class="row"></div>, 3 ]');
t.deepEqual(inspect(obj, { quoteStyle: 'single' }), "[ 1, <div class='row'></div>, 3 ]");
t.deepEqual(inspect(obj, { quoteStyle: 'double' }), '[ 1, <div class="row"></div>, 3 ]');
});

@@ -17,0 +19,0 @@

@@ -19,1 +19,11 @@ var inspect = require('../');

});
test('anon function', function (t) {
var f = (function () {
return function () {};
}());
var obj = [ 1, 2, f, 4 ];
t.equal(inspect(obj), '[ 1, 2, [Function], 4 ]');
t.end();
});

@@ -110,3 +110,7 @@ var inspect = require('../');

t.equal(inspect(str), "'" + str + "'", 'primitive string shows as such');
t.equal(inspect(str, { quoteStyle: 'single' }), "'" + str + "'", 'primitive string shows as such, single quoted');
t.equal(inspect(str, { quoteStyle: 'double' }), '"' + str + '"', 'primitive string shows as such, double quoted');
t.equal(inspect(Object(str)), 'Object(' + inspect(str) + ')', 'String object shows as such');
t.equal(inspect(Object(str), { quoteStyle: 'single' }), 'Object(' + inspect(str, { quoteStyle: 'single' }) + ')', 'String object shows as such, single quoted');
t.equal(inspect(Object(str), { quoteStyle: 'double' }), 'Object(' + inspect(str, { quoteStyle: 'double' }) + ')', 'String object shows as such, double quoted');

@@ -113,0 +117,0 @@ t.end();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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