# search-path

> locate and fetch files from the filesystem using search path

Latest version **1.0.4** (published 2016-03-24) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install search-path
pnpm add search-path
yarn add search-path
bun add search-path
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2016-03-24 |
| First published | 2016-03-21 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.28 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Peter K. Lee |
| Maintainers | corenova |
| Keywords | locate, search, fetch, path, file, include, link, cache |

## Links

- npm: https://www.npmjs.com/package/search-path
- Repository: https://github.com/saintkepha/search-path
- Homepage: https://github.com/saintkepha/search-path#readme
- Issues: https://github.com/saintkepha/search-path/issues
- npm.io page: https://npm.io/package/search-path

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.4 (latest) — 2016-03-24
- 1.0.3 — 2016-03-21
- 1.0.2 — 2016-03-21
- 1.0.1 — 2016-03-21
- 1.0.0 — 2016-03-21

## 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):

```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.

```coffeescript
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)

---
_Source: https://npm.io/package/search-path · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
