https://github.com/martinheidegger/exec-fallback
node library to fallback to executable if a method call falls.
https://github.com/martinheidegger/exec-fallback
Last synced: 3 months ago
JSON representation
node library to fallback to executable if a method call falls.
- Host: GitHub
- URL: https://github.com/martinheidegger/exec-fallback
- Owner: martinheidegger
- License: other
- Created: 2015-12-06T16:36:43.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-14T17:20:42.000Z (about 8 years ago)
- Last Synced: 2025-03-29T06:35:21.801Z (3 months ago)
- Language: JavaScript
- Size: 22.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 45
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# exec-fallback [](https://travis-ci.org/martinheidegger/exec-fallback)
Tool to fallback to an `exec` command in case that a method doesn't return a satisfactory value
## Usage
Install with ...
```
$ npm install exec-fallback --save
```and create a fallback in case a **synchronous** template is empty:
```JavaScript
var fb = require('exec-fallback')
var myFallback = fb(function () {
// do something
}, 'fallback-command')
```Here is a example where `pwd` is called in case a `config.path` property doesn't exist.
```JavaScript
var fb = require('exec-fallback')
function regularCall() {
return config.path
}
var myConfigPath = fb(regularCall, 'pwd')
```since the fallback is an async exec command you need to register a callback hook to get the value
```JavaScript
myConfigPath(function (error, value) {
// there will never be an error,
})
```## Caching & Invalidation
The result will be cached by default for **10 minutes**. You can change the cache time by passing in a third parameter.```JavaScript
var myConfigPath = fb(regularCall, 'pwd', 100000)
```It is also possible to invalidate the currently cached value.
```JavaScript
myConfigPath.invalidate()
```## License
ISC
Originally inspired by [osenv](https://github.com/npm/osenv).