Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

match-sorter

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

match-sorter

Simple, expected, and deterministic best-match sorting of an array in JavaScript

  • 1.7.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.2M
increased by11.08%
Maintainers
1
Weekly downloads
 
Created

What is match-sorter?

The match-sorter npm package is a simple, expected, and deterministic best-match sorting of an array in JavaScript. It's used to filter and sort lists of strings or objects by best match against a given query.

What are match-sorter's main functionalities?

Simple string matching

This feature allows you to sort an array of strings by matching against a single query string. It returns the items that match the query, ordered by best match.

import matchSorter from 'match-sorter';
const fruits = ['apple', 'orange', 'grape', 'banana'];
const sortedFruits = matchSorter(fruits, 'ap');
// sortedFruits will be ['apple', 'grape']

Object array matching

This feature allows you to sort an array of objects by matching against a query string on specified object keys. It returns the objects that match the query, ordered by best match.

import matchSorter from 'match-sorter';
const items = [{name: 'apple'}, {name: 'orange'}, {name: 'grape'}, {name: 'banana'}];
const sortedItems = matchSorter(items, 'ap', {keys: ['name']});
// sortedItems will be [{name: 'apple'}, {name: 'grape'}]

Custom ranking strategies

This feature allows you to customize the ranking strategy used for sorting. You can specify the order of ranking methods to tailor the sorting to your needs.

import matchSorter, {rankings} from 'match-sorter';
const books = ['The Hobbit', 'Game of Thrones', 'Curious George'];
const sortedBooks = matchSorter(books, 'th', {rankings: [rankings.STARTS_WITH, rankings.EQUAL, rankings.CONTAINS]});
// sortedBooks will be ['The Hobbit', 'Game of Thrones']

Other packages similar to match-sorter

FAQs

Package last updated on 08 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc