From 67e853bdd98ab9e438c15f8ef45e898857997f1d Mon Sep 17 00:00:00 2001 From: Nick Barry Date: Wed, 24 Apr 2024 17:21:12 +0300 Subject: [PATCH] feat:Support bigint cell content type (#340) * support bigint cell content type * add bigint tests * increase ecmaVersion to 2020 --- .eslintrc.js | 2 +- index.d.ts | 2 +- src/cell.js | 4 ++-- test/cell-test.js | 10 ++++++++++ 4 files changed, 14 insertions(+), 4 deletions(-) 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, diff --git a/index.d.ts b/index.d.ts index 09c95b5..8f468ef 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 || ''; 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');