Skip to content

Commit

Permalink
feat:Support bigint cell content type (#340)
Browse files Browse the repository at this point in the history
* support bigint cell content type

* add bigint tests

* increase ecmaVersion to 2020
  • Loading branch information
ItsNickBarry committed Apr 24, 2024
1 parent 2fee5ae commit 67e853b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 2020,
},
env: {
node: true,
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ declare namespace CliTable3 {
style?: Partial<TableInstanceOptions["style"]>;
}

type CellValue = boolean | number | string | null | undefined;
type CellValue = boolean | number | bigint | string | null | undefined;

interface CellOptions {
content: CellValue;
Expand Down
4 changes: 2 additions & 2 deletions src/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class Cell {
}

setOptions(options) {
if (['boolean', 'number', 'string'].indexOf(typeof options) !== -1) {
if (['boolean', 'number', 'bigint', 'string'].indexOf(typeof options) !== -1) {
options = { content: '' + options };
}
options = options || {};
this.options = options;
let content = options.content;
if (['boolean', 'number', 'string'].indexOf(typeof content) !== -1) {
if (['boolean', 'number', 'bigint', 'string'].indexOf(typeof content) !== -1) {
this.content = String(content);
} else if (!content) {
this.content = this.options.href || '';
Expand Down
10 changes: 10 additions & 0 deletions test/cell-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ describe('Cell', function () {
expect(cell.content).toEqual('0');
});

it('new Cell(1n) will have "1" as content', function () {
let cell = new Cell(1n);
expect(cell.content).toEqual('1');
});

it('new Cell({content: 1n}) will have "1" as content', function () {
let cell = new Cell({ content: 1n });
expect(cell.content).toEqual('1');
});

it('new Cell(false) will have "false" as content', function () {
let cell = new Cell(false);
expect(cell.content).toEqual('false');
Expand Down

0 comments on commit 67e853b

Please sign in to comment.