import chalk from 'chalk'
import fuzzysort from 'fuzzysort'
const findWord = 'lorem'
const resource = ['lorem ipsum', 'lorei mpsum', 'ipsum dolor', 'ipsum lor', 'losum remip', 'lor', 'loiem iplor']
console.log(
[...fuzzysort.go(findWord, resource.map(a => ({title: a})), { keys: ['title'] })]
.map(a => fuzzysort.highlight(a[0], (m) => chalk.yellow(m)))
.map(b => b.join(''))
.join("\n")
)
Output:
lorem
ipsum
lore
i m
psum
lo
sum rem
ip