removed modules
parent
9bec510066
commit
cd76893f23
@ -1 +0,0 @@
|
|||||||
../yamljs/bin/json2yaml
|
|
@ -1 +0,0 @@
|
|||||||
../mime/cli.js
|
|
@ -1 +0,0 @@
|
|||||||
../yamljs/bin/yaml2json
|
|
@ -1,236 +0,0 @@
|
|||||||
1.3.7 / 2019-04-29
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: negotiator@0.6.2
|
|
||||||
- Fix sorting charset, encoding, and language with extra parameters
|
|
||||||
|
|
||||||
1.3.6 / 2019-04-28
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.1.24
|
|
||||||
- deps: mime-db@~1.40.0
|
|
||||||
|
|
||||||
1.3.5 / 2018-02-28
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.1.18
|
|
||||||
- deps: mime-db@~1.33.0
|
|
||||||
|
|
||||||
1.3.4 / 2017-08-22
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.1.16
|
|
||||||
- deps: mime-db@~1.29.0
|
|
||||||
|
|
||||||
1.3.3 / 2016-05-02
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.1.11
|
|
||||||
- deps: mime-db@~1.23.0
|
|
||||||
* deps: negotiator@0.6.1
|
|
||||||
- perf: improve `Accept` parsing speed
|
|
||||||
- perf: improve `Accept-Charset` parsing speed
|
|
||||||
- perf: improve `Accept-Encoding` parsing speed
|
|
||||||
- perf: improve `Accept-Language` parsing speed
|
|
||||||
|
|
||||||
1.3.2 / 2016-03-08
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.1.10
|
|
||||||
- Fix extension of `application/dash+xml`
|
|
||||||
- Update primary extension for `audio/mp4`
|
|
||||||
- deps: mime-db@~1.22.0
|
|
||||||
|
|
||||||
1.3.1 / 2016-01-19
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.1.9
|
|
||||||
- deps: mime-db@~1.21.0
|
|
||||||
|
|
||||||
1.3.0 / 2015-09-29
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.1.7
|
|
||||||
- deps: mime-db@~1.19.0
|
|
||||||
* deps: negotiator@0.6.0
|
|
||||||
- Fix including type extensions in parameters in `Accept` parsing
|
|
||||||
- Fix parsing `Accept` parameters with quoted equals
|
|
||||||
- Fix parsing `Accept` parameters with quoted semicolons
|
|
||||||
- Lazy-load modules from main entry point
|
|
||||||
- perf: delay type concatenation until needed
|
|
||||||
- perf: enable strict mode
|
|
||||||
- perf: hoist regular expressions
|
|
||||||
- perf: remove closures getting spec properties
|
|
||||||
- perf: remove a closure from media type parsing
|
|
||||||
- perf: remove property delete from media type parsing
|
|
||||||
|
|
||||||
1.2.13 / 2015-09-06
|
|
||||||
===================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.1.6
|
|
||||||
- deps: mime-db@~1.18.0
|
|
||||||
|
|
||||||
1.2.12 / 2015-07-30
|
|
||||||
===================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.1.4
|
|
||||||
- deps: mime-db@~1.16.0
|
|
||||||
|
|
||||||
1.2.11 / 2015-07-16
|
|
||||||
===================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.1.3
|
|
||||||
- deps: mime-db@~1.15.0
|
|
||||||
|
|
||||||
1.2.10 / 2015-07-01
|
|
||||||
===================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.1.2
|
|
||||||
- deps: mime-db@~1.14.0
|
|
||||||
|
|
||||||
1.2.9 / 2015-06-08
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.1.1
|
|
||||||
- perf: fix deopt during mapping
|
|
||||||
|
|
||||||
1.2.8 / 2015-06-07
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.1.0
|
|
||||||
- deps: mime-db@~1.13.0
|
|
||||||
* perf: avoid argument reassignment & argument slice
|
|
||||||
* perf: avoid negotiator recursive construction
|
|
||||||
* perf: enable strict mode
|
|
||||||
* perf: remove unnecessary bitwise operator
|
|
||||||
|
|
||||||
1.2.7 / 2015-05-10
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: negotiator@0.5.3
|
|
||||||
- Fix media type parameter matching to be case-insensitive
|
|
||||||
|
|
||||||
1.2.6 / 2015-05-07
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.0.11
|
|
||||||
- deps: mime-db@~1.9.1
|
|
||||||
* deps: negotiator@0.5.2
|
|
||||||
- Fix comparing media types with quoted values
|
|
||||||
- Fix splitting media types with quoted commas
|
|
||||||
|
|
||||||
1.2.5 / 2015-03-13
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.0.10
|
|
||||||
- deps: mime-db@~1.8.0
|
|
||||||
|
|
||||||
1.2.4 / 2015-02-14
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Support Node.js 0.6
|
|
||||||
* deps: mime-types@~2.0.9
|
|
||||||
- deps: mime-db@~1.7.0
|
|
||||||
* deps: negotiator@0.5.1
|
|
||||||
- Fix preference sorting to be stable for long acceptable lists
|
|
||||||
|
|
||||||
1.2.3 / 2015-01-31
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.0.8
|
|
||||||
- deps: mime-db@~1.6.0
|
|
||||||
|
|
||||||
1.2.2 / 2014-12-30
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.0.7
|
|
||||||
- deps: mime-db@~1.5.0
|
|
||||||
|
|
||||||
1.2.1 / 2014-12-30
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.0.5
|
|
||||||
- deps: mime-db@~1.3.1
|
|
||||||
|
|
||||||
1.2.0 / 2014-12-19
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: negotiator@0.5.0
|
|
||||||
- Fix list return order when large accepted list
|
|
||||||
- Fix missing identity encoding when q=0 exists
|
|
||||||
- Remove dynamic building of Negotiator class
|
|
||||||
|
|
||||||
1.1.4 / 2014-12-10
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.0.4
|
|
||||||
- deps: mime-db@~1.3.0
|
|
||||||
|
|
||||||
1.1.3 / 2014-11-09
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.0.3
|
|
||||||
- deps: mime-db@~1.2.0
|
|
||||||
|
|
||||||
1.1.2 / 2014-10-14
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: negotiator@0.4.9
|
|
||||||
- Fix error when media type has invalid parameter
|
|
||||||
|
|
||||||
1.1.1 / 2014-09-28
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: mime-types@~2.0.2
|
|
||||||
- deps: mime-db@~1.1.0
|
|
||||||
* deps: negotiator@0.4.8
|
|
||||||
- Fix all negotiations to be case-insensitive
|
|
||||||
- Stable sort preferences of same quality according to client order
|
|
||||||
|
|
||||||
1.1.0 / 2014-09-02
|
|
||||||
==================
|
|
||||||
|
|
||||||
* update `mime-types`
|
|
||||||
|
|
||||||
1.0.7 / 2014-07-04
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix wrong type returned from `type` when match after unknown extension
|
|
||||||
|
|
||||||
1.0.6 / 2014-06-24
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: negotiator@0.4.7
|
|
||||||
|
|
||||||
1.0.5 / 2014-06-20
|
|
||||||
==================
|
|
||||||
|
|
||||||
* fix crash when unknown extension given
|
|
||||||
|
|
||||||
1.0.4 / 2014-06-19
|
|
||||||
==================
|
|
||||||
|
|
||||||
* use `mime-types`
|
|
||||||
|
|
||||||
1.0.3 / 2014-06-11
|
|
||||||
==================
|
|
||||||
|
|
||||||
* deps: negotiator@0.4.6
|
|
||||||
- Order by specificity when quality is the same
|
|
||||||
|
|
||||||
1.0.2 / 2014-05-29
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix interpretation when header not in request
|
|
||||||
* deps: pin negotiator@0.4.5
|
|
||||||
|
|
||||||
1.0.1 / 2014-01-18
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Identity encoding isn't always acceptable
|
|
||||||
* deps: negotiator@~0.4.0
|
|
||||||
|
|
||||||
1.0.0 / 2013-12-27
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Genesis
|
|
@ -1,23 +0,0 @@
|
|||||||
(The MIT License)
|
|
||||||
|
|
||||||
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
|
|
||||||
Copyright (c) 2015 Douglas Christopher Wilson <doug@somethingdoug.com>
|
|
||||||
|
|
||||||
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:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
|
||||||
included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
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.
|
|
@ -1,142 +0,0 @@
|
|||||||
# accepts
|
|
||||||
|
|
||||||
[![NPM Version][npm-version-image]][npm-url]
|
|
||||||
[![NPM Downloads][npm-downloads-image]][npm-url]
|
|
||||||
[![Node.js Version][node-version-image]][node-version-url]
|
|
||||||
[![Build Status][travis-image]][travis-url]
|
|
||||||
[![Test Coverage][coveralls-image]][coveralls-url]
|
|
||||||
|
|
||||||
Higher level content negotiation based on [negotiator](https://www.npmjs.com/package/negotiator).
|
|
||||||
Extracted from [koa](https://www.npmjs.com/package/koa) for general use.
|
|
||||||
|
|
||||||
In addition to negotiator, it allows:
|
|
||||||
|
|
||||||
- Allows types as an array or arguments list, ie `(['text/html', 'application/json'])`
|
|
||||||
as well as `('text/html', 'application/json')`.
|
|
||||||
- Allows type shorthands such as `json`.
|
|
||||||
- Returns `false` when no types match
|
|
||||||
- Treats non-existent headers as `*`
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
This is a [Node.js](https://nodejs.org/en/) module available through the
|
|
||||||
[npm registry](https://www.npmjs.com/). Installation is done using the
|
|
||||||
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install accepts
|
|
||||||
```
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
<!-- eslint-disable no-unused-vars -->
|
|
||||||
|
|
||||||
```js
|
|
||||||
var accepts = require('accepts')
|
|
||||||
```
|
|
||||||
|
|
||||||
### accepts(req)
|
|
||||||
|
|
||||||
Create a new `Accepts` object for the given `req`.
|
|
||||||
|
|
||||||
#### .charset(charsets)
|
|
||||||
|
|
||||||
Return the first accepted charset. If nothing in `charsets` is accepted,
|
|
||||||
then `false` is returned.
|
|
||||||
|
|
||||||
#### .charsets()
|
|
||||||
|
|
||||||
Return the charsets that the request accepts, in the order of the client's
|
|
||||||
preference (most preferred first).
|
|
||||||
|
|
||||||
#### .encoding(encodings)
|
|
||||||
|
|
||||||
Return the first accepted encoding. If nothing in `encodings` is accepted,
|
|
||||||
then `false` is returned.
|
|
||||||
|
|
||||||
#### .encodings()
|
|
||||||
|
|
||||||
Return the encodings that the request accepts, in the order of the client's
|
|
||||||
preference (most preferred first).
|
|
||||||
|
|
||||||
#### .language(languages)
|
|
||||||
|
|
||||||
Return the first accepted language. If nothing in `languages` is accepted,
|
|
||||||
then `false` is returned.
|
|
||||||
|
|
||||||
#### .languages()
|
|
||||||
|
|
||||||
Return the languages that the request accepts, in the order of the client's
|
|
||||||
preference (most preferred first).
|
|
||||||
|
|
||||||
#### .type(types)
|
|
||||||
|
|
||||||
Return the first accepted type (and it is returned as the same text as what
|
|
||||||
appears in the `types` array). If nothing in `types` is accepted, then `false`
|
|
||||||
is returned.
|
|
||||||
|
|
||||||
The `types` array can contain full MIME types or file extensions. Any value
|
|
||||||
that is not a full MIME types is passed to `require('mime-types').lookup`.
|
|
||||||
|
|
||||||
#### .types()
|
|
||||||
|
|
||||||
Return the types that the request accepts, in the order of the client's
|
|
||||||
preference (most preferred first).
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
### Simple type negotiation
|
|
||||||
|
|
||||||
This simple example shows how to use `accepts` to return a different typed
|
|
||||||
respond body based on what the client wants to accept. The server lists it's
|
|
||||||
preferences in order and will get back the best match between the client and
|
|
||||||
server.
|
|
||||||
|
|
||||||
```js
|
|
||||||
var accepts = require('accepts')
|
|
||||||
var http = require('http')
|
|
||||||
|
|
||||||
function app (req, res) {
|
|
||||||
var accept = accepts(req)
|
|
||||||
|
|
||||||
// the order of this list is significant; should be server preferred order
|
|
||||||
switch (accept.type(['json', 'html'])) {
|
|
||||||
case 'json':
|
|
||||||
res.setHeader('Content-Type', 'application/json')
|
|
||||||
res.write('{"hello":"world!"}')
|
|
||||||
break
|
|
||||||
case 'html':
|
|
||||||
res.setHeader('Content-Type', 'text/html')
|
|
||||||
res.write('<b>hello, world!</b>')
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
// the fallback is text/plain, so no need to specify it above
|
|
||||||
res.setHeader('Content-Type', 'text/plain')
|
|
||||||
res.write('hello, world!')
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
res.end()
|
|
||||||
}
|
|
||||||
|
|
||||||
http.createServer(app).listen(3000)
|
|
||||||
```
|
|
||||||
|
|
||||||
You can test this out with the cURL program:
|
|
||||||
```sh
|
|
||||||
curl -I -H'Accept: text/html' http://localhost:3000/
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
[MIT](LICENSE)
|
|
||||||
|
|
||||||
[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/accepts/master
|
|
||||||
[coveralls-url]: https://coveralls.io/r/jshttp/accepts?branch=master
|
|
||||||
[node-version-image]: https://badgen.net/npm/node/accepts
|
|
||||||
[node-version-url]: https://nodejs.org/en/download
|
|
||||||
[npm-downloads-image]: https://badgen.net/npm/dm/accepts
|
|
||||||
[npm-url]: https://npmjs.org/package/accepts
|
|
||||||
[npm-version-image]: https://badgen.net/npm/v/accepts
|
|
||||||
[travis-image]: https://badgen.net/travis/jshttp/accepts/master
|
|
||||||
[travis-url]: https://travis-ci.org/jshttp/accepts
|
|
@ -1,238 +0,0 @@
|
|||||||
/*!
|
|
||||||
* accepts
|
|
||||||
* Copyright(c) 2014 Jonathan Ong
|
|
||||||
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
||||||
* MIT Licensed
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
|
|
||||||
var Negotiator = require('negotiator')
|
|
||||||
var mime = require('mime-types')
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module exports.
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = Accepts
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new Accepts object for the given req.
|
|
||||||
*
|
|
||||||
* @param {object} req
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
|
|
||||||
function Accepts (req) {
|
|
||||||
if (!(this instanceof Accepts)) {
|
|
||||||
return new Accepts(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.headers = req.headers
|
|
||||||
this.negotiator = new Negotiator(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the given `type(s)` is acceptable, returning
|
|
||||||
* the best match when true, otherwise `undefined`, in which
|
|
||||||
* case you should respond with 406 "Not Acceptable".
|
|
||||||
*
|
|
||||||
* The `type` value may be a single mime type string
|
|
||||||
* such as "application/json", the extension name
|
|
||||||
* such as "json" or an array `["json", "html", "text/plain"]`. When a list
|
|
||||||
* or array is given the _best_ match, if any is returned.
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
*
|
|
||||||
* // Accept: text/html
|
|
||||||
* this.types('html');
|
|
||||||
* // => "html"
|
|
||||||
*
|
|
||||||
* // Accept: text/*, application/json
|
|
||||||
* this.types('html');
|
|
||||||
* // => "html"
|
|
||||||
* this.types('text/html');
|
|
||||||
* // => "text/html"
|
|
||||||
* this.types('json', 'text');
|
|
||||||
* // => "json"
|
|
||||||
* this.types('application/json');
|
|
||||||
* // => "application/json"
|
|
||||||
*
|
|
||||||
* // Accept: text/*, application/json
|
|
||||||
* this.types('image/png');
|
|
||||||
* this.types('png');
|
|
||||||
* // => undefined
|
|
||||||
*
|
|
||||||
* // Accept: text/*;q=.5, application/json
|
|
||||||
* this.types(['html', 'json']);
|
|
||||||
* this.types('html', 'json');
|
|
||||||
* // => "json"
|
|
||||||
*
|
|
||||||
* @param {String|Array} types...
|
|
||||||
* @return {String|Array|Boolean}
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
|
|
||||||
Accepts.prototype.type =
|
|
||||||
Accepts.prototype.types = function (types_) {
|
|
||||||
var types = types_
|
|
||||||
|
|
||||||
// support flattened arguments
|
|
||||||
if (types && !Array.isArray(types)) {
|
|
||||||
types = new Array(arguments.length)
|
|
||||||
for (var i = 0; i < types.length; i++) {
|
|
||||||
types[i] = arguments[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// no types, return all requested types
|
|
||||||
if (!types || types.length === 0) {
|
|
||||||
return this.negotiator.mediaTypes()
|
|
||||||
}
|
|
||||||
|
|
||||||
// no accept header, return first given type
|
|
||||||
if (!this.headers.accept) {
|
|
||||||
return types[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
var mimes = types.map(extToMime)
|
|
||||||
var accepts = this.negotiator.mediaTypes(mimes.filter(validMime))
|
|
||||||
var first = accepts[0]
|
|
||||||
|
|
||||||
return first
|
|
||||||
? types[mimes.indexOf(first)]
|
|
||||||
: false
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return accepted encodings or best fit based on `encodings`.
|
|
||||||
*
|
|
||||||
* Given `Accept-Encoding: gzip, deflate`
|
|
||||||
* an array sorted by quality is returned:
|
|
||||||
*
|
|
||||||
* ['gzip', 'deflate']
|
|
||||||
*
|
|
||||||
* @param {String|Array} encodings...
|
|
||||||
* @return {String|Array}
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
|
|
||||||
Accepts.prototype.encoding =
|
|
||||||
Accepts.prototype.encodings = function (encodings_) {
|
|
||||||
var encodings = encodings_
|
|
||||||
|
|
||||||
// support flattened arguments
|
|
||||||
if (encodings && !Array.isArray(encodings)) {
|
|
||||||
encodings = new Array(arguments.length)
|
|
||||||
for (var i = 0; i < encodings.length; i++) {
|
|
||||||
encodings[i] = arguments[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// no encodings, return all requested encodings
|
|
||||||
if (!encodings || encodings.length === 0) {
|
|
||||||
return this.negotiator.encodings()
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.negotiator.encodings(encodings)[0] || false
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return accepted charsets or best fit based on `charsets`.
|
|
||||||
*
|
|
||||||
* Given `Accept-Charset: utf-8, iso-8859-1;q=0.2, utf-7;q=0.5`
|
|
||||||
* an array sorted by quality is returned:
|
|
||||||
*
|
|
||||||
* ['utf-8', 'utf-7', 'iso-8859-1']
|
|
||||||
*
|
|
||||||
* @param {String|Array} charsets...
|
|
||||||
* @return {String|Array}
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
|
|
||||||
Accepts.prototype.charset =
|
|
||||||
Accepts.prototype.charsets = function (charsets_) {
|
|
||||||
var charsets = charsets_
|
|
||||||
|
|
||||||
// support flattened arguments
|
|
||||||
if (charsets && !Array.isArray(charsets)) {
|
|
||||||
charsets = new Array(arguments.length)
|
|
||||||
for (var i = 0; i < charsets.length; i++) {
|
|
||||||
charsets[i] = arguments[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// no charsets, return all requested charsets
|
|
||||||
if (!charsets || charsets.length === 0) {
|
|
||||||
return this.negotiator.charsets()
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.negotiator.charsets(charsets)[0] || false
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return accepted languages or best fit based on `langs`.
|
|
||||||
*
|
|
||||||
* Given `Accept-Language: en;q=0.8, es, pt`
|
|
||||||
* an array sorted by quality is returned:
|
|
||||||
*
|
|
||||||
* ['es', 'pt', 'en']
|
|
||||||
*
|
|
||||||
* @param {String|Array} langs...
|
|
||||||
* @return {Array|String}
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
|
|
||||||
Accepts.prototype.lang =
|
|
||||||
Accepts.prototype.langs =
|
|
||||||
Accepts.prototype.language =
|
|
||||||
Accepts.prototype.languages = function (languages_) {
|
|
||||||
var languages = languages_
|
|
||||||
|
|
||||||
// support flattened arguments
|
|
||||||
if (languages && !Array.isArray(languages)) {
|
|
||||||
languages = new Array(arguments.length)
|
|
||||||
for (var i = 0; i < languages.length; i++) {
|
|
||||||
languages[i] = arguments[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// no languages, return all requested languages
|
|
||||||
if (!languages || languages.length === 0) {
|
|
||||||
return this.negotiator.languages()
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.negotiator.languages(languages)[0] || false
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert extnames to mime.
|
|
||||||
*
|
|
||||||
* @param {String} type
|
|
||||||
* @return {String}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
|
|
||||||
function extToMime (type) {
|
|
||||||
return type.indexOf('/') === -1
|
|
||||||
? mime.lookup(type)
|
|
||||||
: type
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if mime is valid.
|
|
||||||
*
|
|
||||||
* @param {String} type
|
|
||||||
* @return {String}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
|
|
||||||
function validMime (type) {
|
|
||||||
return typeof type === 'string'
|
|
||||||
}
|
|
@ -1,86 +0,0 @@
|
|||||||
{
|
|
||||||
"_from": "accepts@~1.3.7",
|
|
||||||
"_id": "accepts@1.3.7",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==",
|
|
||||||
"_location": "/accepts",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "range",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "accepts@~1.3.7",
|
|
||||||
"name": "accepts",
|
|
||||||
"escapedName": "accepts",
|
|
||||||
"rawSpec": "~1.3.7",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "~1.3.7"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/express"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
|
|
||||||
"_shasum": "531bc726517a3b2b41f850021c6cc15eaab507cd",
|
|
||||||
"_spec": "accepts@~1.3.7",
|
|
||||||
"_where": "/Users/paolo/Desktop/multiplayer games/tutorials/hellosocket/node_modules/express",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/jshttp/accepts/issues"
|
|
||||||
},
|
|
||||||
"bundleDependencies": false,
|
|
||||||
"contributors": [
|
|
||||||
{
|
|
||||||
"name": "Douglas Christopher Wilson",
|
|
||||||
"email": "doug@somethingdoug.com"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Jonathan Ong",
|
|
||||||
"email": "me@jongleberry.com",
|
|
||||||
"url": "http://jongleberry.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"dependencies": {
|
|
||||||
"mime-types": "~2.1.24",
|
|
||||||
"negotiator": "0.6.2"
|
|
||||||
},
|
|
||||||
"deprecated": false,
|
|
||||||
"description": "Higher-level content negotiation",
|
|
||||||
"devDependencies": {
|
|
||||||
"deep-equal": "1.0.1",
|
|
||||||
"eslint": "5.16.0",
|
|
||||||
"eslint-config-standard": "12.0.0",
|
|
||||||
"eslint-plugin-import": "2.17.2",
|
|
||||||
"eslint-plugin-markdown": "1.0.0",
|
|
||||||
"eslint-plugin-node": "8.0.1",
|
|
||||||
"eslint-plugin-promise": "4.1.1",
|
|
||||||
"eslint-plugin-standard": "4.0.0",
|
|
||||||
"mocha": "6.1.4",
|
|
||||||
"nyc": "14.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 0.6"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"LICENSE",
|
|
||||||
"HISTORY.md",
|
|
||||||
"index.js"
|
|
||||||
],
|
|
||||||
"homepage": "https://github.com/jshttp/accepts#readme",
|
|
||||||
"keywords": [
|
|
||||||
"content",
|
|
||||||
"negotiation",
|
|
||||||
"accept",
|
|
||||||
"accepts"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"name": "accepts",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/jshttp/accepts.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"lint": "eslint --plugin markdown --ext js,md .",
|
|
||||||
"test": "mocha --reporter spec --check-leaks --bail test/",
|
|
||||||
"test-cov": "nyc --reporter=html --reporter=text npm test",
|
|
||||||
"test-travis": "nyc --reporter=text npm test"
|
|
||||||
},
|
|
||||||
"version": "1.3.7"
|
|
||||||
}
|
|
@ -1,2 +0,0 @@
|
|||||||
node_modules
|
|
||||||
.monitor
|
|
@ -1,12 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- 0.6
|
|
||||||
- 0.8
|
|
||||||
- 0.9
|
|
||||||
- 0.10
|
|
||||||
- 0.12
|
|
||||||
- 4.2.4
|
|
||||||
- 5.4.1
|
|
||||||
- iojs-1
|
|
||||||
- iojs-2
|
|
||||||
- iojs-3
|
|
@ -1,19 +0,0 @@
|
|||||||
Copyright (c) 2011 Raynos.
|
|
||||||
|
|
||||||
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:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
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.
|
|
@ -1,115 +0,0 @@
|
|||||||
# After [![Build Status][1]][2]
|
|
||||||
|
|
||||||
Invoke callback after n calls
|
|
||||||
|
|
||||||
## Status: production ready
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```js
|
|
||||||
var after = require("after")
|
|
||||||
var db = require("./db") // some db.
|
|
||||||
|
|
||||||
var updateUser = function (req, res) {
|
|
||||||
// use after to run two tasks in parallel,
|
|
||||||
// namely get request body and get session
|
|
||||||
// then run updateUser with the results
|
|
||||||
var next = after(2, updateUser)
|
|
||||||
var results = {}
|
|
||||||
|
|
||||||
getJSONBody(req, res, function (err, body) {
|
|
||||||
if (err) return next(err)
|
|
||||||
|
|
||||||
results.body = body
|
|
||||||
next(null, results)
|
|
||||||
})
|
|
||||||
|
|
||||||
getSessionUser(req, res, function (err, user) {
|
|
||||||
if (err) return next(err)
|
|
||||||
|
|
||||||
results.user = user
|
|
||||||
next(null, results)
|
|
||||||
})
|
|
||||||
|
|
||||||
// now do the thing!
|
|
||||||
function updateUser(err, result) {
|
|
||||||
if (err) {
|
|
||||||
res.statusCode = 500
|
|
||||||
return res.end("Unexpected Error")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result.user || result.user.role !== "admin") {
|
|
||||||
res.statusCode = 403
|
|
||||||
return res.end("Permission Denied")
|
|
||||||
}
|
|
||||||
|
|
||||||
db.put("users:" + req.params.userId, result.body, function (err) {
|
|
||||||
if (err) {
|
|
||||||
res.statusCode = 500
|
|
||||||
return res.end("Unexpected Error")
|
|
||||||
}
|
|
||||||
|
|
||||||
res.statusCode = 200
|
|
||||||
res.end("Ok")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Naive Example
|
|
||||||
|
|
||||||
```js
|
|
||||||
var after = require("after")
|
|
||||||
, next = after(3, logItWorks)
|
|
||||||
|
|
||||||
next()
|
|
||||||
next()
|
|
||||||
next() // it works
|
|
||||||
|
|
||||||
function logItWorks() {
|
|
||||||
console.log("it works!")
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Example with error handling
|
|
||||||
|
|
||||||
```js
|
|
||||||
var after = require("after")
|
|
||||||
, next = after(3, logError)
|
|
||||||
|
|
||||||
next()
|
|
||||||
next(new Error("oops")) // logs oops
|
|
||||||
next() // does nothing
|
|
||||||
|
|
||||||
// This callback is only called once.
|
|
||||||
// If there is an error the callback gets called immediately
|
|
||||||
// this avoids the situation where errors get lost.
|
|
||||||
function logError(err) {
|
|
||||||
console.log(err)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
`npm install after`
|
|
||||||
|
|
||||||
## Tests
|
|
||||||
|
|
||||||
`npm test`
|
|
||||||
|
|
||||||
## Contributors
|
|
||||||
|
|
||||||
- Raynos
|
|
||||||
- defunctzombie
|
|
||||||
|
|
||||||
## MIT Licenced
|
|
||||||
|
|
||||||
[1]: https://secure.travis-ci.org/Raynos/after.png
|
|
||||||
[2]: http://travis-ci.org/Raynos/after
|
|
||||||
[3]: http://raynos.org/blog/2/Flow-control-in-node.js
|
|
||||||
[4]: http://stackoverflow.com/questions/6852059/determining-the-end-of-asynchronous-operations-javascript/6852307#6852307
|
|
||||||
[5]: http://stackoverflow.com/questions/6869872/in-javascript-what-are-best-practices-for-executing-multiple-asynchronous-functi/6870031#6870031
|
|
||||||
[6]: http://stackoverflow.com/questions/6864397/javascript-performance-long-running-tasks/6889419#6889419
|
|
||||||
[7]: http://stackoverflow.com/questions/6597493/synchronous-database-queries-with-node-js/6620091#6620091
|
|
||||||
[8]: http://github.com/Raynos/iterators
|
|
||||||
[9]: http://github.com/Raynos/composite
|
|
@ -1,28 +0,0 @@
|
|||||||
module.exports = after
|
|
||||||
|
|
||||||
function after(count, callback, err_cb) {
|
|
||||||
var bail = false
|
|
||||||
err_cb = err_cb || noop
|
|
||||||
proxy.count = count
|
|
||||||
|
|
||||||
return (count === 0) ? callback() : proxy
|
|
||||||
|
|
||||||
function proxy(err, result) {
|
|
||||||
if (proxy.count <= 0) {
|
|
||||||
throw new Error('after called too many times')
|
|
||||||
}
|
|
||||||
--proxy.count
|
|
||||||
|
|
||||||
// after first error, rest are passed to err_cb
|
|
||||||
if (err) {
|
|
||||||
bail = true
|
|
||||||
callback(err)
|
|
||||||
// future error callbacks will go to error handler
|
|
||||||
callback = err_cb
|
|
||||||
} else if (proxy.count === 0 && !bail) {
|
|
||||||
callback(null, result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function noop() {}
|
|
@ -1,63 +0,0 @@
|
|||||||
{
|
|
||||||
"_from": "after@0.8.2",
|
|
||||||
"_id": "after@0.8.2",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8=",
|
|
||||||
"_location": "/after",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "version",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "after@0.8.2",
|
|
||||||
"name": "after",
|
|
||||||
"escapedName": "after",
|
|
||||||
"rawSpec": "0.8.2",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "0.8.2"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/engine.io-parser"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/after/-/after-0.8.2.tgz",
|
|
||||||
"_shasum": "fedb394f9f0e02aa9768e702bda23b505fae7e1f",
|
|
||||||
"_spec": "after@0.8.2",
|
|
||||||
"_where": "/Users/paolo/Desktop/multiplayer games/tutorials/hellosocket/node_modules/engine.io-parser",
|
|
||||||
"author": {
|
|
||||||
"name": "Raynos",
|
|
||||||
"email": "raynos2@gmail.com"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/Raynos/after/issues"
|
|
||||||
},
|
|
||||||
"bundleDependencies": false,
|
|
||||||
"contributors": [
|
|
||||||
{
|
|
||||||
"name": "Raynos",
|
|
||||||
"email": "raynos2@gmail.com",
|
|
||||||
"url": "http://raynos.org"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"deprecated": false,
|
|
||||||
"description": "after - tiny flow control",
|
|
||||||
"devDependencies": {
|
|
||||||
"mocha": "~1.8.1"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/Raynos/after#readme",
|
|
||||||
"keywords": [
|
|
||||||
"flowcontrol",
|
|
||||||
"after",
|
|
||||||
"flow",
|
|
||||||
"control",
|
|
||||||
"arch"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"name": "after",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/Raynos/after.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "mocha --ui tdd --reporter spec test/*.js"
|
|
||||||
},
|
|
||||||
"version": "0.8.2"
|
|
||||||
}
|
|
@ -1,120 +0,0 @@
|
|||||||
/*global suite, test*/
|
|
||||||
|
|
||||||
var assert = require("assert")
|
|
||||||
, after = require("../")
|
|
||||||
|
|
||||||
test("exists", function () {
|
|
||||||
assert(typeof after === "function", "after is not a function")
|
|
||||||
})
|
|
||||||
|
|
||||||
test("after when called with 0 invokes", function (done) {
|
|
||||||
after(0, done)
|
|
||||||
});
|
|
||||||
|
|
||||||
test("after 1", function (done) {
|
|
||||||
var next = after(1, done)
|
|
||||||
next()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("after 5", function (done) {
|
|
||||||
var next = after(5, done)
|
|
||||||
, i = 5
|
|
||||||
|
|
||||||
while (i--) {
|
|
||||||
next()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
test("manipulate count", function (done) {
|
|
||||||
var next = after(1, done)
|
|
||||||
, i = 5
|
|
||||||
|
|
||||||
next.count = i
|
|
||||||
while (i--) {
|
|
||||||
next()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
test("after terminates on error", function (done) {
|
|
||||||
var next = after(2, function(err) {
|
|
||||||
assert.equal(err.message, 'test');
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
next(new Error('test'))
|
|
||||||
next(new Error('test2'))
|
|
||||||
})
|
|
||||||
|
|
||||||
test('gee', function(done) {
|
|
||||||
done = after(2, done)
|
|
||||||
|
|
||||||
function cb(err) {
|
|
||||||
assert.equal(err.message, 1);
|
|
||||||
done()
|
|
||||||
}
|
|
||||||
|
|
||||||
var next = after(3, cb, function(err) {
|
|
||||||
assert.equal(err.message, 2)
|
|
||||||
done()
|
|
||||||
});
|
|
||||||
|
|
||||||
next()
|
|
||||||
next(new Error(1))
|
|
||||||
next(new Error(2))
|
|
||||||
})
|
|
||||||
|
|
||||||
test('eee', function(done) {
|
|
||||||
done = after(3, done)
|
|
||||||
|
|
||||||
function cb(err) {
|
|
||||||
assert.equal(err.message, 1);
|
|
||||||
done()
|
|
||||||
}
|
|
||||||
|
|
||||||
var next = after(3, cb, function(err) {
|
|
||||||
assert.equal(err.message, 2)
|
|
||||||
done()
|
|
||||||
});
|
|
||||||
|
|
||||||
next(new Error(1))
|
|
||||||
next(new Error(2))
|
|
||||||
next(new Error(2))
|
|
||||||
})
|
|
||||||
|
|
||||||
test('gge', function(done) {
|
|
||||||
function cb(err) {
|
|
||||||
assert.equal(err.message, 1);
|
|
||||||
done()
|
|
||||||
}
|
|
||||||
|
|
||||||
var next = after(3, cb, function(err) {
|
|
||||||
// should not happen
|
|
||||||
assert.ok(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
next()
|
|
||||||
next()
|
|
||||||
next(new Error(1))
|
|
||||||
})
|
|
||||||
|
|
||||||
test('egg', function(done) {
|
|
||||||
function cb(err) {
|
|
||||||
assert.equal(err.message, 1);
|
|
||||||
done()
|
|
||||||
}
|
|
||||||
|
|
||||||
var next = after(3, cb, function(err) {
|
|
||||||
// should not happen
|
|
||||||
assert.ok(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
next(new Error(1))
|
|
||||||
next()
|
|
||||||
next()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('throws on too many calls', function(done) {
|
|
||||||
var next = after(1, done);
|
|
||||||
next()
|
|
||||||
assert.throws(next, /after called too many times/);
|
|
||||||
});
|
|
||||||
|
|
@ -1,185 +0,0 @@
|
|||||||
1.0.10 / 2018-02-15
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Use .concat instead of + for arrays, #122.
|
|
||||||
|
|
||||||
|
|
||||||
1.0.9 / 2016-09-29
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Rerelease after 1.0.8 - deps cleanup.
|
|
||||||
|
|
||||||
|
|
||||||
1.0.8 / 2016-09-29
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Maintenance (deps bump, fix node 6.5+ tests, coverage report).
|
|
||||||
|
|
||||||
|
|
||||||
1.0.7 / 2016-03-17
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Teach `addArgument` to accept string arg names. #97, @tomxtobin.
|
|
||||||
|
|
||||||
|
|
||||||
1.0.6 / 2016-02-06
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Maintenance: moved to eslint & updated CS.
|
|
||||||
|
|
||||||
|
|
||||||
1.0.5 / 2016-02-05
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Removed lodash dependency to significantly reduce install size.
|
|
||||||
Thanks to @mourner.
|
|
||||||
|
|
||||||
|
|
||||||
1.0.4 / 2016-01-17
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Maintenance: lodash update to 4.0.0.
|
|
||||||
|
|
||||||
|
|
||||||
1.0.3 / 2015-10-27
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Fix parse `=` in args: `--examplepath="C:\myfolder\env=x64"`. #84, @CatWithApple.
|
|
||||||
|
|
||||||
|
|
||||||
1.0.2 / 2015-03-22
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Relaxed lodash version dependency.
|
|
||||||
|
|
||||||
|
|
||||||
1.0.1 / 2015-02-20
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Changed dependencies to be compatible with ancient nodejs.
|
|
||||||
|
|
||||||
|
|
||||||
1.0.0 / 2015-02-19
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Maintenance release.
|
|
||||||
- Replaced `underscore` with `lodash`.
|
|
||||||
- Bumped version to 1.0.0 to better reflect semver meaning.
|
|
||||||
- HISTORY.md -> CHANGELOG.md
|
|
||||||
|
|
||||||
|
|
||||||
0.1.16 / 2013-12-01
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
- Maintenance release. Updated dependencies and docs.
|
|
||||||
|
|
||||||
|
|
||||||
0.1.15 / 2013-05-13
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
- Fixed #55, @trebor89
|
|
||||||
|
|
||||||
|
|
||||||
0.1.14 / 2013-05-12
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
- Fixed #62, @maxtaco
|
|
||||||
|
|
||||||
|
|
||||||
0.1.13 / 2013-04-08
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
- Added `.npmignore` to reduce package size
|
|
||||||
|
|
||||||
|
|
||||||
0.1.12 / 2013-02-10
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
- Fixed conflictHandler (#46), @hpaulj
|
|
||||||
|
|
||||||
|
|
||||||
0.1.11 / 2013-02-07
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
- Multiple bugfixes, @hpaulj
|
|
||||||
- Added 70+ tests (ported from python), @hpaulj
|
|
||||||
- Added conflictHandler, @applepicke
|
|
||||||
- Added fromfilePrefixChar, @hpaulj
|
|
||||||
|
|
||||||
|
|
||||||
0.1.10 / 2012-12-30
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
- Added [mutual exclusion](http://docs.python.org/dev/library/argparse.html#mutual-exclusion)
|
|
||||||
support, thanks to @hpaulj
|
|
||||||
- Fixed options check for `storeConst` & `appendConst` actions, thanks to @hpaulj
|
|
||||||
|
|
||||||
|
|
||||||
0.1.9 / 2012-12-27
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Fixed option dest interferens with other options (issue #23), thanks to @hpaulj
|
|
||||||
- Fixed default value behavior with `*` positionals, thanks to @hpaulj
|
|
||||||
- Improve `getDefault()` behavior, thanks to @hpaulj
|
|
||||||
- Imrove negative argument parsing, thanks to @hpaulj
|
|
||||||
|
|
||||||
|
|
||||||
0.1.8 / 2012-12-01
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Fixed parser parents (issue #19), thanks to @hpaulj
|
|
||||||
- Fixed negative argument parse (issue #20), thanks to @hpaulj
|
|
||||||
|
|
||||||
|
|
||||||
0.1.7 / 2012-10-14
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Fixed 'choices' argument parse (issue #16)
|
|
||||||
- Fixed stderr output (issue #15)
|
|
||||||
|
|
||||||
|
|
||||||
0.1.6 / 2012-09-09
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Fixed check for conflict of options (thanks to @tomxtobin)
|
|
||||||
|
|
||||||
|
|
||||||
0.1.5 / 2012-09-03
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Fix parser #setDefaults method (thanks to @tomxtobin)
|
|
||||||
|
|
||||||
|
|
||||||
0.1.4 / 2012-07-30
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Fixed pseudo-argument support (thanks to @CGamesPlay)
|
|
||||||
- Fixed addHelp default (should be true), if not set (thanks to @benblank)
|
|
||||||
|
|
||||||
|
|
||||||
0.1.3 / 2012-06-27
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Fixed formatter api name: Formatter -> HelpFormatter
|
|
||||||
|
|
||||||
|
|
||||||
0.1.2 / 2012-05-29
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Added basic tests
|
|
||||||
- Removed excess whitespace in help
|
|
||||||
- Fixed error reporting, when parcer with subcommands
|
|
||||||
called with empty arguments
|
|
||||||
|
|
||||||
|
|
||||||
0.1.1 / 2012-05-23
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Fixed line wrapping in help formatter
|
|
||||||
- Added better error reporting on invalid arguments
|
|
||||||
|
|
||||||
|
|
||||||
0.1.0 / 2012-05-16
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- First release.
|
|
@ -1,21 +0,0 @@
|
|||||||
(The MIT License)
|
|
||||||
|
|
||||||
Copyright (C) 2012 by Vitaly Puzrin
|
|
||||||
|
|
||||||
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:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
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.
|
|
@ -1,3 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = require('./lib/argparse');
|
|
@ -1,146 +0,0 @@
|
|||||||
/**
|
|
||||||
* class Action
|
|
||||||
*
|
|
||||||
* Base class for all actions
|
|
||||||
* Do not call in your code, use this class only for inherits your own action
|
|
||||||
*
|
|
||||||
* Information about how to convert command line strings to Javascript objects.
|
|
||||||
* Action objects are used by an ArgumentParser to represent the information
|
|
||||||
* needed to parse a single argument from one or more strings from the command
|
|
||||||
* line. The keyword arguments to the Action constructor are also all attributes
|
|
||||||
* of Action instances.
|
|
||||||
*
|
|
||||||
* ##### Allowed keywords:
|
|
||||||
*
|
|
||||||
* - `store`
|
|
||||||
* - `storeConstant`
|
|
||||||
* - `storeTrue`
|
|
||||||
* - `storeFalse`
|
|
||||||
* - `append`
|
|
||||||
* - `appendConstant`
|
|
||||||
* - `count`
|
|
||||||
* - `help`
|
|
||||||
* - `version`
|
|
||||||
*
|
|
||||||
* Information about action options see [[Action.new]]
|
|
||||||
*
|
|
||||||
* See also [original guide](http://docs.python.org/dev/library/argparse.html#action)
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
|
|
||||||
// Constants
|
|
||||||
var c = require('./const');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* new Action(options)
|
|
||||||
*
|
|
||||||
* Base class for all actions. Used only for inherits
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* ##### Options:
|
|
||||||
*
|
|
||||||
* - `optionStrings` A list of command-line option strings for the action.
|
|
||||||
* - `dest` Attribute to hold the created object(s)
|
|
||||||
* - `nargs` The number of command-line arguments that should be consumed.
|
|
||||||
* By default, one argument will be consumed and a single value will be
|
|
||||||
* produced.
|
|
||||||
* - `constant` Default value for an action with no value.
|
|
||||||
* - `defaultValue` The value to be produced if the option is not specified.
|
|
||||||
* - `type` Cast to 'string'|'int'|'float'|'complex'|function (string). If
|
|
||||||
* None, 'string'.
|
|
||||||
* - `choices` The choices available.
|
|
||||||
* - `required` True if the action must always be specified at the command
|
|
||||||
* line.
|
|
||||||
* - `help` The help describing the argument.
|
|
||||||
* - `metavar` The name to be used for the option's argument with the help
|
|
||||||
* string. If None, the 'dest' value will be used as the name.
|
|
||||||
*
|
|
||||||
* ##### nargs supported values:
|
|
||||||
*
|
|
||||||
* - `N` (an integer) consumes N arguments (and produces a list)
|
|
||||||
* - `?` consumes zero or one arguments
|
|
||||||
* - `*` consumes zero or more arguments (and produces a list)
|
|
||||||
* - `+` consumes one or more arguments (and produces a list)
|
|
||||||
*
|
|
||||||
* Note: that the difference between the default and nargs=1 is that with the
|
|
||||||
* default, a single value will be produced, while with nargs=1, a list
|
|
||||||
* containing a single value will be produced.
|
|
||||||
**/
|
|
||||||
var Action = module.exports = function Action(options) {
|
|
||||||
options = options || {};
|
|
||||||
this.optionStrings = options.optionStrings || [];
|
|
||||||
this.dest = options.dest;
|
|
||||||
this.nargs = typeof options.nargs !== 'undefined' ? options.nargs : null;
|
|
||||||
this.constant = typeof options.constant !== 'undefined' ? options.constant : null;
|
|
||||||
this.defaultValue = options.defaultValue;
|
|
||||||
this.type = typeof options.type !== 'undefined' ? options.type : null;
|
|
||||||
this.choices = typeof options.choices !== 'undefined' ? options.choices : null;
|
|
||||||
this.required = typeof options.required !== 'undefined' ? options.required : false;
|
|
||||||
this.help = typeof options.help !== 'undefined' ? options.help : null;
|
|
||||||
this.metavar = typeof options.metavar !== 'undefined' ? options.metavar : null;
|
|
||||||
|
|
||||||
if (!(this.optionStrings instanceof Array)) {
|
|
||||||
throw new Error('optionStrings should be an array');
|
|
||||||
}
|
|
||||||
if (typeof this.required !== 'undefined' && typeof this.required !== 'boolean') {
|
|
||||||
throw new Error('required should be a boolean');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Action#getName -> String
|
|
||||||
*
|
|
||||||
* Tells action name
|
|
||||||
**/
|
|
||||||
Action.prototype.getName = function () {
|
|
||||||
if (this.optionStrings.length > 0) {
|
|
||||||
return this.optionStrings.join('/');
|
|
||||||
} else if (this.metavar !== null && this.metavar !== c.SUPPRESS) {
|
|
||||||
return this.metavar;
|
|
||||||
} else if (typeof this.dest !== 'undefined' && this.dest !== c.SUPPRESS) {
|
|
||||||
return this.dest;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Action#isOptional -> Boolean
|
|
||||||
*
|
|
||||||
* Return true if optional
|
|
||||||
**/
|
|
||||||
Action.prototype.isOptional = function () {
|
|
||||||
return !this.isPositional();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Action#isPositional -> Boolean
|
|
||||||
*
|
|
||||||
* Return true if positional
|
|
||||||
**/
|
|
||||||
Action.prototype.isPositional = function () {
|
|
||||||
return (this.optionStrings.length === 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Action#call(parser, namespace, values, optionString) -> Void
|
|
||||||
* - parser (ArgumentParser): current parser
|
|
||||||
* - namespace (Namespace): namespace for output data
|
|
||||||
* - values (Array): parsed values
|
|
||||||
* - optionString (Array): input option string(not parsed)
|
|
||||||
*
|
|
||||||
* Call the action. Should be implemented in inherited classes
|
|
||||||
*
|
|
||||||
* ##### Example
|
|
||||||
*
|
|
||||||
* ActionCount.prototype.call = function (parser, namespace, values, optionString) {
|
|
||||||
* namespace.set(this.dest, (namespace[this.dest] || 0) + 1);
|
|
||||||
* };
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
Action.prototype.call = function () {
|
|
||||||
throw new Error('.call() not defined');// Not Implemented error
|
|
||||||
};
|
|
@ -1,53 +0,0 @@
|
|||||||
/*:nodoc:*
|
|
||||||
* class ActionAppend
|
|
||||||
*
|
|
||||||
* This action stores a list, and appends each argument value to the list.
|
|
||||||
* This is useful to allow an option to be specified multiple times.
|
|
||||||
* This class inherided from [[Action]]
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
var Action = require('../action');
|
|
||||||
|
|
||||||
// Constants
|
|
||||||
var c = require('../const');
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* new ActionAppend(options)
|
|
||||||
* - options (object): options hash see [[Action.new]]
|
|
||||||
*
|
|
||||||
* Note: options.nargs should be optional for constants
|
|
||||||
* and more then zero for other
|
|
||||||
**/
|
|
||||||
var ActionAppend = module.exports = function ActionAppend(options) {
|
|
||||||
options = options || {};
|
|
||||||
if (this.nargs <= 0) {
|
|
||||||
throw new Error('nargs for append actions must be > 0; if arg ' +
|
|
||||||
'strings are not supplying the value to append, ' +
|
|
||||||
'the append const action may be more appropriate');
|
|
||||||
}
|
|
||||||
if (!!this.constant && this.nargs !== c.OPTIONAL) {
|
|
||||||
throw new Error('nargs must be OPTIONAL to supply const');
|
|
||||||
}
|
|
||||||
Action.call(this, options);
|
|
||||||
};
|
|
||||||
util.inherits(ActionAppend, Action);
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* ActionAppend#call(parser, namespace, values, optionString) -> Void
|
|
||||||
* - parser (ArgumentParser): current parser
|
|
||||||
* - namespace (Namespace): namespace for output data
|
|
||||||
* - values (Array): parsed values
|
|
||||||
* - optionString (Array): input option string(not parsed)
|
|
||||||
*
|
|
||||||
* Call the action. Save result in namespace object
|
|
||||||
**/
|
|
||||||
ActionAppend.prototype.call = function (parser, namespace, values) {
|
|
||||||
var items = (namespace[this.dest] || []).slice();
|
|
||||||
items.push(values);
|
|
||||||
namespace.set(this.dest, items);
|
|
||||||
};
|
|
@ -1,47 +0,0 @@
|
|||||||
/*:nodoc:*
|
|
||||||
* class ActionAppendConstant
|
|
||||||
*
|
|
||||||
* This stores a list, and appends the value specified by
|
|
||||||
* the const keyword argument to the list.
|
|
||||||
* (Note that the const keyword argument defaults to null.)
|
|
||||||
* The 'appendConst' action is typically useful when multiple
|
|
||||||
* arguments need to store constants to the same list.
|
|
||||||
*
|
|
||||||
* This class inherited from [[Action]]
|
|
||||||
**/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
var Action = require('../../action');
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* new ActionAppendConstant(options)
|
|
||||||
* - options (object): options hash see [[Action.new]]
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
var ActionAppendConstant = module.exports = function ActionAppendConstant(options) {
|
|
||||||
options = options || {};
|
|
||||||
options.nargs = 0;
|
|
||||||
if (typeof options.constant === 'undefined') {
|
|
||||||
throw new Error('constant option is required for appendAction');
|
|
||||||
}
|
|
||||||
Action.call(this, options);
|
|
||||||
};
|
|
||||||
util.inherits(ActionAppendConstant, Action);
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* ActionAppendConstant#call(parser, namespace, values, optionString) -> Void
|
|
||||||
* - parser (ArgumentParser): current parser
|
|
||||||
* - namespace (Namespace): namespace for output data
|
|
||||||
* - values (Array): parsed values
|
|
||||||
* - optionString (Array): input option string(not parsed)
|
|
||||||
*
|
|
||||||
* Call the action. Save result in namespace object
|
|
||||||
**/
|
|
||||||
ActionAppendConstant.prototype.call = function (parser, namespace) {
|
|
||||||
var items = [].concat(namespace[this.dest] || []);
|
|
||||||
items.push(this.constant);
|
|
||||||
namespace.set(this.dest, items);
|
|
||||||
};
|
|
@ -1,40 +0,0 @@
|
|||||||
/*:nodoc:*
|
|
||||||
* class ActionCount
|
|
||||||
*
|
|
||||||
* This counts the number of times a keyword argument occurs.
|
|
||||||
* For example, this is useful for increasing verbosity levels
|
|
||||||
*
|
|
||||||
* This class inherided from [[Action]]
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
var Action = require('../action');
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* new ActionCount(options)
|
|
||||||
* - options (object): options hash see [[Action.new]]
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
var ActionCount = module.exports = function ActionCount(options) {
|
|
||||||
options = options || {};
|
|
||||||
options.nargs = 0;
|
|
||||||
|
|
||||||
Action.call(this, options);
|
|
||||||
};
|
|
||||||
util.inherits(ActionCount, Action);
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* ActionCount#call(parser, namespace, values, optionString) -> Void
|
|
||||||
* - parser (ArgumentParser): current parser
|
|
||||||
* - namespace (Namespace): namespace for output data
|
|
||||||
* - values (Array): parsed values
|
|
||||||
* - optionString (Array): input option string(not parsed)
|
|
||||||
*
|
|
||||||
* Call the action. Save result in namespace object
|
|
||||||
**/
|
|
||||||
ActionCount.prototype.call = function (parser, namespace) {
|
|
||||||
namespace.set(this.dest, (namespace[this.dest] || 0) + 1);
|
|
||||||
};
|
|
@ -1,47 +0,0 @@
|
|||||||
/*:nodoc:*
|
|
||||||
* class ActionHelp
|
|
||||||
*
|
|
||||||
* Support action for printing help
|
|
||||||
* This class inherided from [[Action]]
|
|
||||||
**/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
var Action = require('../action');
|
|
||||||
|
|
||||||
// Constants
|
|
||||||
var c = require('../const');
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* new ActionHelp(options)
|
|
||||||
* - options (object): options hash see [[Action.new]]
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
var ActionHelp = module.exports = function ActionHelp(options) {
|
|
||||||
options = options || {};
|
|
||||||
if (options.defaultValue !== null) {
|
|
||||||
options.defaultValue = options.defaultValue;
|
|
||||||
} else {
|
|
||||||
options.defaultValue = c.SUPPRESS;
|
|
||||||
}
|
|
||||||
options.dest = (options.dest !== null ? options.dest : c.SUPPRESS);
|
|
||||||
options.nargs = 0;
|
|
||||||
Action.call(this, options);
|
|
||||||
|
|
||||||
};
|
|
||||||
util.inherits(ActionHelp, Action);
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* ActionHelp#call(parser, namespace, values, optionString)
|
|
||||||
* - parser (ArgumentParser): current parser
|
|
||||||
* - namespace (Namespace): namespace for output data
|
|
||||||
* - values (Array): parsed values
|
|
||||||
* - optionString (Array): input option string(not parsed)
|
|
||||||
*
|
|
||||||
* Print help and exit
|
|
||||||
**/
|
|
||||||
ActionHelp.prototype.call = function (parser) {
|
|
||||||
parser.printHelp();
|
|
||||||
parser.exit();
|
|
||||||
};
|
|
@ -1,43 +0,0 @@
|
|||||||
/*:nodoc:*
|
|
||||||
* class ActionStoreConstant
|
|
||||||
*
|
|
||||||
* This action stores the value specified by the const keyword argument.
|
|
||||||
* (Note that the const keyword argument defaults to the rather unhelpful null.)
|
|
||||||
* The 'store_const' action is most commonly used with optional
|
|
||||||
* arguments that specify some sort of flag.
|
|
||||||
*
|
|
||||||
* This class inherited from [[Action]]
|
|
||||||
**/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
var Action = require('../../action');
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* new ActionStoreConstant(options)
|
|
||||||
* - options (object): options hash see [[Action.new]]
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
var ActionStoreConstant = module.exports = function ActionStoreConstant(options) {
|
|
||||||
options = options || {};
|
|
||||||
options.nargs = 0;
|
|
||||||
if (typeof options.constant === 'undefined') {
|
|
||||||
throw new Error('constant option is required for storeAction');
|
|
||||||
}
|
|
||||||
Action.call(this, options);
|
|
||||||
};
|
|
||||||
util.inherits(ActionStoreConstant, Action);
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* ActionStoreConstant#call(parser, namespace, values, optionString) -> Void
|
|
||||||
* - parser (ArgumentParser): current parser
|
|
||||||
* - namespace (Namespace): namespace for output data
|
|
||||||
* - values (Array): parsed values
|
|
||||||
* - optionString (Array): input option string(not parsed)
|
|
||||||
*
|
|
||||||
* Call the action. Save result in namespace object
|
|
||||||
**/
|
|
||||||
ActionStoreConstant.prototype.call = function (parser, namespace) {
|
|
||||||
namespace.set(this.dest, this.constant);
|
|
||||||
};
|
|
@ -1,27 +0,0 @@
|
|||||||
/*:nodoc:*
|
|
||||||
* class ActionStoreFalse
|
|
||||||
*
|
|
||||||
* This action store the values False respectively.
|
|
||||||
* This is special cases of 'storeConst'
|
|
||||||
*
|
|
||||||
* This class inherited from [[Action]]
|
|
||||||
**/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
var ActionStoreConstant = require('./constant');
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* new ActionStoreFalse(options)
|
|
||||||
* - options (object): hash of options see [[Action.new]]
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
var ActionStoreFalse = module.exports = function ActionStoreFalse(options) {
|
|
||||||
options = options || {};
|
|
||||||
options.constant = false;
|
|
||||||
options.defaultValue = options.defaultValue !== null ? options.defaultValue : true;
|
|
||||||
ActionStoreConstant.call(this, options);
|
|
||||||
};
|
|
||||||
util.inherits(ActionStoreFalse, ActionStoreConstant);
|
|
@ -1,26 +0,0 @@
|
|||||||
/*:nodoc:*
|
|
||||||
* class ActionStoreTrue
|
|
||||||
*
|
|
||||||
* This action store the values True respectively.
|
|
||||||
* This isspecial cases of 'storeConst'
|
|
||||||
*
|
|
||||||
* This class inherited from [[Action]]
|
|
||||||
**/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
var ActionStoreConstant = require('./constant');
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* new ActionStoreTrue(options)
|
|
||||||
* - options (object): options hash see [[Action.new]]
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
var ActionStoreTrue = module.exports = function ActionStoreTrue(options) {
|
|
||||||
options = options || {};
|
|
||||||
options.constant = true;
|
|
||||||
options.defaultValue = options.defaultValue !== null ? options.defaultValue : false;
|
|
||||||
ActionStoreConstant.call(this, options);
|
|
||||||
};
|
|
||||||
util.inherits(ActionStoreTrue, ActionStoreConstant);
|
|
@ -1,149 +0,0 @@
|
|||||||
/** internal
|
|
||||||
* class ActionSubparsers
|
|
||||||
*
|
|
||||||
* Support the creation of such sub-commands with the addSubparsers()
|
|
||||||
*
|
|
||||||
* This class inherited from [[Action]]
|
|
||||||
**/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
var format = require('util').format;
|
|
||||||
|
|
||||||
|
|
||||||
var Action = require('../action');
|
|
||||||
|
|
||||||
// Constants
|
|
||||||
var c = require('../const');
|
|
||||||
|
|
||||||
// Errors
|
|
||||||
var argumentErrorHelper = require('../argument/error');
|
|
||||||
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* new ChoicesPseudoAction(name, help)
|
|
||||||
*
|
|
||||||
* Create pseudo action for correct help text
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
function ChoicesPseudoAction(name, help) {
|
|
||||||
var options = {
|
|
||||||
optionStrings: [],
|
|
||||||
dest: name,
|
|
||||||
help: help
|
|
||||||
};
|
|
||||||
|
|
||||||
Action.call(this, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
util.inherits(ChoicesPseudoAction, Action);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* new ActionSubparsers(options)
|
|
||||||
* - options (object): options hash see [[Action.new]]
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
function ActionSubparsers(options) {
|
|
||||||
options = options || {};
|
|
||||||
options.dest = options.dest || c.SUPPRESS;
|
|
||||||
options.nargs = c.PARSER;
|
|
||||||
|
|
||||||
this.debug = (options.debug === true);
|
|
||||||
|
|
||||||
this._progPrefix = options.prog;
|
|
||||||
this._parserClass = options.parserClass;
|
|
||||||
this._nameParserMap = {};
|
|
||||||
this._choicesActions = [];
|
|
||||||
|
|
||||||
options.choices = this._nameParserMap;
|
|
||||||
Action.call(this, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
util.inherits(ActionSubparsers, Action);
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* ActionSubparsers#addParser(name, options) -> ArgumentParser
|
|
||||||
* - name (string): sub-command name
|
|
||||||
* - options (object): see [[ArgumentParser.new]]
|
|
||||||
*
|
|
||||||
* Note:
|
|
||||||
* addParser supports an additional aliases option,
|
|
||||||
* which allows multiple strings to refer to the same subparser.
|
|
||||||
* This example, like svn, aliases co as a shorthand for checkout
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
ActionSubparsers.prototype.addParser = function (name, options) {
|
|
||||||
var parser;
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
options = options || {};
|
|
||||||
|
|
||||||
options.debug = (this.debug === true);
|
|
||||||
|
|
||||||
// set program from the existing prefix
|
|
||||||
if (!options.prog) {
|
|
||||||
options.prog = this._progPrefix + ' ' + name;
|
|
||||||
}
|
|
||||||
|
|
||||||
var aliases = options.aliases || [];
|
|
||||||
|
|
||||||
// create a pseudo-action to hold the choice help
|
|
||||||
if (!!options.help || typeof options.help === 'string') {
|
|
||||||
var help = options.help;
|
|
||||||
delete options.help;
|
|
||||||
|
|
||||||
var choiceAction = new ChoicesPseudoAction(name, help);
|
|
||||||
this._choicesActions.push(choiceAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
// create the parser and add it to the map
|
|
||||||
parser = new this._parserClass(options);
|
|
||||||
this._nameParserMap[name] = parser;
|
|
||||||
|
|
||||||
// make parser available under aliases also
|
|
||||||
aliases.forEach(function (alias) {
|
|
||||||
self._nameParserMap[alias] = parser;
|
|
||||||
});
|
|
||||||
|
|
||||||
return parser;
|
|
||||||
};
|
|
||||||
|
|
||||||
ActionSubparsers.prototype._getSubactions = function () {
|
|
||||||
return this._choicesActions;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* ActionSubparsers#call(parser, namespace, values, optionString) -> Void
|
|
||||||
* - parser (ArgumentParser): current parser
|
|
||||||
* - namespace (Namespace): namespace for output data
|
|
||||||
* - values (Array): parsed values
|
|
||||||
* - optionString (Array): input option string(not parsed)
|
|
||||||
*
|
|
||||||
* Call the action. Parse input aguments
|
|
||||||
**/
|
|
||||||
ActionSubparsers.prototype.call = function (parser, namespace, values) {
|
|
||||||
var parserName = values[0];
|
|
||||||
var argStrings = values.slice(1);
|
|
||||||
|
|
||||||
// set the parser name if requested
|
|
||||||
if (this.dest !== c.SUPPRESS) {
|
|
||||||
namespace[this.dest] = parserName;
|
|
||||||
}
|
|
||||||
|
|
||||||
// select the parser
|
|
||||||
if (this._nameParserMap[parserName]) {
|
|
||||||
parser = this._nameParserMap[parserName];
|
|
||||||
} else {
|
|
||||||
throw argumentErrorHelper(format(
|
|
||||||
'Unknown parser "%s" (choices: [%s]).',
|
|
||||||
parserName,
|
|
||||||
Object.keys(this._nameParserMap).join(', ')
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse all the remaining options into the namespace
|
|
||||||
parser.parseArgs(argStrings, namespace);
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = ActionSubparsers;
|
|
@ -1,47 +0,0 @@
|
|||||||
/*:nodoc:*
|
|
||||||
* class ActionVersion
|
|
||||||
*
|
|
||||||
* Support action for printing program version
|
|
||||||
* This class inherited from [[Action]]
|
|
||||||
**/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
var Action = require('../action');
|
|
||||||
|
|
||||||
//
|
|
||||||
// Constants
|
|
||||||
//
|
|
||||||
var c = require('../const');
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* new ActionVersion(options)
|
|
||||||
* - options (object): options hash see [[Action.new]]
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
var ActionVersion = module.exports = function ActionVersion(options) {
|
|
||||||
options = options || {};
|
|
||||||
options.defaultValue = (options.defaultValue ? options.defaultValue : c.SUPPRESS);
|
|
||||||
options.dest = (options.dest || c.SUPPRESS);
|
|
||||||
options.nargs = 0;
|
|
||||||
this.version = options.version;
|
|
||||||
Action.call(this, options);
|
|
||||||
};
|
|
||||||
util.inherits(ActionVersion, Action);
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* ActionVersion#call(parser, namespace, values, optionString) -> Void
|
|
||||||
* - parser (ArgumentParser): current parser
|
|
||||||
* - namespace (Namespace): namespace for output data
|
|
||||||
* - values (Array): parsed values
|
|
||||||
* - optionString (Array): input option string(not parsed)
|
|
||||||
*
|
|
||||||
* Print version and exit
|
|
||||||
**/
|
|
||||||
ActionVersion.prototype.call = function (parser) {
|
|
||||||
var version = this.version || parser.version;
|
|
||||||
var formatter = parser._getFormatter();
|
|
||||||
formatter.addText(version);
|
|
||||||
parser.exit(0, formatter.formatHelp());
|
|
||||||
};
|
|
@ -1,482 +0,0 @@
|
|||||||
/** internal
|
|
||||||
* class ActionContainer
|
|
||||||
*
|
|
||||||
* Action container. Parent for [[ArgumentParser]] and [[ArgumentGroup]]
|
|
||||||
**/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var format = require('util').format;
|
|
||||||
|
|
||||||
// Constants
|
|
||||||
var c = require('./const');
|
|
||||||
|
|
||||||
var $$ = require('./utils');
|
|
||||||
|
|
||||||
//Actions
|
|
||||||
var ActionHelp = require('./action/help');
|
|
||||||
var ActionAppend = require('./action/append');
|
|
||||||
var ActionAppendConstant = require('./action/append/constant');
|
|
||||||
var ActionCount = require('./action/count');
|
|
||||||
var ActionStore = require('./action/store');
|
|
||||||
var ActionStoreConstant = require('./action/store/constant');
|
|
||||||
var ActionStoreTrue = require('./action/store/true');
|
|
||||||
var ActionStoreFalse = require('./action/store/false');
|
|
||||||
var ActionVersion = require('./action/version');
|
|
||||||
var ActionSubparsers = require('./action/subparsers');
|
|
||||||
|
|
||||||
// Errors
|
|
||||||
var argumentErrorHelper = require('./argument/error');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* new ActionContainer(options)
|
|
||||||
*
|
|
||||||
* Action container. Parent for [[ArgumentParser]] and [[ArgumentGroup]]
|
|
||||||
*
|
|
||||||
* ##### Options:
|
|
||||||
*
|
|
||||||
* - `description` -- A description of what the program does
|
|
||||||
* - `prefixChars` -- Characters that prefix optional arguments
|
|
||||||
* - `argumentDefault` -- The default value for all arguments
|
|
||||||
* - `conflictHandler` -- The conflict handler to use for duplicate arguments
|
|
||||||
**/
|
|
||||||
var ActionContainer = module.exports = function ActionContainer(options) {
|
|
||||||
options = options || {};
|
|
||||||
|
|
||||||
this.description = options.description;
|
|
||||||
this.argumentDefault = options.argumentDefault;
|
|
||||||
this.prefixChars = options.prefixChars || '';
|
|
||||||
this.conflictHandler = options.conflictHandler;
|
|
||||||
|
|
||||||
// set up registries
|
|
||||||
this._registries = {};
|
|
||||||
|
|
||||||
// register actions
|
|
||||||
this.register('action', null, ActionStore);
|
|
||||||
this.register('action', 'store', ActionStore);
|
|
||||||
this.register('action', 'storeConst', ActionStoreConstant);
|
|
||||||
this.register('action', 'storeTrue', ActionStoreTrue);
|
|
||||||
this.register('action', 'storeFalse', ActionStoreFalse);
|
|
||||||
this.register('action', 'append', ActionAppend);
|
|
||||||
this.register('action', 'appendConst', ActionAppendConstant);
|
|
||||||
this.register('action', 'count', ActionCount);
|
|
||||||
this.register('action', 'help', ActionHelp);
|
|
||||||
this.register('action', 'version', ActionVersion);
|
|
||||||
this.register('action', 'parsers', ActionSubparsers);
|
|
||||||
|
|
||||||
// raise an exception if the conflict handler is invalid
|
|
||||||
this._getHandler();
|
|
||||||
|
|
||||||
// action storage
|
|
||||||
this._actions = [];
|
|
||||||
this._optionStringActions = {};
|
|
||||||
|
|
||||||
// groups
|
|
||||||
this._actionGroups = [];
|
|
||||||
this._mutuallyExclusiveGroups = [];
|
|
||||||
|
|
||||||
// defaults storage
|
|
||||||
this._defaults = {};
|
|
||||||
|
|
||||||
// determines whether an "option" looks like a negative number
|
|
||||||
// -1, -1.5 -5e+4
|
|
||||||
this._regexpNegativeNumber = new RegExp('^[-]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$');
|
|
||||||
|
|
||||||
// whether or not there are any optionals that look like negative
|
|
||||||
// numbers -- uses a list so it can be shared and edited
|
|
||||||
this._hasNegativeNumberOptionals = [];
|
|
||||||
};
|
|
||||||
|
|
||||||
// Groups must be required, then ActionContainer already defined
|
|
||||||
var ArgumentGroup = require('./argument/group');
|
|
||||||
var MutuallyExclusiveGroup = require('./argument/exclusive');
|
|
||||||
|
|
||||||
//
|
|
||||||
// Registration methods
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ActionContainer#register(registryName, value, object) -> Void
|
|
||||||
* - registryName (String) : object type action|type
|
|
||||||
* - value (string) : keyword
|
|
||||||
* - object (Object|Function) : handler
|
|
||||||
*
|
|
||||||
* Register handlers
|
|
||||||
**/
|
|
||||||
ActionContainer.prototype.register = function (registryName, value, object) {
|
|
||||||
this._registries[registryName] = this._registries[registryName] || {};
|
|
||||||
this._registries[registryName][value] = object;
|
|
||||||
};
|
|
||||||
|
|
||||||
ActionContainer.prototype._registryGet = function (registryName, value, defaultValue) {
|
|
||||||
if (arguments.length < 3) {
|
|
||||||
defaultValue = null;
|
|
||||||
}
|
|
||||||
return this._registries[registryName][value] || defaultValue;
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// Namespace default accessor methods
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ActionContainer#setDefaults(options) -> Void
|
|
||||||
* - options (object):hash of options see [[Action.new]]
|
|
||||||
*
|
|
||||||
* Set defaults
|
|
||||||
**/
|
|
||||||
ActionContainer.prototype.setDefaults = function (options) {
|
|
||||||
options = options || {};
|
|
||||||
for (var property in options) {
|
|
||||||
if ($$.has(options, property)) {
|
|
||||||
this._defaults[property] = options[property];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if these defaults match any existing arguments, replace the previous
|
|
||||||
// default on the object with the new one
|
|
||||||
this._actions.forEach(function (action) {
|
|
||||||
if ($$.has(options, action.dest)) {
|
|
||||||
action.defaultValue = options[action.dest];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ActionContainer#getDefault(dest) -> Mixed
|
|
||||||
* - dest (string): action destination
|
|
||||||
*
|
|
||||||
* Return action default value
|
|
||||||
**/
|
|
||||||
ActionContainer.prototype.getDefault = function (dest) {
|
|
||||||
var result = $$.has(this._defaults, dest) ? this._defaults[dest] : null;
|
|
||||||
|
|
||||||
this._actions.forEach(function (action) {
|
|
||||||
if (action.dest === dest && $$.has(action, 'defaultValue')) {
|
|
||||||
result = action.defaultValue;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
//
|
|
||||||
// Adding argument actions
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ActionContainer#addArgument(args, options) -> Object
|
|
||||||
* - args (String|Array): argument key, or array of argument keys
|
|
||||||
* - options (Object): action objects see [[Action.new]]
|
|
||||||
*
|
|
||||||
* #### Examples
|
|
||||||
* - addArgument([ '-f', '--foo' ], { action: 'store', defaultValue: 1, ... })
|
|
||||||
* - addArgument([ 'bar' ], { action: 'store', nargs: 1, ... })
|
|
||||||
* - addArgument('--baz', { action: 'store', nargs: 1, ... })
|
|
||||||
**/
|
|
||||||
ActionContainer.prototype.addArgument = function (args, options) {
|
|
||||||
args = args;
|
|
||||||
options = options || {};
|
|
||||||
|
|
||||||
if (typeof args === 'string') {
|
|
||||||
args = [ args ];
|
|
||||||
}
|
|
||||||
if (!Array.isArray(args)) {
|
|
||||||
throw new TypeError('addArgument first argument should be a string or an array');
|
|
||||||
}
|
|
||||||
if (typeof options !== 'object' || Array.isArray(options)) {
|
|
||||||
throw new TypeError('addArgument second argument should be a hash');
|
|
||||||
}
|
|
||||||
|
|
||||||
// if no positional args are supplied or only one is supplied and
|
|
||||||
// it doesn't look like an option string, parse a positional argument
|
|
||||||
if (!args || args.length === 1 && this.prefixChars.indexOf(args[0][0]) < 0) {
|
|
||||||
if (args && !!options.dest) {
|
|
||||||
throw new Error('dest supplied twice for positional argument');
|
|
||||||
}
|
|
||||||
options = this._getPositional(args, options);
|
|
||||||
|
|
||||||
// otherwise, we're adding an optional argument
|
|
||||||
} else {
|
|
||||||
options = this._getOptional(args, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if no default was supplied, use the parser-level default
|
|
||||||
if (typeof options.defaultValue === 'undefined') {
|
|
||||||
var dest = options.dest;
|
|
||||||
if ($$.has(this._defaults, dest)) {
|
|
||||||
options.defaultValue = this._defaults[dest];
|
|
||||||
} else if (typeof this.argumentDefault !== 'undefined') {
|
|
||||||
options.defaultValue = this.argumentDefault;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// create the action object, and add it to the parser
|
|
||||||
var ActionClass = this._popActionClass(options);
|
|
||||||
if (typeof ActionClass !== 'function') {
|
|
||||||
throw new Error(format('Unknown action "%s".', ActionClass));
|
|
||||||
}
|
|
||||||
var action = new ActionClass(options);
|
|
||||||
|
|
||||||
// throw an error if the action type is not callable
|
|
||||||
var typeFunction = this._registryGet('type', action.type, action.type);
|
|
||||||
if (typeof typeFunction !== 'function') {
|
|
||||||
throw new Error(format('"%s" is not callable', typeFunction));
|
|
||||||
}
|
|
||||||
|
|
||||||
return this._addAction(action);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ActionContainer#addArgumentGroup(options) -> ArgumentGroup
|
|
||||||
* - options (Object): hash of options see [[ArgumentGroup.new]]
|
|
||||||
*
|
|
||||||
* Create new arguments groups
|
|
||||||
**/
|
|
||||||
ActionContainer.prototype.addArgumentGroup = function (options) {
|
|
||||||
var group = new ArgumentGroup(this, options);
|
|
||||||
this._actionGroups.push(group);
|
|
||||||
return group;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ActionContainer#addMutuallyExclusiveGroup(options) -> ArgumentGroup
|
|
||||||
* - options (Object): {required: false}
|
|
||||||
*
|
|
||||||
* Create new mutual exclusive groups
|
|
||||||
**/
|
|
||||||
ActionContainer.prototype.addMutuallyExclusiveGroup = function (options) {
|
|
||||||
var group = new MutuallyExclusiveGroup(this, options);
|
|
||||||
this._mutuallyExclusiveGroups.push(group);
|
|
||||||
return group;
|
|
||||||
};
|
|
||||||
|
|
||||||
ActionContainer.prototype._addAction = function (action) {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
// resolve any conflicts
|
|
||||||
this._checkConflict(action);
|
|
||||||
|
|
||||||
// add to actions list
|
|
||||||
this._actions.push(action);
|
|
||||||
action.container = this;
|
|
||||||
|
|
||||||
// index the action by any option strings it has
|
|
||||||
action.optionStrings.forEach(function (optionString) {
|
|
||||||
self._optionStringActions[optionString] = action;
|
|
||||||
});
|
|
||||||
|
|
||||||
// set the flag if any option strings look like negative numbers
|
|
||||||
action.optionStrings.forEach(function (optionString) {
|
|
||||||
if (optionString.match(self._regexpNegativeNumber)) {
|
|
||||||
if (!self._hasNegativeNumberOptionals.some(Boolean)) {
|
|
||||||
self._hasNegativeNumberOptionals.push(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// return the created action
|
|
||||||
return action;
|
|
||||||
};
|
|
||||||
|
|
||||||
ActionContainer.prototype._removeAction = function (action) {
|
|
||||||
var actionIndex = this._actions.indexOf(action);
|
|
||||||
if (actionIndex >= 0) {
|
|
||||||
this._actions.splice(actionIndex, 1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ActionContainer.prototype._addContainerActions = function (container) {
|
|
||||||
// collect groups by titles
|
|
||||||
var titleGroupMap = {};
|
|
||||||
this._actionGroups.forEach(function (group) {
|
|
||||||
if (titleGroupMap[group.title]) {
|
|
||||||
throw new Error(format('Cannot merge actions - two groups are named "%s".', group.title));
|
|
||||||
}
|
|
||||||
titleGroupMap[group.title] = group;
|
|
||||||
});
|
|
||||||
|
|
||||||
// map each action to its group
|
|
||||||
var groupMap = {};
|
|
||||||
function actionHash(action) {
|
|
||||||
// unique (hopefully?) string suitable as dictionary key
|
|
||||||
return action.getName();
|
|
||||||
}
|
|
||||||
container._actionGroups.forEach(function (group) {
|
|
||||||
// if a group with the title exists, use that, otherwise
|
|
||||||
// create a new group matching the container's group
|
|
||||||
if (!titleGroupMap[group.title]) {
|
|
||||||
titleGroupMap[group.title] = this.addArgumentGroup({
|
|
||||||
title: group.title,
|
|
||||||
description: group.description
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// map the actions to their new group
|
|
||||||
group._groupActions.forEach(function (action) {
|
|
||||||
groupMap[actionHash(action)] = titleGroupMap[group.title];
|
|
||||||
});
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
// add container's mutually exclusive groups
|
|
||||||
// NOTE: if add_mutually_exclusive_group ever gains title= and
|
|
||||||
// description= then this code will need to be expanded as above
|
|
||||||
var mutexGroup;
|
|
||||||
container._mutuallyExclusiveGroups.forEach(function (group) {
|
|
||||||
mutexGroup = this.addMutuallyExclusiveGroup({
|
|
||||||
required: group.required
|
|
||||||
});
|
|
||||||
// map the actions to their new mutex group
|
|
||||||
group._groupActions.forEach(function (action) {
|
|
||||||
groupMap[actionHash(action)] = mutexGroup;
|
|
||||||
});
|
|
||||||
}, this); // forEach takes a 'this' argument
|
|
||||||
|
|
||||||
// add all actions to this container or their group
|
|
||||||
container._actions.forEach(function (action) {
|
|
||||||
var key = actionHash(action);
|
|
||||||
if (groupMap[key]) {
|
|
||||||
groupMap[key]._addAction(action);
|
|
||||||
} else {
|
|
||||||
this._addAction(action);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ActionContainer.prototype._getPositional = function (dest, options) {
|
|
||||||
if (Array.isArray(dest)) {
|
|
||||||
dest = dest[0];
|
|
||||||
}
|
|
||||||
// make sure required is not specified
|
|
||||||
if (options.required) {
|
|
||||||
throw new Error('"required" is an invalid argument for positionals.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// mark positional arguments as required if at least one is
|
|
||||||
// always required
|
|
||||||
if (options.nargs !== c.OPTIONAL && options.nargs !== c.ZERO_OR_MORE) {
|
|
||||||
options.required = true;
|
|
||||||
}
|
|
||||||
if (options.nargs === c.ZERO_OR_MORE && typeof options.defaultValue === 'undefined') {
|
|
||||||
options.required = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the keyword arguments with no option strings
|
|
||||||
options.dest = dest;
|
|
||||||
options.optionStrings = [];
|
|
||||||
return options;
|
|
||||||
};
|
|
||||||
|
|
||||||
ActionContainer.prototype._getOptional = function (args, options) {
|
|
||||||
var prefixChars = this.prefixChars;
|
|
||||||
var optionStrings = [];
|
|
||||||
var optionStringsLong = [];
|
|
||||||
|
|
||||||
// determine short and long option strings
|
|
||||||
args.forEach(function (optionString) {
|
|
||||||
// error on strings that don't start with an appropriate prefix
|
|
||||||
if (prefixChars.indexOf(optionString[0]) < 0) {
|
|
||||||
throw new Error(format('Invalid option string "%s": must start with a "%s".',
|
|
||||||
optionString,
|
|
||||||
prefixChars
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
// strings starting with two prefix characters are long options
|
|
||||||
optionStrings.push(optionString);
|
|
||||||
if (optionString.length > 1 && prefixChars.indexOf(optionString[1]) >= 0) {
|
|
||||||
optionStringsLong.push(optionString);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// infer dest, '--foo-bar' -> 'foo_bar' and '-x' -> 'x'
|
|
||||||
var dest = options.dest || null;
|
|
||||||
delete options.dest;
|
|
||||||
|
|
||||||
if (!dest) {
|
|
||||||
var optionStringDest = optionStringsLong.length ? optionStringsLong[0] : optionStrings[0];
|
|
||||||
dest = $$.trimChars(optionStringDest, this.prefixChars);
|
|
||||||
|
|
||||||
if (dest.length === 0) {
|
|
||||||
throw new Error(
|
|
||||||
format('dest= is required for options like "%s"', optionStrings.join(', '))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
dest = dest.replace(/-/g, '_');
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the updated keyword arguments
|
|
||||||
options.dest = dest;
|
|
||||||
options.optionStrings = optionStrings;
|
|
||||||
|
|
||||||
return options;
|
|
||||||
};
|
|
||||||
|
|
||||||
ActionContainer.prototype._popActionClass = function (options, defaultValue) {
|
|
||||||
defaultValue = defaultValue || null;
|
|
||||||
|
|
||||||
var action = (options.action || defaultValue);
|
|
||||||
delete options.action;
|
|
||||||
|
|
||||||
var actionClass = this._registryGet('action', action, action);
|
|
||||||
return actionClass;
|
|
||||||
};
|
|
||||||
|
|
||||||
ActionContainer.prototype._getHandler = function () {
|
|
||||||
var handlerString = this.conflictHandler;
|
|
||||||
var handlerFuncName = '_handleConflict' + $$.capitalize(handlerString);
|
|
||||||
var func = this[handlerFuncName];
|
|
||||||
if (typeof func === 'undefined') {
|
|
||||||
var msg = 'invalid conflict resolution value: ' + handlerString;
|
|
||||||
throw new Error(msg);
|
|
||||||
} else {
|
|
||||||
return func;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ActionContainer.prototype._checkConflict = function (action) {
|
|
||||||
var optionStringActions = this._optionStringActions;
|
|
||||||
var conflictOptionals = [];
|
|
||||||
|
|
||||||
// find all options that conflict with this option
|
|
||||||
// collect pairs, the string, and an existing action that it conflicts with
|
|
||||||
action.optionStrings.forEach(function (optionString) {
|
|
||||||
var conflOptional = optionStringActions[optionString];
|
|
||||||
if (typeof conflOptional !== 'undefined') {
|
|
||||||
conflictOptionals.push([ optionString, conflOptional ]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (conflictOptionals.length > 0) {
|
|
||||||
var conflictHandler = this._getHandler();
|
|
||||||
conflictHandler.call(this, action, conflictOptionals);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ActionContainer.prototype._handleConflictError = function (action, conflOptionals) {
|
|
||||||
var conflicts = conflOptionals.map(function (pair) { return pair[0]; });
|
|
||||||
conflicts = conflicts.join(', ');
|
|
||||||
throw argumentErrorHelper(
|
|
||||||
action,
|
|
||||||
format('Conflicting option string(s): %s', conflicts)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
ActionContainer.prototype._handleConflictResolve = function (action, conflOptionals) {
|
|
||||||
// remove all conflicting options
|
|
||||||
var self = this;
|
|
||||||
conflOptionals.forEach(function (pair) {
|
|
||||||
var optionString = pair[0];
|
|
||||||
var conflictingAction = pair[1];
|
|
||||||
// remove the conflicting option string
|
|
||||||
var i = conflictingAction.optionStrings.indexOf(optionString);
|
|
||||||
if (i >= 0) {
|
|
||||||
conflictingAction.optionStrings.splice(i, 1);
|
|
||||||
}
|
|
||||||
delete self._optionStringActions[optionString];
|
|
||||||
// if the option now has no option string, remove it from the
|
|
||||||
// container holding it
|
|
||||||
if (conflictingAction.optionStrings.length === 0) {
|
|
||||||
conflictingAction.container._removeAction(conflictingAction);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
@ -1,14 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports.ArgumentParser = require('./argument_parser.js');
|
|
||||||
module.exports.Namespace = require('./namespace');
|
|
||||||
module.exports.Action = require('./action');
|
|
||||||
module.exports.HelpFormatter = require('./help/formatter.js');
|
|
||||||
module.exports.Const = require('./const.js');
|
|
||||||
|
|
||||||
module.exports.ArgumentDefaultsHelpFormatter =
|
|
||||||
require('./help/added_formatters.js').ArgumentDefaultsHelpFormatter;
|
|
||||||
module.exports.RawDescriptionHelpFormatter =
|
|
||||||
require('./help/added_formatters.js').RawDescriptionHelpFormatter;
|
|
||||||
module.exports.RawTextHelpFormatter =
|
|
||||||
require('./help/added_formatters.js').RawTextHelpFormatter;
|
|
@ -1,50 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
|
|
||||||
var format = require('util').format;
|
|
||||||
|
|
||||||
|
|
||||||
var ERR_CODE = 'ARGError';
|
|
||||||
|
|
||||||
/*:nodoc:*
|
|
||||||
* argumentError(argument, message) -> TypeError
|
|
||||||
* - argument (Object): action with broken argument
|
|
||||||
* - message (String): error message
|
|
||||||
*
|
|
||||||
* Error format helper. An error from creating or using an argument
|
|
||||||
* (optional or positional). The string value of this exception
|
|
||||||
* is the message, augmented with information
|
|
||||||
* about the argument that caused it.
|
|
||||||
*
|
|
||||||
* #####Example
|
|
||||||
*
|
|
||||||
* var argumentErrorHelper = require('./argument/error');
|
|
||||||
* if (conflictOptionals.length > 0) {
|
|
||||||
* throw argumentErrorHelper(
|
|
||||||
* action,
|
|
||||||
* format('Conflicting option string(s): %s', conflictOptionals.join(', '))
|
|
||||||
* );
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
module.exports = function (argument, message) {
|
|
||||||
var argumentName = null;
|
|
||||||
var errMessage;
|
|
||||||
var err;
|
|
||||||
|
|
||||||
if (argument.getName) {
|
|
||||||
argumentName = argument.getName();
|
|
||||||
} else {
|
|
||||||
argumentName = '' + argument;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!argumentName) {
|
|
||||||
errMessage = message;
|
|
||||||
} else {
|
|
||||||
errMessage = format('argument "%s": %s', argumentName, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
err = new TypeError(errMessage);
|
|
||||||
err.code = ERR_CODE;
|
|
||||||
return err;
|
|
||||||
};
|
|
@ -1,54 +0,0 @@
|
|||||||
/** internal
|
|
||||||
* class MutuallyExclusiveGroup
|
|
||||||
*
|
|
||||||
* Group arguments.
|
|
||||||
* By default, ArgumentParser groups command-line arguments
|
|
||||||
* into “positional arguments” and “optional arguments”
|
|
||||||
* when displaying help messages. When there is a better
|
|
||||||
* conceptual grouping of arguments than this default one,
|
|
||||||
* appropriate groups can be created using the addArgumentGroup() method
|
|
||||||
*
|
|
||||||
* This class inherited from [[ArgumentContainer]]
|
|
||||||
**/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
var ArgumentGroup = require('./group');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* new MutuallyExclusiveGroup(container, options)
|
|
||||||
* - container (object): main container
|
|
||||||
* - options (object): options.required -> true/false
|
|
||||||
*
|
|
||||||
* `required` could be an argument itself, but making it a property of
|
|
||||||
* the options argument is more consistent with the JS adaptation of the Python)
|
|
||||||
**/
|
|
||||||
var MutuallyExclusiveGroup = module.exports = function MutuallyExclusiveGroup(container, options) {
|
|
||||||
var required;
|
|
||||||
options = options || {};
|
|
||||||
required = options.required || false;
|
|
||||||
ArgumentGroup.call(this, container);
|
|
||||||
this.required = required;
|
|
||||||
|
|
||||||
};
|
|
||||||
util.inherits(MutuallyExclusiveGroup, ArgumentGroup);
|
|
||||||
|
|
||||||
|
|
||||||
MutuallyExclusiveGroup.prototype._addAction = function (action) {
|
|
||||||
var msg;
|
|
||||||
if (action.required) {
|
|
||||||
msg = 'mutually exclusive arguments must be optional';
|
|
||||||
throw new Error(msg);
|
|
||||||
}
|
|
||||||
action = this._container._addAction(action);
|
|
||||||
this._groupActions.push(action);
|
|
||||||
return action;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
MutuallyExclusiveGroup.prototype._removeAction = function (action) {
|
|
||||||
this._container._removeAction(action);
|
|
||||||
this._groupActions.remove(action);
|
|
||||||
};
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
|||||||
/** internal
|
|
||||||
* class ArgumentGroup
|
|
||||||
*
|
|
||||||
* Group arguments.
|
|
||||||
* By default, ArgumentParser groups command-line arguments
|
|
||||||
* into “positional arguments” and “optional arguments”
|
|
||||||
* when displaying help messages. When there is a better
|
|
||||||
* conceptual grouping of arguments than this default one,
|
|
||||||
* appropriate groups can be created using the addArgumentGroup() method
|
|
||||||
*
|
|
||||||
* This class inherited from [[ArgumentContainer]]
|
|
||||||
**/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
var ActionContainer = require('../action_container');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* new ArgumentGroup(container, options)
|
|
||||||
* - container (object): main container
|
|
||||||
* - options (object): hash of group options
|
|
||||||
*
|
|
||||||
* #### options
|
|
||||||
* - **prefixChars** group name prefix
|
|
||||||
* - **argumentDefault** default argument value
|
|
||||||
* - **title** group title
|
|
||||||
* - **description** group description
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
var ArgumentGroup = module.exports = function ArgumentGroup(container, options) {
|
|
||||||
|
|
||||||
options = options || {};
|
|
||||||
|
|
||||||
// add any missing keyword arguments by checking the container
|
|
||||||
options.conflictHandler = (options.conflictHandler || container.conflictHandler);
|
|
||||||
options.prefixChars = (options.prefixChars || container.prefixChars);
|
|
||||||
options.argumentDefault = (options.argumentDefault || container.argumentDefault);
|
|
||||||
|
|
||||||
ActionContainer.call(this, options);
|
|
||||||
|
|
||||||
// group attributes
|
|
||||||
this.title = options.title;
|
|
||||||
this._groupActions = [];
|
|
||||||
|
|
||||||
// share most attributes with the container
|
|
||||||
this._container = container;
|
|
||||||
this._registries = container._registries;
|
|
||||||
this._actions = container._actions;
|
|
||||||
this._optionStringActions = container._optionStringActions;
|
|
||||||
this._defaults = container._defaults;
|
|
||||||
this._hasNegativeNumberOptionals = container._hasNegativeNumberOptionals;
|
|
||||||
this._mutuallyExclusiveGroups = container._mutuallyExclusiveGroups;
|
|
||||||
};
|
|
||||||
util.inherits(ArgumentGroup, ActionContainer);
|
|
||||||
|
|
||||||
|
|
||||||
ArgumentGroup.prototype._addAction = function (action) {
|
|
||||||
// Parent add action
|
|
||||||
action = ActionContainer.prototype._addAction.call(this, action);
|
|
||||||
this._groupActions.push(action);
|
|
||||||
return action;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
ArgumentGroup.prototype._removeAction = function (action) {
|
|
||||||
// Parent remove action
|
|
||||||
ActionContainer.prototype._removeAction.call(this, action);
|
|
||||||
var actionIndex = this._groupActions.indexOf(action);
|
|
||||||
if (actionIndex >= 0) {
|
|
||||||
this._groupActions.splice(actionIndex, 1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
@ -1,21 +0,0 @@
|
|||||||
//
|
|
||||||
// Constants
|
|
||||||
//
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports.EOL = '\n';
|
|
||||||
|
|
||||||
module.exports.SUPPRESS = '==SUPPRESS==';
|
|
||||||
|
|
||||||
module.exports.OPTIONAL = '?';
|
|
||||||
|
|
||||||
module.exports.ZERO_OR_MORE = '*';
|
|
||||||
|
|
||||||
module.exports.ONE_OR_MORE = '+';
|
|
||||||
|
|
||||||
module.exports.PARSER = 'A...';
|
|
||||||
|
|
||||||
module.exports.REMAINDER = '...';
|
|
||||||
|
|
||||||
module.exports._UNRECOGNIZED_ARGS_ATTR = '_unrecognized_args';
|
|
@ -1,87 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
// Constants
|
|
||||||
var c = require('../const');
|
|
||||||
|
|
||||||
var $$ = require('../utils');
|
|
||||||
var HelpFormatter = require('./formatter.js');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* new RawDescriptionHelpFormatter(options)
|
|
||||||
* new ArgumentParser({formatterClass: argparse.RawDescriptionHelpFormatter, ...})
|
|
||||||
*
|
|
||||||
* Help message formatter which adds default values to argument help.
|
|
||||||
*
|
|
||||||
* Only the name of this class is considered a public API. All the methods
|
|
||||||
* provided by the class are considered an implementation detail.
|
|
||||||
**/
|
|
||||||
|
|
||||||
function ArgumentDefaultsHelpFormatter(options) {
|
|
||||||
HelpFormatter.call(this, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
util.inherits(ArgumentDefaultsHelpFormatter, HelpFormatter);
|
|
||||||
|
|
||||||
ArgumentDefaultsHelpFormatter.prototype._getHelpString = function (action) {
|
|
||||||
var help = action.help;
|
|
||||||
if (action.help.indexOf('%(defaultValue)s') === -1) {
|
|
||||||
if (action.defaultValue !== c.SUPPRESS) {
|
|
||||||
var defaulting_nargs = [ c.OPTIONAL, c.ZERO_OR_MORE ];
|
|
||||||
if (action.isOptional() || (defaulting_nargs.indexOf(action.nargs) >= 0)) {
|
|
||||||
help += ' (default: %(defaultValue)s)';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return help;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.ArgumentDefaultsHelpFormatter = ArgumentDefaultsHelpFormatter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* new RawDescriptionHelpFormatter(options)
|
|
||||||
* new ArgumentParser({formatterClass: argparse.RawDescriptionHelpFormatter, ...})
|
|
||||||
*
|
|
||||||
* Help message formatter which retains any formatting in descriptions.
|
|
||||||
*
|
|
||||||
* Only the name of this class is considered a public API. All the methods
|
|
||||||
* provided by the class are considered an implementation detail.
|
|
||||||
**/
|
|
||||||
|
|
||||||
function RawDescriptionHelpFormatter(options) {
|
|
||||||
HelpFormatter.call(this, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
util.inherits(RawDescriptionHelpFormatter, HelpFormatter);
|
|
||||||
|
|
||||||
RawDescriptionHelpFormatter.prototype._fillText = function (text, width, indent) {
|
|
||||||
var lines = text.split('\n');
|
|
||||||
lines = lines.map(function (line) {
|
|
||||||
return $$.trimEnd(indent + line);
|
|
||||||
});
|
|
||||||
return lines.join('\n');
|
|
||||||
};
|
|
||||||
module.exports.RawDescriptionHelpFormatter = RawDescriptionHelpFormatter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* new RawTextHelpFormatter(options)
|
|
||||||
* new ArgumentParser({formatterClass: argparse.RawTextHelpFormatter, ...})
|
|
||||||
*
|
|
||||||
* Help message formatter which retains formatting of all help text.
|
|
||||||
*
|
|
||||||
* Only the name of this class is considered a public API. All the methods
|
|
||||||
* provided by the class are considered an implementation detail.
|
|
||||||
**/
|
|
||||||
|
|
||||||
function RawTextHelpFormatter(options) {
|
|
||||||
RawDescriptionHelpFormatter.call(this, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
util.inherits(RawTextHelpFormatter, RawDescriptionHelpFormatter);
|
|
||||||
|
|
||||||
RawTextHelpFormatter.prototype._splitLines = function (text) {
|
|
||||||
return text.split('\n');
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.RawTextHelpFormatter = RawTextHelpFormatter;
|
|
@ -1,795 +0,0 @@
|
|||||||
/**
|
|
||||||
* class HelpFormatter
|
|
||||||
*
|
|
||||||
* Formatter for generating usage messages and argument help strings. Only the
|
|
||||||
* name of this class is considered a public API. All the methods provided by
|
|
||||||
* the class are considered an implementation detail.
|
|
||||||
*
|
|
||||||
* Do not call in your code, use this class only for inherits your own forvatter
|
|
||||||
*
|
|
||||||
* ToDo add [additonal formatters][1]
|
|
||||||
*
|
|
||||||
* [1]:http://docs.python.org/dev/library/argparse.html#formatter-class
|
|
||||||
**/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var sprintf = require('sprintf-js').sprintf;
|
|
||||||
|
|
||||||
// Constants
|
|
||||||
var c = require('../const');
|
|
||||||
|
|
||||||
var $$ = require('../utils');
|
|
||||||
|
|
||||||
|
|
||||||
/*:nodoc:* internal
|
|
||||||
* new Support(parent, heding)
|
|
||||||
* - parent (object): parent section
|
|
||||||
* - heading (string): header string
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
function Section(parent, heading) {
|
|
||||||
this._parent = parent;
|
|
||||||
this._heading = heading;
|
|
||||||
this._items = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*:nodoc:* internal
|
|
||||||
* Section#addItem(callback) -> Void
|
|
||||||
* - callback (array): tuple with function and args
|
|
||||||
*
|
|
||||||
* Add function for single element
|
|
||||||
**/
|
|
||||||
Section.prototype.addItem = function (callback) {
|
|
||||||
this._items.push(callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
/*:nodoc:* internal
|
|
||||||
* Section#formatHelp(formatter) -> string
|
|
||||||
* - formatter (HelpFormatter): current formatter
|
|
||||||
*
|
|
||||||
* Form help section string
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
Section.prototype.formatHelp = function (formatter) {
|
|
||||||
var itemHelp, heading;
|
|
||||||
|
|
||||||
// format the indented section
|
|
||||||
if (this._parent) {
|
|
||||||
formatter._indent();
|
|
||||||
}
|
|
||||||
|
|
||||||
itemHelp = this._items.map(function (item) {
|
|
||||||
var obj, func, args;
|
|
||||||
|
|
||||||
obj = formatter;
|
|
||||||
func = item[0];
|
|
||||||
args = item[1];
|
|
||||||
return func.apply(obj, args);
|
|
||||||
});
|
|
||||||
itemHelp = formatter._joinParts(itemHelp);
|
|
||||||
|
|
||||||
if (this._parent) {
|
|
||||||
formatter._dedent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// return nothing if the section was empty
|
|
||||||
if (!itemHelp) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// add the heading if the section was non-empty
|
|
||||||
heading = '';
|
|
||||||
if (this._heading && this._heading !== c.SUPPRESS) {
|
|
||||||
var currentIndent = formatter.currentIndent;
|
|
||||||
heading = $$.repeat(' ', currentIndent) + this._heading + ':' + c.EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// join the section-initialize newline, the heading and the help
|
|
||||||
return formatter._joinParts([ c.EOL, heading, itemHelp, c.EOL ]);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* new HelpFormatter(options)
|
|
||||||
*
|
|
||||||
* #### Options:
|
|
||||||
* - `prog`: program name
|
|
||||||
* - `indentIncriment`: indent step, default value 2
|
|
||||||
* - `maxHelpPosition`: max help position, default value = 24
|
|
||||||
* - `width`: line width
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
var HelpFormatter = module.exports = function HelpFormatter(options) {
|
|
||||||
options = options || {};
|
|
||||||
|
|
||||||
this._prog = options.prog;
|
|
||||||
|
|
||||||
this._maxHelpPosition = options.maxHelpPosition || 24;
|
|
||||||
this._width = (options.width || ((process.env.COLUMNS || 80) - 2));
|
|
||||||
|
|
||||||
this._currentIndent = 0;
|
|
||||||
this._indentIncriment = options.indentIncriment || 2;
|
|
||||||
this._level = 0;
|
|
||||||
this._actionMaxLength = 0;
|
|
||||||
|
|
||||||
this._rootSection = new Section(null);
|
|
||||||
this._currentSection = this._rootSection;
|
|
||||||
|
|
||||||
this._whitespaceMatcher = new RegExp('\\s+', 'g');
|
|
||||||
this._longBreakMatcher = new RegExp(c.EOL + c.EOL + c.EOL + '+', 'g');
|
|
||||||
};
|
|
||||||
|
|
||||||
HelpFormatter.prototype._indent = function () {
|
|
||||||
this._currentIndent += this._indentIncriment;
|
|
||||||
this._level += 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
HelpFormatter.prototype._dedent = function () {
|
|
||||||
this._currentIndent -= this._indentIncriment;
|
|
||||||
this._level -= 1;
|
|
||||||
if (this._currentIndent < 0) {
|
|
||||||
throw new Error('Indent decreased below 0.');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
HelpFormatter.prototype._addItem = function (func, args) {
|
|
||||||
this._currentSection.addItem([ func, args ]);
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// Message building methods
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HelpFormatter#startSection(heading) -> Void
|
|
||||||
* - heading (string): header string
|
|
||||||
*
|
|
||||||
* Start new help section
|
|
||||||
*
|
|
||||||
* See alse [code example][1]
|
|
||||||
*
|
|
||||||
* ##### Example
|
|
||||||
*
|
|
||||||
* formatter.startSection(actionGroup.title);
|
|
||||||
* formatter.addText(actionGroup.description);
|
|
||||||
* formatter.addArguments(actionGroup._groupActions);
|
|
||||||
* formatter.endSection();
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
HelpFormatter.prototype.startSection = function (heading) {
|
|
||||||
this._indent();
|
|
||||||
var section = new Section(this._currentSection, heading);
|
|
||||||
var func = section.formatHelp.bind(section);
|
|
||||||
this._addItem(func, [ this ]);
|
|
||||||
this._currentSection = section;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HelpFormatter#endSection -> Void
|
|
||||||
*
|
|
||||||
* End help section
|
|
||||||
*
|
|
||||||
* ##### Example
|
|
||||||
*
|
|
||||||
* formatter.startSection(actionGroup.title);
|
|
||||||
* formatter.addText(actionGroup.description);
|
|
||||||
* formatter.addArguments(actionGroup._groupActions);
|
|
||||||
* formatter.endSection();
|
|
||||||
**/
|
|
||||||
HelpFormatter.prototype.endSection = function () {
|
|
||||||
this._currentSection = this._currentSection._parent;
|
|
||||||
this._dedent();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HelpFormatter#addText(text) -> Void
|
|
||||||
* - text (string): plain text
|
|
||||||
*
|
|
||||||
* Add plain text into current section
|
|
||||||
*
|
|
||||||
* ##### Example
|
|
||||||
*
|
|
||||||
* formatter.startSection(actionGroup.title);
|
|
||||||
* formatter.addText(actionGroup.description);
|
|
||||||
* formatter.addArguments(actionGroup._groupActions);
|
|
||||||
* formatter.endSection();
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
HelpFormatter.prototype.addText = function (text) {
|
|
||||||
if (text && text !== c.SUPPRESS) {
|
|
||||||
this._addItem(this._formatText, [ text ]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HelpFormatter#addUsage(usage, actions, groups, prefix) -> Void
|
|
||||||
* - usage (string): usage text
|
|
||||||
* - actions (array): actions list
|
|
||||||
* - groups (array): groups list
|
|
||||||
* - prefix (string): usage prefix
|
|
||||||
*
|
|
||||||
* Add usage data into current section
|
|
||||||
*
|
|
||||||
* ##### Example
|
|
||||||
*
|
|
||||||
* formatter.addUsage(this.usage, this._actions, []);
|
|
||||||
* return formatter.formatHelp();
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
HelpFormatter.prototype.addUsage = function (usage, actions, groups, prefix) {
|
|
||||||
if (usage !== c.SUPPRESS) {
|
|
||||||
this._addItem(this._formatUsage, [ usage, actions, groups, prefix ]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HelpFormatter#addArgument(action) -> Void
|
|
||||||
* - action (object): action
|
|
||||||
*
|
|
||||||
* Add argument into current section
|
|
||||||
*
|
|
||||||
* Single variant of [[HelpFormatter#addArguments]]
|
|
||||||
**/
|
|
||||||
HelpFormatter.prototype.addArgument = function (action) {
|
|
||||||
if (action.help !== c.SUPPRESS) {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
// find all invocations
|
|
||||||
var invocations = [ this._formatActionInvocation(action) ];
|
|
||||||
var invocationLength = invocations[0].length;
|
|
||||||
|
|
||||||
var actionLength;
|
|
||||||
|
|
||||||
if (action._getSubactions) {
|
|
||||||
this._indent();
|
|
||||||
action._getSubactions().forEach(function (subaction) {
|
|
||||||
|
|
||||||
var invocationNew = self._formatActionInvocation(subaction);
|
|
||||||
invocations.push(invocationNew);
|
|
||||||
invocationLength = Math.max(invocationLength, invocationNew.length);
|
|
||||||
|
|
||||||
});
|
|
||||||
this._dedent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// update the maximum item length
|
|
||||||
actionLength = invocationLength + this._currentIndent;
|
|
||||||
this._actionMaxLength = Math.max(this._actionMaxLength, actionLength);
|
|
||||||
|
|
||||||
// add the item to the list
|
|
||||||
this._addItem(this._formatAction, [ action ]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HelpFormatter#addArguments(actions) -> Void
|
|
||||||
* - actions (array): actions list
|
|
||||||
*
|
|
||||||
* Mass add arguments into current section
|
|
||||||
*
|
|
||||||
* ##### Example
|
|
||||||
*
|
|
||||||
* formatter.startSection(actionGroup.title);
|
|
||||||
* formatter.addText(actionGroup.description);
|
|
||||||
* formatter.addArguments(actionGroup._groupActions);
|
|
||||||
* formatter.endSection();
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
HelpFormatter.prototype.addArguments = function (actions) {
|
|
||||||
var self = this;
|
|
||||||
actions.forEach(function (action) {
|
|
||||||
self.addArgument(action);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// Help-formatting methods
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HelpFormatter#formatHelp -> string
|
|
||||||
*
|
|
||||||
* Format help
|
|
||||||
*
|
|
||||||
* ##### Example
|
|
||||||
*
|
|
||||||
* formatter.addText(this.epilog);
|
|
||||||
* return formatter.formatHelp();
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
HelpFormatter.prototype.formatHelp = function () {
|
|
||||||
var help = this._rootSection.formatHelp(this);
|
|
||||||
if (help) {
|
|
||||||
help = help.replace(this._longBreakMatcher, c.EOL + c.EOL);
|
|
||||||
help = $$.trimChars(help, c.EOL) + c.EOL;
|
|
||||||
}
|
|
||||||
return help;
|
|
||||||
};
|
|
||||||
|
|
||||||
HelpFormatter.prototype._joinParts = function (partStrings) {
|
|
||||||
return partStrings.filter(function (part) {
|
|
||||||
return (part && part !== c.SUPPRESS);
|
|
||||||
}).join('');
|
|
||||||
};
|
|
||||||
|
|
||||||
HelpFormatter.prototype._formatUsage = function (usage, actions, groups, prefix) {
|
|
||||||
if (!prefix && typeof prefix !== 'string') {
|
|
||||||
prefix = 'usage: ';
|
|
||||||
}
|
|
||||||
|
|
||||||
actions = actions || [];
|
|
||||||
groups = groups || [];
|
|
||||||
|
|
||||||
|
|
||||||
// if usage is specified, use that
|
|
||||||
if (usage) {
|
|
||||||
usage = sprintf(usage, { prog: this._prog });
|
|
||||||
|
|
||||||
// if no optionals or positionals are available, usage is just prog
|
|
||||||
} else if (!usage && actions.length === 0) {
|
|
||||||
usage = this._prog;
|
|
||||||
|
|
||||||
// if optionals and positionals are available, calculate usage
|
|
||||||
} else if (!usage) {
|
|
||||||
var prog = this._prog;
|
|
||||||
var optionals = [];
|
|
||||||
var positionals = [];
|
|
||||||
var actionUsage;
|
|
||||||
var textWidth;
|
|
||||||
|
|
||||||
// split optionals from positionals
|
|
||||||
actions.forEach(function (action) {
|
|
||||||
if (action.isOptional()) {
|
|
||||||
optionals.push(action);
|
|
||||||
} else {
|
|
||||||
positionals.push(action);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// build full usage string
|
|
||||||
actionUsage = this._formatActionsUsage([].concat(optionals, positionals), groups);
|
|
||||||
usage = [ prog, actionUsage ].join(' ');
|
|
||||||
|
|
||||||
// wrap the usage parts if it's too long
|
|
||||||
textWidth = this._width - this._currentIndent;
|
|
||||||
if ((prefix.length + usage.length) > textWidth) {
|
|
||||||
|
|
||||||
// break usage into wrappable parts
|
|
||||||
var regexpPart = new RegExp('\\(.*?\\)+|\\[.*?\\]+|\\S+', 'g');
|
|
||||||
var optionalUsage = this._formatActionsUsage(optionals, groups);
|
|
||||||
var positionalUsage = this._formatActionsUsage(positionals, groups);
|
|
||||||
|
|
||||||
|
|
||||||
var optionalParts = optionalUsage.match(regexpPart);
|
|
||||||
var positionalParts = positionalUsage.match(regexpPart) || [];
|
|
||||||
|
|
||||||
if (optionalParts.join(' ') !== optionalUsage) {
|
|
||||||
throw new Error('assert "optionalParts.join(\' \') === optionalUsage"');
|
|
||||||
}
|
|
||||||
if (positionalParts.join(' ') !== positionalUsage) {
|
|
||||||
throw new Error('assert "positionalParts.join(\' \') === positionalUsage"');
|
|
||||||
}
|
|
||||||
|
|
||||||
// helper for wrapping lines
|
|
||||||
/*eslint-disable func-style*/ // node 0.10 compat
|
|
||||||
var _getLines = function (parts, indent, prefix) {
|
|
||||||
var lines = [];
|
|
||||||
var line = [];
|
|
||||||
|
|
||||||
var lineLength = prefix ? prefix.length - 1 : indent.length - 1;
|
|
||||||
|
|
||||||
parts.forEach(function (part) {
|
|
||||||
if (lineLength + 1 + part.length > textWidth) {
|
|
||||||
lines.push(indent + line.join(' '));
|
|
||||||
line = [];
|
|
||||||
lineLength = indent.length - 1;
|
|
||||||
}
|
|
||||||
line.push(part);
|
|
||||||
lineLength += part.length + 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (line) {
|
|
||||||
lines.push(indent + line.join(' '));
|
|
||||||
}
|
|
||||||
if (prefix) {
|
|
||||||
lines[0] = lines[0].substr(indent.length);
|
|
||||||
}
|
|
||||||
return lines;
|
|
||||||
};
|
|
||||||
|
|
||||||
var lines, indent, parts;
|
|
||||||
// if prog is short, follow it with optionals or positionals
|
|
||||||
if (prefix.length + prog.length <= 0.75 * textWidth) {
|
|
||||||
indent = $$.repeat(' ', (prefix.length + prog.length + 1));
|
|
||||||
if (optionalParts) {
|
|
||||||
lines = [].concat(
|
|
||||||
_getLines([ prog ].concat(optionalParts), indent, prefix),
|
|
||||||
_getLines(positionalParts, indent)
|
|
||||||
);
|
|
||||||
} else if (positionalParts) {
|
|
||||||
lines = _getLines([ prog ].concat(positionalParts), indent, prefix);
|
|
||||||
} else {
|
|
||||||
lines = [ prog ];
|
|
||||||
}
|
|
||||||
|
|
||||||
// if prog is long, put it on its own line
|
|
||||||
} else {
|
|
||||||
indent = $$.repeat(' ', prefix.length);
|
|
||||||
parts = optionalParts.concat(positionalParts);
|
|
||||||
lines = _getLines(parts, indent);
|
|
||||||
if (lines.length > 1) {
|
|
||||||
lines = [].concat(
|
|
||||||
_getLines(optionalParts, indent),
|
|
||||||
_getLines(positionalParts, indent)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
lines = [ prog ].concat(lines);
|
|
||||||
}
|
|
||||||
// join lines into usage
|
|
||||||
usage = lines.join(c.EOL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// prefix with 'usage:'
|
|
||||||
return prefix + usage + c.EOL + c.EOL;
|
|
||||||
};
|
|
||||||
|
|
||||||
HelpFormatter.prototype._formatActionsUsage = function (actions, groups) {
|
|
||||||
// find group indices and identify actions in groups
|
|
||||||
var groupActions = [];
|
|
||||||
var inserts = [];
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
groups.forEach(function (group) {
|
|
||||||
var end;
|
|
||||||
var i;
|
|
||||||
|
|
||||||
var start = actions.indexOf(group._groupActions[0]);
|
|
||||||
if (start >= 0) {
|
|
||||||
end = start + group._groupActions.length;
|
|
||||||
|
|
||||||
//if (actions.slice(start, end) === group._groupActions) {
|
|
||||||
if ($$.arrayEqual(actions.slice(start, end), group._groupActions)) {
|
|
||||||
group._groupActions.forEach(function (action) {
|
|
||||||
groupActions.push(action);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!group.required) {
|
|
||||||
if (inserts[start]) {
|
|
||||||
inserts[start] += ' [';
|
|
||||||
} else {
|
|
||||||
inserts[start] = '[';
|
|
||||||
}
|
|
||||||
inserts[end] = ']';
|
|
||||||
} else {
|
|
||||||
if (inserts[start]) {
|
|
||||||
inserts[start] += ' (';
|
|
||||||
} else {
|
|
||||||
inserts[start] = '(';
|
|
||||||
}
|
|
||||||
inserts[end] = ')';
|
|
||||||
}
|
|
||||||
for (i = start + 1; i < end; i += 1) {
|
|
||||||
inserts[i] = '|';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// collect all actions format strings
|
|
||||||
var parts = [];
|
|
||||||
|
|
||||||
actions.forEach(function (action, actionIndex) {
|
|
||||||
var part;
|
|
||||||
var optionString;
|
|
||||||
var argsDefault;
|
|
||||||
var argsString;
|
|
||||||
|
|
||||||
// suppressed arguments are marked with None
|
|
||||||
// remove | separators for suppressed arguments
|
|
||||||
if (action.help === c.SUPPRESS) {
|
|
||||||
parts.push(null);
|
|
||||||
if (inserts[actionIndex] === '|') {
|
|
||||||
inserts.splice(actionIndex, actionIndex);
|
|
||||||
} else if (inserts[actionIndex + 1] === '|') {
|
|
||||||
inserts.splice(actionIndex + 1, actionIndex + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// produce all arg strings
|
|
||||||
} else if (!action.isOptional()) {
|
|
||||||
part = self._formatArgs(action, action.dest);
|
|
||||||
|
|
||||||
// if it's in a group, strip the outer []
|
|
||||||
if (groupActions.indexOf(action) >= 0) {
|
|
||||||
if (part[0] === '[' && part[part.length - 1] === ']') {
|
|
||||||
part = part.slice(1, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// add the action string to the list
|
|
||||||
parts.push(part);
|
|
||||||
|
|
||||||
// produce the first way to invoke the option in brackets
|
|
||||||
} else {
|
|
||||||
optionString = action.optionStrings[0];
|
|
||||||
|
|
||||||
// if the Optional doesn't take a value, format is: -s or --long
|
|
||||||
if (action.nargs === 0) {
|
|
||||||
part = '' + optionString;
|
|
||||||
|
|
||||||
// if the Optional takes a value, format is: -s ARGS or --long ARGS
|
|
||||||
} else {
|
|
||||||
argsDefault = action.dest.toUpperCase();
|
|
||||||
argsString = self._formatArgs(action, argsDefault);
|
|
||||||
part = optionString + ' ' + argsString;
|
|
||||||
}
|
|
||||||
// make it look optional if it's not required or in a group
|
|
||||||
if (!action.required && groupActions.indexOf(action) < 0) {
|
|
||||||
part = '[' + part + ']';
|
|
||||||
}
|
|
||||||
// add the action string to the list
|
|
||||||
parts.push(part);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// insert things at the necessary indices
|
|
||||||
for (var i = inserts.length - 1; i >= 0; --i) {
|
|
||||||
if (inserts[i] !== null) {
|
|
||||||
parts.splice(i, 0, inserts[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// join all the action items with spaces
|
|
||||||
var text = parts.filter(function (part) {
|
|
||||||
return !!part;
|
|
||||||
}).join(' ');
|
|
||||||
|
|
||||||
// clean up separators for mutually exclusive groups
|
|
||||||
text = text.replace(/([\[(]) /g, '$1'); // remove spaces
|
|
||||||
text = text.replace(/ ([\])])/g, '$1');
|
|
||||||
text = text.replace(/\[ *\]/g, ''); // remove empty groups
|
|
||||||
text = text.replace(/\( *\)/g, '');
|
|
||||||
text = text.replace(/\(([^|]*)\)/g, '$1'); // remove () from single action groups
|
|
||||||
|
|
||||||
text = text.trim();
|
|
||||||
|
|
||||||
// return the text
|
|
||||||
return text;
|
|
||||||
};
|
|
||||||
|
|
||||||
HelpFormatter.prototype._formatText = function (text) {
|
|
||||||
text = sprintf(text, { prog: this._prog });
|
|
||||||
var textWidth = this._width - this._currentIndent;
|
|
||||||
var indentIncriment = $$.repeat(' ', this._currentIndent);
|
|
||||||
return this._fillText(text, textWidth, indentIncriment) + c.EOL + c.EOL;
|
|
||||||
};
|
|
||||||
|
|
||||||
HelpFormatter.prototype._formatAction = function (action) {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
var helpText;
|
|
||||||
var helpLines;
|
|
||||||
var parts;
|
|
||||||
var indentFirst;
|
|
||||||
|
|
||||||
// determine the required width and the entry label
|
|
||||||
var helpPosition = Math.min(this._actionMaxLength + 2, this._maxHelpPosition);
|
|
||||||
var helpWidth = this._width - helpPosition;
|
|
||||||
var actionWidth = helpPosition - this._currentIndent - 2;
|
|
||||||
var actionHeader = this._formatActionInvocation(action);
|
|
||||||
|
|
||||||
// no help; start on same line and add a final newline
|
|
||||||
if (!action.help) {
|
|
||||||
actionHeader = $$.repeat(' ', this._currentIndent) + actionHeader + c.EOL;
|
|
||||||
|
|
||||||
// short action name; start on the same line and pad two spaces
|
|
||||||
} else if (actionHeader.length <= actionWidth) {
|
|
||||||
actionHeader = $$.repeat(' ', this._currentIndent) +
|
|
||||||
actionHeader +
|
|
||||||
' ' +
|
|
||||||
$$.repeat(' ', actionWidth - actionHeader.length);
|
|
||||||
indentFirst = 0;
|
|
||||||
|
|
||||||
// long action name; start on the next line
|
|
||||||
} else {
|
|
||||||
actionHeader = $$.repeat(' ', this._currentIndent) + actionHeader + c.EOL;
|
|
||||||
indentFirst = helpPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
// collect the pieces of the action help
|
|
||||||
parts = [ actionHeader ];
|
|
||||||
|
|
||||||
// if there was help for the action, add lines of help text
|
|
||||||
if (action.help) {
|
|
||||||
helpText = this._expandHelp(action);
|
|
||||||
helpLines = this._splitLines(helpText, helpWidth);
|
|
||||||
parts.push($$.repeat(' ', indentFirst) + helpLines[0] + c.EOL);
|
|
||||||
helpLines.slice(1).forEach(function (line) {
|
|
||||||
parts.push($$.repeat(' ', helpPosition) + line + c.EOL);
|
|
||||||
});
|
|
||||||
|
|
||||||
// or add a newline if the description doesn't end with one
|
|
||||||
} else if (actionHeader.charAt(actionHeader.length - 1) !== c.EOL) {
|
|
||||||
parts.push(c.EOL);
|
|
||||||
}
|
|
||||||
// if there are any sub-actions, add their help as well
|
|
||||||
if (action._getSubactions) {
|
|
||||||
this._indent();
|
|
||||||
action._getSubactions().forEach(function (subaction) {
|
|
||||||
parts.push(self._formatAction(subaction));
|
|
||||||
});
|
|
||||||
this._dedent();
|
|
||||||
}
|
|
||||||
// return a single string
|
|
||||||
return this._joinParts(parts);
|
|
||||||
};
|
|
||||||
|
|
||||||
HelpFormatter.prototype._formatActionInvocation = function (action) {
|
|
||||||
if (!action.isOptional()) {
|
|
||||||
var format_func = this._metavarFormatter(action, action.dest);
|
|
||||||
var metavars = format_func(1);
|
|
||||||
return metavars[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
var parts = [];
|
|
||||||
var argsDefault;
|
|
||||||
var argsString;
|
|
||||||
|
|
||||||
// if the Optional doesn't take a value, format is: -s, --long
|
|
||||||
if (action.nargs === 0) {
|
|
||||||
parts = parts.concat(action.optionStrings);
|
|
||||||
|
|
||||||
// if the Optional takes a value, format is: -s ARGS, --long ARGS
|
|
||||||
} else {
|
|
||||||
argsDefault = action.dest.toUpperCase();
|
|
||||||
argsString = this._formatArgs(action, argsDefault);
|
|
||||||
action.optionStrings.forEach(function (optionString) {
|
|
||||||
parts.push(optionString + ' ' + argsString);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return parts.join(', ');
|
|
||||||
};
|
|
||||||
|
|
||||||
HelpFormatter.prototype._metavarFormatter = function (action, metavarDefault) {
|
|
||||||
var result;
|
|
||||||
|
|
||||||
if (action.metavar || action.metavar === '') {
|
|
||||||
result = action.metavar;
|
|
||||||
} else if (action.choices) {
|
|
||||||
var choices = action.choices;
|
|
||||||
|
|
||||||
if (typeof choices === 'string') {
|
|
||||||
choices = choices.split('').join(', ');
|
|
||||||
} else if (Array.isArray(choices)) {
|
|
||||||
choices = choices.join(',');
|
|
||||||
} else {
|
|
||||||
choices = Object.keys(choices).join(',');
|
|
||||||
}
|
|
||||||
result = '{' + choices + '}';
|
|
||||||
} else {
|
|
||||||
result = metavarDefault;
|
|
||||||
}
|
|
||||||
|
|
||||||
return function (size) {
|
|
||||||
if (Array.isArray(result)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var metavars = [];
|
|
||||||
for (var i = 0; i < size; i += 1) {
|
|
||||||
metavars.push(result);
|
|
||||||
}
|
|
||||||
return metavars;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
HelpFormatter.prototype._formatArgs = function (action, metavarDefault) {
|
|
||||||
var result;
|
|
||||||
var metavars;
|
|
||||||
|
|
||||||
var buildMetavar = this._metavarFormatter(action, metavarDefault);
|
|
||||||
|
|
||||||
switch (action.nargs) {
|
|
||||||
/*eslint-disable no-undefined*/
|
|
||||||
case undefined:
|
|
||||||
case null:
|
|
||||||
metavars = buildMetavar(1);
|
|
||||||
result = '' + metavars[0];
|
|
||||||
break;
|
|
||||||
case c.OPTIONAL:
|
|
||||||
metavars = buildMetavar(1);
|
|
||||||
result = '[' + metavars[0] + ']';
|
|
||||||
break;
|
|
||||||
case c.ZERO_OR_MORE:
|
|
||||||
metavars = buildMetavar(2);
|
|
||||||
result = '[' + metavars[0] + ' [' + metavars[1] + ' ...]]';
|
|
||||||
break;
|
|
||||||
case c.ONE_OR_MORE:
|
|
||||||
metavars = buildMetavar(2);
|
|
||||||
result = '' + metavars[0] + ' [' + metavars[1] + ' ...]';
|
|
||||||
break;
|
|
||||||
case c.REMAINDER:
|
|
||||||
result = '...';
|
|
||||||
break;
|
|
||||||
case c.PARSER:
|
|
||||||
metavars = buildMetavar(1);
|
|
||||||
result = metavars[0] + ' ...';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
metavars = buildMetavar(action.nargs);
|
|
||||||
result = metavars.join(' ');
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
HelpFormatter.prototype._expandHelp = function (action) {
|
|
||||||
var params = { prog: this._prog };
|
|
||||||
|
|
||||||
Object.keys(action).forEach(function (actionProperty) {
|
|
||||||
var actionValue = action[actionProperty];
|
|
||||||
|
|
||||||
if (actionValue !== c.SUPPRESS) {
|
|
||||||
params[actionProperty] = actionValue;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (params.choices) {
|
|
||||||
if (typeof params.choices === 'string') {
|
|
||||||
params.choices = params.choices.split('').join(', ');
|
|
||||||
} else if (Array.isArray(params.choices)) {
|
|
||||||
params.choices = params.choices.join(', ');
|
|
||||||
} else {
|
|
||||||
params.choices = Object.keys(params.choices).join(', ');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sprintf(this._getHelpString(action), params);
|
|
||||||
};
|
|
||||||
|
|
||||||
HelpFormatter.prototype._splitLines = function (text, width) {
|
|
||||||
var lines = [];
|
|
||||||
var delimiters = [ ' ', '.', ',', '!', '?' ];
|
|
||||||
var re = new RegExp('[' + delimiters.join('') + '][^' + delimiters.join('') + ']*$');
|
|
||||||
|
|
||||||
text = text.replace(/[\n\|\t]/g, ' ');
|
|
||||||
|
|
||||||
text = text.trim();
|
|
||||||
text = text.replace(this._whitespaceMatcher, ' ');
|
|
||||||
|
|
||||||
// Wraps the single paragraph in text (a string) so every line
|
|
||||||
// is at most width characters long.
|
|
||||||
text.split(c.EOL).forEach(function (line) {
|
|
||||||
if (width >= line.length) {
|
|
||||||
lines.push(line);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var wrapStart = 0;
|
|
||||||
var wrapEnd = width;
|
|
||||||
var delimiterIndex = 0;
|
|
||||||
while (wrapEnd <= line.length) {
|
|
||||||
if (wrapEnd !== line.length && delimiters.indexOf(line[wrapEnd] < -1)) {
|
|
||||||
delimiterIndex = (re.exec(line.substring(wrapStart, wrapEnd)) || {}).index;
|
|
||||||
wrapEnd = wrapStart + delimiterIndex + 1;
|
|
||||||
}
|
|
||||||
lines.push(line.substring(wrapStart, wrapEnd));
|
|
||||||
wrapStart = wrapEnd;
|
|
||||||
wrapEnd += width;
|
|
||||||
}
|
|
||||||
if (wrapStart < line.length) {
|
|
||||||
lines.push(line.substring(wrapStart, wrapEnd));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return lines;
|
|
||||||
};
|
|
||||||
|
|
||||||
HelpFormatter.prototype._fillText = function (text, width, indent) {
|
|
||||||
var lines = this._splitLines(text, width);
|
|
||||||
lines = lines.map(function (line) {
|
|
||||||
return indent + line;
|
|
||||||
});
|
|
||||||
return lines.join(c.EOL);
|
|
||||||
};
|
|
||||||
|
|
||||||
HelpFormatter.prototype._getHelpString = function (action) {
|
|
||||||
return action.help;
|
|
||||||
};
|
|
@ -1,76 +0,0 @@
|
|||||||
/**
|
|
||||||
* class Namespace
|
|
||||||
*
|
|
||||||
* Simple object for storing attributes. Implements equality by attribute names
|
|
||||||
* and values, and provides a simple string representation.
|
|
||||||
*
|
|
||||||
* See also [original guide][1]
|
|
||||||
*
|
|
||||||
* [1]:http://docs.python.org/dev/library/argparse.html#the-namespace-object
|
|
||||||
**/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var $$ = require('./utils');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* new Namespace(options)
|
|
||||||
* - options(object): predefined propertis for result object
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
var Namespace = module.exports = function Namespace(options) {
|
|
||||||
$$.extend(this, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Namespace#isset(key) -> Boolean
|
|
||||||
* - key (string|number): property name
|
|
||||||
*
|
|
||||||
* Tells whenever `namespace` contains given `key` or not.
|
|
||||||
**/
|
|
||||||
Namespace.prototype.isset = function (key) {
|
|
||||||
return $$.has(this, key);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Namespace#set(key, value) -> self
|
|
||||||
* -key (string|number|object): propery name
|
|
||||||
* -value (mixed): new property value
|
|
||||||
*
|
|
||||||
* Set the property named key with value.
|
|
||||||
* If key object then set all key properties to namespace object
|
|
||||||
**/
|
|
||||||
Namespace.prototype.set = function (key, value) {
|
|
||||||
if (typeof (key) === 'object') {
|
|
||||||
$$.extend(this, key);
|
|
||||||
} else {
|
|
||||||
this[key] = value;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Namespace#get(key, defaultValue) -> mixed
|
|
||||||
* - key (string|number): property name
|
|
||||||
* - defaultValue (mixed): default value
|
|
||||||
*
|
|
||||||
* Return the property key or defaulValue if not set
|
|
||||||
**/
|
|
||||||
Namespace.prototype.get = function (key, defaultValue) {
|
|
||||||
return !this[key] ? defaultValue : this[key];
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Namespace#unset(key, defaultValue) -> mixed
|
|
||||||
* - key (string|number): property name
|
|
||||||
* - defaultValue (mixed): default value
|
|
||||||
*
|
|
||||||
* Return data[key](and delete it) or defaultValue
|
|
||||||
**/
|
|
||||||
Namespace.prototype.unset = function (key, defaultValue) {
|
|
||||||
var value = this[key];
|
|
||||||
if (value !== null) {
|
|
||||||
delete this[key];
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
};
|
|
@ -1,57 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
exports.repeat = function (str, num) {
|
|
||||||
var result = '';
|
|
||||||
for (var i = 0; i < num; i++) { result += str; }
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.arrayEqual = function (a, b) {
|
|
||||||
if (a.length !== b.length) { return false; }
|
|
||||||
for (var i = 0; i < a.length; i++) {
|
|
||||||
if (a[i] !== b[i]) { return false; }
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.trimChars = function (str, chars) {
|
|
||||||
var start = 0;
|
|
||||||
var end = str.length - 1;
|
|
||||||
while (chars.indexOf(str.charAt(start)) >= 0) { start++; }
|
|
||||||
while (chars.indexOf(str.charAt(end)) >= 0) { end--; }
|
|
||||||
return str.slice(start, end + 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.capitalize = function (str) {
|
|
||||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.arrayUnion = function () {
|
|
||||||
var result = [];
|
|
||||||
for (var i = 0, values = {}; i < arguments.length; i++) {
|
|
||||||
var arr = arguments[i];
|
|
||||||
for (var j = 0; j < arr.length; j++) {
|
|
||||||
if (!values[arr[j]]) {
|
|
||||||
values[arr[j]] = true;
|
|
||||||
result.push(arr[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
function has(obj, key) {
|
|
||||||
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.has = has;
|
|
||||||
|
|
||||||
exports.extend = function (dest, src) {
|
|
||||||
for (var i in src) {
|
|
||||||
if (has(src, i)) { dest[i] = src[i]; }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.trimEnd = function (str) {
|
|
||||||
return str.replace(/\s+$/g, '');
|
|
||||||
};
|
|
@ -1,70 +0,0 @@
|
|||||||
{
|
|
||||||
"_from": "argparse@^1.0.7",
|
|
||||||
"_id": "argparse@1.0.10",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
|
|
||||||
"_location": "/argparse",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "range",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "argparse@^1.0.7",
|
|
||||||
"name": "argparse",
|
|
||||||
"escapedName": "argparse",
|
|
||||||
"rawSpec": "^1.0.7",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "^1.0.7"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/yamljs"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
|
|
||||||
"_shasum": "bcd6791ea5ae09725e17e5ad988134cd40b3d911",
|
|
||||||
"_spec": "argparse@^1.0.7",
|
|
||||||
"_where": "/Users/paolo/Desktop/multiplayer games/likelike-online/node_modules/yamljs",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/nodeca/argparse/issues"
|
|
||||||
},
|
|
||||||
"bundleDependencies": false,
|
|
||||||
"contributors": [
|
|
||||||
{
|
|
||||||
"name": "Eugene Shkuropat"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Paul Jacobson"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"dependencies": {
|
|
||||||
"sprintf-js": "~1.0.2"
|
|
||||||
},
|
|
||||||
"deprecated": false,
|
|
||||||
"description": "Very powerful CLI arguments parser. Native port of argparse - python's options parsing library",
|
|
||||||
"devDependencies": {
|
|
||||||
"eslint": "^2.13.1",
|
|
||||||
"istanbul": "^0.4.5",
|
|
||||||
"mocha": "^3.1.0",
|
|
||||||
"ndoc": "^5.0.1"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"index.js",
|
|
||||||
"lib/"
|
|
||||||
],
|
|
||||||
"homepage": "https://github.com/nodeca/argparse#readme",
|
|
||||||
"keywords": [
|
|
||||||
"cli",
|
|
||||||
"parser",
|
|
||||||
"argparse",
|
|
||||||
"option",
|
|
||||||
"args"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"name": "argparse",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/nodeca/argparse.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "make test"
|
|
||||||
},
|
|
||||||
"version": "1.0.10"
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com)
|
|
||||||
|
|
||||||
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:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
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.
|
|
@ -1,43 +0,0 @@
|
|||||||
# Array Flatten
|
|
||||||
|
|
||||||
[![NPM version][npm-image]][npm-url]
|
|
||||||
[![NPM downloads][downloads-image]][downloads-url]
|
|
||||||
[![Build status][travis-image]][travis-url]
|
|
||||||
[![Test coverage][coveralls-image]][coveralls-url]
|
|
||||||
|
|
||||||
> Flatten an array of nested arrays into a single flat array. Accepts an optional depth.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```
|
|
||||||
npm install array-flatten --save
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var flatten = require('array-flatten')
|
|
||||||
|
|
||||||
flatten([1, [2, [3, [4, [5], 6], 7], 8], 9])
|
|
||||||
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
||||||
|
|
||||||
flatten([1, [2, [3, [4, [5], 6], 7], 8], 9], 2)
|
|
||||||
//=> [1, 2, 3, [4, [5], 6], 7, 8, 9]
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
flatten(arguments) //=> [1, 2, 3]
|
|
||||||
})(1, [2, 3])
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
MIT
|
|
||||||
|
|
||||||
[npm-image]: https://img.shields.io/npm/v/array-flatten.svg?style=flat
|
|
||||||
[npm-url]: https://npmjs.org/package/array-flatten
|
|
||||||
[downloads-image]: https://img.shields.io/npm/dm/array-flatten.svg?style=flat
|
|
||||||
[downloads-url]: https://npmjs.org/package/array-flatten
|
|
||||||
[travis-image]: https://img.shields.io/travis/blakeembrey/array-flatten.svg?style=flat
|
|
||||||
[travis-url]: https://travis-ci.org/blakeembrey/array-flatten
|
|
||||||
[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/array-flatten.svg?style=flat
|
|
||||||
[coveralls-url]: https://coveralls.io/r/blakeembrey/array-flatten?branch=master
|
|
@ -1,64 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Expose `arrayFlatten`.
|
|
||||||
*/
|
|
||||||
module.exports = arrayFlatten
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Recursive flatten function with depth.
|
|
||||||
*
|
|
||||||
* @param {Array} array
|
|
||||||
* @param {Array} result
|
|
||||||
* @param {Number} depth
|
|
||||||
* @return {Array}
|
|
||||||
*/
|
|
||||||
function flattenWithDepth (array, result, depth) {
|
|
||||||
for (var i = 0; i < array.length; i++) {
|
|
||||||
var value = array[i]
|
|
||||||
|
|
||||||
if (depth > 0 && Array.isArray(value)) {
|
|
||||||
flattenWithDepth(value, result, depth - 1)
|
|
||||||
} else {
|
|
||||||
result.push(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Recursive flatten function. Omitting depth is slightly faster.
|
|
||||||
*
|
|
||||||
* @param {Array} array
|
|
||||||
* @param {Array} result
|
|
||||||
* @return {Array}
|
|
||||||
*/
|
|
||||||
function flattenForever (array, result) {
|
|
||||||
for (var i = 0; i < array.length; i++) {
|
|
||||||
var value = array[i]
|
|
||||||
|
|
||||||
if (Array.isArray(value)) {
|
|
||||||
flattenForever(value, result)
|
|
||||||
} else {
|
|
||||||
result.push(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flatten an array, with the ability to define a depth.
|
|
||||||
*
|
|
||||||
* @param {Array} array
|
|
||||||
* @param {Number} depth
|
|
||||||
* @return {Array}
|
|
||||||
*/
|
|
||||||
function arrayFlatten (array, depth) {
|
|
||||||
if (depth == null) {
|
|
||||||
return flattenForever(array, [])
|
|
||||||
}
|
|
||||||
|
|
||||||
return flattenWithDepth(array, [], depth)
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
{
|
|
||||||
"_from": "array-flatten@1.1.1",
|
|
||||||
"_id": "array-flatten@1.1.1",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=",
|
|
||||||
"_location": "/array-flatten",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "version",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "array-flatten@1.1.1",
|
|
||||||
"name": "array-flatten",
|
|
||||||
"escapedName": "array-flatten",
|
|
||||||
"rawSpec": "1.1.1",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "1.1.1"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/express"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
|
|
||||||
"_shasum": "9a5f699051b1e7073328f2a008968b64ea2955d2",
|
|
||||||
"_spec": "array-flatten@1.1.1",
|
|
||||||
"_where": "/Users/paolo/Desktop/multiplayer games/tutorials/hellosocket/node_modules/express",
|
|
||||||
"author": {
|
|
||||||
"name": "Blake Embrey",
|
|
||||||
"email": "hello@blakeembrey.com",
|
|
||||||
"url": "http://blakeembrey.me"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/blakeembrey/array-flatten/issues"
|
|
||||||
},
|
|
||||||
"bundleDependencies": false,
|
|
||||||
"deprecated": false,
|
|
||||||
"description": "Flatten an array of nested arrays into a single flat array",
|
|
||||||
"devDependencies": {
|
|
||||||
"istanbul": "^0.3.13",
|
|
||||||
"mocha": "^2.2.4",
|
|
||||||
"pre-commit": "^1.0.7",
|
|
||||||
"standard": "^3.7.3"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"array-flatten.js",
|
|
||||||
"LICENSE"
|
|
||||||
],
|
|
||||||
"homepage": "https://github.com/blakeembrey/array-flatten",
|
|
||||||
"keywords": [
|
|
||||||
"array",
|
|
||||||
"flatten",
|
|
||||||
"arguments",
|
|
||||||
"depth"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"main": "array-flatten.js",
|
|
||||||
"name": "array-flatten",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/blakeembrey/array-flatten.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "istanbul cover _mocha -- -R spec"
|
|
||||||
},
|
|
||||||
"version": "1.1.1"
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
lib-cov
|
|
||||||
lcov.info
|
|
||||||
*.seed
|
|
||||||
*.log
|
|
||||||
*.csv
|
|
||||||
*.dat
|
|
||||||
*.out
|
|
||||||
*.pid
|
|
||||||
*.gz
|
|
||||||
|
|
||||||
pids
|
|
||||||
logs
|
|
||||||
results
|
|
||||||
build
|
|
||||||
.grunt
|
|
||||||
|
|
||||||
node_modules
|
|
@ -1,18 +0,0 @@
|
|||||||
Copyright (C) 2013 Rase-
|
|
||||||
|
|
||||||
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:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
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.
|
|
@ -1,8 +0,0 @@
|
|||||||
|
|
||||||
REPORTER = dot
|
|
||||||
|
|
||||||
test:
|
|
||||||
@./node_modules/.bin/mocha \
|
|
||||||
--reporter $(REPORTER)
|
|
||||||
|
|
||||||
.PHONY: test
|
|
@ -1,17 +0,0 @@
|
|||||||
# How to
|
|
||||||
```javascript
|
|
||||||
var sliceBuffer = require('arraybuffer.slice');
|
|
||||||
var ab = (new Int8Array(5)).buffer;
|
|
||||||
var sliced = sliceBuffer(ab, 1, 3);
|
|
||||||
sliced = sliceBuffer(ab, 1);
|
|
||||||
```
|
|
||||||
|
|
||||||
# Licence (MIT)
|
|
||||||
Copyright (C) 2013 Rase-
|
|
||||||
|
|
||||||
|
|
||||||
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:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
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.
|
|
@ -1,29 +0,0 @@
|
|||||||
/**
|
|
||||||
* An abstraction for slicing an arraybuffer even when
|
|
||||||
* ArrayBuffer.prototype.slice is not supported
|
|
||||||
*
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = function(arraybuffer, start, end) {
|
|
||||||
var bytes = arraybuffer.byteLength;
|
|
||||||
start = start || 0;
|
|
||||||
end = end || bytes;
|
|
||||||
|
|
||||||
if (arraybuffer.slice) { return arraybuffer.slice(start, end); }
|
|
||||||
|
|
||||||
if (start < 0) { start += bytes; }
|
|
||||||
if (end < 0) { end += bytes; }
|
|
||||||
if (end > bytes) { end = bytes; }
|
|
||||||
|
|
||||||
if (start >= bytes || start >= end || bytes === 0) {
|
|
||||||
return new ArrayBuffer(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
var abv = new Uint8Array(arraybuffer);
|
|
||||||
var result = new Uint8Array(end - start);
|
|
||||||
for (var i = start, ii = 0; i < end; i++, ii++) {
|
|
||||||
result[ii] = abv[i];
|
|
||||||
}
|
|
||||||
return result.buffer;
|
|
||||||
};
|
|
@ -1,44 +0,0 @@
|
|||||||
{
|
|
||||||
"_from": "arraybuffer.slice@~0.0.7",
|
|
||||||
"_id": "arraybuffer.slice@0.0.7",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha512-wGUIVQXuehL5TCqQun8OW81jGzAWycqzFF8lFp+GOM5BXLYj3bKNsYC4daB7n6XjCqxQA/qgTJ+8ANR3acjrog==",
|
|
||||||
"_location": "/arraybuffer.slice",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "range",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "arraybuffer.slice@~0.0.7",
|
|
||||||
"name": "arraybuffer.slice",
|
|
||||||
"escapedName": "arraybuffer.slice",
|
|
||||||
"rawSpec": "~0.0.7",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "~0.0.7"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/engine.io-parser"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/arraybuffer.slice/-/arraybuffer.slice-0.0.7.tgz",
|
|
||||||
"_shasum": "3bbc4275dd584cc1b10809b89d4e8b63a69e7675",
|
|
||||||
"_spec": "arraybuffer.slice@~0.0.7",
|
|
||||||
"_where": "/Users/paolo/Desktop/multiplayer games/tutorials/hellosocket/node_modules/engine.io-parser",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/rase-/arraybuffer.slice/issues"
|
|
||||||
},
|
|
||||||
"bundleDependencies": false,
|
|
||||||
"dependencies": {},
|
|
||||||
"deprecated": false,
|
|
||||||
"description": "Exports a function for slicing ArrayBuffers (no polyfilling)",
|
|
||||||
"devDependencies": {
|
|
||||||
"expect.js": "0.2.0",
|
|
||||||
"mocha": "1.17.1"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/rase-/arraybuffer.slice",
|
|
||||||
"license": "MIT",
|
|
||||||
"name": "arraybuffer.slice",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+ssh://git@github.com/rase-/arraybuffer.slice.git"
|
|
||||||
},
|
|
||||||
"version": "0.0.7"
|
|
||||||
}
|
|
@ -1,227 +0,0 @@
|
|||||||
/*
|
|
||||||
* Test dependencies
|
|
||||||
*/
|
|
||||||
|
|
||||||
var sliceBuffer = require('../index.js');
|
|
||||||
var expect = require('expect.js');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests
|
|
||||||
*/
|
|
||||||
|
|
||||||
describe('sliceBuffer', function() {
|
|
||||||
describe('using standard slice', function() {
|
|
||||||
it('should slice correctly with only start provided', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(abv.buffer, 3);
|
|
||||||
var sabv = new Uint8Array(sliced);
|
|
||||||
for (var i = 3, ii = 0; i < abv.length; i++, ii++) {
|
|
||||||
expect(abv[i]).to.equal(sabv[ii]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should slice correctly with start and end provided', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(abv.buffer, 3, 8);
|
|
||||||
var sabv = new Uint8Array(sliced);
|
|
||||||
for (var i = 3, ii = 0; i < 8; i++, ii++) {
|
|
||||||
expect(abv[i]).to.equal(sabv[ii]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should slice correctly with negative start', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(abv.buffer, -3);
|
|
||||||
var sabv = new Uint8Array(sliced);
|
|
||||||
for (var i = abv.length - 3, ii = 0; i < abv.length; i++, ii++) {
|
|
||||||
expect(abv[i]).to.equal(sabv[ii]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should slice correctly with negative end', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(abv.buffer, 0, -3);
|
|
||||||
var sabv = new Uint8Array(sliced);
|
|
||||||
for (var i = 0, ii = 0; i < abv.length - 3; i++, ii++) {
|
|
||||||
expect(abv[i]).to.equal(sabv[ii]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should slice correctly with negative start and end', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(abv.buffer, -6, -3);
|
|
||||||
var sabv = new Uint8Array(sliced);
|
|
||||||
for (var i = abv.length - 6, ii = 0; i < abv.length - 3; i++, ii++) {
|
|
||||||
expect(abv[i]).to.equal(sabv[ii]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should slice correctly with equal start and end', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(abv.buffer, 1, 1);
|
|
||||||
expect(sliced.byteLength).to.equal(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should slice correctly when end larger than buffer', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(abv.buffer, 0, 100);
|
|
||||||
expect(new Uint8Array(sliced)).to.eql(abv);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('shoud slice correctly when start larger than end', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(abv.buffer, 6, 5);
|
|
||||||
expect(sliced.byteLength).to.equal(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('using fallback', function() {
|
|
||||||
it('should slice correctly with only start provided', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
var ab = abv.buffer;
|
|
||||||
ab.slice = undefined;
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(ab, 3);
|
|
||||||
var sabv = new Uint8Array(sliced);
|
|
||||||
for (var i = 3, ii = 0; i < abv.length; i++, ii++) {
|
|
||||||
expect(abv[i]).to.equal(sabv[ii]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should slice correctly with start and end provided', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
var ab = abv.buffer;
|
|
||||||
ab.slice = undefined;
|
|
||||||
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(ab, 3, 8);
|
|
||||||
var sabv = new Uint8Array(sliced);
|
|
||||||
for (var i = 3, ii = 0; i < 8; i++, ii++) {
|
|
||||||
expect(abv[i]).to.equal(sabv[ii]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should slice correctly with negative start', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
var ab = abv.buffer;
|
|
||||||
ab.slice = undefined;
|
|
||||||
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(ab, -3);
|
|
||||||
var sabv = new Uint8Array(sliced);
|
|
||||||
for (var i = abv.length - 3, ii = 0; i < abv.length; i++, ii++) {
|
|
||||||
expect(abv[i]).to.equal(sabv[ii]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should slice correctly with negative end', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
var ab = abv.buffer;
|
|
||||||
ab.slice = undefined;
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(ab, 0, -3);
|
|
||||||
var sabv = new Uint8Array(sliced);
|
|
||||||
for (var i = 0, ii = 0; i < abv.length - 3; i++, ii++) {
|
|
||||||
expect(abv[i]).to.equal(sabv[ii]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should slice correctly with negative start and end', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
var ab = abv.buffer;
|
|
||||||
ab.slice = undefined;
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(ab, -6, -3);
|
|
||||||
var sabv = new Uint8Array(sliced);
|
|
||||||
for (var i = abv.length - 6, ii = 0; i < abv.length - 3; i++, ii++) {
|
|
||||||
expect(abv[i]).to.equal(sabv[ii]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should slice correctly with equal start and end', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
var ab = abv.buffer;
|
|
||||||
ab.slice = undefined;
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(ab, 1, 1);
|
|
||||||
expect(sliced.byteLength).to.equal(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should slice correctly when end larger than buffer', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
var ab = abv.buffer;
|
|
||||||
ab.slice = undefined;
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(ab, 0, 100);
|
|
||||||
var sabv = new Uint8Array(sliced);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
expect(abv[i]).to.equal(sabv[i]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('shoud slice correctly when start larger than end', function() {
|
|
||||||
var abv = new Uint8Array(10);
|
|
||||||
for (var i = 0; i < abv.length; i++) {
|
|
||||||
abv[i] = i;
|
|
||||||
}
|
|
||||||
var ab = abv.buffer;
|
|
||||||
ab.slice = undefined;
|
|
||||||
|
|
||||||
var sliced = sliceBuffer(ab, 6, 5);
|
|
||||||
expect(sliced.byteLength).to.equal(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,2 +0,0 @@
|
|||||||
coverage
|
|
||||||
.nyc_output
|
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"check-coverage": false,
|
|
||||||
"lines": 99,
|
|
||||||
"statements": 99,
|
|
||||||
"functions": 99,
|
|
||||||
"branches": 99,
|
|
||||||
"include": [
|
|
||||||
"index.js"
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- "6"
|
|
||||||
- "8"
|
|
||||||
- "10"
|
|
||||||
- "node"
|
|
||||||
script: npm run travis
|
|
||||||
cache:
|
|
||||||
yarn: true
|
|
@ -1,8 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
Copyright (c) 2017 Samuel Reed <samuel.trace.reed@gmail.com>
|
|
||||||
|
|
||||||
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:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
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.
|
|
@ -1,67 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
function Queue(options) {
|
|
||||||
if (!(this instanceof Queue)) {
|
|
||||||
return new Queue(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
options = options || {};
|
|
||||||
this.concurrency = options.concurrency || Infinity;
|
|
||||||
this.pending = 0;
|
|
||||||
this.jobs = [];
|
|
||||||
this.cbs = [];
|
|
||||||
this._done = done.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
var arrayAddMethods = [
|
|
||||||
'push',
|
|
||||||
'unshift',
|
|
||||||
'splice'
|
|
||||||
];
|
|
||||||
|
|
||||||
arrayAddMethods.forEach(function(method) {
|
|
||||||
Queue.prototype[method] = function() {
|
|
||||||
var methodResult = Array.prototype[method].apply(this.jobs, arguments);
|
|
||||||
this._run();
|
|
||||||
return methodResult;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.defineProperty(Queue.prototype, 'length', {
|
|
||||||
get: function() {
|
|
||||||
return this.pending + this.jobs.length;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Queue.prototype._run = function() {
|
|
||||||
if (this.pending === this.concurrency) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.jobs.length) {
|
|
||||||
var job = this.jobs.shift();
|
|
||||||
this.pending++;
|
|
||||||
job(this._done);
|
|
||||||
this._run();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.pending === 0) {
|
|
||||||
while (this.cbs.length !== 0) {
|
|
||||||
var cb = this.cbs.pop();
|
|
||||||
process.nextTick(cb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Queue.prototype.onDone = function(cb) {
|
|
||||||
if (typeof cb === 'function') {
|
|
||||||
this.cbs.push(cb);
|
|
||||||
this._run();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function done() {
|
|
||||||
this.pending--;
|
|
||||||
this._run();
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Queue;
|
|
@ -1,69 +0,0 @@
|
|||||||
{
|
|
||||||
"_from": "async-limiter@~1.0.0",
|
|
||||||
"_id": "async-limiter@1.0.1",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==",
|
|
||||||
"_location": "/async-limiter",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "range",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "async-limiter@~1.0.0",
|
|
||||||
"name": "async-limiter",
|
|
||||||
"escapedName": "async-limiter",
|
|
||||||
"rawSpec": "~1.0.0",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "~1.0.0"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/engine.io-client/ws"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz",
|
|
||||||
"_shasum": "dd379e94f0db8310b08291f9d64c3209766617fd",
|
|
||||||
"_spec": "async-limiter@~1.0.0",
|
|
||||||
"_where": "/Users/paolo/Desktop/multiplayer games/tutorials/hellosocket/node_modules/engine.io-client/node_modules/ws",
|
|
||||||
"author": {
|
|
||||||
"name": "Samuel Reed"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/strml/async-limiter/issues"
|
|
||||||
},
|
|
||||||
"bundleDependencies": false,
|
|
||||||
"dependencies": {},
|
|
||||||
"deprecated": false,
|
|
||||||
"description": "asynchronous function queue with adjustable concurrency",
|
|
||||||
"devDependencies": {
|
|
||||||
"coveralls": "^3.0.3",
|
|
||||||
"eslint": "^5.16.0",
|
|
||||||
"eslint-plugin-mocha": "^5.3.0",
|
|
||||||
"intelli-espower-loader": "^1.0.1",
|
|
||||||
"mocha": "^6.1.4",
|
|
||||||
"nyc": "^14.1.1",
|
|
||||||
"power-assert": "^1.6.1"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/strml/async-limiter#readme",
|
|
||||||
"keywords": [
|
|
||||||
"throttle",
|
|
||||||
"async",
|
|
||||||
"limiter",
|
|
||||||
"asynchronous",
|
|
||||||
"job",
|
|
||||||
"task",
|
|
||||||
"concurrency",
|
|
||||||
"concurrent"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"name": "async-limiter",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/strml/async-limiter.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"coverage": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
|
|
||||||
"example": "node example",
|
|
||||||
"lint": "eslint .",
|
|
||||||
"test": "mocha --require intelli-espower-loader test/",
|
|
||||||
"travis": "npm run lint && npm run test"
|
|
||||||
},
|
|
||||||
"version": "1.0.1"
|
|
||||||
}
|
|
@ -1,132 +0,0 @@
|
|||||||
# Async-Limiter
|
|
||||||
|
|
||||||
A module for limiting concurrent asynchronous actions in flight. Forked from [queue](https://github.com/jessetane/queue).
|
|
||||||
|
|
||||||
[![npm](http://img.shields.io/npm/v/async-limiter.svg?style=flat-square)](http://www.npmjs.org/async-limiter)
|
|
||||||
[![tests](https://img.shields.io/travis/STRML/async-limiter.svg?style=flat-square&branch=master)](https://travis-ci.org/STRML/async-limiter)
|
|
||||||
[![coverage](https://img.shields.io/coveralls/STRML/async-limiter.svg?style=flat-square&branch=master)](https://coveralls.io/r/STRML/async-limiter)
|
|
||||||
|
|
||||||
This module exports a class `Limiter` that implements some of the `Array` API.
|
|
||||||
Pass async functions (ones that accept a callback or return a promise) to an instance's additive array methods.
|
|
||||||
|
|
||||||
## Motivation
|
|
||||||
|
|
||||||
Certain functions, like `zlib`, have [undesirable behavior](https://github.com/nodejs/node/issues/8871#issuecomment-250915913) when
|
|
||||||
run at infinite concurrency.
|
|
||||||
|
|
||||||
In this case, it is actually faster, and takes far less memory, to limit concurrency.
|
|
||||||
|
|
||||||
This module should do the absolute minimum work necessary to queue up functions. PRs are welcome that would
|
|
||||||
make this module faster or lighter, but new functionality is not desired.
|
|
||||||
|
|
||||||
Style should confirm to nodejs/node style.
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
``` javascript
|
|
||||||
var Limiter = require('async-limiter')
|
|
||||||
|
|
||||||
var t = new Limiter({concurrency: 2});
|
|
||||||
var results = []
|
|
||||||
|
|
||||||
// add jobs using the familiar Array API
|
|
||||||
t.push(function (cb) {
|
|
||||||
results.push('two')
|
|
||||||
cb()
|
|
||||||
})
|
|
||||||
|
|
||||||
t.push(
|
|
||||||
function (cb) {
|
|
||||||
results.push('four')
|
|
||||||
cb()
|
|
||||||
},
|
|
||||||
function (cb) {
|
|
||||||
results.push('five')
|
|
||||||
cb()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
t.unshift(function (cb) {
|
|
||||||
results.push('one')
|
|
||||||
cb()
|
|
||||||
})
|
|
||||||
|
|
||||||
t.splice(2, 0, function (cb) {
|
|
||||||
results.push('three')
|
|
||||||
cb()
|
|
||||||
})
|
|
||||||
|
|
||||||
// Jobs run automatically. If you want a callback when all are done,
|
|
||||||
// call 'onDone()'.
|
|
||||||
t.onDone(function () {
|
|
||||||
console.log('all done:', results)
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
## Zlib Example
|
|
||||||
|
|
||||||
```js
|
|
||||||
const zlib = require('zlib');
|
|
||||||
const Limiter = require('async-limiter');
|
|
||||||
|
|
||||||
const message = {some: "data"};
|
|
||||||
const payload = new Buffer(JSON.stringify(message));
|
|
||||||
|
|
||||||
// Try with different concurrency values to see how this actually
|
|
||||||
// slows significantly with higher concurrency!
|
|
||||||
//
|
|
||||||
// 5: 1398.607ms
|
|
||||||
// 10: 1375.668ms
|
|
||||||
// Infinity: 4423.300ms
|
|
||||||
//
|
|
||||||
const t = new Limiter({concurrency: 5});
|
|
||||||
function deflate(payload, cb) {
|
|
||||||
t.push(function(done) {
|
|
||||||
zlib.deflate(payload, function(err, buffer) {
|
|
||||||
done();
|
|
||||||
cb(err, buffer);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
console.time('deflate');
|
|
||||||
for(let i = 0; i < 30000; ++i) {
|
|
||||||
deflate(payload, function (err, buffer) {});
|
|
||||||
}
|
|
||||||
t.onDone(function() {
|
|
||||||
console.timeEnd('deflate');
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
`npm install async-limiter`
|
|
||||||
|
|
||||||
## Test
|
|
||||||
|
|
||||||
`npm test`
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
### `var t = new Limiter([opts])`
|
|
||||||
Constructor. `opts` may contain inital values for:
|
|
||||||
* `t.concurrency`
|
|
||||||
|
|
||||||
## Instance methods
|
|
||||||
|
|
||||||
### `t.onDone(fn)`
|
|
||||||
`fn` will be called once and only once, when the queue is empty.
|
|
||||||
|
|
||||||
## Instance methods mixed in from `Array`
|
|
||||||
Mozilla has docs on how these methods work [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).
|
|
||||||
### `t.push(element1, ..., elementN)`
|
|
||||||
### `t.unshift(element1, ..., elementN)`
|
|
||||||
### `t.splice(index , howMany[, element1[, ...[, elementN]]])`
|
|
||||||
|
|
||||||
## Properties
|
|
||||||
### `t.concurrency`
|
|
||||||
Max number of jobs the queue should process concurrently, defaults to `Infinity`.
|
|
||||||
|
|
||||||
### `t.length`
|
|
||||||
Jobs pending + jobs to process (readonly).
|
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
node_modules/
|
|
@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
1.0.1 / 2014-02-17
|
|
||||||
==================
|
|
||||||
|
|
||||||
* go away decimal point
|
|
||||||
* history
|
|
||||||
|
|
||||||
1.0.0 / 2014-02-17
|
|
||||||
==================
|
|
||||||
|
|
||||||
* add jitter option
|
|
||||||
* Initial commit
|
|
@ -1,8 +0,0 @@
|
|||||||
|
|
||||||
test:
|
|
||||||
@./node_modules/.bin/mocha \
|
|
||||||
--require should \
|
|
||||||
--reporter dot \
|
|
||||||
--bail
|
|
||||||
|
|
||||||
.PHONY: test
|
|
@ -1,34 +0,0 @@
|
|||||||
# backo
|
|
||||||
|
|
||||||
Simple exponential backoff because the others seem to have weird abstractions.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```
|
|
||||||
$ npm install backo
|
|
||||||
```
|
|
||||||
|
|
||||||
## Options
|
|
||||||
|
|
||||||
- `min` initial timeout in milliseconds [100]
|
|
||||||
- `max` max timeout [10000]
|
|
||||||
- `jitter` [0]
|
|
||||||
- `factor` [2]
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```js
|
|
||||||
var Backoff = require('backo');
|
|
||||||
var backoff = new Backoff({ min: 100, max: 20000 });
|
|
||||||
|
|
||||||
setTimeout(function(){
|
|
||||||
something.reconnect();
|
|
||||||
}, backoff.duration());
|
|
||||||
|
|
||||||
// later when something works
|
|
||||||
backoff.reset()
|
|
||||||
```
|
|
||||||
|
|
||||||
# License
|
|
||||||
|
|
||||||
MIT
|
|
@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "backo",
|
|
||||||
"repo": "segmentio/backo",
|
|
||||||
"dependencies": {},
|
|
||||||
"version": "1.0.1",
|
|
||||||
"description": "simple backoff without the weird abstractions",
|
|
||||||
"keywords": ["backoff"],
|
|
||||||
"license": "MIT",
|
|
||||||
"scripts": ["index.js"],
|
|
||||||
"main": "index.js"
|
|
||||||
}
|
|
@ -1,85 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* Expose `Backoff`.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = Backoff;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize backoff timer with `opts`.
|
|
||||||
*
|
|
||||||
* - `min` initial timeout in milliseconds [100]
|
|
||||||
* - `max` max timeout [10000]
|
|
||||||
* - `jitter` [0]
|
|
||||||
* - `factor` [2]
|
|
||||||
*
|
|
||||||
* @param {Object} opts
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
function Backoff(opts) {
|
|
||||||
opts = opts || {};
|
|
||||||
this.ms = opts.min || 100;
|
|
||||||
this.max = opts.max || 10000;
|
|
||||||
this.factor = opts.factor || 2;
|
|
||||||
this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
|
|
||||||
this.attempts = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the backoff duration.
|
|
||||||
*
|
|
||||||
* @return {Number}
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
Backoff.prototype.duration = function(){
|
|
||||||
var ms = this.ms * Math.pow(this.factor, this.attempts++);
|
|
||||||
if (this.jitter) {
|
|
||||||
var rand = Math.random();
|
|
||||||
var deviation = Math.floor(rand * this.jitter * ms);
|
|
||||||
ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
|
|
||||||
}
|
|
||||||
return Math.min(ms, this.max) | 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset the number of attempts.
|
|
||||||
*
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
Backoff.prototype.reset = function(){
|
|
||||||
this.attempts = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the minimum duration
|
|
||||||
*
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
Backoff.prototype.setMin = function(min){
|
|
||||||
this.ms = min;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the maximum duration
|
|
||||||
*
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
Backoff.prototype.setMax = function(max){
|
|
||||||
this.max = max;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the jitter
|
|
||||||
*
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
Backoff.prototype.setJitter = function(jitter){
|
|
||||||
this.jitter = jitter;
|
|
||||||
};
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
|||||||
{
|
|
||||||
"_from": "backo2@1.0.2",
|
|
||||||
"_id": "backo2@1.0.2",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha1-MasayLEpNjRj41s+u2n038+6eUc=",
|
|
||||||
"_location": "/backo2",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "version",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "backo2@1.0.2",
|
|
||||||
"name": "backo2",
|
|
||||||
"escapedName": "backo2",
|
|
||||||
"rawSpec": "1.0.2",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "1.0.2"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/socket.io-client"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz",
|
|
||||||
"_shasum": "31ab1ac8b129363463e35b3ebb69f4dfcfba7947",
|
|
||||||
"_spec": "backo2@1.0.2",
|
|
||||||
"_where": "/Users/paolo/Desktop/multiplayer games/tutorials/hellosocket/node_modules/socket.io-client",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/mokesmokes/backo/issues"
|
|
||||||
},
|
|
||||||
"bundleDependencies": false,
|
|
||||||
"dependencies": {},
|
|
||||||
"deprecated": false,
|
|
||||||
"description": "simple backoff based on segmentio/backo",
|
|
||||||
"devDependencies": {
|
|
||||||
"mocha": "*",
|
|
||||||
"should": "*"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/mokesmokes/backo#readme",
|
|
||||||
"keywords": [
|
|
||||||
"backoff"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"name": "backo2",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/mokesmokes/backo.git"
|
|
||||||
},
|
|
||||||
"version": "1.0.2"
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
|
|
||||||
var Backoff = require('..');
|
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
describe('.duration()', function(){
|
|
||||||
it('should increase the backoff', function(){
|
|
||||||
var b = new Backoff;
|
|
||||||
|
|
||||||
assert(100 == b.duration());
|
|
||||||
assert(200 == b.duration());
|
|
||||||
assert(400 == b.duration());
|
|
||||||
assert(800 == b.duration());
|
|
||||||
|
|
||||||
b.reset();
|
|
||||||
assert(100 == b.duration());
|
|
||||||
assert(200 == b.duration());
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,4 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- "8"
|
|
||||||
script: npm test
|
|
@ -1,121 +0,0 @@
|
|||||||
# Change Log
|
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
||||||
|
|
||||||
<a name="3.0.3"></a>
|
|
||||||
## [3.0.3](https://github.com/web-mech/badwords/compare/v3.0.2...v3.0.3) (2019-07-25)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="3.0.2"></a>
|
|
||||||
## [3.0.2](https://github.com/web-mech/badwords/compare/v3.0.1...v3.0.2) (2019-03-14)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* **lang.json:** remove gay from badwords ([88d1aed](https://github.com/web-mech/badwords/commit/88d1aed))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="3.0.1"></a>
|
|
||||||
## [3.0.1](https://github.com/web-mech/badwords/compare/v3.0.0...v3.0.1) (2019-02-19)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* update removeWords functionality to be case-insensitive ([235121d](https://github.com/web-mech/badwords/commit/235121d))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="3.0.0"></a>
|
|
||||||
# [3.0.0](https://github.com/web-mech/badwords/compare/v2.0.0...v3.0.0) (2018-10-23)
|
|
||||||
|
|
||||||
|
|
||||||
### Code Refactoring
|
|
||||||
|
|
||||||
* utilize es6 spread in addWords/removeWords ([656b87c](https://github.com/web-mech/badwords/commit/656b87c))
|
|
||||||
|
|
||||||
|
|
||||||
### BREAKING CHANGES
|
|
||||||
|
|
||||||
* changes the way addWords is used, no longer accepts a single array as a parameter unless used with the spread operator
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="2.0.0"></a>
|
|
||||||
# [2.0.0](https://github.com/web-mech/badwords/compare/v1.6.5...v2.0.0) (2018-10-23)
|
|
||||||
|
|
||||||
|
|
||||||
### Documentation
|
|
||||||
|
|
||||||
* update documentation. add requirements for using lib moving forward ([9b2831d](https://github.com/web-mech/badwords/commit/9b2831d))
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* **profane:** support profane phrases and well as words ([995ea1e](https://github.com/web-mech/badwords/commit/995ea1e))
|
|
||||||
|
|
||||||
|
|
||||||
### BREAKING CHANGES
|
|
||||||
|
|
||||||
* moving into es2016+ language features
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="1.6.5"></a>
|
|
||||||
## [1.6.5](https://github.com/web-mech/badwords/compare/v1.6.4...v1.6.5) (2018-10-23)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="1.6.4"></a>
|
|
||||||
## [1.6.4](https://github.com/web-mech/badwords/compare/v1.6.3...v1.6.4) (2018-09-21)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* **isProfane:** Adding regex word boundary for isProfane ([3908f3c](https://github.com/web-mech/badwords/commit/3908f3c))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="1.6.3"></a>
|
|
||||||
## [1.6.3](https://github.com/web-mech/badwords/compare/v1.6.2...v1.6.3) (2018-08-02)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="1.6.2"></a>
|
|
||||||
## [1.6.2](https://github.com/web-mech/badwords/compare/v1.6.1...v1.6.2) (2018-08-02)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* **isProfaneLike:** abort trying to match every instance of profane words. ([31126d6](https://github.com/web-mech/badwords/commit/31126d6))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="1.6.1"></a>
|
|
||||||
## [1.6.1](https://github.com/web-mech/badwords/compare/v1.6.0...v1.6.1) (2017-10-25)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* **isProfaneLike:** fix case sensitive checks within list ([bfa05ce](https://github.com/web-mech/badwords/commit/bfa05ce))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="1.6.0"></a>
|
|
||||||
# [1.6.0](https://github.com/web-mech/badwords/compare/v1.5.2...v1.6.0) (2017-10-16)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* fixes and updates ([8049222](https://github.com/web-mech/badwords/commit/8049222))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="1.5.2"></a>
|
|
||||||
## [1.5.2](https://github.com/web-mech/badwords/compare/v1.5.1...v1.5.2) (2017-10-16)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* support for better filtering ([7c8d0e2](https://github.com/web-mech/badwords/commit/7c8d0e2))
|
|
@ -1,20 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Michael Price
|
|
||||||
|
|
||||||
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:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
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.
|
|
@ -1,4 +0,0 @@
|
|||||||
test:
|
|
||||||
@./node_modules/mocha/bin/_mocha -R $(REPORTER)
|
|
||||||
|
|
||||||
.PHONY: test
|
|
@ -1,175 +0,0 @@
|
|||||||
# bad-words
|
|
||||||
|
|
||||||
A javascript filter for badwords
|
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.org/web-mech/badwords.svg?branch=master)](https://travis-ci.org/web-mech/badwords)
|
|
||||||
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
|
|
||||||
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
|
|
||||||
|
|
||||||
## Requirements
|
|
||||||
|
|
||||||
As of version 2, requires you either have an environment that understands ES2016 and beyond or a transpiler like Babel.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
npm install bad-words --save
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```js
|
|
||||||
var Filter = require('bad-words'),
|
|
||||||
filter = new Filter();
|
|
||||||
|
|
||||||
console.log(filter.clean("Don't be an ash0le")); //Don't be an ******
|
|
||||||
```
|
|
||||||
|
|
||||||
### Placeholder Overrides
|
|
||||||
|
|
||||||
```js
|
|
||||||
var Filter = require('bad-words');
|
|
||||||
var customFilter = new Filter({ placeHolder: 'x'});
|
|
||||||
|
|
||||||
customFilter.clean("Don't be an ash0le"); //Don't be an xxxxxx
|
|
||||||
```
|
|
||||||
|
|
||||||
### Regex Overrides
|
|
||||||
|
|
||||||
```js
|
|
||||||
var filter = new Filter({ regex: /\*|\.|$/gi });
|
|
||||||
|
|
||||||
var filter = new Filter({ replaceRegex: /[A-Za-z0-9가-힣_]/g });
|
|
||||||
//multilingual support for word filtering
|
|
||||||
```
|
|
||||||
|
|
||||||
### Add words to the blacklist
|
|
||||||
|
|
||||||
```js
|
|
||||||
var filter = new Filter();
|
|
||||||
|
|
||||||
filter.addWords('some', 'bad', 'word');
|
|
||||||
|
|
||||||
filter.clean("some bad word!") //**** *** ****!
|
|
||||||
|
|
||||||
//or use an array using the spread operator
|
|
||||||
|
|
||||||
var newBadWords = ['some', 'bad', 'word'];
|
|
||||||
|
|
||||||
filter.addWords(...newBadWords);
|
|
||||||
|
|
||||||
filter.clean("some bad word!") //**** *** ****!
|
|
||||||
|
|
||||||
//or
|
|
||||||
|
|
||||||
var filter = new Filter({ list: ['some', 'bad', 'word'] });
|
|
||||||
|
|
||||||
filter.clean("some bad word!") //**** *** ****!
|
|
||||||
```
|
|
||||||
|
|
||||||
### Instantiate with an empty list
|
|
||||||
|
|
||||||
```js
|
|
||||||
var filter = new Filter({ emptyList: true });
|
|
||||||
filter.clean('hell this wont clean anything'); //hell this wont clean anything
|
|
||||||
```
|
|
||||||
|
|
||||||
### Remove words from the blacklist
|
|
||||||
|
|
||||||
```js
|
|
||||||
let filter = new Filter();
|
|
||||||
|
|
||||||
filter.removeWords('hells', 'sadist');
|
|
||||||
|
|
||||||
filter.clean("some hells word!"); //some hells word!
|
|
||||||
|
|
||||||
//or use an array using the spread operator
|
|
||||||
|
|
||||||
let removeWords = ['hells', 'sadist'];
|
|
||||||
|
|
||||||
filter.removeWords(...removeWords);
|
|
||||||
|
|
||||||
filter.clean("some sadist hells word!"); //some sadist hells word!
|
|
||||||
```
|
|
||||||
|
|
||||||
### API
|
|
||||||
|
|
||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
||||||
|
|
||||||
#### constructor
|
|
||||||
|
|
||||||
Filter constructor.
|
|
||||||
|
|
||||||
**Parameters**
|
|
||||||
|
|
||||||
- `options` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Filter instance options (optional, default `{}`)
|
|
||||||
- `options.emptyList` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Instantiate filter with no blacklist
|
|
||||||
- `options.list` **[array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** Instantiate filter with custom list
|
|
||||||
- `options.placeHolder` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Character used to replace profane words.
|
|
||||||
- `options.regex` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Regular expression used to sanitize words before comparing them to blacklist.
|
|
||||||
- `options.replaceRegex` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Regular expression used to replace profane words with placeHolder.
|
|
||||||
|
|
||||||
#### isProfane
|
|
||||||
|
|
||||||
Determine if a string contains profane language.
|
|
||||||
|
|
||||||
**Parameters**
|
|
||||||
|
|
||||||
- `string` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** String to evaluate for profanity.
|
|
||||||
|
|
||||||
#### replaceWord
|
|
||||||
|
|
||||||
Replace a word with placeHolder characters;
|
|
||||||
|
|
||||||
**Parameters**
|
|
||||||
|
|
||||||
- `string` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** String to replace.
|
|
||||||
|
|
||||||
#### clean
|
|
||||||
|
|
||||||
Evaluate a string for profanity and return an edited version.
|
|
||||||
|
|
||||||
**Parameters**
|
|
||||||
|
|
||||||
- `string` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Sentence to filter.
|
|
||||||
|
|
||||||
#### addWords
|
|
||||||
|
|
||||||
Add word(s) to blacklist filter / remove words from whitelist filter
|
|
||||||
|
|
||||||
**Parameters**
|
|
||||||
|
|
||||||
- `word` **...[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Word(s) to add to blacklist
|
|
||||||
|
|
||||||
#### removeWords
|
|
||||||
|
|
||||||
Add words to whitelist filter
|
|
||||||
|
|
||||||
**Parameters**
|
|
||||||
|
|
||||||
- `word` **...[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Word(s) to add to whitelist.
|
|
||||||
|
|
||||||
## Testing
|
|
||||||
|
|
||||||
npm test
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2013 Michael Price
|
|
||||||
|
|
||||||
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:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
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.
|
|
@ -1,108 +0,0 @@
|
|||||||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.badwords = f()}})(function(){var define,module,exports;module={exports:(exports={})};
|
|
||||||
var localList = require('./lang.json').words;
|
|
||||||
var baseList = require('badwords-list').array;
|
|
||||||
var Filter = (function() {
|
|
||||||
/**
|
|
||||||
* Filter constructor.
|
|
||||||
* @constructor
|
|
||||||
* @param {object} options - Filter instance options
|
|
||||||
* @param {boolean} options.emptyList - Instantiate filter with no blacklist
|
|
||||||
* @param {array} options.list - Instantiate filter with custom list
|
|
||||||
* @param {string} options.placeHolder - Character used to replace profane words.
|
|
||||||
* @param {string} options.regex - Regular expression used to sanitize words before comparing them to blacklist.
|
|
||||||
* @param {string} options.replaceRegex - Regular expression used to replace profane words with placeHolder.
|
|
||||||
*/
|
|
||||||
function Filter(options) {
|
|
||||||
options = options || {};
|
|
||||||
this.list = options.emptyList && [] || Array.prototype.concat.apply(localList, [baseList, options.list || []]);
|
|
||||||
this.exclude = options.exclude || [];
|
|
||||||
this.placeHolder = options.placeHolder || '*';
|
|
||||||
this.regex = options.regex || /[^a-zA-Z0-9|\$|\@]|\^/g;
|
|
||||||
this.replaceRegex = options.replaceRegex || /\w/g;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if a string contains profane language.
|
|
||||||
* @param {string} string - String to evaluate for profanity.
|
|
||||||
*/
|
|
||||||
Filter.prototype.isProfane = function isProfane(string) {
|
|
||||||
return string
|
|
||||||
.split(/\b/)
|
|
||||||
.map(function(w) {
|
|
||||||
return w.toLowerCase().replace(this.regex, '');
|
|
||||||
}, this)
|
|
||||||
.filter(this.isProfaneLike, this)
|
|
||||||
.shift() || false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if a single word is profane or looks profane.
|
|
||||||
* @param {string} word - String to evaluate for profanity.
|
|
||||||
*/
|
|
||||||
Filter.prototype.isProfaneLike = function profaneLike(word) {
|
|
||||||
if (!!~this.exclude.indexOf(word)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!!~this.list.indexOf(word)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.list
|
|
||||||
.map(function(w) {
|
|
||||||
return new RegExp('^' + w.replace(/(\W)/g, '\\$1') + '$', 'gi');
|
|
||||||
}, this)
|
|
||||||
.reduce(function(outcome, wordExp) {
|
|
||||||
return outcome || wordExp.test(word);
|
|
||||||
}, false);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace a word with placeHolder characters;
|
|
||||||
* @param {string} string - String to replace.
|
|
||||||
*/
|
|
||||||
Filter.prototype.replaceWord = function replaceWord(string) {
|
|
||||||
return string.replace(this.regex, '').replace(this.replaceRegex, this.placeHolder);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Evaluate a string for profanity and return an edited version.
|
|
||||||
* @param {string} string - Sentence to filter.
|
|
||||||
*/
|
|
||||||
Filter.prototype.clean = function clean(string) {
|
|
||||||
return string.split(/\b/).map(function(word) {
|
|
||||||
return this.isProfane(word) ? this.replaceWord(word) : word;
|
|
||||||
}.bind(this)).join('');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add words to blacklist filter / remove words from whitelist filter
|
|
||||||
* @param {(string|string[])}
|
|
||||||
*/
|
|
||||||
Filter.prototype.addWords = function addWords(words) {
|
|
||||||
words = (words instanceof Array) ? words : [words];
|
|
||||||
this.list = this.list.concat(words);
|
|
||||||
|
|
||||||
words.forEach(function(word) {
|
|
||||||
if(!!~this.exclude.indexOf(word)) {
|
|
||||||
this.exclude.splice(this.exclude.indexOf(word), 1);
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add words to whitelist filter
|
|
||||||
* @param {...string} word - Word to add to whitelist.
|
|
||||||
*/
|
|
||||||
Filter.prototype.removeWords = function removeWords() {
|
|
||||||
var words = Array.prototype.slice.call(arguments);
|
|
||||||
this.exclude.push.apply(this.exclude, words);
|
|
||||||
};
|
|
||||||
|
|
||||||
return Filter;
|
|
||||||
})();
|
|
||||||
|
|
||||||
module.exports = Filter;
|
|
||||||
|
|
||||||
return module.exports;});
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
|||||||
const localList = require('./lang.json').words;
|
|
||||||
const baseList = require('badwords-list').array;
|
|
||||||
|
|
||||||
class Filter {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter constructor.
|
|
||||||
* @constructor
|
|
||||||
* @param {object} options - Filter instance options
|
|
||||||
* @param {boolean} options.emptyList - Instantiate filter with no blacklist
|
|
||||||
* @param {array} options.list - Instantiate filter with custom list
|
|
||||||
* @param {string} options.placeHolder - Character used to replace profane words.
|
|
||||||
* @param {string} options.regex - Regular expression used to sanitize words before comparing them to blacklist.
|
|
||||||
* @param {string} options.replaceRegex - Regular expression used to replace profane words with placeHolder.
|
|
||||||
*/
|
|
||||||
constructor(options = {}) {
|
|
||||||
Object.assign(this, {
|
|
||||||
list: options.emptyList && [] || Array.prototype.concat.apply(localList, [baseList, options.list || []]),
|
|
||||||
exclude: options.exclude || [],
|
|
||||||
placeHolder: options.placeHolder || '*',
|
|
||||||
regex: options.regex || /[^a-zA-Z0-9|\$|\@]|\^/g,
|
|
||||||
replaceRegex: options.replaceRegex || /\w/g
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if a string contains profane language.
|
|
||||||
* @param {string} string - String to evaluate for profanity.
|
|
||||||
*/
|
|
||||||
isProfane(string) {
|
|
||||||
return this.list
|
|
||||||
.filter((word) => {
|
|
||||||
const wordExp = new RegExp(`\\b${word.replace(/(\W)/g, '\\$1')}\\b`, 'gi');
|
|
||||||
return !this.exclude.includes(word.toLowerCase()) && wordExp.test(string);
|
|
||||||
})
|
|
||||||
.length > 0 || false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace a word with placeHolder characters;
|
|
||||||
* @param {string} string - String to replace.
|
|
||||||
*/
|
|
||||||
replaceWord(string) {
|
|
||||||
return string
|
|
||||||
.replace(this.regex, '')
|
|
||||||
.replace(this.replaceRegex, this.placeHolder);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Evaluate a string for profanity and return an edited version.
|
|
||||||
* @param {string} string - Sentence to filter.
|
|
||||||
*/
|
|
||||||
clean(string) {
|
|
||||||
return string.split(/\b/).map((word) => {
|
|
||||||
return this.isProfane(word) ? this.replaceWord(word) : word;
|
|
||||||
}).join('');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add word(s) to blacklist filter / remove words from whitelist filter
|
|
||||||
* @param {...string} word - Word(s) to add to blacklist
|
|
||||||
*/
|
|
||||||
addWords() {
|
|
||||||
let words = Array.from(arguments);
|
|
||||||
|
|
||||||
this.list.push(...words);
|
|
||||||
|
|
||||||
words
|
|
||||||
.map(word => word.toLowerCase())
|
|
||||||
.forEach((word) => {
|
|
||||||
if (this.exclude.includes(word)) {
|
|
||||||
this.exclude.splice(this.exclude.indexOf(word), 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add words to whitelist filter
|
|
||||||
* @param {...string} word - Word(s) to add to whitelist.
|
|
||||||
*/
|
|
||||||
removeWords() {
|
|
||||||
this.exclude.push(...Array.from(arguments).map(word => word.toLowerCase()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Filter;
|
|
@ -1,457 +0,0 @@
|
|||||||
{
|
|
||||||
"words":[
|
|
||||||
"ahole",
|
|
||||||
"anus",
|
|
||||||
"ash0le",
|
|
||||||
"ash0les",
|
|
||||||
"asholes",
|
|
||||||
"ass",
|
|
||||||
"Ass Monkey",
|
|
||||||
"Assface",
|
|
||||||
"assh0le",
|
|
||||||
"assh0lez",
|
|
||||||
"asshole",
|
|
||||||
"assholes",
|
|
||||||
"assholz",
|
|
||||||
"asswipe",
|
|
||||||
"azzhole",
|
|
||||||
"bassterds",
|
|
||||||
"bastard",
|
|
||||||
"bastards",
|
|
||||||
"bastardz",
|
|
||||||
"basterds",
|
|
||||||
"basterdz",
|
|
||||||
"Biatch",
|
|
||||||
"bitch",
|
|
||||||
"bitches",
|
|
||||||
"Blow Job",
|
|
||||||
"boffing",
|
|
||||||
"butthole",
|
|
||||||
"buttwipe",
|
|
||||||
"c0ck",
|
|
||||||
"c0cks",
|
|
||||||
"c0k",
|
|
||||||
"Carpet Muncher",
|
|
||||||
"cawk",
|
|
||||||
"cawks",
|
|
||||||
"Clit",
|
|
||||||
"cnts",
|
|
||||||
"cntz",
|
|
||||||
"cock",
|
|
||||||
"cockhead",
|
|
||||||
"cock-head",
|
|
||||||
"cocks",
|
|
||||||
"CockSucker",
|
|
||||||
"cock-sucker",
|
|
||||||
"crap",
|
|
||||||
"cum",
|
|
||||||
"cunt",
|
|
||||||
"cunts",
|
|
||||||
"cuntz",
|
|
||||||
"dick",
|
|
||||||
"dild0",
|
|
||||||
"dild0s",
|
|
||||||
"dildo",
|
|
||||||
"dildos",
|
|
||||||
"dilld0",
|
|
||||||
"dilld0s",
|
|
||||||
"dominatricks",
|
|
||||||
"dominatrics",
|
|
||||||
"dominatrix",
|
|
||||||
"dyke",
|
|
||||||
"enema",
|
|
||||||
"f u c k",
|
|
||||||
"f u c k e r",
|
|
||||||
"fag",
|
|
||||||
"fag1t",
|
|
||||||
"faget",
|
|
||||||
"fagg1t",
|
|
||||||
"faggit",
|
|
||||||
"faggot",
|
|
||||||
"fagg0t",
|
|
||||||
"fagit",
|
|
||||||
"fags",
|
|
||||||
"fagz",
|
|
||||||
"faig",
|
|
||||||
"faigs",
|
|
||||||
"fart",
|
|
||||||
"flipping the bird",
|
|
||||||
"fuck",
|
|
||||||
"fucker",
|
|
||||||
"fuckin",
|
|
||||||
"fucking",
|
|
||||||
"fucks",
|
|
||||||
"Fudge Packer",
|
|
||||||
"fuk",
|
|
||||||
"Fukah",
|
|
||||||
"Fuken",
|
|
||||||
"fuker",
|
|
||||||
"Fukin",
|
|
||||||
"Fukk",
|
|
||||||
"Fukkah",
|
|
||||||
"Fukken",
|
|
||||||
"Fukker",
|
|
||||||
"Fukkin",
|
|
||||||
"g00k",
|
|
||||||
"God-damned",
|
|
||||||
"h00r",
|
|
||||||
"h0ar",
|
|
||||||
"h0re",
|
|
||||||
"hells",
|
|
||||||
"hoar",
|
|
||||||
"hoor",
|
|
||||||
"hoore",
|
|
||||||
"jackoff",
|
|
||||||
"jap",
|
|
||||||
"japs",
|
|
||||||
"jerk-off",
|
|
||||||
"jisim",
|
|
||||||
"jiss",
|
|
||||||
"jizm",
|
|
||||||
"jizz",
|
|
||||||
"knob",
|
|
||||||
"knobs",
|
|
||||||
"knobz",
|
|
||||||
"kunt",
|
|
||||||
"kunts",
|
|
||||||
"kuntz",
|
|
||||||
"Lezzian",
|
|
||||||
"Lipshits",
|
|
||||||
"Lipshitz",
|
|
||||||
"masochist",
|
|
||||||
"masokist",
|
|
||||||
"massterbait",
|
|
||||||
"masstrbait",
|
|
||||||
"masstrbate",
|
|
||||||
"masterbaiter",
|
|
||||||
"masterbate",
|
|
||||||
"masterbates",
|
|
||||||
"Motha Fucker",
|
|
||||||
"Motha Fuker",
|
|
||||||
"Motha Fukkah",
|
|
||||||
"Motha Fukker",
|
|
||||||
"Mother Fucker",
|
|
||||||
"Mother Fukah",
|
|
||||||
"Mother Fuker",
|
|
||||||
"Mother Fukkah",
|
|
||||||
"Mother Fukker",
|
|
||||||
"mother-fucker",
|
|
||||||
"Mutha Fucker",
|
|
||||||
"Mutha Fukah",
|
|
||||||
"Mutha Fuker",
|
|
||||||
"Mutha Fukkah",
|
|
||||||
"Mutha Fukker",
|
|
||||||
"n1gr",
|
|
||||||
"nastt",
|
|
||||||
"nigger;",
|
|
||||||
"nigur;",
|
|
||||||
"niiger;",
|
|
||||||
"niigr;",
|
|
||||||
"orafis",
|
|
||||||
"orgasim;",
|
|
||||||
"orgasm",
|
|
||||||
"orgasum",
|
|
||||||
"oriface",
|
|
||||||
"orifice",
|
|
||||||
"orifiss",
|
|
||||||
"packi",
|
|
||||||
"packie",
|
|
||||||
"packy",
|
|
||||||
"paki",
|
|
||||||
"pakie",
|
|
||||||
"paky",
|
|
||||||
"pecker",
|
|
||||||
"peeenus",
|
|
||||||
"peeenusss",
|
|
||||||
"peenus",
|
|
||||||
"peinus",
|
|
||||||
"pen1s",
|
|
||||||
"penas",
|
|
||||||
"penis",
|
|
||||||
"penis-breath",
|
|
||||||
"penus",
|
|
||||||
"penuus",
|
|
||||||
"Phuc",
|
|
||||||
"Phuck",
|
|
||||||
"Phuk",
|
|
||||||
"Phuker",
|
|
||||||
"Phukker",
|
|
||||||
"polac",
|
|
||||||
"polack",
|
|
||||||
"polak",
|
|
||||||
"Poonani",
|
|
||||||
"pr1c",
|
|
||||||
"pr1ck",
|
|
||||||
"pr1k",
|
|
||||||
"pusse",
|
|
||||||
"pussee",
|
|
||||||
"pussy",
|
|
||||||
"puuke",
|
|
||||||
"puuker",
|
|
||||||
"queer",
|
|
||||||
"queers",
|
|
||||||
"queerz",
|
|
||||||
"qweers",
|
|
||||||
"qweerz",
|
|
||||||
"qweir",
|
|
||||||
"recktum",
|
|
||||||
"rectum",
|
|
||||||
"retard",
|
|
||||||
"sadist",
|
|
||||||
"scank",
|
|
||||||
"schlong",
|
|
||||||
"screwing",
|
|
||||||
"semen",
|
|
||||||
"sex",
|
|
||||||
"sexy",
|
|
||||||
"Sh!t",
|
|
||||||
"sh1t",
|
|
||||||
"sh1ter",
|
|
||||||
"sh1ts",
|
|
||||||
"sh1tter",
|
|
||||||
"sh1tz",
|
|
||||||
"shit",
|
|
||||||
"shits",
|
|
||||||
"shitter",
|
|
||||||
"Shitty",
|
|
||||||
"Shity",
|
|
||||||
"shitz",
|
|
||||||
"Shyt",
|
|
||||||
"Shyte",
|
|
||||||
"Shytty",
|
|
||||||
"Shyty",
|
|
||||||
"skanck",
|
|
||||||
"skank",
|
|
||||||
"skankee",
|
|
||||||
"skankey",
|
|
||||||
"skanks",
|
|
||||||
"Skanky",
|
|
||||||
"slag",
|
|
||||||
"slut",
|
|
||||||
"sluts",
|
|
||||||
"Slutty",
|
|
||||||
"slutz",
|
|
||||||
"son-of-a-bitch",
|
|
||||||
"tit",
|
|
||||||
"turd",
|
|
||||||
"va1jina",
|
|
||||||
"vag1na",
|
|
||||||
"vagiina",
|
|
||||||
"vagina",
|
|
||||||
"vaj1na",
|
|
||||||
"vajina",
|
|
||||||
"vullva",
|
|
||||||
"vulva",
|
|
||||||
"w0p",
|
|
||||||
"wh00r",
|
|
||||||
"wh0re",
|
|
||||||
"whore",
|
|
||||||
"xrated",
|
|
||||||
"xxx",
|
|
||||||
"b!+ch",
|
|
||||||
"bitch",
|
|
||||||
"blowjob",
|
|
||||||
"clit",
|
|
||||||
"arschloch",
|
|
||||||
"fuck",
|
|
||||||
"shit",
|
|
||||||
"ass",
|
|
||||||
"asshole",
|
|
||||||
"b!tch",
|
|
||||||
"b17ch",
|
|
||||||
"b1tch",
|
|
||||||
"bastard",
|
|
||||||
"bi+ch",
|
|
||||||
"boiolas",
|
|
||||||
"buceta",
|
|
||||||
"c0ck",
|
|
||||||
"cawk",
|
|
||||||
"chink",
|
|
||||||
"cipa",
|
|
||||||
"clits",
|
|
||||||
"cock",
|
|
||||||
"cum",
|
|
||||||
"cunt",
|
|
||||||
"dildo",
|
|
||||||
"dirsa",
|
|
||||||
"ejakulate",
|
|
||||||
"fatass",
|
|
||||||
"fcuk",
|
|
||||||
"fuk",
|
|
||||||
"fux0r",
|
|
||||||
"hoer",
|
|
||||||
"hore",
|
|
||||||
"jism",
|
|
||||||
"kawk",
|
|
||||||
"l3itch",
|
|
||||||
"l3i+ch",
|
|
||||||
"lesbian",
|
|
||||||
"masturbate",
|
|
||||||
"masterbat*",
|
|
||||||
"masterbat3",
|
|
||||||
"motherfucker",
|
|
||||||
"s.o.b.",
|
|
||||||
"mofo",
|
|
||||||
"nazi",
|
|
||||||
"nigga",
|
|
||||||
"nigger",
|
|
||||||
"nutsack",
|
|
||||||
"phuck",
|
|
||||||
"pimpis",
|
|
||||||
"pusse",
|
|
||||||
"pussy",
|
|
||||||
"scrotum",
|
|
||||||
"sh!t",
|
|
||||||
"shemale",
|
|
||||||
"shi+",
|
|
||||||
"sh!+",
|
|
||||||
"slut",
|
|
||||||
"smut",
|
|
||||||
"teets",
|
|
||||||
"tits",
|
|
||||||
"boobs",
|
|
||||||
"b00bs",
|
|
||||||
"teez",
|
|
||||||
"testical",
|
|
||||||
"testicle",
|
|
||||||
"titt",
|
|
||||||
"w00se",
|
|
||||||
"jackoff",
|
|
||||||
"wank",
|
|
||||||
"whoar",
|
|
||||||
"whore",
|
|
||||||
"*damn",
|
|
||||||
"*dyke",
|
|
||||||
"*fuck*",
|
|
||||||
"*shit*",
|
|
||||||
"@$$",
|
|
||||||
"amcik",
|
|
||||||
"andskota",
|
|
||||||
"arse*",
|
|
||||||
"assrammer",
|
|
||||||
"ayir",
|
|
||||||
"bi7ch",
|
|
||||||
"bitch*",
|
|
||||||
"bollock*",
|
|
||||||
"breasts",
|
|
||||||
"butt-pirate",
|
|
||||||
"cabron",
|
|
||||||
"cazzo",
|
|
||||||
"chraa",
|
|
||||||
"chuj",
|
|
||||||
"Cock*",
|
|
||||||
"cunt*",
|
|
||||||
"d4mn",
|
|
||||||
"daygo",
|
|
||||||
"dego",
|
|
||||||
"dick*",
|
|
||||||
"dike*",
|
|
||||||
"dupa",
|
|
||||||
"dziwka",
|
|
||||||
"ejackulate",
|
|
||||||
"Ekrem*",
|
|
||||||
"Ekto",
|
|
||||||
"enculer",
|
|
||||||
"faen",
|
|
||||||
"fag*",
|
|
||||||
"fanculo",
|
|
||||||
"fanny",
|
|
||||||
"feces",
|
|
||||||
"feg",
|
|
||||||
"Felcher",
|
|
||||||
"ficken",
|
|
||||||
"fitt*",
|
|
||||||
"Flikker",
|
|
||||||
"foreskin",
|
|
||||||
"Fotze",
|
|
||||||
"Fu(*",
|
|
||||||
"fuk*",
|
|
||||||
"futkretzn",
|
|
||||||
"gook",
|
|
||||||
"guiena",
|
|
||||||
"h0r",
|
|
||||||
"h4x0r",
|
|
||||||
"hell",
|
|
||||||
"helvete",
|
|
||||||
"hoer*",
|
|
||||||
"honkey",
|
|
||||||
"Huevon",
|
|
||||||
"hui",
|
|
||||||
"injun",
|
|
||||||
"jizz",
|
|
||||||
"kanker*",
|
|
||||||
"kike",
|
|
||||||
"klootzak",
|
|
||||||
"kraut",
|
|
||||||
"knulle",
|
|
||||||
"kuk",
|
|
||||||
"kuksuger",
|
|
||||||
"Kurac",
|
|
||||||
"kurwa",
|
|
||||||
"kusi*",
|
|
||||||
"kyrpa*",
|
|
||||||
"lesbo",
|
|
||||||
"mamhoon",
|
|
||||||
"masturbat*",
|
|
||||||
"merd*",
|
|
||||||
"mibun",
|
|
||||||
"monkleigh",
|
|
||||||
"mouliewop",
|
|
||||||
"muie",
|
|
||||||
"mulkku",
|
|
||||||
"muschi",
|
|
||||||
"nazis",
|
|
||||||
"nepesaurio",
|
|
||||||
"nigger*",
|
|
||||||
"orospu",
|
|
||||||
"paska*",
|
|
||||||
"perse",
|
|
||||||
"picka",
|
|
||||||
"pierdol*",
|
|
||||||
"pillu*",
|
|
||||||
"pimmel",
|
|
||||||
"piss*",
|
|
||||||
"pizda",
|
|
||||||
"poontsee",
|
|
||||||
"poop",
|
|
||||||
"porn",
|
|
||||||
"p0rn",
|
|
||||||
"pr0n",
|
|
||||||
"preteen",
|
|
||||||
"pula",
|
|
||||||
"pule",
|
|
||||||
"puta",
|
|
||||||
"puto",
|
|
||||||
"qahbeh",
|
|
||||||
"queef*",
|
|
||||||
"rautenberg",
|
|
||||||
"schaffer",
|
|
||||||
"scheiss*",
|
|
||||||
"schlampe",
|
|
||||||
"schmuck",
|
|
||||||
"screw",
|
|
||||||
"sh!t*",
|
|
||||||
"sharmuta",
|
|
||||||
"sharmute",
|
|
||||||
"shipal",
|
|
||||||
"shiz",
|
|
||||||
"skribz",
|
|
||||||
"skurwysyn",
|
|
||||||
"sphencter",
|
|
||||||
"spic",
|
|
||||||
"spierdalaj",
|
|
||||||
"splooge",
|
|
||||||
"suka",
|
|
||||||
"b00b*",
|
|
||||||
"testicle*",
|
|
||||||
"titt*",
|
|
||||||
"twat",
|
|
||||||
"vittu",
|
|
||||||
"wank*",
|
|
||||||
"wetback*",
|
|
||||||
"wichser",
|
|
||||||
"wop*",
|
|
||||||
"yed",
|
|
||||||
"zabourah"
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
{
|
|
||||||
"_from": "bad-words@^3.0.3",
|
|
||||||
"_id": "bad-words@3.0.3",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha512-To+nGz+U8SpEQieZ2kSadY/1hVO88UXAslCJuTgLjDOuGrs/tNW2BYwl0fctxcRLooe0nzYN1pGzgvRIrd0BeA==",
|
|
||||||
"_location": "/bad-words",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "range",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "bad-words@^3.0.3",
|
|
||||||
"name": "bad-words",
|
|
||||||
"escapedName": "bad-words",
|
|
||||||
"rawSpec": "^3.0.3",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "^3.0.3"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"#USER",
|
|
||||||
"/"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/bad-words/-/bad-words-3.0.3.tgz",
|
|
||||||
"_shasum": "fa6fe18ffce3101a415193ebd8647c289b58b554",
|
|
||||||
"_spec": "bad-words@^3.0.3",
|
|
||||||
"_where": "/Users/paolo/Desktop/multiplayer games/tutorials/chat3",
|
|
||||||
"author": {
|
|
||||||
"name": "Mike P."
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/web-mech/badwords/issues"
|
|
||||||
},
|
|
||||||
"bundleDependencies": false,
|
|
||||||
"dependencies": {
|
|
||||||
"badwords-list": "^1.0.0"
|
|
||||||
},
|
|
||||||
"deprecated": false,
|
|
||||||
"description": "A javascript filter for bad words",
|
|
||||||
"devDependencies": {
|
|
||||||
"better-assert": "1.0.0",
|
|
||||||
"documentation": "^5.3.3",
|
|
||||||
"mocha": "^5.2.0"
|
|
||||||
},
|
|
||||||
"directories": {
|
|
||||||
"test": "test"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8.0.0"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/web-mech/badwords#readme",
|
|
||||||
"keywords": [
|
|
||||||
"curse",
|
|
||||||
"words",
|
|
||||||
"profanity",
|
|
||||||
"filter"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"main": "./lib/badwords",
|
|
||||||
"name": "bad-words",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/web-mech/badwords.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"docs": "documentation readme --section API ./lib/badwords.js",
|
|
||||||
"test": "mocha -R spec"
|
|
||||||
},
|
|
||||||
"version": "3.0.3"
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
require('assert');
|
|
||||||
var Filter = require('../lib/badwords.js'),
|
|
||||||
filter = new Filter(),
|
|
||||||
assert = require('better-assert');
|
|
||||||
|
|
||||||
describe('filter', function(){
|
|
||||||
describe('addWords',function(){
|
|
||||||
it('Should append words to the filter list.', function(){
|
|
||||||
filter.addWords('dog', 'go');
|
|
||||||
assert(filter.clean('Go dog go') === '** *** **');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should append words to the filter using an array', () => {
|
|
||||||
let addWords = ['go', 'dog'];
|
|
||||||
filter = new Filter()
|
|
||||||
filter.addWords(...addWords);
|
|
||||||
assert(filter.clean('Go dog go') === '** *** **');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should allow a list to be passed to the constructor', function() {
|
|
||||||
filter = new Filter({
|
|
||||||
list: ['dog']
|
|
||||||
});
|
|
||||||
|
|
||||||
assert(filter.clean('Go dog go') === 'Go *** go');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,47 +0,0 @@
|
|||||||
require('assert');
|
|
||||||
var Filter = require('../lib/badwords.js'),
|
|
||||||
filter = new Filter(),
|
|
||||||
assert = require('better-assert');
|
|
||||||
|
|
||||||
describe('filter', function(){
|
|
||||||
describe('clean',function(){
|
|
||||||
it('Should replace a bad word within a sentence asterisks (******)',function(){
|
|
||||||
console.log(filter.clean('Don\'t be an ash0le'));
|
|
||||||
assert(filter.clean('Don\'t be an ash0le') === 'Don\'t be an ******');
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should replace multiple instances of any bad words within a sentence asterisks (******)',function(){
|
|
||||||
assert(filter.clean('cnts ash0le knob xxx') === '**** ****** **** ***');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should not replace anything within a sentence if there are no bad words',function(){
|
|
||||||
assert(filter.clean('The cat ran fast') === 'The cat ran fast');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should replace a string with proper placeholder when overridden', function(){
|
|
||||||
var customFilter = new Filter({ placeHolder: 'x'});
|
|
||||||
assert(customFilter.clean('This is a hells good test') === 'This is a xxxxx good test');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should allow an instance of filter with an empty blacklist', function() {
|
|
||||||
var customFilter = new Filter({
|
|
||||||
emptyList: true
|
|
||||||
});
|
|
||||||
assert(customFilter.clean('This is a hells good test') === 'This is a hells good test');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should tokenize words according to regex word boundaries',function(){
|
|
||||||
assert(filter.clean('what a bitch...fuck you') === 'what a *****...**** you');
|
|
||||||
assert(filter.clean('<p>Don\'t be an asshole</p>') === '<p>Don\'t be an *******</p>');
|
|
||||||
});
|
|
||||||
|
|
||||||
xit('Should filter words that are derivatives of words from the filter blacklist', function() {
|
|
||||||
assert(filter.clean('shitshit') === '********');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Shouldn\'t filter words that aren\'t profane.', function() {
|
|
||||||
assert(filter.clean('hello there') === 'hello there');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,44 +0,0 @@
|
|||||||
require('assert');
|
|
||||||
var Filter = require('../lib/badwords.js'),
|
|
||||||
filter = new Filter(),
|
|
||||||
assert = require('better-assert');
|
|
||||||
|
|
||||||
describe('filter', function(){
|
|
||||||
describe('isProfane',function(){
|
|
||||||
it("Should detect a bad word and return a boolean value",function(){
|
|
||||||
assert(filter.isProfane("ash0le"));
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Should return false when no bad word is detected",function(){
|
|
||||||
assert(filter.isProfane("wife") === false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Should be able to detect a bad word in a sentence",function(){
|
|
||||||
assert(filter.isProfane("that person is an ash0le"));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Filters out special characters appropriately', function() {
|
|
||||||
assert(filter.isProfane("You're an asshole^ you are"));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should detect filtered words from badwords-list', function(){
|
|
||||||
assert(filter.isProfane('willies'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should detect filtered words regardless of type case', function() {
|
|
||||||
var filter = new Filter({
|
|
||||||
list: ['Test']
|
|
||||||
});
|
|
||||||
assert(filter.isProfane('test'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should tokenize words according to regex word boundaries', function() {
|
|
||||||
assert(filter.isProfane("that person is an\nasshole"));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should detect bad word phrases', function () {
|
|
||||||
filter.addWords('oh no');
|
|
||||||
assert(filter.isProfane("oh no! this is profane!"));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,21 +0,0 @@
|
|||||||
require('assert');
|
|
||||||
var Filter = require('../lib/badwords.js'),
|
|
||||||
filter = new Filter(),
|
|
||||||
assert = require('better-assert');
|
|
||||||
|
|
||||||
describe('filter', () => {
|
|
||||||
describe('removeWords',() => {
|
|
||||||
it('Should allow you to remove words from the filter blacklist and no longer filter them (case-insensitive)', () => {
|
|
||||||
filter.removeWords('Hells');
|
|
||||||
assert(filter.clean('This is a hells good test') === 'This is a hells good test');
|
|
||||||
});
|
|
||||||
|
|
||||||
it ('Should allow you to remove an array of words from the filter blacklist and no longer filter them', () => {
|
|
||||||
let removingWords = ['hells', 'sadist'];
|
|
||||||
|
|
||||||
filter = new Filter();
|
|
||||||
filter.removeWords(...removingWords);
|
|
||||||
assert(filter.clean('This is a hells sadist test') === 'This is a hells sadist test');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,12 +0,0 @@
|
|||||||
require('assert');
|
|
||||||
var Filter = require('../lib/badwords.js'),
|
|
||||||
filter = new Filter(),
|
|
||||||
assert = require('better-assert');
|
|
||||||
|
|
||||||
describe('filter', function(){
|
|
||||||
describe('replaceWord',function(){
|
|
||||||
it("Should replace a bad word with asterisks (******)",function(){
|
|
||||||
assert(filter.replaceWord("ash0le") == '******');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,15 +0,0 @@
|
|||||||
lib-cov
|
|
||||||
*.seed
|
|
||||||
*.log
|
|
||||||
*.csv
|
|
||||||
*.dat
|
|
||||||
*.out
|
|
||||||
*.pid
|
|
||||||
*.gz
|
|
||||||
|
|
||||||
pids
|
|
||||||
logs
|
|
||||||
results
|
|
||||||
|
|
||||||
npm-debug.log
|
|
||||||
node_modules/
|
|
@ -1,20 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2013 Maurice Butler
|
|
||||||
|
|
||||||
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:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
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.
|
|
@ -1,4 +0,0 @@
|
|||||||
test:
|
|
||||||
@./node_modules/mocha/bin/_mocha -R $(REPORTER)
|
|
||||||
|
|
||||||
.PHONY: test
|
|
@ -1,57 +0,0 @@
|
|||||||
badwords-list v1.0.0
|
|
||||||
========
|
|
||||||
|
|
||||||
A highly consumable list of bad (profanity) english words based on the nice short and simple list found in [Google's "what do you love" project](http://www.wdyl.com/) made accessable by [Jamie Wilkinson](https://gist.github.com/jamiew) [here](https://gist.github.com/jamiew/1112488)
|
|
||||||
|
|
||||||
Inspired by [badwords](https://github.com/MauriceButler/badwords)
|
|
||||||
|
|
||||||
This data has been exposed as an object that contains
|
|
||||||
|
|
||||||
- an array
|
|
||||||
- an object
|
|
||||||
- a regular expression
|
|
||||||
|
|
||||||
depending on what is required for your purposes.
|
|
||||||
|
|
||||||
|
|
||||||
Install
|
|
||||||
=======
|
|
||||||
|
|
||||||
npm install badwords-list
|
|
||||||
|
|
||||||
Usage
|
|
||||||
=====
|
|
||||||
|
|
||||||
```
|
|
||||||
var list = require('badwords-list'),
|
|
||||||
array = list.array,
|
|
||||||
object = list.object,
|
|
||||||
regex = list.regex;
|
|
||||||
```
|
|
||||||
|
|
||||||
Testing
|
|
||||||
=======
|
|
||||||
|
|
||||||
####Requires
|
|
||||||
- Mocha
|
|
||||||
- better-assert
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
npm test
|
|
||||||
```
|
|
||||||
|
|
||||||
**or**
|
|
||||||
|
|
||||||
```
|
|
||||||
REPORTER=spec make
|
|
||||||
```
|
|
||||||
|
|
||||||
**or**
|
|
||||||
|
|
||||||
```
|
|
||||||
mocha
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
module.exports = ["4r5e", "5h1t", "5hit", "a55", "anal", "anus", "ar5e", "arrse", "arse", "ass", "ass-fucker", "asses", "assfucker", "assfukka", "asshole", "assholes", "asswhole", "a_s_s", "b!tch", "b00bs", "b17ch", "b1tch", "ballbag", "balls", "ballsack", "bastard", "beastial", "beastiality", "bellend", "bestial", "bestiality", "bi+ch", "biatch", "bitch", "bitcher", "bitchers", "bitches", "bitchin", "bitching", "bloody", "blow job", "blowjob", "blowjobs", "boiolas", "bollock", "bollok", "boner", "boob", "boobs", "booobs", "boooobs", "booooobs", "booooooobs", "breasts", "buceta", "bugger", "bum", "bunny fucker", "butt", "butthole", "buttmuch", "buttplug", "c0ck", "c0cksucker", "carpet muncher", "cawk", "chink", "cipa", "cl1t", "clit", "clitoris", "clits", "cnut", "cock", "cock-sucker", "cockface", "cockhead", "cockmunch", "cockmuncher", "cocks", "cocksuck", "cocksucked", "cocksucker", "cocksucking", "cocksucks", "cocksuka", "cocksukka", "cok", "cokmuncher", "coksucka", "coon", "cox", "crap", "cum", "cummer", "cumming", "cums", "cumshot", "cunilingus", "cunillingus", "cunnilingus", "cunt", "cuntlick", "cuntlicker", "cuntlicking", "cunts", "cyalis", "cyberfuc", "cyberfuck", "cyberfucked", "cyberfucker", "cyberfuckers", "cyberfucking", "d1ck", "damn", "dick", "dickhead", "dildo", "dildos", "dink", "dinks", "dirsa", "dlck", "dog-fucker", "doggin", "dogging", "donkeyribber", "doosh", "duche", "dyke", "ejaculate", "ejaculated", "ejaculates", "ejaculating", "ejaculatings", "ejaculation", "ejakulate", "f u c k", "f u c k e r", "f4nny", "fag", "fagging", "faggitt", "faggot", "faggs", "fagot", "fagots", "fags", "fanny", "fannyflaps", "fannyfucker", "fanyy", "fatass", "fcuk", "fcuker", "fcuking", "feck", "fecker", "felching", "fellate", "fellatio", "fingerfuck", "fingerfucked", "fingerfucker", "fingerfuckers", "fingerfucking", "fingerfucks", "fistfuck", "fistfucked", "fistfucker", "fistfuckers", "fistfucking", "fistfuckings", "fistfucks", "flange", "fook", "fooker", "fuck", "fucka", "fucked", "fucker", "fuckers", "fuckhead", "fuckheads", "fuckin", "fucking", "fuckings", "fuckingshitmotherfucker", "fuckme", "fucks", "fuckwhit", "fuckwit", "fudge packer", "fudgepacker", "fuk", "fuker", "fukker", "fukkin", "fuks", "fukwhit", "fukwit", "fux", "fux0r", "f_u_c_k", "gangbang", "gangbanged", "gangbangs", "gaylord", "gaysex", "goatse", "God", "god-dam", "god-damned", "goddamn", "goddamned", "hardcoresex", "hell", "heshe", "hoar", "hoare", "hoer", "homo", "hore", "horniest", "horny", "hotsex", "jack-off", "jackoff", "jap", "jerk-off", "jism", "jiz", "jizm", "jizz", "kawk", "knob", "knobead", "knobed", "knobend", "knobhead", "knobjocky", "knobjokey", "kock", "kondum", "kondums", "kum", "kummer", "kumming", "kums", "kunilingus", "l3i+ch", "l3itch", "labia", "lust", "lusting", "m0f0", "m0fo", "m45terbate", "ma5terb8", "ma5terbate", "masochist", "master-bate", "masterb8", "masterbat*", "masterbat3", "masterbate", "masterbation", "masterbations", "masturbate", "mo-fo", "mof0", "mofo", "mothafuck", "mothafucka", "mothafuckas", "mothafuckaz", "mothafucked", "mothafucker", "mothafuckers", "mothafuckin", "mothafucking", "mothafuckings", "mothafucks", "mother fucker", "motherfuck", "motherfucked", "motherfucker", "motherfuckers", "motherfuckin", "motherfucking", "motherfuckings", "motherfuckka", "motherfucks", "muff", "mutha", "muthafecker", "muthafuckker", "muther", "mutherfucker", "n1gga", "n1gger", "nazi", "nigg3r", "nigg4h", "nigga", "niggah", "niggas", "niggaz", "nigger", "niggers", "nob", "nob jokey", "nobhead", "nobjocky", "nobjokey", "numbnuts", "nutsack", "orgasim", "orgasims", "orgasm", "orgasms", "p0rn", "pawn", "pecker", "penis", "penisfucker", "phonesex", "phuck", "phuk", "phuked", "phuking", "phukked", "phukking", "phuks", "phuq", "pigfucker", "pimpis", "piss", "pissed", "pisser", "pissers", "pisses", "pissflaps", "pissin", "pissing", "pissoff", "poop", "porn", "porno", "pornography", "pornos", "prick", "pricks", "pron", "pube", "pusse", "pussi", "pussies", "pussy", "pussys", "rectum", "retard", "rimjaw", "rimming", "s hit", "s.o.b.", "sadist", "schlong", "screwing", "scroat", "scrote", "scrotum", "semen", "sex", "sh!+", "sh!t", "sh1t", "shag", "shagger", "shaggin", "shagging", "shemale", "shi+", "shit", "shitdick", "shite", "shited", "shitey", "shitfuck", "shitfull", "shithead", "shiting", "shitings", "shits", "shitted", "shitter", "shitters", "shitting", "shittings", "shitty", "skank", "slut", "sluts", "smegma", "smut", "snatch", "son-of-a-bitch", "spac", "spunk", "s_h_i_t", "t1tt1e5", "t1tties", "teets", "teez", "testical", "testicle", "tit", "titfuck", "tits", "titt", "tittie5", "tittiefucker", "titties", "tittyfuck", "tittywank", "titwank", "tosser", "turd", "tw4t", "twat", "twathead", "twatty", "twunt", "twunter", "v14gra", "v1gra", "vagina", "viagra", "vulva", "w00se", "wang", "wank", "wanker", "wanky", "whoar", "whore", "willies", "willy", "xrated", "xxx"];
|
|
@ -1,5 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
object: require('./object'),
|
|
||||||
array: require('./array'),
|
|
||||||
regex: require('./regexp')
|
|
||||||
};
|
|
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
|||||||
module.exports = /\b(4r5e|5h1t|5hit|a55|anal|anus|ar5e|arrse|arse|ass|ass-fucker|asses|assfucker|assfukka|asshole|assholes|asswhole|a_s_s|b!tch|b00bs|b17ch|b1tch|ballbag|balls|ballsack|bastard|beastial|beastiality|bellend|bestial|bestiality|bi\+ch|biatch|bitch|bitcher|bitchers|bitches|bitchin|bitching|bloody|blow job|blowjob|blowjobs|boiolas|bollock|bollok|boner|boob|boobs|booobs|boooobs|booooobs|booooooobs|breasts|buceta|bugger|bum|bunny fucker|butt|butthole|buttmuch|buttplug|c0ck|c0cksucker|carpet muncher|cawk|chink|cipa|cl1t|clit|clitoris|clits|cnut|cock|cock-sucker|cockface|cockhead|cockmunch|cockmuncher|cocks|cocksuck|cocksucked|cocksucker|cocksucking|cocksucks|cocksuka|cocksukka|cok|cokmuncher|coksucka|coon|cox|crap|cum|cummer|cumming|cums|cumshot|cunilingus|cunillingus|cunnilingus|cunt|cuntlick|cuntlicker|cuntlicking|cunts|cyalis|cyberfuc|cyberfuck|cyberfucked|cyberfucker|cyberfuckers|cyberfucking|d1ck|damn|dick|dickhead|dildo|dildos|dink|dinks|dirsa|dlck|dog-fucker|doggin|dogging|donkeyribber|doosh|duche|dyke|ejaculate|ejaculated|ejaculates|ejaculating|ejaculatings|ejaculation|ejakulate|f u c k|f u c k e r|f4nny|fag|fagging|faggitt|faggot|faggs|fagot|fagots|fags|fanny|fannyflaps|fannyfucker|fanyy|fatass|fcuk|fcuker|fcuking|feck|fecker|felching|fellate|fellatio|fingerfuck|fingerfucked|fingerfucker|fingerfuckers|fingerfucking|fingerfucks|fistfuck|fistfucked|fistfucker|fistfuckers|fistfucking|fistfuckings|fistfucks|flange|fook|fooker|fuck|fucka|fucked|fucker|fuckers|fuckhead|fuckheads|fuckin|fucking|fuckings|fuckingshitmotherfucker|fuckme|fucks|fuckwhit|fuckwit|fudge packer|fudgepacker|fuk|fuker|fukker|fukkin|fuks|fukwhit|fukwit|fux|fux0r|f_u_c_k|gangbang|gangbanged|gangbangs|gaylord|gaysex|goatse|God|god-dam|god-damned|goddamn|goddamned|hardcoresex|hell|heshe|hoar|hoare|hoer|homo|hore|horniest|horny|hotsex|jack-off|jackoff|jap|jerk-off|jism|jiz|jizm|jizz|kawk|knob|knobead|knobed|knobend|knobhead|knobjocky|knobjokey|kock|kondum|kondums|kum|kummer|kumming|kums|kunilingus|l3i\+ch|l3itch|labia|lust|lusting|m0f0|m0fo|m45terbate|ma5terb8|ma5terbate|masochist|master-bate|masterb8|masterbat*|masterbat3|masterbate|masterbation|masterbations|masturbate|mo-fo|mof0|mofo|mothafuck|mothafucka|mothafuckas|mothafuckaz|mothafucked|mothafucker|mothafuckers|mothafuckin|mothafucking|mothafuckings|mothafucks|mother fucker|motherfuck|motherfucked|motherfucker|motherfuckers|motherfuckin|motherfucking|motherfuckings|motherfuckka|motherfucks|muff|mutha|muthafecker|muthafuckker|muther|mutherfucker|n1gga|n1gger|nazi|nigg3r|nigg4h|nigga|niggah|niggas|niggaz|nigger|niggers|nob|nob jokey|nobhead|nobjocky|nobjokey|numbnuts|nutsack|orgasim|orgasims|orgasm|orgasms|p0rn|pawn|pecker|penis|penisfucker|phonesex|phuck|phuk|phuked|phuking|phukked|phukking|phuks|phuq|pigfucker|pimpis|piss|pissed|pisser|pissers|pisses|pissflaps|pissin|pissing|pissoff|poop|porn|porno|pornography|pornos|prick|pricks|pron|pube|pusse|pussi|pussies|pussy|pussys|rectum|retard|rimjaw|rimming|s hit|s.o.b.|sadist|schlong|screwing|scroat|scrote|scrotum|semen|sex|sh!\+|sh!t|sh1t|shag|shagger|shaggin|shagging|shemale|shi\+|shit|shitdick|shite|shited|shitey|shitfuck|shitfull|shithead|shiting|shitings|shits|shitted|shitter|shitters|shitting|shittings|shitty|skank|slut|sluts|smegma|smut|snatch|son-of-a-bitch|spac|spunk|s_h_i_t|t1tt1e5|t1tties|teets|teez|testical|testicle|tit|titfuck|tits|titt|tittie5|tittiefucker|titties|tittyfuck|tittywank|titwank|tosser|turd|tw4t|twat|twathead|twatty|twunt|twunter|v14gra|v1gra|vagina|viagra|vulva|w00se|wang|wank|wanker|wanky|whoar|whore|willies|willy|xrated|xxx)\b/gi;
|
|
@ -1,62 +0,0 @@
|
|||||||
{
|
|
||||||
"_from": "badwords-list@^1.0.0",
|
|
||||||
"_id": "badwords-list@1.0.0",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha1-XphW2/E0gqKVw7CzBK+51M/FxXk=",
|
|
||||||
"_location": "/badwords-list",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "range",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "badwords-list@^1.0.0",
|
|
||||||
"name": "badwords-list",
|
|
||||||
"escapedName": "badwords-list",
|
|
||||||
"rawSpec": "^1.0.0",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "^1.0.0"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/bad-words"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/badwords-list/-/badwords-list-1.0.0.tgz",
|
|
||||||
"_shasum": "5e9856dbf13482a295c3b0b304afb9d4cfc5c579",
|
|
||||||
"_spec": "badwords-list@^1.0.0",
|
|
||||||
"_where": "/Users/paolo/Desktop/multiplayer games/tutorials/chat3/node_modules/bad-words",
|
|
||||||
"author": {
|
|
||||||
"name": "Michael Price",
|
|
||||||
"email": "webmech@gmail.com"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/web-mech/badwords-list/issues"
|
|
||||||
},
|
|
||||||
"bundleDependencies": false,
|
|
||||||
"deprecated": false,
|
|
||||||
"description": "A highly consumable list of bad (profanity) english words (forked from badwords)",
|
|
||||||
"devDependencies": {
|
|
||||||
"better-assert": "1.0.0",
|
|
||||||
"mocha": "1.14.0"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/web-mech/badwords-list#readme",
|
|
||||||
"keywords": [
|
|
||||||
"bad",
|
|
||||||
"word",
|
|
||||||
"words",
|
|
||||||
"profanity",
|
|
||||||
"filter",
|
|
||||||
"blacklist",
|
|
||||||
"black",
|
|
||||||
"list",
|
|
||||||
"swear"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"main": "./lib/index",
|
|
||||||
"name": "badwords-list",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+ssh://git@github.com/web-mech/badwords-list.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "mocha -R nyan"
|
|
||||||
},
|
|
||||||
"version": "1.0.0"
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
var assert = require('better-assert');
|
|
||||||
|
|
||||||
describe('filter', function(){
|
|
||||||
it('Should contain property object', function(){
|
|
||||||
var list = require('../lib/index');
|
|
||||||
assert(list.hasOwnProperty('object'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should contain property array', function(){
|
|
||||||
var list = require('../lib/index');
|
|
||||||
assert(list.hasOwnProperty('array'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should contain property regex', function(){
|
|
||||||
var list = require('../lib/index');
|
|
||||||
assert(list.hasOwnProperty('regex'));
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,5 +0,0 @@
|
|||||||
test
|
|
||||||
.gitignore
|
|
||||||
.travis.yml
|
|
||||||
Makefile
|
|
||||||
example.js
|
|
@ -1,21 +0,0 @@
|
|||||||
(MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
|
|
||||||
|
|
||||||
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:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
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.
|
|
@ -1,91 +0,0 @@
|
|||||||
# balanced-match
|
|
||||||
|
|
||||||
Match balanced string pairs, like `{` and `}` or `<b>` and `</b>`. Supports regular expressions as well!
|
|
||||||
|
|
||||||
[![build status](https://secure.travis-ci.org/juliangruber/balanced-match.svg)](http://travis-ci.org/juliangruber/balanced-match)
|
|
||||||
[![downloads](https://img.shields.io/npm/dm/balanced-match.svg)](https://www.npmjs.org/package/balanced-match)
|
|
||||||
|
|
||||||
[![testling badge](https://ci.testling.com/juliangruber/balanced-match.png)](https://ci.testling.com/juliangruber/balanced-match)
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
Get the first matching pair of braces:
|
|
||||||
|
|
||||||
```js
|
|
||||||
var balanced = require('balanced-match');
|
|
||||||
|
|
||||||
console.log(balanced('{', '}', 'pre{in{nested}}post'));
|
|
||||||
console.log(balanced('{', '}', 'pre{first}between{second}post'));
|
|
||||||
console.log(balanced(/\s+\{\s+/, /\s+\}\s+/, 'pre { in{nest} } post'));
|
|
||||||
```
|
|
||||||
|
|
||||||
The matches are:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ node example.js
|
|
||||||
{ start: 3, end: 14, pre: 'pre', body: 'in{nested}', post: 'post' }
|
|
||||||
{ start: 3,
|
|
||||||
end: 9,
|
|
||||||
pre: 'pre',
|
|
||||||
body: 'first',
|
|
||||||
post: 'between{second}post' }
|
|
||||||
{ start: 3, end: 17, pre: 'pre', body: 'in{nest}', post: 'post' }
|
|
||||||
```
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
### var m = balanced(a, b, str)
|
|
||||||
|
|
||||||
For the first non-nested matching pair of `a` and `b` in `str`, return an
|
|
||||||
object with those keys:
|
|
||||||
|
|
||||||
* **start** the index of the first match of `a`
|
|
||||||
* **end** the index of the matching `b`
|
|
||||||
* **pre** the preamble, `a` and `b` not included
|
|
||||||
* **body** the match, `a` and `b` not included
|
|
||||||
* **post** the postscript, `a` and `b` not included
|
|
||||||
|
|
||||||
If there's no match, `undefined` will be returned.
|
|
||||||
|
|
||||||
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `['{', 'a', '']` and `{a}}` will match `['', 'a', '}']`.
|
|
||||||
|
|
||||||
### var r = balanced.range(a, b, str)
|
|
||||||
|
|
||||||
For the first non-nested matching pair of `a` and `b` in `str`, return an
|
|
||||||
array with indexes: `[ <a index>, <b index> ]`.
|
|
||||||
|
|
||||||
If there's no match, `undefined` will be returned.
|
|
||||||
|
|
||||||
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `[ 1, 3 ]` and `{a}}` will match `[0, 2]`.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
With [npm](https://npmjs.org) do:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm install balanced-match
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
(MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
|
|
||||||
|
|
||||||
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:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
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.
|
|
@ -1,59 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
module.exports = balanced;
|
|
||||||
function balanced(a, b, str) {
|
|
||||||
if (a instanceof RegExp) a = maybeMatch(a, str);
|
|
||||||
if (b instanceof RegExp) b = maybeMatch(b, str);
|
|
||||||
|
|
||||||
var r = range(a, b, str);
|
|
||||||
|
|
||||||
return r && {
|
|
||||||
start: r[0],
|
|
||||||
end: r[1],
|
|
||||||
pre: str.slice(0, r[0]),
|
|
||||||
body: str.slice(r[0] + a.length, r[1]),
|
|
||||||
post: str.slice(r[1] + b.length)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function maybeMatch(reg, str) {
|
|
||||||
var m = str.match(reg);
|
|
||||||
return m ? m[0] : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
balanced.range = range;
|
|
||||||
function range(a, b, str) {
|
|
||||||
var begs, beg, left, right, result;
|
|
||||||
var ai = str.indexOf(a);
|
|
||||||
var bi = str.indexOf(b, ai + 1);
|
|
||||||
var i = ai;
|
|
||||||
|
|
||||||
if (ai >= 0 && bi > 0) {
|
|
||||||
begs = [];
|
|
||||||
left = str.length;
|
|
||||||
|
|
||||||
while (i >= 0 && !result) {
|
|
||||||
if (i == ai) {
|
|
||||||
begs.push(i);
|
|
||||||
ai = str.indexOf(a, i + 1);
|
|
||||||
} else if (begs.length == 1) {
|
|
||||||
result = [ begs.pop(), bi ];
|
|
||||||
} else {
|
|
||||||
beg = begs.pop();
|
|
||||||
if (beg < left) {
|
|
||||||
left = beg;
|
|
||||||
right = bi;
|
|
||||||
}
|
|
||||||
|
|
||||||
bi = str.indexOf(b, i + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
i = ai < bi && ai >= 0 ? ai : bi;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (begs.length) {
|
|
||||||
result = [ left, right ];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
@ -1,77 +0,0 @@
|
|||||||
{
|
|
||||||
"_from": "balanced-match@^1.0.0",
|
|
||||||
"_id": "balanced-match@1.0.0",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
|
|
||||||
"_location": "/balanced-match",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "range",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "balanced-match@^1.0.0",
|
|
||||||
"name": "balanced-match",
|
|
||||||
"escapedName": "balanced-match",
|
|
||||||
"rawSpec": "^1.0.0",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "^1.0.0"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/brace-expansion"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
|
||||||
"_shasum": "89b4d199ab2bee49de164ea02b89ce462d71b767",
|
|
||||||
"_spec": "balanced-match@^1.0.0",
|
|
||||||
"_where": "/Users/paolo/Desktop/multiplayer games/likelike-online/node_modules/brace-expansion",
|
|
||||||
"author": {
|
|
||||||
"name": "Julian Gruber",
|
|
||||||
"email": "mail@juliangruber.com",
|
|
||||||
"url": "http://juliangruber.com"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/juliangruber/balanced-match/issues"
|
|
||||||
},
|
|
||||||
"bundleDependencies": false,
|
|
||||||
"dependencies": {},
|
|
||||||
"deprecated": false,
|
|
||||||
"description": "Match balanced character pairs, like \"{\" and \"}\"",
|
|
||||||
"devDependencies": {
|
|
||||||
"matcha": "^0.7.0",
|
|
||||||
"tape": "^4.6.0"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/juliangruber/balanced-match",
|
|
||||||
"keywords": [
|
|
||||||
"match",
|
|
||||||
"regexp",
|
|
||||||
"test",
|
|
||||||
"balanced",
|
|
||||||
"parse"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"main": "index.js",
|
|
||||||
"name": "balanced-match",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/juliangruber/balanced-match.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"bench": "make bench",
|
|
||||||
"test": "make test"
|
|
||||||
},
|
|
||||||
"testling": {
|
|
||||||
"files": "test/*.js",
|
|
||||||
"browsers": [
|
|
||||||
"ie/8..latest",
|
|
||||||
"firefox/20..latest",
|
|
||||||
"firefox/nightly",
|
|
||||||
"chrome/25..latest",
|
|
||||||
"chrome/canary",
|
|
||||||
"opera/12..latest",
|
|
||||||
"opera/next",
|
|
||||||
"safari/5.1..latest",
|
|
||||||
"ipad/6.0..latest",
|
|
||||||
"iphone/6.0..latest",
|
|
||||||
"android-browser/4.2..latest"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"version": "1.0.0"
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
/node_modules/
|
|
||||||
Gruntfile.js
|
|
||||||
/test/
|
|
@ -1,19 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- '0.12'
|
|
||||||
- iojs-1
|
|
||||||
- iojs-2
|
|
||||||
- iojs-3
|
|
||||||
- '4.1'
|
|
||||||
before_script:
|
|
||||||
- npm install
|
|
||||||
before_install: npm install -g npm@'>=2.13.5'
|
|
||||||
deploy:
|
|
||||||
provider: npm
|
|
||||||
email: niklasvh@gmail.com
|
|
||||||
api_key:
|
|
||||||
secure: oHV9ArprTj5WOk7MP1UF7QMJ70huXw+y7xXb5wF4+V2H8Hyfa5TfE0DiOmqrube1WXTeH1FLgq54shp/sJWi47Hkg/GyeoB5NnsPhYEaJkaON9UG5blML+ODiNVsEnq/1kNBQ8e0+0JItMPLGySKyFmuZ3yflulXKS8O88mfINo=
|
|
||||||
on:
|
|
||||||
tags: true
|
|
||||||
branch: master
|
|
||||||
repo: niklasvh/base64-arraybuffer
|
|
@ -1,22 +0,0 @@
|
|||||||
Copyright (c) 2012 Niklas von Hertzen
|
|
||||||
|
|
||||||
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:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
|
||||||
included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
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.
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue