@@ -84,6 +84,29 @@ function matchSorter<ItemType = string>(
8484 value : string ,
8585 options : MatchSorterOptions < ItemType > = { } ,
8686) : Array < ItemType > {
87+ return getRankedItems ( items , value , options ) . map ( ( { item} ) => item )
88+ }
89+
90+ /**
91+ * Takes an array of items and a value and returns ranked items with metadata attached
92+ * @param {Array } items - the items to sort
93+ * @param {String } value - the value to use for ranking
94+ * @param {Object } options - Some options to configure the sorter
95+ * @return {Array } - the new ranked array
96+ */
97+ function matchSorterWithRankInfo < ItemType = string > (
98+ items : ReadonlyArray < ItemType > ,
99+ value : string ,
100+ options : MatchSorterOptions < ItemType > = { } ,
101+ ) : Array < RankedItem < ItemType > > {
102+ return getRankedItems ( items , value , options )
103+ }
104+
105+ function getRankedItems < ItemType = string > (
106+ items : ReadonlyArray < ItemType > ,
107+ value : string ,
108+ options : MatchSorterOptions < ItemType > ,
109+ ) : Array < RankedItem < ItemType > > {
87110 const {
88111 keys,
89112 threshold = rankings . MATCHES ,
@@ -92,7 +115,7 @@ function matchSorter<ItemType = string>(
92115 matchedItems . sort ( ( a , b ) => sortRankedValues ( a , b , baseSort ) ) ,
93116 } = options
94117 const matchedItems = items . reduce ( reduceItemsToRanked , [ ] )
95- return sorter ( matchedItems ) . map ( ( { item } ) => item )
118+ return sorter ( matchedItems )
96119
97120 function reduceItemsToRanked (
98121 matches : Array < RankedItem < ItemType > > ,
@@ -109,6 +132,7 @@ function matchSorter<ItemType = string>(
109132}
110133
111134matchSorter . rankings = rankings
135+ matchSorterWithRankInfo . rankings = rankings
112136
113137/**
114138 * Gets the highest ranking for value for the given item based on its values for the given keys
@@ -520,14 +544,21 @@ function getKeyAttributes<ItemType>(key: KeyOption<ItemType>): KeyAttributes {
520544 return { ...defaultKeyAttributes , ...key }
521545}
522546
523- export { matchSorter , rankings , defaultBaseSortFn , getItemValues }
547+ export {
548+ matchSorter ,
549+ matchSorterWithRankInfo ,
550+ rankings ,
551+ defaultBaseSortFn ,
552+ getItemValues ,
553+ }
524554
525555export type {
526556 MatchSorterOptions ,
527557 KeyAttributesOptions ,
528558 KeyOption ,
529559 KeyAttributes ,
530560 RankingInfo ,
561+ RankedItem ,
531562 ValueGetterKey ,
532563}
533564
0 commit comments