pretty-format
Advanced tools
Comparing version 4.1.0 to 4.2.0
73
index.js
@@ -39,4 +39,6 @@ 'use strict'; | ||
function printFunction(val) { | ||
if (val.name === '') { | ||
function printFunction(val, printFunctionName) { | ||
if (!printFunctionName) { | ||
return '[Function]'; | ||
} else if (val.name === '') { | ||
return '[Function anonymous]' | ||
@@ -56,3 +58,3 @@ } else { | ||
function printBasicValue(val) { | ||
function printBasicValue(val, printFunctionName) { | ||
if (val === true || val === false) return '' + val; | ||
@@ -66,3 +68,3 @@ if (val === undefined) return 'undefined'; | ||
if (typeOf === 'string') return '"' + printString(val) + '"'; | ||
if (typeOf === 'function') return printFunction(val); | ||
if (typeOf === 'function') return printFunction(val, printFunctionName); | ||
if (typeOf === 'symbol') return printSymbol(val); | ||
@@ -74,3 +76,3 @@ | ||
if (toStringed === '[object WeakSet]') return 'WeakSet {}'; | ||
if (toStringed === '[object Function]' || toStringed === '[object GeneratorFunction]') return printFunction(val, min); | ||
if (toStringed === '[object Function]' || toStringed === '[object GeneratorFunction]') return printFunction(val, printFunctionName); | ||
if (toStringed === '[object Symbol]') return printSymbol(val); | ||
@@ -88,3 +90,3 @@ if (toStringed === '[object Date]') return toISOString.call(val); | ||
function printList(list, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON) { | ||
function printList(list, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
let body = ''; | ||
@@ -98,3 +100,3 @@ | ||
for (let i = 0; i < list.length; i++) { | ||
body += innerIndent + print(list[i], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
body += innerIndent + print(list[i], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
@@ -112,11 +114,11 @@ if (i < list.length - 1) { | ||
function printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON) { | ||
return (min ? '' : 'Arguments ') + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
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 printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON) { | ||
return (min ? '' : val.constructor.name + ' ') + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
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 printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON) { | ||
function printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
let result = 'Map {'; | ||
@@ -132,4 +134,4 @@ const iterator = val.entries(); | ||
while (!current.done) { | ||
const key = print(current.value[0], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
const value = print(current.value[1], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
const key = print(current.value[0], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
const value = print(current.value[1], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
@@ -151,3 +153,3 @@ result += innerIndent + key + ' => ' + value; | ||
function printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON) { | ||
function printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
const constructor = min ? '' : (val.constructor ? val.constructor.name + ' ' : 'Object '); | ||
@@ -171,4 +173,4 @@ let result = constructor + '{'; | ||
const key = keys[i]; | ||
const name = print(key, indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
const value = print(val[key], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
const name = print(key, indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
const value = print(val[key], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
@@ -188,3 +190,3 @@ result += innerIndent + name + ': ' + value; | ||
function printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON) { | ||
function printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
let result = 'Set {'; | ||
@@ -200,3 +202,3 @@ const iterator = val.entries(); | ||
while (!current.done) { | ||
result += innerIndent + print(current.value[1], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
result += innerIndent + print(current.value[1], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
@@ -216,3 +218,3 @@ current = iterator.next(); | ||
function printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON) { | ||
function printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
refs = refs.slice(); | ||
@@ -230,3 +232,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); | ||
return print(val.toJSON(), indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
} | ||
@@ -236,15 +238,15 @@ | ||
if (toStringed === '[object Arguments]') { | ||
return hitMaxDepth ? '[Arguments]' : printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
return hitMaxDepth ? '[Arguments]' : printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
} else if (isToStringedArrayType(toStringed)) { | ||
return hitMaxDepth ? '[Array]' : printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
return hitMaxDepth ? '[Array]' : printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
} else if (toStringed === '[object Map]') { | ||
return hitMaxDepth ? '[Map]' : printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
return hitMaxDepth ? '[Map]' : printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
} else if (toStringed === '[object Set]') { | ||
return hitMaxDepth ? '[Set]' : printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
return hitMaxDepth ? '[Set]' : printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
} else if (typeof val === 'object') { | ||
return hitMaxDepth ? '[Object]' : printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
return hitMaxDepth ? '[Object]' : printObject(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) { | ||
function printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
let match = false; | ||
@@ -267,3 +269,3 @@ let plugin; | ||
function boundPrint(val) { | ||
return print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
return print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
} | ||
@@ -282,10 +284,10 @@ | ||
function print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON) { | ||
const basic = printBasicValue(val); | ||
function print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName) { | ||
const basic = printBasicValue(val, printFunctionName); | ||
if (basic) return basic; | ||
const plugin = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
const plugin = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
if (plugin) return plugin; | ||
return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON); | ||
return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName); | ||
} | ||
@@ -299,2 +301,3 @@ | ||
plugins: [], | ||
printFunctionName: true, | ||
}; | ||
@@ -352,7 +355,7 @@ | ||
refs = []; | ||
var pluginsResult = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min, opts.callToJSON); | ||
var pluginsResult = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min, opts.callToJSON, opts.printFunctionName); | ||
if (pluginsResult) return pluginsResult; | ||
} | ||
var basicResult = printBasicValue(val); | ||
var basicResult = printBasicValue(val, opts.printFunctionName); | ||
if (basicResult) return basicResult; | ||
@@ -362,5 +365,5 @@ | ||
if (!refs) refs = []; | ||
return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min, opts.callToJSON); | ||
return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min, opts.callToJSON, opts.printFunctionName); | ||
} | ||
module.exports = prettyFormat; |
{ | ||
"name": "pretty-format", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "Stringify any JavaScript value.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19385
381