Skip to content

Commit

Permalink
Factor @75lb/deepmerge out of the project. Fixes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
75lb committed Jul 31, 2024
1 parent ef39f3a commit ee28d6d
Show file tree
Hide file tree
Showing 9 changed files with 574 additions and 1,692 deletions.
724 changes: 21 additions & 703 deletions dist/index.cjs

Large diffs are not rendered by default.

724 changes: 21 additions & 703 deletions dist/index.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/computed-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ const germanNumber = new Intl.NumberFormat('de-DE', { notation: 'compact', maxim
}
})
})
const table = new Table(proxiedRows, { maxWidth: 60})
const table = new Table(proxiedRows, { maxWidth: 60 })
console.log(table.toString())
}
1 change: 0 additions & 1 deletion example/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ <h2>Computed values</h2>
"imports": {
"table-layout": "../../index.js",
"wordwrapjs": "/node_modules/wordwrapjs/index.js",
"@75lb/deep-merge": "/node_modules/@75lb/deep-merge/dist/index.mjs",
"array-back": "/node_modules/array-back/index.js",
"typical": "/node_modules/typical/index.js"
}
Expand Down
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import Rows from './lib/rows.js'
import Columns from './lib/columns.js'
import wrap from 'wordwrapjs'
import deepMerge from '@75lb/deep-merge'
import Cell from './lib/cell.js'
import arrayify from 'array-back'
import * as ansi from './lib/ansi.js'
import { removeEmptyColumns, getLongestWord, getLongestArray, padCell } from './lib/util.js'
import { removeEmptyColumns, getLongestWord, getLongestArray, padCell, applyDefaultValues } from './lib/util.js'

/**
* @module table-layout
Expand Down Expand Up @@ -41,7 +40,7 @@ class Table {
columns: [],
eol: '\n'
}
this.options = deepMerge(defaults, options)
this.options = applyDefaultValues(options, defaults)
this.rows = null
this.columns = null
this.load(data)
Expand Down
18 changes: 17 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,20 @@ function removeEmptyColumns (data) {
})
}

export { getLongestArray, padCell, getLongestWord, removeEmptyColumns }
function applyDefaultValues (options = {}, defaults = {}) {
/* Take a shallow copy of the supplied options */
const result = Object.assign({}, options)
/* Apply default values as required */
if (typeof result.padding === 'object') {
if (result.padding.left === undefined) result.padding.left = defaults.padding.left
if (result.padding.right === undefined) result.padding.right = defaults.padding.right
} else {
result.padding = defaults.padding
}
if (result.maxWidth === undefined) result.maxWidth = defaults.maxWidth
if (result.columns === undefined) result.columns = defaults.columns
if (result.eol === undefined) result.eol = defaults.eol
return result
}

export { getLongestArray, padCell, getLongestWord, removeEmptyColumns, applyDefaultValues }
Loading

0 comments on commit ee28d6d

Please sign in to comment.