From 0168fcb994ce67e20fc3f54bad4166bbe78f595a Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Tue, 4 Oct 2022 22:39:18 -0700 Subject: [PATCH] Fix bug caused by mutating default options --- src/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 938188f..f25289f 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,7 @@ import path from 'path'; import fs from 'fs'; import { createCanvas } from 'canvas'; -const defaultOptions = { +const defaultOptions = Object.freeze({ cellWidth: 100, cellHeight: 40, offsetLeft: 8, @@ -13,10 +13,10 @@ const defaultOptions = { paddingVertical: 0, paddingHorizontal: 0, backgroundColor: '#ffffff', -}; +}); const TableRenderer = (options = {}) => { - const { cellWidth, cellHeight, offsetLeft, offsetTop, spacing, titleSpacing, fontFamily, paddingHorizontal, paddingVertical, backgroundColor } = Object.assign(defaultOptions, options); + const { cellWidth, cellHeight, offsetLeft, offsetTop, spacing, titleSpacing, fontFamily, paddingHorizontal, paddingVertical, backgroundColor } = {...defaultOptions, ...options}; const getTableWidth = (columns) => { return columns?.reduce((sum, col) => sum + (col === '|' ? 1 : col.width ?? cellWidth), 0) ?? cellWidth;