Giter Site home page Giter Site logo

ascii-table's People

Contributors

coders-kitchen avatar fokkezb avatar kelsadita avatar sorensen avatar zephod avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ascii-table's Issues

Remove the concept of heading in favour of a break

There is no need of having the entire concept of heading.

setHeading(heading, [...])
setHeadingAlign(direction)
setHeadingAlignLeft()
setHeadingAlignCenter()

CLI is non-interactive, therefore differentiating between a header and a regular row does not have value, i.e. user can set headings using a regular row at the beginning of the table.

Instead, I propose that a new method addBreak is added, that would generate that line that separates the main content from the header.

How to align heading?

Is it currently possible to align the heading? I personally, would almost always want the headings aligned to the left, not the center. If it's not currently possible, would you consider adding an such an option?

I did try .setAlign(0, AsciiTable.LEFT), but that didn't seem to work. Otherwise, working as expected.

Cool library. Thanks for your work : )

Example d.ts code for Typescript

I love this project, but for Typescript I have to write it myself every time. Here is a sample code for those looking for d.ts for Typescript.

declare module 'ascii-table' {
  export default class AsciiTable {
    constructor(title?: string);

    setTitle(title: string): void;
    setHeading(...headings: string[]): void;
    addRow(...values: string[]): void;
    addRow(row: string[]): void;
    addRow(row: Record<string, string>): void;
    addRow(row: string[], truncate: boolean): void;
    addRow(row: Record<string, string>, truncate: boolean): void;
    setAlign(column: number, alignment: 'left' | 'center' | 'right'): void;
    setAlign(alignments: ('left' | 'center' | 'right')[]): void;
    setJustify(column: number, justify: boolean): void;
    setJustify(justify: boolean[]): void;
    setChars(chars: Record<string, string>): void;
    setStyle(style: 'default' | 'fat' | 'thin' | 'double' | 'round' | 'single'): void;
    setBorder(border: boolean): void;
    setTruncate(truncate: boolean): void;
    setMaxColWidth(maxWidth: number): void;
    setMinColWidth(minWidth: number): void;
    setColWidth(column: number, width: number): void;
    setColWidths(widths: number[]): void;
    setDefaultColWidth(width: number): void;
    setDefaultAlignment(alignment: 'left' | 'center' | 'right'): void;
    setDefaultJustify(justify: boolean): void;
    setDefaultTruncate(truncate: boolean): void;
    setDefaultMaxColWidth(maxWidth: number): void;
    setDefaultMinColWidth(minWidth: number): void;
    setDefaultStyle(style: 'default' | 'fat' | 'thin' | 'double' | 'round' | 'single'): void;
    setDefaultBorder(border: boolean): void;
    setDefaultChars(chars: Record<string, string>): void;
    toString(): string;
  }
}

max number of columns

It appears I am hitting a max number of columns issues, could it be that there is a max of 11 columns?

Prepend whitespace before each line for Markdown code block?

Would it be possible to add an option to prepend whitespace before each line?

The use case for this is to create a Markdown code block. In my case, I'm trying to create a Hubot script to insert an ASCII table into a Flowdock chat, using ascii-table.

Flowdock can create a code block (which will use mono-spaced font), however, each line needs to be pre-pended with four space characters. Stackoverflow also uses a similar system (four spaces), as does Github.

Is it possible to add an option to allow you to pad the beginning each line with spaces? E.g.

.----------------.
|    A Title     |
|----------------|
|   | Name | Age |
|---|------|-----|
| 1 | Bob  |  52 |
| 2 | John |  34 |
| 3 | Jim  |  83 |
'----------------'

Ok, the above will probably render as a code block, lol, but you get what I mean. Four spaces at the beginning of each line?

instance.removeBorder() also removes inner border

The readme example includes a ---- style border below the header for .removeBorder(), but when I tried it, it seems to be removed as well:

> console.log(new (require('ascii-table'))().setHeading('a', 'b').addRow(1, 2).removeBorder().toString())
  a   b

  1   2

global 'this' may not always be available, leading to breakage

In your last line, you pass 'this' context to a self-calling function. 'this' later gets used to append AsciiTable class to it. Normally, 'this' references the window object. Depending on how you load the script, however, 'this' could be undefined. One example is if you load the script via an eval. My solution was to change .call(this) to .call(window), I suggest a similar fix for the version in this repo, or something like .call(window || global) if it needs to work in node.

