From e8b5512e48402a0cc462de2ef0e614aad25c8a6e Mon Sep 17 00:00:00 2001 From: Nick Barry Date: Mon, 22 Apr 2024 01:19:16 +0400 Subject: [PATCH 1/3] support bigint cell content type --- index.d.ts | 2 +- src/cell.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 77e220a..083cbaa 100644 --- a/index.d.ts +++ b/index.d.ts @@ -46,7 +46,7 @@ declare namespace CliTable3 { style?: Partial; } - type CellValue = boolean | number | string | null | undefined; + type CellValue = boolean | number | bigint | string | null | undefined; interface CellOptions { content: CellValue; diff --git a/src/cell.js b/src/cell.js index 8c3df35..37530bf 100644 --- a/src/cell.js +++ b/src/cell.js @@ -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 || ''; From a711642e7f2b48989b531515fb5ca949c2228635 Mon Sep 17 00:00:00 2001 From: Nick Barry Date: Wed, 24 Apr 2024 00:39:48 +0400 Subject: [PATCH 2/3] add bigint tests --- test/cell-test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/cell-test.js b/test/cell-test.js index ec4c1e3..9baaa1d 100644 --- a/test/cell-test.js +++ b/test/cell-test.js @@ -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'); From b1732a9684199f17dc02d08e96137d5fce0f4f32 Mon Sep 17 00:00:00 2001 From: Nick Barry Date: Wed, 24 Apr 2024 00:40:16 +0400 Subject: [PATCH 3/3] increase ecmaVersion to 2020 --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 86e9a35..f119e5b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,6 +1,6 @@ module.exports = { parserOptions: { - ecmaVersion: 2018, + ecmaVersion: 2020, }, env: { node: true,