first-existing-path

Get the first existing path

Usage no npm install needed!

<script type="module">
  import firstExistingPath from 'https://cdn.skypack.dev/first-existing-path';
</script>

README

First existing path

Build Status

Get the first existing path from an array of strings

Install

npm install first-existing-path [--save]

Usage

const firstExistingPath = require('first-existing-path')

firstExistingPath([
  process.env.CONFIG, '~/.config', '.config'
], function(err, path) {

})

Or as a promise:

const firstExistingPath = require('first-existing-path')

firstExistingPath([
  process.env.CONFIG, '~/.config', '.config'
])
.then((path) => {

})

Or synchronous:

const firstExistingPath = require('first-existing-path')

let path = firstExistingPath.sync([
  process.env.CONFIG, '~/.config', '.config'
])

API

/**
 * firstExistingPath
 * Get back the first path that does exist
 * @param {Array} paths
 * @param {Function} cb optional callback
 * @return {String|Boolean} Promise the founded path or false
 */
function firstExistingPath(paths, cb)

/**
 * firstExistingPath sync
 * Get back the first path that does exist
 * @param {Array} paths
 * @return {String|Boolean} the founded path or false
 */

function firstExistingPathSync(paths)

License

MIT