Skip to content

v1.4.0 — extract() list helper (top N matches with threshold + optional details)

Choose a tag to compare

@Tfoucher5 Tfoucher5 released this 22 Apr 13:34
· 98 commits to master since this release

✨ Highlights

This release adds a new list utility: extract().

extract() is the “top matches” helper for list workflows:

rank → filter (threshold) → limit (top N)

It is designed to be simple by default, with optional detailed output when needed.


✅ Added: extract()

extract() compares an input string against a list of candidates and returns the top N matches.

Simple by default (values only)

By default, it returns a string[]:

import { extract } from 'guess-rater'

const results = extract('hello', ['hello', 'world'], {
  threshold: 90,
  limit: 5
})

console.log(results) // ['hello']

Detailed on demand

If you need scores and indices, request entries:

const results = extract('hello', ['hello', 'world'], {
  threshold: 90,
  limit: 5,
  return: 'entries'
})

// [{ value, score, index }, ...]

Explain output (debug/tuning)

Explain details are available when using return: 'entries':

const results = extract('hello', ['hello', 'world'], {
  threshold: 90,
  limit: 5,
  return: 'entries',
  explain: true
})

// Each entry includes normalized strings + breakdown (like rate(..., { explain:true }))

Notes:

  • explain is ignored when using the default return: 'values' (values-only mode).
  • No behavior changes to existing functions.

📚 Documentation

  • Added a new API page documenting extract()
  • Updated the exports list and navigation

🧪 Tests & quality

  • Added unit tests covering:
    • default values-only return (string[])
    • limit handling (limit)
    • detailed entries return ({ value, score, index }[])
    • explain output behavior

🔄 Compatibility

  • No breaking changes
  • Backward compatible
  • Existing behavior remains unchanged unless you call extract()