ahmad-module 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ahmad-module might be problematic. Click here for more details.
- package/.bin/sshpk-conv +12 -0
- package/.bin/sshpk-conv.cmd +17 -0
- package/.bin/sshpk-conv.ps1 +28 -0
- package/.bin/sshpk-sign +12 -0
- package/.bin/sshpk-sign.cmd +17 -0
- package/.bin/sshpk-sign.ps1 +28 -0
- package/.bin/sshpk-verify +12 -0
- package/.bin/sshpk-verify.cmd +17 -0
- package/.bin/sshpk-verify.ps1 +28 -0
- package/.bin/uuid +12 -0
- package/.bin/uuid.cmd +17 -0
- package/.bin/uuid.ps1 +28 -0
- package/ajv/.tonic_example.js +20 -0
- package/ajv/LICENSE +22 -0
- package/ajv/README.md +1497 -0
- package/ajv/dist/ajv.bundle.js +7189 -0
- package/ajv/dist/ajv.min.js +3 -0
- package/ajv/dist/ajv.min.js.map +1 -0
- package/ajv/lib/ajv.d.ts +397 -0
- package/ajv/lib/ajv.js +506 -0
- package/ajv/lib/cache.js +26 -0
- package/ajv/lib/compile/async.js +90 -0
- package/ajv/lib/compile/equal.js +5 -0
- package/ajv/lib/compile/error_classes.js +34 -0
- package/ajv/lib/compile/formats.js +142 -0
- package/ajv/lib/compile/index.js +387 -0
- package/ajv/lib/compile/resolve.js +270 -0
- package/ajv/lib/compile/rules.js +66 -0
- package/ajv/lib/compile/schema_obj.js +9 -0
- package/ajv/lib/compile/ucs2length.js +20 -0
- package/ajv/lib/compile/util.js +239 -0
- package/ajv/lib/data.js +49 -0
- package/ajv/lib/definition_schema.js +37 -0
- package/ajv/lib/dot/_limit.jst +113 -0
- package/ajv/lib/dot/_limitItems.jst +12 -0
- package/ajv/lib/dot/_limitLength.jst +12 -0
- package/ajv/lib/dot/_limitProperties.jst +12 -0
- package/ajv/lib/dot/allOf.jst +32 -0
- package/ajv/lib/dot/anyOf.jst +46 -0
- package/ajv/lib/dot/coerce.def +51 -0
- package/ajv/lib/dot/comment.jst +9 -0
- package/ajv/lib/dot/const.jst +11 -0
- package/ajv/lib/dot/contains.jst +55 -0
- package/ajv/lib/dot/custom.jst +191 -0
- package/ajv/lib/dot/defaults.def +47 -0
- package/ajv/lib/dot/definitions.def +203 -0
- package/ajv/lib/dot/dependencies.jst +79 -0
- package/ajv/lib/dot/enum.jst +30 -0
- package/ajv/lib/dot/errors.def +194 -0
- package/ajv/lib/dot/format.jst +106 -0
- package/ajv/lib/dot/if.jst +73 -0
- package/ajv/lib/dot/items.jst +98 -0
- package/ajv/lib/dot/missing.def +39 -0
- package/ajv/lib/dot/multipleOf.jst +22 -0
- package/ajv/lib/dot/not.jst +43 -0
- package/ajv/lib/dot/oneOf.jst +54 -0
- package/ajv/lib/dot/pattern.jst +14 -0
- package/ajv/lib/dot/properties.jst +245 -0
- package/ajv/lib/dot/propertyNames.jst +52 -0
- package/ajv/lib/dot/ref.jst +85 -0
- package/ajv/lib/dot/required.jst +108 -0
- package/ajv/lib/dot/uniqueItems.jst +62 -0
- package/ajv/lib/dot/validate.jst +276 -0
- package/ajv/lib/dotjs/README.md +3 -0
- package/ajv/lib/dotjs/_limit.js +163 -0
- package/ajv/lib/dotjs/_limitItems.js +80 -0
- package/ajv/lib/dotjs/_limitLength.js +85 -0
- package/ajv/lib/dotjs/_limitProperties.js +80 -0
- package/ajv/lib/dotjs/allOf.js +42 -0
- package/ajv/lib/dotjs/anyOf.js +73 -0
- package/ajv/lib/dotjs/comment.js +14 -0
- package/ajv/lib/dotjs/const.js +56 -0
- package/ajv/lib/dotjs/contains.js +81 -0
- package/ajv/lib/dotjs/custom.js +228 -0
- package/ajv/lib/dotjs/dependencies.js +168 -0
- package/ajv/lib/dotjs/enum.js +66 -0
- package/ajv/lib/dotjs/format.js +150 -0
- package/ajv/lib/dotjs/if.js +103 -0
- package/ajv/lib/dotjs/index.js +33 -0
- package/ajv/lib/dotjs/items.js +140 -0
- package/ajv/lib/dotjs/multipleOf.js +80 -0
- package/ajv/lib/dotjs/not.js +84 -0
- package/ajv/lib/dotjs/oneOf.js +73 -0
- package/ajv/lib/dotjs/pattern.js +75 -0
- package/ajv/lib/dotjs/properties.js +335 -0
- package/ajv/lib/dotjs/propertyNames.js +81 -0
- package/ajv/lib/dotjs/ref.js +124 -0
- package/ajv/lib/dotjs/required.js +270 -0
- package/ajv/lib/dotjs/uniqueItems.js +86 -0
- package/ajv/lib/dotjs/validate.js +482 -0
- package/ajv/lib/keyword.js +146 -0
- package/ajv/lib/refs/data.json +17 -0
- package/ajv/lib/refs/json-schema-draft-04.json +149 -0
- package/ajv/lib/refs/json-schema-draft-06.json +154 -0
- package/ajv/lib/refs/json-schema-draft-07.json +168 -0
- package/ajv/lib/refs/json-schema-secure.json +94 -0
- package/ajv/package.json +106 -0
- package/ajv/scripts/.eslintrc.yml +3 -0
- package/ajv/scripts/bundle.js +61 -0
- package/ajv/scripts/compile-dots.js +73 -0
- package/ajv/scripts/info +10 -0
- package/ajv/scripts/prepare-tests +12 -0
- package/ajv/scripts/publish-built-version +32 -0
- package/ajv/scripts/travis-gh-pages +23 -0
- package/asn1/Jenkinsfile +65 -0
- package/asn1/LICENSE +19 -0
- package/asn1/README.md +50 -0
- package/asn1/lib/ber/errors.js +13 -0
- package/asn1/lib/ber/index.js +27 -0
- package/asn1/lib/ber/reader.js +262 -0
- package/asn1/lib/ber/types.js +36 -0
- package/asn1/lib/ber/writer.js +317 -0
- package/asn1/lib/index.js +20 -0
- package/asn1/package.json +31 -0
- package/assert-plus/AUTHORS +6 -0
- package/assert-plus/CHANGES.md +14 -0
- package/assert-plus/README.md +162 -0
- package/assert-plus/assert.js +211 -0
- package/assert-plus/package.json +23 -0
- package/asynckit/LICENSE +21 -0
- package/asynckit/README.md +233 -0
- package/asynckit/bench.js +76 -0
- package/asynckit/index.js +6 -0
- package/asynckit/lib/abort.js +29 -0
- package/asynckit/lib/async.js +34 -0
- package/asynckit/lib/defer.js +26 -0
- package/asynckit/lib/iterate.js +75 -0
- package/asynckit/lib/readable_asynckit.js +91 -0
- package/asynckit/lib/readable_parallel.js +25 -0
- package/asynckit/lib/readable_serial.js +25 -0
- package/asynckit/lib/readable_serial_ordered.js +29 -0
- package/asynckit/lib/state.js +37 -0
- package/asynckit/lib/streamify.js +141 -0
- package/asynckit/lib/terminator.js +29 -0
- package/asynckit/package.json +63 -0
- package/asynckit/parallel.js +43 -0
- package/asynckit/serial.js +17 -0
- package/asynckit/serialOrdered.js +75 -0
- package/asynckit/stream.js +21 -0
- package/aws-sign2/LICENSE +55 -0
- package/aws-sign2/README.md +4 -0
- package/aws-sign2/index.js +212 -0
- package/aws-sign2/package.json +17 -0
- package/aws4/.github/FUNDING.yml +3 -0
- package/aws4/.travis.yml +9 -0
- package/aws4/LICENSE +19 -0
- package/aws4/README.md +183 -0
- package/aws4/aws4.js +373 -0
- package/aws4/lru.js +96 -0
- package/aws4/package.json +17 -0
- package/axios/CHANGELOG.md +775 -0
- package/axios/LICENSE +19 -0
- package/axios/README.md +868 -0
- package/axios/SECURITY.md +5 -0
- package/axios/UPGRADE_GUIDE.md +162 -0
- package/axios/dist/axios.js +2193 -0
- package/axios/dist/axios.map +1 -0
- package/axios/dist/axios.min.js +3 -0
- package/axios/dist/axios.min.map +1 -0
- package/axios/index.d.ts +168 -0
- package/axios/index.js +1 -0
- package/axios/lib/adapters/README.md +37 -0
- package/axios/lib/adapters/http.js +331 -0
- package/axios/lib/adapters/xhr.js +189 -0
- package/axios/lib/axios.js +56 -0
- package/axios/lib/cancel/Cancel.js +19 -0
- package/axios/lib/cancel/CancelToken.js +57 -0
- package/axios/lib/cancel/isCancel.js +5 -0
- package/axios/lib/core/Axios.js +148 -0
- package/axios/lib/core/InterceptorManager.js +54 -0
- package/axios/lib/core/README.md +8 -0
- package/axios/lib/core/buildFullPath.js +20 -0
- package/axios/lib/core/createError.js +18 -0
- package/axios/lib/core/dispatchRequest.js +82 -0
- package/axios/lib/core/enhanceError.js +42 -0
- package/axios/lib/core/mergeConfig.js +87 -0
- package/axios/lib/core/settle.js +25 -0
- package/axios/lib/core/transformData.js +22 -0
- package/axios/lib/defaults.js +134 -0
- package/axios/lib/helpers/README.md +7 -0
- package/axios/lib/helpers/bind.js +11 -0
- package/axios/lib/helpers/buildURL.js +70 -0
- package/axios/lib/helpers/combineURLs.js +14 -0
- package/axios/lib/helpers/cookies.js +53 -0
- package/axios/lib/helpers/deprecatedMethod.js +24 -0
- package/axios/lib/helpers/isAbsoluteURL.js +14 -0
- package/axios/lib/helpers/isAxiosError.js +11 -0
- package/axios/lib/helpers/isURLSameOrigin.js +68 -0
- package/axios/lib/helpers/normalizeHeaderName.js +12 -0
- package/axios/lib/helpers/parseHeaders.js +53 -0
- package/axios/lib/helpers/spread.js +27 -0
- package/axios/lib/helpers/validator.js +105 -0
- package/axios/lib/utils.js +349 -0
- package/axios/package.json +84 -0
- package/bcrypt-pbkdf/CONTRIBUTING.md +13 -0
- package/bcrypt-pbkdf/LICENSE +66 -0
- package/bcrypt-pbkdf/README.md +45 -0
- package/bcrypt-pbkdf/index.js +556 -0
- package/bcrypt-pbkdf/package.json +15 -0
- package/caseless/LICENSE +28 -0
- package/caseless/README.md +45 -0
- package/caseless/index.js +67 -0
- package/caseless/package.json +27 -0
- package/caseless/test.js +67 -0
- package/combined-stream/License +19 -0
- package/combined-stream/Readme.md +138 -0
- package/combined-stream/lib/combined_stream.js +208 -0
- package/combined-stream/package.json +25 -0
- package/combined-stream/yarn.lock +17 -0
- package/core-util-is/LICENSE +19 -0
- package/core-util-is/README.md +3 -0
- package/core-util-is/float.patch +604 -0
- package/core-util-is/lib/util.js +107 -0
- package/core-util-is/package.json +32 -0
- package/core-util-is/test.js +68 -0
- package/dashdash/CHANGES.md +364 -0
- package/dashdash/LICENSE.txt +24 -0
- package/dashdash/README.md +574 -0
- package/dashdash/etc/dashdash.bash_completion.in +389 -0
- package/dashdash/lib/dashdash.js +1055 -0
- package/dashdash/package.json +26 -0
- package/delayed-stream/License +19 -0
- package/delayed-stream/Makefile +7 -0
- package/delayed-stream/Readme.md +141 -0
- package/delayed-stream/lib/delayed_stream.js +107 -0
- package/delayed-stream/package.json +27 -0
- package/ecc-jsbn/LICENSE +21 -0
- package/ecc-jsbn/README.md +8 -0
- package/ecc-jsbn/index.js +58 -0
- package/ecc-jsbn/lib/LICENSE-jsbn +40 -0
- package/ecc-jsbn/lib/ec.js +561 -0
- package/ecc-jsbn/lib/sec.js +170 -0
- package/ecc-jsbn/package.json +40 -0
- package/ecc-jsbn/test.js +14 -0
- package/extend/.editorconfig +20 -0
- package/extend/.eslintrc +17 -0
- package/extend/.jscs.json +175 -0
- package/extend/.travis.yml +230 -0
- package/extend/CHANGELOG.md +83 -0
- package/extend/LICENSE +23 -0
- package/extend/README.md +81 -0
- package/extend/component.json +32 -0
- package/extend/index.js +117 -0
- package/extend/package.json +42 -0
- package/extsprintf/.gitmodules +0 -0
- package/extsprintf/LICENSE +19 -0
- package/extsprintf/Makefile +24 -0
- package/extsprintf/Makefile.targ +285 -0
- package/extsprintf/README.md +46 -0
- package/extsprintf/jsl.node.conf +137 -0
- package/extsprintf/lib/extsprintf.js +183 -0
- package/extsprintf/package.json +14 -0
- package/fast-deep-equal/LICENSE +21 -0
- package/fast-deep-equal/README.md +96 -0
- package/fast-deep-equal/es6/index.d.ts +2 -0
- package/fast-deep-equal/es6/index.js +72 -0
- package/fast-deep-equal/es6/react.d.ts +2 -0
- package/fast-deep-equal/es6/react.js +79 -0
- package/fast-deep-equal/index.d.ts +4 -0
- package/fast-deep-equal/index.js +46 -0
- package/fast-deep-equal/package.json +61 -0
- package/fast-deep-equal/react.d.ts +2 -0
- package/fast-deep-equal/react.js +53 -0
- package/fast-json-stable-stringify/.eslintrc.yml +26 -0
- package/fast-json-stable-stringify/.github/FUNDING.yml +1 -0
- package/fast-json-stable-stringify/.travis.yml +8 -0
- package/fast-json-stable-stringify/LICENSE +21 -0
- package/fast-json-stable-stringify/README.md +131 -0
- package/fast-json-stable-stringify/benchmark/index.js +31 -0
- package/fast-json-stable-stringify/benchmark/test.json +137 -0
- package/fast-json-stable-stringify/example/key_cmp.js +7 -0
- package/fast-json-stable-stringify/example/nested.js +3 -0
- package/fast-json-stable-stringify/example/str.js +3 -0
- package/fast-json-stable-stringify/example/value_cmp.js +7 -0
- package/fast-json-stable-stringify/index.d.ts +4 -0
- package/fast-json-stable-stringify/index.js +59 -0
- package/fast-json-stable-stringify/package.json +52 -0
- package/fast-json-stable-stringify/test/cmp.js +13 -0
- package/fast-json-stable-stringify/test/nested.js +44 -0
- package/fast-json-stable-stringify/test/str.js +46 -0
- package/fast-json-stable-stringify/test/to-json.js +22 -0
- package/follow-redirects/LICENSE +18 -0
- package/follow-redirects/README.md +155 -0
- package/follow-redirects/debug.js +15 -0
- package/follow-redirects/http.js +1 -0
- package/follow-redirects/https.js +1 -0
- package/follow-redirects/index.js +598 -0
- package/follow-redirects/package.json +59 -0
- package/forever-agent/LICENSE +55 -0
- package/forever-agent/README.md +4 -0
- package/forever-agent/index.js +138 -0
- package/forever-agent/package.json +17 -0
- package/form-data/License +19 -0
- package/form-data/README.md +234 -0
- package/form-data/README.md.bak +234 -0
- package/form-data/lib/browser.js +2 -0
- package/form-data/lib/form_data.js +457 -0
- package/form-data/lib/populate.js +10 -0
- package/form-data/package.json +65 -0
- package/form-data/yarn.lock +2662 -0
- package/getpass/.travis.yml +9 -0
- package/getpass/LICENSE +18 -0
- package/getpass/README.md +32 -0
- package/getpass/lib/index.js +123 -0
- package/getpass/package.json +18 -0
- package/har-schema/LICENSE +13 -0
- package/har-schema/README.md +49 -0
- package/har-schema/lib/afterRequest.json +30 -0
- package/har-schema/lib/beforeRequest.json +30 -0
- package/har-schema/lib/browser.json +20 -0
- package/har-schema/lib/cache.json +21 -0
- package/har-schema/lib/content.json +29 -0
- package/har-schema/lib/cookie.json +36 -0
- package/har-schema/lib/creator.json +20 -0
- package/har-schema/lib/entry.json +53 -0
- package/har-schema/lib/har.json +13 -0
- package/har-schema/lib/header.json +20 -0
- package/har-schema/lib/index.js +22 -0
- package/har-schema/lib/log.json +36 -0
- package/har-schema/lib/page.json +32 -0
- package/har-schema/lib/pageTimings.json +18 -0
- package/har-schema/lib/postData.json +43 -0
- package/har-schema/lib/query.json +20 -0
- package/har-schema/lib/request.json +57 -0
- package/har-schema/lib/response.json +54 -0
- package/har-schema/lib/timings.json +42 -0
- package/har-schema/package.json +54 -0
- package/har-validator/LICENSE +9 -0
- package/har-validator/README.md +43 -0
- package/har-validator/lib/async.js +105 -0
- package/har-validator/lib/error.js +17 -0
- package/har-validator/lib/promise.js +102 -0
- package/har-validator/package.json +43 -0
- package/http-signature/.dir-locals.el +6 -0
- package/http-signature/CHANGES.md +46 -0
- package/http-signature/LICENSE +18 -0
- package/http-signature/README.md +79 -0
- package/http-signature/http_signing.md +363 -0
- package/http-signature/lib/index.js +29 -0
- package/http-signature/lib/parser.js +315 -0
- package/http-signature/lib/signer.js +401 -0
- package/http-signature/lib/utils.js +112 -0
- package/http-signature/lib/verify.js +88 -0
- package/http-signature/package.json +39 -0
- package/is-typedarray/LICENSE.md +18 -0
- package/is-typedarray/README.md +16 -0
- package/is-typedarray/index.js +41 -0
- package/is-typedarray/package.json +30 -0
- package/is-typedarray/test.js +34 -0
- package/isstream/.jshintrc +59 -0
- package/isstream/.travis.yml +12 -0
- package/isstream/LICENSE.md +11 -0
- package/isstream/README.md +66 -0
- package/isstream/isstream.js +27 -0
- package/isstream/package.json +33 -0
- package/isstream/test.js +168 -0
- package/jsbn/LICENSE +40 -0
- package/jsbn/README.md +175 -0
- package/jsbn/example.html +12 -0
- package/jsbn/example.js +3 -0
- package/jsbn/index.js +1357 -0
- package/jsbn/package.json +21 -0
- package/json-schema/LICENSE +195 -0
- package/json-schema/README.md +3 -0
- package/json-schema/lib/links.js +65 -0
- package/json-schema/lib/validate.js +271 -0
- package/json-schema/package.json +24 -0
- package/json-schema-traverse/.eslintrc.yml +27 -0
- package/json-schema-traverse/.travis.yml +8 -0
- package/json-schema-traverse/LICENSE +21 -0
- package/json-schema-traverse/README.md +83 -0
- package/json-schema-traverse/index.js +89 -0
- package/json-schema-traverse/package.json +43 -0
- package/json-schema-traverse/spec/.eslintrc.yml +6 -0
- package/json-schema-traverse/spec/fixtures/schema.js +125 -0
- package/json-schema-traverse/spec/index.spec.js +171 -0
- package/json-stringify-safe/CHANGELOG.md +14 -0
- package/json-stringify-safe/LICENSE +15 -0
- package/json-stringify-safe/Makefile +35 -0
- package/json-stringify-safe/README.md +52 -0
- package/json-stringify-safe/package.json +31 -0
- package/json-stringify-safe/stringify.js +27 -0
- package/json-stringify-safe/test/mocha.opts +2 -0
- package/json-stringify-safe/test/stringify_test.js +246 -0
- package/jsprim/CHANGES.md +53 -0
- package/jsprim/CONTRIBUTING.md +19 -0
- package/jsprim/LICENSE +19 -0
- package/jsprim/README.md +287 -0
- package/jsprim/lib/jsprim.js +735 -0
- package/jsprim/package.json +20 -0
- package/m3u8stream/LICENSE +21 -0
- package/m3u8stream/README.md +81 -0
- package/m3u8stream/dist/dash-mpd-parser.d.ts +11 -0
- package/m3u8stream/dist/dash-mpd-parser.js +183 -0
- package/m3u8stream/dist/dash-mpd-parser.js.map +1 -0
- package/m3u8stream/dist/index.d.ts +31 -0
- package/m3u8stream/dist/index.js +180 -0
- package/m3u8stream/dist/index.js.map +1 -0
- package/m3u8stream/dist/m3u8-parser.d.ts +18 -0
- package/m3u8stream/dist/m3u8-parser.js +111 -0
- package/m3u8stream/dist/m3u8-parser.js.map +1 -0
- package/m3u8stream/dist/parse-time.d.ts +16 -0
- package/m3u8stream/dist/parse-time.js +59 -0
- package/m3u8stream/dist/parse-time.js.map +1 -0
- package/m3u8stream/dist/parser.d.ts +19 -0
- package/m3u8stream/dist/parser.js +3 -0
- package/m3u8stream/dist/parser.js.map +1 -0
- package/m3u8stream/dist/queue.d.ts +39 -0
- package/m3u8stream/dist/queue.js +58 -0
- package/m3u8stream/dist/queue.js.map +1 -0
- package/m3u8stream/node_modules/sax/LICENSE +41 -0
- package/m3u8stream/node_modules/sax/README.md +225 -0
- package/m3u8stream/node_modules/sax/lib/sax.js +1565 -0
- package/m3u8stream/node_modules/sax/package.json +25 -0
- package/m3u8stream/package.json +54 -0
- package/mime-db/HISTORY.md +507 -0
- package/mime-db/LICENSE +23 -0
- package/mime-db/README.md +100 -0
- package/mime-db/db.json +8519 -0
- package/mime-db/index.js +12 -0
- package/mime-db/package.json +60 -0
- package/mime-types/HISTORY.md +397 -0
- package/mime-types/LICENSE +23 -0
- package/mime-types/README.md +113 -0
- package/mime-types/index.js +188 -0
- package/mime-types/package.json +44 -0
- package/miniget/LICENSE +21 -0
- package/miniget/README.md +111 -0
- package/miniget/dist/index.d.ts +65 -0
- package/miniget/dist/index.js +281 -0
- package/miniget/dist/index.js.map +1 -0
- package/miniget/package.json +49 -0
- package/oauth-sign/LICENSE +55 -0
- package/oauth-sign/README.md +11 -0
- package/oauth-sign/index.js +146 -0
- package/oauth-sign/package.json +23 -0
- package/package.json +11 -0
- package/performance-now/.tm_properties +7 -0
- package/performance-now/.travis.yml +6 -0
- package/performance-now/README.md +30 -0
- package/performance-now/lib/performance-now.js +36 -0
- package/performance-now/lib/performance-now.js.map +10 -0
- package/performance-now/license.txt +7 -0
- package/performance-now/package.json +35 -0
- package/performance-now/src/index.d.ts +8 -0
- package/performance-now/src/performance-now.coffee +17 -0
- package/performance-now/test/mocha.opts +3 -0
- package/performance-now/test/performance-now.coffee +43 -0
- package/performance-now/test/scripts/delayed-call.coffee +11 -0
- package/performance-now/test/scripts/delayed-require.coffee +12 -0
- package/performance-now/test/scripts/difference.coffee +6 -0
- package/performance-now/test/scripts/initial-value.coffee +10 -0
- package/performance-now/test/scripts.coffee +27 -0
- package/psl/.env +0 -0
- package/psl/LICENSE +9 -0
- package/psl/README.md +211 -0
- package/psl/browserstack-logo.svg +90 -0
- package/psl/data/rules.json +9376 -0
- package/psl/dist/psl.js +10187 -0
- package/psl/dist/psl.min.js +1 -0
- package/psl/index.js +269 -0
- package/psl/package.json +43 -0
- package/punycode/LICENSE-MIT.txt +20 -0
- package/punycode/README.md +122 -0
- package/punycode/package.json +58 -0
- package/punycode/punycode.es6.js +441 -0
- package/punycode/punycode.js +440 -0
- package/qs/.editorconfig +43 -0
- package/qs/.eslintrc +37 -0
- package/qs/.github/FUNDING.yml +12 -0
- package/qs/.nycrc +13 -0
- package/qs/CHANGELOG.md +250 -0
- package/qs/LICENSE.md +29 -0
- package/qs/README.md +510 -0
- package/qs/bower.json +21 -0
- package/qs/component.json +15 -0
- package/qs/dist/qs.js +648 -0
- package/qs/lib/formats.js +18 -0
- package/qs/lib/index.js +11 -0
- package/qs/lib/parse.js +175 -0
- package/qs/lib/stringify.js +217 -0
- package/qs/lib/utils.js +215 -0
- package/qs/package.json +54 -0
- package/qs/test/index.js +7 -0
- package/qs/test/parse.js +649 -0
- package/qs/test/stringify.js +642 -0
- package/qs/test/utils.js +65 -0
- package/request/CHANGELOG.md +717 -0
- package/request/LICENSE +55 -0
- package/request/README.md +1133 -0
- package/request/index.js +155 -0
- package/request/lib/auth.js +167 -0
- package/request/lib/cookies.js +38 -0
- package/request/lib/getProxyFromURI.js +79 -0
- package/request/lib/har.js +205 -0
- package/request/lib/hawk.js +89 -0
- package/request/lib/helpers.js +66 -0
- package/request/lib/multipart.js +112 -0
- package/request/lib/oauth.js +148 -0
- package/request/lib/querystring.js +50 -0
- package/request/lib/redirect.js +154 -0
- package/request/lib/tunnel.js +175 -0
- package/request/package.json +86 -0
- package/request/request.js +1553 -0
- package/safe-buffer/LICENSE +21 -0
- package/safe-buffer/README.md +584 -0
- package/safe-buffer/index.d.ts +187 -0
- package/safe-buffer/index.js +65 -0
- package/safe-buffer/package.json +51 -0
- package/safer-buffer/LICENSE +21 -0
- package/safer-buffer/Porting-Buffer.md +268 -0
- package/safer-buffer/Readme.md +156 -0
- package/safer-buffer/dangerous.js +58 -0
- package/safer-buffer/package.json +34 -0
- package/safer-buffer/safer.js +77 -0
- package/safer-buffer/tests.js +406 -0
- package/sax/AUTHORS +10 -0
- package/sax/LICENSE +32 -0
- package/sax/LICENSE-W3C.html +188 -0
- package/sax/README.md +216 -0
- package/sax/component.json +12 -0
- package/sax/examples/big-not-pretty.xml +8002 -0
- package/sax/examples/example.js +29 -0
- package/sax/examples/get-products.js +58 -0
- package/sax/examples/hello-world.js +4 -0
- package/sax/examples/not-pretty.xml +8 -0
- package/sax/examples/pretty-print.js +74 -0
- package/sax/examples/shopping.xml +2 -0
- package/sax/examples/strict.dtd +870 -0
- package/sax/examples/test.html +15 -0
- package/sax/examples/test.xml +1254 -0
- package/sax/lib/sax.js +1355 -0
- package/sax/package.json +12 -0
- package/sax/test/attribute-name.js +33 -0
- package/sax/test/attribute-no-space.js +75 -0
- package/sax/test/buffer-overrun.js +26 -0
- package/sax/test/case.js +50 -0
- package/sax/test/cdata-chunked.js +11 -0
- package/sax/test/cdata-end-split.js +15 -0
- package/sax/test/cdata-fake-end.js +28 -0
- package/sax/test/cdata-multiple.js +15 -0
- package/sax/test/cdata.js +10 -0
- package/sax/test/cyrillic.js +8 -0
- package/sax/test/duplicate-attribute.js +13 -0
- package/sax/test/end_empty_stream.js +5 -0
- package/sax/test/entities.js +10 -0
- package/sax/test/entity-mega.js +16 -0
- package/sax/test/flush.js +13 -0
- package/sax/test/index.js +86 -0
- package/sax/test/issue-23.js +43 -0
- package/sax/test/issue-30.js +24 -0
- package/sax/test/issue-35.js +15 -0
- package/sax/test/issue-47.js +12 -0
- package/sax/test/issue-49.js +31 -0
- package/sax/test/issue-84.js +13 -0
- package/sax/test/parser-position.js +28 -0
- package/sax/test/script-close-better.js +12 -0
- package/sax/test/script.js +12 -0
- package/sax/test/self-closing-child-strict.js +44 -0
- package/sax/test/self-closing-child.js +44 -0
- package/sax/test/self-closing-tag.js +25 -0
- package/sax/test/stray-ending.js +17 -0
- package/sax/test/trailing-attribute-no-value.js +10 -0
- package/sax/test/trailing-non-whitespace.js +18 -0
- package/sax/test/unclosed-root.js +11 -0
- package/sax/test/unquoted.js +18 -0
- package/sax/test/utf8-split.js +32 -0
- package/sax/test/xmlns-as-tag-name.js +15 -0
- package/sax/test/xmlns-issue-41.js +68 -0
- package/sax/test/xmlns-rebinding.js +63 -0
- package/sax/test/xmlns-strict.js +74 -0
- package/sax/test/xmlns-unbound-element.js +33 -0
- package/sax/test/xmlns-unbound.js +15 -0
- package/sax/test/xmlns-xml-default-ns.js +31 -0
- package/sax/test/xmlns-xml-default-prefix-attribute.js +36 -0
- package/sax/test/xmlns-xml-default-prefix.js +21 -0
- package/sax/test/xmlns-xml-default-redefine.js +41 -0
- package/simple-csv-reader/.editorconfig +8 -0
- package/simple-csv-reader/LICENSE +21 -0
- package/simple-csv-reader/README.md +32 -0
- package/simple-csv-reader/dist/simple-csv-reader.min.js +2 -0
- package/simple-csv-reader/dist/simple-csv-reader.min.js.map +1 -0
- package/simple-csv-reader/gulpfile.js +26 -0
- package/simple-csv-reader/index.js +131 -0
- package/simple-csv-reader/package.json +38 -0
- package/sshpk/.travis.yml +11 -0
- package/sshpk/Jenkinsfile +86 -0
- package/sshpk/LICENSE +18 -0
- package/sshpk/README.md +804 -0
- package/sshpk/bin/sshpk-conv +243 -0
- package/sshpk/bin/sshpk-sign +191 -0
- package/sshpk/bin/sshpk-verify +167 -0
- package/sshpk/lib/algs.js +168 -0
- package/sshpk/lib/certificate.js +410 -0
- package/sshpk/lib/dhe.js +397 -0
- package/sshpk/lib/ed-compat.js +92 -0
- package/sshpk/lib/errors.js +84 -0
- package/sshpk/lib/fingerprint.js +220 -0
- package/sshpk/lib/formats/auto.js +124 -0
- package/sshpk/lib/formats/dnssec.js +287 -0
- package/sshpk/lib/formats/openssh-cert.js +352 -0
- package/sshpk/lib/formats/pem.js +290 -0
- package/sshpk/lib/formats/pkcs1.js +373 -0
- package/sshpk/lib/formats/pkcs8.js +631 -0
- package/sshpk/lib/formats/putty.js +194 -0
- package/sshpk/lib/formats/rfc4253.js +166 -0
- package/sshpk/lib/formats/ssh-private.js +262 -0
- package/sshpk/lib/formats/ssh.js +115 -0
- package/sshpk/lib/formats/x509-pem.js +88 -0
- package/sshpk/lib/formats/x509.js +752 -0
- package/sshpk/lib/identity.js +373 -0
- package/sshpk/lib/index.js +40 -0
- package/sshpk/lib/key.js +294 -0
- package/sshpk/lib/private-key.js +247 -0
- package/sshpk/lib/signature.js +314 -0
- package/sshpk/lib/ssh-buffer.js +149 -0
- package/sshpk/lib/utils.js +404 -0
- package/sshpk/man/man1/sshpk-conv.1 +135 -0
- package/sshpk/man/man1/sshpk-sign.1 +81 -0
- package/sshpk/man/man1/sshpk-verify.1 +68 -0
- package/sshpk/package.json +60 -0
- package/tough-cookie/LICENSE +12 -0
- package/tough-cookie/README.md +527 -0
- package/tough-cookie/lib/cookie.js +1482 -0
- package/tough-cookie/lib/memstore.js +181 -0
- package/tough-cookie/lib/pathMatch.js +61 -0
- package/tough-cookie/lib/permuteDomain.js +56 -0
- package/tough-cookie/lib/pubsuffix-psl.js +38 -0
- package/tough-cookie/lib/store.js +75 -0
- package/tough-cookie/lib/version.js +2 -0
- package/tough-cookie/package.json +78 -0
- package/tunnel-agent/LICENSE +55 -0
- package/tunnel-agent/README.md +4 -0
- package/tunnel-agent/index.js +244 -0
- package/tunnel-agent/package.json +22 -0
- package/tweetnacl/AUTHORS.md +28 -0
- package/tweetnacl/CHANGELOG.md +221 -0
- package/tweetnacl/LICENSE +24 -0
- package/tweetnacl/PULL_REQUEST_TEMPLATE.md +20 -0
- package/tweetnacl/README.md +459 -0
- package/tweetnacl/nacl-fast.js +2388 -0
- package/tweetnacl/nacl-fast.min.js +2 -0
- package/tweetnacl/nacl.d.ts +98 -0
- package/tweetnacl/nacl.js +1175 -0
- package/tweetnacl/nacl.min.js +1 -0
- package/tweetnacl/package.json +58 -0
- package/uri-js/LICENSE +11 -0
- package/uri-js/README.md +203 -0
- package/uri-js/dist/es5/uri.all.d.ts +59 -0
- package/uri-js/dist/es5/uri.all.js +1443 -0
- package/uri-js/dist/es5/uri.all.js.map +1 -0
- package/uri-js/dist/es5/uri.all.min.d.ts +59 -0
- package/uri-js/dist/es5/uri.all.min.js +3 -0
- package/uri-js/dist/es5/uri.all.min.js.map +1 -0
- package/uri-js/dist/esnext/index.d.ts +1 -0
- package/uri-js/dist/esnext/index.js +17 -0
- package/uri-js/dist/esnext/index.js.map +1 -0
- package/uri-js/dist/esnext/regexps-iri.d.ts +3 -0
- package/uri-js/dist/esnext/regexps-iri.js +3 -0
- package/uri-js/dist/esnext/regexps-iri.js.map +1 -0
- package/uri-js/dist/esnext/regexps-uri.d.ts +4 -0
- package/uri-js/dist/esnext/regexps-uri.js +42 -0
- package/uri-js/dist/esnext/regexps-uri.js.map +1 -0
- package/uri-js/dist/esnext/schemes/http.d.ts +3 -0
- package/uri-js/dist/esnext/schemes/http.js +28 -0
- package/uri-js/dist/esnext/schemes/http.js.map +1 -0
- package/uri-js/dist/esnext/schemes/https.d.ts +3 -0
- package/uri-js/dist/esnext/schemes/https.js +9 -0
- package/uri-js/dist/esnext/schemes/https.js.map +1 -0
- package/uri-js/dist/esnext/schemes/mailto.d.ts +12 -0
- package/uri-js/dist/esnext/schemes/mailto.js +148 -0
- package/uri-js/dist/esnext/schemes/mailto.js.map +1 -0
- package/uri-js/dist/esnext/schemes/urn-uuid.d.ts +7 -0
- package/uri-js/dist/esnext/schemes/urn-uuid.js +23 -0
- package/uri-js/dist/esnext/schemes/urn-uuid.js.map +1 -0
- package/uri-js/dist/esnext/schemes/urn.d.ts +10 -0
- package/uri-js/dist/esnext/schemes/urn.js +49 -0
- package/uri-js/dist/esnext/schemes/urn.js.map +1 -0
- package/uri-js/dist/esnext/schemes/ws.d.ts +7 -0
- package/uri-js/dist/esnext/schemes/ws.js +41 -0
- package/uri-js/dist/esnext/schemes/ws.js.map +1 -0
- package/uri-js/dist/esnext/schemes/wss.d.ts +3 -0
- package/uri-js/dist/esnext/schemes/wss.js +9 -0
- package/uri-js/dist/esnext/schemes/wss.js.map +1 -0
- package/uri-js/dist/esnext/uri.d.ts +59 -0
- package/uri-js/dist/esnext/uri.js +480 -0
- package/uri-js/dist/esnext/uri.js.map +1 -0
- package/uri-js/dist/esnext/util.d.ts +6 -0
- package/uri-js/dist/esnext/util.js +36 -0
- package/uri-js/dist/esnext/util.js.map +1 -0
- package/uri-js/package.json +77 -0
- package/uri-js/yarn.lock +2558 -0
- package/uuid/AUTHORS +5 -0
- package/uuid/CHANGELOG.md +119 -0
- package/uuid/LICENSE.md +21 -0
- package/uuid/README.md +276 -0
- package/uuid/bin/uuid +65 -0
- package/uuid/index.js +8 -0
- package/uuid/lib/bytesToUuid.js +26 -0
- package/uuid/lib/md5-browser.js +216 -0
- package/uuid/lib/md5.js +25 -0
- package/uuid/lib/rng-browser.js +34 -0
- package/uuid/lib/rng.js +8 -0
- package/uuid/lib/sha1-browser.js +89 -0
- package/uuid/lib/sha1.js +25 -0
- package/uuid/lib/v35.js +57 -0
- package/uuid/package.json +49 -0
- package/uuid/v1.js +109 -0
- package/uuid/v3.js +4 -0
- package/uuid/v4.js +29 -0
- package/uuid/v5.js +3 -0
- package/verror/CHANGES.md +28 -0
- package/verror/CONTRIBUTING.md +19 -0
- package/verror/LICENSE +19 -0
- package/verror/README.md +528 -0
- package/verror/lib/verror.js +451 -0
- package/verror/package.json +22 -0
- package/xml2js/.travis.yml +5 -0
- package/xml2js/83.coffee +6 -0
- package/xml2js/LICENSE +19 -0
- package/xml2js/README.md +248 -0
- package/xml2js/canon.xml +482 -0
- package/xml2js/lib/xml2js.js +299 -0
- package/xml2js/package.json +47 -0
- package/xml2js/text.coffee +11 -0
- package/xml2js/text.xml +485 -0
- package/youtube-search/.travis.yml +5 -0
- package/youtube-search/README.md +61 -0
- package/youtube-search/index.d.ts +77 -0
- package/youtube-search/index.js +111 -0
- package/youtube-search/package.json +29 -0
- package/youtube-search/tests/test-search.js +32 -0
- package/ytdl-core/LICENSE +21 -0
- package/ytdl-core/README.md +238 -0
- package/ytdl-core/lib/cache.js +54 -0
- package/ytdl-core/lib/format-utils.js +250 -0
- package/ytdl-core/lib/formats.js +524 -0
- package/ytdl-core/lib/index.js +214 -0
- package/ytdl-core/lib/info-extras.js +365 -0
- package/ytdl-core/lib/info.js +495 -0
- package/ytdl-core/lib/sig.js +122 -0
- package/ytdl-core/lib/url-utils.js +91 -0
- package/ytdl-core/lib/utils.js +286 -0
- package/ytdl-core/node_modules/sax/LICENSE +41 -0
- package/ytdl-core/node_modules/sax/README.md +225 -0
- package/ytdl-core/node_modules/sax/lib/sax.js +1565 -0
- package/ytdl-core/node_modules/sax/package.json +25 -0
- package/ytdl-core/package.json +61 -0
- package/ytdl-core/typings/index.d.ts +426 -0
- package/ytdl-getinfo/.travis.yml +3 -0
- package/ytdl-getinfo/README.md +77 -0
- package/ytdl-getinfo/index.js +105 -0
- package/ytdl-getinfo/package.json +33 -0
- package/ytdl-getinfo/playlist.js +50 -0
- package/ytdl-getinfo/test/test.js +68 -0
- package/ytdl-getinfo/updater.js +42 -0
- package/ytdl-getinfo/yarn.lock +533 -0
- package/ytdl-getinfo/ytdl/.gitkeep +0 -0
- package/ytdl-getinfo/ytdl/youtube-dl.exe +0 -0
@@ -0,0 +1,1055 @@
|
|
1
|
+
/**
|
2
|
+
* dashdash - A light, featureful and explicit option parsing library for
|
3
|
+
* node.js.
|
4
|
+
*/
|
5
|
+
// vim: set ts=4 sts=4 sw=4 et:
|
6
|
+
|
7
|
+
var assert = require('assert-plus');
|
8
|
+
var format = require('util').format;
|
9
|
+
var fs = require('fs');
|
10
|
+
var path = require('path');
|
11
|
+
|
12
|
+
|
13
|
+
var DEBUG = true;
|
14
|
+
if (DEBUG) {
|
15
|
+
var debug = console.warn;
|
16
|
+
} else {
|
17
|
+
var debug = function () {};
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
// ---- internal support stuff
|
23
|
+
|
24
|
+
// Replace {{variable}} in `s` with the template data in `d`.
|
25
|
+
function renderTemplate(s, d) {
|
26
|
+
return s.replace(/{{([a-zA-Z]+)}}/g, function (match, key) {
|
27
|
+
return d.hasOwnProperty(key) ? d[key] : match;
|
28
|
+
});
|
29
|
+
}
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Return a shallow copy of the given object;
|
33
|
+
*/
|
34
|
+
function shallowCopy(obj) {
|
35
|
+
if (!obj) {
|
36
|
+
return (obj);
|
37
|
+
}
|
38
|
+
var copy = {};
|
39
|
+
Object.keys(obj).forEach(function (k) {
|
40
|
+
copy[k] = obj[k];
|
41
|
+
});
|
42
|
+
return (copy);
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
function space(n) {
|
47
|
+
var s = '';
|
48
|
+
for (var i = 0; i < n; i++) {
|
49
|
+
s += ' ';
|
50
|
+
}
|
51
|
+
return s;
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
function makeIndent(arg, deflen, name) {
|
56
|
+
if (arg === null || arg === undefined)
|
57
|
+
return space(deflen);
|
58
|
+
else if (typeof (arg) === 'number')
|
59
|
+
return space(arg);
|
60
|
+
else if (typeof (arg) === 'string')
|
61
|
+
return arg;
|
62
|
+
else
|
63
|
+
assert.fail('invalid "' + name + '": not a string or number: ' + arg);
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
/**
|
68
|
+
* Return an array of lines wrapping the given text to the given width.
|
69
|
+
* This splits on whitespace. Single tokens longer than `width` are not
|
70
|
+
* broken up.
|
71
|
+
*/
|
72
|
+
function textwrap(s, width) {
|
73
|
+
var words = s.trim().split(/\s+/);
|
74
|
+
var lines = [];
|
75
|
+
var line = '';
|
76
|
+
words.forEach(function (w) {
|
77
|
+
var newLength = line.length + w.length;
|
78
|
+
if (line.length > 0)
|
79
|
+
newLength += 1;
|
80
|
+
if (newLength > width) {
|
81
|
+
lines.push(line);
|
82
|
+
line = '';
|
83
|
+
}
|
84
|
+
if (line.length > 0)
|
85
|
+
line += ' ';
|
86
|
+
line += w;
|
87
|
+
});
|
88
|
+
lines.push(line);
|
89
|
+
return lines;
|
90
|
+
}
|
91
|
+
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Transform an option name to a "key" that is used as the field
|
95
|
+
* on the `opts` object returned from `<parser>.parse()`.
|
96
|
+
*
|
97
|
+
* Transformations:
|
98
|
+
* - '-' -> '_': This allow one to use hyphen in option names (common)
|
99
|
+
* but not have to do silly things like `opt["dry-run"]` to access the
|
100
|
+
* parsed results.
|
101
|
+
*/
|
102
|
+
function optionKeyFromName(name) {
|
103
|
+
return name.replace(/-/g, '_');
|
104
|
+
}
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
// ---- Option types
|
109
|
+
|
110
|
+
function parseBool(option, optstr, arg) {
|
111
|
+
return Boolean(arg);
|
112
|
+
}
|
113
|
+
|
114
|
+
function parseString(option, optstr, arg) {
|
115
|
+
assert.string(arg, 'arg');
|
116
|
+
return arg;
|
117
|
+
}
|
118
|
+
|
119
|
+
function parseNumber(option, optstr, arg) {
|
120
|
+
assert.string(arg, 'arg');
|
121
|
+
var num = Number(arg);
|
122
|
+
if (isNaN(num)) {
|
123
|
+
throw new Error(format('arg for "%s" is not a number: "%s"',
|
124
|
+
optstr, arg));
|
125
|
+
}
|
126
|
+
return num;
|
127
|
+
}
|
128
|
+
|
129
|
+
function parseInteger(option, optstr, arg) {
|
130
|
+
assert.string(arg, 'arg');
|
131
|
+
var num = Number(arg);
|
132
|
+
if (!/^[0-9-]+$/.test(arg) || isNaN(num)) {
|
133
|
+
throw new Error(format('arg for "%s" is not an integer: "%s"',
|
134
|
+
optstr, arg));
|
135
|
+
}
|
136
|
+
return num;
|
137
|
+
}
|
138
|
+
|
139
|
+
function parsePositiveInteger(option, optstr, arg) {
|
140
|
+
assert.string(arg, 'arg');
|
141
|
+
var num = Number(arg);
|
142
|
+
if (!/^[0-9]+$/.test(arg) || isNaN(num) || num === 0) {
|
143
|
+
throw new Error(format('arg for "%s" is not a positive integer: "%s"',
|
144
|
+
optstr, arg));
|
145
|
+
}
|
146
|
+
return num;
|
147
|
+
}
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Supported date args:
|
151
|
+
* - epoch second times (e.g. 1396031701)
|
152
|
+
* - ISO 8601 format: YYYY-MM-DD[THH:MM:SS[.sss][Z]]
|
153
|
+
* 2014-03-28T18:35:01.489Z
|
154
|
+
* 2014-03-28T18:35:01.489
|
155
|
+
* 2014-03-28T18:35:01Z
|
156
|
+
* 2014-03-28T18:35:01
|
157
|
+
* 2014-03-28
|
158
|
+
*/
|
159
|
+
function parseDate(option, optstr, arg) {
|
160
|
+
assert.string(arg, 'arg');
|
161
|
+
var date;
|
162
|
+
if (/^\d+$/.test(arg)) {
|
163
|
+
// epoch seconds
|
164
|
+
date = new Date(Number(arg) * 1000);
|
165
|
+
/* JSSTYLED */
|
166
|
+
} else if (/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?Z?)?$/i.test(arg)) {
|
167
|
+
// ISO 8601 format
|
168
|
+
date = new Date(arg);
|
169
|
+
} else {
|
170
|
+
throw new Error(format('arg for "%s" is not a valid date format: "%s"',
|
171
|
+
optstr, arg));
|
172
|
+
}
|
173
|
+
if (date.toString() === 'Invalid Date') {
|
174
|
+
throw new Error(format('arg for "%s" is an invalid date: "%s"',
|
175
|
+
optstr, arg));
|
176
|
+
}
|
177
|
+
return date;
|
178
|
+
}
|
179
|
+
|
180
|
+
var optionTypes = {
|
181
|
+
bool: {
|
182
|
+
takesArg: false,
|
183
|
+
parseArg: parseBool
|
184
|
+
},
|
185
|
+
string: {
|
186
|
+
takesArg: true,
|
187
|
+
helpArg: 'ARG',
|
188
|
+
parseArg: parseString
|
189
|
+
},
|
190
|
+
number: {
|
191
|
+
takesArg: true,
|
192
|
+
helpArg: 'NUM',
|
193
|
+
parseArg: parseNumber
|
194
|
+
},
|
195
|
+
integer: {
|
196
|
+
takesArg: true,
|
197
|
+
helpArg: 'INT',
|
198
|
+
parseArg: parseInteger
|
199
|
+
},
|
200
|
+
positiveInteger: {
|
201
|
+
takesArg: true,
|
202
|
+
helpArg: 'INT',
|
203
|
+
parseArg: parsePositiveInteger
|
204
|
+
},
|
205
|
+
date: {
|
206
|
+
takesArg: true,
|
207
|
+
helpArg: 'DATE',
|
208
|
+
parseArg: parseDate
|
209
|
+
},
|
210
|
+
arrayOfBool: {
|
211
|
+
takesArg: false,
|
212
|
+
array: true,
|
213
|
+
parseArg: parseBool
|
214
|
+
},
|
215
|
+
arrayOfString: {
|
216
|
+
takesArg: true,
|
217
|
+
helpArg: 'ARG',
|
218
|
+
array: true,
|
219
|
+
parseArg: parseString
|
220
|
+
},
|
221
|
+
arrayOfNumber: {
|
222
|
+
takesArg: true,
|
223
|
+
helpArg: 'NUM',
|
224
|
+
array: true,
|
225
|
+
parseArg: parseNumber
|
226
|
+
},
|
227
|
+
arrayOfInteger: {
|
228
|
+
takesArg: true,
|
229
|
+
helpArg: 'INT',
|
230
|
+
array: true,
|
231
|
+
parseArg: parseInteger
|
232
|
+
},
|
233
|
+
arrayOfPositiveInteger: {
|
234
|
+
takesArg: true,
|
235
|
+
helpArg: 'INT',
|
236
|
+
array: true,
|
237
|
+
parseArg: parsePositiveInteger
|
238
|
+
},
|
239
|
+
arrayOfDate: {
|
240
|
+
takesArg: true,
|
241
|
+
helpArg: 'INT',
|
242
|
+
array: true,
|
243
|
+
parseArg: parseDate
|
244
|
+
},
|
245
|
+
};
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
// ---- Parser
|
250
|
+
|
251
|
+
/**
|
252
|
+
* Parser constructor.
|
253
|
+
*
|
254
|
+
* @param config {Object} The parser configuration
|
255
|
+
* - options {Array} Array of option specs. See the README for how to
|
256
|
+
* specify each option spec.
|
257
|
+
* - allowUnknown {Boolean} Default false. Whether to throw on unknown
|
258
|
+
* options. If false, then unknown args are included in the _args array.
|
259
|
+
* - interspersed {Boolean} Default true. Whether to allow interspersed
|
260
|
+
* arguments (non-options) and options. E.g.:
|
261
|
+
* node tool.js arg1 arg2 -v
|
262
|
+
* '-v' is after some args here. If `interspersed: false` then '-v'
|
263
|
+
* would not be parsed out. Note that regardless of `interspersed`
|
264
|
+
* the presence of '--' will stop option parsing, as all good
|
265
|
+
* option parsers should.
|
266
|
+
*/
|
267
|
+
function Parser(config) {
|
268
|
+
assert.object(config, 'config');
|
269
|
+
assert.arrayOfObject(config.options, 'config.options');
|
270
|
+
assert.optionalBool(config.interspersed, 'config.interspersed');
|
271
|
+
var self = this;
|
272
|
+
|
273
|
+
// Allow interspersed arguments (true by default).
|
274
|
+
this.interspersed = (config.interspersed !== undefined
|
275
|
+
? config.interspersed : true);
|
276
|
+
|
277
|
+
// Don't allow unknown flags (true by default).
|
278
|
+
this.allowUnknown = (config.allowUnknown !== undefined
|
279
|
+
? config.allowUnknown : false);
|
280
|
+
|
281
|
+
this.options = config.options.map(function (o) { return shallowCopy(o); });
|
282
|
+
this.optionFromName = {};
|
283
|
+
this.optionFromEnv = {};
|
284
|
+
for (var i = 0; i < this.options.length; i++) {
|
285
|
+
var o = this.options[i];
|
286
|
+
if (o.group !== undefined && o.group !== null) {
|
287
|
+
assert.optionalString(o.group,
|
288
|
+
format('config.options.%d.group', i));
|
289
|
+
continue;
|
290
|
+
}
|
291
|
+
assert.ok(optionTypes[o.type],
|
292
|
+
format('invalid config.options.%d.type: "%s" in %j',
|
293
|
+
i, o.type, o));
|
294
|
+
assert.optionalString(o.name, format('config.options.%d.name', i));
|
295
|
+
assert.optionalArrayOfString(o.names,
|
296
|
+
format('config.options.%d.names', i));
|
297
|
+
assert.ok((o.name || o.names) && !(o.name && o.names),
|
298
|
+
format('exactly one of "name" or "names" required: %j', o));
|
299
|
+
assert.optionalString(o.help, format('config.options.%d.help', i));
|
300
|
+
var env = o.env || [];
|
301
|
+
if (typeof (env) === 'string') {
|
302
|
+
env = [env];
|
303
|
+
}
|
304
|
+
assert.optionalArrayOfString(env, format('config.options.%d.env', i));
|
305
|
+
assert.optionalString(o.helpGroup,
|
306
|
+
format('config.options.%d.helpGroup', i));
|
307
|
+
assert.optionalBool(o.helpWrap,
|
308
|
+
format('config.options.%d.helpWrap', i));
|
309
|
+
assert.optionalBool(o.hidden, format('config.options.%d.hidden', i));
|
310
|
+
|
311
|
+
if (o.name) {
|
312
|
+
o.names = [o.name];
|
313
|
+
} else {
|
314
|
+
assert.string(o.names[0],
|
315
|
+
format('config.options.%d.names is empty', i));
|
316
|
+
}
|
317
|
+
o.key = optionKeyFromName(o.names[0]);
|
318
|
+
o.names.forEach(function (n) {
|
319
|
+
if (self.optionFromName[n]) {
|
320
|
+
throw new Error(format(
|
321
|
+
'option name collision: "%s" used in %j and %j',
|
322
|
+
n, self.optionFromName[n], o));
|
323
|
+
}
|
324
|
+
self.optionFromName[n] = o;
|
325
|
+
});
|
326
|
+
env.forEach(function (n) {
|
327
|
+
if (self.optionFromEnv[n]) {
|
328
|
+
throw new Error(format(
|
329
|
+
'option env collision: "%s" used in %j and %j',
|
330
|
+
n, self.optionFromEnv[n], o));
|
331
|
+
}
|
332
|
+
self.optionFromEnv[n] = o;
|
333
|
+
});
|
334
|
+
}
|
335
|
+
}
|
336
|
+
|
337
|
+
Parser.prototype.optionTakesArg = function optionTakesArg(option) {
|
338
|
+
return optionTypes[option.type].takesArg;
|
339
|
+
};
|
340
|
+
|
341
|
+
/**
|
342
|
+
* Parse options from the given argv.
|
343
|
+
*
|
344
|
+
* @param inputs {Object} Optional.
|
345
|
+
* - argv {Array} Optional. The argv to parse. Defaults to
|
346
|
+
* `process.argv`.
|
347
|
+
* - slice {Number} The index into argv at which options/args begin.
|
348
|
+
* Default is 2, as appropriate for `process.argv`.
|
349
|
+
* - env {Object} Optional. The env to use for 'env' entries in the
|
350
|
+
* option specs. Defaults to `process.env`.
|
351
|
+
* @returns {Object} Parsed `opts`. It has special keys `_args` (the
|
352
|
+
* remaining args from `argv`) and `_order` (gives the order that
|
353
|
+
* options were specified).
|
354
|
+
*/
|
355
|
+
Parser.prototype.parse = function parse(inputs) {
|
356
|
+
var self = this;
|
357
|
+
|
358
|
+
// Old API was `parse([argv, [slice]])`
|
359
|
+
if (Array.isArray(arguments[0])) {
|
360
|
+
inputs = {argv: arguments[0], slice: arguments[1]};
|
361
|
+
}
|
362
|
+
|
363
|
+
assert.optionalObject(inputs, 'inputs');
|
364
|
+
if (!inputs) {
|
365
|
+
inputs = {};
|
366
|
+
}
|
367
|
+
assert.optionalArrayOfString(inputs.argv, 'inputs.argv');
|
368
|
+
//assert.optionalNumber(slice, 'slice');
|
369
|
+
var argv = inputs.argv || process.argv;
|
370
|
+
var slice = inputs.slice !== undefined ? inputs.slice : 2;
|
371
|
+
var args = argv.slice(slice);
|
372
|
+
var env = inputs.env || process.env;
|
373
|
+
var opts = {};
|
374
|
+
var _order = [];
|
375
|
+
|
376
|
+
function addOpt(option, optstr, key, val, from) {
|
377
|
+
var type = optionTypes[option.type];
|
378
|
+
var parsedVal = type.parseArg(option, optstr, val);
|
379
|
+
if (type.array) {
|
380
|
+
if (!opts[key]) {
|
381
|
+
opts[key] = [];
|
382
|
+
}
|
383
|
+
if (type.arrayFlatten && Array.isArray(parsedVal)) {
|
384
|
+
for (var i = 0; i < parsedVal.length; i++) {
|
385
|
+
opts[key].push(parsedVal[i]);
|
386
|
+
}
|
387
|
+
} else {
|
388
|
+
opts[key].push(parsedVal);
|
389
|
+
}
|
390
|
+
} else {
|
391
|
+
opts[key] = parsedVal;
|
392
|
+
}
|
393
|
+
var item = { key: key, value: parsedVal, from: from };
|
394
|
+
_order.push(item);
|
395
|
+
}
|
396
|
+
|
397
|
+
// Parse args.
|
398
|
+
var _args = [];
|
399
|
+
var i = 0;
|
400
|
+
outer: while (i < args.length) {
|
401
|
+
var arg = args[i];
|
402
|
+
|
403
|
+
// End of options marker.
|
404
|
+
if (arg === '--') {
|
405
|
+
i++;
|
406
|
+
break;
|
407
|
+
|
408
|
+
// Long option
|
409
|
+
} else if (arg.slice(0, 2) === '--') {
|
410
|
+
var name = arg.slice(2);
|
411
|
+
var val = null;
|
412
|
+
var idx = name.indexOf('=');
|
413
|
+
if (idx !== -1) {
|
414
|
+
val = name.slice(idx + 1);
|
415
|
+
name = name.slice(0, idx);
|
416
|
+
}
|
417
|
+
var option = this.optionFromName[name];
|
418
|
+
if (!option) {
|
419
|
+
if (!this.allowUnknown)
|
420
|
+
throw new Error(format('unknown option: "--%s"', name));
|
421
|
+
else if (this.interspersed)
|
422
|
+
_args.push(arg);
|
423
|
+
else
|
424
|
+
break outer;
|
425
|
+
} else {
|
426
|
+
var takesArg = this.optionTakesArg(option);
|
427
|
+
if (val !== null && !takesArg) {
|
428
|
+
throw new Error(format('argument given to "--%s" option '
|
429
|
+
+ 'that does not take one: "%s"', name, arg));
|
430
|
+
}
|
431
|
+
if (!takesArg) {
|
432
|
+
addOpt(option, '--'+name, option.key, true, 'argv');
|
433
|
+
} else if (val !== null) {
|
434
|
+
addOpt(option, '--'+name, option.key, val, 'argv');
|
435
|
+
} else if (i + 1 >= args.length) {
|
436
|
+
throw new Error(format('do not have enough args for "--%s" '
|
437
|
+
+ 'option', name));
|
438
|
+
} else {
|
439
|
+
addOpt(option, '--'+name, option.key, args[i + 1], 'argv');
|
440
|
+
i++;
|
441
|
+
}
|
442
|
+
}
|
443
|
+
|
444
|
+
// Short option
|
445
|
+
} else if (arg[0] === '-' && arg.length > 1) {
|
446
|
+
var j = 1;
|
447
|
+
var allFound = true;
|
448
|
+
while (j < arg.length) {
|
449
|
+
var name = arg[j];
|
450
|
+
var option = this.optionFromName[name];
|
451
|
+
if (!option) {
|
452
|
+
allFound = false;
|
453
|
+
if (this.allowUnknown) {
|
454
|
+
if (this.interspersed) {
|
455
|
+
_args.push(arg);
|
456
|
+
break;
|
457
|
+
} else
|
458
|
+
break outer;
|
459
|
+
} else if (arg.length > 2) {
|
460
|
+
throw new Error(format(
|
461
|
+
'unknown option: "-%s" in "%s" group',
|
462
|
+
name, arg));
|
463
|
+
} else {
|
464
|
+
throw new Error(format('unknown option: "-%s"', name));
|
465
|
+
}
|
466
|
+
} else if (this.optionTakesArg(option)) {
|
467
|
+
break;
|
468
|
+
}
|
469
|
+
j++;
|
470
|
+
}
|
471
|
+
|
472
|
+
j = 1;
|
473
|
+
while (allFound && j < arg.length) {
|
474
|
+
var name = arg[j];
|
475
|
+
var val = arg.slice(j + 1); // option val if it takes an arg
|
476
|
+
var option = this.optionFromName[name];
|
477
|
+
var takesArg = this.optionTakesArg(option);
|
478
|
+
if (!takesArg) {
|
479
|
+
addOpt(option, '-'+name, option.key, true, 'argv');
|
480
|
+
} else if (val) {
|
481
|
+
addOpt(option, '-'+name, option.key, val, 'argv');
|
482
|
+
break;
|
483
|
+
} else {
|
484
|
+
if (i + 1 >= args.length) {
|
485
|
+
throw new Error(format('do not have enough args '
|
486
|
+
+ 'for "-%s" option', name));
|
487
|
+
}
|
488
|
+
addOpt(option, '-'+name, option.key, args[i + 1], 'argv');
|
489
|
+
i++;
|
490
|
+
break;
|
491
|
+
}
|
492
|
+
j++;
|
493
|
+
}
|
494
|
+
|
495
|
+
// An interspersed arg
|
496
|
+
} else if (this.interspersed) {
|
497
|
+
_args.push(arg);
|
498
|
+
|
499
|
+
// An arg and interspersed args are not allowed, so done options.
|
500
|
+
} else {
|
501
|
+
break outer;
|
502
|
+
}
|
503
|
+
i++;
|
504
|
+
}
|
505
|
+
_args = _args.concat(args.slice(i));
|
506
|
+
|
507
|
+
// Parse environment.
|
508
|
+
Object.keys(this.optionFromEnv).forEach(function (envname) {
|
509
|
+
var val = env[envname];
|
510
|
+
if (val === undefined)
|
511
|
+
return;
|
512
|
+
var option = self.optionFromEnv[envname];
|
513
|
+
if (opts[option.key] !== undefined)
|
514
|
+
return;
|
515
|
+
var takesArg = self.optionTakesArg(option);
|
516
|
+
if (takesArg) {
|
517
|
+
addOpt(option, envname, option.key, val, 'env');
|
518
|
+
} else if (val !== '') {
|
519
|
+
// Boolean envvar handling:
|
520
|
+
// - VAR=<empty-string> not set (as if the VAR was not set)
|
521
|
+
// - VAR=0 false
|
522
|
+
// - anything else true
|
523
|
+
addOpt(option, envname, option.key, (val !== '0'), 'env');
|
524
|
+
}
|
525
|
+
});
|
526
|
+
|
527
|
+
// Apply default values.
|
528
|
+
this.options.forEach(function (o) {
|
529
|
+
if (opts[o.key] === undefined) {
|
530
|
+
if (o.default !== undefined) {
|
531
|
+
opts[o.key] = o.default;
|
532
|
+
} else if (o.type && optionTypes[o.type].default !== undefined) {
|
533
|
+
opts[o.key] = optionTypes[o.type].default;
|
534
|
+
}
|
535
|
+
}
|
536
|
+
});
|
537
|
+
|
538
|
+
opts._order = _order;
|
539
|
+
opts._args = _args;
|
540
|
+
return opts;
|
541
|
+
};
|
542
|
+
|
543
|
+
|
544
|
+
/**
|
545
|
+
* Return help output for the current options.
|
546
|
+
*
|
547
|
+
* E.g.: if the current options are:
|
548
|
+
* [{names: ['help', 'h'], type: 'bool', help: 'Show help and exit.'}]
|
549
|
+
* then this would return:
|
550
|
+
* ' -h, --help Show help and exit.\n'
|
551
|
+
*
|
552
|
+
* @param config {Object} Config for controlling the option help output.
|
553
|
+
* - indent {Number|String} Default 4. An indent/prefix to use for
|
554
|
+
* each option line.
|
555
|
+
* - nameSort {String} Default is 'length'. By default the names are
|
556
|
+
* sorted to put the short opts first (i.e. '-h, --help' preferred
|
557
|
+
* to '--help, -h'). Set to 'none' to not do this sorting.
|
558
|
+
* - maxCol {Number} Default 80. Note that long tokens in a help string
|
559
|
+
* can go past this.
|
560
|
+
* - helpCol {Number} Set to specify a specific column at which
|
561
|
+
* option help will be aligned. By default this is determined
|
562
|
+
* automatically.
|
563
|
+
* - minHelpCol {Number} Default 20.
|
564
|
+
* - maxHelpCol {Number} Default 40.
|
565
|
+
* - includeEnv {Boolean} Default false. If true, a note stating the `env`
|
566
|
+
* envvar (if specified for this option) will be appended to the help
|
567
|
+
* output.
|
568
|
+
* - includeDefault {Boolean} Default false. If true, a note stating
|
569
|
+
* the `default` for this option, if any, will be appended to the help
|
570
|
+
* output.
|
571
|
+
* - helpWrap {Boolean} Default true. Wrap help text in helpCol..maxCol
|
572
|
+
* bounds.
|
573
|
+
* @returns {String}
|
574
|
+
*/
|
575
|
+
Parser.prototype.help = function help(config) {
|
576
|
+
config = config || {};
|
577
|
+
assert.object(config, 'config');
|
578
|
+
|
579
|
+
var indent = makeIndent(config.indent, 4, 'config.indent');
|
580
|
+
var headingIndent = makeIndent(config.headingIndent,
|
581
|
+
Math.round(indent.length / 2), 'config.headingIndent');
|
582
|
+
|
583
|
+
assert.optionalString(config.nameSort, 'config.nameSort');
|
584
|
+
var nameSort = config.nameSort || 'length';
|
585
|
+
assert.ok(~['length', 'none'].indexOf(nameSort),
|
586
|
+
'invalid "config.nameSort"');
|
587
|
+
assert.optionalNumber(config.maxCol, 'config.maxCol');
|
588
|
+
assert.optionalNumber(config.maxHelpCol, 'config.maxHelpCol');
|
589
|
+
assert.optionalNumber(config.minHelpCol, 'config.minHelpCol');
|
590
|
+
assert.optionalNumber(config.helpCol, 'config.helpCol');
|
591
|
+
assert.optionalBool(config.includeEnv, 'config.includeEnv');
|
592
|
+
assert.optionalBool(config.includeDefault, 'config.includeDefault');
|
593
|
+
assert.optionalBool(config.helpWrap, 'config.helpWrap');
|
594
|
+
var maxCol = config.maxCol || 80;
|
595
|
+
var minHelpCol = config.minHelpCol || 20;
|
596
|
+
var maxHelpCol = config.maxHelpCol || 40;
|
597
|
+
|
598
|
+
var lines = [];
|
599
|
+
var maxWidth = 0;
|
600
|
+
this.options.forEach(function (o) {
|
601
|
+
if (o.hidden) {
|
602
|
+
return;
|
603
|
+
}
|
604
|
+
if (o.group !== undefined && o.group !== null) {
|
605
|
+
// We deal with groups in the next pass
|
606
|
+
lines.push(null);
|
607
|
+
return;
|
608
|
+
}
|
609
|
+
var type = optionTypes[o.type];
|
610
|
+
var arg = o.helpArg || type.helpArg || 'ARG';
|
611
|
+
var line = '';
|
612
|
+
var names = o.names.slice();
|
613
|
+
if (nameSort === 'length') {
|
614
|
+
names.sort(function (a, b) {
|
615
|
+
if (a.length < b.length)
|
616
|
+
return -1;
|
617
|
+
else if (b.length < a.length)
|
618
|
+
return 1;
|
619
|
+
else
|
620
|
+
return 0;
|
621
|
+
})
|
622
|
+
}
|
623
|
+
names.forEach(function (name, i) {
|
624
|
+
if (i > 0)
|
625
|
+
line += ', ';
|
626
|
+
if (name.length === 1) {
|
627
|
+
line += '-' + name
|
628
|
+
if (type.takesArg)
|
629
|
+
line += ' ' + arg;
|
630
|
+
} else {
|
631
|
+
line += '--' + name
|
632
|
+
if (type.takesArg)
|
633
|
+
line += '=' + arg;
|
634
|
+
}
|
635
|
+
});
|
636
|
+
maxWidth = Math.max(maxWidth, line.length);
|
637
|
+
lines.push(line);
|
638
|
+
});
|
639
|
+
|
640
|
+
// Add help strings.
|
641
|
+
var helpCol = config.helpCol;
|
642
|
+
if (!helpCol) {
|
643
|
+
helpCol = maxWidth + indent.length + 2;
|
644
|
+
helpCol = Math.min(Math.max(helpCol, minHelpCol), maxHelpCol);
|
645
|
+
}
|
646
|
+
var i = -1;
|
647
|
+
this.options.forEach(function (o) {
|
648
|
+
if (o.hidden) {
|
649
|
+
return;
|
650
|
+
}
|
651
|
+
i++;
|
652
|
+
|
653
|
+
if (o.group !== undefined && o.group !== null) {
|
654
|
+
if (o.group === '') {
|
655
|
+
// Support a empty string "group" to have a blank line between
|
656
|
+
// sets of options.
|
657
|
+
lines[i] = '';
|
658
|
+
} else {
|
659
|
+
// Render the group heading with the heading-specific indent.
|
660
|
+
lines[i] = (i === 0 ? '' : '\n') + headingIndent +
|
661
|
+
o.group + ':';
|
662
|
+
}
|
663
|
+
return;
|
664
|
+
}
|
665
|
+
|
666
|
+
var helpDefault;
|
667
|
+
if (config.includeDefault) {
|
668
|
+
if (o.default !== undefined) {
|
669
|
+
helpDefault = format('Default: %j', o.default);
|
670
|
+
} else if (o.type && optionTypes[o.type].default !== undefined) {
|
671
|
+
helpDefault = format('Default: %j',
|
672
|
+
optionTypes[o.type].default);
|
673
|
+
}
|
674
|
+
}
|
675
|
+
|
676
|
+
var line = lines[i] = indent + lines[i];
|
677
|
+
if (!o.help && !(config.includeEnv && o.env) && !helpDefault) {
|
678
|
+
return;
|
679
|
+
}
|
680
|
+
var n = helpCol - line.length;
|
681
|
+
if (n >= 0) {
|
682
|
+
line += space(n);
|
683
|
+
} else {
|
684
|
+
line += '\n' + space(helpCol);
|
685
|
+
}
|
686
|
+
|
687
|
+
var helpEnv = '';
|
688
|
+
if (o.env && o.env.length && config.includeEnv) {
|
689
|
+
helpEnv += 'Environment: ';
|
690
|
+
var type = optionTypes[o.type];
|
691
|
+
var arg = o.helpArg || type.helpArg || 'ARG';
|
692
|
+
var envs = (Array.isArray(o.env) ? o.env : [o.env]).map(
|
693
|
+
function (e) {
|
694
|
+
if (type.takesArg) {
|
695
|
+
return e + '=' + arg;
|
696
|
+
} else {
|
697
|
+
return e + '=1';
|
698
|
+
}
|
699
|
+
}
|
700
|
+
);
|
701
|
+
helpEnv += envs.join(', ');
|
702
|
+
}
|
703
|
+
var help = (o.help || '').trim();
|
704
|
+
if (o.helpWrap !== false && config.helpWrap !== false) {
|
705
|
+
// Wrap help description normally.
|
706
|
+
if (help.length && !~'.!?"\''.indexOf(help.slice(-1))) {
|
707
|
+
help += '.';
|
708
|
+
}
|
709
|
+
if (help.length) {
|
710
|
+
help += ' ';
|
711
|
+
}
|
712
|
+
help += helpEnv;
|
713
|
+
if (helpDefault) {
|
714
|
+
if (helpEnv) {
|
715
|
+
help += '. ';
|
716
|
+
}
|
717
|
+
help += helpDefault;
|
718
|
+
}
|
719
|
+
line += textwrap(help, maxCol - helpCol).join(
|
720
|
+
'\n' + space(helpCol));
|
721
|
+
} else {
|
722
|
+
// Do not wrap help description, but indent newlines appropriately.
|
723
|
+
var helpLines = help.split('\n').filter(
|
724
|
+
function (ln) { return ln.length });
|
725
|
+
if (helpEnv !== '') {
|
726
|
+
helpLines.push(helpEnv);
|
727
|
+
}
|
728
|
+
if (helpDefault) {
|
729
|
+
helpLines.push(helpDefault);
|
730
|
+
}
|
731
|
+
line += helpLines.join('\n' + space(helpCol));
|
732
|
+
}
|
733
|
+
|
734
|
+
lines[i] = line;
|
735
|
+
});
|
736
|
+
|
737
|
+
var rv = '';
|
738
|
+
if (lines.length > 0) {
|
739
|
+
rv = lines.join('\n') + '\n';
|
740
|
+
}
|
741
|
+
return rv;
|
742
|
+
};
|
743
|
+
|
744
|
+
|
745
|
+
/**
|
746
|
+
* Return a string suitable for a Bash completion file for this tool.
|
747
|
+
*
|
748
|
+
* @param args.name {String} The tool name.
|
749
|
+
* @param args.specExtra {String} Optional. Extra Bash code content to add
|
750
|
+
* to the end of the "spec". Typically this is used to append Bash
|
751
|
+
* "complete_TYPE" functions for custom option types. See
|
752
|
+
* "examples/ddcompletion.js" for an example.
|
753
|
+
* @param args.argtypes {Array} Optional. Array of completion types for
|
754
|
+
* positional args (i.e. non-options). E.g.
|
755
|
+
* argtypes = ['fruit', 'veggie', 'file']
|
756
|
+
* will result in completion of fruits for the first arg, veggies for the
|
757
|
+
* second, and filenames for the third and subsequent positional args.
|
758
|
+
* If not given, positional args will use Bash's 'default' completion.
|
759
|
+
* See `specExtra` for providing Bash `complete_TYPE` functions, e.g.
|
760
|
+
* `complete_fruit` and `complete_veggie` in this example.
|
761
|
+
*/
|
762
|
+
Parser.prototype.bashCompletion = function bashCompletion(args) {
|
763
|
+
assert.object(args, 'args');
|
764
|
+
assert.string(args.name, 'args.name');
|
765
|
+
assert.optionalString(args.specExtra, 'args.specExtra');
|
766
|
+
assert.optionalArrayOfString(args.argtypes, 'args.argtypes');
|
767
|
+
|
768
|
+
return bashCompletionFromOptions({
|
769
|
+
name: args.name,
|
770
|
+
specExtra: args.specExtra,
|
771
|
+
argtypes: args.argtypes,
|
772
|
+
options: this.options
|
773
|
+
});
|
774
|
+
};
|
775
|
+
|
776
|
+
|
777
|
+
// ---- Bash completion
|
778
|
+
|
779
|
+
const BASH_COMPLETION_TEMPLATE_PATH = path.join(
|
780
|
+
__dirname, '../etc/dashdash.bash_completion.in');
|
781
|
+
|
782
|
+
/**
|
783
|
+
* Return the Bash completion "spec" (the string value for the "{{spec}}"
|
784
|
+
* var in the "dashdash.bash_completion.in" template) for this tool.
|
785
|
+
*
|
786
|
+
* The "spec" is Bash code that defines the CLI options and subcmds for
|
787
|
+
* the template's completion code. It looks something like this:
|
788
|
+
*
|
789
|
+
* local cmd_shortopts="-J ..."
|
790
|
+
* local cmd_longopts="--help ..."
|
791
|
+
* local cmd_optargs="-p=tritonprofile ..."
|
792
|
+
*
|
793
|
+
* @param args.options {Array} The array of dashdash option specs.
|
794
|
+
* @param args.context {String} Optional. A context string for the "local cmd*"
|
795
|
+
* vars in the spec. By default it is the empty string. When used to
|
796
|
+
* scope for completion on a *sub-command* (e.g. for "git log" on a "git"
|
797
|
+
* tool), then it would have a value (e.g. "__log"). See
|
798
|
+
* <http://github.com/trentm/node-cmdln> Bash completion for details.
|
799
|
+
* @param opts.includeHidden {Boolean} Optional. Default false. By default
|
800
|
+
* hidden options and subcmds are "excluded". Here excluded means they
|
801
|
+
* won't be offered as a completion, but if used, their argument type
|
802
|
+
* will be completed. "Hidden" options and subcmds are ones with the
|
803
|
+
* `hidden: true` attribute to exclude them from default help output.
|
804
|
+
* @param args.argtypes {Array} Optional. Array of completion types for
|
805
|
+
* positional args (i.e. non-options). E.g.
|
806
|
+
* argtypes = ['fruit', 'veggie', 'file']
|
807
|
+
* will result in completion of fruits for the first arg, veggies for the
|
808
|
+
* second, and filenames for the third and subsequent positional args.
|
809
|
+
* If not given, positional args will use Bash's 'default' completion.
|
810
|
+
* See `specExtra` for providing Bash `complete_TYPE` functions, e.g.
|
811
|
+
* `complete_fruit` and `complete_veggie` in this example.
|
812
|
+
*/
|
813
|
+
function bashCompletionSpecFromOptions(args) {
|
814
|
+
assert.object(args, 'args');
|
815
|
+
assert.object(args.options, 'args.options');
|
816
|
+
assert.optionalString(args.context, 'args.context');
|
817
|
+
assert.optionalBool(args.includeHidden, 'args.includeHidden');
|
818
|
+
assert.optionalArrayOfString(args.argtypes, 'args.argtypes');
|
819
|
+
|
820
|
+
var context = args.context || '';
|
821
|
+
var includeHidden = (args.includeHidden === undefined
|
822
|
+
? false : args.includeHidden);
|
823
|
+
|
824
|
+
var spec = [];
|
825
|
+
var shortopts = [];
|
826
|
+
var longopts = [];
|
827
|
+
var optargs = [];
|
828
|
+
(args.options || []).forEach(function (o) {
|
829
|
+
if (o.group !== undefined && o.group !== null) {
|
830
|
+
// Skip group headers.
|
831
|
+
return;
|
832
|
+
}
|
833
|
+
|
834
|
+
var optNames = o.names || [o.name];
|
835
|
+
var optType = getOptionType(o.type);
|
836
|
+
if (optType.takesArg) {
|
837
|
+
var completionType = o.completionType ||
|
838
|
+
optType.completionType || o.type;
|
839
|
+
optNames.forEach(function (optName) {
|
840
|
+
if (optName.length === 1) {
|
841
|
+
if (includeHidden || !o.hidden) {
|
842
|
+
shortopts.push('-' + optName);
|
843
|
+
}
|
844
|
+
// Include even hidden options in `optargs` so that bash
|
845
|
+
// completion of its arg still works.
|
846
|
+
optargs.push('-' + optName + '=' + completionType);
|
847
|
+
} else {
|
848
|
+
if (includeHidden || !o.hidden) {
|
849
|
+
longopts.push('--' + optName);
|
850
|
+
}
|
851
|
+
optargs.push('--' + optName + '=' + completionType);
|
852
|
+
}
|
853
|
+
});
|
854
|
+
} else {
|
855
|
+
optNames.forEach(function (optName) {
|
856
|
+
if (includeHidden || !o.hidden) {
|
857
|
+
if (optName.length === 1) {
|
858
|
+
shortopts.push('-' + optName);
|
859
|
+
} else {
|
860
|
+
longopts.push('--' + optName);
|
861
|
+
}
|
862
|
+
}
|
863
|
+
});
|
864
|
+
}
|
865
|
+
});
|
866
|
+
|
867
|
+
spec.push(format('local cmd%s_shortopts="%s"',
|
868
|
+
context, shortopts.sort().join(' ')));
|
869
|
+
spec.push(format('local cmd%s_longopts="%s"',
|
870
|
+
context, longopts.sort().join(' ')));
|
871
|
+
spec.push(format('local cmd%s_optargs="%s"',
|
872
|
+
context, optargs.sort().join(' ')));
|
873
|
+
if (args.argtypes) {
|
874
|
+
spec.push(format('local cmd%s_argtypes="%s"',
|
875
|
+
context, args.argtypes.join(' ')));
|
876
|
+
}
|
877
|
+
return spec.join('\n');
|
878
|
+
}
|
879
|
+
|
880
|
+
|
881
|
+
/**
|
882
|
+
* Return a string suitable for a Bash completion file for this tool.
|
883
|
+
*
|
884
|
+
* @param args.name {String} The tool name.
|
885
|
+
* @param args.options {Array} The array of dashdash option specs.
|
886
|
+
* @param args.specExtra {String} Optional. Extra Bash code content to add
|
887
|
+
* to the end of the "spec". Typically this is used to append Bash
|
888
|
+
* "complete_TYPE" functions for custom option types. See
|
889
|
+
* "examples/ddcompletion.js" for an example.
|
890
|
+
* @param args.argtypes {Array} Optional. Array of completion types for
|
891
|
+
* positional args (i.e. non-options). E.g.
|
892
|
+
* argtypes = ['fruit', 'veggie', 'file']
|
893
|
+
* will result in completion of fruits for the first arg, veggies for the
|
894
|
+
* second, and filenames for the third and subsequent positional args.
|
895
|
+
* If not given, positional args will use Bash's 'default' completion.
|
896
|
+
* See `specExtra` for providing Bash `complete_TYPE` functions, e.g.
|
897
|
+
* `complete_fruit` and `complete_veggie` in this example.
|
898
|
+
*/
|
899
|
+
function bashCompletionFromOptions(args) {
|
900
|
+
assert.object(args, 'args');
|
901
|
+
assert.object(args.options, 'args.options');
|
902
|
+
assert.string(args.name, 'args.name');
|
903
|
+
assert.optionalString(args.specExtra, 'args.specExtra');
|
904
|
+
assert.optionalArrayOfString(args.argtypes, 'args.argtypes');
|
905
|
+
|
906
|
+
// Gather template data.
|
907
|
+
var data = {
|
908
|
+
name: args.name,
|
909
|
+
date: new Date(),
|
910
|
+
spec: bashCompletionSpecFromOptions({
|
911
|
+
options: args.options,
|
912
|
+
argtypes: args.argtypes
|
913
|
+
}),
|
914
|
+
};
|
915
|
+
if (args.specExtra) {
|
916
|
+
data.spec += '\n\n' + args.specExtra;
|
917
|
+
}
|
918
|
+
|
919
|
+
// Render template.
|
920
|
+
var template = fs.readFileSync(BASH_COMPLETION_TEMPLATE_PATH, 'utf8');
|
921
|
+
return renderTemplate(template, data);
|
922
|
+
}
|
923
|
+
|
924
|
+
|
925
|
+
|
926
|
+
// ---- exports
|
927
|
+
|
928
|
+
function createParser(config) {
|
929
|
+
return new Parser(config);
|
930
|
+
}
|
931
|
+
|
932
|
+
/**
|
933
|
+
* Parse argv with the given options.
|
934
|
+
*
|
935
|
+
* @param config {Object} A merge of all the available fields from
|
936
|
+
* `dashdash.Parser` and `dashdash.Parser.parse`: options, interspersed,
|
937
|
+
* argv, env, slice.
|
938
|
+
*/
|
939
|
+
function parse(config) {
|
940
|
+
assert.object(config, 'config');
|
941
|
+
assert.optionalArrayOfString(config.argv, 'config.argv');
|
942
|
+
assert.optionalObject(config.env, 'config.env');
|
943
|
+
var config = shallowCopy(config);
|
944
|
+
var argv = config.argv;
|
945
|
+
delete config.argv;
|
946
|
+
var env = config.env;
|
947
|
+
delete config.env;
|
948
|
+
|
949
|
+
var parser = new Parser(config);
|
950
|
+
return parser.parse({argv: argv, env: env});
|
951
|
+
}
|
952
|
+
|
953
|
+
|
954
|
+
/**
|
955
|
+
* Add a new option type.
|
956
|
+
*
|
957
|
+
* @params optionType {Object}:
|
958
|
+
* - name {String} Required.
|
959
|
+
* - takesArg {Boolean} Required. Whether this type of option takes an
|
960
|
+
* argument on process.argv. Typically this is true for all but the
|
961
|
+
* "bool" type.
|
962
|
+
* - helpArg {String} Required iff `takesArg === true`. The string to
|
963
|
+
* show in generated help for options of this type.
|
964
|
+
* - parseArg {Function} Require. `function (option, optstr, arg)` parser
|
965
|
+
* that takes a string argument and returns an instance of the
|
966
|
+
* appropriate type, or throws an error if the arg is invalid.
|
967
|
+
* - array {Boolean} Optional. Set to true if this is an 'arrayOf' type
|
968
|
+
* that collects multiple usages of the option in process.argv and
|
969
|
+
* puts results in an array.
|
970
|
+
* - arrayFlatten {Boolean} Optional. XXX
|
971
|
+
* - default Optional. Default value for options of this type, if no
|
972
|
+
* default is specified in the option type usage.
|
973
|
+
*/
|
974
|
+
function addOptionType(optionType) {
|
975
|
+
assert.object(optionType, 'optionType');
|
976
|
+
assert.string(optionType.name, 'optionType.name');
|
977
|
+
assert.bool(optionType.takesArg, 'optionType.takesArg');
|
978
|
+
if (optionType.takesArg) {
|
979
|
+
assert.string(optionType.helpArg, 'optionType.helpArg');
|
980
|
+
}
|
981
|
+
assert.func(optionType.parseArg, 'optionType.parseArg');
|
982
|
+
assert.optionalBool(optionType.array, 'optionType.array');
|
983
|
+
assert.optionalBool(optionType.arrayFlatten, 'optionType.arrayFlatten');
|
984
|
+
|
985
|
+
optionTypes[optionType.name] = {
|
986
|
+
takesArg: optionType.takesArg,
|
987
|
+
helpArg: optionType.helpArg,
|
988
|
+
parseArg: optionType.parseArg,
|
989
|
+
array: optionType.array,
|
990
|
+
arrayFlatten: optionType.arrayFlatten,
|
991
|
+
default: optionType.default
|
992
|
+
}
|
993
|
+
}
|
994
|
+
|
995
|
+
|
996
|
+
function getOptionType(name) {
|
997
|
+
assert.string(name, 'name');
|
998
|
+
return optionTypes[name];
|
999
|
+
}
|
1000
|
+
|
1001
|
+
|
1002
|
+
/**
|
1003
|
+
* Return a synopsis string for the given option spec.
|
1004
|
+
*
|
1005
|
+
* Examples:
|
1006
|
+
* > synopsisFromOpt({names: ['help', 'h'], type: 'bool'});
|
1007
|
+
* '[ --help | -h ]'
|
1008
|
+
* > synopsisFromOpt({name: 'file', type: 'string', helpArg: 'FILE'});
|
1009
|
+
* '[ --file=FILE ]'
|
1010
|
+
*/
|
1011
|
+
function synopsisFromOpt(o) {
|
1012
|
+
assert.object(o, 'o');
|
1013
|
+
|
1014
|
+
if (o.hasOwnProperty('group')) {
|
1015
|
+
return null;
|
1016
|
+
}
|
1017
|
+
var names = o.names || [o.name];
|
1018
|
+
// `type` here could be undefined if, for example, the command has a
|
1019
|
+
// dashdash option spec with a bogus 'type'.
|
1020
|
+
var type = getOptionType(o.type);
|
1021
|
+
var helpArg = o.helpArg || (type && type.helpArg) || 'ARG';
|
1022
|
+
var parts = [];
|
1023
|
+
names.forEach(function (name) {
|
1024
|
+
var part = (name.length === 1 ? '-' : '--') + name;
|
1025
|
+
if (type && type.takesArg) {
|
1026
|
+
part += (name.length === 1 ? ' ' + helpArg : '=' + helpArg);
|
1027
|
+
}
|
1028
|
+
parts.push(part);
|
1029
|
+
});
|
1030
|
+
return ('[ ' + parts.join(' | ') + ' ]');
|
1031
|
+
};
|
1032
|
+
|
1033
|
+
|
1034
|
+
module.exports = {
|
1035
|
+
createParser: createParser,
|
1036
|
+
Parser: Parser,
|
1037
|
+
parse: parse,
|
1038
|
+
addOptionType: addOptionType,
|
1039
|
+
getOptionType: getOptionType,
|
1040
|
+
synopsisFromOpt: synopsisFromOpt,
|
1041
|
+
|
1042
|
+
// Bash completion-related exports
|
1043
|
+
BASH_COMPLETION_TEMPLATE_PATH: BASH_COMPLETION_TEMPLATE_PATH,
|
1044
|
+
bashCompletionFromOptions: bashCompletionFromOptions,
|
1045
|
+
bashCompletionSpecFromOptions: bashCompletionSpecFromOptions,
|
1046
|
+
|
1047
|
+
// Export the parseFoo parsers because they might be useful as primitives
|
1048
|
+
// for custom option types.
|
1049
|
+
parseBool: parseBool,
|
1050
|
+
parseString: parseString,
|
1051
|
+
parseNumber: parseNumber,
|
1052
|
+
parseInteger: parseInteger,
|
1053
|
+
parsePositiveInteger: parsePositiveInteger,
|
1054
|
+
parseDate: parseDate
|
1055
|
+
};
|