How to use the match-sorter.default function in match-sorter

To help you get started, we’ve selected a few match-sorter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kylart / MalScraper / src / seasons.js View on Github external
const getType = (type, $) => {
  const result = []

  // If TV has been selected, filter New from Continuing.
  const typeString = matchSorter(possibleTypes, type)[0]

  let classToSearch = `.js-seasonal-anime-list-key-${type2Class[typeString]} .seasonal-anime.js-seasonal-anime`
  const typeClass = `.js-seasonal-anime-list-key-${type2Class[typeString]}`

  // If TVNew or TVCon are selected, filter them out to the specific elements on page
  if (typeString.substr(0, 2) === 'TV' && typeString !== 'TV') {
    const tvType = matchSorter(possibleTV, typeString)[0]
    $(typeClass).children('.anime-header').each(function () {
      if ($(this).text() === tvType) {
        classToSearch = $(this).parent().children()
      }
    })
  }

  $(classToSearch).each(function () {
    if (!$(this).hasClass('kids') && !$(this).hasClass('r18')) {
github Kylart / MalScraper / src / info.js View on Github external
.then(async (items) => {
        if (!items.length) {
          resolve(null)
          return
        }
        try {
          const bestMacth = getBestMatch
            ? match(items, name, { keys: ['name'] })[0]
            : items[0]
          const url = bestMacth ? bestMacth.url : items[0].url
          const data = await getInfoFromURL(url)

          data.url = url

          resolve(data)
        } catch (e) {
          /* istanbul ignore next */
          reject(e)
        }
      })
      .catch(/* istanbul ignore next */(err) => reject(err))
github Kylart / MalScraper / src / seasons.js View on Github external
const getType = (type, $) => {
  const result = []

  // If TV has been selected, filter New from Continuing.
  const typeString = matchSorter(possibleTypes, type)[0]

  let classToSearch = `.js-seasonal-anime-list-key-${type2Class[typeString]} .seasonal-anime.js-seasonal-anime`
  const typeClass = `.js-seasonal-anime-list-key-${type2Class[typeString]}`

  // If TVNew or TVCon are selected, filter them out to the specific elements on page
  if (typeString.substr(0, 2) === 'TV' && typeString !== 'TV') {
    const tvType = matchSorter(possibleTV, typeString)[0]
    $(typeClass).children('.anime-header').each(function () {
      if ($(this).text() === tvType) {
        classToSearch = $(this).parent().children()
      }
    })
  }

  $(classToSearch).each(function () {
    if (!$(this).hasClass('kids') && !$(this).hasClass('r18')) {
      const general = $(this).find('div:nth-child(1)')
      const picture = $(this).find('.image').find('img')
      const prod = $(this).find('.prodsrc')
      const info = $(this).find('.information')
      const synopsis = $(this).find('.synopsis')

      result.push({

match-sorter

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

MIT
Latest version published 2 months ago

Package Health Score

91 / 100
Full package analysis