Wide heading pushing out right boundary character by itself

Hi, when I put in a heading that is longer than the width of the column headers and/or row data the character to the right of the heading gets pushed out like below resulting in an uneven right border.

image

If I make one of the column headers one or more characters wider, it fixes it like ...

image

Shouldn't it of expanded all the right boundary characters by one in first screenshot above so they all align? If not, is there a way to add a line break in the heading so it does not go so wide or an alternative solution other than unnecessarily widening the column header names or row data?

Headings do not align with the content

  Line   Column   Type                Message                                                                       Rule ID

     1        1   warning   Definition for rule 'react/no-unused-vars' was not found                      react/no-unused-vars
    15        5   error     Variables within the same declaration block should be sorted alphabetically   sort-vars
    17        5   error     Variables within the same declaration block should be sorted alphabetically   sort-vars
    18        5   error     Variables within the same declaration block should be sorted alphabetically   sort-vars
    35        9   error     Variables within the same declaration block should be sorted alphabetically   sort-vars
    35        9   error     Variable 'appendPaths' should not be initialized on declaration               init-declarations

The code:

table.setHeading([`Line`, `Column`, `Type`, `Message`, `Rule ID`]);
table.setHeadingAlignLeft();
table.addRow([
    message.line || 0,
    message.column || 0,
    messageType,
    message.message.replace(/\.$/, ``),
    chalk.gray(message.ruleId || ``)
]);

I'd expect headings to align with the beginning of the text in each column.

Row separators

Is there any way to add row separators? Like separator after heading.

Remove alignLeft, alignCenter, alignRight, alignAuto

Remove:

alignLeft(val, len, [pad])
alignCenter(val, len, [pad])
alignRight(val, len, [pad])
alignAuto(val, len, [pad])
setAlignLeft(idx)
setAlignCenter(idx)
setAlignRight(idx)
setTitleAlignLeft()
setTitleAlignCenter()
setTitleAlignRight()
setHeadingAlignLeft()
setHeadingAlignCenter()
setHeadingAlignRight()

None of the methods provide value to the package. It only makes the API looks less approachable and use less predictable. Removing these methods in favour of keeping just align, setAlign, and setHeadingAlign would reduce the complexity of the API.

Cannot call setTitle of undefined

Hi I'm getting the following error when running some example code:

    .setTitle(obj.title)
     ^
TypeError: Cannot call method 'setTitle' of undefined
    at AsciiTable.parse.AsciiTable.fromJSON (/Users/jvallelonga/src/sandbox/stick-tools/query-viewer/node_modules/ascii-table/ascii-table.js:450:6)
    at AsciiTable.reset.AsciiTable.clear (/Users/jvallelonga/src/sandbox/stick-tools/query-viewer/node_modules/ascii-table/ascii-table.js:204:10)
    at new AsciiTable (/Users/jvallelonga/src/sandbox/stick-tools/query-viewer/node_modules/ascii-table/ascii-table.js:27:8)
    at Function.AsciiTable.factory (/Users/jvallelonga/src/sandbox/stick-tools/query-viewer/node_modules/ascii-table/ascii-table.js:56:10)

The example code that I'm running is:

var table = AsciiTable.factory({
  title: 'Title'
, heading: [ 'id', 'name' ]
, rows: [ 
    [ 1, 'Bob' ]
  , [ 2, 'Steve' ] 
  ] 
})

I haven't taken the time to understand your codebase fully, but I think it's because the clear method isn't returning this. Maybe adding return this after line 205 of ascii-table.js would fix it. I can make a pull request if this is the correct fix for the issue. Just wanted to get your input first.

Title going out of the table

If the table's title width is bigger than the rest of the content's width, the title goes out of the table.
e.g.:

.-----------.
| == CONDITIONNEL == |
|-----------|
|  Présent  |
|-----------|
| verrais   |
| verrais   |
| verrait   |
| verrions  |
| verriez   |
| verraient |
'-----------'

support question => indent entire table

I looked for indent options and searched for indent in the repo, doesn't seem to be an option.

screenshot 2016-04-07 16 20 45

I'd like to indent the table pictured, is there a way to move it over to the right?

let me know thanks!

NPM warn

WARN engine [email protected]: wanted: {"node":"0.x"} (current: {"node":"5.4.1","npm":"3.3.12"})

