best-matcher

v1.0.0
find best matched string in list
best match best-match

best-matcher

find the best matched string amoung a list that starts with the same prefix;

useage

import { getBestMatch } from "best-matcher";

const currentActiveMenu = getBestMatch(location.href, menus, '/')

if the routes follow the hierarchy naming rules, this function will match the most intuitive and logically correct path in the sidemenu.

eg. if current path is /user/list/detail?uid=123, best match will be /user/list amoung the list of ['/user/manage', '/user/list']

npm i best-matcher

Metadata

  • MIT
  • Whatever
  • troy.lty
  • released 3/5/2021

Downloads

Maintainers