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

search-path

v1.0.4

Published

locate and fetch files from the filesystem using search path

Downloads

3

Readme

search-path - locate and fetch files from the filesystem using search path

A simple extension to Array to hold various search path directories and provide checks for existence and locate/fetch files accordingly.

Usage

Example usage (coffeescript):

SearchPath = require 'search-path'
search = new SearchPath basedir: __dirname, exts: [ 'txt', 'doc' ], encoding: 'utf-8'

# include example and test/foo directories as part of search (relative
# to basedir)
search.add 'example', 'test/foo'

console.log search                  # shows current contents of search path
console.log (search.locate 'hello') # shows where 'hello', 'hello.txt', or 'hello.doc' was found
console.log (search.fetch 'hello')  # retrieves located content using 'encoding'

API

exists (paths..., opts)

Checks whether passed in paths exists in the local filesystem.

opts.basedir | string | prefix for relative paths opts.isDirectory | boolean | if true, checks if directory opts.isFile | boolean | if true, checks if file

base (path)

Update the current basedir to use for relative paths.

search.base('/home')
  .include 'some-user'
  .include 'other-user/docs'

console.log search

## include (paths...)

Adds additional directories into search path if they exist.

## locate (files...)

Finds all *files* existing in the current search path. Always returns
an array containing one or more matching files.

## resolve (files...)

Locates all *files* existing in the current search path including any
files matching the configured *exts* as part of the current search
path instance.

## fetch (files...)

Grabs content(s) of all resolved *files* using the *encoding* for the
search path.

This is a convenience function and simply applies `fs.readFileSync` on
the results of `resolve` from above.

# License
  [Apache 2.0](LICENSE)