npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@themathkoch/leven-search

v1.1.3

Published

A Search library, with integrated threshhold.

Downloads

55

Readme

LEVEN SEARCH

Leven Search is a Search algorithmen used for string based objects, or strings itself.

Installation

To install the package simply write the following in the terminal.


npm i @themathkoch/leven-search

To use the package check that you are using "commonjs" as your package type. Then you can get the module via the following.


const levenSearch = require("@themathkoch/leven-search");

Functions

The package gives the following three functions to work with.

function dist(str1, str2) ~ levenSearch.dist

function pass(input, compare, threshold = 0.5, Leven = false, ...attr) ~ levenSearch.pass

function search(input, data, threshold = 0.5, Leven = false, ...attr) ~ levenSearch.search

The first function calculates the so called levenshtein distance for two strings. This distance describes the number of transformation needed to get to one string to the other. This distance will be calculated in O(nm), where n,m are the respective string lengths.

The second function checks if the input and compare value fits the threshold. There we use the following properties:

| property | datatype | usecase | standardValue | |----------|:-------------:|------:|------:| | input | Obj/String | first Obj/String to Compare |none | | compare | Obj/String | second Obj/String to Compare |none | | threshold | number | threshold which must be exceeded |0.5 | | Leven | bool |true, threshold in [0,∞). false, threshold in [0,1) |false | | attr | Obj[]/String[] |which attr to compare |empty |

This function is in O(nm), with n,m the respectiv lengths of input and compare.

The third function is the search algorithmen to use for in Arrays. There we use the following properties:

| property | datatype | usecase | standardValue | |----------|:-------------:|------:|------:| | input | Obj/String | Obj/STring to search |none | | data | Obj[]/String[] | Dataset to search in |none | | threshold | number | threshold which must be exceeded |0.5 | | Leven | bool |true, threshold in [0,∞). false, threshold in [0,1) |false | | attr | Obj[]/String[] |which attributes to compare to |empty |

In the case, that threshold < 0, the function will return []. In the case of threshold ≥ 1 (to be ignored when Leven = true), the result will be data.

Search value in multiply attributes

Short explanation

Sometimes it is the case, that you want to search one string inside two attr. of an array of obj. e.g. you have an array of obj. with attr. name1, and name2, but all you got is a string called name. You can know search inside both attr. simultaneously via the following input in attr.

let attr = [
    {
        Search: "name",
        In: ["name1","name2"]
    }
]
levenSearch.search(input, data, threshold, leven, ...attr)

Formal structure

let attr = [
    {
        Search: "attr-to-search",
        In: ["attr-to-search-in"]
    },
    ...add as many cond. as you like
]

Exceptions

The pass function throws 2 exceptions when using no string in a search, or missing an attr. in an object.

function TypeException(message) {
    this.message = message;
    this.name = "TypeException";
}

function UndefinedException(message) {
    this.message = message;
    this.name = "UndefinedException";
}

Examples

Here we have 4 short examples of usecases for the package.

1. Example


const levenSearch = require("@themathkoch/leven-search");

let str1 = "OneWord"
let str2 = "ÖneWord"
let str3 = "ThirdWord"

console.log(levenSearch.dist(str1,str2),levenSearch.dist(str2,str3),levenSearch.dist(str1,str3));
//Output 1 5 5

console.log(levenSearch.pass(str1,str2)); //ref. to Functions for the standard values
//Output true
console.log(levenSearch.pass(str2,str3))
//Output false

2. Example


const levenSearch = require("@themathkoch/leven-search");

let input = "Apple";

let data = ["Apple", "Grapple", "Banana", "Appletree", "pple"];

let threshold = 3;

let leven = true;

console.log(levenSearch.search(input, data, threshold, leven));
//Output [ 'Apple', 'Grapple', 'pple' ]

threshold = 0.6;

leven = false

console.log(levenSearch.search(input, data, threshold, leven));
//Output [ 'Apple', 'Grapple', 'Appletree', 'pple' ]

3. Example


const levenSearch = require("@themathkoch/leven-search");

let input = {1: "Apple", 2: "Euro", 3: "Tree"};

let data = [{1: "Grapple", 2: "Dollar", 3: "Forest"},{1: "Grapple", 2: "Eüro", 3: "Tre", 4: "Ignored"}, input];

let threshold = 3;

let leven = true;

console.log(levenSearch.search(input, data, threshold, leven, "1", "2", "3")); //Attribute 4 is ignored
/* Output
    [
        { '1': 'Grapple', '2': 'Eüro', '3': 'Tre' , '4': 'Ignored'},
        { '1': 'Apple', '2': 'Euro', '3': 'Tree' }
    ]
*/

console.log(levenSearch.search(input, data, threshold, leven, "1")); //Use only one attribute
/* Output
    [
        { '1': 'Grapple', '2': 'Dollar', '3': 'Forest' },
        { '1': 'Grapple', '2': 'Eüro', '3': 'Tre', '4': 'Ignored' },
        { '1': 'Apple', '2': 'Euro', '3': 'Tree' }
    ]
*/

4. Example


const levenSearch = require("@themathkoch/leven-search");

let input = {
    1: "Apple",
    2: "Euro",
    3: "Tree"
};

let data = [
    {
        1: "Grapple",
        2: "Dollar",
        3: "Forest"
    }, {
        1: "NooooApple",
        2: "Apple",
        3: "Tre"
    },
    input, {
        1: "NooooApple",
        2: "NoooooApple",
        3: "Tre"
    }
];

let threshold = 3;

let leven = true;

let attr = [
    {
        Search: "1",
        In: ["1"]
    }, {
        Search: "2",
        In: ["2"]
    }, {
        Search: "3",
        In: ["3"]
    }
]

console.log(levenSearch.search(input, data, threshold, leven, ...attr));
/* Output
    [ { '1': 'Apple', '2': 'Euro', '3': 'Tree' } ]
*/

attr = [
    {
        Search: "1",
        In: ["1","2"]
    }
]

console.log(levenSearch.search(input, data, threshold, leven, ...attr));
/* Output
    [
        { '1': 'Grapple', '2': 'Dollar', '3': 'Forest' }, close enough to Grapple
        { '1': 'NooooApple', '2': 'Apple', '3': 'Tre' }, not close enough to NooooApple, but to Apple
        { '1': 'Apple', '2': 'Euro', '3': 'Tree' }, that is just the input itself :)
    ]
    { 1: "NooooApple", 2: "NoooooApple", 3: "Tre"}, did not pass, because both attr. do not fit the distance 
*/