kentcdodds / match-sorter

Simple, expected, and deterministic best-match sorting of an array in JavaScript
https://npm.im/match-sorter
MIT License
3.73k stars 129 forks source link

Allow readonly arrays as inputs #129

Closed diesieben07 closed 3 years ago

diesieben07 commented 3 years ago

What: The items parameter of matchSorter as well as the keys option are being changed to ReadonlyArray from a plain Array. This more closely represents the contract of the function, as it does not modify these arrays. Fixes #128.

Why: Even though matchSorter does not modify its input array, it cannot be called with a value of type ReadonlyArray:

const input: readonly string[] = ['foo', 'bar', 'baz'];
matchSorter(input, 'f'); // does not compile

How: The required changes are simple: The input types are changed to ReadyonlyArray. This is not a breaking change, as Array is a subtype of ReadonlyArray in typescript, so "normal arrays" can be passed in like before.

Checklist:

codecov[bot] commented 3 years ago

Codecov Report

Merging #129 (3a49b43) into main (fba154b) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #129   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          163       163           
  Branches        39        39           
=========================================
  Hits           163       163           
Impacted Files Coverage Δ
src/index.ts 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update fba154b...3a49b43. Read the comment docs.

kentcdodds commented 3 years ago

@all-contributors please add @diesieben07 for code

allcontributors[bot] commented 3 years ago

@kentcdodds

I've put up a pull request to add @diesieben07! :tada:

github-actions[bot] commented 3 years ago

:tada: This PR is included in version 6.3.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: