# flipfind

> auto-find & resolve a file or path that is somewhere nearby in an optimized manner

Latest version **0.1.4** (published 2017-04-16) · 0 weekly downloads

## Install

```sh
npm install flipfind
pnpm add flipfind
yarn add flipfind
bun add flipfind
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2017-04-16 |
| First published | 2017-04-03 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 30 |
| Author | James |
| Maintainers | aretecode |
| Keywords | auto, find-file, file, find, resolve, fliphub, flipbox |

## Links

- npm: https://www.npmjs.com/package/flipfind
- Repository: https://github.com/fliphub/fliphub
- Homepage: https://github.com/fliphub/fliphub#readme
- Issues: https://github.com/fliphub/fliphub/issues
- npm.io page: https://npm.io/package/flipfind

## Dependencies (7)

- [fliplog](https://npm.io/package/fliplog.md) *
- [glob-fs](https://npm.io/package/glob-fs.md) 0.1.6
- [flipfile](https://npm.io/package/flipfile.md) *
- [mono-root](https://npm.io/package/mono-root.md) *
- [does-include](https://npm.io/package/does-include.md) *
- [app-root-path](https://npm.io/package/app-root-path.md) ^2.0.1
- [fliphub-resolve](https://npm.io/package/fliphub-resolve.md) *

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 0.1.4 (latest) — 2017-04-16
- 0.1.3 — 2017-04-13
- 0.1.2 — 2017-04-06
- 0.1.1 — 2017-04-03
- 0.1.0 — 2017-04-03

## README

# 🔎 🎯 flipfind

> find and resolve files automatically
> searches nearby paths in an optimized order

[![NPM version][flipfind-npm-image]][flipfind-npm-url]
[![MIT License][license-image]][license-url]
[![fliphub][gitter-badge]][gitter-url]
[![flipfam][flipfam-image]][flipfam-url]

[flipfind-npm-image]: https://img.shields.io/npm/v/flipfind.svg
[flipfind-npm-url]: https://npmjs.org/package/flipfind
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
[license-url]: https://spdx.org/licenses/MIT
[gitter-badge]: https://img.shields.io/gitter/room/fliphub/pink.svg
[gitter-url]: https://gitter.im/fliphub/Lobby
[flipfam-image]: https://img.shields.io/badge/%F0%9F%8F%97%20%F0%9F%92%A0-flipfam-9659F7.svg
[flipfam-url]: https://www.npmjs.com/package/flipfam

## usage
```bash
yarn add flipfind
npm i flipfind --save
```

```js
// can be used as a class for chaining and debugging
const {Finder} = require('flipfind')

// or as a function for easier fun
const finder = require('flipfind')
```

## 🔊 debug

![example debug output](https://cloud.githubusercontent.com/assets/4022631/24595185/09917ea2-17e9-11e7-908e-36778c0c5cd2.png)

```js
const found = Finder.file('./src/eh').debug().all().asObj().find()
```


## 👣 steps

to optimize, it will go through the steps in order and `return` once it finds the correct existing path. If [.debug](#debug) is used with `.all`, it will go through every step and output the results so you can see the process.

1. if a file and dir are given, it will attempt to resolve using file + dir
2. if the given file is [absolute](https://nodejs.org/api/path.html#path_path_isabsolute_path), and if it [exists](https://www.npmjs.com/package/flipfile)
3. checks with the [cwd](https://nodejs.org/api/process.html#process_process_cwd)
4. checks with [require.main](https://nodejs.org/api/modules.html#modules_accessing_the_main_module) extracts the [dirname](https://nodejs.org/api/path.html#path_path_dirname_path) from it
5. checks the [app-root-path](https://github.com/inxilpro/node-app-root-path)
6. checks a [glob](https://github.com/isaacs/node-glob) for very near files
  - filters to ensure it [does-include](https://www.npmjs.com/package/does-include) the file and/or dir passed in through options
7. checks with the [mono-root](https://www.npmjs.com/package/mono-root)

## 📘 examples

```js
// will return null
const found = Finder.file('not-real').find()

// without ext
Finder.file('eh').find()
// with ext
Finder.file('eh.js').find()
// can use relative,  
Finder.file('./src/eh').find()
// or shorthand
Finder.file('src/eh').find()
// with dir
Finder.file('eh').dir('test/fixtures').find()

// return an object
const {
  abs,
  file,
  name,
  ext,
  dir,
} = Finder.file('src/eh').asObj().find()

// as function
find('src/eh')
```


### 📝 todo
- add fallback for resolving a file that does not yet exist - currently is `null`, will require an option
- cache the results

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