can you update this? thanks :)

RangeError: Invalid array length on ascii-table.js line 95

Hi,

I'm using phantomas, which uses ascii-table.js. On certain runs of that tool I was getting this error:

usr/local/lib/node_modules/phantomas/node_modules/ascii-table/ascii-table.js:95
  return str + Array(len + 1 - str.length).join(pad)
               ^
RangeError: Invalid array length
    at Function.AsciiTable.alignLeft (/usr/local/lib/node_modules/phantomas/node_modules/ascii-table/ascii-table.js:95:16)
    at Function.AsciiTable.align (/usr/local/lib/node_modules/phantomas/node_modules/ascii-table/ascii-table.js:70:50)
    at AsciiTable._renderTitle (/usr/local/lib/node_modules/phantomas/node_modules/ascii-table/ascii-table.js:552:24)
    at AsciiTable.render.AsciiTable.valueOf.AsciiTable.toString (/usr/local/lib/node_modules/phantomas/node_modules/ascii-table/ascii-table.js:503:20)
    at formatMultipleRunResults (/usr/local/lib/node_modules/phantomas/reporters/plain.js:142:16)
    at Object.render (/usr/local/lib/node_modules/phantomas/reporters/plain.js:152:12)
    at Object.render (/usr/local/lib/node_modules/phantomas/core/reporter.js:64:20)
    at /usr/local/lib/node_modules/phantomas/bin/phantomas.js:191:19
    at /usr/local/lib/node_modules/phantomas/node_modules/async/lib/async.js:254:17
    at /usr/local/lib/node_modules/phantomas/node_modules/async/lib/async.js:157:25

After a little debugging, I found that the problem was that a negative array length was being passed to the Array constructor here:

https://github.com/sorensen/ascii-table/blob/master/ascii-table.js#L90

I solved it by checking to make sure the calculated length is greater than 0:

if ((len + 1 - str.length) > 0) {
  return str + Array(len + 1 - str.length).join(pad)
}
else {
  return str;
}

Makes for an uneven table, but at least it doesn't break. Sorry I didn't make a proper PR.

duplicate object key in .jshintrc

unused is defined twice.
{
"node": true
, "asi": true
, "nonstandard": true
, "strict": false
, "smarttabs": true
, "maxlen": 1800
, "newcap": false
, "expr": true
, "undef": true
, "unused": false
, "onecase": true
, "laxcomma": true
, "laxbreak": true
, "white": false
, "shadow": true
, "proto": true
, "loopfunc": true
, "boss": true
, "validthis": true
, "unused": "vars"
, "globals": {
"describe": false
, "it": false
}
}

Heading not respected when there are fewer columns

Consider the following use case:

  • heading has 3 items
  • the only row in the table has 1 item
    In this case the table will only render a single heading and a single column, ignoring the remaining headings rather than rendering the other 2 columns as blank

Now consider the case when there are more than one row and some rows are not filled to 3 items. In this case the omitted columns will be rendered as empty rather than being dropped for rows that do have them.

Case 2 and case 1 contradict each other in terms of behavior. Case 2 makes sense to me, case 1 does not. If the heading is specified, I expect the column to render. Could this edge case be fixed? Or, perhaps if this behavior is desired in some cases add a flag to the table that tells it whether to render or omit empty columns.

array input instead of arguments?

For my application I'd like to be able to pass arrays of headers and rows in.
I thought I could pull this off by using the "apply" method... but it doesn't work for me.

So I want to say:
var heading = ['a', 'b', 'c']
var row = [1, 2, 3...]
table.setHeading(heading)
table.addRow(row)

but it doesn't like arrays as an input. So I tried "apply" like this:
table.setHeading.apply(this, heading)
table.addRow.apply(this, row)

but no dice, get an error with both. Is there a way I can do this?

Support question, handling spillover

With a table like so:

screenshot 2016-04-09 17 46 44

How can I handle spillover in the "Notes" column. Can this lib handle when a row is more than 1 line?
I just tried some newline chars and yeah it doesn't work. Any advice on how to handle rows that have multiple lines of text? Thanks for your help!

Using colors

Hi, I tried to use colors (I used gulp util which is using chalk) and it misaligned the values. I guess it's because of the extra characters for the color or style. There's probably not a fix for this but figure I ask.

Great job by the way, real easy to use.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.