Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

as-table

Package Overview
Dependencies
Maintainers
2
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

as-table - npm Package Compare versions

Comparing version 1.0.9 to 1.0.10

14

as-table.js

@@ -7,2 +7,4 @@ "use strict";

limit = (s, n) => s && ((s.length <= n) ? s : (s.substr (0, n - 1) + '…')),
asColumns = (rows, cfg_) => {

@@ -37,3 +39,3 @@

relativeWidths = maxWidths.map (w => w / totalWidth),
maxTotalWidth = cfg.maxTotalWidth - (cfg.delimiter.length * maxWidths.length),
maxTotalWidth = cfg.maxTotalWidth - (cfg.delimiter.length * (maxWidths.length - 1)),
excessWidth = Math.max (0, totalWidth - maxTotalWidth),

@@ -52,3 +54,3 @@ computedWidths = zip ([cfg.minColumnWidths, maxWidths, relativeWidths],

? (str + ' '.repeat (w))
: (str.slice (0, w))).join (cfg.delimiter))
: (limit (str, str.length + w))).join (cfg.delimiter))
}

@@ -66,5 +68,5 @@ },

const colNames = [...new Set (arr.map (O.keys).reduce ((a, b) => [...a, ...b], []))],
columns = [colNames, ...arr.map (o => colNames.map (key => o[key]))],
lines = asColumns (columns, O.assign ({ minColumnWidths: colNames.map (n => n.length) }, cfg))
const colNames = [...new Set ([].concat (...arr.map (O.keys)))],
columns = [colNames, ...arr.map (o => colNames.map (key => o[key]))],
lines = asColumns (columns, cfg)

@@ -78,4 +80,4 @@ return [lines[0], '-'.repeat (lines[0].length), ...lines.slice (1)].join ('\n')

module.exports = asTable ({ maxTotalWidth: 120 })
module.exports = asTable ({ maxTotalWidth: Number.MAX_SAFE_INTEGER })
{
"name": "as-table",
"version": "1.0.9",
"version": "1.0.10",
"description": "A simple function to print objects as ASCII tables",

@@ -5,0 +5,0 @@ "main": "as-table.js",

@@ -20,7 +20,7 @@ "use strict";

assert.equal (asTable.configure ({ maxTotalWidth: 25, delimiter: ' | ' }) (testData),
assert.equal (asTable.configure ({ maxTotalWidth: 22, delimiter: ' | ' }) (testData),
'qwe | 12345 | zxcv\n' +
'qwert | 12 | zxcv\n' +
'qwert | 12345 | z ')
'qwe | 1234… | zxc…\n' +
'qwer… | 12 | zxc…\n' +
'qwer… | 1234… | z ')
})

@@ -42,4 +42,19 @@

' null 44 ')
}),
})
it ('maxTotalWidth correctly handles object field names', () => {
assert.equal (
asTable.configure ({ maxTotalWidth: 15 }) ([{
'0123456789': '0123456789',
'abcdefxyzw': 'abcdefxyzw' }]),
'01234… abcde…\n' +
'--------------\n' +
'01234… abcde…'
)
})
it ('everything renders as singleline', () => {

@@ -46,0 +61,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc