Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bevry/extract-opts
Deprecated. Convert your API to promises
https://github.com/bevry/extract-opts
argument-parser client-side nodejs
Last synced: 19 days ago
JSON representation
Deprecated. Convert your API to promises
- Host: GitHub
- URL: https://github.com/bevry/extract-opts
- Owner: bevry
- License: other
- Created: 2013-06-23T13:42:39.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2024-01-02T03:36:09.000Z (about 1 year ago)
- Last Synced: 2024-10-30T00:55:54.639Z (2 months ago)
- Topics: argument-parser, client-side, nodejs
- Language: JavaScript
- Homepage:
- Size: 939 KB
- Stars: 7
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Extract Options & Callback
Extract the options and callback from a function's arguments easily
## Usage
```javascript
var log = console.log.bind(console)
var extractOptsAndCallback = require('extract-opts')// fs.readFile(filename, [options], callback)
function readFile(filename, opts, next) {
// Extract options and callback
var args = extractOptsAndCallback(opts, next)
opts = args[0]
next = args[1]// Forward for simplicities sake
require('fs').readFile(filename, opts, next)
}// Test it
readFile('package.json', log) // works with no options
readFile('package.json', null, log) // works with null options
readFile('package.json', { next: log }) // works with just options
```### Customisation
Extract Options and Callback also supports a third argument.
You can use this third argument to customize the `completionCallbackNames` property that defaults to `['next']`.
This is useful if your completion callback has other names besides `next`.
Allowing you to do the following:```javascript
var log = console.log.bind(console)
function extractOptsAndCallback(opts, next, config) {
if (config == null) config = {}
if (config.completionCallbackNames == null)
config.completionCallbackNames = ['next', 'complete', 'done']
return require('extract-opts')(opts, next, config)
}// The readFile method as before
// Test it
readFile('package.json', { next: log }) // works the standard completion callback name
readFile('package.json', { complete: log }) // works with our custom completion callback name
readFile('package.json', { done: log }) // works with our custom completion callback name
```## Install
### [npm](https://npmjs.com "npm is a package manager for javascript")
- Install: `npm install --save extract-opts`
- Import: `import * as pkg from ('extract-opts')`
- Require: `const pkg = require('extract-opts')`### [jspm](https://jspm.io "Native ES Modules CDN")
``` html
import * as pkg from '//dev.jspm.io/[email protected]'
```
### [Editions](https://editions.bevry.me "Editions are the best way to produce and consume packages you care about.")This package is published with the following editions:
- `extract-opts` aliases `extract-opts/index.cjs` which uses the [Editions Autoloader](https://github.com/bevry/editions "You can use the Editions Autoloader to autoload the appropriate edition for your consumers environment") to automatically select the correct edition for the consumer's environment
- `extract-opts/source/index.js` is [ESNext](https://en.wikipedia.org/wiki/ECMAScript#ES.Next "ECMAScript Next") source code for [Node.js](https://nodejs.org "Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine") 6 || 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21 with [Require](https://nodejs.org/dist/latest-v5.x/docs/api/modules.html "Node/CJS Modules") for modules
- `extract-opts/edition-browsers/index.js` is [ESNext](https://en.wikipedia.org/wiki/ECMAScript#ES.Next "ECMAScript Next") compiled for web browsers with [Require](https://nodejs.org/dist/latest-v5.x/docs/api/modules.html "Node/CJS Modules") for modules
- `extract-opts/edition-node-4/index.js` is [ESNext](https://en.wikipedia.org/wiki/ECMAScript#ES.Next "ECMAScript Next") compiled for [Node.js](https://nodejs.org "Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine") 4 || 6 || 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21 with [Require](https://nodejs.org/dist/latest-v5.x/docs/api/modules.html "Node/CJS Modules") for modules## History
[Discover the release history by heading on over to the `HISTORY.md` file.](https://github.com/bevry/extract-opts/blob/HEAD/HISTORY.md#files)
## Backers
### Code
[Discover how to contribute via the `CONTRIBUTING.md` file.](https://github.com/bevry/extract-opts/blob/HEAD/CONTRIBUTING.md#files)
#### Authors
- [Benjamin Lupton](https://balupton.com) — Accelerating collaborative wisdom.
#### Maintainers
- [Benjamin Lupton](https://balupton.com) — Accelerating collaborative wisdom.
#### Contributors
- [Benjamin Lupton](https://github.com/balupton) — [view contributions](https://github.com/bevry/extract-opts/commits?author=balupton "View the GitHub contributions of Benjamin Lupton on repository bevry/extract-opts")
- [Matt Bierner](https://github.com/mjbvz) — [view contributions](https://github.com/bevry/extract-opts/commits?author=mjbvz "View the GitHub contributions of Matt Bierner on repository bevry/extract-opts")
- [Sean Fridman](https://github.com/sfrdmn) — [view contributions](https://github.com/bevry/extract-opts/commits?author=sfrdmn "View the GitHub contributions of Sean Fridman on repository bevry/extract-opts")### Finances
#### Sponsors
- [Andrew Nesbitt](https://nesbitt.io) — Software engineer and researcher
- [Balsa](https://balsa.com) — We're Balsa, and we're building tools for builders.
- [Codecov](https://codecov.io) — Empower developers with tools to improve code quality and testing.
- [Poonacha Medappa](https://poonachamedappa.com)
- [Rob Morris](https://github.com/Rob-Morris)
- [Sentry](https://sentry.io) — Real-time crash reporting for your web apps, mobile apps, and games.
- [Syntax](https://syntax.fm) — Syntax Podcast#### Donors
- [Andrew Nesbitt](https://nesbitt.io)
- [Armen Mkrtchian](https://mogoni.dev)
- [Balsa](https://balsa.com)
- [Chad](https://opencollective.com/chad8)
- [Codecov](https://codecov.io)
- [dr.dimitru](https://veliovgroup.com)
- [Elliott Ditman](https://elliottditman.com)
- [entroniq](https://gitlab.com/entroniq)
- [GitHub](https://github.com/about)
- [Hunter Beast](https://cryptoquick.com)
- [Jean-Luc Geering](https://github.com/jlgeering)
- [Michael Duane Mooring](https://mdm.cc)
- [Michael Harry Scepaniak](https://michaelscepaniak.com)
- [Mohammed Shah](https://github.com/smashah)
- [Mr. Henry](https://mrhenry.be)
- [Nermal](https://arjunaditya.vercel.app)
- [Pleo](https://pleo.io)
- [Poonacha Medappa](https://poonachamedappa.com)
- [Rob Morris](https://github.com/Rob-Morris)
- [Robert de Forest](https://github.com/rdeforest)
- [Sentry](https://sentry.io)
- [ServieJS](https://github.com/serviejs)
- [Skunk Team](https://skunk.team)
- [Syntax](https://syntax.fm)
- [WriterJohnBuck](https://github.com/WriterJohnBuck)## License
Unless stated otherwise all works are:
- Copyright © [Benjamin Lupton](https://balupton.com)
and licensed under:
- [Artistic License 2.0](http://spdx.org/licenses/Artistic-2.0.html)