Spaces:
Paused
Paused
Upload folder using huggingface_hub (part 16)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- node_modules/on-finished/README.md +162 -0
- node_modules/on-finished/index.js +234 -0
- node_modules/on-finished/package.json +39 -0
- node_modules/once/LICENSE +15 -0
- node_modules/once/README.md +79 -0
- node_modules/once/once.js +42 -0
- node_modules/once/package.json +33 -0
- node_modules/optionator/CHANGELOG.md +59 -0
- node_modules/optionator/LICENSE +22 -0
- node_modules/optionator/README.md +238 -0
- node_modules/optionator/lib/help.js +260 -0
- node_modules/optionator/lib/index.js +465 -0
- node_modules/optionator/lib/util.js +54 -0
- node_modules/optionator/package.json +43 -0
- node_modules/otplib/LICENSE +21 -0
- node_modules/otplib/README.md +534 -0
- node_modules/otplib/core.d.ts +1 -0
- node_modules/otplib/core.js +23 -0
- node_modules/otplib/index.d.ts +1 -0
- node_modules/otplib/index.js +23 -0
- node_modules/otplib/package.json +34 -0
- node_modules/otplib/v11.d.ts +1 -0
- node_modules/otplib/v11.js +23 -0
- node_modules/outvariant/LICENSE +9 -0
- node_modules/outvariant/README.md +146 -0
- node_modules/outvariant/lib/index.d.ts +21 -0
- node_modules/outvariant/lib/index.js +120 -0
- node_modules/outvariant/lib/index.js.map +1 -0
- node_modules/outvariant/lib/index.mjs +91 -0
- node_modules/outvariant/lib/index.mjs.map +1 -0
- node_modules/outvariant/package.json +47 -0
- node_modules/p-limit/index.d.ts +42 -0
- node_modules/p-limit/index.js +71 -0
- node_modules/p-limit/license +9 -0
- node_modules/p-limit/package.json +52 -0
- node_modules/p-limit/readme.md +101 -0
- node_modules/p-locate/index.d.ts +53 -0
- node_modules/p-locate/index.js +50 -0
- node_modules/p-locate/license +9 -0
- node_modules/p-locate/package.json +54 -0
- node_modules/p-locate/readme.md +93 -0
- node_modules/p-try/index.d.ts +39 -0
- node_modules/p-try/index.js +9 -0
- node_modules/p-try/license +9 -0
- node_modules/p-try/package.json +42 -0
- node_modules/p-try/readme.md +58 -0
- node_modules/p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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# on-finished
|
| 2 |
+
|
| 3 |
+
[![NPM Version][npm-version-image]][npm-url]
|
| 4 |
+
[![NPM Downloads][npm-downloads-image]][npm-url]
|
| 5 |
+
[![Node.js Version][node-image]][node-url]
|
| 6 |
+
[![Build Status][ci-image]][ci-url]
|
| 7 |
+
[![Coverage Status][coveralls-image]][coveralls-url]
|
| 8 |
+
|
| 9 |
+
Execute a callback when a HTTP request closes, finishes, or errors.
|
| 10 |
+
|
| 11 |
+
## Install
|
| 12 |
+
|
| 13 |
+
This is a [Node.js](https://nodejs.org/en/) module available through the
|
| 14 |
+
[npm registry](https://www.npmjs.com/). Installation is done using the
|
| 15 |
+
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
|
| 16 |
+
|
| 17 |
+
```sh
|
| 18 |
+
$ npm install on-finished
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
## API
|
| 22 |
+
|
| 23 |
+
```js
|
| 24 |
+
var onFinished = require('on-finished')
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
### onFinished(res, listener)
|
| 28 |
+
|
| 29 |
+
Attach a listener to listen for the response to finish. The listener will
|
| 30 |
+
be invoked only once when the response finished. If the response finished
|
| 31 |
+
to an error, the first argument will contain the error. If the response
|
| 32 |
+
has already finished, the listener will be invoked.
|
| 33 |
+
|
| 34 |
+
Listening to the end of a response would be used to close things associated
|
| 35 |
+
with the response, like open files.
|
| 36 |
+
|
| 37 |
+
Listener is invoked as `listener(err, res)`.
|
| 38 |
+
|
| 39 |
+
<!-- eslint-disable handle-callback-err -->
|
| 40 |
+
|
| 41 |
+
```js
|
| 42 |
+
onFinished(res, function (err, res) {
|
| 43 |
+
// clean up open fds, etc.
|
| 44 |
+
// err contains the error if request error'd
|
| 45 |
+
})
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
### onFinished(req, listener)
|
| 49 |
+
|
| 50 |
+
Attach a listener to listen for the request to finish. The listener will
|
| 51 |
+
be invoked only once when the request finished. If the request finished
|
| 52 |
+
to an error, the first argument will contain the error. If the request
|
| 53 |
+
has already finished, the listener will be invoked.
|
| 54 |
+
|
| 55 |
+
Listening to the end of a request would be used to know when to continue
|
| 56 |
+
after reading the data.
|
| 57 |
+
|
| 58 |
+
Listener is invoked as `listener(err, req)`.
|
| 59 |
+
|
| 60 |
+
<!-- eslint-disable handle-callback-err -->
|
| 61 |
+
|
| 62 |
+
```js
|
| 63 |
+
var data = ''
|
| 64 |
+
|
| 65 |
+
req.setEncoding('utf8')
|
| 66 |
+
req.on('data', function (str) {
|
| 67 |
+
data += str
|
| 68 |
+
})
|
| 69 |
+
|
| 70 |
+
onFinished(req, function (err, req) {
|
| 71 |
+
// data is read unless there is err
|
| 72 |
+
})
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
### onFinished.isFinished(res)
|
| 76 |
+
|
| 77 |
+
Determine if `res` is already finished. This would be useful to check and
|
| 78 |
+
not even start certain operations if the response has already finished.
|
| 79 |
+
|
| 80 |
+
### onFinished.isFinished(req)
|
| 81 |
+
|
| 82 |
+
Determine if `req` is already finished. This would be useful to check and
|
| 83 |
+
not even start certain operations if the request has already finished.
|
| 84 |
+
|
| 85 |
+
## Special Node.js requests
|
| 86 |
+
|
| 87 |
+
### HTTP CONNECT method
|
| 88 |
+
|
| 89 |
+
The meaning of the `CONNECT` method from RFC 7231, section 4.3.6:
|
| 90 |
+
|
| 91 |
+
> The CONNECT method requests that the recipient establish a tunnel to
|
| 92 |
+
> the destination origin server identified by the request-target and,
|
| 93 |
+
> if successful, thereafter restrict its behavior to blind forwarding
|
| 94 |
+
> of packets, in both directions, until the tunnel is closed. Tunnels
|
| 95 |
+
> are commonly used to create an end-to-end virtual connection, through
|
| 96 |
+
> one or more proxies, which can then be secured using TLS (Transport
|
| 97 |
+
> Layer Security, [RFC5246]).
|
| 98 |
+
|
| 99 |
+
In Node.js, these request objects come from the `'connect'` event on
|
| 100 |
+
the HTTP server.
|
| 101 |
+
|
| 102 |
+
When this module is used on a HTTP `CONNECT` request, the request is
|
| 103 |
+
considered "finished" immediately, **due to limitations in the Node.js
|
| 104 |
+
interface**. This means if the `CONNECT` request contains a request entity,
|
| 105 |
+
the request will be considered "finished" even before it has been read.
|
| 106 |
+
|
| 107 |
+
There is no such thing as a response object to a `CONNECT` request in
|
| 108 |
+
Node.js, so there is no support for one.
|
| 109 |
+
|
| 110 |
+
### HTTP Upgrade request
|
| 111 |
+
|
| 112 |
+
The meaning of the `Upgrade` header from RFC 7230, section 6.1:
|
| 113 |
+
|
| 114 |
+
> The "Upgrade" header field is intended to provide a simple mechanism
|
| 115 |
+
> for transitioning from HTTP/1.1 to some other protocol on the same
|
| 116 |
+
> connection.
|
| 117 |
+
|
| 118 |
+
In Node.js, these request objects come from the `'upgrade'` event on
|
| 119 |
+
the HTTP server.
|
| 120 |
+
|
| 121 |
+
When this module is used on a HTTP request with an `Upgrade` header, the
|
| 122 |
+
request is considered "finished" immediately, **due to limitations in the
|
| 123 |
+
Node.js interface**. This means if the `Upgrade` request contains a request
|
| 124 |
+
entity, the request will be considered "finished" even before it has been
|
| 125 |
+
read.
|
| 126 |
+
|
| 127 |
+
There is no such thing as a response object to a `Upgrade` request in
|
| 128 |
+
Node.js, so there is no support for one.
|
| 129 |
+
|
| 130 |
+
## Example
|
| 131 |
+
|
| 132 |
+
The following code ensures that file descriptors are always closed
|
| 133 |
+
once the response finishes.
|
| 134 |
+
|
| 135 |
+
```js
|
| 136 |
+
var destroy = require('destroy')
|
| 137 |
+
var fs = require('fs')
|
| 138 |
+
var http = require('http')
|
| 139 |
+
var onFinished = require('on-finished')
|
| 140 |
+
|
| 141 |
+
http.createServer(function onRequest (req, res) {
|
| 142 |
+
var stream = fs.createReadStream('package.json')
|
| 143 |
+
stream.pipe(res)
|
| 144 |
+
onFinished(res, function () {
|
| 145 |
+
destroy(stream)
|
| 146 |
+
})
|
| 147 |
+
})
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
## License
|
| 151 |
+
|
| 152 |
+
[MIT](LICENSE)
|
| 153 |
+
|
| 154 |
+
[ci-image]: https://badgen.net/github/checks/jshttp/on-finished/master?label=ci
|
| 155 |
+
[ci-url]: https://github.com/jshttp/on-finished/actions/workflows/ci.yml
|
| 156 |
+
[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/on-finished/master
|
| 157 |
+
[coveralls-url]: https://coveralls.io/r/jshttp/on-finished?branch=master
|
| 158 |
+
[node-image]: https://badgen.net/npm/node/on-finished
|
| 159 |
+
[node-url]: https://nodejs.org/en/download
|
| 160 |
+
[npm-downloads-image]: https://badgen.net/npm/dm/on-finished
|
| 161 |
+
[npm-url]: https://npmjs.org/package/on-finished
|
| 162 |
+
[npm-version-image]: https://badgen.net/npm/v/on-finished
|
node_modules/on-finished/index.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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'use strict'
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* Module exports.
|
| 12 |
+
* @public
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
module.exports = onFinished
|
| 16 |
+
module.exports.isFinished = isFinished
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Module dependencies.
|
| 20 |
+
* @private
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
var asyncHooks = tryRequireAsyncHooks()
|
| 24 |
+
var first = require('ee-first')
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* Variables.
|
| 28 |
+
* @private
|
| 29 |
+
*/
|
| 30 |
+
|
| 31 |
+
/* istanbul ignore next */
|
| 32 |
+
var defer = typeof setImmediate === 'function'
|
| 33 |
+
? setImmediate
|
| 34 |
+
: function (fn) { process.nextTick(fn.bind.apply(fn, arguments)) }
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* Invoke callback when the response has finished, useful for
|
| 38 |
+
* cleaning up resources afterwards.
|
| 39 |
+
*
|
| 40 |
+
* @param {object} msg
|
| 41 |
+
* @param {function} listener
|
| 42 |
+
* @return {object}
|
| 43 |
+
* @public
|
| 44 |
+
*/
|
| 45 |
+
|
| 46 |
+
function onFinished (msg, listener) {
|
| 47 |
+
if (isFinished(msg) !== false) {
|
| 48 |
+
defer(listener, null, msg)
|
| 49 |
+
return msg
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
// attach the listener to the message
|
| 53 |
+
attachListener(msg, wrap(listener))
|
| 54 |
+
|
| 55 |
+
return msg
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Determine if message is already finished.
|
| 60 |
+
*
|
| 61 |
+
* @param {object} msg
|
| 62 |
+
* @return {boolean}
|
| 63 |
+
* @public
|
| 64 |
+
*/
|
| 65 |
+
|
| 66 |
+
function isFinished (msg) {
|
| 67 |
+
var socket = msg.socket
|
| 68 |
+
|
| 69 |
+
if (typeof msg.finished === 'boolean') {
|
| 70 |
+
// OutgoingMessage
|
| 71 |
+
return Boolean(msg.finished || (socket && !socket.writable))
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
if (typeof msg.complete === 'boolean') {
|
| 75 |
+
// IncomingMessage
|
| 76 |
+
return Boolean(msg.upgrade || !socket || !socket.readable || (msg.complete && !msg.readable))
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// don't know
|
| 80 |
+
return undefined
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/**
|
| 84 |
+
* Attach a finished listener to the message.
|
| 85 |
+
*
|
| 86 |
+
* @param {object} msg
|
| 87 |
+
* @param {function} callback
|
| 88 |
+
* @private
|
| 89 |
+
*/
|
| 90 |
+
|
| 91 |
+
function attachFinishedListener (msg, callback) {
|
| 92 |
+
var eeMsg
|
| 93 |
+
var eeSocket
|
| 94 |
+
var finished = false
|
| 95 |
+
|
| 96 |
+
function onFinish (error) {
|
| 97 |
+
eeMsg.cancel()
|
| 98 |
+
eeSocket.cancel()
|
| 99 |
+
|
| 100 |
+
finished = true
|
| 101 |
+
callback(error)
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// finished on first message event
|
| 105 |
+
eeMsg = eeSocket = first([[msg, 'end', 'finish']], onFinish)
|
| 106 |
+
|
| 107 |
+
function onSocket (socket) {
|
| 108 |
+
// remove listener
|
| 109 |
+
msg.removeListener('socket', onSocket)
|
| 110 |
+
|
| 111 |
+
if (finished) return
|
| 112 |
+
if (eeMsg !== eeSocket) return
|
| 113 |
+
|
| 114 |
+
// finished on first socket event
|
| 115 |
+
eeSocket = first([[socket, 'error', 'close']], onFinish)
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
if (msg.socket) {
|
| 119 |
+
// socket already assigned
|
| 120 |
+
onSocket(msg.socket)
|
| 121 |
+
return
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
// wait for socket to be assigned
|
| 125 |
+
msg.on('socket', onSocket)
|
| 126 |
+
|
| 127 |
+
if (msg.socket === undefined) {
|
| 128 |
+
// istanbul ignore next: node.js 0.8 patch
|
| 129 |
+
patchAssignSocket(msg, onSocket)
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
/**
|
| 134 |
+
* Attach the listener to the message.
|
| 135 |
+
*
|
| 136 |
+
* @param {object} msg
|
| 137 |
+
* @return {function}
|
| 138 |
+
* @private
|
| 139 |
+
*/
|
| 140 |
+
|
| 141 |
+
function attachListener (msg, listener) {
|
| 142 |
+
var attached = msg.__onFinished
|
| 143 |
+
|
| 144 |
+
// create a private single listener with queue
|
| 145 |
+
if (!attached || !attached.queue) {
|
| 146 |
+
attached = msg.__onFinished = createListener(msg)
|
| 147 |
+
attachFinishedListener(msg, attached)
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
attached.queue.push(listener)
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
/**
|
| 154 |
+
* Create listener on message.
|
| 155 |
+
*
|
| 156 |
+
* @param {object} msg
|
| 157 |
+
* @return {function}
|
| 158 |
+
* @private
|
| 159 |
+
*/
|
| 160 |
+
|
| 161 |
+
function createListener (msg) {
|
| 162 |
+
function listener (err) {
|
| 163 |
+
if (msg.__onFinished === listener) msg.__onFinished = null
|
| 164 |
+
if (!listener.queue) return
|
| 165 |
+
|
| 166 |
+
var queue = listener.queue
|
| 167 |
+
listener.queue = null
|
| 168 |
+
|
| 169 |
+
for (var i = 0; i < queue.length; i++) {
|
| 170 |
+
queue[i](err, msg)
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
listener.queue = []
|
| 175 |
+
|
| 176 |
+
return listener
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
/**
|
| 180 |
+
* Patch ServerResponse.prototype.assignSocket for node.js 0.8.
|
| 181 |
+
*
|
| 182 |
+
* @param {ServerResponse} res
|
| 183 |
+
* @param {function} callback
|
| 184 |
+
* @private
|
| 185 |
+
*/
|
| 186 |
+
|
| 187 |
+
// istanbul ignore next: node.js 0.8 patch
|
| 188 |
+
function patchAssignSocket (res, callback) {
|
| 189 |
+
var assignSocket = res.assignSocket
|
| 190 |
+
|
| 191 |
+
if (typeof assignSocket !== 'function') return
|
| 192 |
+
|
| 193 |
+
// res.on('socket', callback) is broken in 0.8
|
| 194 |
+
res.assignSocket = function _assignSocket (socket) {
|
| 195 |
+
assignSocket.call(this, socket)
|
| 196 |
+
callback(socket)
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
/**
|
| 201 |
+
* Try to require async_hooks
|
| 202 |
+
* @private
|
| 203 |
+
*/
|
| 204 |
+
|
| 205 |
+
function tryRequireAsyncHooks () {
|
| 206 |
+
try {
|
| 207 |
+
return require('async_hooks')
|
| 208 |
+
} catch (e) {
|
| 209 |
+
return {}
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
/**
|
| 214 |
+
* Wrap function with async resource, if possible.
|
| 215 |
+
* AsyncResource.bind static method backported.
|
| 216 |
+
* @private
|
| 217 |
+
*/
|
| 218 |
+
|
| 219 |
+
function wrap (fn) {
|
| 220 |
+
var res
|
| 221 |
+
|
| 222 |
+
// create anonymous resource
|
| 223 |
+
if (asyncHooks.AsyncResource) {
|
| 224 |
+
res = new asyncHooks.AsyncResource(fn.name || 'bound-anonymous-fn')
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
// incompatible node.js
|
| 228 |
+
if (!res || !res.runInAsyncScope) {
|
| 229 |
+
return fn
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
// return bound function
|
| 233 |
+
return res.runInAsyncScope.bind(res, fn, null)
|
| 234 |
+
}
|
node_modules/on-finished/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "on-finished",
|
| 3 |
+
"description": "Execute a callback when a request closes, finishes, or errors",
|
| 4 |
+
"version": "2.4.1",
|
| 5 |
+
"contributors": [
|
| 6 |
+
"Douglas Christopher Wilson <doug@somethingdoug.com>",
|
| 7 |
+
"Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"
|
| 8 |
+
],
|
| 9 |
+
"license": "MIT",
|
| 10 |
+
"repository": "jshttp/on-finished",
|
| 11 |
+
"dependencies": {
|
| 12 |
+
"ee-first": "1.1.1"
|
| 13 |
+
},
|
| 14 |
+
"devDependencies": {
|
| 15 |
+
"eslint": "7.32.0",
|
| 16 |
+
"eslint-config-standard": "14.1.1",
|
| 17 |
+
"eslint-plugin-import": "2.25.4",
|
| 18 |
+
"eslint-plugin-markdown": "2.2.1",
|
| 19 |
+
"eslint-plugin-node": "11.1.0",
|
| 20 |
+
"eslint-plugin-promise": "5.2.0",
|
| 21 |
+
"eslint-plugin-standard": "4.1.0",
|
| 22 |
+
"mocha": "9.2.1",
|
| 23 |
+
"nyc": "15.1.0"
|
| 24 |
+
},
|
| 25 |
+
"engines": {
|
| 26 |
+
"node": ">= 0.8"
|
| 27 |
+
},
|
| 28 |
+
"files": [
|
| 29 |
+
"HISTORY.md",
|
| 30 |
+
"LICENSE",
|
| 31 |
+
"index.js"
|
| 32 |
+
],
|
| 33 |
+
"scripts": {
|
| 34 |
+
"lint": "eslint .",
|
| 35 |
+
"test": "mocha --reporter spec --bail --check-leaks test/",
|
| 36 |
+
"test-ci": "nyc --reporter=lcovonly --reporter=text npm test",
|
| 37 |
+
"test-cov": "nyc --reporter=html --reporter=text npm test"
|
| 38 |
+
}
|
| 39 |
+
}
|
node_modules/once/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The ISC License
|
| 2 |
+
|
| 3 |
+
Copyright (c) Isaac Z. Schlueter and Contributors
|
| 4 |
+
|
| 5 |
+
Permission to use, copy, modify, and/or distribute this software for any
|
| 6 |
+
purpose with or without fee is hereby granted, provided that the above
|
| 7 |
+
copyright notice and this permission notice appear in all copies.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
| 10 |
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 11 |
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
| 12 |
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 13 |
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 14 |
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
| 15 |
+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
node_modules/once/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# once
|
| 2 |
+
|
| 3 |
+
Only call a function once.
|
| 4 |
+
|
| 5 |
+
## usage
|
| 6 |
+
|
| 7 |
+
```javascript
|
| 8 |
+
var once = require('once')
|
| 9 |
+
|
| 10 |
+
function load (file, cb) {
|
| 11 |
+
cb = once(cb)
|
| 12 |
+
loader.load('file')
|
| 13 |
+
loader.once('load', cb)
|
| 14 |
+
loader.once('error', cb)
|
| 15 |
+
}
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
Or add to the Function.prototype in a responsible way:
|
| 19 |
+
|
| 20 |
+
```javascript
|
| 21 |
+
// only has to be done once
|
| 22 |
+
require('once').proto()
|
| 23 |
+
|
| 24 |
+
function load (file, cb) {
|
| 25 |
+
cb = cb.once()
|
| 26 |
+
loader.load('file')
|
| 27 |
+
loader.once('load', cb)
|
| 28 |
+
loader.once('error', cb)
|
| 29 |
+
}
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
Ironically, the prototype feature makes this module twice as
|
| 33 |
+
complicated as necessary.
|
| 34 |
+
|
| 35 |
+
To check whether you function has been called, use `fn.called`. Once the
|
| 36 |
+
function is called for the first time the return value of the original
|
| 37 |
+
function is saved in `fn.value` and subsequent calls will continue to
|
| 38 |
+
return this value.
|
| 39 |
+
|
| 40 |
+
```javascript
|
| 41 |
+
var once = require('once')
|
| 42 |
+
|
| 43 |
+
function load (cb) {
|
| 44 |
+
cb = once(cb)
|
| 45 |
+
var stream = createStream()
|
| 46 |
+
stream.once('data', cb)
|
| 47 |
+
stream.once('end', function () {
|
| 48 |
+
if (!cb.called) cb(new Error('not found'))
|
| 49 |
+
})
|
| 50 |
+
}
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
## `once.strict(func)`
|
| 54 |
+
|
| 55 |
+
Throw an error if the function is called twice.
|
| 56 |
+
|
| 57 |
+
Some functions are expected to be called only once. Using `once` for them would
|
| 58 |
+
potentially hide logical errors.
|
| 59 |
+
|
| 60 |
+
In the example below, the `greet` function has to call the callback only once:
|
| 61 |
+
|
| 62 |
+
```javascript
|
| 63 |
+
function greet (name, cb) {
|
| 64 |
+
// return is missing from the if statement
|
| 65 |
+
// when no name is passed, the callback is called twice
|
| 66 |
+
if (!name) cb('Hello anonymous')
|
| 67 |
+
cb('Hello ' + name)
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
function log (msg) {
|
| 71 |
+
console.log(msg)
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// this will print 'Hello anonymous' but the logical error will be missed
|
| 75 |
+
greet(null, once(msg))
|
| 76 |
+
|
| 77 |
+
// once.strict will print 'Hello anonymous' and throw an error when the callback will be called the second time
|
| 78 |
+
greet(null, once.strict(msg))
|
| 79 |
+
```
|
node_modules/once/once.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var wrappy = require('wrappy')
|
| 2 |
+
module.exports = wrappy(once)
|
| 3 |
+
module.exports.strict = wrappy(onceStrict)
|
| 4 |
+
|
| 5 |
+
once.proto = once(function () {
|
| 6 |
+
Object.defineProperty(Function.prototype, 'once', {
|
| 7 |
+
value: function () {
|
| 8 |
+
return once(this)
|
| 9 |
+
},
|
| 10 |
+
configurable: true
|
| 11 |
+
})
|
| 12 |
+
|
| 13 |
+
Object.defineProperty(Function.prototype, 'onceStrict', {
|
| 14 |
+
value: function () {
|
| 15 |
+
return onceStrict(this)
|
| 16 |
+
},
|
| 17 |
+
configurable: true
|
| 18 |
+
})
|
| 19 |
+
})
|
| 20 |
+
|
| 21 |
+
function once (fn) {
|
| 22 |
+
var f = function () {
|
| 23 |
+
if (f.called) return f.value
|
| 24 |
+
f.called = true
|
| 25 |
+
return f.value = fn.apply(this, arguments)
|
| 26 |
+
}
|
| 27 |
+
f.called = false
|
| 28 |
+
return f
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
function onceStrict (fn) {
|
| 32 |
+
var f = function () {
|
| 33 |
+
if (f.called)
|
| 34 |
+
throw new Error(f.onceError)
|
| 35 |
+
f.called = true
|
| 36 |
+
return f.value = fn.apply(this, arguments)
|
| 37 |
+
}
|
| 38 |
+
var name = fn.name || 'Function wrapped with `once`'
|
| 39 |
+
f.onceError = name + " shouldn't be called more than once"
|
| 40 |
+
f.called = false
|
| 41 |
+
return f
|
| 42 |
+
}
|
node_modules/once/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "once",
|
| 3 |
+
"version": "1.4.0",
|
| 4 |
+
"description": "Run a function exactly one time",
|
| 5 |
+
"main": "once.js",
|
| 6 |
+
"directories": {
|
| 7 |
+
"test": "test"
|
| 8 |
+
},
|
| 9 |
+
"dependencies": {
|
| 10 |
+
"wrappy": "1"
|
| 11 |
+
},
|
| 12 |
+
"devDependencies": {
|
| 13 |
+
"tap": "^7.0.1"
|
| 14 |
+
},
|
| 15 |
+
"scripts": {
|
| 16 |
+
"test": "tap test/*.js"
|
| 17 |
+
},
|
| 18 |
+
"files": [
|
| 19 |
+
"once.js"
|
| 20 |
+
],
|
| 21 |
+
"repository": {
|
| 22 |
+
"type": "git",
|
| 23 |
+
"url": "git://github.com/isaacs/once"
|
| 24 |
+
},
|
| 25 |
+
"keywords": [
|
| 26 |
+
"once",
|
| 27 |
+
"function",
|
| 28 |
+
"one",
|
| 29 |
+
"single"
|
| 30 |
+
],
|
| 31 |
+
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
|
| 32 |
+
"license": "ISC"
|
| 33 |
+
}
|
node_modules/optionator/CHANGELOG.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 0.9.0
|
| 2 |
+
- update dependencies, in particular `levn` and `type-check` - this could affect behaviour of argument parsing
|
| 3 |
+
|
| 4 |
+
# 0.8.3
|
| 5 |
+
- changes dependency from `wordwrap` to `word-wrap` due to license issue
|
| 6 |
+
- update dependencies
|
| 7 |
+
|
| 8 |
+
# 0.8.2
|
| 9 |
+
- fix bug #18 - detect missing value when flag is last item
|
| 10 |
+
- update dependencies
|
| 11 |
+
|
| 12 |
+
# 0.8.1
|
| 13 |
+
- update `fast-levenshtein` dependency
|
| 14 |
+
|
| 15 |
+
# 0.8.0
|
| 16 |
+
- update `levn` dependency - supplying a float value to an option with type `Int` now throws an error, instead of silently converting to an `Int`
|
| 17 |
+
|
| 18 |
+
# 0.7.1
|
| 19 |
+
- fix bug with use of `defaults` and `concatRepeatedArrays` or `mergeRepeatedObjects`
|
| 20 |
+
|
| 21 |
+
# 0.7.0
|
| 22 |
+
- added `concatrepeatedarrays` option: `oneValuePerFlag`, only allows one array value per flag
|
| 23 |
+
- added `typeAliases` option
|
| 24 |
+
- added `parseArgv` which takes an array and parses with the first two items sliced off
|
| 25 |
+
- changed enum help style
|
| 26 |
+
- bug fixes (#12)
|
| 27 |
+
- use of `concatRepeatedArrays` and `mergeRepeatedObjects` at the top level is deprecated, use it as either a per-option option, or set them in the `defaults` object to set them for all objects
|
| 28 |
+
|
| 29 |
+
# 0.6.0
|
| 30 |
+
- added `defaults` lib-option flag, allowing one to set default properties for all options
|
| 31 |
+
- added `concatRepeatedArrays` and `mergeRepeatedObjects` as option level properties, allowing you to turn this feature on for specific options only
|
| 32 |
+
|
| 33 |
+
# 0.5.0
|
| 34 |
+
- `Boolean` flags with `default: 'true'`, and no short aliases, will by default show the `--no` version in help
|
| 35 |
+
|
| 36 |
+
# 0.4.0
|
| 37 |
+
- add `mergeRepeatedObjects` setting
|
| 38 |
+
|
| 39 |
+
# 0.3.0
|
| 40 |
+
- add `concatRepeatedArrays` setting
|
| 41 |
+
- add `overrideRequired` option setting
|
| 42 |
+
- use just Levenshtein string compare algo rather than Levenshtein Damerau to due dependency license issue
|
| 43 |
+
|
| 44 |
+
# 0.2.2
|
| 45 |
+
- bug fixes
|
| 46 |
+
|
| 47 |
+
# 0.2.1
|
| 48 |
+
- improved interpolation
|
| 49 |
+
- added changelog
|
| 50 |
+
|
| 51 |
+
# 0.2.0
|
| 52 |
+
- add dependency checks to options - added `dependsOn` as an option property
|
| 53 |
+
- add interpolation for `prepend` and `append` text with new `generateHelp` option, `interpolate`
|
| 54 |
+
|
| 55 |
+
# 0.1.1
|
| 56 |
+
- update dependencies
|
| 57 |
+
|
| 58 |
+
# 0.1.0
|
| 59 |
+
- initial release
|
node_modules/optionator/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) George Zahariev
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person
|
| 4 |
+
obtaining a copy of this software and associated documentation
|
| 5 |
+
files (the "Software"), to deal in the Software without
|
| 6 |
+
restriction, including without limitation the rights to use,
|
| 7 |
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
copies of the Software, and to permit persons to whom the
|
| 9 |
+
Software is furnished to do so, subject to the following
|
| 10 |
+
conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be
|
| 13 |
+
included in all copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 16 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
| 17 |
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 18 |
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
| 19 |
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
| 20 |
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 21 |
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
| 22 |
+
OTHER DEALINGS IN THE SOFTWARE.
|
node_modules/optionator/README.md
ADDED
|
@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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Optionator
|
| 2 |
+
<a name="optionator" />
|
| 3 |
+
|
| 4 |
+
Optionator is a JavaScript/Node.js option parsing and help generation library used by [eslint](http://eslint.org), [Grasp](http://graspjs.com), [LiveScript](http://livescript.net), [esmangle](https://github.com/estools/esmangle), [escodegen](https://github.com/estools/escodegen), and [many more](https://www.npmjs.com/browse/depended/optionator).
|
| 5 |
+
|
| 6 |
+
For an online demo, check out the [Grasp online demo](http://www.graspjs.com/#demo).
|
| 7 |
+
|
| 8 |
+
[About](#about) · [Usage](#usage) · [Settings Format](#settings-format) · [Argument Format](#argument-format)
|
| 9 |
+
|
| 10 |
+
## Why?
|
| 11 |
+
The problem with other option parsers, such as `yargs` or `minimist`, is they just accept all input, valid or not.
|
| 12 |
+
With Optionator, if you mistype an option, it will give you an error (with a suggestion for what you meant).
|
| 13 |
+
If you give the wrong type of argument for an option, it will give you an error rather than supplying the wrong input to your application.
|
| 14 |
+
|
| 15 |
+
$ cmd --halp
|
| 16 |
+
Invalid option '--halp' - perhaps you meant '--help'?
|
| 17 |
+
|
| 18 |
+
$ cmd --count str
|
| 19 |
+
Invalid value for option 'count' - expected type Int, received value: str.
|
| 20 |
+
|
| 21 |
+
Other helpful features include reformatting the help text based on the size of the console, so that it fits even if the console is narrow, and accepting not just an array (eg. process.argv), but a string or object as well, making things like testing much easier.
|
| 22 |
+
|
| 23 |
+
## About
|
| 24 |
+
Optionator uses [type-check](https://github.com/gkz/type-check) and [levn](https://github.com/gkz/levn) behind the scenes to cast and verify input according the specified types.
|
| 25 |
+
|
| 26 |
+
MIT license. Version 0.9.4
|
| 27 |
+
|
| 28 |
+
npm install optionator
|
| 29 |
+
|
| 30 |
+
For updates on Optionator, [follow me on twitter](https://twitter.com/gkzahariev).
|
| 31 |
+
|
| 32 |
+
Optionator is a Node.js module, but can be used in the browser as well if packed with webpack/browserify.
|
| 33 |
+
|
| 34 |
+
## Usage
|
| 35 |
+
`require('optionator');` returns a function. It has one property, `VERSION`, the current version of the library as a string. This function is called with an object specifying your options and other information, see the [settings format section](#settings-format). This in turn returns an object with three properties, `parse`, `parseArgv`, `generateHelp`, and `generateHelpForOption`, which are all functions.
|
| 36 |
+
|
| 37 |
+
```js
|
| 38 |
+
var optionator = require('optionator')({
|
| 39 |
+
prepend: 'Usage: cmd [options]',
|
| 40 |
+
append: 'Version 1.0.0',
|
| 41 |
+
options: [{
|
| 42 |
+
option: 'help',
|
| 43 |
+
alias: 'h',
|
| 44 |
+
type: 'Boolean',
|
| 45 |
+
description: 'displays help'
|
| 46 |
+
}, {
|
| 47 |
+
option: 'count',
|
| 48 |
+
alias: 'c',
|
| 49 |
+
type: 'Int',
|
| 50 |
+
description: 'number of things',
|
| 51 |
+
example: 'cmd --count 2'
|
| 52 |
+
}]
|
| 53 |
+
});
|
| 54 |
+
|
| 55 |
+
var options = optionator.parseArgv(process.argv);
|
| 56 |
+
if (options.help) {
|
| 57 |
+
console.log(optionator.generateHelp());
|
| 58 |
+
}
|
| 59 |
+
...
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
### parse(input, parseOptions)
|
| 63 |
+
`parse` processes the `input` according to your settings, and returns an object with the results.
|
| 64 |
+
|
| 65 |
+
##### arguments
|
| 66 |
+
* input - `[String] | Object | String` - the input you wish to parse
|
| 67 |
+
* parseOptions - `{slice: Int}` - all options optional
|
| 68 |
+
- `slice` specifies how much to slice away from the beginning if the input is an array or string - by default `0` for string, `2` for array (works with `process.argv`)
|
| 69 |
+
|
| 70 |
+
##### returns
|
| 71 |
+
`Object` - the parsed options, each key is a camelCase version of the option name (specified in dash-case), and each value is the processed value for that option. Positional values are in an array under the `_` key.
|
| 72 |
+
|
| 73 |
+
##### example
|
| 74 |
+
```js
|
| 75 |
+
parse(['node', 't.js', '--count', '2', 'positional']); // {count: 2, _: ['positional']}
|
| 76 |
+
parse('--count 2 positional'); // {count: 2, _: ['positional']}
|
| 77 |
+
parse({count: 2, _:['positional']}); // {count: 2, _: ['positional']}
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
### parseArgv(input)
|
| 81 |
+
`parseArgv` works exactly like `parse`, but only for array input and it slices off the first two elements.
|
| 82 |
+
|
| 83 |
+
##### arguments
|
| 84 |
+
* input - `[String]` - the input you wish to parse
|
| 85 |
+
|
| 86 |
+
##### returns
|
| 87 |
+
See "returns" section in "parse"
|
| 88 |
+
|
| 89 |
+
##### example
|
| 90 |
+
```js
|
| 91 |
+
parseArgv(process.argv);
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### generateHelp(helpOptions)
|
| 95 |
+
`generateHelp` produces help text based on your settings.
|
| 96 |
+
|
| 97 |
+
##### arguments
|
| 98 |
+
* helpOptions - `{showHidden: Boolean, interpolate: Object}` - all options optional
|
| 99 |
+
- `showHidden` specifies whether to show options with `hidden: true` specified, by default it is `false`
|
| 100 |
+
- `interpolate` specify data to be interpolated in `prepend` and `append` text, `{{key}}` is the format - eg. `generateHelp({interpolate:{version: '0.4.2'}})`, will change this `append` text: `Version {{version}}` to `Version 0.4.2`
|
| 101 |
+
|
| 102 |
+
##### returns
|
| 103 |
+
`String` - the generated help text
|
| 104 |
+
|
| 105 |
+
##### example
|
| 106 |
+
```js
|
| 107 |
+
generateHelp(); /*
|
| 108 |
+
"Usage: cmd [options] positional
|
| 109 |
+
|
| 110 |
+
-h, --help displays help
|
| 111 |
+
-c, --count Int number of things
|
| 112 |
+
|
| 113 |
+
Version 1.0.0
|
| 114 |
+
"*/
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
### generateHelpForOption(optionName)
|
| 118 |
+
`generateHelpForOption` produces expanded help text for the specified with `optionName` option. If an `example` was specified for the option, it will be displayed, and if a `longDescription` was specified, it will display that instead of the `description`.
|
| 119 |
+
|
| 120 |
+
##### arguments
|
| 121 |
+
* optionName - `String` - the name of the option to display
|
| 122 |
+
|
| 123 |
+
##### returns
|
| 124 |
+
`String` - the generated help text for the option
|
| 125 |
+
|
| 126 |
+
##### example
|
| 127 |
+
```js
|
| 128 |
+
generateHelpForOption('count'); /*
|
| 129 |
+
"-c, --count Int
|
| 130 |
+
description: number of things
|
| 131 |
+
example: cmd --count 2
|
| 132 |
+
"*/
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
## Settings Format
|
| 136 |
+
When your `require('optionator')`, you get a function that takes in a settings object. This object has the type:
|
| 137 |
+
|
| 138 |
+
{
|
| 139 |
+
prepend: String,
|
| 140 |
+
append: String,
|
| 141 |
+
options: [{heading: String} | {
|
| 142 |
+
option: String,
|
| 143 |
+
alias: [String] | String,
|
| 144 |
+
type: String,
|
| 145 |
+
enum: [String],
|
| 146 |
+
default: String,
|
| 147 |
+
restPositional: Boolean,
|
| 148 |
+
required: Boolean,
|
| 149 |
+
overrideRequired: Boolean,
|
| 150 |
+
dependsOn: [String] | String,
|
| 151 |
+
concatRepeatedArrays: Boolean | (Boolean, Object),
|
| 152 |
+
mergeRepeatedObjects: Boolean,
|
| 153 |
+
description: String,
|
| 154 |
+
longDescription: String,
|
| 155 |
+
example: [String] | String
|
| 156 |
+
}],
|
| 157 |
+
helpStyle: {
|
| 158 |
+
aliasSeparator: String,
|
| 159 |
+
typeSeparator: String,
|
| 160 |
+
descriptionSeparator: String,
|
| 161 |
+
initialIndent: Int,
|
| 162 |
+
secondaryIndent: Int,
|
| 163 |
+
maxPadFactor: Number
|
| 164 |
+
},
|
| 165 |
+
mutuallyExclusive: [[String | [String]]],
|
| 166 |
+
concatRepeatedArrays: Boolean | (Boolean, Object), // deprecated, set in defaults object
|
| 167 |
+
mergeRepeatedObjects: Boolean, // deprecated, set in defaults object
|
| 168 |
+
positionalAnywhere: Boolean,
|
| 169 |
+
typeAliases: Object,
|
| 170 |
+
defaults: Object
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
All of the properties are optional (the `Maybe` has been excluded for brevities sake), except for having either `heading: String` or `option: String` in each object in the `options` array.
|
| 174 |
+
|
| 175 |
+
### Top Level Properties
|
| 176 |
+
* `prepend` is an optional string to be placed before the options in the help text
|
| 177 |
+
* `append` is an optional string to be placed after the options in the help text
|
| 178 |
+
* `options` is a required array specifying your options and headings, the options and headings will be displayed in the order specified
|
| 179 |
+
* `helpStyle` is an optional object which enables you to change the default appearance of some aspects of the help text
|
| 180 |
+
* `mutuallyExclusive` is an optional array of arrays of either strings or arrays of strings. The top level array is a list of rules, each rule is a list of elements - each element can be either a string (the name of an option), or a list of strings (a group of option names) - there will be an error if more than one element is present
|
| 181 |
+
* `concatRepeatedArrays` see description under the "Option Properties" heading - use at the top level is deprecated, if you want to set this for all options, use the `defaults` property
|
| 182 |
+
* `mergeRepeatedObjects` see description under the "Option Properties" heading - use at the top level is deprecated, if you want to set this for all options, use the `defaults` property
|
| 183 |
+
* `positionalAnywhere` is an optional boolean (defaults to `true`) - when `true` it allows positional arguments anywhere, when `false`, all arguments after the first positional one are taken to be positional as well, even if they look like a flag. For example, with `positionalAnywhere: false`, the arguments `--flag --boom 12 --crack` would have two positional arguments: `12` and `--crack`
|
| 184 |
+
* `typeAliases` is an optional object, it allows you to set aliases for types, eg. `{Path: 'String'}` would allow you to use the type `Path` as an alias for the type `String`
|
| 185 |
+
* `defaults` is an optional object following the option properties format, which specifies default values for all options. A default will be overridden if manually set. For example, you can do `default: { type: "String" }` to set the default type of all options to `String`, and then override that default in an individual option by setting the `type` property
|
| 186 |
+
|
| 187 |
+
#### Heading Properties
|
| 188 |
+
* `heading` a required string, the name of the heading
|
| 189 |
+
|
| 190 |
+
#### Option Properties
|
| 191 |
+
* `option` the required name of the option - use dash-case, without the leading dashes
|
| 192 |
+
* `alias` is an optional string or array of strings which specify any aliases for the option
|
| 193 |
+
* `type` is a required string in the [type check](https://github.com/gkz/type-check) [format](https://github.com/gkz/type-check#type-format), this will be used to cast the inputted value and validate it
|
| 194 |
+
* `enum` is an optional array of strings, each string will be parsed by [levn](https://github.com/gkz/levn) - the argument value must be one of the resulting values - each potential value must validate against the specified `type`
|
| 195 |
+
* `default` is a optional string, which will be parsed by [levn](https://github.com/gkz/levn) and used as the default value if none is set - the value must validate against the specified `type`
|
| 196 |
+
* `restPositional` is an optional boolean - if set to `true`, everything after the option will be taken to be a positional argument, even if it looks like a named argument
|
| 197 |
+
* `required` is an optional boolean - if set to `true`, the option parsing will fail if the option is not defined
|
| 198 |
+
* `overrideRequired` is a optional boolean - if set to `true` and the option is used, and there is another option which is required but not set, it will override the need for the required option and there will be no error - this is useful if you have required options and want to use `--help` or `--version` flags
|
| 199 |
+
* `concatRepeatedArrays` is an optional boolean or tuple with boolean and options object (defaults to `false`) - when set to `true` and an option contains an array value and is repeated, the subsequent values for the flag will be appended rather than overwriting the original value - eg. option `g` of type `[String]`: `-g a -g b -g c,d` will result in `['a','b','c','d']`
|
| 200 |
+
|
| 201 |
+
You can supply an options object by giving the following value: `[true, options]`. The one currently supported option is `oneValuePerFlag`, this only allows one array value per flag. This is useful if your potential values contain a comma.
|
| 202 |
+
* `mergeRepeatedObjects` is an optional boolean (defaults to `false`) - when set to `true` and an option contains an object value and is repeated, the subsequent values for the flag will be merged rather than overwriting the original value - eg. option `g` of type `Object`: `-g a:1 -g b:2 -g c:3,d:4` will result in `{a: 1, b: 2, c: 3, d: 4}`
|
| 203 |
+
* `dependsOn` is an optional string or array of strings - if simply a string (the name of another option), it will make sure that that other option is set, if an array of strings, depending on whether `'and'` or `'or'` is first, it will either check whether all (`['and', 'option-a', 'option-b']`), or at least one (`['or', 'option-a', 'option-b']`) other options are set
|
| 204 |
+
* `description` is an optional string, which will be displayed next to the option in the help text
|
| 205 |
+
* `longDescription` is an optional string, it will be displayed instead of the `description` when `generateHelpForOption` is used
|
| 206 |
+
* `example` is an optional string or array of strings with example(s) for the option - these will be displayed when `generateHelpForOption` is used
|
| 207 |
+
|
| 208 |
+
#### Help Style Properties
|
| 209 |
+
* `aliasSeparator` is an optional string, separates multiple names from each other - default: ' ,'
|
| 210 |
+
* `typeSeparator` is an optional string, separates the type from the names - default: ' '
|
| 211 |
+
* `descriptionSeparator` is an optional string , separates the description from the padded name and type - default: ' '
|
| 212 |
+
* `initialIndent` is an optional int - the amount of indent for options - default: 2
|
| 213 |
+
* `secondaryIndent` is an optional int - the amount of indent if wrapped fully (in addition to the initial indent) - default: 4
|
| 214 |
+
* `maxPadFactor` is an optional number - affects the default level of padding for the names/type, it is multiplied by the average of the length of the names/type - default: 1.5
|
| 215 |
+
|
| 216 |
+
## Argument Format
|
| 217 |
+
At the highest level there are two types of arguments: named, and positional.
|
| 218 |
+
|
| 219 |
+
Name arguments of any length are prefixed with `--` (eg. `--go`), and those of one character may be prefixed with either `--` or `-` (eg. `-g`).
|
| 220 |
+
|
| 221 |
+
There are two types of named arguments: boolean flags (eg. `--problemo`, `-p`) which take no value and result in a `true` if they are present, the falsey `undefined` if they are not present, or `false` if present and explicitly prefixed with `no` (eg. `--no-problemo`). Named arguments with values (eg. `--tseries 800`, `-t 800`) are the other type. If the option has a type `Boolean` it will automatically be made into a boolean flag. Any other type results in a named argument that takes a value.
|
| 222 |
+
|
| 223 |
+
For more information about how to properly set types to get the value you want, take a look at the [type check](https://github.com/gkz/type-check) and [levn](https://github.com/gkz/levn) pages.
|
| 224 |
+
|
| 225 |
+
You can group single character arguments that use a single `-`, however all except the last must be boolean flags (which take no value). The last may be a boolean flag, or an argument which takes a value - eg. `-ba 2` is equivalent to `-b -a 2`.
|
| 226 |
+
|
| 227 |
+
Positional arguments are all those values which do not fall under the above - they can be anywhere, not just at the end. For example, in `cmd -b one -a 2 two` where `b` is a boolean flag, and `a` has the type `Number`, there are two positional arguments, `one` and `two`.
|
| 228 |
+
|
| 229 |
+
Everything after an `--` is positional, even if it looks like a named argument.
|
| 230 |
+
|
| 231 |
+
You may optionally use `=` to separate option names from values, for example: `--count=2`.
|
| 232 |
+
|
| 233 |
+
If you specify the option `NUM`, then any argument using a single `-` followed by a number will be valid and will set the value of `NUM`. Eg. `-2` will be parsed into `NUM: 2`.
|
| 234 |
+
|
| 235 |
+
If duplicate named arguments are present, the last one will be taken.
|
| 236 |
+
|
| 237 |
+
## Technical About
|
| 238 |
+
`optionator` is written in [LiveScript](http://livescript.net/) - a language that compiles to JavaScript. It uses [levn](https://github.com/gkz/levn) to cast arguments to their specified type, and uses [type-check](https://github.com/gkz/type-check) to validate values. It also uses the [prelude.ls](http://preludels.com/) library.
|
node_modules/optionator/lib/help.js
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Generated by LiveScript 1.6.0
|
| 2 |
+
(function(){
|
| 3 |
+
var ref$, id, find, sort, min, max, map, unlines, nameToRaw, dasherize, naturalJoin, wordWrap, wordwrap, getPreText, setHelpStyleDefaults, generateHelpForOption, generateHelp;
|
| 4 |
+
ref$ = require('prelude-ls'), id = ref$.id, find = ref$.find, sort = ref$.sort, min = ref$.min, max = ref$.max, map = ref$.map, unlines = ref$.unlines;
|
| 5 |
+
ref$ = require('./util'), nameToRaw = ref$.nameToRaw, dasherize = ref$.dasherize, naturalJoin = ref$.naturalJoin;
|
| 6 |
+
wordWrap = require('word-wrap');
|
| 7 |
+
wordwrap = function(a, b){
|
| 8 |
+
var ref$, indent, width;
|
| 9 |
+
ref$ = b === undefined
|
| 10 |
+
? ['', a - 1]
|
| 11 |
+
: [repeatString$(' ', a), b - a - 1], indent = ref$[0], width = ref$[1];
|
| 12 |
+
return function(text){
|
| 13 |
+
return wordWrap(text, {
|
| 14 |
+
indent: indent,
|
| 15 |
+
width: width,
|
| 16 |
+
trim: true
|
| 17 |
+
});
|
| 18 |
+
};
|
| 19 |
+
};
|
| 20 |
+
getPreText = function(option, arg$, maxWidth){
|
| 21 |
+
var mainName, shortNames, ref$, longNames, type, description, aliasSeparator, typeSeparator, initialIndent, names, namesString, namesStringLen, typeSeparatorString, typeSeparatorStringLen, wrap;
|
| 22 |
+
mainName = option.option, shortNames = (ref$ = option.shortNames) != null
|
| 23 |
+
? ref$
|
| 24 |
+
: [], longNames = (ref$ = option.longNames) != null
|
| 25 |
+
? ref$
|
| 26 |
+
: [], type = option.type, description = option.description;
|
| 27 |
+
aliasSeparator = arg$.aliasSeparator, typeSeparator = arg$.typeSeparator, initialIndent = arg$.initialIndent;
|
| 28 |
+
if (option.negateName) {
|
| 29 |
+
mainName = "no-" + mainName;
|
| 30 |
+
if (longNames) {
|
| 31 |
+
longNames = map(function(it){
|
| 32 |
+
return "no-" + it;
|
| 33 |
+
}, longNames);
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
names = mainName.length === 1
|
| 37 |
+
? [mainName].concat(shortNames, longNames)
|
| 38 |
+
: shortNames.concat([mainName], longNames);
|
| 39 |
+
namesString = map(nameToRaw, names).join(aliasSeparator);
|
| 40 |
+
namesStringLen = namesString.length;
|
| 41 |
+
typeSeparatorString = mainName === 'NUM' ? '::' : typeSeparator;
|
| 42 |
+
typeSeparatorStringLen = typeSeparatorString.length;
|
| 43 |
+
if (maxWidth != null && !option.boolean && initialIndent + namesStringLen + typeSeparatorStringLen + type.length > maxWidth) {
|
| 44 |
+
wrap = wordwrap(initialIndent + namesStringLen + typeSeparatorStringLen, maxWidth);
|
| 45 |
+
return namesString + "" + typeSeparatorString + wrap(type).replace(/^\s+/, '');
|
| 46 |
+
} else {
|
| 47 |
+
return namesString + "" + (option.boolean
|
| 48 |
+
? ''
|
| 49 |
+
: typeSeparatorString + "" + type);
|
| 50 |
+
}
|
| 51 |
+
};
|
| 52 |
+
setHelpStyleDefaults = function(helpStyle){
|
| 53 |
+
helpStyle.aliasSeparator == null && (helpStyle.aliasSeparator = ', ');
|
| 54 |
+
helpStyle.typeSeparator == null && (helpStyle.typeSeparator = ' ');
|
| 55 |
+
helpStyle.descriptionSeparator == null && (helpStyle.descriptionSeparator = ' ');
|
| 56 |
+
helpStyle.initialIndent == null && (helpStyle.initialIndent = 2);
|
| 57 |
+
helpStyle.secondaryIndent == null && (helpStyle.secondaryIndent = 4);
|
| 58 |
+
helpStyle.maxPadFactor == null && (helpStyle.maxPadFactor = 1.5);
|
| 59 |
+
};
|
| 60 |
+
generateHelpForOption = function(getOption, arg$){
|
| 61 |
+
var stdout, helpStyle, ref$;
|
| 62 |
+
stdout = arg$.stdout, helpStyle = (ref$ = arg$.helpStyle) != null
|
| 63 |
+
? ref$
|
| 64 |
+
: {};
|
| 65 |
+
setHelpStyleDefaults(helpStyle);
|
| 66 |
+
return function(optionName){
|
| 67 |
+
var maxWidth, wrap, option, e, pre, defaultString, restPositionalString, description, fullDescription, that, preDescription, descriptionString, exampleString, examples, seperator;
|
| 68 |
+
maxWidth = stdout != null && stdout.isTTY ? stdout.columns - 1 : null;
|
| 69 |
+
wrap = maxWidth ? wordwrap(maxWidth) : id;
|
| 70 |
+
try {
|
| 71 |
+
option = getOption(dasherize(optionName));
|
| 72 |
+
} catch (e$) {
|
| 73 |
+
e = e$;
|
| 74 |
+
return e.message;
|
| 75 |
+
}
|
| 76 |
+
pre = getPreText(option, helpStyle);
|
| 77 |
+
defaultString = option['default'] && !option.negateName ? "\ndefault: " + option['default'] : '';
|
| 78 |
+
restPositionalString = option.restPositional ? 'Everything after this option is considered a positional argument, even if it looks like an option.' : '';
|
| 79 |
+
description = option.longDescription || option.description && sentencize(option.description);
|
| 80 |
+
fullDescription = description && restPositionalString
|
| 81 |
+
? description + " " + restPositionalString
|
| 82 |
+
: (that = description || restPositionalString) ? that : '';
|
| 83 |
+
preDescription = 'description:';
|
| 84 |
+
descriptionString = !fullDescription
|
| 85 |
+
? ''
|
| 86 |
+
: maxWidth && fullDescription.length - 1 - preDescription.length > maxWidth
|
| 87 |
+
? "\n" + preDescription + "\n" + wrap(fullDescription)
|
| 88 |
+
: "\n" + preDescription + " " + fullDescription;
|
| 89 |
+
exampleString = (that = option.example) ? (examples = [].concat(that), examples.length > 1
|
| 90 |
+
? "\nexamples:\n" + unlines(examples)
|
| 91 |
+
: "\nexample: " + examples[0]) : '';
|
| 92 |
+
seperator = defaultString || descriptionString || exampleString ? "\n" + repeatString$('=', pre.length) : '';
|
| 93 |
+
return pre + "" + seperator + defaultString + descriptionString + exampleString;
|
| 94 |
+
};
|
| 95 |
+
};
|
| 96 |
+
generateHelp = function(arg$){
|
| 97 |
+
var options, prepend, append, helpStyle, ref$, stdout, aliasSeparator, typeSeparator, descriptionSeparator, maxPadFactor, initialIndent, secondaryIndent;
|
| 98 |
+
options = arg$.options, prepend = arg$.prepend, append = arg$.append, helpStyle = (ref$ = arg$.helpStyle) != null
|
| 99 |
+
? ref$
|
| 100 |
+
: {}, stdout = arg$.stdout;
|
| 101 |
+
setHelpStyleDefaults(helpStyle);
|
| 102 |
+
aliasSeparator = helpStyle.aliasSeparator, typeSeparator = helpStyle.typeSeparator, descriptionSeparator = helpStyle.descriptionSeparator, maxPadFactor = helpStyle.maxPadFactor, initialIndent = helpStyle.initialIndent, secondaryIndent = helpStyle.secondaryIndent;
|
| 103 |
+
return function(arg$){
|
| 104 |
+
var ref$, showHidden, interpolate, maxWidth, output, out, data, optionCount, totalPreLen, preLens, i$, len$, item, that, pre, descParts, desc, preLen, sortedPreLens, maxPreLen, preLenMean, x, padAmount, descSepLen, fullWrapCount, partialWrapCount, descLen, totalLen, initialSpace, wrapAllFull, i, wrap;
|
| 105 |
+
ref$ = arg$ != null
|
| 106 |
+
? arg$
|
| 107 |
+
: {}, showHidden = ref$.showHidden, interpolate = ref$.interpolate;
|
| 108 |
+
maxWidth = stdout != null && stdout.isTTY ? stdout.columns - 1 : null;
|
| 109 |
+
output = [];
|
| 110 |
+
out = function(it){
|
| 111 |
+
return output.push(it != null ? it : '');
|
| 112 |
+
};
|
| 113 |
+
if (prepend) {
|
| 114 |
+
out(interpolate ? interp(prepend, interpolate) : prepend);
|
| 115 |
+
out();
|
| 116 |
+
}
|
| 117 |
+
data = [];
|
| 118 |
+
optionCount = 0;
|
| 119 |
+
totalPreLen = 0;
|
| 120 |
+
preLens = [];
|
| 121 |
+
for (i$ = 0, len$ = (ref$ = options).length; i$ < len$; ++i$) {
|
| 122 |
+
item = ref$[i$];
|
| 123 |
+
if (showHidden || !item.hidden) {
|
| 124 |
+
if (that = item.heading) {
|
| 125 |
+
data.push({
|
| 126 |
+
type: 'heading',
|
| 127 |
+
value: that
|
| 128 |
+
});
|
| 129 |
+
} else {
|
| 130 |
+
pre = getPreText(item, helpStyle, maxWidth);
|
| 131 |
+
descParts = [];
|
| 132 |
+
if ((that = item.description) != null) {
|
| 133 |
+
descParts.push(that);
|
| 134 |
+
}
|
| 135 |
+
if (that = item['enum']) {
|
| 136 |
+
descParts.push("either: " + naturalJoin(that));
|
| 137 |
+
}
|
| 138 |
+
if (item['default'] && !item.negateName) {
|
| 139 |
+
descParts.push("default: " + item['default']);
|
| 140 |
+
}
|
| 141 |
+
desc = descParts.join(' - ');
|
| 142 |
+
data.push({
|
| 143 |
+
type: 'option',
|
| 144 |
+
pre: pre,
|
| 145 |
+
desc: desc,
|
| 146 |
+
descLen: desc.length
|
| 147 |
+
});
|
| 148 |
+
preLen = pre.length;
|
| 149 |
+
optionCount++;
|
| 150 |
+
totalPreLen += preLen;
|
| 151 |
+
preLens.push(preLen);
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
sortedPreLens = sort(preLens);
|
| 156 |
+
maxPreLen = sortedPreLens[sortedPreLens.length - 1];
|
| 157 |
+
preLenMean = initialIndent + totalPreLen / optionCount;
|
| 158 |
+
x = optionCount > 2 ? min(preLenMean * maxPadFactor, maxPreLen) : maxPreLen;
|
| 159 |
+
for (i$ = sortedPreLens.length - 1; i$ >= 0; --i$) {
|
| 160 |
+
preLen = sortedPreLens[i$];
|
| 161 |
+
if (preLen <= x) {
|
| 162 |
+
padAmount = preLen;
|
| 163 |
+
break;
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
descSepLen = descriptionSeparator.length;
|
| 167 |
+
if (maxWidth != null) {
|
| 168 |
+
fullWrapCount = 0;
|
| 169 |
+
partialWrapCount = 0;
|
| 170 |
+
for (i$ = 0, len$ = data.length; i$ < len$; ++i$) {
|
| 171 |
+
item = data[i$];
|
| 172 |
+
if (item.type === 'option') {
|
| 173 |
+
pre = item.pre, desc = item.desc, descLen = item.descLen;
|
| 174 |
+
if (descLen === 0) {
|
| 175 |
+
item.wrap = 'none';
|
| 176 |
+
} else {
|
| 177 |
+
preLen = max(padAmount, pre.length) + initialIndent + descSepLen;
|
| 178 |
+
totalLen = preLen + descLen;
|
| 179 |
+
if (totalLen > maxWidth) {
|
| 180 |
+
if (descLen / 2.5 > maxWidth - preLen) {
|
| 181 |
+
fullWrapCount++;
|
| 182 |
+
item.wrap = 'full';
|
| 183 |
+
} else {
|
| 184 |
+
partialWrapCount++;
|
| 185 |
+
item.wrap = 'partial';
|
| 186 |
+
}
|
| 187 |
+
} else {
|
| 188 |
+
item.wrap = 'none';
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
}
|
| 194 |
+
initialSpace = repeatString$(' ', initialIndent);
|
| 195 |
+
wrapAllFull = optionCount > 1 && fullWrapCount + partialWrapCount * 0.5 > optionCount * 0.5;
|
| 196 |
+
for (i$ = 0, len$ = data.length; i$ < len$; ++i$) {
|
| 197 |
+
i = i$;
|
| 198 |
+
item = data[i$];
|
| 199 |
+
if (item.type === 'heading') {
|
| 200 |
+
if (i !== 0) {
|
| 201 |
+
out();
|
| 202 |
+
}
|
| 203 |
+
out(item.value + ":");
|
| 204 |
+
} else {
|
| 205 |
+
pre = item.pre, desc = item.desc, descLen = item.descLen, wrap = item.wrap;
|
| 206 |
+
if (maxWidth != null) {
|
| 207 |
+
if (wrapAllFull || wrap === 'full') {
|
| 208 |
+
wrap = wordwrap(initialIndent + secondaryIndent, maxWidth);
|
| 209 |
+
out(initialSpace + "" + pre + "\n" + wrap(desc));
|
| 210 |
+
continue;
|
| 211 |
+
} else if (wrap === 'partial') {
|
| 212 |
+
wrap = wordwrap(initialIndent + descSepLen + max(padAmount, pre.length), maxWidth);
|
| 213 |
+
out(initialSpace + "" + pad(pre, padAmount) + descriptionSeparator + wrap(desc).replace(/^\s+/, ''));
|
| 214 |
+
continue;
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
if (descLen === 0) {
|
| 218 |
+
out(initialSpace + "" + pre);
|
| 219 |
+
} else {
|
| 220 |
+
out(initialSpace + "" + pad(pre, padAmount) + descriptionSeparator + desc);
|
| 221 |
+
}
|
| 222 |
+
}
|
| 223 |
+
}
|
| 224 |
+
if (append) {
|
| 225 |
+
out();
|
| 226 |
+
out(interpolate ? interp(append, interpolate) : append);
|
| 227 |
+
}
|
| 228 |
+
return unlines(output);
|
| 229 |
+
};
|
| 230 |
+
};
|
| 231 |
+
function pad(str, num){
|
| 232 |
+
var len, padAmount;
|
| 233 |
+
len = str.length;
|
| 234 |
+
padAmount = num - len;
|
| 235 |
+
return str + "" + repeatString$(' ', padAmount > 0 ? padAmount : 0);
|
| 236 |
+
}
|
| 237 |
+
function sentencize(str){
|
| 238 |
+
var first, rest, period;
|
| 239 |
+
first = str.charAt(0).toUpperCase();
|
| 240 |
+
rest = str.slice(1);
|
| 241 |
+
period = /[\.!\?]$/.test(str) ? '' : '.';
|
| 242 |
+
return first + "" + rest + period;
|
| 243 |
+
}
|
| 244 |
+
function interp(string, object){
|
| 245 |
+
return string.replace(/{{([a-zA-Z$_][a-zA-Z$_0-9]*)}}/g, function(arg$, key){
|
| 246 |
+
var ref$;
|
| 247 |
+
return (ref$ = object[key]) != null
|
| 248 |
+
? ref$
|
| 249 |
+
: "{{" + key + "}}";
|
| 250 |
+
});
|
| 251 |
+
}
|
| 252 |
+
module.exports = {
|
| 253 |
+
generateHelp: generateHelp,
|
| 254 |
+
generateHelpForOption: generateHelpForOption
|
| 255 |
+
};
|
| 256 |
+
function repeatString$(str, n){
|
| 257 |
+
for (var r = ''; n > 0; (n >>= 1) && (str += str)) if (n & 1) r += str;
|
| 258 |
+
return r;
|
| 259 |
+
}
|
| 260 |
+
}).call(this);
|
node_modules/optionator/lib/index.js
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Generated by LiveScript 1.6.0
|
| 2 |
+
(function(){
|
| 3 |
+
var VERSION, ref$, id, map, compact, any, groupBy, partition, chars, isItNaN, keys, Obj, camelize, deepIs, closestString, nameToRaw, dasherize, naturalJoin, generateHelp, generateHelpForOption, parsedTypeCheck, parseType, parseLevn, camelizeKeys, parseString, main, toString$ = {}.toString, slice$ = [].slice, arrayFrom$ = Array.from || function(x){return slice$.call(x);};
|
| 4 |
+
VERSION = '0.9.4';
|
| 5 |
+
ref$ = require('prelude-ls'), id = ref$.id, map = ref$.map, compact = ref$.compact, any = ref$.any, groupBy = ref$.groupBy, partition = ref$.partition, chars = ref$.chars, isItNaN = ref$.isItNaN, keys = ref$.keys, Obj = ref$.Obj, camelize = ref$.camelize;
|
| 6 |
+
deepIs = require('deep-is');
|
| 7 |
+
ref$ = require('./util'), closestString = ref$.closestString, nameToRaw = ref$.nameToRaw, dasherize = ref$.dasherize, naturalJoin = ref$.naturalJoin;
|
| 8 |
+
ref$ = require('./help'), generateHelp = ref$.generateHelp, generateHelpForOption = ref$.generateHelpForOption;
|
| 9 |
+
ref$ = require('type-check'), parsedTypeCheck = ref$.parsedTypeCheck, parseType = ref$.parseType;
|
| 10 |
+
parseLevn = require('levn').parsedTypeParse;
|
| 11 |
+
camelizeKeys = function(obj){
|
| 12 |
+
var key, value, resultObj$ = {};
|
| 13 |
+
for (key in obj) {
|
| 14 |
+
value = obj[key];
|
| 15 |
+
resultObj$[camelize(key)] = value;
|
| 16 |
+
}
|
| 17 |
+
return resultObj$;
|
| 18 |
+
};
|
| 19 |
+
parseString = function(string){
|
| 20 |
+
var assignOpt, regex, replaceRegex, result;
|
| 21 |
+
assignOpt = '--?[a-zA-Z][-a-z-A-Z0-9]*=';
|
| 22 |
+
regex = RegExp('(?:' + assignOpt + ')?(?:\'(?:\\\\\'|[^\'])+\'|"(?:\\\\"|[^"])+")|[^\'"\\s]+', 'g');
|
| 23 |
+
replaceRegex = RegExp('^(' + assignOpt + ')?[\'"]([\\s\\S]*)[\'"]$');
|
| 24 |
+
result = map(function(it){
|
| 25 |
+
return it.replace(replaceRegex, '$1$2');
|
| 26 |
+
}, string.match(regex) || []);
|
| 27 |
+
return result;
|
| 28 |
+
};
|
| 29 |
+
main = function(libOptions){
|
| 30 |
+
var opts, defaults, required, traverse, getOption, parse;
|
| 31 |
+
opts = {};
|
| 32 |
+
defaults = {};
|
| 33 |
+
required = [];
|
| 34 |
+
if (toString$.call(libOptions.stdout).slice(8, -1) === 'Undefined') {
|
| 35 |
+
libOptions.stdout = process.stdout;
|
| 36 |
+
}
|
| 37 |
+
libOptions.positionalAnywhere == null && (libOptions.positionalAnywhere = true);
|
| 38 |
+
libOptions.typeAliases == null && (libOptions.typeAliases = {});
|
| 39 |
+
libOptions.defaults == null && (libOptions.defaults = {});
|
| 40 |
+
if (libOptions.concatRepeatedArrays != null) {
|
| 41 |
+
libOptions.defaults.concatRepeatedArrays = libOptions.concatRepeatedArrays;
|
| 42 |
+
}
|
| 43 |
+
if (libOptions.mergeRepeatedObjects != null) {
|
| 44 |
+
libOptions.defaults.mergeRepeatedObjects = libOptions.mergeRepeatedObjects;
|
| 45 |
+
}
|
| 46 |
+
traverse = function(options){
|
| 47 |
+
var i$, len$, option, name, k, ref$, v, type, that, e, parsedPossibilities, parsedType, j$, len1$, possibility, rawDependsType, dependsOpts, dependsType, cra, alias, shortNames, longNames;
|
| 48 |
+
if (toString$.call(options).slice(8, -1) !== 'Array') {
|
| 49 |
+
throw new Error('No options defined.');
|
| 50 |
+
}
|
| 51 |
+
for (i$ = 0, len$ = options.length; i$ < len$; ++i$) {
|
| 52 |
+
option = options[i$];
|
| 53 |
+
if (option.heading == null) {
|
| 54 |
+
name = option.option;
|
| 55 |
+
if (opts[name] != null) {
|
| 56 |
+
throw new Error("Option '" + name + "' already defined.");
|
| 57 |
+
}
|
| 58 |
+
for (k in ref$ = libOptions.defaults) {
|
| 59 |
+
v = ref$[k];
|
| 60 |
+
option[k] == null && (option[k] = v);
|
| 61 |
+
}
|
| 62 |
+
if (option.type === 'Boolean') {
|
| 63 |
+
option.boolean == null && (option.boolean = true);
|
| 64 |
+
}
|
| 65 |
+
if (option.parsedType == null) {
|
| 66 |
+
if (!option.type) {
|
| 67 |
+
throw new Error("No type defined for option '" + name + "'.");
|
| 68 |
+
}
|
| 69 |
+
try {
|
| 70 |
+
type = (that = libOptions.typeAliases[option.type]) != null
|
| 71 |
+
? that
|
| 72 |
+
: option.type;
|
| 73 |
+
option.parsedType = parseType(type);
|
| 74 |
+
} catch (e$) {
|
| 75 |
+
e = e$;
|
| 76 |
+
throw new Error("Option '" + name + "': Error parsing type '" + option.type + "': " + e.message);
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
if (option['default']) {
|
| 80 |
+
try {
|
| 81 |
+
defaults[name] = parseLevn(option.parsedType, option['default']);
|
| 82 |
+
} catch (e$) {
|
| 83 |
+
e = e$;
|
| 84 |
+
throw new Error("Option '" + name + "': Error parsing default value '" + option['default'] + "' for type '" + option.type + "': " + e.message);
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
if (option['enum'] && !option.parsedPossiblities) {
|
| 88 |
+
parsedPossibilities = [];
|
| 89 |
+
parsedType = option.parsedType;
|
| 90 |
+
for (j$ = 0, len1$ = (ref$ = option['enum']).length; j$ < len1$; ++j$) {
|
| 91 |
+
possibility = ref$[j$];
|
| 92 |
+
try {
|
| 93 |
+
parsedPossibilities.push(parseLevn(parsedType, possibility));
|
| 94 |
+
} catch (e$) {
|
| 95 |
+
e = e$;
|
| 96 |
+
throw new Error("Option '" + name + "': Error parsing enum value '" + possibility + "' for type '" + option.type + "': " + e.message);
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
option.parsedPossibilities = parsedPossibilities;
|
| 100 |
+
}
|
| 101 |
+
if (that = option.dependsOn) {
|
| 102 |
+
if (that.length) {
|
| 103 |
+
ref$ = [].concat(option.dependsOn), rawDependsType = ref$[0], dependsOpts = slice$.call(ref$, 1);
|
| 104 |
+
dependsType = rawDependsType.toLowerCase();
|
| 105 |
+
if (dependsOpts.length) {
|
| 106 |
+
if (dependsType === 'and' || dependsType === 'or') {
|
| 107 |
+
option.dependsOn = [dependsType].concat(arrayFrom$(dependsOpts));
|
| 108 |
+
} else {
|
| 109 |
+
throw new Error("Option '" + name + "': If you have more than one dependency, you must specify either 'and' or 'or'");
|
| 110 |
+
}
|
| 111 |
+
} else {
|
| 112 |
+
if ((ref$ = dependsType.toLowerCase()) === 'and' || ref$ === 'or') {
|
| 113 |
+
option.dependsOn = null;
|
| 114 |
+
} else {
|
| 115 |
+
option.dependsOn = ['and', rawDependsType];
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
} else {
|
| 119 |
+
option.dependsOn = null;
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
if (option.required) {
|
| 123 |
+
required.push(name);
|
| 124 |
+
}
|
| 125 |
+
opts[name] = option;
|
| 126 |
+
if (option.concatRepeatedArrays != null) {
|
| 127 |
+
cra = option.concatRepeatedArrays;
|
| 128 |
+
if ('Boolean' === toString$.call(cra).slice(8, -1)) {
|
| 129 |
+
option.concatRepeatedArrays = [cra, {}];
|
| 130 |
+
} else if (cra.length === 1) {
|
| 131 |
+
option.concatRepeatedArrays = [cra[0], {}];
|
| 132 |
+
} else if (cra.length !== 2) {
|
| 133 |
+
throw new Error("Invalid setting for concatRepeatedArrays");
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
if (option.alias || option.aliases) {
|
| 137 |
+
if (name === 'NUM') {
|
| 138 |
+
throw new Error("-NUM option can't have aliases.");
|
| 139 |
+
}
|
| 140 |
+
if (option.alias) {
|
| 141 |
+
option.aliases == null && (option.aliases = [].concat(option.alias));
|
| 142 |
+
}
|
| 143 |
+
for (j$ = 0, len1$ = (ref$ = option.aliases).length; j$ < len1$; ++j$) {
|
| 144 |
+
alias = ref$[j$];
|
| 145 |
+
if (opts[alias] != null) {
|
| 146 |
+
throw new Error("Option '" + alias + "' already defined.");
|
| 147 |
+
}
|
| 148 |
+
opts[alias] = option;
|
| 149 |
+
}
|
| 150 |
+
ref$ = partition(fn$, option.aliases), shortNames = ref$[0], longNames = ref$[1];
|
| 151 |
+
option.shortNames == null && (option.shortNames = shortNames);
|
| 152 |
+
option.longNames == null && (option.longNames = longNames);
|
| 153 |
+
}
|
| 154 |
+
if ((!option.aliases || option.shortNames.length === 0) && option.type === 'Boolean' && option['default'] === 'true') {
|
| 155 |
+
option.negateName = true;
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
function fn$(it){
|
| 160 |
+
return it.length === 1;
|
| 161 |
+
}
|
| 162 |
+
};
|
| 163 |
+
traverse(libOptions.options);
|
| 164 |
+
getOption = function(name){
|
| 165 |
+
var opt, possiblyMeant;
|
| 166 |
+
opt = opts[name];
|
| 167 |
+
if (opt == null) {
|
| 168 |
+
possiblyMeant = closestString(keys(opts), name);
|
| 169 |
+
throw new Error("Invalid option '" + nameToRaw(name) + "'" + (possiblyMeant ? " - perhaps you meant '" + nameToRaw(possiblyMeant) + "'?" : '.'));
|
| 170 |
+
}
|
| 171 |
+
return opt;
|
| 172 |
+
};
|
| 173 |
+
parse = function(input, arg$){
|
| 174 |
+
var slice, obj, positional, restPositional, overrideRequired, prop, setValue, setDefaults, checkRequired, mutuallyExclusiveError, checkMutuallyExclusive, checkDependency, checkDependencies, checkProp, args, key, value, option, ref$, i$, len$, arg, that, result, short, argName, usingAssign, val, flags, len, j$, len1$, i, flag, opt, name, valPrime, negated, noedName;
|
| 175 |
+
slice = (arg$ != null
|
| 176 |
+
? arg$
|
| 177 |
+
: {}).slice;
|
| 178 |
+
obj = {};
|
| 179 |
+
positional = [];
|
| 180 |
+
restPositional = false;
|
| 181 |
+
overrideRequired = false;
|
| 182 |
+
prop = null;
|
| 183 |
+
setValue = function(name, value){
|
| 184 |
+
var opt, val, cra, e, currentType;
|
| 185 |
+
opt = getOption(name);
|
| 186 |
+
if (opt.boolean) {
|
| 187 |
+
val = value;
|
| 188 |
+
} else {
|
| 189 |
+
try {
|
| 190 |
+
cra = opt.concatRepeatedArrays;
|
| 191 |
+
if (cra != null && cra[0] && cra[1].oneValuePerFlag && opt.parsedType.length === 1 && opt.parsedType[0].structure === 'array') {
|
| 192 |
+
val = [parseLevn(opt.parsedType[0].of, value)];
|
| 193 |
+
} else {
|
| 194 |
+
val = parseLevn(opt.parsedType, value);
|
| 195 |
+
}
|
| 196 |
+
} catch (e$) {
|
| 197 |
+
e = e$;
|
| 198 |
+
throw new Error("Invalid value for option '" + name + "' - expected type " + opt.type + ", received value: " + value + ".");
|
| 199 |
+
}
|
| 200 |
+
if (opt['enum'] && !any(function(it){
|
| 201 |
+
return deepIs(it, val);
|
| 202 |
+
}, opt.parsedPossibilities)) {
|
| 203 |
+
throw new Error("Option " + name + ": '" + val + "' not one of " + naturalJoin(opt['enum']) + ".");
|
| 204 |
+
}
|
| 205 |
+
}
|
| 206 |
+
currentType = toString$.call(obj[name]).slice(8, -1);
|
| 207 |
+
if (obj[name] != null) {
|
| 208 |
+
if (opt.concatRepeatedArrays != null && opt.concatRepeatedArrays[0] && currentType === 'Array') {
|
| 209 |
+
obj[name] = obj[name].concat(val);
|
| 210 |
+
} else if (opt.mergeRepeatedObjects && currentType === 'Object') {
|
| 211 |
+
import$(obj[name], val);
|
| 212 |
+
} else {
|
| 213 |
+
obj[name] = val;
|
| 214 |
+
}
|
| 215 |
+
} else {
|
| 216 |
+
obj[name] = val;
|
| 217 |
+
}
|
| 218 |
+
if (opt.restPositional) {
|
| 219 |
+
restPositional = true;
|
| 220 |
+
}
|
| 221 |
+
if (opt.overrideRequired) {
|
| 222 |
+
overrideRequired = true;
|
| 223 |
+
}
|
| 224 |
+
};
|
| 225 |
+
setDefaults = function(){
|
| 226 |
+
var name, ref$, value;
|
| 227 |
+
for (name in ref$ = defaults) {
|
| 228 |
+
value = ref$[name];
|
| 229 |
+
if (obj[name] == null) {
|
| 230 |
+
obj[name] = value;
|
| 231 |
+
}
|
| 232 |
+
}
|
| 233 |
+
};
|
| 234 |
+
checkRequired = function(){
|
| 235 |
+
var i$, ref$, len$, name;
|
| 236 |
+
if (overrideRequired) {
|
| 237 |
+
return;
|
| 238 |
+
}
|
| 239 |
+
for (i$ = 0, len$ = (ref$ = required).length; i$ < len$; ++i$) {
|
| 240 |
+
name = ref$[i$];
|
| 241 |
+
if (!obj[name]) {
|
| 242 |
+
throw new Error("Option " + nameToRaw(name) + " is required.");
|
| 243 |
+
}
|
| 244 |
+
}
|
| 245 |
+
};
|
| 246 |
+
mutuallyExclusiveError = function(first, second){
|
| 247 |
+
throw new Error("The options " + nameToRaw(first) + " and " + nameToRaw(second) + " are mutually exclusive - you cannot use them at the same time.");
|
| 248 |
+
};
|
| 249 |
+
checkMutuallyExclusive = function(){
|
| 250 |
+
var rules, i$, len$, rule, present, j$, len1$, element, k$, len2$, opt;
|
| 251 |
+
rules = libOptions.mutuallyExclusive;
|
| 252 |
+
if (!rules) {
|
| 253 |
+
return;
|
| 254 |
+
}
|
| 255 |
+
for (i$ = 0, len$ = rules.length; i$ < len$; ++i$) {
|
| 256 |
+
rule = rules[i$];
|
| 257 |
+
present = null;
|
| 258 |
+
for (j$ = 0, len1$ = rule.length; j$ < len1$; ++j$) {
|
| 259 |
+
element = rule[j$];
|
| 260 |
+
if (toString$.call(element).slice(8, -1) === 'Array') {
|
| 261 |
+
for (k$ = 0, len2$ = element.length; k$ < len2$; ++k$) {
|
| 262 |
+
opt = element[k$];
|
| 263 |
+
if (opt in obj) {
|
| 264 |
+
if (present != null) {
|
| 265 |
+
mutuallyExclusiveError(present, opt);
|
| 266 |
+
} else {
|
| 267 |
+
present = opt;
|
| 268 |
+
break;
|
| 269 |
+
}
|
| 270 |
+
}
|
| 271 |
+
}
|
| 272 |
+
} else {
|
| 273 |
+
if (element in obj) {
|
| 274 |
+
if (present != null) {
|
| 275 |
+
mutuallyExclusiveError(present, element);
|
| 276 |
+
} else {
|
| 277 |
+
present = element;
|
| 278 |
+
}
|
| 279 |
+
}
|
| 280 |
+
}
|
| 281 |
+
}
|
| 282 |
+
}
|
| 283 |
+
};
|
| 284 |
+
checkDependency = function(option){
|
| 285 |
+
var dependsOn, type, targetOptionNames, i$, len$, targetOptionName, targetOption;
|
| 286 |
+
dependsOn = option.dependsOn;
|
| 287 |
+
if (!dependsOn || option.dependenciesMet) {
|
| 288 |
+
return true;
|
| 289 |
+
}
|
| 290 |
+
type = dependsOn[0], targetOptionNames = slice$.call(dependsOn, 1);
|
| 291 |
+
for (i$ = 0, len$ = targetOptionNames.length; i$ < len$; ++i$) {
|
| 292 |
+
targetOptionName = targetOptionNames[i$];
|
| 293 |
+
targetOption = obj[targetOptionName];
|
| 294 |
+
if (targetOption && checkDependency(targetOption)) {
|
| 295 |
+
if (type === 'or') {
|
| 296 |
+
return true;
|
| 297 |
+
}
|
| 298 |
+
} else if (type === 'and') {
|
| 299 |
+
throw new Error("The option '" + option.option + "' did not have its dependencies met.");
|
| 300 |
+
}
|
| 301 |
+
}
|
| 302 |
+
if (type === 'and') {
|
| 303 |
+
return true;
|
| 304 |
+
} else {
|
| 305 |
+
throw new Error("The option '" + option.option + "' did not meet any of its dependencies.");
|
| 306 |
+
}
|
| 307 |
+
};
|
| 308 |
+
checkDependencies = function(){
|
| 309 |
+
var name;
|
| 310 |
+
for (name in obj) {
|
| 311 |
+
checkDependency(opts[name]);
|
| 312 |
+
}
|
| 313 |
+
};
|
| 314 |
+
checkProp = function(){
|
| 315 |
+
if (prop) {
|
| 316 |
+
throw new Error("Value for '" + prop + "' of type '" + getOption(prop).type + "' required.");
|
| 317 |
+
}
|
| 318 |
+
};
|
| 319 |
+
switch (toString$.call(input).slice(8, -1)) {
|
| 320 |
+
case 'String':
|
| 321 |
+
args = parseString(input.slice(slice != null ? slice : 0));
|
| 322 |
+
break;
|
| 323 |
+
case 'Array':
|
| 324 |
+
args = input.slice(slice != null ? slice : 2);
|
| 325 |
+
break;
|
| 326 |
+
case 'Object':
|
| 327 |
+
obj = {};
|
| 328 |
+
for (key in input) {
|
| 329 |
+
value = input[key];
|
| 330 |
+
if (key !== '_') {
|
| 331 |
+
option = getOption(dasherize(key));
|
| 332 |
+
if (parsedTypeCheck(option.parsedType, value)) {
|
| 333 |
+
obj[option.option] = value;
|
| 334 |
+
} else {
|
| 335 |
+
throw new Error("Option '" + option.option + "': Invalid type for '" + value + "' - expected type '" + option.type + "'.");
|
| 336 |
+
}
|
| 337 |
+
}
|
| 338 |
+
}
|
| 339 |
+
checkMutuallyExclusive();
|
| 340 |
+
checkDependencies();
|
| 341 |
+
setDefaults();
|
| 342 |
+
checkRequired();
|
| 343 |
+
return ref$ = camelizeKeys(obj), ref$._ = input._ || [], ref$;
|
| 344 |
+
default:
|
| 345 |
+
throw new Error("Invalid argument to 'parse': " + input + ".");
|
| 346 |
+
}
|
| 347 |
+
for (i$ = 0, len$ = args.length; i$ < len$; ++i$) {
|
| 348 |
+
arg = args[i$];
|
| 349 |
+
if (arg === '--') {
|
| 350 |
+
restPositional = true;
|
| 351 |
+
} else if (restPositional) {
|
| 352 |
+
positional.push(arg);
|
| 353 |
+
} else {
|
| 354 |
+
if (that = arg.match(/^(--?)([a-zA-Z][-a-zA-Z0-9]*)(=)?(.*)?$/)) {
|
| 355 |
+
result = that;
|
| 356 |
+
checkProp();
|
| 357 |
+
short = result[1].length === 1;
|
| 358 |
+
argName = result[2];
|
| 359 |
+
usingAssign = result[3] != null;
|
| 360 |
+
val = result[4];
|
| 361 |
+
if (usingAssign && val == null) {
|
| 362 |
+
throw new Error("No value for '" + argName + "' specified.");
|
| 363 |
+
}
|
| 364 |
+
if (short) {
|
| 365 |
+
flags = chars(argName);
|
| 366 |
+
len = flags.length;
|
| 367 |
+
for (j$ = 0, len1$ = flags.length; j$ < len1$; ++j$) {
|
| 368 |
+
i = j$;
|
| 369 |
+
flag = flags[j$];
|
| 370 |
+
opt = getOption(flag);
|
| 371 |
+
name = opt.option;
|
| 372 |
+
if (restPositional) {
|
| 373 |
+
positional.push(flag);
|
| 374 |
+
} else if (i === len - 1) {
|
| 375 |
+
if (usingAssign) {
|
| 376 |
+
valPrime = opt.boolean ? parseLevn([{
|
| 377 |
+
type: 'Boolean'
|
| 378 |
+
}], val) : val;
|
| 379 |
+
setValue(name, valPrime);
|
| 380 |
+
} else if (opt.boolean) {
|
| 381 |
+
setValue(name, true);
|
| 382 |
+
} else {
|
| 383 |
+
prop = name;
|
| 384 |
+
}
|
| 385 |
+
} else if (opt.boolean) {
|
| 386 |
+
setValue(name, true);
|
| 387 |
+
} else {
|
| 388 |
+
throw new Error("Can't set argument '" + flag + "' when not last flag in a group of short flags.");
|
| 389 |
+
}
|
| 390 |
+
}
|
| 391 |
+
} else {
|
| 392 |
+
negated = false;
|
| 393 |
+
if (that = argName.match(/^no-(.+)$/)) {
|
| 394 |
+
negated = true;
|
| 395 |
+
noedName = that[1];
|
| 396 |
+
opt = getOption(noedName);
|
| 397 |
+
} else {
|
| 398 |
+
opt = getOption(argName);
|
| 399 |
+
}
|
| 400 |
+
name = opt.option;
|
| 401 |
+
if (opt.boolean) {
|
| 402 |
+
valPrime = usingAssign ? parseLevn([{
|
| 403 |
+
type: 'Boolean'
|
| 404 |
+
}], val) : true;
|
| 405 |
+
if (negated) {
|
| 406 |
+
setValue(name, !valPrime);
|
| 407 |
+
} else {
|
| 408 |
+
setValue(name, valPrime);
|
| 409 |
+
}
|
| 410 |
+
} else {
|
| 411 |
+
if (negated) {
|
| 412 |
+
throw new Error("Only use 'no-' prefix for Boolean options, not with '" + noedName + "'.");
|
| 413 |
+
}
|
| 414 |
+
if (usingAssign) {
|
| 415 |
+
setValue(name, val);
|
| 416 |
+
} else {
|
| 417 |
+
prop = name;
|
| 418 |
+
}
|
| 419 |
+
}
|
| 420 |
+
}
|
| 421 |
+
} else if (that = arg.match(/^-([0-9]+(?:\.[0-9]+)?)$/)) {
|
| 422 |
+
opt = opts.NUM;
|
| 423 |
+
if (!opt) {
|
| 424 |
+
throw new Error('No -NUM option defined.');
|
| 425 |
+
}
|
| 426 |
+
setValue(opt.option, that[1]);
|
| 427 |
+
} else {
|
| 428 |
+
if (prop) {
|
| 429 |
+
setValue(prop, arg);
|
| 430 |
+
prop = null;
|
| 431 |
+
} else {
|
| 432 |
+
positional.push(arg);
|
| 433 |
+
if (!libOptions.positionalAnywhere) {
|
| 434 |
+
restPositional = true;
|
| 435 |
+
}
|
| 436 |
+
}
|
| 437 |
+
}
|
| 438 |
+
}
|
| 439 |
+
}
|
| 440 |
+
checkProp();
|
| 441 |
+
checkMutuallyExclusive();
|
| 442 |
+
checkDependencies();
|
| 443 |
+
setDefaults();
|
| 444 |
+
checkRequired();
|
| 445 |
+
return ref$ = camelizeKeys(obj), ref$._ = positional, ref$;
|
| 446 |
+
};
|
| 447 |
+
return {
|
| 448 |
+
parse: parse,
|
| 449 |
+
parseArgv: function(it){
|
| 450 |
+
return parse(it, {
|
| 451 |
+
slice: 2
|
| 452 |
+
});
|
| 453 |
+
},
|
| 454 |
+
generateHelp: generateHelp(libOptions),
|
| 455 |
+
generateHelpForOption: generateHelpForOption(getOption, libOptions)
|
| 456 |
+
};
|
| 457 |
+
};
|
| 458 |
+
main.VERSION = VERSION;
|
| 459 |
+
module.exports = main;
|
| 460 |
+
function import$(obj, src){
|
| 461 |
+
var own = {}.hasOwnProperty;
|
| 462 |
+
for (var key in src) if (own.call(src, key)) obj[key] = src[key];
|
| 463 |
+
return obj;
|
| 464 |
+
}
|
| 465 |
+
}).call(this);
|
node_modules/optionator/lib/util.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Generated by LiveScript 1.6.0
|
| 2 |
+
(function(){
|
| 3 |
+
var prelude, map, sortBy, fl, closestString, nameToRaw, dasherize, naturalJoin;
|
| 4 |
+
prelude = require('prelude-ls'), map = prelude.map, sortBy = prelude.sortBy;
|
| 5 |
+
fl = require('fast-levenshtein');
|
| 6 |
+
closestString = function(possibilities, input){
|
| 7 |
+
var distances, ref$, string, distance;
|
| 8 |
+
if (!possibilities.length) {
|
| 9 |
+
return;
|
| 10 |
+
}
|
| 11 |
+
distances = map(function(it){
|
| 12 |
+
var ref$, longer, shorter;
|
| 13 |
+
ref$ = input.length > it.length
|
| 14 |
+
? [input, it]
|
| 15 |
+
: [it, input], longer = ref$[0], shorter = ref$[1];
|
| 16 |
+
return {
|
| 17 |
+
string: it,
|
| 18 |
+
distance: fl.get(longer, shorter)
|
| 19 |
+
};
|
| 20 |
+
})(
|
| 21 |
+
possibilities);
|
| 22 |
+
ref$ = sortBy(function(it){
|
| 23 |
+
return it.distance;
|
| 24 |
+
}, distances)[0], string = ref$.string, distance = ref$.distance;
|
| 25 |
+
return string;
|
| 26 |
+
};
|
| 27 |
+
nameToRaw = function(name){
|
| 28 |
+
if (name.length === 1 || name === 'NUM') {
|
| 29 |
+
return "-" + name;
|
| 30 |
+
} else {
|
| 31 |
+
return "--" + name;
|
| 32 |
+
}
|
| 33 |
+
};
|
| 34 |
+
dasherize = function(string){
|
| 35 |
+
if (/^[A-Z]/.test(string)) {
|
| 36 |
+
return string;
|
| 37 |
+
} else {
|
| 38 |
+
return prelude.dasherize(string);
|
| 39 |
+
}
|
| 40 |
+
};
|
| 41 |
+
naturalJoin = function(array){
|
| 42 |
+
if (array.length < 3) {
|
| 43 |
+
return array.join(' or ');
|
| 44 |
+
} else {
|
| 45 |
+
return array.slice(0, -1).join(', ') + ", or " + array[array.length - 1];
|
| 46 |
+
}
|
| 47 |
+
};
|
| 48 |
+
module.exports = {
|
| 49 |
+
closestString: closestString,
|
| 50 |
+
nameToRaw: nameToRaw,
|
| 51 |
+
dasherize: dasherize,
|
| 52 |
+
naturalJoin: naturalJoin
|
| 53 |
+
};
|
| 54 |
+
}).call(this);
|
node_modules/optionator/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "optionator",
|
| 3 |
+
"version": "0.9.4",
|
| 4 |
+
"author": "George Zahariev <z@georgezahariev.com>",
|
| 5 |
+
"description": "option parsing and help generation",
|
| 6 |
+
"homepage": "https://github.com/gkz/optionator",
|
| 7 |
+
"keywords": [
|
| 8 |
+
"options",
|
| 9 |
+
"flags",
|
| 10 |
+
"option parsing",
|
| 11 |
+
"cli"
|
| 12 |
+
],
|
| 13 |
+
"files": [
|
| 14 |
+
"lib",
|
| 15 |
+
"README.md",
|
| 16 |
+
"LICENSE"
|
| 17 |
+
],
|
| 18 |
+
"main": "./lib/",
|
| 19 |
+
"bugs": "https://github.com/gkz/optionator/issues",
|
| 20 |
+
"license": "MIT",
|
| 21 |
+
"engines": {
|
| 22 |
+
"node": ">= 0.8.0"
|
| 23 |
+
},
|
| 24 |
+
"repository": {
|
| 25 |
+
"type": "git",
|
| 26 |
+
"url": "git://github.com/gkz/optionator.git"
|
| 27 |
+
},
|
| 28 |
+
"scripts": {
|
| 29 |
+
"test": "make test"
|
| 30 |
+
},
|
| 31 |
+
"dependencies": {
|
| 32 |
+
"prelude-ls": "^1.2.1",
|
| 33 |
+
"deep-is": "^0.1.3",
|
| 34 |
+
"word-wrap": "^1.2.5",
|
| 35 |
+
"type-check": "^0.4.0",
|
| 36 |
+
"levn": "^0.4.1",
|
| 37 |
+
"fast-levenshtein": "^2.0.6"
|
| 38 |
+
},
|
| 39 |
+
"devDependencies": {
|
| 40 |
+
"livescript": "^1.6.0",
|
| 41 |
+
"mocha": "^10.4.0"
|
| 42 |
+
}
|
| 43 |
+
}
|
node_modules/otplib/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The MIT License (MIT)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2014 Gerald Yeo <contact@fusedthought.com>
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
node_modules/otplib/README.md
ADDED
|
@@ -0,0 +1,534 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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+
# otplib
|
| 2 |
+
|
| 3 |
+
> Time-based (TOTP) and HMAC-based (HOTP) One-Time Password library
|
| 4 |
+
|
| 5 |
+
[![npm][badge-npm]][project-npm]
|
| 6 |
+
[![Build Status][badge-circle]][project-circle]
|
| 7 |
+
[![Coverage Status][badge-coveralls]][project-coveralls]
|
| 8 |
+
[![npm downloads][badge-npm-downloads]][project-npm]
|
| 9 |
+
[![TypeScript Support][badge-type-ts]][project-v-api]
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
<!-- TOC depthFrom:2 -->
|
| 14 |
+
|
| 15 |
+
- [About](#about)
|
| 16 |
+
- [Features](#features)
|
| 17 |
+
- [Quick Start](#quick-start)
|
| 18 |
+
- [In Node.js](#in-nodejs)
|
| 19 |
+
- [In Browser](#in-browser)
|
| 20 |
+
- [References](#references)
|
| 21 |
+
- [API / Demo Website](#api--demo-website)
|
| 22 |
+
- [Versioning](#versioning)
|
| 23 |
+
- [Migrating from v11.x](#migrating-from-v11x)
|
| 24 |
+
- [Available Options](#available-options)
|
| 25 |
+
- [HOTP Options](#hotp-options)
|
| 26 |
+
- [TOTP Options](#totp-options)
|
| 27 |
+
- [Authenticator Options](#authenticator-options)
|
| 28 |
+
- [Appendix](#appendix)
|
| 29 |
+
- [Type Definitions](#type-definitions)
|
| 30 |
+
- [Async Support](#async-support)
|
| 31 |
+
- [Browser Compatiblity](#browser-compatiblity)
|
| 32 |
+
- [Length of Secrets](#length-of-secrets)
|
| 33 |
+
- [Google Authenticator](#google-authenticator)
|
| 34 |
+
- [Difference between Authenticator and TOTP](#difference-between-authenticator-and-totp)
|
| 35 |
+
- [RFC3548 Base32](#rfc3548-base32)
|
| 36 |
+
- [Displaying a QR code](#displaying-a-qr-code)
|
| 37 |
+
- [Getting Time Remaining / Time Used](#getting-time-remaining--time-used)
|
| 38 |
+
- [Using with Expo](#using-with-expo)
|
| 39 |
+
- [Exploring with local-repl](#exploring-with-local-repl)
|
| 40 |
+
- [OTP Backup Codes](#otp-backup-codes)
|
| 41 |
+
- [Contributors](#contributors)
|
| 42 |
+
- [License](#license)
|
| 43 |
+
|
| 44 |
+
<!-- /TOC -->
|
| 45 |
+
|
| 46 |
+
## About
|
| 47 |
+
|
| 48 |
+
`otplib` is a JavaScript One Time Password (OTP) library for OTP generation and verification.
|
| 49 |
+
|
| 50 |
+
It implements both [HOTP][rfc-4226-wiki] - [RFC 4226][rfc-4226]
|
| 51 |
+
and [TOTP][rfc-6238-wiki] - [RFC 6238][rfc-6238],
|
| 52 |
+
and are tested against the test vectors provided in their respective RFC specifications.
|
| 53 |
+
These datasets can be found in the `tests/data` folder.
|
| 54 |
+
|
| 55 |
+
- [RFC 4226 Dataset][rfc-4226-dataset]
|
| 56 |
+
- [RFC 6238 Dataset][rfc-6238-dataset]
|
| 57 |
+
|
| 58 |
+
This library is also compatible with [Google Authenticator](https://github.com/google/google-authenticator),
|
| 59 |
+
and includes additional methods to allow you to work with Google Authenticator.
|
| 60 |
+
|
| 61 |
+
## Features
|
| 62 |
+
|
| 63 |
+
- Typescript support
|
| 64 |
+
- [Class][link-mdn-classes] interfaces
|
| 65 |
+
- [Function][link-mdn-functions] interfaces
|
| 66 |
+
- [Async][link-mdn-async] interfaces
|
| 67 |
+
- Pluggable modules (crypto / base32)
|
| 68 |
+
- `crypto (node)`
|
| 69 |
+
- `crypto-js`
|
| 70 |
+
- `@ronomon/crypto-async`
|
| 71 |
+
- `thirty-two`
|
| 72 |
+
- `base32-encode` + `base32-decode`
|
| 73 |
+
- Presets provided
|
| 74 |
+
- `browser`
|
| 75 |
+
- `default (node)`
|
| 76 |
+
- `default-async (same as default, but with async methods)`
|
| 77 |
+
- `v11 (adapter for previous version)`
|
| 78 |
+
|
| 79 |
+
## Quick Start
|
| 80 |
+
|
| 81 |
+
> If you need to customise your base32 or crypto libraries,
|
| 82 |
+
> check out the [In-Depth Guide][docs-in-depth] and [Available Packages][docs-available-packages]
|
| 83 |
+
|
| 84 |
+
### In Node.js
|
| 85 |
+
|
| 86 |
+
```bash
|
| 87 |
+
npm install otplib --save
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
```js
|
| 91 |
+
import { authenticator } from 'otplib';
|
| 92 |
+
|
| 93 |
+
const secret = 'KVKFKRCPNZQUYMLXOVYDSQKJKZDTSRLD';
|
| 94 |
+
// Alternative:
|
| 95 |
+
// const secret = authenticator.generateSecret();
|
| 96 |
+
// Note: .generateSecret() is only available for authenticator and not totp/hotp
|
| 97 |
+
|
| 98 |
+
const token = authenticator.generate(secret);
|
| 99 |
+
|
| 100 |
+
try {
|
| 101 |
+
const isValid = authenticator.check(token, secret);
|
| 102 |
+
// or
|
| 103 |
+
const isValid = authenticator.verify({ token, secret });
|
| 104 |
+
} catch (err) {
|
| 105 |
+
// Possible errors
|
| 106 |
+
// - options validation
|
| 107 |
+
// - "Invalid input - it is not base32 encoded string" (if thiry-two is used)
|
| 108 |
+
console.error(err);
|
| 109 |
+
}
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
Please replace "authenticator" with "totp" or "hotp" depending on your requirements.
|
| 113 |
+
|
| 114 |
+
```js
|
| 115 |
+
// For TOTP
|
| 116 |
+
import { totp } from 'otplib';
|
| 117 |
+
const token = totp.generate(secret);
|
| 118 |
+
const isValid = totp.check(token, secret);
|
| 119 |
+
const isValid = totp.verify({ token, secret });
|
| 120 |
+
|
| 121 |
+
// For HOTP
|
| 122 |
+
import { hotp } from 'otplib';
|
| 123 |
+
const token = hotp.generate(secret, counter);
|
| 124 |
+
const isValid = hotp.check(token, secret, counter);
|
| 125 |
+
const isValid = hotp.verify({ token, secret, counter });
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
For all available APIs, please refer to [API Documentation][project-v-api].
|
| 129 |
+
|
| 130 |
+
### In Browser
|
| 131 |
+
|
| 132 |
+
The browser preset is a self-contained `umd` module, and it is provided in a separate bundle.
|
| 133 |
+
|
| 134 |
+
```bash
|
| 135 |
+
npm install @otplib/preset-browser --save
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
The following is an example, where we are using the scripts hosted by `unpkg.com`.
|
| 139 |
+
|
| 140 |
+
```html
|
| 141 |
+
<script src="https://unpkg.com/@otplib/preset-browser@^12.0.0/buffer.js"></script>
|
| 142 |
+
<script src="https://unpkg.com/@otplib/preset-browser@^12.0.0/index.js"></script>
|
| 143 |
+
|
| 144 |
+
<script type="text/javascript">
|
| 145 |
+
// window.otplib.authenticator
|
| 146 |
+
// window.otplib.hotp
|
| 147 |
+
// window.otplib.totp
|
| 148 |
+
</script>
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
For more details, please refer to the [@otplib/preset-browser documentation][docs-preset-browser].
|
| 152 |
+
|
| 153 |
+
## References
|
| 154 |
+
|
| 155 |
+
### API / Demo Website
|
| 156 |
+
|
| 157 |
+
| Version | Links |
|
| 158 |
+
| --------------- | ----------------------------------------------------------------------------------- |
|
| 159 |
+
| v12.x | [Website][project-v-site] / [API][project-v-api] / [Readme][project-v-readme] |
|
| 160 |
+
| v11.x | [API][project-v11-api] / [Readme][project-v11-readme] |
|
| 161 |
+
| v10.x and below | Available via git history |
|
| 162 |
+
|
| 163 |
+
### Versioning
|
| 164 |
+
|
| 165 |
+
This library follows `semver`. As such, major version bumps usually mean API changes or behavior changes.
|
| 166 |
+
Please check [upgrade notes](https://github.com/yeojz/otplib/wiki/upgrade-notes) for more information,
|
| 167 |
+
especially before making any major upgrades.
|
| 168 |
+
|
| 169 |
+
To simplify releases, all packages within this repository have their versions synced.
|
| 170 |
+
Therefore, if there are any releases or updates to a package, we will bump all packages.
|
| 171 |
+
|
| 172 |
+
Check out the release notes associated with each tagged versions
|
| 173 |
+
in the [releases](https://github.com/yeojz/otplib/releases) page.
|
| 174 |
+
|
| 175 |
+
| Release Type | Version Pattern | Command | |
|
| 176 |
+
| :---------------- | --------------- | ------------------------- | :------------------------------------ |
|
| 177 |
+
| Current / Stable | 0.0.0 | `npm install otplib` | [![npm][badge-npm]][project-npm] |
|
| 178 |
+
| Release Candidate | 0.0.0-0 | `npm install otplib@next` | [![npm][badge-npm-next]][project-npm] |
|
| 179 |
+
|
| 180 |
+
### Migrating from v11.x
|
| 181 |
+
|
| 182 |
+
> v12.x is a huge architectural and language rewrite. Please check out the docs if you are migrating.
|
| 183 |
+
> A preset adapter is available to provide methods that behave like `v11.x` of `otplib`.
|
| 184 |
+
|
| 185 |
+
```js
|
| 186 |
+
// Update
|
| 187 |
+
import { authenticator } from 'otplib'; // v11.x
|
| 188 |
+
// to
|
| 189 |
+
import { authenticator } from '@otplib/preset-v11';
|
| 190 |
+
|
| 191 |
+
// There should be no changes to your current code.
|
| 192 |
+
// However, deprecated or modified class methods will have console.warn.
|
| 193 |
+
```
|
| 194 |
+
|
| 195 |
+
### Available Options
|
| 196 |
+
|
| 197 |
+
All instantiated classes will have their options inherited from their respective options
|
| 198 |
+
generator. i.e. HOTP from `hotpOptions`, TOTP from `totpOptions`
|
| 199 |
+
and Authenticator from `authenticatorOptions`.
|
| 200 |
+
|
| 201 |
+
All OTP classes have an object setter and getter method to override these default options.
|
| 202 |
+
|
| 203 |
+
For example,
|
| 204 |
+
|
| 205 |
+
```js
|
| 206 |
+
import { authenticator, totp, hotp } from 'otplib';
|
| 207 |
+
|
| 208 |
+
// setting
|
| 209 |
+
authenticator.options = { digits: 6 };
|
| 210 |
+
totp.options = { digits: 6 };
|
| 211 |
+
hotp.options = { digits: 6 };
|
| 212 |
+
|
| 213 |
+
// getting
|
| 214 |
+
const opts = authenticator.options;
|
| 215 |
+
const opts = totp.options;
|
| 216 |
+
const opts = hotp.options;
|
| 217 |
+
|
| 218 |
+
// reset to default
|
| 219 |
+
authenticator.resetOptions();
|
| 220 |
+
totp.resetOptions();
|
| 221 |
+
hotp.resetOptions();
|
| 222 |
+
|
| 223 |
+
// getting all options, with validation
|
| 224 |
+
// and backfilled with library defaults
|
| 225 |
+
const opts = authenticator.allOptions();
|
| 226 |
+
const opts = totp.allOptions();
|
| 227 |
+
const opts = hotp.allOptions();
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
#### HOTP Options
|
| 231 |
+
|
| 232 |
+
| Option | Type | Description |
|
| 233 |
+
| ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------- |
|
| 234 |
+
| algorithm | string | The algorithm used for calculating the HMAC. |
|
| 235 |
+
| createDigest | function | Creates the digest which token is derived from. |
|
| 236 |
+
| createHmacKey | function | Formats the secret into a HMAC key, applying transformations (like padding) where needed. |
|
| 237 |
+
| digest | string | **USE WITH CAUTION**. Same digest = same token. <br />Used in cases where digest is generated externally. (eg: async use cases) |
|
| 238 |
+
| digits | integer | The length of the token. |
|
| 239 |
+
| encoding | string | The encoding that was used on the secret. |
|
| 240 |
+
|
| 241 |
+
```js
|
| 242 |
+
// HOTP defaults
|
| 243 |
+
{
|
| 244 |
+
algorithm: 'sha1'
|
| 245 |
+
createDigest: undefined, // to be provided via a @otplib/plugin-*
|
| 246 |
+
createHmacKey: hotpCreateHmacKey,
|
| 247 |
+
digits: 6,
|
| 248 |
+
encoding: 'ascii',
|
| 249 |
+
}
|
| 250 |
+
```
|
| 251 |
+
|
| 252 |
+
#### TOTP Options
|
| 253 |
+
|
| 254 |
+
> Note: Includes all HOTP Options
|
| 255 |
+
|
| 256 |
+
| Option | Type | Description |
|
| 257 |
+
| ------ | -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 258 |
+
| epoch | integer | **USE WITH CAUTION**. Same epoch = same token. <br />Starting time since the UNIX epoch (seconds). <br /> Epoch is JavaScript formatted. i.e. `Date.now()` or `UNIX time * 1000` |
|
| 259 |
+
| step | integer | Time step (seconds) |
|
| 260 |
+
| window | integer, <br /> [number, number] | Tokens in the previous and future x-windows that should be considered valid. <br /> If integer, same value will be used for both. <br /> Alternatively, define array: `[past, future]` |
|
| 261 |
+
|
| 262 |
+
```js
|
| 263 |
+
// TOTP defaults
|
| 264 |
+
{
|
| 265 |
+
// ...includes all HOTP defaults
|
| 266 |
+
createHmacKey: totpCreateHmacKey,
|
| 267 |
+
epoch: Date.now(),
|
| 268 |
+
step: 30,
|
| 269 |
+
window: 0,
|
| 270 |
+
}
|
| 271 |
+
```
|
| 272 |
+
|
| 273 |
+
#### Authenticator Options
|
| 274 |
+
|
| 275 |
+
> Note: Includes all HOTP + TOTP Options
|
| 276 |
+
|
| 277 |
+
| Option | Type | Description |
|
| 278 |
+
| ----------------- | -------- | ----------------------------------------------------------------------------------------------------- |
|
| 279 |
+
| createRandomBytes | function | Creates a random string containing the defined number of bytes to be used in generating a secret key. |
|
| 280 |
+
| keyEncoder | function | Encodes a secret key into a Base32 string before it is sent to the user (in QR Code etc). |
|
| 281 |
+
| keyDecoder | function | Decodes the Base32 string given by the user into a secret. |
|
| 282 |
+
|
| 283 |
+
```js
|
| 284 |
+
// Authenticator defaults
|
| 285 |
+
{
|
| 286 |
+
// ...includes all HOTP + TOTP defaults
|
| 287 |
+
encoding: 'hex',
|
| 288 |
+
createRandomBytes: undefined, // to be provided via a @otplib/plugin-*
|
| 289 |
+
keyEncoder: undefined, // to be provided via a @otplib/plugin-*
|
| 290 |
+
keyDecoder: undefined, // to be provided via a @otplib/plugin-*
|
| 291 |
+
}
|
| 292 |
+
```
|
| 293 |
+
|
| 294 |
+
## Appendix
|
| 295 |
+
|
| 296 |
+
### Type Definitions
|
| 297 |
+
|
| 298 |
+
`TypeScript` support was introduced in `v10.0.0`, which added type definitions over `.js` files.
|
| 299 |
+
|
| 300 |
+
As of `v12.0.0`, the library has been re-written in Typescript from the ground up.
|
| 301 |
+
|
| 302 |
+
### Async Support
|
| 303 |
+
|
| 304 |
+
`async` support was introduced in `v12.0.0` as an additional core library.
|
| 305 |
+
|
| 306 |
+
This was added as some libraries like [expo.io][link-expo-crypto] or even
|
| 307 |
+
the browser API ([window.Crypto.subtle][link-mdn-subtlecrypto]) started providing
|
| 308 |
+
only async methods.
|
| 309 |
+
|
| 310 |
+
You to find more details in the [core-async][docs-core-async] folder.
|
| 311 |
+
|
| 312 |
+
### Browser Compatiblity
|
| 313 |
+
|
| 314 |
+
`@otplib/preset-browser` is a `umd` bundle with some node modules replaced to reduce the browser size.
|
| 315 |
+
|
| 316 |
+
The approximate size for the **optimised, minified + gzipped** bundle is **9.53KB**.
|
| 317 |
+
Paired with the gzipped browser `buffer.js` module, it would be about `7.65KB + 9.53KB = 17.18KB`.
|
| 318 |
+
|
| 319 |
+
For more details, please refer to the [@otplib/preset-browser documentation][docs-preset-browser].
|
| 320 |
+
|
| 321 |
+
### Length of Secrets
|
| 322 |
+
|
| 323 |
+
In [RFC 6238][rfc-6238], the secret / seed length for different algorithms are predefined:
|
| 324 |
+
|
| 325 |
+
```txt
|
| 326 |
+
HMAC-SHA1 - 20 bytes
|
| 327 |
+
HMAC-SHA256 - 32 bytes
|
| 328 |
+
HMAC-SHA512 - 64 bytes
|
| 329 |
+
```
|
| 330 |
+
|
| 331 |
+
As such, the length of the secret provided (after any decoding) will be padded and sliced
|
| 332 |
+
according to the expected length for respective algorithms.
|
| 333 |
+
|
| 334 |
+
### Google Authenticator
|
| 335 |
+
|
| 336 |
+
#### Difference between Authenticator and TOTP
|
| 337 |
+
|
| 338 |
+
The default encoding option has been set to `hex` (Authenticator) instead of `ascii` (TOTP).
|
| 339 |
+
|
| 340 |
+
#### RFC3548 Base32
|
| 341 |
+
|
| 342 |
+
> Note: [RFC4648][rfc-4648] obseletes [RFC 3548][rfc-3548].
|
| 343 |
+
> Any encoders following the newer specifications will work.
|
| 344 |
+
|
| 345 |
+
Google Authenticator requires keys to be base32 encoded.
|
| 346 |
+
It also requires the base32 encoder to be [RFC 3548][rfc-3548] compliant.
|
| 347 |
+
|
| 348 |
+
OTP calculation will still work should you want to use
|
| 349 |
+
other base32 encoding methods (like Crockford's Base32)
|
| 350 |
+
but it will NOT be compatible with Google Authenticator.
|
| 351 |
+
|
| 352 |
+
```js
|
| 353 |
+
const secret = authenticator.generateSecret(); // base32 encoded hex secret key
|
| 354 |
+
const token = authenticator.generate(secret);
|
| 355 |
+
```
|
| 356 |
+
|
| 357 |
+
#### Displaying a QR code
|
| 358 |
+
|
| 359 |
+
You may want to generate and display a QR Code so that users can scan
|
| 360 |
+
instead of manually entering the secret. Google Authenticator and similar apps
|
| 361 |
+
take in a QR code that holds a URL with the protocol `otpauth://`,
|
| 362 |
+
which you get from `authenticator.keyuri`.
|
| 363 |
+
|
| 364 |
+
Google Authenticator will ignore the `algorithm`, `digits`, and `step` options.
|
| 365 |
+
See the [keyuri documentation](https://github.com/google/google-authenticator/wiki/Key-Uri-Format)
|
| 366 |
+
for more information.
|
| 367 |
+
|
| 368 |
+
If you are using a different authenticator app, check the documentation
|
| 369 |
+
for that app to see if any options are ignored, which will result in invalid tokens.
|
| 370 |
+
|
| 371 |
+
While this library provides the "otpauth" uri, you'll need a library to
|
| 372 |
+
generate the QR Code image.
|
| 373 |
+
|
| 374 |
+
An example is shown below:
|
| 375 |
+
|
| 376 |
+
```js
|
| 377 |
+
// npm install qrcode
|
| 378 |
+
import qrcode from 'qrcode';
|
| 379 |
+
import { authenticator } from '@otplib/preset-default';
|
| 380 |
+
|
| 381 |
+
const user = 'A user name, possibly an email';
|
| 382 |
+
const service = 'A service name';
|
| 383 |
+
|
| 384 |
+
// v11.x and above
|
| 385 |
+
const otpauth = authenticator.keyuri(user, service, secret);
|
| 386 |
+
|
| 387 |
+
// v10.x and below
|
| 388 |
+
const otpauth = authenticator.keyuri(
|
| 389 |
+
encodeURIComponent(user),
|
| 390 |
+
encodeURIComponent(service),
|
| 391 |
+
secret
|
| 392 |
+
);
|
| 393 |
+
|
| 394 |
+
qrcode.toDataURL(otpauth, (err, imageUrl) => {
|
| 395 |
+
if (err) {
|
| 396 |
+
console.log('Error with QR');
|
| 397 |
+
return;
|
| 398 |
+
}
|
| 399 |
+
console.log(imageUrl);
|
| 400 |
+
});
|
| 401 |
+
```
|
| 402 |
+
|
| 403 |
+
> **Note**: For versions `v10.x` and below, `keyuri` does not URI encode
|
| 404 |
+
> `user` and `service`. You'll need to do so before passing in the parameteres.
|
| 405 |
+
|
| 406 |
+
### Getting Time Remaining / Time Used
|
| 407 |
+
|
| 408 |
+
Helper methods for getting the remaining time and used time within a validity period
|
| 409 |
+
of a `totp` or `authenticator` token were introduced in `v10.0.0`.
|
| 410 |
+
|
| 411 |
+
```js
|
| 412 |
+
authenticator.timeUsed(); // or totp.timeUsed();
|
| 413 |
+
authenticator.timeRemaining(); // or totp.timeRemaining();
|
| 414 |
+
|
| 415 |
+
// The start of a new token would be when:
|
| 416 |
+
// - timeUsed() === 0
|
| 417 |
+
// - timeRemaining() === step
|
| 418 |
+
```
|
| 419 |
+
|
| 420 |
+
### Using with Expo
|
| 421 |
+
|
| 422 |
+
[Expo][link-expo-io] contains modified crypto implmentations targeted at the platform.
|
| 423 |
+
While `otplib` does not provide an `expo` specified package, with the re-architecture
|
| 424 |
+
of `otplib`, you can now provide an expo native `createDigest` to the library.
|
| 425 |
+
|
| 426 |
+
Alternatively, you can make use of crypto provided by `@otplib/plugin-crypto-js` or
|
| 427 |
+
the bundled browser umd module `@otplib/preset-browser`.
|
| 428 |
+
|
| 429 |
+
Pull Requests are much welcomed for a native expo implementation as well.
|
| 430 |
+
|
| 431 |
+
### Exploring with local-repl
|
| 432 |
+
|
| 433 |
+
If you'll like to explore the library with `local-repl` you can do so as well.
|
| 434 |
+
|
| 435 |
+
```bash
|
| 436 |
+
# after cloning the repo:
|
| 437 |
+
npm run setup
|
| 438 |
+
npm run build
|
| 439 |
+
npx local-repl
|
| 440 |
+
# You should see something like:
|
| 441 |
+
# Node v8.9.4, local-repl 4.0.0
|
| 442 |
+
# otplib 10.0.0
|
| 443 |
+
# Context: otplib
|
| 444 |
+
# [otplib] >
|
| 445 |
+
|
| 446 |
+
[otplib] > secret = 'KVKFKRCPNZQUYMLXOVYDSQKJKZDTSRLD'
|
| 447 |
+
[otplib] > otplib.authenticator.generate(secret)
|
| 448 |
+
```
|
| 449 |
+
|
| 450 |
+
### OTP Backup Codes
|
| 451 |
+
|
| 452 |
+
It is common for services to also provide a set of backup codes to authenticate
|
| 453 |
+
and bypass the OTP step in the event that you are not able to access your 2FA
|
| 454 |
+
device or have misplaced the device.
|
| 455 |
+
|
| 456 |
+
As this process is separate from the specifications for OTP, this library does not
|
| 457 |
+
provide any backup code related verification logic, and thus would have to be
|
| 458 |
+
implemented separately.
|
| 459 |
+
|
| 460 |
+
## Contributors
|
| 461 |
+
|
| 462 |
+
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
| 463 |
+
|
| 464 |
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
| 465 |
+
<!-- prettier-ignore-start -->
|
| 466 |
+
<!-- markdownlint-disable -->
|
| 467 |
+
<table>
|
| 468 |
+
<tr>
|
| 469 |
+
<td align="center"><a href="https://github.com/yeojz"><img src="https://avatars2.githubusercontent.com/u/429598?v=4" width="80px;" alt="Gerald Yeo"/><br /><sub><b>Gerald Yeo</b></sub></a><br /><a href="https://github.com/yeojz/otplib/commits?author=yeojz" title="Code">💻</a> <a href="https://github.com/yeojz/otplib/commits?author=yeojz" title="Documentation">📖</a> <a href="#maintenance-yeojz" title="Maintenance">🚧</a> <a href="https://github.com/yeojz/otplib/commits?author=yeojz" title="Tests">⚠️</a></td>
|
| 470 |
+
<td align="center"><a href="https://ols.io"><img src="https://avatars3.githubusercontent.com/u/6209178?v=4" width="80px;" alt="Oliver Schneider"/><br /><sub><b>Oliver Schneider</b></sub></a><br /><a href="https://github.com/yeojz/otplib/commits?author=olsio" title="Documentation">📖</a></td>
|
| 471 |
+
<td align="center"><a href="https://developer.mozilla.org/profiles/madarche/"><img src="https://avatars0.githubusercontent.com/u/152407?v=4" width="80px;" alt="Marc-Aurèle DARCHE"/><br /><sub><b>Marc-Aurèle DARCHE</b></sub></a><br /><a href="https://github.com/yeojz/otplib/commits?author=madarche" title="Documentation">📖</a></td>
|
| 472 |
+
<td align="center"><a href="http://shakram02.github.io/"><img src="https://avatars3.githubusercontent.com/u/10996982?v=4" width="80px;" alt="Ahmed Hamdy (@shakram02)"/><br /><sub><b>Ahmed Hamdy (@shakram02)</b></sub></a><br /><a href="https://github.com/yeojz/otplib/commits?author=shakram02" title="Documentation">📖</a></td>
|
| 473 |
+
<td align="center"><a href="https://tony.brix.ninja"><img src="https://avatars3.githubusercontent.com/u/97994?v=4" width="80px;" alt="Tony Brix"/><br /><sub><b>Tony Brix</b></sub></a><br /><a href="https://github.com/yeojz/otplib/commits?author=UziTech" title="Code">💻</a> <a href="https://github.com/yeojz/otplib/commits?author=UziTech" title="Documentation">📖</a></td>
|
| 474 |
+
<td align="center"><a href="https://github.com/encX"><img src="https://avatars3.githubusercontent.com/u/5965883?v=4" width="80px;" alt="Plai"/><br /><sub><b>Plai</b></sub></a><br /><a href="https://github.com/yeojz/otplib/commits?author=encX" title="Documentation">📖</a></td>
|
| 475 |
+
</tr>
|
| 476 |
+
</table>
|
| 477 |
+
|
| 478 |
+
<!-- markdownlint-enable -->
|
| 479 |
+
<!-- prettier-ignore-end -->
|
| 480 |
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
| 481 |
+
|
| 482 |
+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors)
|
| 483 |
+
specification. Contributions of any kind welcome!
|
| 484 |
+
|
| 485 |
+
## License
|
| 486 |
+
|
| 487 |
+
`otplib` is [MIT licensed][project-license]
|
| 488 |
+
|
| 489 |
+
<img width="150" src="https://otplib.yeojz.dev/otplib.png" />
|
| 490 |
+
|
| 491 |
+
<!-- Badges -->
|
| 492 |
+
|
| 493 |
+
[badge-circle]: https://img.shields.io/circleci/project/github/yeojz/otplib/master.svg?style=flat-square
|
| 494 |
+
[badge-coveralls]: https://img.shields.io/coveralls/yeojz/otplib/master.svg?style=flat-square
|
| 495 |
+
[badge-npm-downloads]: https://img.shields.io/npm/dt/otplib.svg?style=flat-square
|
| 496 |
+
[badge-npm-next]: https://img.shields.io/npm/v/otplib/next.svg?style=flat-square
|
| 497 |
+
[badge-npm]: https://img.shields.io/npm/v/otplib.svg?style=flat-square
|
| 498 |
+
[badge-type-ts]: https://img.shields.io/badge/typedef-.d.ts-blue.svg?style=flat-square&longCache=true
|
| 499 |
+
|
| 500 |
+
<!-- External Links -->
|
| 501 |
+
|
| 502 |
+
[link-expo-crypto]: https://docs.expo.io/versions/v33.0.0/sdk/crypto/
|
| 503 |
+
[link-expo-io]: https://expo.io
|
| 504 |
+
[link-mdn-async]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
|
| 505 |
+
[link-mdn-classes]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
|
| 506 |
+
[link-mdn-functions]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions
|
| 507 |
+
[link-mdn-subtlecrypto]: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto
|
| 508 |
+
[link-npm-buffer]: https://www.npmjs.com/package/buffer
|
| 509 |
+
[rfc-3548]: http://tools.ietf.org/html/rfc3548
|
| 510 |
+
[rfc-4226-dataset]: https://github.com/yeojz/otplib/blob/master/tests/data/rfc-4226.ts
|
| 511 |
+
[rfc-4226-wiki]: http://en.wikipedia.org/wiki/HMAC-based_One-time_Password_Algorithm
|
| 512 |
+
[rfc-4226]: http://tools.ietf.org/html/rfc4226
|
| 513 |
+
[rfc-4648]: https://tools.ietf.org/html/rfc4648
|
| 514 |
+
[rfc-6238-dataset]: https://github.com/yeojz/otplib/blob/master/tests/data/rfc-6238.ts
|
| 515 |
+
[rfc-6238-wiki]: http://en.wikipedia.org/wiki/Time-based_One-time_Password_Algorithm
|
| 516 |
+
[rfc-6238]: http://tools.ietf.org/html/rfc6238
|
| 517 |
+
|
| 518 |
+
<!-- Project Links -->
|
| 519 |
+
|
| 520 |
+
[docs-available-packages]: https://github.com/yeojz/otplib/blob/master/packages/README.md
|
| 521 |
+
[docs-core-async]: https://github.com/yeojz/otplib/blob/master/packages/otplib-core-async/README.md
|
| 522 |
+
[docs-in-depth]: https://github.com/yeojz/otplib/blob/master/packages/otplib-core/README.md#getting-started
|
| 523 |
+
[docs-preset-browser-src]: https://github.com/yeojz/otplib/blob/master/packages/otplib-preset-browser/src/index.ts
|
| 524 |
+
[docs-preset-browser]: https://github.com/yeojz/otplib/blob/master/packages/otplib-preset-browser/README.md
|
| 525 |
+
[project-circle]: https://circleci.com/gh/yeojz/otplib
|
| 526 |
+
[project-coveralls]: https://coveralls.io/github/yeojz/otplib
|
| 527 |
+
[project-license]: https://github.com/yeojz/otplib/blob/master/LICENSE
|
| 528 |
+
[project-npm]: https://www.npmjs.com/package/otplib
|
| 529 |
+
[project-repo]: https://github.com/yeojz/otplib
|
| 530 |
+
[project-v-api]: https://otplib.yeojz.dev/api
|
| 531 |
+
[project-v-readme]: https://github.com/yeojz/otplib/blob/master/README.md
|
| 532 |
+
[project-v-site]: https://otplib.yeojz.dev
|
| 533 |
+
[project-v11-api]: https://5d4d0cc4c85e00000788a456--otplib.netlify.com/docs
|
| 534 |
+
[project-v11-readme]: https://github.com/yeojz/otplib/blob/d0aedccbca8ae7ec1983f40da4d7a14c9e815e9c/README.md
|
node_modules/otplib/core.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export * from '@otplib/core';
|
node_modules/otplib/core.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* otplib
|
| 3 |
+
*
|
| 4 |
+
* @author Gerald Yeo <contact@fusedthought.com>
|
| 5 |
+
* @version: 12.0.1
|
| 6 |
+
* @license: MIT
|
| 7 |
+
**/
|
| 8 |
+
'use strict';
|
| 9 |
+
|
| 10 |
+
Object.defineProperty(exports, '__esModule', { value: true });
|
| 11 |
+
|
| 12 |
+
var core = require('@otplib/core');
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Object.keys(core).forEach(function (k) {
|
| 17 |
+
if (k !== 'default') Object.defineProperty(exports, k, {
|
| 18 |
+
enumerable: true,
|
| 19 |
+
get: function () {
|
| 20 |
+
return core[k];
|
| 21 |
+
}
|
| 22 |
+
});
|
| 23 |
+
});
|
node_modules/otplib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export * from '@otplib/preset-default';
|
node_modules/otplib/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* otplib
|
| 3 |
+
*
|
| 4 |
+
* @author Gerald Yeo <contact@fusedthought.com>
|
| 5 |
+
* @version: 12.0.1
|
| 6 |
+
* @license: MIT
|
| 7 |
+
**/
|
| 8 |
+
'use strict';
|
| 9 |
+
|
| 10 |
+
Object.defineProperty(exports, '__esModule', { value: true });
|
| 11 |
+
|
| 12 |
+
var presetDefault = require('@otplib/preset-default');
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Object.keys(presetDefault).forEach(function (k) {
|
| 17 |
+
if (k !== 'default') Object.defineProperty(exports, k, {
|
| 18 |
+
enumerable: true,
|
| 19 |
+
get: function () {
|
| 20 |
+
return presetDefault[k];
|
| 21 |
+
}
|
| 22 |
+
});
|
| 23 |
+
});
|
node_modules/otplib/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "otplib",
|
| 3 |
+
"description": "HMAC-based (HOTP) and Time-based (TOTP) One-Time Password library",
|
| 4 |
+
"version": "12.0.1",
|
| 5 |
+
"main": "./index.js",
|
| 6 |
+
"publishConfig": {
|
| 7 |
+
"access": "public"
|
| 8 |
+
},
|
| 9 |
+
"scripts": {},
|
| 10 |
+
"dependencies": {
|
| 11 |
+
"@otplib/core": "^12.0.1",
|
| 12 |
+
"@otplib/preset-default": "^12.0.1",
|
| 13 |
+
"@otplib/preset-v11": "^12.0.1"
|
| 14 |
+
},
|
| 15 |
+
"otplib": {},
|
| 16 |
+
"keywords": [
|
| 17 |
+
"totp",
|
| 18 |
+
"hotp",
|
| 19 |
+
"otp",
|
| 20 |
+
"authenticator",
|
| 21 |
+
"one time password",
|
| 22 |
+
"google authenticator",
|
| 23 |
+
"authentication",
|
| 24 |
+
"2FA",
|
| 25 |
+
"2 factor",
|
| 26 |
+
"node",
|
| 27 |
+
"browser"
|
| 28 |
+
],
|
| 29 |
+
"author": "Gerald Yeo <contact@fusedthought.com>",
|
| 30 |
+
"license": "MIT",
|
| 31 |
+
"homepage": "https://yeojz.otplib.dev",
|
| 32 |
+
"repository": "https://github.com/yeojz/otplib",
|
| 33 |
+
"types": "./index.d.ts"
|
| 34 |
+
}
|
node_modules/otplib/v11.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export * from '@otplib/preset-v11';
|
node_modules/otplib/v11.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* otplib
|
| 3 |
+
*
|
| 4 |
+
* @author Gerald Yeo <contact@fusedthought.com>
|
| 5 |
+
* @version: 12.0.1
|
| 6 |
+
* @license: MIT
|
| 7 |
+
**/
|
| 8 |
+
'use strict';
|
| 9 |
+
|
| 10 |
+
Object.defineProperty(exports, '__esModule', { value: true });
|
| 11 |
+
|
| 12 |
+
var presetV11 = require('@otplib/preset-v11');
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Object.keys(presetV11).forEach(function (k) {
|
| 17 |
+
if (k !== 'default') Object.defineProperty(exports, k, {
|
| 18 |
+
enumerable: true,
|
| 19 |
+
get: function () {
|
| 20 |
+
return presetV11[k];
|
| 21 |
+
}
|
| 22 |
+
});
|
| 23 |
+
});
|
node_modules/outvariant/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2021–present Artem Zakharchenko
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 6 |
+
|
| 7 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABIL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
|
| 1 |
+
# `outvariant`
|
| 2 |
+
|
| 3 |
+
Type-safe implementation of invariant with positionals.
|
| 4 |
+
|
| 5 |
+
## Motivation
|
| 6 |
+
|
| 7 |
+
### Type-safely
|
| 8 |
+
|
| 9 |
+
This implementation asserts the given predicate expression so it's treated as non-nullable after the `invariant` call:
|
| 10 |
+
|
| 11 |
+
```ts
|
| 12 |
+
// Regular invariant:
|
| 13 |
+
invariant(user, 'Failed to fetch')
|
| 14 |
+
user?.firstName // "user" is possibly undefined
|
| 15 |
+
|
| 16 |
+
// Outvariant:
|
| 17 |
+
invariant(user, 'Failed to fetch')
|
| 18 |
+
user.firstName // OK, "invariant" ensured the "user" exists
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
### Positionals support
|
| 22 |
+
|
| 23 |
+
This implementation uses [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) to support dynamic number of positionals:
|
| 24 |
+
|
| 25 |
+
```js
|
| 26 |
+
invariant(predicate, 'Expected %s but got %s', 'one', false)
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
## What is this for?
|
| 30 |
+
|
| 31 |
+
Invariant is a shorthand function that asserts a given predicate and throws an error if that predicate is false.
|
| 32 |
+
|
| 33 |
+
Compare these two pieces of code identical in behavior:
|
| 34 |
+
|
| 35 |
+
```js
|
| 36 |
+
if (!token) {
|
| 37 |
+
throw new Error(`Expected a token to be set but got ${typeof token}`)
|
| 38 |
+
}
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
```js
|
| 42 |
+
import { invariant } from 'outvariant'
|
| 43 |
+
|
| 44 |
+
invariant(token, 'Expected a token to be set but got %s', typeof token)
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
Using `invariant` reduces the visual nesting of the code and leads to cleaner error messages thanks to formatted positionals (i.e. the `%s` (string) positional above).
|
| 48 |
+
|
| 49 |
+
## Usage
|
| 50 |
+
|
| 51 |
+
### Install
|
| 52 |
+
|
| 53 |
+
```sh
|
| 54 |
+
npm install outvariant
|
| 55 |
+
# or
|
| 56 |
+
yarn add outvariant
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
> You may want to install this library as a dev dependency (`-D`) based on your usage.
|
| 60 |
+
|
| 61 |
+
### Write an assertion
|
| 62 |
+
|
| 63 |
+
```js
|
| 64 |
+
import { invariant } from 'outvariant'
|
| 65 |
+
|
| 66 |
+
invariant(user, 'Failed to load: expected user, but got %o', user)
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## Positionals
|
| 70 |
+
|
| 71 |
+
The following positional tokens are supported:
|
| 72 |
+
|
| 73 |
+
| Token | Expected value type |
|
| 74 |
+
| --------- | ------------------------------------------------------- |
|
| 75 |
+
| `%s` | String |
|
| 76 |
+
| `%d`/`%i` | Number |
|
| 77 |
+
| `%j` | JSON (non-stringified) |
|
| 78 |
+
| `%o` | Arbitrary object or object-like (i.e. a class instance) |
|
| 79 |
+
|
| 80 |
+
Whenever present in the error message, a positional token will look up the value to insert in its place from the arguments given to `invariant`.
|
| 81 |
+
|
| 82 |
+
```js
|
| 83 |
+
invariant(
|
| 84 |
+
false,
|
| 85 |
+
'Expected the "%s" property but got %j',
|
| 86 |
+
// Note that positionals are sensitive to order:
|
| 87 |
+
// - "firstName" replaces "%s" because it's first.
|
| 88 |
+
// - {"id":1} replaces "%j" because it's second.
|
| 89 |
+
'firstName',
|
| 90 |
+
{
|
| 91 |
+
id: 1,
|
| 92 |
+
}
|
| 93 |
+
)
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
## Polymorphic errors
|
| 97 |
+
|
| 98 |
+
It is possible to throw a custom `Error` instance using `invariant.as`:
|
| 99 |
+
|
| 100 |
+
```js
|
| 101 |
+
import { invariant } from 'outvariant'
|
| 102 |
+
|
| 103 |
+
class NetworkError extends Error {
|
| 104 |
+
constructor(message) {
|
| 105 |
+
super(message)
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
invariant.as(NetworkError, res.fulfilled, 'Failed to handle response')
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
Note that providing a custom error constructor as the argument to `invariant.as` requires the custom constructor's signature to be compatible with the `Error` class constructor.
|
| 113 |
+
|
| 114 |
+
If your error constructor has a different signature, you can pass a function as the first argument to `invariant.as` that creates a new custom error instance.
|
| 115 |
+
|
| 116 |
+
```js
|
| 117 |
+
import { invariant } from 'outvariant'
|
| 118 |
+
|
| 119 |
+
class NetworkError extends Error {
|
| 120 |
+
constructor(statusCode, message) {
|
| 121 |
+
super(message)
|
| 122 |
+
this.statusCode = statusCode
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
invariant.as(
|
| 127 |
+
(message) => new NetworkError(500, message),
|
| 128 |
+
res.fulfilled,
|
| 129 |
+
'Failed to handle response'
|
| 130 |
+
)
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
Abstract the error into helper functions for flexibility:
|
| 134 |
+
|
| 135 |
+
```js
|
| 136 |
+
function toNetworkError(statusCode) {
|
| 137 |
+
return (message) => new NetworkError(statusCode, message)
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
invariant.as(toNetworkError(404), res?.user?.id, 'User Not Found')
|
| 141 |
+
invariant.as(toNetworkError(500), res.fulfilled, 'Internal Server Error')
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
## Contributing
|
| 145 |
+
|
| 146 |
+
Please [open an issue](https://github.com/open-draft/outvariant/issues) or [submit a pull request](https://github.com/open-draft/outvariant/pulls) if you wish to contribute. Thank you.
|
node_modules/outvariant/lib/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare class InvariantError extends Error {
|
| 2 |
+
readonly message: string;
|
| 3 |
+
name: string;
|
| 4 |
+
constructor(message: string, ...positionals: any[]);
|
| 5 |
+
}
|
| 6 |
+
interface CustomErrorConstructor {
|
| 7 |
+
new (message: string): Error;
|
| 8 |
+
}
|
| 9 |
+
interface CustomErrorFactory {
|
| 10 |
+
(message: string): Error;
|
| 11 |
+
}
|
| 12 |
+
declare type CustomError = CustomErrorConstructor | CustomErrorFactory;
|
| 13 |
+
declare type Invariant = {
|
| 14 |
+
(predicate: unknown, message: string, ...positionals: any[]): asserts predicate;
|
| 15 |
+
as(ErrorConstructor: CustomError, predicate: unknown, message: string, ...positionals: unknown[]): asserts predicate;
|
| 16 |
+
};
|
| 17 |
+
declare const invariant: Invariant;
|
| 18 |
+
|
| 19 |
+
declare function format(message: string, ...positionals: any[]): string;
|
| 20 |
+
|
| 21 |
+
export { CustomError, CustomErrorConstructor, CustomErrorFactory, InvariantError, format, invariant };
|
node_modules/outvariant/lib/index.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
var __defProp = Object.defineProperty;
|
| 3 |
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
| 4 |
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
| 5 |
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
| 6 |
+
var __export = (target, all) => {
|
| 7 |
+
for (var name in all)
|
| 8 |
+
__defProp(target, name, { get: all[name], enumerable: true });
|
| 9 |
+
};
|
| 10 |
+
var __copyProps = (to, from, except, desc) => {
|
| 11 |
+
if (from && typeof from === "object" || typeof from === "function") {
|
| 12 |
+
for (let key of __getOwnPropNames(from))
|
| 13 |
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
| 14 |
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
| 15 |
+
}
|
| 16 |
+
return to;
|
| 17 |
+
};
|
| 18 |
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
| 19 |
+
|
| 20 |
+
// src/index.ts
|
| 21 |
+
var src_exports = {};
|
| 22 |
+
__export(src_exports, {
|
| 23 |
+
InvariantError: () => InvariantError,
|
| 24 |
+
format: () => format,
|
| 25 |
+
invariant: () => invariant
|
| 26 |
+
});
|
| 27 |
+
module.exports = __toCommonJS(src_exports);
|
| 28 |
+
|
| 29 |
+
// src/format.ts
|
| 30 |
+
var POSITIONALS_EXP = /(%?)(%([sdijo]))/g;
|
| 31 |
+
function serializePositional(positional, flag) {
|
| 32 |
+
switch (flag) {
|
| 33 |
+
case "s":
|
| 34 |
+
return positional;
|
| 35 |
+
case "d":
|
| 36 |
+
case "i":
|
| 37 |
+
return Number(positional);
|
| 38 |
+
case "j":
|
| 39 |
+
return JSON.stringify(positional);
|
| 40 |
+
case "o": {
|
| 41 |
+
if (typeof positional === "string") {
|
| 42 |
+
return positional;
|
| 43 |
+
}
|
| 44 |
+
const json = JSON.stringify(positional);
|
| 45 |
+
if (json === "{}" || json === "[]" || /^\[object .+?\]$/.test(json)) {
|
| 46 |
+
return positional;
|
| 47 |
+
}
|
| 48 |
+
return json;
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
function format(message, ...positionals) {
|
| 53 |
+
if (positionals.length === 0) {
|
| 54 |
+
return message;
|
| 55 |
+
}
|
| 56 |
+
let positionalIndex = 0;
|
| 57 |
+
let formattedMessage = message.replace(
|
| 58 |
+
POSITIONALS_EXP,
|
| 59 |
+
(match, isEscaped, _, flag) => {
|
| 60 |
+
const positional = positionals[positionalIndex];
|
| 61 |
+
const value = serializePositional(positional, flag);
|
| 62 |
+
if (!isEscaped) {
|
| 63 |
+
positionalIndex++;
|
| 64 |
+
return value;
|
| 65 |
+
}
|
| 66 |
+
return match;
|
| 67 |
+
}
|
| 68 |
+
);
|
| 69 |
+
if (positionalIndex < positionals.length) {
|
| 70 |
+
formattedMessage += ` ${positionals.slice(positionalIndex).join(" ")}`;
|
| 71 |
+
}
|
| 72 |
+
formattedMessage = formattedMessage.replace(/%{2,2}/g, "%");
|
| 73 |
+
return formattedMessage;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
// src/invariant.ts
|
| 77 |
+
var STACK_FRAMES_TO_IGNORE = 2;
|
| 78 |
+
function cleanErrorStack(error) {
|
| 79 |
+
if (!error.stack) {
|
| 80 |
+
return;
|
| 81 |
+
}
|
| 82 |
+
const nextStack = error.stack.split("\n");
|
| 83 |
+
nextStack.splice(1, STACK_FRAMES_TO_IGNORE);
|
| 84 |
+
error.stack = nextStack.join("\n");
|
| 85 |
+
}
|
| 86 |
+
var InvariantError = class extends Error {
|
| 87 |
+
constructor(message, ...positionals) {
|
| 88 |
+
super(message);
|
| 89 |
+
this.message = message;
|
| 90 |
+
this.name = "Invariant Violation";
|
| 91 |
+
this.message = format(message, ...positionals);
|
| 92 |
+
cleanErrorStack(this);
|
| 93 |
+
}
|
| 94 |
+
};
|
| 95 |
+
var invariant = (predicate, message, ...positionals) => {
|
| 96 |
+
if (!predicate) {
|
| 97 |
+
throw new InvariantError(message, ...positionals);
|
| 98 |
+
}
|
| 99 |
+
};
|
| 100 |
+
invariant.as = (ErrorConstructor, predicate, message, ...positionals) => {
|
| 101 |
+
if (!predicate) {
|
| 102 |
+
const formatMessage = positionals.length === 0 ? message : format(message, ...positionals);
|
| 103 |
+
let error;
|
| 104 |
+
try {
|
| 105 |
+
error = Reflect.construct(ErrorConstructor, [
|
| 106 |
+
formatMessage
|
| 107 |
+
]);
|
| 108 |
+
} catch (err) {
|
| 109 |
+
error = ErrorConstructor(formatMessage);
|
| 110 |
+
}
|
| 111 |
+
throw error;
|
| 112 |
+
}
|
| 113 |
+
};
|
| 114 |
+
// Annotate the CommonJS export names for ESM import in node:
|
| 115 |
+
0 && (module.exports = {
|
| 116 |
+
InvariantError,
|
| 117 |
+
format,
|
| 118 |
+
invariant
|
| 119 |
+
});
|
| 120 |
+
//# sourceMappingURL=index.js.map
|
node_modules/outvariant/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"sources":["../src/index.ts","../src/format.ts","../src/invariant.ts"],"sourcesContent":["export * from './invariant'\nexport * from './format'\n","const POSITIONALS_EXP = /(%?)(%([sdijo]))/g\n\nfunction serializePositional(positional: any, flag: string): any {\n switch (flag) {\n // Strings.\n case 's':\n return positional\n\n // Digits.\n case 'd':\n case 'i':\n return Number(positional)\n\n // JSON.\n case 'j':\n return JSON.stringify(positional)\n\n // Objects.\n case 'o': {\n // Preserve stings to prevent extra quotes around them.\n if (typeof positional === 'string') {\n return positional\n }\n\n const json = JSON.stringify(positional)\n\n // If the positional isn't serializable, return it as-is.\n if (json === '{}' || json === '[]' || /^\\[object .+?\\]$/.test(json)) {\n return positional\n }\n\n return json\n }\n }\n}\n\nexport function format(message: string, ...positionals: any[]): string {\n if (positionals.length === 0) {\n return message\n }\n\n let positionalIndex = 0\n let formattedMessage = message.replace(\n POSITIONALS_EXP,\n (match, isEscaped, _, flag) => {\n const positional = positionals[positionalIndex]\n const value = serializePositional(positional, flag)\n\n if (!isEscaped) {\n positionalIndex++\n return value\n }\n\n return match\n }\n )\n\n // Append unresolved positionals to string as-is.\n if (positionalIndex < positionals.length) {\n formattedMessage += ` ${positionals.slice(positionalIndex).join(' ')}`\n }\n\n formattedMessage = formattedMessage.replace(/%{2,2}/g, '%')\n\n return formattedMessage\n}\n","import { format } from './format'\n\nconst STACK_FRAMES_TO_IGNORE = 2\n\n/**\n * Remove the \"outvariant\" package trace from the given error.\n * This scopes down the error stack to the relevant parts\n * when used in other applications.\n */\nfunction cleanErrorStack(error: Error): void {\n if (!error.stack) {\n return\n }\n\n const nextStack = error.stack.split('\\n')\n nextStack.splice(1, STACK_FRAMES_TO_IGNORE)\n error.stack = nextStack.join('\\n')\n}\n\nexport class InvariantError extends Error {\n name = 'Invariant Violation'\n\n constructor(public readonly message: string, ...positionals: any[]) {\n super(message)\n this.message = format(message, ...positionals)\n cleanErrorStack(this)\n }\n}\n\nexport interface CustomErrorConstructor {\n new (message: string): Error\n}\n\nexport interface CustomErrorFactory {\n (message: string): Error\n}\n\nexport type CustomError = CustomErrorConstructor | CustomErrorFactory\n\ntype Invariant = {\n (\n predicate: unknown,\n message: string,\n ...positionals: any[]\n ): asserts predicate\n\n as(\n ErrorConstructor: CustomError,\n predicate: unknown,\n message: string,\n ...positionals: unknown[]\n ): asserts predicate\n}\n\nexport const invariant: Invariant = (\n predicate,\n message,\n ...positionals\n): asserts predicate => {\n if (!predicate) {\n throw new InvariantError(message, ...positionals)\n }\n}\n\ninvariant.as = (ErrorConstructor, predicate, message, ...positionals) => {\n if (!predicate) {\n const formatMessage =\n positionals.length === 0 ? message : format(message, ...positionals)\n let error: Error\n\n try {\n error = Reflect.construct(ErrorConstructor as CustomErrorConstructor, [\n formatMessage,\n ])\n } catch (err) {\n error = (ErrorConstructor as CustomErrorFactory)(formatMessage)\n }\n\n throw error\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAM,kBAAkB;AAExB,SAAS,oBAAoB,YAAiB,MAAmB;AAC/D,UAAQ,MAAM;AAAA,IAEZ,KAAK;AACH,aAAO;AAAA,IAGT,KAAK;AAAA,IACL,KAAK;AACH,aAAO,OAAO,UAAU;AAAA,IAG1B,KAAK;AACH,aAAO,KAAK,UAAU,UAAU;AAAA,IAGlC,KAAK,KAAK;AAER,UAAI,OAAO,eAAe,UAAU;AAClC,eAAO;AAAA,MACT;AAEA,YAAM,OAAO,KAAK,UAAU,UAAU;AAGtC,UAAI,SAAS,QAAQ,SAAS,QAAQ,mBAAmB,KAAK,IAAI,GAAG;AACnE,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,SAAS,OAAO,YAAoB,aAA4B;AACrE,MAAI,YAAY,WAAW,GAAG;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI,kBAAkB;AACtB,MAAI,mBAAmB,QAAQ;AAAA,IAC7B;AAAA,IACA,CAAC,OAAO,WAAW,GAAG,SAAS;AAC7B,YAAM,aAAa,YAAY;AAC/B,YAAM,QAAQ,oBAAoB,YAAY,IAAI;AAElD,UAAI,CAAC,WAAW;AACd;AACA,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,MAAI,kBAAkB,YAAY,QAAQ;AACxC,wBAAoB,IAAI,YAAY,MAAM,eAAe,EAAE,KAAK,GAAG;AAAA,EACrE;AAEA,qBAAmB,iBAAiB,QAAQ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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// src/format.ts
|
| 2 |
+
var POSITIONALS_EXP = /(%?)(%([sdijo]))/g;
|
| 3 |
+
function serializePositional(positional, flag) {
|
| 4 |
+
switch (flag) {
|
| 5 |
+
case "s":
|
| 6 |
+
return positional;
|
| 7 |
+
case "d":
|
| 8 |
+
case "i":
|
| 9 |
+
return Number(positional);
|
| 10 |
+
case "j":
|
| 11 |
+
return JSON.stringify(positional);
|
| 12 |
+
case "o": {
|
| 13 |
+
if (typeof positional === "string") {
|
| 14 |
+
return positional;
|
| 15 |
+
}
|
| 16 |
+
const json = JSON.stringify(positional);
|
| 17 |
+
if (json === "{}" || json === "[]" || /^\[object .+?\]$/.test(json)) {
|
| 18 |
+
return positional;
|
| 19 |
+
}
|
| 20 |
+
return json;
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
function format(message, ...positionals) {
|
| 25 |
+
if (positionals.length === 0) {
|
| 26 |
+
return message;
|
| 27 |
+
}
|
| 28 |
+
let positionalIndex = 0;
|
| 29 |
+
let formattedMessage = message.replace(
|
| 30 |
+
POSITIONALS_EXP,
|
| 31 |
+
(match, isEscaped, _, flag) => {
|
| 32 |
+
const positional = positionals[positionalIndex];
|
| 33 |
+
const value = serializePositional(positional, flag);
|
| 34 |
+
if (!isEscaped) {
|
| 35 |
+
positionalIndex++;
|
| 36 |
+
return value;
|
| 37 |
+
}
|
| 38 |
+
return match;
|
| 39 |
+
}
|
| 40 |
+
);
|
| 41 |
+
if (positionalIndex < positionals.length) {
|
| 42 |
+
formattedMessage += ` ${positionals.slice(positionalIndex).join(" ")}`;
|
| 43 |
+
}
|
| 44 |
+
formattedMessage = formattedMessage.replace(/%{2,2}/g, "%");
|
| 45 |
+
return formattedMessage;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
// src/invariant.ts
|
| 49 |
+
var STACK_FRAMES_TO_IGNORE = 2;
|
| 50 |
+
function cleanErrorStack(error) {
|
| 51 |
+
if (!error.stack) {
|
| 52 |
+
return;
|
| 53 |
+
}
|
| 54 |
+
const nextStack = error.stack.split("\n");
|
| 55 |
+
nextStack.splice(1, STACK_FRAMES_TO_IGNORE);
|
| 56 |
+
error.stack = nextStack.join("\n");
|
| 57 |
+
}
|
| 58 |
+
var InvariantError = class extends Error {
|
| 59 |
+
constructor(message, ...positionals) {
|
| 60 |
+
super(message);
|
| 61 |
+
this.message = message;
|
| 62 |
+
this.name = "Invariant Violation";
|
| 63 |
+
this.message = format(message, ...positionals);
|
| 64 |
+
cleanErrorStack(this);
|
| 65 |
+
}
|
| 66 |
+
};
|
| 67 |
+
var invariant = (predicate, message, ...positionals) => {
|
| 68 |
+
if (!predicate) {
|
| 69 |
+
throw new InvariantError(message, ...positionals);
|
| 70 |
+
}
|
| 71 |
+
};
|
| 72 |
+
invariant.as = (ErrorConstructor, predicate, message, ...positionals) => {
|
| 73 |
+
if (!predicate) {
|
| 74 |
+
const formatMessage = positionals.length === 0 ? message : format(message, ...positionals);
|
| 75 |
+
let error;
|
| 76 |
+
try {
|
| 77 |
+
error = Reflect.construct(ErrorConstructor, [
|
| 78 |
+
formatMessage
|
| 79 |
+
]);
|
| 80 |
+
} catch (err) {
|
| 81 |
+
error = ErrorConstructor(formatMessage);
|
| 82 |
+
}
|
| 83 |
+
throw error;
|
| 84 |
+
}
|
| 85 |
+
};
|
| 86 |
+
export {
|
| 87 |
+
InvariantError,
|
| 88 |
+
format,
|
| 89 |
+
invariant
|
| 90 |
+
};
|
| 91 |
+
//# sourceMappingURL=index.mjs.map
|
node_modules/outvariant/lib/index.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"sources":["../src/format.ts","../src/invariant.ts"],"sourcesContent":["const POSITIONALS_EXP = /(%?)(%([sdijo]))/g\n\nfunction serializePositional(positional: any, flag: string): any {\n switch (flag) {\n // Strings.\n case 's':\n return positional\n\n // Digits.\n case 'd':\n case 'i':\n return Number(positional)\n\n // JSON.\n case 'j':\n return JSON.stringify(positional)\n\n // Objects.\n case 'o': {\n // Preserve stings to prevent extra quotes around them.\n if (typeof positional === 'string') {\n return positional\n }\n\n const json = JSON.stringify(positional)\n\n // If the positional isn't serializable, return it as-is.\n if (json === '{}' || json === '[]' || /^\\[object .+?\\]$/.test(json)) {\n return positional\n }\n\n return json\n }\n }\n}\n\nexport function format(message: string, ...positionals: any[]): string {\n if (positionals.length === 0) {\n return message\n }\n\n let positionalIndex = 0\n let formattedMessage = message.replace(\n POSITIONALS_EXP,\n (match, isEscaped, _, flag) => {\n const positional = positionals[positionalIndex]\n const value = serializePositional(positional, flag)\n\n if (!isEscaped) {\n positionalIndex++\n return value\n }\n\n return match\n }\n )\n\n // Append unresolved positionals to string as-is.\n if (positionalIndex < positionals.length) {\n formattedMessage += ` ${positionals.slice(positionalIndex).join(' ')}`\n }\n\n formattedMessage = formattedMessage.replace(/%{2,2}/g, '%')\n\n return formattedMessage\n}\n","import { format } from './format'\n\nconst STACK_FRAMES_TO_IGNORE = 2\n\n/**\n * Remove the \"outvariant\" package trace from the given error.\n * This scopes down the error stack to the relevant parts\n * when used in other applications.\n */\nfunction cleanErrorStack(error: Error): void {\n if (!error.stack) {\n return\n }\n\n const nextStack = error.stack.split('\\n')\n nextStack.splice(1, STACK_FRAMES_TO_IGNORE)\n error.stack = nextStack.join('\\n')\n}\n\nexport class InvariantError extends Error {\n name = 'Invariant Violation'\n\n constructor(public readonly message: string, ...positionals: any[]) {\n super(message)\n this.message = format(message, ...positionals)\n cleanErrorStack(this)\n }\n}\n\nexport interface CustomErrorConstructor {\n new (message: string): Error\n}\n\nexport interface CustomErrorFactory {\n (message: string): Error\n}\n\nexport type CustomError = CustomErrorConstructor | CustomErrorFactory\n\ntype Invariant = {\n (\n predicate: unknown,\n message: string,\n ...positionals: any[]\n ): asserts predicate\n\n as(\n ErrorConstructor: CustomError,\n predicate: unknown,\n message: string,\n ...positionals: unknown[]\n ): asserts predicate\n}\n\nexport const invariant: Invariant = (\n predicate,\n message,\n ...positionals\n): asserts predicate => {\n if (!predicate) {\n throw new InvariantError(message, ...positionals)\n }\n}\n\ninvariant.as = (ErrorConstructor, predicate, message, ...positionals) => {\n if (!predicate) {\n const formatMessage =\n positionals.length === 0 ? message : format(message, ...positionals)\n let error: Error\n\n try {\n error = Reflect.construct(ErrorConstructor as CustomErrorConstructor, [\n formatMessage,\n ])\n } catch (err) {\n error = (ErrorConstructor as CustomErrorFactory)(formatMessage)\n }\n\n throw error\n }\n}\n"],"mappings":";AAAA,IAAM,kBAAkB;AAExB,SAAS,oBAAoB,YAAiB,MAAmB;AAC/D,UAAQ,MAAM;AAAA,IAEZ,KAAK;AACH,aAAO;AAAA,IAGT,KAAK;AAAA,IACL,KAAK;AACH,aAAO,OAAO,UAAU;AAAA,IAG1B,KAAK;AACH,aAAO,KAAK,UAAU,UAAU;AAAA,IAGlC,KAAK,KAAK;AAER,UAAI,OAAO,eAAe,UAAU;AAClC,eAAO;AAAA,MACT;AAEA,YAAM,OAAO,KAAK,UAAU,UAAU;AAGtC,UAAI,SAAS,QAAQ,SAAS,QAAQ,mBAAmB,KAAK,IAAI,GAAG;AACnE,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,SAAS,OAAO,YAAoB,aAA4B;AACrE,MAAI,YAAY,WAAW,GAAG;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI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UAAM;AAAA,EACR;AACF;","names":[]}
|
node_modules/outvariant/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "outvariant",
|
| 3 |
+
"version": "1.4.3",
|
| 4 |
+
"description": "Type-safe implementation of invariant with positionals.",
|
| 5 |
+
"main": "lib/index.js",
|
| 6 |
+
"module": "lib/index.mjs",
|
| 7 |
+
"typings": "lib/index.d.ts",
|
| 8 |
+
"exports": {
|
| 9 |
+
".": {
|
| 10 |
+
"types": "./lib/index.d.ts",
|
| 11 |
+
"require": "./lib/index.js",
|
| 12 |
+
"default": "./lib/index.mjs"
|
| 13 |
+
}
|
| 14 |
+
},
|
| 15 |
+
"author": "Artem Zakharchenko",
|
| 16 |
+
"license": "MIT",
|
| 17 |
+
"scripts": {
|
| 18 |
+
"test": "jest",
|
| 19 |
+
"clean": "rimraf ./lib",
|
| 20 |
+
"build": "yarn clean && tsup",
|
| 21 |
+
"prepublishOnly": "yarn test && yarn build",
|
| 22 |
+
"release": "release publish"
|
| 23 |
+
},
|
| 24 |
+
"files": [
|
| 25 |
+
"lib"
|
| 26 |
+
],
|
| 27 |
+
"keywords": [
|
| 28 |
+
"invariant",
|
| 29 |
+
"outvariant",
|
| 30 |
+
"exception",
|
| 31 |
+
"positional"
|
| 32 |
+
],
|
| 33 |
+
"devDependencies": {
|
| 34 |
+
"@ossjs/release": "^0.8.0",
|
| 35 |
+
"@types/jest": "^26.0.23",
|
| 36 |
+
"jest": "^27.0.6",
|
| 37 |
+
"rimraf": "^3.0.2",
|
| 38 |
+
"ts-jest": "^27.0.3",
|
| 39 |
+
"ts-node": "^10.0.0",
|
| 40 |
+
"tsup": "^6.2.3",
|
| 41 |
+
"typescript": "^4.3.4"
|
| 42 |
+
},
|
| 43 |
+
"repository": {
|
| 44 |
+
"type": "git",
|
| 45 |
+
"url": "https://github.com/open-draft/outvariant"
|
| 46 |
+
}
|
| 47 |
+
}
|
node_modules/p-limit/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare namespace pLimit {
|
| 2 |
+
interface Limit {
|
| 3 |
+
/**
|
| 4 |
+
The number of promises that are currently running.
|
| 5 |
+
*/
|
| 6 |
+
readonly activeCount: number;
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
The number of promises that are waiting to run (i.e. their internal `fn` was not called yet).
|
| 10 |
+
*/
|
| 11 |
+
readonly pendingCount: number;
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
Discard pending promises that are waiting to run.
|
| 15 |
+
|
| 16 |
+
This might be useful if you want to teardown the queue at the end of your program's lifecycle or discard any function calls referencing an intermediary state of your app.
|
| 17 |
+
|
| 18 |
+
Note: This does not cancel promises that are already running.
|
| 19 |
+
*/
|
| 20 |
+
clearQueue: () => void;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
@param fn - Promise-returning/async function.
|
| 24 |
+
@param arguments - Any arguments to pass through to `fn`. Support for passing arguments on to the `fn` is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a lot of functions.
|
| 25 |
+
@returns The promise returned by calling `fn(...arguments)`.
|
| 26 |
+
*/
|
| 27 |
+
<Arguments extends unknown[], ReturnType>(
|
| 28 |
+
fn: (...arguments: Arguments) => PromiseLike<ReturnType> | ReturnType,
|
| 29 |
+
...arguments: Arguments
|
| 30 |
+
): Promise<ReturnType>;
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
Run multiple promise-returning & async functions with limited concurrency.
|
| 36 |
+
|
| 37 |
+
@param concurrency - Concurrency limit. Minimum: `1`.
|
| 38 |
+
@returns A `limit` function.
|
| 39 |
+
*/
|
| 40 |
+
declare function pLimit(concurrency: number): pLimit.Limit;
|
| 41 |
+
|
| 42 |
+
export = pLimit;
|
node_modules/p-limit/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
const Queue = require('yocto-queue');
|
| 3 |
+
|
| 4 |
+
const pLimit = concurrency => {
|
| 5 |
+
if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
|
| 6 |
+
throw new TypeError('Expected `concurrency` to be a number from 1 and up');
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
const queue = new Queue();
|
| 10 |
+
let activeCount = 0;
|
| 11 |
+
|
| 12 |
+
const next = () => {
|
| 13 |
+
activeCount--;
|
| 14 |
+
|
| 15 |
+
if (queue.size > 0) {
|
| 16 |
+
queue.dequeue()();
|
| 17 |
+
}
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
const run = async (fn, resolve, ...args) => {
|
| 21 |
+
activeCount++;
|
| 22 |
+
|
| 23 |
+
const result = (async () => fn(...args))();
|
| 24 |
+
|
| 25 |
+
resolve(result);
|
| 26 |
+
|
| 27 |
+
try {
|
| 28 |
+
await result;
|
| 29 |
+
} catch {}
|
| 30 |
+
|
| 31 |
+
next();
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
const enqueue = (fn, resolve, ...args) => {
|
| 35 |
+
queue.enqueue(run.bind(null, fn, resolve, ...args));
|
| 36 |
+
|
| 37 |
+
(async () => {
|
| 38 |
+
// This function needs to wait until the next microtask before comparing
|
| 39 |
+
// `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
|
| 40 |
+
// when the run function is dequeued and called. The comparison in the if-statement
|
| 41 |
+
// needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
|
| 42 |
+
await Promise.resolve();
|
| 43 |
+
|
| 44 |
+
if (activeCount < concurrency && queue.size > 0) {
|
| 45 |
+
queue.dequeue()();
|
| 46 |
+
}
|
| 47 |
+
})();
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
const generator = (fn, ...args) => new Promise(resolve => {
|
| 51 |
+
enqueue(fn, resolve, ...args);
|
| 52 |
+
});
|
| 53 |
+
|
| 54 |
+
Object.defineProperties(generator, {
|
| 55 |
+
activeCount: {
|
| 56 |
+
get: () => activeCount
|
| 57 |
+
},
|
| 58 |
+
pendingCount: {
|
| 59 |
+
get: () => queue.size
|
| 60 |
+
},
|
| 61 |
+
clearQueue: {
|
| 62 |
+
value: () => {
|
| 63 |
+
queue.clear();
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
});
|
| 67 |
+
|
| 68 |
+
return generator;
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
module.exports = pLimit;
|
node_modules/p-limit/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 6 |
+
|
| 7 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
node_modules/p-limit/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "p-limit",
|
| 3 |
+
"version": "3.1.0",
|
| 4 |
+
"description": "Run multiple promise-returning & async functions with limited concurrency",
|
| 5 |
+
"license": "MIT",
|
| 6 |
+
"repository": "sindresorhus/p-limit",
|
| 7 |
+
"funding": "https://github.com/sponsors/sindresorhus",
|
| 8 |
+
"author": {
|
| 9 |
+
"name": "Sindre Sorhus",
|
| 10 |
+
"email": "sindresorhus@gmail.com",
|
| 11 |
+
"url": "https://sindresorhus.com"
|
| 12 |
+
},
|
| 13 |
+
"engines": {
|
| 14 |
+
"node": ">=10"
|
| 15 |
+
},
|
| 16 |
+
"scripts": {
|
| 17 |
+
"test": "xo && ava && tsd"
|
| 18 |
+
},
|
| 19 |
+
"files": [
|
| 20 |
+
"index.js",
|
| 21 |
+
"index.d.ts"
|
| 22 |
+
],
|
| 23 |
+
"keywords": [
|
| 24 |
+
"promise",
|
| 25 |
+
"limit",
|
| 26 |
+
"limited",
|
| 27 |
+
"concurrency",
|
| 28 |
+
"throttle",
|
| 29 |
+
"throat",
|
| 30 |
+
"rate",
|
| 31 |
+
"batch",
|
| 32 |
+
"ratelimit",
|
| 33 |
+
"task",
|
| 34 |
+
"queue",
|
| 35 |
+
"async",
|
| 36 |
+
"await",
|
| 37 |
+
"promises",
|
| 38 |
+
"bluebird"
|
| 39 |
+
],
|
| 40 |
+
"dependencies": {
|
| 41 |
+
"yocto-queue": "^0.1.0"
|
| 42 |
+
},
|
| 43 |
+
"devDependencies": {
|
| 44 |
+
"ava": "^2.4.0",
|
| 45 |
+
"delay": "^4.4.0",
|
| 46 |
+
"in-range": "^2.0.0",
|
| 47 |
+
"random-int": "^2.0.1",
|
| 48 |
+
"time-span": "^4.0.0",
|
| 49 |
+
"tsd": "^0.13.1",
|
| 50 |
+
"xo": "^0.35.0"
|
| 51 |
+
}
|
| 52 |
+
}
|
node_modules/p-limit/readme.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p-limit
|
| 2 |
+
|
| 3 |
+
> Run multiple promise-returning & async functions with limited concurrency
|
| 4 |
+
|
| 5 |
+
## Install
|
| 6 |
+
|
| 7 |
+
```
|
| 8 |
+
$ npm install p-limit
|
| 9 |
+
```
|
| 10 |
+
|
| 11 |
+
## Usage
|
| 12 |
+
|
| 13 |
+
```js
|
| 14 |
+
const pLimit = require('p-limit');
|
| 15 |
+
|
| 16 |
+
const limit = pLimit(1);
|
| 17 |
+
|
| 18 |
+
const input = [
|
| 19 |
+
limit(() => fetchSomething('foo')),
|
| 20 |
+
limit(() => fetchSomething('bar')),
|
| 21 |
+
limit(() => doSomething())
|
| 22 |
+
];
|
| 23 |
+
|
| 24 |
+
(async () => {
|
| 25 |
+
// Only one promise is run at once
|
| 26 |
+
const result = await Promise.all(input);
|
| 27 |
+
console.log(result);
|
| 28 |
+
})();
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
## API
|
| 32 |
+
|
| 33 |
+
### pLimit(concurrency)
|
| 34 |
+
|
| 35 |
+
Returns a `limit` function.
|
| 36 |
+
|
| 37 |
+
#### concurrency
|
| 38 |
+
|
| 39 |
+
Type: `number`\
|
| 40 |
+
Minimum: `1`\
|
| 41 |
+
Default: `Infinity`
|
| 42 |
+
|
| 43 |
+
Concurrency limit.
|
| 44 |
+
|
| 45 |
+
### limit(fn, ...args)
|
| 46 |
+
|
| 47 |
+
Returns the promise returned by calling `fn(...args)`.
|
| 48 |
+
|
| 49 |
+
#### fn
|
| 50 |
+
|
| 51 |
+
Type: `Function`
|
| 52 |
+
|
| 53 |
+
Promise-returning/async function.
|
| 54 |
+
|
| 55 |
+
#### args
|
| 56 |
+
|
| 57 |
+
Any arguments to pass through to `fn`.
|
| 58 |
+
|
| 59 |
+
Support for passing arguments on to the `fn` is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a *lot* of functions.
|
| 60 |
+
|
| 61 |
+
### limit.activeCount
|
| 62 |
+
|
| 63 |
+
The number of promises that are currently running.
|
| 64 |
+
|
| 65 |
+
### limit.pendingCount
|
| 66 |
+
|
| 67 |
+
The number of promises that are waiting to run (i.e. their internal `fn` was not called yet).
|
| 68 |
+
|
| 69 |
+
### limit.clearQueue()
|
| 70 |
+
|
| 71 |
+
Discard pending promises that are waiting to run.
|
| 72 |
+
|
| 73 |
+
This might be useful if you want to teardown the queue at the end of your program's lifecycle or discard any function calls referencing an intermediary state of your app.
|
| 74 |
+
|
| 75 |
+
Note: This does not cancel promises that are already running.
|
| 76 |
+
|
| 77 |
+
## FAQ
|
| 78 |
+
|
| 79 |
+
### How is this different from the [`p-queue`](https://github.com/sindresorhus/p-queue) package?
|
| 80 |
+
|
| 81 |
+
This package is only about limiting the number of concurrent executions, while `p-queue` is a fully featured queue implementation with lots of different options, introspection, and ability to pause the queue.
|
| 82 |
+
|
| 83 |
+
## Related
|
| 84 |
+
|
| 85 |
+
- [p-queue](https://github.com/sindresorhus/p-queue) - Promise queue with concurrency control
|
| 86 |
+
- [p-throttle](https://github.com/sindresorhus/p-throttle) - Throttle promise-returning & async functions
|
| 87 |
+
- [p-debounce](https://github.com/sindresorhus/p-debounce) - Debounce promise-returning & async functions
|
| 88 |
+
- [p-all](https://github.com/sindresorhus/p-all) - Run promise-returning & async functions concurrently with optional limited concurrency
|
| 89 |
+
- [More…](https://github.com/sindresorhus/promise-fun)
|
| 90 |
+
|
| 91 |
+
---
|
| 92 |
+
|
| 93 |
+
<div align="center">
|
| 94 |
+
<b>
|
| 95 |
+
<a href="https://tidelift.com/subscription/pkg/npm-p-limit?utm_source=npm-p-limit&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
| 96 |
+
</b>
|
| 97 |
+
<br>
|
| 98 |
+
<sub>
|
| 99 |
+
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
| 100 |
+
</sub>
|
| 101 |
+
</div>
|
node_modules/p-locate/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare namespace pLocate {
|
| 2 |
+
interface Options {
|
| 3 |
+
/**
|
| 4 |
+
Number of concurrently pending promises returned by `tester`. Minimum: `1`.
|
| 5 |
+
|
| 6 |
+
@default Infinity
|
| 7 |
+
*/
|
| 8 |
+
readonly concurrency?: number;
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
Preserve `input` order when searching.
|
| 12 |
+
|
| 13 |
+
Disable this to improve performance if you don't care about the order.
|
| 14 |
+
|
| 15 |
+
@default true
|
| 16 |
+
*/
|
| 17 |
+
readonly preserveOrder?: boolean;
|
| 18 |
+
}
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
Get the first fulfilled promise that satisfies the provided testing function.
|
| 23 |
+
|
| 24 |
+
@param input - An iterable of promises/values to test.
|
| 25 |
+
@param tester - This function will receive resolved values from `input` and is expected to return a `Promise<boolean>` or `boolean`.
|
| 26 |
+
@returns A `Promise` that is fulfilled when `tester` resolves to `true` or the iterable is done, or rejects if any of the promises reject. The fulfilled value is the current iterable value or `undefined` if `tester` never resolved to `true`.
|
| 27 |
+
|
| 28 |
+
@example
|
| 29 |
+
```
|
| 30 |
+
import pathExists = require('path-exists');
|
| 31 |
+
import pLocate = require('p-locate');
|
| 32 |
+
|
| 33 |
+
const files = [
|
| 34 |
+
'unicorn.png',
|
| 35 |
+
'rainbow.png', // Only this one actually exists on disk
|
| 36 |
+
'pony.png'
|
| 37 |
+
];
|
| 38 |
+
|
| 39 |
+
(async () => {
|
| 40 |
+
const foundPath = await pLocate(files, file => pathExists(file));
|
| 41 |
+
|
| 42 |
+
console.log(foundPath);
|
| 43 |
+
//=> 'rainbow'
|
| 44 |
+
})();
|
| 45 |
+
```
|
| 46 |
+
*/
|
| 47 |
+
declare function pLocate<ValueType>(
|
| 48 |
+
input: Iterable<PromiseLike<ValueType> | ValueType>,
|
| 49 |
+
tester: (element: ValueType) => PromiseLike<boolean> | boolean,
|
| 50 |
+
options?: pLocate.Options
|
| 51 |
+
): Promise<ValueType | undefined>;
|
| 52 |
+
|
| 53 |
+
export = pLocate;
|
node_modules/p-locate/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
const pLimit = require('p-limit');
|
| 3 |
+
|
| 4 |
+
class EndError extends Error {
|
| 5 |
+
constructor(value) {
|
| 6 |
+
super();
|
| 7 |
+
this.value = value;
|
| 8 |
+
}
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
// The input can also be a promise, so we await it
|
| 12 |
+
const testElement = async (element, tester) => tester(await element);
|
| 13 |
+
|
| 14 |
+
// The input can also be a promise, so we `Promise.all()` them both
|
| 15 |
+
const finder = async element => {
|
| 16 |
+
const values = await Promise.all(element);
|
| 17 |
+
if (values[1] === true) {
|
| 18 |
+
throw new EndError(values[0]);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
return false;
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
const pLocate = async (iterable, tester, options) => {
|
| 25 |
+
options = {
|
| 26 |
+
concurrency: Infinity,
|
| 27 |
+
preserveOrder: true,
|
| 28 |
+
...options
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
const limit = pLimit(options.concurrency);
|
| 32 |
+
|
| 33 |
+
// Start all the promises concurrently with optional limit
|
| 34 |
+
const items = [...iterable].map(element => [element, limit(testElement, element, tester)]);
|
| 35 |
+
|
| 36 |
+
// Check the promises either serially or concurrently
|
| 37 |
+
const checkLimit = pLimit(options.preserveOrder ? 1 : Infinity);
|
| 38 |
+
|
| 39 |
+
try {
|
| 40 |
+
await Promise.all(items.map(element => checkLimit(finder, element)));
|
| 41 |
+
} catch (error) {
|
| 42 |
+
if (error instanceof EndError) {
|
| 43 |
+
return error.value;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
throw error;
|
| 47 |
+
}
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
module.exports = pLocate;
|
node_modules/p-locate/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 6 |
+
|
| 7 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
node_modules/p-locate/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "p-locate",
|
| 3 |
+
"version": "5.0.0",
|
| 4 |
+
"description": "Get the first fulfilled promise that satisfies the provided testing function",
|
| 5 |
+
"license": "MIT",
|
| 6 |
+
"repository": "sindresorhus/p-locate",
|
| 7 |
+
"funding": "https://github.com/sponsors/sindresorhus",
|
| 8 |
+
"author": {
|
| 9 |
+
"name": "Sindre Sorhus",
|
| 10 |
+
"email": "sindresorhus@gmail.com",
|
| 11 |
+
"url": "https://sindresorhus.com"
|
| 12 |
+
},
|
| 13 |
+
"engines": {
|
| 14 |
+
"node": ">=10"
|
| 15 |
+
},
|
| 16 |
+
"scripts": {
|
| 17 |
+
"test": "xo && ava && tsd"
|
| 18 |
+
},
|
| 19 |
+
"files": [
|
| 20 |
+
"index.js",
|
| 21 |
+
"index.d.ts"
|
| 22 |
+
],
|
| 23 |
+
"keywords": [
|
| 24 |
+
"promise",
|
| 25 |
+
"locate",
|
| 26 |
+
"find",
|
| 27 |
+
"finder",
|
| 28 |
+
"search",
|
| 29 |
+
"searcher",
|
| 30 |
+
"test",
|
| 31 |
+
"array",
|
| 32 |
+
"collection",
|
| 33 |
+
"iterable",
|
| 34 |
+
"iterator",
|
| 35 |
+
"race",
|
| 36 |
+
"fulfilled",
|
| 37 |
+
"fastest",
|
| 38 |
+
"async",
|
| 39 |
+
"await",
|
| 40 |
+
"promises",
|
| 41 |
+
"bluebird"
|
| 42 |
+
],
|
| 43 |
+
"dependencies": {
|
| 44 |
+
"p-limit": "^3.0.2"
|
| 45 |
+
},
|
| 46 |
+
"devDependencies": {
|
| 47 |
+
"ava": "^2.4.0",
|
| 48 |
+
"delay": "^4.1.0",
|
| 49 |
+
"in-range": "^2.0.0",
|
| 50 |
+
"time-span": "^4.0.0",
|
| 51 |
+
"tsd": "^0.13.1",
|
| 52 |
+
"xo": "^0.32.1"
|
| 53 |
+
}
|
| 54 |
+
}
|
node_modules/p-locate/readme.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p-locate [](https://travis-ci.com/github/sindresorhus/p-locate)
|
| 2 |
+
|
| 3 |
+
> Get the first fulfilled promise that satisfies the provided testing function
|
| 4 |
+
|
| 5 |
+
Think of it like an async version of [`Array#find`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find).
|
| 6 |
+
|
| 7 |
+
## Install
|
| 8 |
+
|
| 9 |
+
```
|
| 10 |
+
$ npm install p-locate
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
## Usage
|
| 14 |
+
|
| 15 |
+
Here we find the first file that exists on disk, in array order.
|
| 16 |
+
|
| 17 |
+
```js
|
| 18 |
+
const pathExists = require('path-exists');
|
| 19 |
+
const pLocate = require('p-locate');
|
| 20 |
+
|
| 21 |
+
const files = [
|
| 22 |
+
'unicorn.png',
|
| 23 |
+
'rainbow.png', // Only this one actually exists on disk
|
| 24 |
+
'pony.png'
|
| 25 |
+
];
|
| 26 |
+
|
| 27 |
+
(async () => {
|
| 28 |
+
const foundPath = await pLocate(files, file => pathExists(file));
|
| 29 |
+
|
| 30 |
+
console.log(foundPath);
|
| 31 |
+
//=> 'rainbow'
|
| 32 |
+
})();
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
*The above is just an example. Use [`locate-path`](https://github.com/sindresorhus/locate-path) if you need this.*
|
| 36 |
+
|
| 37 |
+
## API
|
| 38 |
+
|
| 39 |
+
### pLocate(input, tester, options?)
|
| 40 |
+
|
| 41 |
+
Returns a `Promise` that is fulfilled when `tester` resolves to `true` or the iterable is done, or rejects if any of the promises reject. The fulfilled value is the current iterable value or `undefined` if `tester` never resolved to `true`.
|
| 42 |
+
|
| 43 |
+
#### input
|
| 44 |
+
|
| 45 |
+
Type: `Iterable<Promise | unknown>`
|
| 46 |
+
|
| 47 |
+
An iterable of promises/values to test.
|
| 48 |
+
|
| 49 |
+
#### tester(element)
|
| 50 |
+
|
| 51 |
+
Type: `Function`
|
| 52 |
+
|
| 53 |
+
This function will receive resolved values from `input` and is expected to return a `Promise<boolean>` or `boolean`.
|
| 54 |
+
|
| 55 |
+
#### options
|
| 56 |
+
|
| 57 |
+
Type: `object`
|
| 58 |
+
|
| 59 |
+
##### concurrency
|
| 60 |
+
|
| 61 |
+
Type: `number`\
|
| 62 |
+
Default: `Infinity`\
|
| 63 |
+
Minimum: `1`
|
| 64 |
+
|
| 65 |
+
Number of concurrently pending promises returned by `tester`.
|
| 66 |
+
|
| 67 |
+
##### preserveOrder
|
| 68 |
+
|
| 69 |
+
Type: `boolean`\
|
| 70 |
+
Default: `true`
|
| 71 |
+
|
| 72 |
+
Preserve `input` order when searching.
|
| 73 |
+
|
| 74 |
+
Disable this to improve performance if you don't care about the order.
|
| 75 |
+
|
| 76 |
+
## Related
|
| 77 |
+
|
| 78 |
+
- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
|
| 79 |
+
- [p-filter](https://github.com/sindresorhus/p-filter) - Filter promises concurrently
|
| 80 |
+
- [p-any](https://github.com/sindresorhus/p-any) - Wait for any promise to be fulfilled
|
| 81 |
+
- [More…](https://github.com/sindresorhus/promise-fun)
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
<div align="center">
|
| 86 |
+
<b>
|
| 87 |
+
<a href="https://tidelift.com/subscription/pkg/npm-p-locate?utm_source=npm-p-locate&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
| 88 |
+
</b>
|
| 89 |
+
<br>
|
| 90 |
+
<sub>
|
| 91 |
+
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
| 92 |
+
</sub>
|
| 93 |
+
</div>
|
node_modules/p-try/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare const pTry: {
|
| 2 |
+
/**
|
| 3 |
+
Start a promise chain.
|
| 4 |
+
|
| 5 |
+
@param fn - The function to run to start the promise chain.
|
| 6 |
+
@param arguments - Arguments to pass to `fn`.
|
| 7 |
+
@returns The value of calling `fn(...arguments)`. If the function throws an error, the returned `Promise` will be rejected with that error.
|
| 8 |
+
|
| 9 |
+
@example
|
| 10 |
+
```
|
| 11 |
+
import pTry = require('p-try');
|
| 12 |
+
|
| 13 |
+
(async () => {
|
| 14 |
+
try {
|
| 15 |
+
const value = await pTry(() => {
|
| 16 |
+
return synchronousFunctionThatMightThrow();
|
| 17 |
+
});
|
| 18 |
+
console.log(value);
|
| 19 |
+
} catch (error) {
|
| 20 |
+
console.error(error);
|
| 21 |
+
}
|
| 22 |
+
})();
|
| 23 |
+
```
|
| 24 |
+
*/
|
| 25 |
+
<ValueType, ArgumentsType extends unknown[]>(
|
| 26 |
+
fn: (...arguments: ArgumentsType) => PromiseLike<ValueType> | ValueType,
|
| 27 |
+
...arguments: ArgumentsType
|
| 28 |
+
): Promise<ValueType>;
|
| 29 |
+
|
| 30 |
+
// TODO: remove this in the next major version, refactor the whole definition to:
|
| 31 |
+
// declare function pTry<ValueType, ArgumentsType extends unknown[]>(
|
| 32 |
+
// fn: (...arguments: ArgumentsType) => PromiseLike<ValueType> | ValueType,
|
| 33 |
+
// ...arguments: ArgumentsType
|
| 34 |
+
// ): Promise<ValueType>;
|
| 35 |
+
// export = pTry;
|
| 36 |
+
default: typeof pTry;
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
export = pTry;
|
node_modules/p-try/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
const pTry = (fn, ...arguments_) => new Promise(resolve => {
|
| 4 |
+
resolve(fn(...arguments_));
|
| 5 |
+
});
|
| 6 |
+
|
| 7 |
+
module.exports = pTry;
|
| 8 |
+
// TODO: remove this in the next major version
|
| 9 |
+
module.exports.default = pTry;
|
node_modules/p-try/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 6 |
+
|
| 7 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
node_modules/p-try/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "p-try",
|
| 3 |
+
"version": "2.2.0",
|
| 4 |
+
"description": "`Start a promise chain",
|
| 5 |
+
"license": "MIT",
|
| 6 |
+
"repository": "sindresorhus/p-try",
|
| 7 |
+
"author": {
|
| 8 |
+
"name": "Sindre Sorhus",
|
| 9 |
+
"email": "sindresorhus@gmail.com",
|
| 10 |
+
"url": "sindresorhus.com"
|
| 11 |
+
},
|
| 12 |
+
"engines": {
|
| 13 |
+
"node": ">=6"
|
| 14 |
+
},
|
| 15 |
+
"scripts": {
|
| 16 |
+
"test": "xo && ava && tsd"
|
| 17 |
+
},
|
| 18 |
+
"files": [
|
| 19 |
+
"index.js",
|
| 20 |
+
"index.d.ts"
|
| 21 |
+
],
|
| 22 |
+
"keywords": [
|
| 23 |
+
"promise",
|
| 24 |
+
"try",
|
| 25 |
+
"resolve",
|
| 26 |
+
"function",
|
| 27 |
+
"catch",
|
| 28 |
+
"async",
|
| 29 |
+
"await",
|
| 30 |
+
"promises",
|
| 31 |
+
"settled",
|
| 32 |
+
"ponyfill",
|
| 33 |
+
"polyfill",
|
| 34 |
+
"shim",
|
| 35 |
+
"bluebird"
|
| 36 |
+
],
|
| 37 |
+
"devDependencies": {
|
| 38 |
+
"ava": "^1.4.1",
|
| 39 |
+
"tsd": "^0.7.1",
|
| 40 |
+
"xo": "^0.24.0"
|
| 41 |
+
}
|
| 42 |
+
}
|
node_modules/p-try/readme.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p-try [](https://travis-ci.org/sindresorhus/p-try)
|
| 2 |
+
|
| 3 |
+
> Start a promise chain
|
| 4 |
+
|
| 5 |
+
[How is it useful?](http://cryto.net/~joepie91/blog/2016/05/11/what-is-promise-try-and-why-does-it-matter/)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
## Install
|
| 9 |
+
|
| 10 |
+
```
|
| 11 |
+
$ npm install p-try
|
| 12 |
+
```
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
## Usage
|
| 16 |
+
|
| 17 |
+
```js
|
| 18 |
+
const pTry = require('p-try');
|
| 19 |
+
|
| 20 |
+
(async () => {
|
| 21 |
+
try {
|
| 22 |
+
const value = await pTry(() => {
|
| 23 |
+
return synchronousFunctionThatMightThrow();
|
| 24 |
+
});
|
| 25 |
+
console.log(value);
|
| 26 |
+
} catch (error) {
|
| 27 |
+
console.error(error);
|
| 28 |
+
}
|
| 29 |
+
})();
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
## API
|
| 34 |
+
|
| 35 |
+
### pTry(fn, ...arguments)
|
| 36 |
+
|
| 37 |
+
Returns a `Promise` resolved with the value of calling `fn(...arguments)`. If the function throws an error, the returned `Promise` will be rejected with that error.
|
| 38 |
+
|
| 39 |
+
Support for passing arguments on to the `fn` is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a *lot* of functions.
|
| 40 |
+
|
| 41 |
+
#### fn
|
| 42 |
+
|
| 43 |
+
The function to run to start the promise chain.
|
| 44 |
+
|
| 45 |
+
#### arguments
|
| 46 |
+
|
| 47 |
+
Arguments to pass to `fn`.
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
## Related
|
| 51 |
+
|
| 52 |
+
- [p-finally](https://github.com/sindresorhus/p-finally) - `Promise#finally()` ponyfill - Invoked when the promise is settled regardless of outcome
|
| 53 |
+
- [More…](https://github.com/sindresorhus/promise-fun)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
## License
|
| 57 |
+
|
| 58 |
+
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
node_modules/pako/CHANGELOG.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Changelog
|
| 2 |
+
|
| 3 |
+
All notable changes to this project will be documented in this file.
|
| 4 |
+
|
| 5 |
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
| 6 |
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
## [1.0.11] - 2020-01-29
|
| 10 |
+
### Fixed
|
| 11 |
+
- Fix tests in node.js v12+, #179.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
## [1.0.10] - 2019-02-28
|
| 15 |
+
### Fixed
|
| 16 |
+
- Fix minified version, #161.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
## [1.0.9] - 2019-02-28
|
| 20 |
+
### Fixed
|
| 21 |
+
- Fix `new Buffer()` warning, #154.
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
## [1.0.8] - 2019-01-14
|
| 25 |
+
### Fixed
|
| 26 |
+
- Fix raw inflate with dictionary, #155.
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
## [1.0.7] - 2018-11-29
|
| 30 |
+
### Fixed
|
| 31 |
+
- Fixed RangeError in Crome 72, #150.
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
## [1.0.6] - 2017-09-14
|
| 35 |
+
### Changed
|
| 36 |
+
- Improve @std/esm compatibility.
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
## [1.0.5] - 2017-03-17
|
| 40 |
+
### Changed
|
| 41 |
+
- Maintenance. More formal `zlib` attribution and related
|
| 42 |
+
changes, #93. Thanks to @bastien-roucaries for the help.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
## [1.0.4] - 2016-12-15
|
| 46 |
+
### Changed
|
| 47 |
+
- Bump dev dependencies.
|
| 48 |
+
|
| 49 |
+
### Fixed
|
| 50 |
+
- Make sure `err.message` is filled on throw.
|
| 51 |
+
|
| 52 |
+
### Added
|
| 53 |
+
- Code examples for utf-16 string encoding & object compression.
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
## [1.0.3] - 2016-07-25
|
| 57 |
+
### Fixed
|
| 58 |
+
- Maintenance: re-release to properly display latest version in npm registry
|
| 59 |
+
and badges. Because `npm publish` timestamp used instead of versions.
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
## [1.0.2] - 2016-07-21
|
| 63 |
+
### Fixed
|
| 64 |
+
- Fixed nasty bug in deflate (wrong `d_buf` offset), which could cause
|
| 65 |
+
broken data in some rare cases.
|
| 66 |
+
- Also released as 0.2.9 to give chance to old dependents, not updated to 1.x
|
| 67 |
+
version.
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
## [1.0.1] - 2016-04-01
|
| 71 |
+
### Added
|
| 72 |
+
- Added dictionary support. Thanks to @dignifiedquire.
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
## [1.0.0] - 2016-02-17
|
| 76 |
+
### Changed
|
| 77 |
+
- Maintenance release (semver, coding style).
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
## [0.2.8] - 2015-09-14
|
| 81 |
+
### Fixed
|
| 82 |
+
- Fixed regression after 0.2.4 for edge conditions in inflate wrapper (#65).
|
| 83 |
+
Added more tests to cover possible cases.
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
## [0.2.7] - 2015-06-09
|
| 87 |
+
### Added
|
| 88 |
+
- Added Z_SYNC_FLUSH support. Thanks to @TinoLange.
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
## [0.2.6] - 2015-03-24
|
| 92 |
+
### Added
|
| 93 |
+
- Allow ArrayBuffer input.
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
## [0.2.5] - 2014-07-19
|
| 97 |
+
### Fixed
|
| 98 |
+
- Workaround for Chrome 38.0.2096.0 script parser bug, #30.
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
## [0.2.4] - 2014-07-07
|
| 102 |
+
### Fixed
|
| 103 |
+
- Fixed bug in inflate wrapper, #29
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
## [0.2.3] - 2014-06-09
|
| 107 |
+
### Changed
|
| 108 |
+
- Maintenance release, dependencies update.
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
## [0.2.2] - 2014-06-04
|
| 112 |
+
### Fixed
|
| 113 |
+
- Fixed iOS 5.1 Safari issue with `apply(typed_array)`, #26.
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
## [0.2.1] - 2014-05-01
|
| 117 |
+
### Fixed
|
| 118 |
+
- Fixed collision on switch dynamic/fixed tables.
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
## [0.2.0] - 2014-04-18
|
| 122 |
+
### Added
|
| 123 |
+
- Added custom gzip headers support.
|
| 124 |
+
- Added strings support.
|
| 125 |
+
- More coverage tests.
|
| 126 |
+
|
| 127 |
+
### Fixed
|
| 128 |
+
- Improved memory allocations for small chunks.
|
| 129 |
+
- ZStream properties rename/cleanup.
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
## [0.1.1] - 2014-03-20
|
| 133 |
+
### Fixed
|
| 134 |
+
- Bugfixes for inflate/deflate.
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
## [0.1.0] - 2014-03-15
|
| 138 |
+
### Added
|
| 139 |
+
- First release.
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
[1.0.10]: https://github.com/nodeca/pako/compare/1.0.10...1.0.11
|
| 143 |
+
[1.0.10]: https://github.com/nodeca/pako/compare/1.0.9...1.0.10
|
| 144 |
+
[1.0.9]: https://github.com/nodeca/pako/compare/1.0.8...1.0.9
|
| 145 |
+
[1.0.8]: https://github.com/nodeca/pako/compare/1.0.7...1.0.8
|
| 146 |
+
[1.0.7]: https://github.com/nodeca/pako/compare/1.0.6...1.0.7
|
| 147 |
+
[1.0.6]: https://github.com/nodeca/pako/compare/1.0.5...1.0.6
|
| 148 |
+
[1.0.5]: https://github.com/nodeca/pako/compare/1.0.4...1.0.5
|
| 149 |
+
[1.0.4]: https://github.com/nodeca/pako/compare/1.0.3...1.0.4
|
| 150 |
+
[1.0.3]: https://github.com/nodeca/pako/compare/1.0.2...1.0.3
|
| 151 |
+
[1.0.2]: https://github.com/nodeca/pako/compare/1.0.1...1.0.2
|
| 152 |
+
[1.0.1]: https://github.com/nodeca/pako/compare/1.0.0...1.0.1
|
| 153 |
+
[1.0.0]: https://github.com/nodeca/pako/compare/0.2.8...1.0.0
|
| 154 |
+
[0.2.8]: https://github.com/nodeca/pako/compare/0.2.7...0.2.8
|
| 155 |
+
[0.2.7]: https://github.com/nodeca/pako/compare/0.2.6...0.2.7
|
| 156 |
+
[0.2.6]: https://github.com/nodeca/pako/compare/0.2.5...0.2.6
|
| 157 |
+
[0.2.5]: https://github.com/nodeca/pako/compare/0.2.4...0.2.5
|
| 158 |
+
[0.2.4]: https://github.com/nodeca/pako/compare/0.2.3...0.2.4
|
| 159 |
+
[0.2.3]: https://github.com/nodeca/pako/compare/0.2.2...0.2.3
|
| 160 |
+
[0.2.2]: https://github.com/nodeca/pako/compare/0.2.1...0.2.2
|
| 161 |
+
[0.2.1]: https://github.com/nodeca/pako/compare/0.2.0...0.2.1
|
| 162 |
+
[0.2.0]: https://github.com/nodeca/pako/compare/0.1.1...0.2.0
|
| 163 |
+
[0.1.1]: https://github.com/nodeca/pako/compare/0.1.0...0.1.1
|
| 164 |
+
[0.1.0]: https://github.com/nodeca/pako/releases/tag/0.1.0
|
node_modules/pako/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(The MIT License)
|
| 2 |
+
|
| 3 |
+
Copyright (C) 2014-2017 by Vitaly Puzrin and Andrei Tuputcyn
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in
|
| 13 |
+
all copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 21 |
+
THE SOFTWARE.
|
node_modules/pako/README.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pako
|
| 2 |
+
==========================================
|
| 3 |
+
|
| 4 |
+
[](https://travis-ci.org/nodeca/pako)
|
| 5 |
+
[](https://www.npmjs.org/package/pako)
|
| 6 |
+
|
| 7 |
+
> zlib port to javascript, very fast!
|
| 8 |
+
|
| 9 |
+
__Why pako is cool:__
|
| 10 |
+
|
| 11 |
+
- Almost as fast in modern JS engines as C implementation (see benchmarks).
|
| 12 |
+
- Works in browsers, you can browserify any separate component.
|
| 13 |
+
- Chunking support for big blobs.
|
| 14 |
+
- Results are binary equal to well known [zlib](http://www.zlib.net/) (now contains ported zlib v1.2.8).
|
| 15 |
+
|
| 16 |
+
This project was done to understand how fast JS can be and is it necessary to
|
| 17 |
+
develop native C modules for CPU-intensive tasks. Enjoy the result!
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
__Famous projects, using pako:__
|
| 21 |
+
|
| 22 |
+
- [browserify](http://browserify.org/) (via [browserify-zlib](https://github.com/devongovett/browserify-zlib))
|
| 23 |
+
- [JSZip](http://stuk.github.io/jszip/)
|
| 24 |
+
- [mincer](https://github.com/nodeca/mincer)
|
| 25 |
+
- [JS-Git](https://github.com/creationix/js-git) and
|
| 26 |
+
[Tedit](https://chrome.google.com/webstore/detail/tedit-development-environ/ooekdijbnbbjdfjocaiflnjgoohnblgf)
|
| 27 |
+
by [@creationix](https://github.com/creationix)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
__Benchmarks:__
|
| 31 |
+
|
| 32 |
+
```
|
| 33 |
+
node v0.10.26, 1mb sample:
|
| 34 |
+
|
| 35 |
+
deflate-dankogai x 4.73 ops/sec ±0.82% (15 runs sampled)
|
| 36 |
+
deflate-gildas x 4.58 ops/sec ±2.33% (15 runs sampled)
|
| 37 |
+
deflate-imaya x 3.22 ops/sec ±3.95% (12 runs sampled)
|
| 38 |
+
! deflate-pako x 6.99 ops/sec ±0.51% (21 runs sampled)
|
| 39 |
+
deflate-pako-string x 5.89 ops/sec ±0.77% (18 runs sampled)
|
| 40 |
+
deflate-pako-untyped x 4.39 ops/sec ±1.58% (14 runs sampled)
|
| 41 |
+
* deflate-zlib x 14.71 ops/sec ±4.23% (59 runs sampled)
|
| 42 |
+
inflate-dankogai x 32.16 ops/sec ±0.13% (56 runs sampled)
|
| 43 |
+
inflate-imaya x 30.35 ops/sec ±0.92% (53 runs sampled)
|
| 44 |
+
! inflate-pako x 69.89 ops/sec ±1.46% (71 runs sampled)
|
| 45 |
+
inflate-pako-string x 19.22 ops/sec ±1.86% (49 runs sampled)
|
| 46 |
+
inflate-pako-untyped x 17.19 ops/sec ±0.85% (32 runs sampled)
|
| 47 |
+
* inflate-zlib x 70.03 ops/sec ±1.64% (81 runs sampled)
|
| 48 |
+
|
| 49 |
+
node v0.11.12, 1mb sample:
|
| 50 |
+
|
| 51 |
+
deflate-dankogai x 5.60 ops/sec ±0.49% (17 runs sampled)
|
| 52 |
+
deflate-gildas x 5.06 ops/sec ±6.00% (16 runs sampled)
|
| 53 |
+
deflate-imaya x 3.52 ops/sec ±3.71% (13 runs sampled)
|
| 54 |
+
! deflate-pako x 11.52 ops/sec ±0.22% (32 runs sampled)
|
| 55 |
+
deflate-pako-string x 9.53 ops/sec ±1.12% (27 runs sampled)
|
| 56 |
+
deflate-pako-untyped x 5.44 ops/sec ±0.72% (17 runs sampled)
|
| 57 |
+
* deflate-zlib x 14.05 ops/sec ±3.34% (63 runs sampled)
|
| 58 |
+
inflate-dankogai x 42.19 ops/sec ±0.09% (56 runs sampled)
|
| 59 |
+
inflate-imaya x 79.68 ops/sec ±1.07% (68 runs sampled)
|
| 60 |
+
! inflate-pako x 97.52 ops/sec ±0.83% (80 runs sampled)
|
| 61 |
+
inflate-pako-string x 45.19 ops/sec ±1.69% (57 runs sampled)
|
| 62 |
+
inflate-pako-untyped x 24.35 ops/sec ±2.59% (40 runs sampled)
|
| 63 |
+
* inflate-zlib x 60.32 ops/sec ±1.36% (69 runs sampled)
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
zlib's test is partially affected by marshalling (that make sense for inflate only).
|
| 67 |
+
You can change deflate level to 0 in benchmark source, to investigate details.
|
| 68 |
+
For deflate level 6 results can be considered as correct.
|
| 69 |
+
|
| 70 |
+
__Install:__
|
| 71 |
+
|
| 72 |
+
node.js:
|
| 73 |
+
|
| 74 |
+
```
|
| 75 |
+
npm install pako
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
browser:
|
| 79 |
+
|
| 80 |
+
```
|
| 81 |
+
bower install pako
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
Example & API
|
| 86 |
+
-------------
|
| 87 |
+
|
| 88 |
+
Full docs - http://nodeca.github.io/pako/
|
| 89 |
+
|
| 90 |
+
```javascript
|
| 91 |
+
var pako = require('pako');
|
| 92 |
+
|
| 93 |
+
// Deflate
|
| 94 |
+
//
|
| 95 |
+
var input = new Uint8Array();
|
| 96 |
+
//... fill input data here
|
| 97 |
+
var output = pako.deflate(input);
|
| 98 |
+
|
| 99 |
+
// Inflate (simple wrapper can throw exception on broken stream)
|
| 100 |
+
//
|
| 101 |
+
var compressed = new Uint8Array();
|
| 102 |
+
//... fill data to uncompress here
|
| 103 |
+
try {
|
| 104 |
+
var result = pako.inflate(compressed);
|
| 105 |
+
} catch (err) {
|
| 106 |
+
console.log(err);
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
//
|
| 110 |
+
// Alternate interface for chunking & without exceptions
|
| 111 |
+
//
|
| 112 |
+
|
| 113 |
+
var inflator = new pako.Inflate();
|
| 114 |
+
|
| 115 |
+
inflator.push(chunk1, false);
|
| 116 |
+
inflator.push(chunk2, false);
|
| 117 |
+
...
|
| 118 |
+
inflator.push(chunkN, true); // true -> last chunk
|
| 119 |
+
|
| 120 |
+
if (inflator.err) {
|
| 121 |
+
console.log(inflator.msg);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
var output = inflator.result;
|
| 125 |
+
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
Sometime you can wish to work with strings. For example, to send
|
| 129 |
+
big objects as json to server. Pako detects input data type. You can
|
| 130 |
+
force output to be string with option `{ to: 'string' }`.
|
| 131 |
+
|
| 132 |
+
```javascript
|
| 133 |
+
var pako = require('pako');
|
| 134 |
+
|
| 135 |
+
var test = { my: 'super', puper: [456, 567], awesome: 'pako' };
|
| 136 |
+
|
| 137 |
+
var binaryString = pako.deflate(JSON.stringify(test), { to: 'string' });
|
| 138 |
+
|
| 139 |
+
//
|
| 140 |
+
// Here you can do base64 encode, make xhr requests and so on.
|
| 141 |
+
//
|
| 142 |
+
|
| 143 |
+
var restored = JSON.parse(pako.inflate(binaryString, { to: 'string' }));
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
Notes
|
| 148 |
+
-----
|
| 149 |
+
|
| 150 |
+
Pako does not contain some specific zlib functions:
|
| 151 |
+
|
| 152 |
+
- __deflate__ - methods `deflateCopy`, `deflateBound`, `deflateParams`,
|
| 153 |
+
`deflatePending`, `deflatePrime`, `deflateTune`.
|
| 154 |
+
- __inflate__ - methods `inflateCopy`, `inflateMark`,
|
| 155 |
+
`inflatePrime`, `inflateGetDictionary`, `inflateSync`, `inflateSyncPoint`, `inflateUndermine`.
|
| 156 |
+
- High level inflate/deflate wrappers (classes) may not support some flush
|
| 157 |
+
modes. Those should work: Z_NO_FLUSH, Z_FINISH, Z_SYNC_FLUSH.
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
pako for enterprise
|
| 161 |
+
-------------------
|
| 162 |
+
|
| 163 |
+
Available as part of the Tidelift Subscription
|
| 164 |
+
|
| 165 |
+
The maintainers of pako and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-pako?utm_source=npm-pako&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
Authors
|
| 169 |
+
-------
|
| 170 |
+
|
| 171 |
+
- Andrey Tupitsin [@anrd83](https://github.com/andr83)
|
| 172 |
+
- Vitaly Puzrin [@puzrin](https://github.com/puzrin)
|
| 173 |
+
|
| 174 |
+
Personal thanks to:
|
| 175 |
+
|
| 176 |
+
- Vyacheslav Egorov ([@mraleph](https://github.com/mraleph)) for his awesome
|
| 177 |
+
tutorials about optimising JS code for v8, [IRHydra](http://mrale.ph/irhydra/)
|
| 178 |
+
tool and his advices.
|
| 179 |
+
- David Duponchel ([@dduponchel](https://github.com/dduponchel)) for help with
|
| 180 |
+
testing.
|
| 181 |
+
|
| 182 |
+
Original implementation (in C):
|
| 183 |
+
|
| 184 |
+
- [zlib](http://zlib.net/) by Jean-loup Gailly and Mark Adler.
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
License
|
| 188 |
+
-------
|
| 189 |
+
|
| 190 |
+
- MIT - all files, except `/lib/zlib` folder
|
| 191 |
+
- ZLIB - `/lib/zlib` content
|
node_modules/pako/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Top level file is just a mixin of submodules & constants
|
| 2 |
+
'use strict';
|
| 3 |
+
|
| 4 |
+
var assign = require('./lib/utils/common').assign;
|
| 5 |
+
|
| 6 |
+
var deflate = require('./lib/deflate');
|
| 7 |
+
var inflate = require('./lib/inflate');
|
| 8 |
+
var constants = require('./lib/zlib/constants');
|
| 9 |
+
|
| 10 |
+
var pako = {};
|
| 11 |
+
|
| 12 |
+
assign(pako, deflate, inflate, constants);
|
| 13 |
+
|
| 14 |
+
module.exports = pako;
|