Socket
Socket
Sign inDemoInstall

prettyoutput

Package Overview
Dependencies
3
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 1.2.0

.eslintrc.yml

30

benchmark/benchmark.js
'use strict'
/* eslint-disable no-console */
const util = require('util')

@@ -11,3 +13,3 @@ const columnify = require('columnify')

function runFunction (loopCount, fn) {
function runFunction(loopCount, fn) {
const diffs = []

@@ -28,3 +30,3 @@

return runFunction(loopCount, () => {
prettyoutput(element, {noColor: true, maxDepth: 100})
prettyoutput(element, { noColor: true, maxDepth: 100 })
})

@@ -35,3 +37,3 @@ }

return runFunction(loopCount, () => {
util.inspect(element, {depth: 100})
util.inspect(element, { depth: 100 })
})

@@ -42,3 +44,3 @@ }

return runFunction(loopCount, () => {
prettyjson.render(element, {noColor: true})
prettyjson.render(element, { noColor: true })
})

@@ -58,4 +60,4 @@ }

const benchDesc = _.assign({levels: levels, keys: keysCount, loops: loopCount}, {weigths: prettyWeights(weights)})
console.log(columnify([benchDesc], {columnSplitter: ' | '}), '\n')
const benchDesc = _.assign({ levels: levels, keys: keysCount, loops: loopCount }, { weigths: prettyWeights(weights) })
console.log(columnify([benchDesc], { columnSplitter: ' | ' }), '\n')

@@ -73,8 +75,8 @@ const element = fixture.makeElement(weights, levels, keysCount)

const result = [
_.assign({name: 'prettyoutput'}, stats.prettyStats(prettyOutputStats)),
_.assign({name: 'prettyjson'}, stats.prettyStats(prettyJsonStats)),
_.assign({name: 'util.inspect'}, stats.prettyStats(utilInspectStats))
_.assign({ name: 'prettyoutput' }, stats.prettyStats(prettyOutputStats)),
_.assign({ name: 'prettyjson' }, stats.prettyStats(prettyJsonStats)),
_.assign({ name: 'util.inspect' }, stats.prettyStats(utilInspectStats))
]
console.log(columnify(result, {columnSplitter: ' | '}))
console.log(columnify(result, { columnSplitter: ' | ' }))
console.log('--------------------------------------------------------------------------------------------------------------')

@@ -84,9 +86,9 @@ }

const tests = [
{loops: 100, levels: 3, keys: 20, weights: {serializable: 0.9, array: 0.3, object: 0.5, multilineString: 0.3, error: 0.2}},
{loops: 100, levels: 4, keys: 20, weights: {serializable: 0.9, array: 0.3, object: 0.5, multilineString: 0.3, error: 0.2}},
{loops: 100, levels: 5, keys: 20, weights: {serializable: 0.9, array: 0.3, object: 0.5, multilineString: 0.3, error: 0.2}},
{ loops: 100, levels: 3, keys: 20, weights: { serializable: 0.9, array: 0.3, object: 0.5, multilineString: 0.3, error: 0.2 } },
{ loops: 100, levels: 4, keys: 20, weights: { serializable: 0.9, array: 0.3, object: 0.5, multilineString: 0.3, error: 0.2 } },
{ loops: 100, levels: 5, keys: 20, weights: { serializable: 0.9, array: 0.3, object: 0.5, multilineString: 0.3, error: 0.2 } }
]
_.forEach(tests, (test) => {
_.forEach(tests, test => {
makeBench(test.weights, test.levels, test.keys, test.loops)
})

@@ -9,11 +9,11 @@ 'use strict'

return []
};
}
internals.make.object = () => {
return {}
};
}
internals.make.multilineString = () => {
return 'A multi \nline \nstring'
};
}

@@ -24,3 +24,3 @@ internals.make.serializable = () => {

return set[idx]
};
}

@@ -31,3 +31,3 @@ internals.make.error = () => {

internals.weightedRand = (weigths) => {
internals.weightedRand = weigths => {
const entries = _.toPairs(weigths)

@@ -66,3 +66,3 @@

const types = internals.weightedRands(weights, keysCount)
_.forEach(types, (type) => {
_.forEach(types, type => {
result.push(internals.make[type]())

@@ -94,7 +94,6 @@ })

_.forEach(elementContent, (element) => {
_.forEach(elementContent, element => {
currentElement.push(element)
nextLevel.push(element)
})
} else if (JSON.stringify(currentElement) === '{}') {

@@ -112,5 +111,4 @@ const elementContent = internals.makeLevelObject(weights, keysCount)

exports.makeElement = (weights, levels, keysCount) => {
const topType = internals.weightedRand({array: 0.5, object: 0.5})
const topType = internals.weightedRand({ array: 0.5, object: 0.5 })
const top = internals.make[topType]()

@@ -117,0 +115,0 @@

@@ -5,5 +5,5 @@ 'use strict'

const fixedInt = exports.fixedInt = function (v) {
const fixedInt = (exports.fixedInt = function(v) {
return Math.floor(v)
}
})

@@ -14,3 +14,3 @@ /**

*/
exports.prettyTime = function (time) {
exports.prettyTime = function(time) {
const mn = fixedInt(time / 1e12)

@@ -30,5 +30,5 @@ const s = fixedInt(time / 1e9) - fixedInt(mn * 1e3)

return result
};
}
exports.stats = function (diffs) {
exports.stats = function(diffs) {
let min = diffs[0]

@@ -38,3 +38,3 @@ let max = diffs[0]

_.forEach(diffs, (diff) => {
_.forEach(diffs, diff => {
min = Math.min(min, diff)

@@ -49,3 +49,3 @@ max = Math.max(max, diff)

exports.prettyStats = function (stats) {
exports.prettyStats = function(stats) {
const result = {}

@@ -52,0 +52,0 @@ result.min = exports.prettyTime(stats.min)

const prettyoutput = require('../lib/prettyoutput')
/* eslint-disable no-console */
const data = {

@@ -4,0 +6,0 @@ username: 'kic',

@@ -18,2 +18,3 @@ 'use strict'

* @property {colors} [colors] - input colors
* @property {boolean} [alignKeyValues] - Align key values. Default: true
*/

@@ -32,3 +33,2 @@

/**

@@ -39,3 +39,3 @@ *

*/
internals.parseOptions = (opts) => {
internals.parseOptions = opts => {
opts = opts || {} //eslint-disable-line no-param-reassign

@@ -51,6 +51,7 @@ const optsColors = opts.colors || {}

false: optsColors.false || 'red',
null: optsColors.null || 'grey'
null: optsColors.null || 'grey',
undefined: optsColors.undefined || 'grey'
}
const indentation = (opts.indentationLength) ? utils.indent(opts.indentationLength) : utils.indent(2)
const indentation = opts.indentationLength ? utils.indent(opts.indentationLength) : utils.indent(2)

@@ -60,3 +61,4 @@ return {

maxDepth: opts.maxDepth || 3,
colors: (!opts.noColor) ? colors : null
colors: !opts.noColor ? colors : null,
alignKeyValues: _.isBoolean(opts.alignKeyValues) ? opts.alignKeyValues : true
}

@@ -72,7 +74,7 @@ }

*/
module.exports = function (input, opts, indent) {
module.exports = function(input, opts, indent) {
const options = internals.parseOptions(opts)
const indentation = (indent) ? utils.indent(indent) : ''
const stack = [ { indentation: indentation, depth: 0, input: input } ]
const indentation = indent ? utils.indent(indent) : ''
const stack = [{ indentation: indentation, depth: 0, input: input }]

@@ -91,14 +93,11 @@ let output = ''

output = `${output}${input}`
} else if (depth > options.maxDepth) {
output = `${output}${renderer.renderMaxDepth(options, indentation)}`
} else if (typeInspect.isSerializable(input)) {
output = `${output}${renderer.renderSerializable(input, options, indentation)}`
} else if (typeof input === 'string') { //unserializable string means it's multiline
} else if (typeof input === 'string') {
//unserializable string means it's multiline
output = `${output}${renderer.renderMultilineString(input, options, indentation)}`
} else if (Array.isArray(input)) {
_.forEachRight(input, (value) => {
_.forEachRight(input, value => {
if (typeInspect.isSerializable(value)) {

@@ -121,3 +120,2 @@ const result = renderer.renderSerializableArrayValue(value, options, indentation)

})
} else {

@@ -127,4 +125,4 @@ // Else render an object

const keys = Object.getOwnPropertyNames(input)
const valueColumn = utils.maxLength(keys)
_.forEachRight(keys, (key) => {
const valueColumn = options.alignKeyValues ? utils.maxLength(keys) : 0
_.forEachRight(keys, key => {
const value = input[key]

@@ -144,3 +142,3 @@

if (depth +1 > options.maxDepth) {
if (depth + 1 > options.maxDepth) {
const result = renderer.renderMaxDepthObjectValue(key, valueColumn, options, indentation)

@@ -147,0 +145,0 @@ stack.push({ input: result, noRender: true })

@@ -12,3 +12,3 @@ 'use strict'

*/
exports.inputColor = function (input, colors) {
exports.inputColor = function(input, colors) {
if (!colors) return null

@@ -27,2 +27,4 @@

if (input === undefined) return colors.undefined
if (type === 'number') return colors.number

@@ -33,7 +35,7 @@

exports.indent = function (input, options) {
exports.indent = function(input, options) {
return `${options.indentation}${input}`
}
exports.renderSerializable = function (input, options, indentation) {
exports.renderSerializable = function(input, options, indentation) {
if (Array.isArray(input)) return exports.renderEmptyArray(options, indentation)

@@ -47,3 +49,3 @@

exports.renderMultilineString = function (input, options, indentation) {
exports.renderMultilineString = function(input, options, indentation) {
const color = exports.inputColor(input, options.colors)

@@ -56,7 +58,7 @@ const indentedString = utils.alignString(input, exports.indent(indentation, options))

exports.renderEmptyArray = function (options, indentation) {
exports.renderEmptyArray = function(options, indentation) {
return `${indentation}(empty array)\n`
}
exports.renderObjectKey = function (key, options, indentation) {
exports.renderObjectKey = function(key, options, indentation) {
const colors = options.colors || {}

@@ -68,3 +70,3 @@ const output = `${indentation}${key}: `

exports.renderDash = function (options, indentation) {
exports.renderDash = function(options, indentation) {
const colors = options.colors || {}

@@ -76,7 +78,7 @@ const output = `${indentation}- `

exports.renderMaxDepth = function (options, indentation) {
exports.renderMaxDepth = function(options, indentation) {
return `${indentation}(max depth reached)\n`
}
exports.renderSerializableObjectValue = function (key, value, valueColumn, options, indentation) {
exports.renderSerializableObjectValue = function(key, value, valueColumn, options, indentation) {
const renderedKey = exports.renderObjectKey(key, options, indentation)

@@ -89,3 +91,3 @@ const alignSpaces = _.repeat(' ', valueColumn - key.length)

exports.renderMaxDepthObjectValue = function (key, valueColumn, options, indentation) {
exports.renderMaxDepthObjectValue = function(key, valueColumn, options, indentation) {
const renderedKey = exports.renderObjectKey(key, options, indentation)

@@ -98,3 +100,3 @@ const alignSpaces = _.repeat(' ', valueColumn - key.length)

exports.renderSerializableArrayValue = function (value, options, indentation) {
exports.renderSerializableArrayValue = function(value, options, indentation) {
const renderedDash = exports.renderDash(options, indentation)

@@ -106,3 +108,3 @@ const renderedValue = exports.renderSerializable(value, options, '')

exports.renderMaxDepthArrayValue = function (options, indentation) {
exports.renderMaxDepthArrayValue = function(options, indentation) {
const renderedDash = exports.renderDash(options, indentation)

@@ -114,3 +116,3 @@ const renderedValue = exports.renderMaxDepth(options, '')

exports.renderErrorStack = function (stack, options, indentation) {
exports.renderErrorStack = function(stack, options, indentation) {
const color = exports.inputColor(stack, options.colors)

@@ -123,3 +125,3 @@ const indentedDash = exports.renderDash(options, indentation)

exports.renderObjectErrorStack = function (key, stack, options, indentation) {
exports.renderObjectErrorStack = function(key, stack, options, indentation) {
const renderedKey = exports.renderObjectKey(key, options, indentation)

@@ -126,0 +128,0 @@ const stackIndentation = exports.indent(indentation, options)

@@ -8,10 +8,15 @@ 'use strict'

*/
exports.isSerializable = function (input) {
exports.isSerializable = function(input) {
const type = typeof input
return (type === 'boolean' || type === 'number' ||
input === null || input === undefined || input instanceof Date ||
exports.isSingleLineString(input) || exports.isEmptyArray(input))
return (
type === 'boolean' ||
type === 'number' ||
input === null ||
input instanceof Date ||
input === undefined ||
exports.isSingleLineString(input) ||
exports.isEmptyArray(input)
)
}
/**

@@ -22,4 +27,4 @@ *

*/
exports.isSingleLineString = function (data) {
return (typeof data === 'string' && data.indexOf('\n') === -1)
exports.isSingleLineString = function(data) {
return typeof data === 'string' && data.indexOf('\n') === -1
}

@@ -32,4 +37,4 @@

*/
exports.isEmptyArray = function (input) {
return (Array.isArray(input) && input.length <= 0)
exports.isEmptyArray = function(input) {
return Array.isArray(input) && input.length <= 0
}

@@ -11,3 +11,3 @@ 'use strict'

*/
exports.indent = function indent (spaceCount) {
exports.indent = function indent(spaceCount) {
return _.repeat(' ', spaceCount)

@@ -21,5 +21,5 @@ }

*/
exports.maxLength = function (strings) {
exports.maxLength = function(strings) {
let maxLength = 0
_.forEach(strings, (string) => {
_.forEach(strings, string => {
const length = string.length

@@ -38,3 +38,3 @@ if (length > maxLength) maxLength = length

*/
exports.alignString = function (string, indentation) {
exports.alignString = function(string, indentation) {
const pattern = new RegExp('\n', 'g') //eslint-disable-line no-control-regex

@@ -50,5 +50,7 @@ return `${indentation}${string}`.replace(pattern, `\n${indentation}`)

*/
exports.colorString = function (string, color) {
exports.colorString = function(string, color) {
if (!color) return string
if (string === null) string = 'null'
if (string === undefined) string = 'undefined'
return colorString[color](string)
}

@@ -5,3 +5,3 @@ {

"description": "Librarie to format js/json objects into a YAML-style colored output. Especially useful to pretty print logs. Performant (benchmarks)",
"version": "1.1.1",
"version": "1.2.0",
"homepage": "http://github.com/keepitcool/prettyoutput",

@@ -31,2 +31,4 @@ "keywords": [

"scripts": {
"fmt": "prettier --print-width 140 --tab-width=4 --single-quote --bracket-spacing --no-semi --color --write \"{.,{test,lib,benchmark}/**/}/*.js\"",
"check-fmt": "prettier --print-width 140 --tab-width=4 --single-quote --bracket-spacing --no-semi --list-different \"{.,{test,lib,benchmark}/**/}/*.js\"",
"test": "./node_modules/.bin/mocha --reporter spec",

@@ -43,15 +45,16 @@ "eslint": "./node_modules/.bin/eslint . bin/prettyoutput",

"dependencies": {
"colors": "1.1.2",
"commander": "2.9.0",
"lodash": "4.16.6"
"colors": "1.3.x",
"commander": "2.19.x",
"lodash": "4.17.x"
},
"devDependencies": {
"columnify": "1.5.4",
"eslint": "3.9.1",
"columnify": "1.x.x",
"eslint": "5.x.x",
"istanbul": "0.4.5",
"mocha": "3.1.2",
"nyc": "8.4.0",
"prettyjson": "1.1.3",
"should": "11.1.1"
"mocha": "5.x.x",
"nyc": "13.x.x",
"prettier": "^1.15.3",
"prettyjson": "1.x.x",
"should": "13.x.x"
}
}

@@ -56,11 +56,13 @@ # prettyoutput [![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][coveralls-image]][coveralls-url]

* {colors} [colors] : Output colors. See below
* {boolean} [alignKeyValues] : Align key values. Default: true
Colors are :
* {string} [keys] : Objects keys color. Default: green
* {string} [dash] : Array prefixing dash ("- "). Default: green
* {string} [number] : Numbers color. Default: blue
* {string} [string] : Strings color. Default: no color
* {string} [true] : Boolean value 'true' color. Default: green
* {string} [false] : Boolean value 'false' color. Default: red
* {string} [null] : 'Null' color. Default: grey
* {string} [keys] : Objects keys color. Default: green
* {string} [dash] : Array prefixing dash ("- "). Default: green
* {string} [number] : Numbers color. Default: blue
* {string} [string] : Strings color. Default: no color
* {string} [true] : Boolean value 'true' color. Default: green
* {string} [false] : Boolean value 'false' color. Default: red
* {string} [null] : 'Null' color. Default: grey
* {string} [undefined] : 'Undefined' color. Default: grey

@@ -67,0 +69,0 @@ Example using options :

@@ -8,5 +8,3 @@ 'use strict'

describe('prettyoutput general tests', () => {
it('should output a string exactly equal as the input', () => {
const input = 'This is a string'

@@ -19,3 +17,2 @@ const output = prettyoutput(input)

it('should output a string with indentation', () => {
const input = 'This is a string'

@@ -28,3 +25,2 @@ const output = prettyoutput(input, {}, 4)

it('should output a multiline string with indentation', () => {
const input = 'multiple\nlines'

@@ -37,68 +33,56 @@ const output = prettyoutput(input, {}, 4)

it('should output an array of strings', () => {
const input = ['first string', 'second string']
const output = prettyoutput(input)
output.should.equal([
colors.green('- ') + input[0],
colors.green('- ') + input[1],
''
].join('\n'))
output.should.equal([colors.green('- ') + input[0], colors.green('- ') + input[1], ''].join('\n'))
})
it('should output an array of arrays', () => {
const input = ['first string', ['nested 1', 'nested 2'], 'second string']
const output = prettyoutput(input)
output.should.equal([
colors.green('- ') + input[0],
colors.green('- '),
colors.green(' - ') + input[1][0],
colors.green(' - ') + input[1][1],
colors.green('- ') + input[2],
''
].join('\n'))
output.should.equal(
[
colors.green('- ') + input[0],
colors.green('- '),
colors.green(' - ') + input[1][0],
colors.green(' - ') + input[1][1],
colors.green('- ') + input[2],
''
].join('\n')
)
})
it('should output a hash of strings', () => {
const input = { param1: 'first string', param2: 'second string' }
const output = prettyoutput(input)
output.should.equal([
`${colors.green('param1: ')}first string`,
`${colors.green('param2: ')}second string`,
''
].join('\n'))
output.should.equal([`${colors.green('param1: ')}first string`, `${colors.green('param2: ')}second string`, ''].join('\n'))
})
it('should output a hash of hashes', () => {
const input = { firstParam: { subparam: 'first string', subparam2: 'another string' }, secondParam: 'second string' }
const output = prettyoutput(input)
output.should.equal([
colors.green('firstParam: '),
`${colors.green(' subparam: ')} first string`,
`${colors.green(' subparam2: ')}another string`,
`${colors.green('secondParam: ')}second string`,
''
].join('\n'))
output.should.equal(
[
colors.green('firstParam: '),
`${colors.green(' subparam: ')} first string`,
`${colors.green(' subparam2: ')}another string`,
`${colors.green('secondParam: ')}second string`,
''
].join('\n')
)
})
it('should indent correctly the hashes keys', () => {
const input = { veryLargeParam: 'first string', param: 'second string' }
const output = prettyoutput(input)
output.should.equal([
`${colors.green('veryLargeParam: ')}first string`,
`${colors.green('param: ')} second string`,
''
].join('\n'))
output.should.equal(
[`${colors.green('veryLargeParam: ')}first string`, `${colors.green('param: ')} second string`, ''].join('\n')
)
})
it('should output a really nested object', () => {
const input = {

@@ -111,6 +95,8 @@ firstParam: {

secondParam: 'second string',
anArray: [{
param3: 'value',
param10: 'other value'
}],
anArray: [
{
param3: 'value',
param10: 'other value'
}
],
emptyArray: []

@@ -121,18 +107,20 @@ }

output.should.equal([
colors.green('firstParam: '),
`${colors.green(' subparam: ')} first string`,
`${colors.green(' subparam2: ')}another string`,
colors.green(' subparam3: '),
`${colors.green(' - ')}different`,
`${colors.green(' - ')}values`,
`${colors.green(' - ')}in an array`,
`${colors.green('secondParam: ')}second string`,
colors.green('anArray: '),
colors.green(' - '),
`${colors.green(' param3: ')} value`,
`${colors.green(' param10: ')}other value`,
`${colors.green('emptyArray: ')} (empty array)`,
''
].join('\n'))
output.should.equal(
[
colors.green('firstParam: '),
`${colors.green(' subparam: ')} first string`,
`${colors.green(' subparam2: ')}another string`,
colors.green(' subparam3: '),
`${colors.green(' - ')}different`,
`${colors.green(' - ')}values`,
`${colors.green(' - ')}in an array`,
`${colors.green('secondParam: ')}second string`,
colors.green('anArray: '),
colors.green(' - '),
`${colors.green(' param3: ')} value`,
`${colors.green(' param10: ')}other value`,
`${colors.green('emptyArray: ')} (empty array)`,
''
].join('\n')
)
})

@@ -142,9 +130,5 @@

const input = { param1: 'first string', param2: 'second string' }
const output = prettyoutput(input, { colors: { keys: 'blue' }})
const output = prettyoutput(input, { colors: { keys: 'blue' } })
output.should.equal([
`${colors.blue('param1: ')}first string`,
`${colors.blue('param2: ')}second string`,
''
].join('\n'))
output.should.equal([`${colors.blue('param1: ')}first string`, `${colors.blue('param2: ')}second string`, ''].join('\n'))
})

@@ -154,9 +138,5 @@

const input = { param1: 17, param2: 22.3 }
const output = prettyoutput(input, { colors: { number: 'red' }})
const output = prettyoutput(input, { colors: { number: 'red' } })
output.should.equal([
colors.green('param1: ') + colors.red('17'),
colors.green('param2: ') + colors.red('22.3'),
''
].join('\n'))
output.should.equal([colors.green('param1: ') + colors.red('17'), colors.green('param2: ') + colors.red('22.3'), ''].join('\n'))
})

@@ -166,21 +146,16 @@

const input = { paramLong: 'first string', param2: 'second string' }
const output = prettyoutput(input, { colors: { keys: 'rainbow' }})
const output = prettyoutput(input, { colors: { keys: 'rainbow' } })
output.should.equal([
`${colors.rainbow('paramLong: ')}first string`,
`${colors.rainbow('param2: ')} second string`,
''
].join('\n'))
output.should.equal(
[`${colors.rainbow('paramLong: ')}first string`, `${colors.rainbow('param2: ')} second string`, ''].join('\n')
)
})
it('should allow to configure the default indentation', () => {
const input = { param: ['first string', 'second string']}
const input = { param: ['first string', 'second string'] }
const output = prettyoutput(input, { indentationLength: 4 })
output.should.equal([
colors.green('param: '),
`${colors.green(' - ')}first string`,
`${colors.green(' - ')}second string`,
''
].join('\n'))
output.should.equal(
[colors.green('param: '), `${colors.green(' - ')}first string`, `${colors.green(' - ')}second string`, ''].join('\n')
)
})

@@ -192,6 +167,3 @@

output.should.equal([
'(empty array)',
''
].join('\n'))
output.should.equal(['(empty array)', ''].join('\n'))
})

@@ -201,25 +173,18 @@

const input = { param1: 'first string', param2: 'second string' }
const output = prettyoutput(input, { colors: { keys: 'blue', string: 'red' }})
const output = prettyoutput(input, { colors: { keys: 'blue', string: 'red' } })
output.should.equal([
colors.blue('param1: ') + colors.red('first string'),
colors.blue('param2: ') + colors.red('second string'),
''
].join('\n'))
output.should.equal(
[colors.blue('param1: ') + colors.red('first string'), colors.blue('param2: ') + colors.red('second string'), ''].join('\n')
)
})
it('should allow to not use colors', () => {
const input = { param1: 'first string', param2: ['second string']}
const input = { param1: 'first string', param2: ['second string'] }
const output = prettyoutput(input, { noColor: true })
output.should.equal([
'param1: first string',
'param2: ',
' - second string',
''
].join('\n'))
output.should.equal(['param1: first string', 'param2: ', ' - second string', ''].join('\n'))
})
it('should not print an object prototype', () => {
const Input = function () {
const Input = function() {
this.param1 = 'first string'

@@ -232,8 +197,11 @@ this.param2 = 'second string'

output.should.equal([
`${colors.green('param1: ')}first string`,
`${colors.green('param2: ')}second string`,
''
].join('\n'))
output.should.equal([`${colors.green('param1: ')}first string`, `${colors.green('param2: ')}second string`, ''].join('\n'))
})
it('should allow turning off aligning hash key values', () => {
const input = { veryLargeParam: 'first string', param: 'second string' }
const output = prettyoutput(input, { alignKeyValues: false })
output.should.equal([`${colors.green('veryLargeParam: ')}first string`, `${colors.green('param: ')}second string`, ''].join('\n'))
})
})

@@ -268,2 +236,9 @@

it('should print undefined correctly ', () => {
const input = undefined
const output = prettyoutput(input, {}, 4)
output.should.equal(` ${colors.grey('undefined')}\n`)
})
it('should print an Error correctly ', () => {

@@ -275,9 +250,11 @@ Error.stackTraceLimit = 1

output.should.equal([
colors.green(' stack: '),
colors.green(' - ') + stack[0],
colors.green(' - ') + stack[1],
`${colors.green(' message: ')}foo`,
''
].join('\n'))
output.should.equal(
[
colors.green(' stack: '),
colors.green(' - ') + stack[0],
colors.green(' - ') + stack[1],
`${colors.green(' message: ')}foo`,
''
].join('\n')
)
})

@@ -287,13 +264,15 @@

const dt = new Date()
const output = prettyoutput([ 'a', 3, null, true, false, dt])
const output = prettyoutput(['a', 3, null, true, false, dt])
output.should.equal([
`${colors.green('- ')}a`,
colors.green('- ') + colors.blue('3'),
colors.green('- ') + colors.grey('null'),
colors.green('- ') + colors.green('true'),
colors.green('- ') + colors.red('false'),
colors.green('- ') + dt,
''
].join('\n'))
output.should.equal(
[
`${colors.green('- ')}a`,
colors.green('- ') + colors.blue('3'),
colors.green('- ') + colors.grey('null'),
colors.green('- ') + colors.green('true'),
colors.green('- ') + colors.red('false'),
colors.green('- ') + dt,
''
].join('\n')
)
})

@@ -320,8 +299,4 @@

output.should.equal([
colors.green(' dt1: ') + dt1.toString(),
colors.green(' dt2: ') + dt2.toString(),
''
].join('\n'))
output.should.equal([colors.green(' dt1: ') + dt1.toString(), colors.green(' dt2: ') + dt2.toString(), ''].join('\n'))
})
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc