table icon indicating copy to clipboard operation
table copied to clipboard

fix: allow readonly array input for table data

Open bmish opened this issue 1 year ago • 5 comments

This is the minimum set of changes needed to allow a readonly array to be passed as input to the public table() function, in addition to regular arrays (backward compatible).

Some users may prefer to declare their arrays as readonly, or use functions/libraries that return readonly arrays when generating the table data. This change improves compatibility for such users.

It's also generally good practice for us to enforce that we do not modify input parameters.

Potential follow-up changes:

  • There's a public spanningCells option that could be changed to use a readonly array. This would require a minor change to avoid mutating the input array by cloning it first.
  • There are dozens of other private/internal places throughout the codebase where additional readonly array types could be used as a best practice if desired. In some cases, this would require rewriting code to avoid mutating arrays.

References:

  • https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#improvements-for-readonlyarray-and-readonly-tuples
  • https://github.com/wooorm/markdown-table/pull/30

bmish avatar Mar 19 '23 16:03 bmish

Pull Request Test Coverage Report for Build 4461649881

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 3374277795: 0.0%
Covered Lines: 642
Relevant Lines: 642

💛 - Coveralls

coveralls avatar Mar 23 '23 16:03 coveralls

Hi @bmish, thanks for contributing!

So this change is a kind of breaking change, isn't it?

nam-hle avatar Mar 29 '23 15:03 nam-hle

Nope, not a breaking change. It allows read-only arrays but does not require them. It expands the allowed input.

bmish avatar Mar 29 '23 15:03 bmish

Ping? Again, this is not a breaking change.

bmish avatar May 11 '23 15:05 bmish

Ping?

bmish avatar Dec 07 '23 18:12 bmish