File: define-columns.js

package info (click to toggle)
node-columnify 1.5.4-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 29,684 kB
  • sloc: makefile: 9
file content (57 lines) | stat: -rw-r--r-- 1,191 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var test = require('tape')
var fs = require('fs')

var columnify =  require('../')

var data = [{
  name: 'module1',
  description: 'some description',
  version: '0.0.1',
}, {
  name: 'module2',
  description: 'another description',
  version: '0.2.0',
}]

test('removes description column', function(t) {
  t.plan(2)
  var result = columnify(data, {
    columns: ['name', 'version'],
  })

  var columnHeaders = result.split('\n')[0]
  t.deepEqual(columnHeaders.split(/\s+/), [
    "NAME",
    "VERSION"
  ])
  t.ok(!(/description/gi.test(result)))
})

test('include == columns', function(t) {
  t.plan(2)
  var result = columnify(data, {
    include: ['name', 'version'],
  })

  var columnHeaders = result.split('\n')[0]
  t.deepEqual(columnHeaders.split(/\s+/), [
    "NAME",
    "VERSION"
  ])
  t.ok(!(/description/gi.test(result)))
})

test('columns preferred over include if both supplied', function(t) {
  t.plan(2)
  var result = columnify(data, {
    columns: ['name', 'version'],
    include: ['description'],
  })

  var columnHeaders = result.split('\n')[0]
  t.deepEqual(columnHeaders.split(/\s+/), [
    "NAME",
    "VERSION"
  ])
  t.ok(!(/description/gi.test(result)))
})