pretty-format
Advanced tools
Comparing version 20.1.0-alpha.3 to 20.1.0-beta.1
@@ -19,2 +19,3 @@ 'use strict'; | ||
var _ansiStyles = require('ansi-styles');var _ansiStyles2 = _interopRequireDefault(_ansiStyles); | ||
@@ -60,2 +61,6 @@ | ||
const isSymbol = key => | ||
// $FlowFixMe string literal `symbol`. This value is not a valid `typeof` return value | ||
typeof key === 'symbol' || toString.call(key) === '[object Symbol]'; | ||
function isToStringedArrayType(toStringed) { | ||
@@ -164,8 +169,2 @@ return ( | ||
} | ||
if (toStringed === '[object Arguments]' && val.length === 0) { | ||
return 'Arguments []'; | ||
} | ||
if (isToStringedArrayType(toStringed) && val.length === 0) { | ||
return val.constructor.name + ' []'; | ||
} | ||
@@ -230,79 +229,5 @@ if (val instanceof Error) { | ||
return '[' + body + ']'; | ||
return body; | ||
} | ||
function printArguments( | ||
val, | ||
indent, | ||
prevIndent, | ||
spacing, | ||
edgeSpacing, | ||
refs, | ||
maxDepth, | ||
currentDepth, | ||
plugins, | ||
min, | ||
callToJSON, | ||
printFunctionName, | ||
escapeRegex, | ||
colors) | ||
{ | ||
return ( | ||
(min ? '' : 'Arguments ') + | ||
printList( | ||
val, | ||
indent, | ||
prevIndent, | ||
spacing, | ||
edgeSpacing, | ||
refs, | ||
maxDepth, | ||
currentDepth, | ||
plugins, | ||
min, | ||
callToJSON, | ||
printFunctionName, | ||
escapeRegex, | ||
colors)); | ||
} | ||
function printArray( | ||
val, | ||
indent, | ||
prevIndent, | ||
spacing, | ||
edgeSpacing, | ||
refs, | ||
maxDepth, | ||
currentDepth, | ||
plugins, | ||
min, | ||
callToJSON, | ||
printFunctionName, | ||
escapeRegex, | ||
colors) | ||
{ | ||
return ( | ||
(min ? '' : val.constructor.name + ' ') + | ||
printList( | ||
val, | ||
indent, | ||
prevIndent, | ||
spacing, | ||
edgeSpacing, | ||
refs, | ||
maxDepth, | ||
currentDepth, | ||
plugins, | ||
min, | ||
callToJSON, | ||
printFunctionName, | ||
escapeRegex, | ||
colors)); | ||
} | ||
function printMap( | ||
@@ -324,3 +249,3 @@ val, | ||
{ | ||
let result = 'Map {'; | ||
let result = ''; | ||
const iterator = val.entries(); | ||
@@ -380,3 +305,3 @@ let current = iterator.next(); | ||
return result + '}'; | ||
return result; | ||
} | ||
@@ -400,6 +325,3 @@ | ||
{ | ||
const constructor = min ? | ||
'' : | ||
val.constructor ? val.constructor.name + ' ' : 'Object '; | ||
let result = constructor + '{'; | ||
let result = ''; | ||
let keys = Object.keys(val).sort(); | ||
@@ -409,10 +331,3 @@ const symbols = getSymbols(val); | ||
if (symbols.length) { | ||
keys = keys. | ||
filter( | ||
key => | ||
// $FlowFixMe string literal `symbol`. This value is not a valid `typeof` return value | ||
!(typeof key === 'symbol' || | ||
toString.call(key) === '[object Symbol]')). | ||
concat(symbols); | ||
keys = keys.filter(key => !isSymbol(key)).concat(symbols); | ||
} | ||
@@ -470,3 +385,3 @@ | ||
return result + '}'; | ||
return result; | ||
} | ||
@@ -490,3 +405,3 @@ | ||
{ | ||
let result = 'Set {'; | ||
let result = ''; | ||
const iterator = val.entries(); | ||
@@ -530,3 +445,3 @@ let current = iterator.next(); | ||
return result + '}'; | ||
return result; | ||
} | ||
@@ -587,5 +502,10 @@ | ||
if (toStringed === '[object Arguments]') { | ||
if (val.length === 0) { | ||
return 'Arguments []'; | ||
} | ||
return hitMaxDepth ? | ||
'[Arguments]' : | ||
printArguments( | ||
(min ? '' : 'Arguments ') + | ||
'[' + | ||
printList( | ||
val, | ||
@@ -604,8 +524,14 @@ indent, | ||
escapeRegex, | ||
colors); | ||
colors) + | ||
']'; | ||
} else if (isToStringedArrayType(toStringed)) { | ||
if (val.length === 0) { | ||
return val.constructor.name + ' []'; | ||
} | ||
return hitMaxDepth ? | ||
'[Array]' : | ||
printArray( | ||
(min ? '' : val.constructor.name + ' ') + | ||
'[' + | ||
printList( | ||
val, | ||
@@ -624,7 +550,9 @@ indent, | ||
escapeRegex, | ||
colors); | ||
colors) + | ||
']'; | ||
} else if (toStringed === '[object Map]') { | ||
return hitMaxDepth ? | ||
'[Map]' : | ||
'Map {' + | ||
printMap( | ||
@@ -644,7 +572,9 @@ val, | ||
escapeRegex, | ||
colors); | ||
colors) + | ||
'}'; | ||
} else if (toStringed === '[object Set]') { | ||
return hitMaxDepth ? | ||
'[Set]' : | ||
'Set {' + | ||
printSet( | ||
@@ -664,4 +594,5 @@ val, | ||
escapeRegex, | ||
colors); | ||
colors) + | ||
'}'; | ||
} | ||
@@ -671,2 +602,4 @@ | ||
'[Object]' : | ||
(min ? '' : val.constructor ? val.constructor.name + ' ' : 'Object ') + | ||
'{' + | ||
printObject( | ||
@@ -686,7 +619,9 @@ val, | ||
escapeRegex, | ||
colors); | ||
colors) + | ||
'}'; | ||
} | ||
function printPlugin( | ||
plugin, | ||
val, | ||
@@ -707,15 +642,2 @@ indent, | ||
{ | ||
let plugin; | ||
for (let p = 0; p < plugins.length; p++) { | ||
if (plugins[p].test(val)) { | ||
plugin = plugins[p]; | ||
break; | ||
} | ||
} | ||
if (!plugin) { | ||
return null; | ||
} | ||
function boundPrint(val) { | ||
@@ -750,5 +672,22 @@ return print( | ||
return plugin.print(val, boundPrint, boundIndent, opts, colors); | ||
const printed = plugin.print(val, boundPrint, boundIndent, opts, colors); | ||
if (typeof printed !== 'string') { | ||
throw new Error( | ||
`pretty-format: Plugin must return type "string" but instead returned "${typeof printed}".`); | ||
} | ||
return printed; | ||
} | ||
function findPlugin(plugins, val) { | ||
for (let p = 0; p < plugins.length; p++) { | ||
if (plugins[p].test(val)) { | ||
return plugins[p]; | ||
} | ||
} | ||
return null; | ||
} | ||
function print( | ||
@@ -770,20 +709,21 @@ val, | ||
{ | ||
const pluginsResult = printPlugin( | ||
val, | ||
indent, | ||
prevIndent, | ||
spacing, | ||
edgeSpacing, | ||
refs, | ||
maxDepth, | ||
currentDepth, | ||
plugins, | ||
min, | ||
callToJSON, | ||
printFunctionName, | ||
escapeRegex, | ||
colors); | ||
const plugin = findPlugin(plugins, val); | ||
if (plugin !== null) { | ||
return printPlugin( | ||
plugin, | ||
val, | ||
indent, | ||
prevIndent, | ||
spacing, | ||
edgeSpacing, | ||
refs, | ||
maxDepth, | ||
currentDepth, | ||
plugins, | ||
min, | ||
callToJSON, | ||
printFunctionName, | ||
escapeRegex, | ||
colors); | ||
if (typeof pluginsResult === 'string') { | ||
return pluginsResult; | ||
} | ||
@@ -915,3 +855,4 @@ | ||
throw new Error( | ||
`pretty-format: Option "theme" has a key "${key}" whose value "${opts.theme[key]}" is undefined in ansi-styles.`); | ||
`pretty-format: Option "theme" has a key "${key}" whose value "${opts. | ||
theme[key]}" is undefined in ansi-styles.`); | ||
@@ -922,4 +863,2 @@ } | ||
let indent; | ||
let refs; | ||
const prevIndent = ''; | ||
@@ -931,22 +870,21 @@ const currentDepth = 0; | ||
if (opts && opts.plugins.length) { | ||
indent = createIndent(opts.indent); | ||
refs = []; | ||
const pluginsResult = printPlugin( | ||
val, | ||
indent, | ||
prevIndent, | ||
spacing, | ||
edgeSpacing, | ||
refs, | ||
opts.maxDepth, | ||
currentDepth, | ||
opts.plugins, | ||
opts.min, | ||
opts.callToJSON, | ||
opts.printFunctionName, | ||
opts.escapeRegex, | ||
colors); | ||
const plugin = findPlugin(opts.plugins, val); | ||
if (plugin !== null) { | ||
return printPlugin( | ||
plugin, | ||
val, | ||
createIndent(opts.indent), | ||
prevIndent, | ||
spacing, | ||
edgeSpacing, | ||
[], | ||
opts.maxDepth, | ||
currentDepth, | ||
opts.plugins, | ||
opts.min, | ||
opts.callToJSON, | ||
opts.printFunctionName, | ||
opts.escapeRegex, | ||
colors); | ||
if (typeof pluginsResult === 'string') { | ||
return pluginsResult; | ||
} | ||
@@ -964,15 +902,9 @@ } | ||
if (!indent) { | ||
indent = createIndent(opts.indent); | ||
} | ||
if (!refs) { | ||
refs = []; | ||
} | ||
return printComplexValue( | ||
val, | ||
indent, | ||
createIndent(opts.indent), | ||
prevIndent, | ||
spacing, | ||
edgeSpacing, | ||
refs, | ||
[], | ||
opts.maxDepth, | ||
@@ -979,0 +911,0 @@ currentDepth, |
{ | ||
"name": "pretty-format", | ||
"version": "20.1.0-alpha.3", | ||
"version": "20.1.0-beta.1", | ||
"repository": { | ||
@@ -13,5 +13,5 @@ "type": "git", | ||
"dependencies": { | ||
"ansi-regex": "^2.1.1", | ||
"ansi-regex": "^3.0.0", | ||
"ansi-styles": "^3.0.0" | ||
} | ||
} |
@@ -54,5 +54,4 @@ /** | ||
function test(name, value, ignoreResult, prettyFormatOpts) { | ||
const formatted = testCase( | ||
'prettyFormat() ', | ||
() => prettyFormat(value, prettyFormatOpts) | ||
const formatted = testCase('prettyFormat() ', () => | ||
prettyFormat(value, prettyFormatOpts), | ||
); | ||
@@ -79,3 +78,3 @@ | ||
item.isWinner = index === 0; | ||
item.isLoser = index === results.length - 1; | ||
item.isLoser = index === results.length - 1; | ||
}); | ||
@@ -91,4 +90,7 @@ | ||
message += | ||
' - ' + (current.total / NANOSECONDS) + 's total (' + | ||
TIMES_TO_RUN + ' runs)'; | ||
' - ' + | ||
current.total / NANOSECONDS + | ||
's total (' + | ||
TIMES_TO_RUN + | ||
' runs)'; | ||
} | ||
@@ -109,7 +111,7 @@ if (current.error) { | ||
const diff = (current.time - winner.time); | ||
const diff = current.time - winner.time; | ||
if (diff > (winner.time * 0.85)) { | ||
if (diff > winner.time * 0.85) { | ||
message = chalk.bgRed.black(message); | ||
} else if (diff > (winner.time * 0.65)) { | ||
} else if (diff > winner.time * 0.65) { | ||
message = chalk.bgYellow.black(message); | ||
@@ -173,3 +175,3 @@ } else if (!current.error) { | ||
test('regular expressions from constructors', new RegExp('regexp')); | ||
test('regular expressions from literals', /regexp/ig); | ||
test('regular expressions from literals', /regexp/gi); | ||
test('an empty set', new Set()); | ||
@@ -207,7 +209,7 @@ const setWithValues = new Set(); | ||
React.createElement('div'), | ||
React.createElement('div', {prop: {a: 1, b: 2}}, | ||
React.createElement('div', null, | ||
React.createElement('div') | ||
) | ||
) | ||
React.createElement( | ||
'div', | ||
{prop: {a: 1, b: 2}}, | ||
React.createElement('div', null, React.createElement('div')), | ||
), | ||
); | ||
@@ -214,0 +216,0 @@ |
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
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances 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
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
327466
2589
+ Addedansi-regex@3.0.1(transitive)
- Removedansi-regex@2.1.1(transitive)
Updatedansi-regex@^3.0.0