pretty-format2
Advanced tools
Comparing version
98
index.js
@@ -195,5 +195,5 @@ // @flow | ||
const DOWN_OP = { op: 'DOWN' }; | ||
const UP_OP = { op: 'UP' }; | ||
const NEWLINE_OP = { op: 'NEWLINE' }; | ||
const DOWN_OP = {op: 'DOWN'}; | ||
const UP_OP = {op: 'UP'}; | ||
const NEWLINE_OP = {op: 'NEWLINE'}; | ||
@@ -221,5 +221,17 @@ class Stack { | ||
down() { this.push(DOWN_OP); } | ||
up() { this.push(UP_OP); } | ||
newLine() { this.push(NEWLINE_OP); } | ||
down() { | ||
this.push(DOWN_OP); | ||
} | ||
up() { | ||
this.push(UP_OP); | ||
} | ||
newLine() { | ||
this.push(NEWLINE_OP); | ||
} | ||
char(value) { | ||
this.push(new Char(value)); | ||
} | ||
} | ||
@@ -409,35 +421,35 @@ | ||
for (let p = 0; p < plugins.length; p++) { | ||
let current = plugins[p]; | ||
if (typeof current === 'function') { | ||
let result = current(value, stack, env, refs); | ||
if (result) return current; | ||
} else { | ||
if (plugins[p].test(value)) { | ||
plugin = plugins[p]; | ||
break; | ||
} | ||
} | ||
} | ||
for (let p = 0; p < plugins.length; p++) { | ||
let current = plugins[p]; | ||
if (typeof current === 'function') { | ||
let result = current(value, stack, env, refs); | ||
if (result) return current; | ||
} else { | ||
if (plugins[p].test(value)) { | ||
plugin = plugins[p]; | ||
break; | ||
} | ||
} | ||
} | ||
if (!plugin) { | ||
return null; | ||
} | ||
if (!plugin) { | ||
return null; | ||
} | ||
function print(value) { | ||
return printStack(value, depth + 1, refs, env); | ||
} | ||
function print(value) { | ||
return printStack(value, depth + 1, refs, env); | ||
} | ||
function indent(str) { | ||
let indentation = createIndent((depth + 1) * env.opts.indent); | ||
return indentation + str; | ||
} | ||
function indent(str) { | ||
let indentation = createIndent((depth + 1) * env.opts.indent); | ||
return indentation + str; | ||
} | ||
const opts = { | ||
edgeSpacing: env.opts.edgeSpacing, | ||
min: env.opts.min, | ||
spacing: env.opts.spacing, | ||
}; | ||
const opts = { | ||
edgeSpacing: env.opts.edgeSpacing, | ||
min: env.opts.min, | ||
spacing: env.opts.spacing, | ||
}; | ||
return plugin.print(value, print, indent, opts, colors); | ||
return plugin.print(value, print, indent, opts, colors); | ||
} | ||
@@ -575,3 +587,5 @@ | ||
if (opts.min && opts.indent !== undefined && opts.indent !== 0) { | ||
throw new Error('pretty-format: Options "min" and "indent" cannot be used together.'); | ||
throw new Error( | ||
'pretty-format: Options "min" and "indent" cannot be used together.' | ||
); | ||
} | ||
@@ -612,4 +626,10 @@ } | ||
function assertColor(key, val, color) { | ||
if (!color || typeof color.close !== 'string' || typeof color.open !== 'string') { | ||
throw new Error(`pretty-format: Option "theme" has a key "${key}" whose value "${val}" is undefined in ansi-styles.`); | ||
if ( | ||
!color || | ||
typeof color.close !== 'string' || | ||
typeof color.open !== 'string' | ||
) { | ||
throw new Error( | ||
`pretty-format: Option "theme" has a key "${key}" whose value "${val}" is undefined in ansi-styles.` | ||
); | ||
} | ||
@@ -643,3 +663,3 @@ } | ||
let env = { opts, colors }; | ||
let env = {opts, colors}; | ||
let refs = new Refs(); | ||
@@ -651,2 +671,4 @@ let depth = 0; | ||
prettyFormat.printSeries = printSeries; | ||
module.exports = prettyFormat; |
{ | ||
"name": "pretty-format2", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Stringify any value. Better, faster, prettier.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
17658
1%552
3.37%