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 🙏

© 2024 – Pkg Stats / Ryan Hefner

rolling-search

v1.0.1

Published

filter the array of string/json objects using Rabin Karp algorithm

Downloads

7

Readme

Rolling Search

Rolling search uses the Rabin-Karp algorithm to search the text pattern from the text data.

Installation

  npm install rolling-search

Features

  • Find the objects having the text pattern.
  • Find the specific indices in objects where text pattern matches.
  • Find the match at the particular fields of the object

Usage/Examples

There are different ways to match the pattern this library provides some of them are :

  • searchMatch: This method finds if there is any match of the pattern in the text with provided parameters. Return the promise of the boolean result.
import {searchMatch} from "rolling-search";

const result = await searchMatch({
      text: "Hello World",
      pattern: "world", // lowercase 'w'
      hasCaseSensitive: false,
      hasMatchOnlyWords: false,
    });


// Output result: true 
  • searchMatchPositions: This method find the the indices wherever the pattern match in the text. Return the promise of the indices array (indices are the starting indices from where the pattern match in the text and each doesn't count the collided range)
import {searchMatchPositions} from "rolling-search"

const result = await searchMatchPositions({
      text: "World, Hello World World, worLdworld, World World",
      pattern: "World",
      hasCaseSensitive: false,
      maxMatchCount: 2, // Limit to first 2 matches
      hasMatchOnlyWords: true,
    });

// Output result: [13, 28]
  • RollingSearch: This class contain the searchMatch and searchMatchPositions methods with extra funtionality to search on the specific fields of the objects.
import {RollingSearch} from "../src/searchEngine";

const searchEngine = new RollingSearch();
const array = [{text: "hello worlD", tags:"hello"}, {text: "this is another way World_", tags:"world"}];
const pattern = "world";

const searchEngine = new RollingSearch(array);

const result = await searchEngine.search({
      pattern: pattern,
      hasMatchOnlyWords: true,
      onlyMatchIndices: false,
    });
// Output result = [{text: true, tags:false}, {text: false, tags:true}]
const array = [{text: "hello worlD", tags:"hello"}, {text: "this is another way World_", tags:"world"}];
const pattern = "world";

const searchEngine = new RollingSearch(array);

const result = await searchEngine.search({
      pattern: pattern,
      hasMatchOnlyWords: true,  
      searchFields: ["tags"]   // search on particular tag
    });
// Output result = [1]
const array = [
      {text: "hello worlD woRld World world"},
      {text: "this is another way World_"},
      {text: "this is world of WORLDS_"},
      {text: "world only"},
      {text: "another world"},
    ];
const pattern = "world";

const searchEngine = new RollingSearch(array, 2);  // limit to max two matches in an iteration

async function search() {
    const result = await searchEngine.search({
        pattern: pattern,
        hasMatchOnlyWords: true,
        onlyMatchIndices: false,
      });
      return result;
    }

const result1 = await search();
// Output result1 : [{text: true}, {text: false}]

const result2 = await search();
// Output result2 : [{text: true}, {text:true}]

const result3 = await search();
// Output result3 : [{text: true}]
const array = [
      {text: "hello worlD woRld World world"},
      {text: "this is another way World_"},
    ];
const pattern = "world";

const searchEngine = new RollingSearch(array);

const result = await searchEngine.searchPositions({
    array: array,
    pattern: pattern,
    hasCaseSensitive:false,
    hasMatchOnlyWords: true,
    maxMatchCount: 2,
});
// Output result : [{text: [6, 12]}, {text: []}]

🔗 Links

github