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

seek

v0.3.0

Published

search through a bunch of files

Downloads

17

Readme

seek is a function that allows to recursively search through files in a directory. It's perfect for providing a search form on your website if the website does only consist of static files.

seek(directory, query, options, found[, filter[, complete]]);
  • directory is the pathname of a readable directory.

  • query is either a string consisting of the keywords to search for or an array of strings and regular expressions.

  • options is an object that redefines some of the default properties.

    The default options are as follows:

    {
      recursive: true,      // - Recursive file walking. If set to false,
                            //   subdirectories of directory will be ignored.
      caseSensitive: false, // - Case insensitive search
      dotFiles: true,       // - Don't ignore "dot files" like '.gitignore'
      requireAll: true,     // - Require to find all keywords so that a file is
                            //   matched.
      findAll: false,       // - Only the first occurrence of a keyword is
                            //   matched. Set this to true, if you want to match
                            //   all occurrences of a keyword in the file.
      ignoreOrder: true,    // - Ignore the order of the keywords. Use with
                            //   care! Only works with findAll set to false.
      separator: ' ',       // - String, which separates the keywords query if
                            //   query is a string.
      bufferSize: 64 * 1024 // - The buffer size used (twice) for a file.
                            //   Decrease this value for a smaller memory
                            //   footprint when you are seeking for large files.
    }
  • found is passed two arguments (file, matches) where file is the pathname of the file that has been found and matches is an array. The array may contain objects or arrays. The objects are returned when you search for strings. They look something like this:

    {
      keyword: 'foo', // - the keyword that has been found
      firstIndex: 43, // - the index of the first character of the keyword in
                      //   the file
      lastIndex: 45,  // - the index of the last character of the keyword in the
                      //   file
    }

    The arrays look like the regular results of a regular expression match. They only occur when query is an array and contains a regular expression.

  • filter [optional] is passed one argument (file). You may filter files out by providing a condition in this file. A file is left out, if filter returns false.

  • complete [optional] is passed no arguments. This callback is called, when the search is over.

Installation

Using npm:

npm install -g seek

Usage

var seek = require('seek');

seek(process.cwd(), 'seek require', {}, function(file, matches) {
  console.log(file);
  console.log(matches);
}, function(file) {
  return /\.(html|txt|xml)$/i.test(file);
  // Only look for files that end with '.html', '.txt', or '.xml'.
});

For more examples, look at the tests.

Bugs and Issues

If you encounter any bugs or issues, feel free to open an issue at github.

License

MIT License