closest-property
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Closest Property

When given an object and a string, will return the value corresponding to the key that is the closest (according to the levenshtein distance, where case is ignored) to the given string.

It may be useful when trying to access members with small spelling mistakes etc.

Installation

npm install closest-property --save

Examples

const things = {
  house: 'this is a house',
  car: 'this is a car',
  dog: 'this is a dog'
}
 
console.log(closest(things, 'cat')) // this is a car
console.log(closest(things, 'horse')) // this is a house

or

const bestCaseTimeComplexity = {
  BUBBLE_SORT: 'O(n^2)',
  QUICK_SORT: 'O(log(n))'
}
 
const userInput = 'bubblesort'
 
console.log(closest(bestCaseTimeComplexity, userInput)) // 'O(n^2)'

Package Sidebar

Install

npm i closest-property

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

4.13 kB

Total Files

4

Last publish

Collaborators

  • shlappas