pretty-format
Advanced tools
Comparing version 4.2.3 to 4.3.0
58
index.js
@@ -57,3 +57,3 @@ 'use strict'; | ||
function printBasicValue(val, printFunctionName) { | ||
function printBasicValue(val, printFunctionName, escapeRegex) { | ||
if (val === true || val === false) return '' + val; | ||
@@ -78,3 +78,8 @@ if (val === undefined) return 'undefined'; | ||
if (toStringed === '[object Error]') return printError(val); | ||
if (toStringed === '[object RegExp]') return regExpToString.call(val); | ||
if (toStringed === '[object RegExp]') { | ||
if (escapeRegex) { | ||
return printString(regExpToString.call(val)); | ||
} | ||
return regExpToString.call(val); | ||
}; | ||
if (toStringed === '[object Arguments]' && val.length === 0) return 'Arguments []'; | ||
@@ -88,3 +93,3 @@ if (isToStringedArrayType(toStringed) && val.length === 0) return val.constructor.name + ' []'; | ||
function printList(list, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
function printList(list, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex) { | ||
let body = ''; | ||
@@ -111,11 +116,11 @@ | ||
function printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
return (min ? '' : 'Arguments ') + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
function printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex) { | ||
return (min ? '' : 'Arguments ') + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex); | ||
} | ||
function printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
return (min ? '' : val.constructor.name + ' ') + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
function printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex) { | ||
return (min ? '' : val.constructor.name + ' ') + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex); | ||
} | ||
function printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
function printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex) { | ||
let result = 'Map {'; | ||
@@ -149,3 +154,3 @@ const iterator = val.entries(); | ||
function printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
function printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex) { | ||
const constructor = min ? '' : (val.constructor ? val.constructor.name + ' ' : 'Object '); | ||
@@ -185,3 +190,3 @@ let result = constructor + '{'; | ||
function printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
function printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex) { | ||
let result = 'Set {'; | ||
@@ -212,3 +217,3 @@ const iterator = val.entries(); | ||
function printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
function printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex) { | ||
refs = refs.slice(); | ||
@@ -226,3 +231,3 @@ if (refs.indexOf(val) > -1) { | ||
if (callToJSON && !hitMaxDepth && val.toJSON && typeof val.toJSON === 'function') { | ||
return print(val.toJSON(), indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
return print(val.toJSON(), indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex); | ||
} | ||
@@ -232,15 +237,15 @@ | ||
if (toStringed === '[object Arguments]') { | ||
return hitMaxDepth ? '[Arguments]' : printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
return hitMaxDepth ? '[Arguments]' : printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex); | ||
} else if (isToStringedArrayType(toStringed)) { | ||
return hitMaxDepth ? '[Array]' : printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
return hitMaxDepth ? '[Array]' : printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex); | ||
} else if (toStringed === '[object Map]') { | ||
return hitMaxDepth ? '[Map]' : printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
return hitMaxDepth ? '[Map]' : printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex); | ||
} else if (toStringed === '[object Set]') { | ||
return hitMaxDepth ? '[Set]' : printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
return hitMaxDepth ? '[Set]' : printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex); | ||
} else if (typeof val === 'object') { | ||
return hitMaxDepth ? '[Object]' : printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
return hitMaxDepth ? '[Object]' : printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex); | ||
} | ||
} | ||
function printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
function printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex) { | ||
let match = false; | ||
@@ -263,3 +268,3 @@ let plugin; | ||
function boundPrint(val) { | ||
return print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
return print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex); | ||
} | ||
@@ -278,10 +283,10 @@ | ||
function print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
const basic = printBasicValue(val, printFunctionName); | ||
function print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex) { | ||
const basic = printBasicValue(val, printFunctionName, escapeRegex); | ||
if (basic) return basic; | ||
const plugin = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
const plugin = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex); | ||
if (plugin) return plugin; | ||
return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex); | ||
} | ||
@@ -296,2 +301,3 @@ | ||
printFunctionName: true, | ||
escapeRegex: false, | ||
}; | ||
@@ -347,7 +353,7 @@ | ||
refs = []; | ||
var pluginsResult = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min, opts.callToJSON, opts.printFunctionName); | ||
var pluginsResult = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min, opts.callToJSON, opts.printFunctionName, opts.escapeRegex); | ||
if (pluginsResult) return pluginsResult; | ||
} | ||
var basicResult = printBasicValue(val, opts.printFunctionName); | ||
var basicResult = printBasicValue(val, opts.printFunctionName, opts.escapeRegex); | ||
if (basicResult) return basicResult; | ||
@@ -357,5 +363,5 @@ | ||
if (!refs) refs = []; | ||
return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min, opts.callToJSON, opts.printFunctionName); | ||
return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min, opts.callToJSON, opts.printFunctionName, opts.escapeRegex); | ||
} | ||
module.exports = prettyFormat; |
{ | ||
"name": "pretty-format", | ||
"version": "4.2.3", | ||
"version": "4.3.0", | ||
"description": "Stringify any JavaScript value.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
20192
395