Compare commits
No commits in common. "main" and "master" have entirely different histories.
|
@ -1,3 +1,4 @@
|
||||||
|
# ---> Node
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
*.log
|
*.log
|
||||||
|
@ -128,3 +129,4 @@ dist
|
||||||
.yarn/build-state.yml
|
.yarn/build-state.yml
|
||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
|
|
121
LICENSE
121
LICENSE
|
@ -1,121 +0,0 @@
|
||||||
Creative Commons Legal Code
|
|
||||||
|
|
||||||
CC0 1.0 Universal
|
|
||||||
|
|
||||||
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
||||||
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
||||||
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
||||||
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
||||||
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
||||||
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
||||||
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
||||||
HEREUNDER.
|
|
||||||
|
|
||||||
Statement of Purpose
|
|
||||||
|
|
||||||
The laws of most jurisdictions throughout the world automatically confer
|
|
||||||
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
||||||
and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
||||||
authorship and/or a database (each, a "Work").
|
|
||||||
|
|
||||||
Certain owners wish to permanently relinquish those rights to a Work for
|
|
||||||
the purpose of contributing to a commons of creative, cultural and
|
|
||||||
scientific works ("Commons") that the public can reliably and without fear
|
|
||||||
of later claims of infringement build upon, modify, incorporate in other
|
|
||||||
works, reuse and redistribute as freely as possible in any form whatsoever
|
|
||||||
and for any purposes, including without limitation commercial purposes.
|
|
||||||
These owners may contribute to the Commons to promote the ideal of a free
|
|
||||||
culture and the further production of creative, cultural and scientific
|
|
||||||
works, or to gain reputation or greater distribution for their Work in
|
|
||||||
part through the use and efforts of others.
|
|
||||||
|
|
||||||
For these and/or other purposes and motivations, and without any
|
|
||||||
expectation of additional consideration or compensation, the person
|
|
||||||
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
||||||
is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
||||||
elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
||||||
terms, with knowledge of his or her Copyright and Related Rights in the
|
|
||||||
Work and the meaning and intended legal effect of CC0 on those rights.
|
|
||||||
|
|
||||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
||||||
protected by copyright and related or neighboring rights ("Copyright and
|
|
||||||
Related Rights"). Copyright and Related Rights include, but are not
|
|
||||||
limited to, the following:
|
|
||||||
|
|
||||||
i. the right to reproduce, adapt, distribute, perform, display,
|
|
||||||
communicate, and translate a Work;
|
|
||||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
||||||
iii. publicity and privacy rights pertaining to a person's image or
|
|
||||||
likeness depicted in a Work;
|
|
||||||
iv. rights protecting against unfair competition in regards to a Work,
|
|
||||||
subject to the limitations in paragraph 4(a), below;
|
|
||||||
v. rights protecting the extraction, dissemination, use and reuse of data
|
|
||||||
in a Work;
|
|
||||||
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
||||||
European Parliament and of the Council of 11 March 1996 on the legal
|
|
||||||
protection of databases, and under any national implementation
|
|
||||||
thereof, including any amended or successor version of such
|
|
||||||
directive); and
|
|
||||||
vii. other similar, equivalent or corresponding rights throughout the
|
|
||||||
world based on applicable law or treaty, and any national
|
|
||||||
implementations thereof.
|
|
||||||
|
|
||||||
2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
||||||
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
||||||
irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
||||||
Affirmer's Copyright and Related Rights and associated claims and causes
|
|
||||||
of action, whether now known or unknown (including existing as well as
|
|
||||||
future claims and causes of action), in the Work (i) in all territories
|
|
||||||
worldwide, (ii) for the maximum duration provided by applicable law or
|
|
||||||
treaty (including future time extensions), (iii) in any current or future
|
|
||||||
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
||||||
including without limitation commercial, advertising or promotional
|
|
||||||
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
||||||
member of the public at large and to the detriment of Affirmer's heirs and
|
|
||||||
successors, fully intending that such Waiver shall not be subject to
|
|
||||||
revocation, rescission, cancellation, termination, or any other legal or
|
|
||||||
equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
||||||
as contemplated by Affirmer's express Statement of Purpose.
|
|
||||||
|
|
||||||
3. Public License Fallback. Should any part of the Waiver for any reason
|
|
||||||
be judged legally invalid or ineffective under applicable law, then the
|
|
||||||
Waiver shall be preserved to the maximum extent permitted taking into
|
|
||||||
account Affirmer's express Statement of Purpose. In addition, to the
|
|
||||||
extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
||||||
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
||||||
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
||||||
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
||||||
maximum duration provided by applicable law or treaty (including future
|
|
||||||
time extensions), (iii) in any current or future medium and for any number
|
|
||||||
of copies, and (iv) for any purpose whatsoever, including without
|
|
||||||
limitation commercial, advertising or promotional purposes (the
|
|
||||||
"License"). The License shall be deemed effective as of the date CC0 was
|
|
||||||
applied by Affirmer to the Work. Should any part of the License for any
|
|
||||||
reason be judged legally invalid or ineffective under applicable law, such
|
|
||||||
partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
||||||
of the License, and in such case Affirmer hereby affirms that he or she
|
|
||||||
will not (i) exercise any of his or her remaining Copyright and Related
|
|
||||||
Rights in the Work or (ii) assert any associated claims and causes of
|
|
||||||
action with respect to the Work, in either case contrary to Affirmer's
|
|
||||||
express Statement of Purpose.
|
|
||||||
|
|
||||||
4. Limitations and Disclaimers.
|
|
||||||
|
|
||||||
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
||||||
surrendered, licensed or otherwise affected by this document.
|
|
||||||
b. Affirmer offers the Work as-is and makes no representations or
|
|
||||||
warranties of any kind concerning the Work, express, implied,
|
|
||||||
statutory or otherwise, including without limitation warranties of
|
|
||||||
title, merchantability, fitness for a particular purpose, non
|
|
||||||
infringement, or the absence of latent or other defects, accuracy, or
|
|
||||||
the present or absence of errors, whether or not discoverable, all to
|
|
||||||
the greatest extent permissible under applicable law.
|
|
||||||
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
||||||
that may apply to the Work or any use thereof, including without
|
|
||||||
limitation any person's Copyright and Related Rights in the Work.
|
|
||||||
Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
||||||
consents, permissions or other rights required for any use of the
|
|
||||||
Work.
|
|
||||||
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
||||||
party to this document and has no duty or obligation with respect to
|
|
||||||
this CC0 or use of the Work.
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
# rickandmorty
|
||||||
|
|
||||||
|
Simple JS CLI program for a job interview
|
|
@ -1 +0,0 @@
|
||||||
../nodemon/bin/nodemon.js
|
|
|
@ -1 +0,0 @@
|
||||||
../touch/bin/nodetouch.js
|
|
|
@ -1 +0,0 @@
|
||||||
../semver/bin/semver.js
|
|
|
@ -1,440 +0,0 @@
|
||||||
{
|
|
||||||
"name": "dh",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"lockfileVersion": 3,
|
|
||||||
"requires": true,
|
|
||||||
"packages": {
|
|
||||||
"node_modules/anymatch": {
|
|
||||||
"version": "3.1.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
|
|
||||||
"integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==",
|
|
||||||
"dependencies": {
|
|
||||||
"normalize-path": "^3.0.0",
|
|
||||||
"picomatch": "^2.0.4"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/balanced-match": {
|
|
||||||
"version": "1.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
|
||||||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
|
|
||||||
},
|
|
||||||
"node_modules/binary-extensions": {
|
|
||||||
"version": "2.3.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz",
|
|
||||||
"integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"url": "https://github.com/sponsors/sindresorhus"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/brace-expansion": {
|
|
||||||
"version": "1.1.11",
|
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
|
||||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
|
||||||
"dependencies": {
|
|
||||||
"balanced-match": "^1.0.0",
|
|
||||||
"concat-map": "0.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/braces": {
|
|
||||||
"version": "3.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
|
|
||||||
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
|
|
||||||
"dependencies": {
|
|
||||||
"fill-range": "^7.1.1"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/chokidar": {
|
|
||||||
"version": "3.6.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
|
|
||||||
"integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==",
|
|
||||||
"dependencies": {
|
|
||||||
"anymatch": "~3.1.2",
|
|
||||||
"braces": "~3.0.2",
|
|
||||||
"glob-parent": "~5.1.2",
|
|
||||||
"is-binary-path": "~2.1.0",
|
|
||||||
"is-glob": "~4.0.1",
|
|
||||||
"normalize-path": "~3.0.0",
|
|
||||||
"readdirp": "~3.6.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 8.10.0"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"url": "https://paulmillr.com/funding/"
|
|
||||||
},
|
|
||||||
"optionalDependencies": {
|
|
||||||
"fsevents": "~2.3.2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/concat-map": {
|
|
||||||
"version": "0.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
|
||||||
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
|
|
||||||
},
|
|
||||||
"node_modules/debug": {
|
|
||||||
"version": "4.3.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.5.tgz",
|
|
||||||
"integrity": "sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==",
|
|
||||||
"dependencies": {
|
|
||||||
"ms": "2.1.2"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=6.0"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"supports-color": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/fill-range": {
|
|
||||||
"version": "7.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
|
||||||
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
|
|
||||||
"dependencies": {
|
|
||||||
"to-regex-range": "^5.0.1"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/glob-parent": {
|
|
||||||
"version": "5.1.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
|
|
||||||
"integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
|
|
||||||
"dependencies": {
|
|
||||||
"is-glob": "^4.0.1"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/has-flag": {
|
|
||||||
"version": "3.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
|
||||||
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/ignore-by-default": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz",
|
|
||||||
"integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA=="
|
|
||||||
},
|
|
||||||
"node_modules/is-binary-path": {
|
|
||||||
"version": "2.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
|
|
||||||
"integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==",
|
|
||||||
"dependencies": {
|
|
||||||
"binary-extensions": "^2.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/is-extglob": {
|
|
||||||
"version": "2.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
|
|
||||||
"integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.10.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/is-glob": {
|
|
||||||
"version": "4.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
|
|
||||||
"integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==",
|
|
||||||
"dependencies": {
|
|
||||||
"is-extglob": "^2.1.1"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.10.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/is-number": {
|
|
||||||
"version": "7.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
|
|
||||||
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.12.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/minimatch": {
|
|
||||||
"version": "3.1.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
|
|
||||||
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
|
|
||||||
"dependencies": {
|
|
||||||
"brace-expansion": "^1.1.7"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/ms": {
|
|
||||||
"version": "2.1.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
|
||||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
|
||||||
},
|
|
||||||
"node_modules/nodemon": {
|
|
||||||
"version": "3.1.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.4.tgz",
|
|
||||||
"integrity": "sha512-wjPBbFhtpJwmIeY2yP7QF+UKzPfltVGtfce1g/bB15/8vCGZj8uxD62b/b9M9/WVgme0NZudpownKN+c0plXlQ==",
|
|
||||||
"dependencies": {
|
|
||||||
"chokidar": "^3.5.2",
|
|
||||||
"debug": "^4",
|
|
||||||
"ignore-by-default": "^1.0.1",
|
|
||||||
"minimatch": "^3.1.2",
|
|
||||||
"pstree.remy": "^1.1.8",
|
|
||||||
"semver": "^7.5.3",
|
|
||||||
"simple-update-notifier": "^2.0.0",
|
|
||||||
"supports-color": "^5.5.0",
|
|
||||||
"touch": "^3.1.0",
|
|
||||||
"undefsafe": "^2.0.5"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"nodemon": "bin/nodemon.js"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=10"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"type": "opencollective",
|
|
||||||
"url": "https://opencollective.com/nodemon"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/normalize-path": {
|
|
||||||
"version": "3.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
|
||||||
"integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.10.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/pg": {
|
|
||||||
"version": "8.12.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/pg/-/pg-8.12.0.tgz",
|
|
||||||
"integrity": "sha512-A+LHUSnwnxrnL/tZ+OLfqR1SxLN3c/pgDztZ47Rpbsd4jUytsTtwQo/TLPRzPJMp/1pbhYVhH9cuSZLAajNfjQ==",
|
|
||||||
"dependencies": {
|
|
||||||
"pg-connection-string": "^2.6.4",
|
|
||||||
"pg-pool": "^3.6.2",
|
|
||||||
"pg-protocol": "^1.6.1",
|
|
||||||
"pg-types": "^2.1.0",
|
|
||||||
"pgpass": "1.x"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 8.0.0"
|
|
||||||
},
|
|
||||||
"optionalDependencies": {
|
|
||||||
"pg-cloudflare": "^1.1.1"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"pg-native": ">=3.0.1"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"pg-native": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/pg-cloudflare": {
|
|
||||||
"version": "1.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.1.1.tgz",
|
|
||||||
"integrity": "sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==",
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"node_modules/pg-connection-string": {
|
|
||||||
"version": "2.6.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.6.4.tgz",
|
|
||||||
"integrity": "sha512-v+Z7W/0EO707aNMaAEfiGnGL9sxxumwLl2fJvCQtMn9Fxsg+lPpPkdcyBSv/KFgpGdYkMfn+EI1Or2EHjpgLCA=="
|
|
||||||
},
|
|
||||||
"node_modules/pg-int8": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
|
|
||||||
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/pg-pool": {
|
|
||||||
"version": "3.6.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.6.2.tgz",
|
|
||||||
"integrity": "sha512-Htjbg8BlwXqSBQ9V8Vjtc+vzf/6fVUuak/3/XXKA9oxZprwW3IMDQTGHP+KDmVL7rtd+R1QjbnCFPuTHm3G4hg==",
|
|
||||||
"peerDependencies": {
|
|
||||||
"pg": ">=8.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/pg-protocol": {
|
|
||||||
"version": "1.6.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.6.1.tgz",
|
|
||||||
"integrity": "sha512-jPIlvgoD63hrEuihvIg+tJhoGjUsLPn6poJY9N5CnlPd91c2T18T/9zBtLxZSb1EhYxBRoZJtzScCaWlYLtktg=="
|
|
||||||
},
|
|
||||||
"node_modules/pg-types": {
|
|
||||||
"version": "2.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
|
|
||||||
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
|
|
||||||
"dependencies": {
|
|
||||||
"pg-int8": "1.0.1",
|
|
||||||
"postgres-array": "~2.0.0",
|
|
||||||
"postgres-bytea": "~1.0.0",
|
|
||||||
"postgres-date": "~1.0.4",
|
|
||||||
"postgres-interval": "^1.1.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/pgpass": {
|
|
||||||
"version": "1.0.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz",
|
|
||||||
"integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==",
|
|
||||||
"dependencies": {
|
|
||||||
"split2": "^4.1.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/picomatch": {
|
|
||||||
"version": "2.3.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
|
|
||||||
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8.6"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"url": "https://github.com/sponsors/jonschlinkert"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/postgres-array": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
|
|
||||||
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/postgres-bytea": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
|
|
||||||
"integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.10.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/postgres-date": {
|
|
||||||
"version": "1.0.7",
|
|
||||||
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
|
|
||||||
"integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.10.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/postgres-interval": {
|
|
||||||
"version": "1.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
|
|
||||||
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
|
|
||||||
"dependencies": {
|
|
||||||
"xtend": "^4.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.10.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/pstree.remy": {
|
|
||||||
"version": "1.1.8",
|
|
||||||
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz",
|
|
||||||
"integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w=="
|
|
||||||
},
|
|
||||||
"node_modules/readdirp": {
|
|
||||||
"version": "3.6.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",
|
|
||||||
"integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==",
|
|
||||||
"dependencies": {
|
|
||||||
"picomatch": "^2.2.1"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8.10.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/semver": {
|
|
||||||
"version": "7.6.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz",
|
|
||||||
"integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==",
|
|
||||||
"bin": {
|
|
||||||
"semver": "bin/semver.js"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=10"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/simple-update-notifier": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz",
|
|
||||||
"integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==",
|
|
||||||
"dependencies": {
|
|
||||||
"semver": "^7.5.3"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=10"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/split2": {
|
|
||||||
"version": "4.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
|
|
||||||
"integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 10.x"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/supports-color": {
|
|
||||||
"version": "5.5.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
|
||||||
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
|
|
||||||
"dependencies": {
|
|
||||||
"has-flag": "^3.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/to-regex-range": {
|
|
||||||
"version": "5.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
|
||||||
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
|
|
||||||
"dependencies": {
|
|
||||||
"is-number": "^7.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/touch": {
|
|
||||||
"version": "3.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz",
|
|
||||||
"integrity": "sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==",
|
|
||||||
"bin": {
|
|
||||||
"nodetouch": "bin/nodetouch.js"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/undefsafe": {
|
|
||||||
"version": "2.0.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz",
|
|
||||||
"integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA=="
|
|
||||||
},
|
|
||||||
"node_modules/xtend": {
|
|
||||||
"version": "4.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
|
||||||
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.4"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
The ISC License
|
|
||||||
|
|
||||||
Copyright (c) 2019 Elan Shanker, Paul Miller (https://paulmillr.com)
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
||||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
@ -1,87 +0,0 @@
|
||||||
anymatch [![Build Status](https://travis-ci.org/micromatch/anymatch.svg?branch=master)](https://travis-ci.org/micromatch/anymatch) [![Coverage Status](https://img.shields.io/coveralls/micromatch/anymatch.svg?branch=master)](https://coveralls.io/r/micromatch/anymatch?branch=master)
|
|
||||||
======
|
|
||||||
Javascript module to match a string against a regular expression, glob, string,
|
|
||||||
or function that takes the string as an argument and returns a truthy or falsy
|
|
||||||
value. The matcher can also be an array of any or all of these. Useful for
|
|
||||||
allowing a very flexible user-defined config to define things like file paths.
|
|
||||||
|
|
||||||
__Note: This module has Bash-parity, please be aware that Windows-style backslashes are not supported as separators. See https://github.com/micromatch/micromatch#backslashes for more information.__
|
|
||||||
|
|
||||||
|
|
||||||
Usage
|
|
||||||
-----
|
|
||||||
```sh
|
|
||||||
npm install anymatch
|
|
||||||
```
|
|
||||||
|
|
||||||
#### anymatch(matchers, testString, [returnIndex], [options])
|
|
||||||
* __matchers__: (_Array|String|RegExp|Function_)
|
|
||||||
String to be directly matched, string with glob patterns, regular expression
|
|
||||||
test, function that takes the testString as an argument and returns a truthy
|
|
||||||
value if it should be matched, or an array of any number and mix of these types.
|
|
||||||
* __testString__: (_String|Array_) The string to test against the matchers. If
|
|
||||||
passed as an array, the first element of the array will be used as the
|
|
||||||
`testString` for non-function matchers, while the entire array will be applied
|
|
||||||
as the arguments for function matchers.
|
|
||||||
* __options__: (_Object_ [optional]_) Any of the [picomatch](https://github.com/micromatch/picomatch#options) options.
|
|
||||||
* __returnIndex__: (_Boolean [optional]_) If true, return the array index of
|
|
||||||
the first matcher that that testString matched, or -1 if no match, instead of a
|
|
||||||
boolean result.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const anymatch = require('anymatch');
|
|
||||||
|
|
||||||
const matchers = [ 'path/to/file.js', 'path/anyjs/**/*.js', /foo.js$/, string => string.includes('bar') && string.length > 10 ] ;
|
|
||||||
|
|
||||||
anymatch(matchers, 'path/to/file.js'); // true
|
|
||||||
anymatch(matchers, 'path/anyjs/baz.js'); // true
|
|
||||||
anymatch(matchers, 'path/to/foo.js'); // true
|
|
||||||
anymatch(matchers, 'path/to/bar.js'); // true
|
|
||||||
anymatch(matchers, 'bar.js'); // false
|
|
||||||
|
|
||||||
// returnIndex = true
|
|
||||||
anymatch(matchers, 'foo.js', {returnIndex: true}); // 2
|
|
||||||
anymatch(matchers, 'path/anyjs/foo.js', {returnIndex: true}); // 1
|
|
||||||
|
|
||||||
// any picomatc
|
|
||||||
|
|
||||||
// using globs to match directories and their children
|
|
||||||
anymatch('node_modules', 'node_modules'); // true
|
|
||||||
anymatch('node_modules', 'node_modules/somelib/index.js'); // false
|
|
||||||
anymatch('node_modules/**', 'node_modules/somelib/index.js'); // true
|
|
||||||
anymatch('node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // false
|
|
||||||
anymatch('**/node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // true
|
|
||||||
|
|
||||||
const matcher = anymatch(matchers);
|
|
||||||
['foo.js', 'bar.js'].filter(matcher); // [ 'foo.js' ]
|
|
||||||
anymatch master* ❯
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
#### anymatch(matchers)
|
|
||||||
You can also pass in only your matcher(s) to get a curried function that has
|
|
||||||
already been bound to the provided matching criteria. This can be used as an
|
|
||||||
`Array#filter` callback.
|
|
||||||
|
|
||||||
```js
|
|
||||||
var matcher = anymatch(matchers);
|
|
||||||
|
|
||||||
matcher('path/to/file.js'); // true
|
|
||||||
matcher('path/anyjs/baz.js', true); // 1
|
|
||||||
|
|
||||||
['foo.js', 'bar.js'].filter(matcher); // ['foo.js']
|
|
||||||
```
|
|
||||||
|
|
||||||
Changelog
|
|
||||||
----------
|
|
||||||
[See release notes page on GitHub](https://github.com/micromatch/anymatch/releases)
|
|
||||||
|
|
||||||
- **v3.0:** Removed `startIndex` and `endIndex` arguments. Node 8.x-only.
|
|
||||||
- **v2.0:** [micromatch](https://github.com/jonschlinkert/micromatch) moves away from minimatch-parity and inline with Bash. This includes handling backslashes differently (see https://github.com/micromatch/micromatch#backslashes for more information).
|
|
||||||
- **v1.2:** anymatch uses [micromatch](https://github.com/jonschlinkert/micromatch)
|
|
||||||
for glob pattern matching. Issues with glob pattern matching should be
|
|
||||||
reported directly to the [micromatch issue tracker](https://github.com/jonschlinkert/micromatch/issues).
|
|
||||||
|
|
||||||
License
|
|
||||||
-------
|
|
||||||
[ISC](https://raw.github.com/micromatch/anymatch/master/LICENSE)
|
|
|
@ -1,20 +0,0 @@
|
||||||
type AnymatchFn = (testString: string) => boolean;
|
|
||||||
type AnymatchPattern = string|RegExp|AnymatchFn;
|
|
||||||
type AnymatchMatcher = AnymatchPattern|AnymatchPattern[]
|
|
||||||
type AnymatchTester = {
|
|
||||||
(testString: string|any[], returnIndex: true): number;
|
|
||||||
(testString: string|any[]): boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
type PicomatchOptions = {dot: boolean};
|
|
||||||
|
|
||||||
declare const anymatch: {
|
|
||||||
(matchers: AnymatchMatcher): AnymatchTester;
|
|
||||||
(matchers: AnymatchMatcher, testString: null, returnIndex: true | PicomatchOptions): AnymatchTester;
|
|
||||||
(matchers: AnymatchMatcher, testString: string|any[], returnIndex: true | PicomatchOptions): number;
|
|
||||||
(matchers: AnymatchMatcher, testString: string|any[]): boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export {AnymatchMatcher as Matcher}
|
|
||||||
export {AnymatchTester as Tester}
|
|
||||||
export default anymatch
|
|
|
@ -1,104 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
|
|
||||||
const picomatch = require('picomatch');
|
|
||||||
const normalizePath = require('normalize-path');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {(testString: string) => boolean} AnymatchFn
|
|
||||||
* @typedef {string|RegExp|AnymatchFn} AnymatchPattern
|
|
||||||
* @typedef {AnymatchPattern|AnymatchPattern[]} AnymatchMatcher
|
|
||||||
*/
|
|
||||||
const BANG = '!';
|
|
||||||
const DEFAULT_OPTIONS = {returnIndex: false};
|
|
||||||
const arrify = (item) => Array.isArray(item) ? item : [item];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {AnymatchPattern} matcher
|
|
||||||
* @param {object} options
|
|
||||||
* @returns {AnymatchFn}
|
|
||||||
*/
|
|
||||||
const createPattern = (matcher, options) => {
|
|
||||||
if (typeof matcher === 'function') {
|
|
||||||
return matcher;
|
|
||||||
}
|
|
||||||
if (typeof matcher === 'string') {
|
|
||||||
const glob = picomatch(matcher, options);
|
|
||||||
return (string) => matcher === string || glob(string);
|
|
||||||
}
|
|
||||||
if (matcher instanceof RegExp) {
|
|
||||||
return (string) => matcher.test(string);
|
|
||||||
}
|
|
||||||
return (string) => false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Array<Function>} patterns
|
|
||||||
* @param {Array<Function>} negPatterns
|
|
||||||
* @param {String|Array} args
|
|
||||||
* @param {Boolean} returnIndex
|
|
||||||
* @returns {boolean|number}
|
|
||||||
*/
|
|
||||||
const matchPatterns = (patterns, negPatterns, args, returnIndex) => {
|
|
||||||
const isList = Array.isArray(args);
|
|
||||||
const _path = isList ? args[0] : args;
|
|
||||||
if (!isList && typeof _path !== 'string') {
|
|
||||||
throw new TypeError('anymatch: second argument must be a string: got ' +
|
|
||||||
Object.prototype.toString.call(_path))
|
|
||||||
}
|
|
||||||
const path = normalizePath(_path, false);
|
|
||||||
|
|
||||||
for (let index = 0; index < negPatterns.length; index++) {
|
|
||||||
const nglob = negPatterns[index];
|
|
||||||
if (nglob(path)) {
|
|
||||||
return returnIndex ? -1 : false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const applied = isList && [path].concat(args.slice(1));
|
|
||||||
for (let index = 0; index < patterns.length; index++) {
|
|
||||||
const pattern = patterns[index];
|
|
||||||
if (isList ? pattern(...applied) : pattern(path)) {
|
|
||||||
return returnIndex ? index : true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnIndex ? -1 : false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {AnymatchMatcher} matchers
|
|
||||||
* @param {Array|string} testString
|
|
||||||
* @param {object} options
|
|
||||||
* @returns {boolean|number|Function}
|
|
||||||
*/
|
|
||||||
const anymatch = (matchers, testString, options = DEFAULT_OPTIONS) => {
|
|
||||||
if (matchers == null) {
|
|
||||||
throw new TypeError('anymatch: specify first argument');
|
|
||||||
}
|
|
||||||
const opts = typeof options === 'boolean' ? {returnIndex: options} : options;
|
|
||||||
const returnIndex = opts.returnIndex || false;
|
|
||||||
|
|
||||||
// Early cache for matchers.
|
|
||||||
const mtchers = arrify(matchers);
|
|
||||||
const negatedGlobs = mtchers
|
|
||||||
.filter(item => typeof item === 'string' && item.charAt(0) === BANG)
|
|
||||||
.map(item => item.slice(1))
|
|
||||||
.map(item => picomatch(item, opts));
|
|
||||||
const patterns = mtchers
|
|
||||||
.filter(item => typeof item !== 'string' || (typeof item === 'string' && item.charAt(0) !== BANG))
|
|
||||||
.map(matcher => createPattern(matcher, opts));
|
|
||||||
|
|
||||||
if (testString == null) {
|
|
||||||
return (testString, ri = false) => {
|
|
||||||
const returnIndex = typeof ri === 'boolean' ? ri : false;
|
|
||||||
return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
|
|
||||||
};
|
|
||||||
|
|
||||||
anymatch.default = anymatch;
|
|
||||||
module.exports = anymatch;
|
|
|
@ -1,48 +0,0 @@
|
||||||
{
|
|
||||||
"name": "anymatch",
|
|
||||||
"version": "3.1.3",
|
|
||||||
"description": "Matches strings against configurable strings, globs, regular expressions, and/or functions",
|
|
||||||
"files": [
|
|
||||||
"index.js",
|
|
||||||
"index.d.ts"
|
|
||||||
],
|
|
||||||
"dependencies": {
|
|
||||||
"normalize-path": "^3.0.0",
|
|
||||||
"picomatch": "^2.0.4"
|
|
||||||
},
|
|
||||||
"author": {
|
|
||||||
"name": "Elan Shanker",
|
|
||||||
"url": "https://github.com/es128"
|
|
||||||
},
|
|
||||||
"license": "ISC",
|
|
||||||
"homepage": "https://github.com/micromatch/anymatch",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/micromatch/anymatch"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"match",
|
|
||||||
"any",
|
|
||||||
"string",
|
|
||||||
"file",
|
|
||||||
"fs",
|
|
||||||
"list",
|
|
||||||
"glob",
|
|
||||||
"regex",
|
|
||||||
"regexp",
|
|
||||||
"regular",
|
|
||||||
"expression",
|
|
||||||
"function"
|
|
||||||
],
|
|
||||||
"scripts": {
|
|
||||||
"test": "nyc mocha",
|
|
||||||
"mocha": "mocha"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"mocha": "^6.1.3",
|
|
||||||
"nyc": "^14.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 8"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
tidelift: "npm/balanced-match"
|
|
||||||
patreon: juliangruber
|
|
|
@ -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,97 +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
|
|
||||||
```
|
|
||||||
|
|
||||||
## Security contact information
|
|
||||||
|
|
||||||
To report a security vulnerability, please use the
|
|
||||||
[Tidelift security contact](https://tidelift.com/security).
|
|
||||||
Tidelift will coordinate the fix and disclosure.
|
|
||||||
|
|
||||||
## 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,62 +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) {
|
|
||||||
if(a===b) {
|
|
||||||
return [ai, bi];
|
|
||||||
}
|
|
||||||
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,48 +0,0 @@
|
||||||
{
|
|
||||||
"name": "balanced-match",
|
|
||||||
"description": "Match balanced character pairs, like \"{\" and \"}\"",
|
|
||||||
"version": "1.0.2",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/juliangruber/balanced-match.git"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/juliangruber/balanced-match",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "tape test/test.js",
|
|
||||||
"bench": "matcha test/bench.js"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"matcha": "^0.7.0",
|
|
||||||
"tape": "^4.6.0"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"match",
|
|
||||||
"regexp",
|
|
||||||
"test",
|
|
||||||
"balanced",
|
|
||||||
"parse"
|
|
||||||
],
|
|
||||||
"author": {
|
|
||||||
"name": "Julian Gruber",
|
|
||||||
"email": "mail@juliangruber.com",
|
|
||||||
"url": "http://juliangruber.com"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"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"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,263 +0,0 @@
|
||||||
[
|
|
||||||
"3dm",
|
|
||||||
"3ds",
|
|
||||||
"3g2",
|
|
||||||
"3gp",
|
|
||||||
"7z",
|
|
||||||
"a",
|
|
||||||
"aac",
|
|
||||||
"adp",
|
|
||||||
"afdesign",
|
|
||||||
"afphoto",
|
|
||||||
"afpub",
|
|
||||||
"ai",
|
|
||||||
"aif",
|
|
||||||
"aiff",
|
|
||||||
"alz",
|
|
||||||
"ape",
|
|
||||||
"apk",
|
|
||||||
"appimage",
|
|
||||||
"ar",
|
|
||||||
"arj",
|
|
||||||
"asf",
|
|
||||||
"au",
|
|
||||||
"avi",
|
|
||||||
"bak",
|
|
||||||
"baml",
|
|
||||||
"bh",
|
|
||||||
"bin",
|
|
||||||
"bk",
|
|
||||||
"bmp",
|
|
||||||
"btif",
|
|
||||||
"bz2",
|
|
||||||
"bzip2",
|
|
||||||
"cab",
|
|
||||||
"caf",
|
|
||||||
"cgm",
|
|
||||||
"class",
|
|
||||||
"cmx",
|
|
||||||
"cpio",
|
|
||||||
"cr2",
|
|
||||||
"cur",
|
|
||||||
"dat",
|
|
||||||
"dcm",
|
|
||||||
"deb",
|
|
||||||
"dex",
|
|
||||||
"djvu",
|
|
||||||
"dll",
|
|
||||||
"dmg",
|
|
||||||
"dng",
|
|
||||||
"doc",
|
|
||||||
"docm",
|
|
||||||
"docx",
|
|
||||||
"dot",
|
|
||||||
"dotm",
|
|
||||||
"dra",
|
|
||||||
"DS_Store",
|
|
||||||
"dsk",
|
|
||||||
"dts",
|
|
||||||
"dtshd",
|
|
||||||
"dvb",
|
|
||||||
"dwg",
|
|
||||||
"dxf",
|
|
||||||
"ecelp4800",
|
|
||||||
"ecelp7470",
|
|
||||||
"ecelp9600",
|
|
||||||
"egg",
|
|
||||||
"eol",
|
|
||||||
"eot",
|
|
||||||
"epub",
|
|
||||||
"exe",
|
|
||||||
"f4v",
|
|
||||||
"fbs",
|
|
||||||
"fh",
|
|
||||||
"fla",
|
|
||||||
"flac",
|
|
||||||
"flatpak",
|
|
||||||
"fli",
|
|
||||||
"flv",
|
|
||||||
"fpx",
|
|
||||||
"fst",
|
|
||||||
"fvt",
|
|
||||||
"g3",
|
|
||||||
"gh",
|
|
||||||
"gif",
|
|
||||||
"graffle",
|
|
||||||
"gz",
|
|
||||||
"gzip",
|
|
||||||
"h261",
|
|
||||||
"h263",
|
|
||||||
"h264",
|
|
||||||
"icns",
|
|
||||||
"ico",
|
|
||||||
"ief",
|
|
||||||
"img",
|
|
||||||
"ipa",
|
|
||||||
"iso",
|
|
||||||
"jar",
|
|
||||||
"jpeg",
|
|
||||||
"jpg",
|
|
||||||
"jpgv",
|
|
||||||
"jpm",
|
|
||||||
"jxr",
|
|
||||||
"key",
|
|
||||||
"ktx",
|
|
||||||
"lha",
|
|
||||||
"lib",
|
|
||||||
"lvp",
|
|
||||||
"lz",
|
|
||||||
"lzh",
|
|
||||||
"lzma",
|
|
||||||
"lzo",
|
|
||||||
"m3u",
|
|
||||||
"m4a",
|
|
||||||
"m4v",
|
|
||||||
"mar",
|
|
||||||
"mdi",
|
|
||||||
"mht",
|
|
||||||
"mid",
|
|
||||||
"midi",
|
|
||||||
"mj2",
|
|
||||||
"mka",
|
|
||||||
"mkv",
|
|
||||||
"mmr",
|
|
||||||
"mng",
|
|
||||||
"mobi",
|
|
||||||
"mov",
|
|
||||||
"movie",
|
|
||||||
"mp3",
|
|
||||||
"mp4",
|
|
||||||
"mp4a",
|
|
||||||
"mpeg",
|
|
||||||
"mpg",
|
|
||||||
"mpga",
|
|
||||||
"mxu",
|
|
||||||
"nef",
|
|
||||||
"npx",
|
|
||||||
"numbers",
|
|
||||||
"nupkg",
|
|
||||||
"o",
|
|
||||||
"odp",
|
|
||||||
"ods",
|
|
||||||
"odt",
|
|
||||||
"oga",
|
|
||||||
"ogg",
|
|
||||||
"ogv",
|
|
||||||
"otf",
|
|
||||||
"ott",
|
|
||||||
"pages",
|
|
||||||
"pbm",
|
|
||||||
"pcx",
|
|
||||||
"pdb",
|
|
||||||
"pdf",
|
|
||||||
"pea",
|
|
||||||
"pgm",
|
|
||||||
"pic",
|
|
||||||
"png",
|
|
||||||
"pnm",
|
|
||||||
"pot",
|
|
||||||
"potm",
|
|
||||||
"potx",
|
|
||||||
"ppa",
|
|
||||||
"ppam",
|
|
||||||
"ppm",
|
|
||||||
"pps",
|
|
||||||
"ppsm",
|
|
||||||
"ppsx",
|
|
||||||
"ppt",
|
|
||||||
"pptm",
|
|
||||||
"pptx",
|
|
||||||
"psd",
|
|
||||||
"pya",
|
|
||||||
"pyc",
|
|
||||||
"pyo",
|
|
||||||
"pyv",
|
|
||||||
"qt",
|
|
||||||
"rar",
|
|
||||||
"ras",
|
|
||||||
"raw",
|
|
||||||
"resources",
|
|
||||||
"rgb",
|
|
||||||
"rip",
|
|
||||||
"rlc",
|
|
||||||
"rmf",
|
|
||||||
"rmvb",
|
|
||||||
"rpm",
|
|
||||||
"rtf",
|
|
||||||
"rz",
|
|
||||||
"s3m",
|
|
||||||
"s7z",
|
|
||||||
"scpt",
|
|
||||||
"sgi",
|
|
||||||
"shar",
|
|
||||||
"snap",
|
|
||||||
"sil",
|
|
||||||
"sketch",
|
|
||||||
"slk",
|
|
||||||
"smv",
|
|
||||||
"snk",
|
|
||||||
"so",
|
|
||||||
"stl",
|
|
||||||
"suo",
|
|
||||||
"sub",
|
|
||||||
"swf",
|
|
||||||
"tar",
|
|
||||||
"tbz",
|
|
||||||
"tbz2",
|
|
||||||
"tga",
|
|
||||||
"tgz",
|
|
||||||
"thmx",
|
|
||||||
"tif",
|
|
||||||
"tiff",
|
|
||||||
"tlz",
|
|
||||||
"ttc",
|
|
||||||
"ttf",
|
|
||||||
"txz",
|
|
||||||
"udf",
|
|
||||||
"uvh",
|
|
||||||
"uvi",
|
|
||||||
"uvm",
|
|
||||||
"uvp",
|
|
||||||
"uvs",
|
|
||||||
"uvu",
|
|
||||||
"viv",
|
|
||||||
"vob",
|
|
||||||
"war",
|
|
||||||
"wav",
|
|
||||||
"wax",
|
|
||||||
"wbmp",
|
|
||||||
"wdp",
|
|
||||||
"weba",
|
|
||||||
"webm",
|
|
||||||
"webp",
|
|
||||||
"whl",
|
|
||||||
"wim",
|
|
||||||
"wm",
|
|
||||||
"wma",
|
|
||||||
"wmv",
|
|
||||||
"wmx",
|
|
||||||
"woff",
|
|
||||||
"woff2",
|
|
||||||
"wrm",
|
|
||||||
"wvx",
|
|
||||||
"xbm",
|
|
||||||
"xif",
|
|
||||||
"xla",
|
|
||||||
"xlam",
|
|
||||||
"xls",
|
|
||||||
"xlsb",
|
|
||||||
"xlsm",
|
|
||||||
"xlsx",
|
|
||||||
"xlt",
|
|
||||||
"xltm",
|
|
||||||
"xltx",
|
|
||||||
"xm",
|
|
||||||
"xmind",
|
|
||||||
"xpi",
|
|
||||||
"xpm",
|
|
||||||
"xwd",
|
|
||||||
"xz",
|
|
||||||
"z",
|
|
||||||
"zip",
|
|
||||||
"zipx"
|
|
||||||
]
|
|
|
@ -1,3 +0,0 @@
|
||||||
declare const binaryExtensionsJson: readonly string[];
|
|
||||||
|
|
||||||
export = binaryExtensionsJson;
|
|
|
@ -1,14 +0,0 @@
|
||||||
/**
|
|
||||||
List of binary file extensions.
|
|
||||||
|
|
||||||
@example
|
|
||||||
```
|
|
||||||
import binaryExtensions = require('binary-extensions');
|
|
||||||
|
|
||||||
console.log(binaryExtensions);
|
|
||||||
//=> ['3ds', '3g2', …]
|
|
||||||
```
|
|
||||||
*/
|
|
||||||
declare const binaryExtensions: readonly string[];
|
|
||||||
|
|
||||||
export = binaryExtensions;
|
|
|
@ -1 +0,0 @@
|
||||||
module.exports = require('./binary-extensions.json');
|
|
|
@ -1,10 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
||||||
Copyright (c) Paul Miller (https://paulmillr.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,40 +0,0 @@
|
||||||
{
|
|
||||||
"name": "binary-extensions",
|
|
||||||
"version": "2.3.0",
|
|
||||||
"description": "List of binary file extensions",
|
|
||||||
"license": "MIT",
|
|
||||||
"repository": "sindresorhus/binary-extensions",
|
|
||||||
"funding": "https://github.com/sponsors/sindresorhus",
|
|
||||||
"author": {
|
|
||||||
"name": "Sindre Sorhus",
|
|
||||||
"email": "sindresorhus@gmail.com",
|
|
||||||
"url": "https://sindresorhus.com"
|
|
||||||
},
|
|
||||||
"sideEffects": false,
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "xo && ava && tsd"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"index.js",
|
|
||||||
"index.d.ts",
|
|
||||||
"binary-extensions.json",
|
|
||||||
"binary-extensions.json.d.ts"
|
|
||||||
],
|
|
||||||
"keywords": [
|
|
||||||
"binary",
|
|
||||||
"extensions",
|
|
||||||
"extension",
|
|
||||||
"file",
|
|
||||||
"json",
|
|
||||||
"list",
|
|
||||||
"array"
|
|
||||||
],
|
|
||||||
"devDependencies": {
|
|
||||||
"ava": "^1.4.1",
|
|
||||||
"tsd": "^0.7.2",
|
|
||||||
"xo": "^0.24.0"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
# binary-extensions
|
|
||||||
|
|
||||||
> List of binary file extensions
|
|
||||||
|
|
||||||
The list is just a [JSON file](binary-extensions.json) and can be used anywhere.
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm install binary-extensions
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```js
|
|
||||||
const binaryExtensions = require('binary-extensions');
|
|
||||||
|
|
||||||
console.log(binaryExtensions);
|
|
||||||
//=> ['3ds', '3g2', …]
|
|
||||||
```
|
|
||||||
|
|
||||||
## Related
|
|
||||||
|
|
||||||
- [is-binary-path](https://github.com/sindresorhus/is-binary-path) - Check if a filepath is a binary file
|
|
||||||
- [text-extensions](https://github.com/sindresorhus/text-extensions) - List of text file extensions
|
|
|
@ -1,21 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
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,129 +0,0 @@
|
||||||
# brace-expansion
|
|
||||||
|
|
||||||
[Brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html),
|
|
||||||
as known from sh/bash, in JavaScript.
|
|
||||||
|
|
||||||
[![build status](https://secure.travis-ci.org/juliangruber/brace-expansion.svg)](http://travis-ci.org/juliangruber/brace-expansion)
|
|
||||||
[![downloads](https://img.shields.io/npm/dm/brace-expansion.svg)](https://www.npmjs.org/package/brace-expansion)
|
|
||||||
[![Greenkeeper badge](https://badges.greenkeeper.io/juliangruber/brace-expansion.svg)](https://greenkeeper.io/)
|
|
||||||
|
|
||||||
[![testling badge](https://ci.testling.com/juliangruber/brace-expansion.png)](https://ci.testling.com/juliangruber/brace-expansion)
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```js
|
|
||||||
var expand = require('brace-expansion');
|
|
||||||
|
|
||||||
expand('file-{a,b,c}.jpg')
|
|
||||||
// => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']
|
|
||||||
|
|
||||||
expand('-v{,,}')
|
|
||||||
// => ['-v', '-v', '-v']
|
|
||||||
|
|
||||||
expand('file{0..2}.jpg')
|
|
||||||
// => ['file0.jpg', 'file1.jpg', 'file2.jpg']
|
|
||||||
|
|
||||||
expand('file-{a..c}.jpg')
|
|
||||||
// => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']
|
|
||||||
|
|
||||||
expand('file{2..0}.jpg')
|
|
||||||
// => ['file2.jpg', 'file1.jpg', 'file0.jpg']
|
|
||||||
|
|
||||||
expand('file{0..4..2}.jpg')
|
|
||||||
// => ['file0.jpg', 'file2.jpg', 'file4.jpg']
|
|
||||||
|
|
||||||
expand('file-{a..e..2}.jpg')
|
|
||||||
// => ['file-a.jpg', 'file-c.jpg', 'file-e.jpg']
|
|
||||||
|
|
||||||
expand('file{00..10..5}.jpg')
|
|
||||||
// => ['file00.jpg', 'file05.jpg', 'file10.jpg']
|
|
||||||
|
|
||||||
expand('{{A..C},{a..c}}')
|
|
||||||
// => ['A', 'B', 'C', 'a', 'b', 'c']
|
|
||||||
|
|
||||||
expand('ppp{,config,oe{,conf}}')
|
|
||||||
// => ['ppp', 'pppconfig', 'pppoe', 'pppoeconf']
|
|
||||||
```
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
```js
|
|
||||||
var expand = require('brace-expansion');
|
|
||||||
```
|
|
||||||
|
|
||||||
### var expanded = expand(str)
|
|
||||||
|
|
||||||
Return an array of all possible and valid expansions of `str`. If none are
|
|
||||||
found, `[str]` is returned.
|
|
||||||
|
|
||||||
Valid expansions are:
|
|
||||||
|
|
||||||
```js
|
|
||||||
/^(.*,)+(.+)?$/
|
|
||||||
// {a,b,...}
|
|
||||||
```
|
|
||||||
|
|
||||||
A comma separated list of options, like `{a,b}` or `{a,{b,c}}` or `{,a,}`.
|
|
||||||
|
|
||||||
```js
|
|
||||||
/^-?\d+\.\.-?\d+(\.\.-?\d+)?$/
|
|
||||||
// {x..y[..incr]}
|
|
||||||
```
|
|
||||||
|
|
||||||
A numeric sequence from `x` to `y` inclusive, with optional increment.
|
|
||||||
If `x` or `y` start with a leading `0`, all the numbers will be padded
|
|
||||||
to have equal length. Negative numbers and backwards iteration work too.
|
|
||||||
|
|
||||||
```js
|
|
||||||
/^-?\d+\.\.-?\d+(\.\.-?\d+)?$/
|
|
||||||
// {x..y[..incr]}
|
|
||||||
```
|
|
||||||
|
|
||||||
An alphabetic sequence from `x` to `y` inclusive, with optional increment.
|
|
||||||
`x` and `y` must be exactly one character, and if given, `incr` must be a
|
|
||||||
number.
|
|
||||||
|
|
||||||
For compatibility reasons, the string `${` is not eligible for brace expansion.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
With [npm](https://npmjs.org) do:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm install brace-expansion
|
|
||||||
```
|
|
||||||
|
|
||||||
## Contributors
|
|
||||||
|
|
||||||
- [Julian Gruber](https://github.com/juliangruber)
|
|
||||||
- [Isaac Z. Schlueter](https://github.com/isaacs)
|
|
||||||
|
|
||||||
## Sponsors
|
|
||||||
|
|
||||||
This module is proudly supported by my [Sponsors](https://github.com/juliangruber/sponsors)!
|
|
||||||
|
|
||||||
Do you want to support modules like this to improve their quality, stability and weigh in on new features? Then please consider donating to my [Patreon](https://www.patreon.com/juliangruber). Not sure how much of my modules you're using? Try [feross/thanks](https://github.com/feross/thanks)!
|
|
||||||
|
|
||||||
## 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,201 +0,0 @@
|
||||||
var concatMap = require('concat-map');
|
|
||||||
var balanced = require('balanced-match');
|
|
||||||
|
|
||||||
module.exports = expandTop;
|
|
||||||
|
|
||||||
var escSlash = '\0SLASH'+Math.random()+'\0';
|
|
||||||
var escOpen = '\0OPEN'+Math.random()+'\0';
|
|
||||||
var escClose = '\0CLOSE'+Math.random()+'\0';
|
|
||||||
var escComma = '\0COMMA'+Math.random()+'\0';
|
|
||||||
var escPeriod = '\0PERIOD'+Math.random()+'\0';
|
|
||||||
|
|
||||||
function numeric(str) {
|
|
||||||
return parseInt(str, 10) == str
|
|
||||||
? parseInt(str, 10)
|
|
||||||
: str.charCodeAt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function escapeBraces(str) {
|
|
||||||
return str.split('\\\\').join(escSlash)
|
|
||||||
.split('\\{').join(escOpen)
|
|
||||||
.split('\\}').join(escClose)
|
|
||||||
.split('\\,').join(escComma)
|
|
||||||
.split('\\.').join(escPeriod);
|
|
||||||
}
|
|
||||||
|
|
||||||
function unescapeBraces(str) {
|
|
||||||
return str.split(escSlash).join('\\')
|
|
||||||
.split(escOpen).join('{')
|
|
||||||
.split(escClose).join('}')
|
|
||||||
.split(escComma).join(',')
|
|
||||||
.split(escPeriod).join('.');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Basically just str.split(","), but handling cases
|
|
||||||
// where we have nested braced sections, which should be
|
|
||||||
// treated as individual members, like {a,{b,c},d}
|
|
||||||
function parseCommaParts(str) {
|
|
||||||
if (!str)
|
|
||||||
return [''];
|
|
||||||
|
|
||||||
var parts = [];
|
|
||||||
var m = balanced('{', '}', str);
|
|
||||||
|
|
||||||
if (!m)
|
|
||||||
return str.split(',');
|
|
||||||
|
|
||||||
var pre = m.pre;
|
|
||||||
var body = m.body;
|
|
||||||
var post = m.post;
|
|
||||||
var p = pre.split(',');
|
|
||||||
|
|
||||||
p[p.length-1] += '{' + body + '}';
|
|
||||||
var postParts = parseCommaParts(post);
|
|
||||||
if (post.length) {
|
|
||||||
p[p.length-1] += postParts.shift();
|
|
||||||
p.push.apply(p, postParts);
|
|
||||||
}
|
|
||||||
|
|
||||||
parts.push.apply(parts, p);
|
|
||||||
|
|
||||||
return parts;
|
|
||||||
}
|
|
||||||
|
|
||||||
function expandTop(str) {
|
|
||||||
if (!str)
|
|
||||||
return [];
|
|
||||||
|
|
||||||
// I don't know why Bash 4.3 does this, but it does.
|
|
||||||
// Anything starting with {} will have the first two bytes preserved
|
|
||||||
// but *only* at the top level, so {},a}b will not expand to anything,
|
|
||||||
// but a{},b}c will be expanded to [a}c,abc].
|
|
||||||
// One could argue that this is a bug in Bash, but since the goal of
|
|
||||||
// this module is to match Bash's rules, we escape a leading {}
|
|
||||||
if (str.substr(0, 2) === '{}') {
|
|
||||||
str = '\\{\\}' + str.substr(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
return expand(escapeBraces(str), true).map(unescapeBraces);
|
|
||||||
}
|
|
||||||
|
|
||||||
function identity(e) {
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
|
|
||||||
function embrace(str) {
|
|
||||||
return '{' + str + '}';
|
|
||||||
}
|
|
||||||
function isPadded(el) {
|
|
||||||
return /^-?0\d/.test(el);
|
|
||||||
}
|
|
||||||
|
|
||||||
function lte(i, y) {
|
|
||||||
return i <= y;
|
|
||||||
}
|
|
||||||
function gte(i, y) {
|
|
||||||
return i >= y;
|
|
||||||
}
|
|
||||||
|
|
||||||
function expand(str, isTop) {
|
|
||||||
var expansions = [];
|
|
||||||
|
|
||||||
var m = balanced('{', '}', str);
|
|
||||||
if (!m || /\$$/.test(m.pre)) return [str];
|
|
||||||
|
|
||||||
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
||||||
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
||||||
var isSequence = isNumericSequence || isAlphaSequence;
|
|
||||||
var isOptions = m.body.indexOf(',') >= 0;
|
|
||||||
if (!isSequence && !isOptions) {
|
|
||||||
// {a},b}
|
|
||||||
if (m.post.match(/,.*\}/)) {
|
|
||||||
str = m.pre + '{' + m.body + escClose + m.post;
|
|
||||||
return expand(str);
|
|
||||||
}
|
|
||||||
return [str];
|
|
||||||
}
|
|
||||||
|
|
||||||
var n;
|
|
||||||
if (isSequence) {
|
|
||||||
n = m.body.split(/\.\./);
|
|
||||||
} else {
|
|
||||||
n = parseCommaParts(m.body);
|
|
||||||
if (n.length === 1) {
|
|
||||||
// x{{a,b}}y ==> x{a}y x{b}y
|
|
||||||
n = expand(n[0], false).map(embrace);
|
|
||||||
if (n.length === 1) {
|
|
||||||
var post = m.post.length
|
|
||||||
? expand(m.post, false)
|
|
||||||
: [''];
|
|
||||||
return post.map(function(p) {
|
|
||||||
return m.pre + n[0] + p;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// at this point, n is the parts, and we know it's not a comma set
|
|
||||||
// with a single entry.
|
|
||||||
|
|
||||||
// no need to expand pre, since it is guaranteed to be free of brace-sets
|
|
||||||
var pre = m.pre;
|
|
||||||
var post = m.post.length
|
|
||||||
? expand(m.post, false)
|
|
||||||
: [''];
|
|
||||||
|
|
||||||
var N;
|
|
||||||
|
|
||||||
if (isSequence) {
|
|
||||||
var x = numeric(n[0]);
|
|
||||||
var y = numeric(n[1]);
|
|
||||||
var width = Math.max(n[0].length, n[1].length)
|
|
||||||
var incr = n.length == 3
|
|
||||||
? Math.abs(numeric(n[2]))
|
|
||||||
: 1;
|
|
||||||
var test = lte;
|
|
||||||
var reverse = y < x;
|
|
||||||
if (reverse) {
|
|
||||||
incr *= -1;
|
|
||||||
test = gte;
|
|
||||||
}
|
|
||||||
var pad = n.some(isPadded);
|
|
||||||
|
|
||||||
N = [];
|
|
||||||
|
|
||||||
for (var i = x; test(i, y); i += incr) {
|
|
||||||
var c;
|
|
||||||
if (isAlphaSequence) {
|
|
||||||
c = String.fromCharCode(i);
|
|
||||||
if (c === '\\')
|
|
||||||
c = '';
|
|
||||||
} else {
|
|
||||||
c = String(i);
|
|
||||||
if (pad) {
|
|
||||||
var need = width - c.length;
|
|
||||||
if (need > 0) {
|
|
||||||
var z = new Array(need + 1).join('0');
|
|
||||||
if (i < 0)
|
|
||||||
c = '-' + z + c.slice(1);
|
|
||||||
else
|
|
||||||
c = z + c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
N.push(c);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
N = concatMap(n, function(el) { return expand(el, false) });
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var j = 0; j < N.length; j++) {
|
|
||||||
for (var k = 0; k < post.length; k++) {
|
|
||||||
var expansion = pre + N[j] + post[k];
|
|
||||||
if (!isTop || isSequence || expansion)
|
|
||||||
expansions.push(expansion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return expansions;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
{
|
|
||||||
"name": "brace-expansion",
|
|
||||||
"description": "Brace expansion as known from sh/bash",
|
|
||||||
"version": "1.1.11",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/juliangruber/brace-expansion.git"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/juliangruber/brace-expansion",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "tape test/*.js",
|
|
||||||
"gentest": "bash test/generate.sh",
|
|
||||||
"bench": "matcha test/perf/bench.js"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"balanced-match": "^1.0.0",
|
|
||||||
"concat-map": "0.0.1"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"matcha": "^0.7.0",
|
|
||||||
"tape": "^4.6.0"
|
|
||||||
},
|
|
||||||
"keywords": [],
|
|
||||||
"author": {
|
|
||||||
"name": "Julian Gruber",
|
|
||||||
"email": "mail@juliangruber.com",
|
|
||||||
"url": "http://juliangruber.com"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"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"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2014-present, Jon Schlinkert.
|
|
||||||
|
|
||||||
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,586 +0,0 @@
|
||||||
# braces [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/braces.svg?style=flat)](https://www.npmjs.com/package/braces) [![NPM monthly downloads](https://img.shields.io/npm/dm/braces.svg?style=flat)](https://npmjs.org/package/braces) [![NPM total downloads](https://img.shields.io/npm/dt/braces.svg?style=flat)](https://npmjs.org/package/braces) [![Linux Build Status](https://img.shields.io/travis/micromatch/braces.svg?style=flat&label=Travis)](https://travis-ci.org/micromatch/braces)
|
|
||||||
|
|
||||||
> Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support for the Bash 4.3 braces specification, without sacrificing speed.
|
|
||||||
|
|
||||||
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
Install with [npm](https://www.npmjs.com/):
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install --save braces
|
|
||||||
```
|
|
||||||
|
|
||||||
## v3.0.0 Released!!
|
|
||||||
|
|
||||||
See the [changelog](CHANGELOG.md) for details.
|
|
||||||
|
|
||||||
## Why use braces?
|
|
||||||
|
|
||||||
Brace patterns make globs more powerful by adding the ability to match specific ranges and sequences of characters.
|
|
||||||
|
|
||||||
- **Accurate** - complete support for the [Bash 4.3 Brace Expansion](www.gnu.org/software/bash/) specification (passes all of the Bash braces tests)
|
|
||||||
- **[fast and performant](#benchmarks)** - Starts fast, runs fast and [scales well](#performance) as patterns increase in complexity.
|
|
||||||
- **Organized code base** - The parser and compiler are easy to maintain and update when edge cases crop up.
|
|
||||||
- **Well-tested** - Thousands of test assertions, and passes all of the Bash, minimatch, and [brace-expansion](https://github.com/juliangruber/brace-expansion) unit tests (as of the date this was written).
|
|
||||||
- **Safer** - You shouldn't have to worry about users defining aggressive or malicious brace patterns that can break your application. Braces takes measures to prevent malicious regex that can be used for DDoS attacks (see [catastrophic backtracking](https://www.regular-expressions.info/catastrophic.html)).
|
|
||||||
- [Supports lists](#lists) - (aka "sets") `a/{b,c}/d` => `['a/b/d', 'a/c/d']`
|
|
||||||
- [Supports sequences](#sequences) - (aka "ranges") `{01..03}` => `['01', '02', '03']`
|
|
||||||
- [Supports steps](#steps) - (aka "increments") `{2..10..2}` => `['2', '4', '6', '8', '10']`
|
|
||||||
- [Supports escaping](#escaping) - To prevent evaluation of special characters.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
The main export is a function that takes one or more brace `patterns` and `options`.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const braces = require('braces');
|
|
||||||
// braces(patterns[, options]);
|
|
||||||
|
|
||||||
console.log(braces(['{01..05}', '{a..e}']));
|
|
||||||
//=> ['(0[1-5])', '([a-e])']
|
|
||||||
|
|
||||||
console.log(braces(['{01..05}', '{a..e}'], { expand: true }));
|
|
||||||
//=> ['01', '02', '03', '04', '05', 'a', 'b', 'c', 'd', 'e']
|
|
||||||
```
|
|
||||||
|
|
||||||
### Brace Expansion vs. Compilation
|
|
||||||
|
|
||||||
By default, brace patterns are compiled into strings that are optimized for creating regular expressions and matching.
|
|
||||||
|
|
||||||
**Compiled**
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(braces('a/{x,y,z}/b'));
|
|
||||||
//=> ['a/(x|y|z)/b']
|
|
||||||
console.log(braces(['a/{01..20}/b', 'a/{1..5}/b']));
|
|
||||||
//=> [ 'a/(0[1-9]|1[0-9]|20)/b', 'a/([1-5])/b' ]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Expanded**
|
|
||||||
|
|
||||||
Enable brace expansion by setting the `expand` option to true, or by using [braces.expand()](#expand) (returns an array similar to what you'd expect from Bash, or `echo {1..5}`, or [minimatch](https://github.com/isaacs/minimatch)):
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(braces('a/{x,y,z}/b', { expand: true }));
|
|
||||||
//=> ['a/x/b', 'a/y/b', 'a/z/b']
|
|
||||||
|
|
||||||
console.log(braces.expand('{01..10}'));
|
|
||||||
//=> ['01','02','03','04','05','06','07','08','09','10']
|
|
||||||
```
|
|
||||||
|
|
||||||
### Lists
|
|
||||||
|
|
||||||
Expand lists (like Bash "sets"):
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(braces('a/{foo,bar,baz}/*.js'));
|
|
||||||
//=> ['a/(foo|bar|baz)/*.js']
|
|
||||||
|
|
||||||
console.log(braces.expand('a/{foo,bar,baz}/*.js'));
|
|
||||||
//=> ['a/foo/*.js', 'a/bar/*.js', 'a/baz/*.js']
|
|
||||||
```
|
|
||||||
|
|
||||||
### Sequences
|
|
||||||
|
|
||||||
Expand ranges of characters (like Bash "sequences"):
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(braces.expand('{1..3}')); // ['1', '2', '3']
|
|
||||||
console.log(braces.expand('a/{1..3}/b')); // ['a/1/b', 'a/2/b', 'a/3/b']
|
|
||||||
console.log(braces('{a..c}', { expand: true })); // ['a', 'b', 'c']
|
|
||||||
console.log(braces('foo/{a..c}', { expand: true })); // ['foo/a', 'foo/b', 'foo/c']
|
|
||||||
|
|
||||||
// supports zero-padded ranges
|
|
||||||
console.log(braces('a/{01..03}/b')); //=> ['a/(0[1-3])/b']
|
|
||||||
console.log(braces('a/{001..300}/b')); //=> ['a/(0{2}[1-9]|0[1-9][0-9]|[12][0-9]{2}|300)/b']
|
|
||||||
```
|
|
||||||
|
|
||||||
See [fill-range](https://github.com/jonschlinkert/fill-range) for all available range-expansion options.
|
|
||||||
|
|
||||||
### Steppped ranges
|
|
||||||
|
|
||||||
Steps, or increments, may be used with ranges:
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(braces.expand('{2..10..2}'));
|
|
||||||
//=> ['2', '4', '6', '8', '10']
|
|
||||||
|
|
||||||
console.log(braces('{2..10..2}'));
|
|
||||||
//=> ['(2|4|6|8|10)']
|
|
||||||
```
|
|
||||||
|
|
||||||
When the [.optimize](#optimize) method is used, or [options.optimize](#optionsoptimize) is set to true, sequences are passed to [to-regex-range](https://github.com/jonschlinkert/to-regex-range) for expansion.
|
|
||||||
|
|
||||||
### Nesting
|
|
||||||
|
|
||||||
Brace patterns may be nested. The results of each expanded string are not sorted, and left to right order is preserved.
|
|
||||||
|
|
||||||
**"Expanded" braces**
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(braces.expand('a{b,c,/{x,y}}/e'));
|
|
||||||
//=> ['ab/e', 'ac/e', 'a/x/e', 'a/y/e']
|
|
||||||
|
|
||||||
console.log(braces.expand('a/{x,{1..5},y}/c'));
|
|
||||||
//=> ['a/x/c', 'a/1/c', 'a/2/c', 'a/3/c', 'a/4/c', 'a/5/c', 'a/y/c']
|
|
||||||
```
|
|
||||||
|
|
||||||
**"Optimized" braces**
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(braces('a{b,c,/{x,y}}/e'));
|
|
||||||
//=> ['a(b|c|/(x|y))/e']
|
|
||||||
|
|
||||||
console.log(braces('a/{x,{1..5},y}/c'));
|
|
||||||
//=> ['a/(x|([1-5])|y)/c']
|
|
||||||
```
|
|
||||||
|
|
||||||
### Escaping
|
|
||||||
|
|
||||||
**Escaping braces**
|
|
||||||
|
|
||||||
A brace pattern will not be expanded or evaluted if _either the opening or closing brace is escaped_:
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(braces.expand('a\\{d,c,b}e'));
|
|
||||||
//=> ['a{d,c,b}e']
|
|
||||||
|
|
||||||
console.log(braces.expand('a{d,c,b\\}e'));
|
|
||||||
//=> ['a{d,c,b}e']
|
|
||||||
```
|
|
||||||
|
|
||||||
**Escaping commas**
|
|
||||||
|
|
||||||
Commas inside braces may also be escaped:
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(braces.expand('a{b\\,c}d'));
|
|
||||||
//=> ['a{b,c}d']
|
|
||||||
|
|
||||||
console.log(braces.expand('a{d\\,c,b}e'));
|
|
||||||
//=> ['ad,ce', 'abe']
|
|
||||||
```
|
|
||||||
|
|
||||||
**Single items**
|
|
||||||
|
|
||||||
Following bash conventions, a brace pattern is also not expanded when it contains a single character:
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(braces.expand('a{b}c'));
|
|
||||||
//=> ['a{b}c']
|
|
||||||
```
|
|
||||||
|
|
||||||
## Options
|
|
||||||
|
|
||||||
### options.maxLength
|
|
||||||
|
|
||||||
**Type**: `Number`
|
|
||||||
|
|
||||||
**Default**: `10,000`
|
|
||||||
|
|
||||||
**Description**: Limit the length of the input string. Useful when the input string is generated or your application allows users to pass a string, et cetera.
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(braces('a/{b,c}/d', { maxLength: 3 })); //=> throws an error
|
|
||||||
```
|
|
||||||
|
|
||||||
### options.expand
|
|
||||||
|
|
||||||
**Type**: `Boolean`
|
|
||||||
|
|
||||||
**Default**: `undefined`
|
|
||||||
|
|
||||||
**Description**: Generate an "expanded" brace pattern (alternatively you can use the `braces.expand()` method, which does the same thing).
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(braces('a/{b,c}/d', { expand: true }));
|
|
||||||
//=> [ 'a/b/d', 'a/c/d' ]
|
|
||||||
```
|
|
||||||
|
|
||||||
### options.nodupes
|
|
||||||
|
|
||||||
**Type**: `Boolean`
|
|
||||||
|
|
||||||
**Default**: `undefined`
|
|
||||||
|
|
||||||
**Description**: Remove duplicates from the returned array.
|
|
||||||
|
|
||||||
### options.rangeLimit
|
|
||||||
|
|
||||||
**Type**: `Number`
|
|
||||||
|
|
||||||
**Default**: `1000`
|
|
||||||
|
|
||||||
**Description**: To prevent malicious patterns from being passed by users, an error is thrown when `braces.expand()` is used or `options.expand` is true and the generated range will exceed the `rangeLimit`.
|
|
||||||
|
|
||||||
You can customize `options.rangeLimit` or set it to `Inifinity` to disable this altogether.
|
|
||||||
|
|
||||||
**Examples**
|
|
||||||
|
|
||||||
```js
|
|
||||||
// pattern exceeds the "rangeLimit", so it's optimized automatically
|
|
||||||
console.log(braces.expand('{1..1000}'));
|
|
||||||
//=> ['([1-9]|[1-9][0-9]{1,2}|1000)']
|
|
||||||
|
|
||||||
// pattern does not exceed "rangeLimit", so it's NOT optimized
|
|
||||||
console.log(braces.expand('{1..100}'));
|
|
||||||
//=> ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '100']
|
|
||||||
```
|
|
||||||
|
|
||||||
### options.transform
|
|
||||||
|
|
||||||
**Type**: `Function`
|
|
||||||
|
|
||||||
**Default**: `undefined`
|
|
||||||
|
|
||||||
**Description**: Customize range expansion.
|
|
||||||
|
|
||||||
**Example: Transforming non-numeric values**
|
|
||||||
|
|
||||||
```js
|
|
||||||
const alpha = braces.expand('x/{a..e}/y', {
|
|
||||||
transform(value, index) {
|
|
||||||
// When non-numeric values are passed, "value" is a character code.
|
|
||||||
return 'foo/' + String.fromCharCode(value) + '-' + index;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
console.log(alpha);
|
|
||||||
//=> [ 'x/foo/a-0/y', 'x/foo/b-1/y', 'x/foo/c-2/y', 'x/foo/d-3/y', 'x/foo/e-4/y' ]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Example: Transforming numeric values**
|
|
||||||
|
|
||||||
```js
|
|
||||||
const numeric = braces.expand('{1..5}', {
|
|
||||||
transform(value) {
|
|
||||||
// when numeric values are passed, "value" is a number
|
|
||||||
return 'foo/' + value * 2;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
console.log(numeric);
|
|
||||||
//=> [ 'foo/2', 'foo/4', 'foo/6', 'foo/8', 'foo/10' ]
|
|
||||||
```
|
|
||||||
|
|
||||||
### options.quantifiers
|
|
||||||
|
|
||||||
**Type**: `Boolean`
|
|
||||||
|
|
||||||
**Default**: `undefined`
|
|
||||||
|
|
||||||
**Description**: In regular expressions, quanitifiers can be used to specify how many times a token can be repeated. For example, `a{1,3}` will match the letter `a` one to three times.
|
|
||||||
|
|
||||||
Unfortunately, regex quantifiers happen to share the same syntax as [Bash lists](#lists)
|
|
||||||
|
|
||||||
The `quantifiers` option tells braces to detect when [regex quantifiers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#quantifiers) are defined in the given pattern, and not to try to expand them as lists.
|
|
||||||
|
|
||||||
**Examples**
|
|
||||||
|
|
||||||
```js
|
|
||||||
const braces = require('braces');
|
|
||||||
console.log(braces('a/b{1,3}/{x,y,z}'));
|
|
||||||
//=> [ 'a/b(1|3)/(x|y|z)' ]
|
|
||||||
console.log(braces('a/b{1,3}/{x,y,z}', { quantifiers: true }));
|
|
||||||
//=> [ 'a/b{1,3}/(x|y|z)' ]
|
|
||||||
console.log(braces('a/b{1,3}/{x,y,z}', { quantifiers: true, expand: true }));
|
|
||||||
//=> [ 'a/b{1,3}/x', 'a/b{1,3}/y', 'a/b{1,3}/z' ]
|
|
||||||
```
|
|
||||||
|
|
||||||
### options.keepEscaping
|
|
||||||
|
|
||||||
**Type**: `Boolean`
|
|
||||||
|
|
||||||
**Default**: `undefined`
|
|
||||||
|
|
||||||
**Description**: Do not strip backslashes that were used for escaping from the result.
|
|
||||||
|
|
||||||
## What is "brace expansion"?
|
|
||||||
|
|
||||||
Brace expansion is a type of parameter expansion that was made popular by unix shells for generating lists of strings, as well as regex-like matching when used alongside wildcards (globs).
|
|
||||||
|
|
||||||
In addition to "expansion", braces are also used for matching. In other words:
|
|
||||||
|
|
||||||
- [brace expansion](#brace-expansion) is for generating new lists
|
|
||||||
- [brace matching](#brace-matching) is for filtering existing lists
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary><strong>More about brace expansion</strong> (click to expand)</summary>
|
|
||||||
|
|
||||||
There are two main types of brace expansion:
|
|
||||||
|
|
||||||
1. **lists**: which are defined using comma-separated values inside curly braces: `{a,b,c}`
|
|
||||||
2. **sequences**: which are defined using a starting value and an ending value, separated by two dots: `a{1..3}b`. Optionally, a third argument may be passed to define a "step" or increment to use: `a{1..100..10}b`. These are also sometimes referred to as "ranges".
|
|
||||||
|
|
||||||
Here are some example brace patterns to illustrate how they work:
|
|
||||||
|
|
||||||
**Sets**
|
|
||||||
|
|
||||||
```
|
|
||||||
{a,b,c} => a b c
|
|
||||||
{a,b,c}{1,2} => a1 a2 b1 b2 c1 c2
|
|
||||||
```
|
|
||||||
|
|
||||||
**Sequences**
|
|
||||||
|
|
||||||
```
|
|
||||||
{1..9} => 1 2 3 4 5 6 7 8 9
|
|
||||||
{4..-4} => 4 3 2 1 0 -1 -2 -3 -4
|
|
||||||
{1..20..3} => 1 4 7 10 13 16 19
|
|
||||||
{a..j} => a b c d e f g h i j
|
|
||||||
{j..a} => j i h g f e d c b a
|
|
||||||
{a..z..3} => a d g j m p s v y
|
|
||||||
```
|
|
||||||
|
|
||||||
**Combination**
|
|
||||||
|
|
||||||
Sets and sequences can be mixed together or used along with any other strings.
|
|
||||||
|
|
||||||
```
|
|
||||||
{a,b,c}{1..3} => a1 a2 a3 b1 b2 b3 c1 c2 c3
|
|
||||||
foo/{a,b,c}/bar => foo/a/bar foo/b/bar foo/c/bar
|
|
||||||
```
|
|
||||||
|
|
||||||
The fact that braces can be "expanded" from relatively simple patterns makes them ideal for quickly generating test fixtures, file paths, and similar use cases.
|
|
||||||
|
|
||||||
## Brace matching
|
|
||||||
|
|
||||||
In addition to _expansion_, brace patterns are also useful for performing regular-expression-like matching.
|
|
||||||
|
|
||||||
For example, the pattern `foo/{1..3}/bar` would match any of following strings:
|
|
||||||
|
|
||||||
```
|
|
||||||
foo/1/bar
|
|
||||||
foo/2/bar
|
|
||||||
foo/3/bar
|
|
||||||
```
|
|
||||||
|
|
||||||
But not:
|
|
||||||
|
|
||||||
```
|
|
||||||
baz/1/qux
|
|
||||||
baz/2/qux
|
|
||||||
baz/3/qux
|
|
||||||
```
|
|
||||||
|
|
||||||
Braces can also be combined with [glob patterns](https://github.com/jonschlinkert/micromatch) to perform more advanced wildcard matching. For example, the pattern `*/{1..3}/*` would match any of following strings:
|
|
||||||
|
|
||||||
```
|
|
||||||
foo/1/bar
|
|
||||||
foo/2/bar
|
|
||||||
foo/3/bar
|
|
||||||
baz/1/qux
|
|
||||||
baz/2/qux
|
|
||||||
baz/3/qux
|
|
||||||
```
|
|
||||||
|
|
||||||
## Brace matching pitfalls
|
|
||||||
|
|
||||||
Although brace patterns offer a user-friendly way of matching ranges or sets of strings, there are also some major disadvantages and potential risks you should be aware of.
|
|
||||||
|
|
||||||
### tldr
|
|
||||||
|
|
||||||
**"brace bombs"**
|
|
||||||
|
|
||||||
- brace expansion can eat up a huge amount of processing resources
|
|
||||||
- as brace patterns increase _linearly in size_, the system resources required to expand the pattern increase exponentially
|
|
||||||
- users can accidentally (or intentially) exhaust your system's resources resulting in the equivalent of a DoS attack (bonus: no programming knowledge is required!)
|
|
||||||
|
|
||||||
For a more detailed explanation with examples, see the [geometric complexity](#geometric-complexity) section.
|
|
||||||
|
|
||||||
### The solution
|
|
||||||
|
|
||||||
Jump to the [performance section](#performance) to see how Braces solves this problem in comparison to other libraries.
|
|
||||||
|
|
||||||
### Geometric complexity
|
|
||||||
|
|
||||||
At minimum, brace patterns with sets limited to two elements have quadradic or `O(n^2)` complexity. But the complexity of the algorithm increases exponentially as the number of sets, _and elements per set_, increases, which is `O(n^c)`.
|
|
||||||
|
|
||||||
For example, the following sets demonstrate quadratic (`O(n^2)`) complexity:
|
|
||||||
|
|
||||||
```
|
|
||||||
{1,2}{3,4} => (2X2) => 13 14 23 24
|
|
||||||
{1,2}{3,4}{5,6} => (2X2X2) => 135 136 145 146 235 236 245 246
|
|
||||||
```
|
|
||||||
|
|
||||||
But add an element to a set, and we get a n-fold Cartesian product with `O(n^c)` complexity:
|
|
||||||
|
|
||||||
```
|
|
||||||
{1,2,3}{4,5,6}{7,8,9} => (3X3X3) => 147 148 149 157 158 159 167 168 169 247 248
|
|
||||||
249 257 258 259 267 268 269 347 348 349 357
|
|
||||||
358 359 367 368 369
|
|
||||||
```
|
|
||||||
|
|
||||||
Now, imagine how this complexity grows given that each element is a n-tuple:
|
|
||||||
|
|
||||||
```
|
|
||||||
{1..100}{1..100} => (100X100) => 10,000 elements (38.4 kB)
|
|
||||||
{1..100}{1..100}{1..100} => (100X100X100) => 1,000,000 elements (5.76 MB)
|
|
||||||
```
|
|
||||||
|
|
||||||
Although these examples are clearly contrived, they demonstrate how brace patterns can quickly grow out of control.
|
|
||||||
|
|
||||||
**More information**
|
|
||||||
|
|
||||||
Interested in learning more about brace expansion?
|
|
||||||
|
|
||||||
- [linuxjournal/bash-brace-expansion](http://www.linuxjournal.com/content/bash-brace-expansion)
|
|
||||||
- [rosettacode/Brace_expansion](https://rosettacode.org/wiki/Brace_expansion)
|
|
||||||
- [cartesian product](https://en.wikipedia.org/wiki/Cartesian_product)
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Performance
|
|
||||||
|
|
||||||
Braces is not only screaming fast, it's also more accurate the other brace expansion libraries.
|
|
||||||
|
|
||||||
### Better algorithms
|
|
||||||
|
|
||||||
Fortunately there is a solution to the ["brace bomb" problem](#brace-matching-pitfalls): _don't expand brace patterns into an array when they're used for matching_.
|
|
||||||
|
|
||||||
Instead, convert the pattern into an optimized regular expression. This is easier said than done, and braces is the only library that does this currently.
|
|
||||||
|
|
||||||
**The proof is in the numbers**
|
|
||||||
|
|
||||||
Minimatch gets exponentially slower as patterns increase in complexity, braces does not. The following results were generated using `braces()` and `minimatch.braceExpand()`, respectively.
|
|
||||||
|
|
||||||
| **Pattern** | **braces** | **[minimatch][]** |
|
|
||||||
| --------------------------- | ------------------- | ---------------------------- |
|
|
||||||
| `{1..9007199254740991}`[^1] | `298 B` (5ms 459μs) | N/A (freezes) |
|
|
||||||
| `{1..1000000000000000}` | `41 B` (1ms 15μs) | N/A (freezes) |
|
|
||||||
| `{1..100000000000000}` | `40 B` (890μs) | N/A (freezes) |
|
|
||||||
| `{1..10000000000000}` | `39 B` (2ms 49μs) | N/A (freezes) |
|
|
||||||
| `{1..1000000000000}` | `38 B` (608μs) | N/A (freezes) |
|
|
||||||
| `{1..100000000000}` | `37 B` (397μs) | N/A (freezes) |
|
|
||||||
| `{1..10000000000}` | `35 B` (983μs) | N/A (freezes) |
|
|
||||||
| `{1..1000000000}` | `34 B` (798μs) | N/A (freezes) |
|
|
||||||
| `{1..100000000}` | `33 B` (733μs) | N/A (freezes) |
|
|
||||||
| `{1..10000000}` | `32 B` (5ms 632μs) | `78.89 MB` (16s 388ms 569μs) |
|
|
||||||
| `{1..1000000}` | `31 B` (1ms 381μs) | `6.89 MB` (1s 496ms 887μs) |
|
|
||||||
| `{1..100000}` | `30 B` (950μs) | `588.89 kB` (146ms 921μs) |
|
|
||||||
| `{1..10000}` | `29 B` (1ms 114μs) | `48.89 kB` (14ms 187μs) |
|
|
||||||
| `{1..1000}` | `28 B` (760μs) | `3.89 kB` (1ms 453μs) |
|
|
||||||
| `{1..100}` | `22 B` (345μs) | `291 B` (196μs) |
|
|
||||||
| `{1..10}` | `10 B` (533μs) | `20 B` (37μs) |
|
|
||||||
| `{1..3}` | `7 B` (190μs) | `5 B` (27μs) |
|
|
||||||
|
|
||||||
### Faster algorithms
|
|
||||||
|
|
||||||
When you need expansion, braces is still much faster.
|
|
||||||
|
|
||||||
_(the following results were generated using `braces.expand()` and `minimatch.braceExpand()`, respectively)_
|
|
||||||
|
|
||||||
| **Pattern** | **braces** | **[minimatch][]** |
|
|
||||||
| --------------- | --------------------------- | ---------------------------- |
|
|
||||||
| `{1..10000000}` | `78.89 MB` (2s 698ms 642μs) | `78.89 MB` (18s 601ms 974μs) |
|
|
||||||
| `{1..1000000}` | `6.89 MB` (458ms 576μs) | `6.89 MB` (1s 491ms 621μs) |
|
|
||||||
| `{1..100000}` | `588.89 kB` (20ms 728μs) | `588.89 kB` (156ms 919μs) |
|
|
||||||
| `{1..10000}` | `48.89 kB` (2ms 202μs) | `48.89 kB` (13ms 641μs) |
|
|
||||||
| `{1..1000}` | `3.89 kB` (1ms 796μs) | `3.89 kB` (1ms 958μs) |
|
|
||||||
| `{1..100}` | `291 B` (424μs) | `291 B` (211μs) |
|
|
||||||
| `{1..10}` | `20 B` (487μs) | `20 B` (72μs) |
|
|
||||||
| `{1..3}` | `5 B` (166μs) | `5 B` (27μs) |
|
|
||||||
|
|
||||||
If you'd like to run these comparisons yourself, see [test/support/generate.js](test/support/generate.js).
|
|
||||||
|
|
||||||
## Benchmarks
|
|
||||||
|
|
||||||
### Running benchmarks
|
|
||||||
|
|
||||||
Install dev dependencies:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm i -d && npm benchmark
|
|
||||||
```
|
|
||||||
|
|
||||||
### Latest results
|
|
||||||
|
|
||||||
Braces is more accurate, without sacrificing performance.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
● expand - range (expanded)
|
|
||||||
braces x 53,167 ops/sec ±0.12% (102 runs sampled)
|
|
||||||
minimatch x 11,378 ops/sec ±0.10% (102 runs sampled)
|
|
||||||
● expand - range (optimized for regex)
|
|
||||||
braces x 373,442 ops/sec ±0.04% (100 runs sampled)
|
|
||||||
minimatch x 3,262 ops/sec ±0.18% (100 runs sampled)
|
|
||||||
● expand - nested ranges (expanded)
|
|
||||||
braces x 33,921 ops/sec ±0.09% (99 runs sampled)
|
|
||||||
minimatch x 10,855 ops/sec ±0.28% (100 runs sampled)
|
|
||||||
● expand - nested ranges (optimized for regex)
|
|
||||||
braces x 287,479 ops/sec ±0.52% (98 runs sampled)
|
|
||||||
minimatch x 3,219 ops/sec ±0.28% (101 runs sampled)
|
|
||||||
● expand - set (expanded)
|
|
||||||
braces x 238,243 ops/sec ±0.19% (97 runs sampled)
|
|
||||||
minimatch x 538,268 ops/sec ±0.31% (96 runs sampled)
|
|
||||||
● expand - set (optimized for regex)
|
|
||||||
braces x 321,844 ops/sec ±0.10% (97 runs sampled)
|
|
||||||
minimatch x 140,600 ops/sec ±0.15% (100 runs sampled)
|
|
||||||
● expand - nested sets (expanded)
|
|
||||||
braces x 165,371 ops/sec ±0.42% (96 runs sampled)
|
|
||||||
minimatch x 337,720 ops/sec ±0.28% (100 runs sampled)
|
|
||||||
● expand - nested sets (optimized for regex)
|
|
||||||
braces x 242,948 ops/sec ±0.12% (99 runs sampled)
|
|
||||||
minimatch x 87,403 ops/sec ±0.79% (96 runs sampled)
|
|
||||||
```
|
|
||||||
|
|
||||||
## About
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary><strong>Contributing</strong></summary>
|
|
||||||
|
|
||||||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary><strong>Running Tests</strong></summary>
|
|
||||||
|
|
||||||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install && npm test
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary><strong>Building docs</strong></summary>
|
|
||||||
|
|
||||||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
|
||||||
|
|
||||||
To generate the readme, run the following command:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install -g verbose/verb#dev verb-generate-readme && verb
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### Contributors
|
|
||||||
|
|
||||||
| **Commits** | **Contributor** |
|
|
||||||
| ----------- | ------------------------------------------------------------- |
|
|
||||||
| 197 | [jonschlinkert](https://github.com/jonschlinkert) |
|
|
||||||
| 4 | [doowb](https://github.com/doowb) |
|
|
||||||
| 1 | [es128](https://github.com/es128) |
|
|
||||||
| 1 | [eush77](https://github.com/eush77) |
|
|
||||||
| 1 | [hemanth](https://github.com/hemanth) |
|
|
||||||
| 1 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |
|
|
||||||
|
|
||||||
### Author
|
|
||||||
|
|
||||||
**Jon Schlinkert**
|
|
||||||
|
|
||||||
- [GitHub Profile](https://github.com/jonschlinkert)
|
|
||||||
- [Twitter Profile](https://twitter.com/jonschlinkert)
|
|
||||||
- [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
|
||||||
|
|
||||||
### License
|
|
||||||
|
|
||||||
Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
|
|
||||||
Released under the [MIT License](LICENSE).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 08, 2019._
|
|
|
@ -1,170 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const stringify = require('./lib/stringify');
|
|
||||||
const compile = require('./lib/compile');
|
|
||||||
const expand = require('./lib/expand');
|
|
||||||
const parse = require('./lib/parse');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Expand the given pattern or create a regex-compatible string.
|
|
||||||
*
|
|
||||||
* ```js
|
|
||||||
* const braces = require('braces');
|
|
||||||
* console.log(braces('{a,b,c}', { compile: true })); //=> ['(a|b|c)']
|
|
||||||
* console.log(braces('{a,b,c}')); //=> ['a', 'b', 'c']
|
|
||||||
* ```
|
|
||||||
* @param {String} `str`
|
|
||||||
* @param {Object} `options`
|
|
||||||
* @return {String}
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
const braces = (input, options = {}) => {
|
|
||||||
let output = [];
|
|
||||||
|
|
||||||
if (Array.isArray(input)) {
|
|
||||||
for (const pattern of input) {
|
|
||||||
const result = braces.create(pattern, options);
|
|
||||||
if (Array.isArray(result)) {
|
|
||||||
output.push(...result);
|
|
||||||
} else {
|
|
||||||
output.push(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
output = [].concat(braces.create(input, options));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options && options.expand === true && options.nodupes === true) {
|
|
||||||
output = [...new Set(output)];
|
|
||||||
}
|
|
||||||
return output;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the given `str` with the given `options`.
|
|
||||||
*
|
|
||||||
* ```js
|
|
||||||
* // braces.parse(pattern, [, options]);
|
|
||||||
* const ast = braces.parse('a/{b,c}/d');
|
|
||||||
* console.log(ast);
|
|
||||||
* ```
|
|
||||||
* @param {String} pattern Brace pattern to parse
|
|
||||||
* @param {Object} options
|
|
||||||
* @return {Object} Returns an AST
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
braces.parse = (input, options = {}) => parse(input, options);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a braces string from an AST, or an AST node.
|
|
||||||
*
|
|
||||||
* ```js
|
|
||||||
* const braces = require('braces');
|
|
||||||
* let ast = braces.parse('foo/{a,b}/bar');
|
|
||||||
* console.log(stringify(ast.nodes[2])); //=> '{a,b}'
|
|
||||||
* ```
|
|
||||||
* @param {String} `input` Brace pattern or AST.
|
|
||||||
* @param {Object} `options`
|
|
||||||
* @return {Array} Returns an array of expanded values.
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
braces.stringify = (input, options = {}) => {
|
|
||||||
if (typeof input === 'string') {
|
|
||||||
return stringify(braces.parse(input, options), options);
|
|
||||||
}
|
|
||||||
return stringify(input, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compiles a brace pattern into a regex-compatible, optimized string.
|
|
||||||
* This method is called by the main [braces](#braces) function by default.
|
|
||||||
*
|
|
||||||
* ```js
|
|
||||||
* const braces = require('braces');
|
|
||||||
* console.log(braces.compile('a/{b,c}/d'));
|
|
||||||
* //=> ['a/(b|c)/d']
|
|
||||||
* ```
|
|
||||||
* @param {String} `input` Brace pattern or AST.
|
|
||||||
* @param {Object} `options`
|
|
||||||
* @return {Array} Returns an array of expanded values.
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
braces.compile = (input, options = {}) => {
|
|
||||||
if (typeof input === 'string') {
|
|
||||||
input = braces.parse(input, options);
|
|
||||||
}
|
|
||||||
return compile(input, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Expands a brace pattern into an array. This method is called by the
|
|
||||||
* main [braces](#braces) function when `options.expand` is true. Before
|
|
||||||
* using this method it's recommended that you read the [performance notes](#performance))
|
|
||||||
* and advantages of using [.compile](#compile) instead.
|
|
||||||
*
|
|
||||||
* ```js
|
|
||||||
* const braces = require('braces');
|
|
||||||
* console.log(braces.expand('a/{b,c}/d'));
|
|
||||||
* //=> ['a/b/d', 'a/c/d'];
|
|
||||||
* ```
|
|
||||||
* @param {String} `pattern` Brace pattern
|
|
||||||
* @param {Object} `options`
|
|
||||||
* @return {Array} Returns an array of expanded values.
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
braces.expand = (input, options = {}) => {
|
|
||||||
if (typeof input === 'string') {
|
|
||||||
input = braces.parse(input, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
let result = expand(input, options);
|
|
||||||
|
|
||||||
// filter out empty strings if specified
|
|
||||||
if (options.noempty === true) {
|
|
||||||
result = result.filter(Boolean);
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter out duplicates if specified
|
|
||||||
if (options.nodupes === true) {
|
|
||||||
result = [...new Set(result)];
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Processes a brace pattern and returns either an expanded array
|
|
||||||
* (if `options.expand` is true), a highly optimized regex-compatible string.
|
|
||||||
* This method is called by the main [braces](#braces) function.
|
|
||||||
*
|
|
||||||
* ```js
|
|
||||||
* const braces = require('braces');
|
|
||||||
* console.log(braces.create('user-{200..300}/project-{a,b,c}-{1..10}'))
|
|
||||||
* //=> 'user-(20[0-9]|2[1-9][0-9]|300)/project-(a|b|c)-([1-9]|10)'
|
|
||||||
* ```
|
|
||||||
* @param {String} `pattern` Brace pattern
|
|
||||||
* @param {Object} `options`
|
|
||||||
* @return {Array} Returns an array of expanded values.
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
braces.create = (input, options = {}) => {
|
|
||||||
if (input === '' || input.length < 3) {
|
|
||||||
return [input];
|
|
||||||
}
|
|
||||||
|
|
||||||
return options.expand !== true
|
|
||||||
? braces.compile(input, options)
|
|
||||||
: braces.expand(input, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Expose "braces"
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = braces;
|
|
|
@ -1,60 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const fill = require('fill-range');
|
|
||||||
const utils = require('./utils');
|
|
||||||
|
|
||||||
const compile = (ast, options = {}) => {
|
|
||||||
const walk = (node, parent = {}) => {
|
|
||||||
const invalidBlock = utils.isInvalidBrace(parent);
|
|
||||||
const invalidNode = node.invalid === true && options.escapeInvalid === true;
|
|
||||||
const invalid = invalidBlock === true || invalidNode === true;
|
|
||||||
const prefix = options.escapeInvalid === true ? '\\' : '';
|
|
||||||
let output = '';
|
|
||||||
|
|
||||||
if (node.isOpen === true) {
|
|
||||||
return prefix + node.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.isClose === true) {
|
|
||||||
console.log('node.isClose', prefix, node.value);
|
|
||||||
return prefix + node.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.type === 'open') {
|
|
||||||
return invalid ? prefix + node.value : '(';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.type === 'close') {
|
|
||||||
return invalid ? prefix + node.value : ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.type === 'comma') {
|
|
||||||
return node.prev.type === 'comma' ? '' : invalid ? node.value : '|';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.value) {
|
|
||||||
return node.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.nodes && node.ranges > 0) {
|
|
||||||
const args = utils.reduce(node.nodes);
|
|
||||||
const range = fill(...args, { ...options, wrap: false, toRegex: true, strictZeros: true });
|
|
||||||
|
|
||||||
if (range.length !== 0) {
|
|
||||||
return args.length > 1 && range.length > 1 ? `(${range})` : range;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.nodes) {
|
|
||||||
for (const child of node.nodes) {
|
|
||||||
output += walk(child, node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
};
|
|
||||||
|
|
||||||
return walk(ast);
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = compile;
|
|
|
@ -1,57 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
MAX_LENGTH: 10000,
|
|
||||||
|
|
||||||
// Digits
|
|
||||||
CHAR_0: '0', /* 0 */
|
|
||||||
CHAR_9: '9', /* 9 */
|
|
||||||
|
|
||||||
// Alphabet chars.
|
|
||||||
CHAR_UPPERCASE_A: 'A', /* A */
|
|
||||||
CHAR_LOWERCASE_A: 'a', /* a */
|
|
||||||
CHAR_UPPERCASE_Z: 'Z', /* Z */
|
|
||||||
CHAR_LOWERCASE_Z: 'z', /* z */
|
|
||||||
|
|
||||||
CHAR_LEFT_PARENTHESES: '(', /* ( */
|
|
||||||
CHAR_RIGHT_PARENTHESES: ')', /* ) */
|
|
||||||
|
|
||||||
CHAR_ASTERISK: '*', /* * */
|
|
||||||
|
|
||||||
// Non-alphabetic chars.
|
|
||||||
CHAR_AMPERSAND: '&', /* & */
|
|
||||||
CHAR_AT: '@', /* @ */
|
|
||||||
CHAR_BACKSLASH: '\\', /* \ */
|
|
||||||
CHAR_BACKTICK: '`', /* ` */
|
|
||||||
CHAR_CARRIAGE_RETURN: '\r', /* \r */
|
|
||||||
CHAR_CIRCUMFLEX_ACCENT: '^', /* ^ */
|
|
||||||
CHAR_COLON: ':', /* : */
|
|
||||||
CHAR_COMMA: ',', /* , */
|
|
||||||
CHAR_DOLLAR: '$', /* . */
|
|
||||||
CHAR_DOT: '.', /* . */
|
|
||||||
CHAR_DOUBLE_QUOTE: '"', /* " */
|
|
||||||
CHAR_EQUAL: '=', /* = */
|
|
||||||
CHAR_EXCLAMATION_MARK: '!', /* ! */
|
|
||||||
CHAR_FORM_FEED: '\f', /* \f */
|
|
||||||
CHAR_FORWARD_SLASH: '/', /* / */
|
|
||||||
CHAR_HASH: '#', /* # */
|
|
||||||
CHAR_HYPHEN_MINUS: '-', /* - */
|
|
||||||
CHAR_LEFT_ANGLE_BRACKET: '<', /* < */
|
|
||||||
CHAR_LEFT_CURLY_BRACE: '{', /* { */
|
|
||||||
CHAR_LEFT_SQUARE_BRACKET: '[', /* [ */
|
|
||||||
CHAR_LINE_FEED: '\n', /* \n */
|
|
||||||
CHAR_NO_BREAK_SPACE: '\u00A0', /* \u00A0 */
|
|
||||||
CHAR_PERCENT: '%', /* % */
|
|
||||||
CHAR_PLUS: '+', /* + */
|
|
||||||
CHAR_QUESTION_MARK: '?', /* ? */
|
|
||||||
CHAR_RIGHT_ANGLE_BRACKET: '>', /* > */
|
|
||||||
CHAR_RIGHT_CURLY_BRACE: '}', /* } */
|
|
||||||
CHAR_RIGHT_SQUARE_BRACKET: ']', /* ] */
|
|
||||||
CHAR_SEMICOLON: ';', /* ; */
|
|
||||||
CHAR_SINGLE_QUOTE: '\'', /* ' */
|
|
||||||
CHAR_SPACE: ' ', /* */
|
|
||||||
CHAR_TAB: '\t', /* \t */
|
|
||||||
CHAR_UNDERSCORE: '_', /* _ */
|
|
||||||
CHAR_VERTICAL_LINE: '|', /* | */
|
|
||||||
CHAR_ZERO_WIDTH_NOBREAK_SPACE: '\uFEFF' /* \uFEFF */
|
|
||||||
};
|
|
|
@ -1,113 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const fill = require('fill-range');
|
|
||||||
const stringify = require('./stringify');
|
|
||||||
const utils = require('./utils');
|
|
||||||
|
|
||||||
const append = (queue = '', stash = '', enclose = false) => {
|
|
||||||
const result = [];
|
|
||||||
|
|
||||||
queue = [].concat(queue);
|
|
||||||
stash = [].concat(stash);
|
|
||||||
|
|
||||||
if (!stash.length) return queue;
|
|
||||||
if (!queue.length) {
|
|
||||||
return enclose ? utils.flatten(stash).map(ele => `{${ele}}`) : stash;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const item of queue) {
|
|
||||||
if (Array.isArray(item)) {
|
|
||||||
for (const value of item) {
|
|
||||||
result.push(append(value, stash, enclose));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (let ele of stash) {
|
|
||||||
if (enclose === true && typeof ele === 'string') ele = `{${ele}}`;
|
|
||||||
result.push(Array.isArray(ele) ? append(item, ele, enclose) : item + ele);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return utils.flatten(result);
|
|
||||||
};
|
|
||||||
|
|
||||||
const expand = (ast, options = {}) => {
|
|
||||||
const rangeLimit = options.rangeLimit === undefined ? 1000 : options.rangeLimit;
|
|
||||||
|
|
||||||
const walk = (node, parent = {}) => {
|
|
||||||
node.queue = [];
|
|
||||||
|
|
||||||
let p = parent;
|
|
||||||
let q = parent.queue;
|
|
||||||
|
|
||||||
while (p.type !== 'brace' && p.type !== 'root' && p.parent) {
|
|
||||||
p = p.parent;
|
|
||||||
q = p.queue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.invalid || node.dollar) {
|
|
||||||
q.push(append(q.pop(), stringify(node, options)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.type === 'brace' && node.invalid !== true && node.nodes.length === 2) {
|
|
||||||
q.push(append(q.pop(), ['{}']));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.nodes && node.ranges > 0) {
|
|
||||||
const args = utils.reduce(node.nodes);
|
|
||||||
|
|
||||||
if (utils.exceedsLimit(...args, options.step, rangeLimit)) {
|
|
||||||
throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
|
|
||||||
}
|
|
||||||
|
|
||||||
let range = fill(...args, options);
|
|
||||||
if (range.length === 0) {
|
|
||||||
range = stringify(node, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
q.push(append(q.pop(), range));
|
|
||||||
node.nodes = [];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const enclose = utils.encloseBrace(node);
|
|
||||||
let queue = node.queue;
|
|
||||||
let block = node;
|
|
||||||
|
|
||||||
while (block.type !== 'brace' && block.type !== 'root' && block.parent) {
|
|
||||||
block = block.parent;
|
|
||||||
queue = block.queue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < node.nodes.length; i++) {
|
|
||||||
const child = node.nodes[i];
|
|
||||||
|
|
||||||
if (child.type === 'comma' && node.type === 'brace') {
|
|
||||||
if (i === 1) queue.push('');
|
|
||||||
queue.push('');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (child.type === 'close') {
|
|
||||||
q.push(append(q.pop(), queue, enclose));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (child.value && child.type !== 'open') {
|
|
||||||
queue.push(append(queue.pop(), child.value));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (child.nodes) {
|
|
||||||
walk(child, node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return queue;
|
|
||||||
};
|
|
||||||
|
|
||||||
return utils.flatten(walk(ast));
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = expand;
|
|
|
@ -1,331 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const stringify = require('./stringify');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constants
|
|
||||||
*/
|
|
||||||
|
|
||||||
const {
|
|
||||||
MAX_LENGTH,
|
|
||||||
CHAR_BACKSLASH, /* \ */
|
|
||||||
CHAR_BACKTICK, /* ` */
|
|
||||||
CHAR_COMMA, /* , */
|
|
||||||
CHAR_DOT, /* . */
|
|
||||||
CHAR_LEFT_PARENTHESES, /* ( */
|
|
||||||
CHAR_RIGHT_PARENTHESES, /* ) */
|
|
||||||
CHAR_LEFT_CURLY_BRACE, /* { */
|
|
||||||
CHAR_RIGHT_CURLY_BRACE, /* } */
|
|
||||||
CHAR_LEFT_SQUARE_BRACKET, /* [ */
|
|
||||||
CHAR_RIGHT_SQUARE_BRACKET, /* ] */
|
|
||||||
CHAR_DOUBLE_QUOTE, /* " */
|
|
||||||
CHAR_SINGLE_QUOTE, /* ' */
|
|
||||||
CHAR_NO_BREAK_SPACE,
|
|
||||||
CHAR_ZERO_WIDTH_NOBREAK_SPACE
|
|
||||||
} = require('./constants');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* parse
|
|
||||||
*/
|
|
||||||
|
|
||||||
const parse = (input, options = {}) => {
|
|
||||||
if (typeof input !== 'string') {
|
|
||||||
throw new TypeError('Expected a string');
|
|
||||||
}
|
|
||||||
|
|
||||||
const opts = options || {};
|
|
||||||
const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
||||||
if (input.length > max) {
|
|
||||||
throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const ast = { type: 'root', input, nodes: [] };
|
|
||||||
const stack = [ast];
|
|
||||||
let block = ast;
|
|
||||||
let prev = ast;
|
|
||||||
let brackets = 0;
|
|
||||||
const length = input.length;
|
|
||||||
let index = 0;
|
|
||||||
let depth = 0;
|
|
||||||
let value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helpers
|
|
||||||
*/
|
|
||||||
|
|
||||||
const advance = () => input[index++];
|
|
||||||
const push = node => {
|
|
||||||
if (node.type === 'text' && prev.type === 'dot') {
|
|
||||||
prev.type = 'text';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prev && prev.type === 'text' && node.type === 'text') {
|
|
||||||
prev.value += node.value;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
block.nodes.push(node);
|
|
||||||
node.parent = block;
|
|
||||||
node.prev = prev;
|
|
||||||
prev = node;
|
|
||||||
return node;
|
|
||||||
};
|
|
||||||
|
|
||||||
push({ type: 'bos' });
|
|
||||||
|
|
||||||
while (index < length) {
|
|
||||||
block = stack[stack.length - 1];
|
|
||||||
value = advance();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invalid chars
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (value === CHAR_ZERO_WIDTH_NOBREAK_SPACE || value === CHAR_NO_BREAK_SPACE) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Escaped chars
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (value === CHAR_BACKSLASH) {
|
|
||||||
push({ type: 'text', value: (options.keepEscaping ? value : '') + advance() });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Right square bracket (literal): ']'
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (value === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
||||||
push({ type: 'text', value: '\\' + value });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Left square bracket: '['
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (value === CHAR_LEFT_SQUARE_BRACKET) {
|
|
||||||
brackets++;
|
|
||||||
|
|
||||||
let next;
|
|
||||||
|
|
||||||
while (index < length && (next = advance())) {
|
|
||||||
value += next;
|
|
||||||
|
|
||||||
if (next === CHAR_LEFT_SQUARE_BRACKET) {
|
|
||||||
brackets++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (next === CHAR_BACKSLASH) {
|
|
||||||
value += advance();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
||||||
brackets--;
|
|
||||||
|
|
||||||
if (brackets === 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
push({ type: 'text', value });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parentheses
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (value === CHAR_LEFT_PARENTHESES) {
|
|
||||||
block = push({ type: 'paren', nodes: [] });
|
|
||||||
stack.push(block);
|
|
||||||
push({ type: 'text', value });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value === CHAR_RIGHT_PARENTHESES) {
|
|
||||||
if (block.type !== 'paren') {
|
|
||||||
push({ type: 'text', value });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
block = stack.pop();
|
|
||||||
push({ type: 'text', value });
|
|
||||||
block = stack[stack.length - 1];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Quotes: '|"|`
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
|
|
||||||
const open = value;
|
|
||||||
let next;
|
|
||||||
|
|
||||||
if (options.keepQuotes !== true) {
|
|
||||||
value = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
while (index < length && (next = advance())) {
|
|
||||||
if (next === CHAR_BACKSLASH) {
|
|
||||||
value += next + advance();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (next === open) {
|
|
||||||
if (options.keepQuotes === true) value += next;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
value += next;
|
|
||||||
}
|
|
||||||
|
|
||||||
push({ type: 'text', value });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Left curly brace: '{'
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (value === CHAR_LEFT_CURLY_BRACE) {
|
|
||||||
depth++;
|
|
||||||
|
|
||||||
const dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
|
|
||||||
const brace = {
|
|
||||||
type: 'brace',
|
|
||||||
open: true,
|
|
||||||
close: false,
|
|
||||||
dollar,
|
|
||||||
depth,
|
|
||||||
commas: 0,
|
|
||||||
ranges: 0,
|
|
||||||
nodes: []
|
|
||||||
};
|
|
||||||
|
|
||||||
block = push(brace);
|
|
||||||
stack.push(block);
|
|
||||||
push({ type: 'open', value });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Right curly brace: '}'
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (value === CHAR_RIGHT_CURLY_BRACE) {
|
|
||||||
if (block.type !== 'brace') {
|
|
||||||
push({ type: 'text', value });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const type = 'close';
|
|
||||||
block = stack.pop();
|
|
||||||
block.close = true;
|
|
||||||
|
|
||||||
push({ type, value });
|
|
||||||
depth--;
|
|
||||||
|
|
||||||
block = stack[stack.length - 1];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Comma: ','
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (value === CHAR_COMMA && depth > 0) {
|
|
||||||
if (block.ranges > 0) {
|
|
||||||
block.ranges = 0;
|
|
||||||
const open = block.nodes.shift();
|
|
||||||
block.nodes = [open, { type: 'text', value: stringify(block) }];
|
|
||||||
}
|
|
||||||
|
|
||||||
push({ type: 'comma', value });
|
|
||||||
block.commas++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dot: '.'
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (value === CHAR_DOT && depth > 0 && block.commas === 0) {
|
|
||||||
const siblings = block.nodes;
|
|
||||||
|
|
||||||
if (depth === 0 || siblings.length === 0) {
|
|
||||||
push({ type: 'text', value });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prev.type === 'dot') {
|
|
||||||
block.range = [];
|
|
||||||
prev.value += value;
|
|
||||||
prev.type = 'range';
|
|
||||||
|
|
||||||
if (block.nodes.length !== 3 && block.nodes.length !== 5) {
|
|
||||||
block.invalid = true;
|
|
||||||
block.ranges = 0;
|
|
||||||
prev.type = 'text';
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
block.ranges++;
|
|
||||||
block.args = [];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prev.type === 'range') {
|
|
||||||
siblings.pop();
|
|
||||||
|
|
||||||
const before = siblings[siblings.length - 1];
|
|
||||||
before.value += prev.value + value;
|
|
||||||
prev = before;
|
|
||||||
block.ranges--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
push({ type: 'dot', value });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Text
|
|
||||||
*/
|
|
||||||
|
|
||||||
push({ type: 'text', value });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark imbalanced braces and brackets as invalid
|
|
||||||
do {
|
|
||||||
block = stack.pop();
|
|
||||||
|
|
||||||
if (block.type !== 'root') {
|
|
||||||
block.nodes.forEach(node => {
|
|
||||||
if (!node.nodes) {
|
|
||||||
if (node.type === 'open') node.isOpen = true;
|
|
||||||
if (node.type === 'close') node.isClose = true;
|
|
||||||
if (!node.nodes) node.type = 'text';
|
|
||||||
node.invalid = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// get the location of the block on parent.nodes (block's siblings)
|
|
||||||
const parent = stack[stack.length - 1];
|
|
||||||
const index = parent.nodes.indexOf(block);
|
|
||||||
// replace the (invalid) block with it's nodes
|
|
||||||
parent.nodes.splice(index, 1, ...block.nodes);
|
|
||||||
}
|
|
||||||
} while (stack.length > 0);
|
|
||||||
|
|
||||||
push({ type: 'eos' });
|
|
||||||
return ast;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = parse;
|
|
|
@ -1,32 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const utils = require('./utils');
|
|
||||||
|
|
||||||
module.exports = (ast, options = {}) => {
|
|
||||||
const stringify = (node, parent = {}) => {
|
|
||||||
const invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
|
|
||||||
const invalidNode = node.invalid === true && options.escapeInvalid === true;
|
|
||||||
let output = '';
|
|
||||||
|
|
||||||
if (node.value) {
|
|
||||||
if ((invalidBlock || invalidNode) && utils.isOpenOrClose(node)) {
|
|
||||||
return '\\' + node.value;
|
|
||||||
}
|
|
||||||
return node.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.value) {
|
|
||||||
return node.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.nodes) {
|
|
||||||
for (const child of node.nodes) {
|
|
||||||
output += stringify(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return output;
|
|
||||||
};
|
|
||||||
|
|
||||||
return stringify(ast);
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,122 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
exports.isInteger = num => {
|
|
||||||
if (typeof num === 'number') {
|
|
||||||
return Number.isInteger(num);
|
|
||||||
}
|
|
||||||
if (typeof num === 'string' && num.trim() !== '') {
|
|
||||||
return Number.isInteger(Number(num));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find a node of the given type
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.find = (node, type) => node.nodes.find(node => node.type === type);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find a node of the given type
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.exceedsLimit = (min, max, step = 1, limit) => {
|
|
||||||
if (limit === false) return false;
|
|
||||||
if (!exports.isInteger(min) || !exports.isInteger(max)) return false;
|
|
||||||
return ((Number(max) - Number(min)) / Number(step)) >= limit;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Escape the given node with '\\' before node.value
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.escapeNode = (block, n = 0, type) => {
|
|
||||||
const node = block.nodes[n];
|
|
||||||
if (!node) return;
|
|
||||||
|
|
||||||
if ((type && node.type === type) || node.type === 'open' || node.type === 'close') {
|
|
||||||
if (node.escaped !== true) {
|
|
||||||
node.value = '\\' + node.value;
|
|
||||||
node.escaped = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the given brace node should be enclosed in literal braces
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.encloseBrace = node => {
|
|
||||||
if (node.type !== 'brace') return false;
|
|
||||||
if ((node.commas >> 0 + node.ranges >> 0) === 0) {
|
|
||||||
node.invalid = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if a brace node is invalid.
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.isInvalidBrace = block => {
|
|
||||||
if (block.type !== 'brace') return false;
|
|
||||||
if (block.invalid === true || block.dollar) return true;
|
|
||||||
if ((block.commas >> 0 + block.ranges >> 0) === 0) {
|
|
||||||
block.invalid = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (block.open !== true || block.close !== true) {
|
|
||||||
block.invalid = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if a node is an open or close node
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.isOpenOrClose = node => {
|
|
||||||
if (node.type === 'open' || node.type === 'close') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return node.open === true || node.close === true;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reduce an array of text nodes.
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.reduce = nodes => nodes.reduce((acc, node) => {
|
|
||||||
if (node.type === 'text') acc.push(node.value);
|
|
||||||
if (node.type === 'range') node.type = 'text';
|
|
||||||
return acc;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flatten an array
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.flatten = (...args) => {
|
|
||||||
const result = [];
|
|
||||||
|
|
||||||
const flat = arr => {
|
|
||||||
for (let i = 0; i < arr.length; i++) {
|
|
||||||
const ele = arr[i];
|
|
||||||
|
|
||||||
if (Array.isArray(ele)) {
|
|
||||||
flat(ele);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ele !== undefined) {
|
|
||||||
result.push(ele);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
flat(args);
|
|
||||||
return result;
|
|
||||||
};
|
|
|
@ -1,77 +0,0 @@
|
||||||
{
|
|
||||||
"name": "braces",
|
|
||||||
"description": "Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support for the Bash 4.3 braces specification, without sacrificing speed.",
|
|
||||||
"version": "3.0.3",
|
|
||||||
"homepage": "https://github.com/micromatch/braces",
|
|
||||||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
|
|
||||||
"contributors": [
|
|
||||||
"Brian Woodward (https://twitter.com/doowb)",
|
|
||||||
"Elan Shanker (https://github.com/es128)",
|
|
||||||
"Eugene Sharygin (https://github.com/eush77)",
|
|
||||||
"hemanth.hm (http://h3manth.com)",
|
|
||||||
"Jon Schlinkert (http://twitter.com/jonschlinkert)"
|
|
||||||
],
|
|
||||||
"repository": "micromatch/braces",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/micromatch/braces/issues"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"files": [
|
|
||||||
"index.js",
|
|
||||||
"lib"
|
|
||||||
],
|
|
||||||
"main": "index.js",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "mocha",
|
|
||||||
"benchmark": "node benchmark"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"fill-range": "^7.1.1"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"ansi-colors": "^3.2.4",
|
|
||||||
"bash-path": "^2.0.1",
|
|
||||||
"gulp-format-md": "^2.0.0",
|
|
||||||
"mocha": "^6.1.1"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"alpha",
|
|
||||||
"alphabetical",
|
|
||||||
"bash",
|
|
||||||
"brace",
|
|
||||||
"braces",
|
|
||||||
"expand",
|
|
||||||
"expansion",
|
|
||||||
"filepath",
|
|
||||||
"fill",
|
|
||||||
"fs",
|
|
||||||
"glob",
|
|
||||||
"globbing",
|
|
||||||
"letter",
|
|
||||||
"match",
|
|
||||||
"matches",
|
|
||||||
"matching",
|
|
||||||
"number",
|
|
||||||
"numerical",
|
|
||||||
"path",
|
|
||||||
"range",
|
|
||||||
"ranges",
|
|
||||||
"sh"
|
|
||||||
],
|
|
||||||
"verb": {
|
|
||||||
"toc": false,
|
|
||||||
"layout": "default",
|
|
||||||
"tasks": [
|
|
||||||
"readme"
|
|
||||||
],
|
|
||||||
"lint": {
|
|
||||||
"reflinks": true
|
|
||||||
},
|
|
||||||
"plugins": [
|
|
||||||
"gulp-format-md"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2012-2019 Paul Miller (https://paulmillr.com), Elan Shanker
|
|
||||||
|
|
||||||
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,308 +0,0 @@
|
||||||
# Chokidar [![Weekly downloads](https://img.shields.io/npm/dw/chokidar.svg)](https://github.com/paulmillr/chokidar) [![Yearly downloads](https://img.shields.io/npm/dy/chokidar.svg)](https://github.com/paulmillr/chokidar)
|
|
||||||
|
|
||||||
> Minimal and efficient cross-platform file watching library
|
|
||||||
|
|
||||||
[![NPM](https://nodei.co/npm/chokidar.png)](https://www.npmjs.com/package/chokidar)
|
|
||||||
|
|
||||||
## Why?
|
|
||||||
|
|
||||||
Node.js `fs.watch`:
|
|
||||||
|
|
||||||
* Doesn't report filenames on MacOS.
|
|
||||||
* Doesn't report events at all when using editors like Sublime on MacOS.
|
|
||||||
* Often reports events twice.
|
|
||||||
* Emits most changes as `rename`.
|
|
||||||
* Does not provide an easy way to recursively watch file trees.
|
|
||||||
* Does not support recursive watching on Linux.
|
|
||||||
|
|
||||||
Node.js `fs.watchFile`:
|
|
||||||
|
|
||||||
* Almost as bad at event handling.
|
|
||||||
* Also does not provide any recursive watching.
|
|
||||||
* Results in high CPU utilization.
|
|
||||||
|
|
||||||
Chokidar resolves these problems.
|
|
||||||
|
|
||||||
Initially made for **[Brunch](https://brunch.io/)** (an ultra-swift web app build tool), it is now used in
|
|
||||||
[Microsoft's Visual Studio Code](https://github.com/microsoft/vscode),
|
|
||||||
[gulp](https://github.com/gulpjs/gulp/),
|
|
||||||
[karma](https://karma-runner.github.io/),
|
|
||||||
[PM2](https://github.com/Unitech/PM2),
|
|
||||||
[browserify](http://browserify.org/),
|
|
||||||
[webpack](https://webpack.github.io/),
|
|
||||||
[BrowserSync](https://www.browsersync.io/),
|
|
||||||
and [many others](https://www.npmjs.com/browse/depended/chokidar).
|
|
||||||
It has proven itself in production environments.
|
|
||||||
|
|
||||||
Version 3 is out! Check out our blog post about it: [Chokidar 3: How to save 32TB of traffic every week](https://paulmillr.com/posts/chokidar-3-save-32tb-of-traffic/)
|
|
||||||
|
|
||||||
## How?
|
|
||||||
|
|
||||||
Chokidar does still rely on the Node.js core `fs` module, but when using
|
|
||||||
`fs.watch` and `fs.watchFile` for watching, it normalizes the events it
|
|
||||||
receives, often checking for truth by getting file stats and/or dir contents.
|
|
||||||
|
|
||||||
On MacOS, chokidar by default uses a native extension exposing the Darwin
|
|
||||||
`FSEvents` API. This provides very efficient recursive watching compared with
|
|
||||||
implementations like `kqueue` available on most \*nix platforms. Chokidar still
|
|
||||||
does have to do some work to normalize the events received that way as well.
|
|
||||||
|
|
||||||
On most other platforms, the `fs.watch`-based implementation is the default, which
|
|
||||||
avoids polling and keeps CPU usage down. Be advised that chokidar will initiate
|
|
||||||
watchers recursively for everything within scope of the paths that have been
|
|
||||||
specified, so be judicious about not wasting system resources by watching much
|
|
||||||
more than needed.
|
|
||||||
|
|
||||||
## Getting started
|
|
||||||
|
|
||||||
Install with npm:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm install chokidar
|
|
||||||
```
|
|
||||||
|
|
||||||
Then `require` and use it in your code:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const chokidar = require('chokidar');
|
|
||||||
|
|
||||||
// One-liner for current directory
|
|
||||||
chokidar.watch('.').on('all', (event, path) => {
|
|
||||||
console.log(event, path);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// Example of a more typical implementation structure
|
|
||||||
|
|
||||||
// Initialize watcher.
|
|
||||||
const watcher = chokidar.watch('file, dir, glob, or array', {
|
|
||||||
ignored: /(^|[\/\\])\../, // ignore dotfiles
|
|
||||||
persistent: true
|
|
||||||
});
|
|
||||||
|
|
||||||
// Something to use when events are received.
|
|
||||||
const log = console.log.bind(console);
|
|
||||||
// Add event listeners.
|
|
||||||
watcher
|
|
||||||
.on('add', path => log(`File ${path} has been added`))
|
|
||||||
.on('change', path => log(`File ${path} has been changed`))
|
|
||||||
.on('unlink', path => log(`File ${path} has been removed`));
|
|
||||||
|
|
||||||
// More possible events.
|
|
||||||
watcher
|
|
||||||
.on('addDir', path => log(`Directory ${path} has been added`))
|
|
||||||
.on('unlinkDir', path => log(`Directory ${path} has been removed`))
|
|
||||||
.on('error', error => log(`Watcher error: ${error}`))
|
|
||||||
.on('ready', () => log('Initial scan complete. Ready for changes'))
|
|
||||||
.on('raw', (event, path, details) => { // internal
|
|
||||||
log('Raw event info:', event, path, details);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 'add', 'addDir' and 'change' events also receive stat() results as second
|
|
||||||
// argument when available: https://nodejs.org/api/fs.html#fs_class_fs_stats
|
|
||||||
watcher.on('change', (path, stats) => {
|
|
||||||
if (stats) console.log(`File ${path} changed size to ${stats.size}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Watch new files.
|
|
||||||
watcher.add('new-file');
|
|
||||||
watcher.add(['new-file-2', 'new-file-3', '**/other-file*']);
|
|
||||||
|
|
||||||
// Get list of actual paths being watched on the filesystem
|
|
||||||
var watchedPaths = watcher.getWatched();
|
|
||||||
|
|
||||||
// Un-watch some files.
|
|
||||||
await watcher.unwatch('new-file*');
|
|
||||||
|
|
||||||
// Stop watching.
|
|
||||||
// The method is async!
|
|
||||||
watcher.close().then(() => console.log('closed'));
|
|
||||||
|
|
||||||
// Full list of options. See below for descriptions.
|
|
||||||
// Do not use this example!
|
|
||||||
chokidar.watch('file', {
|
|
||||||
persistent: true,
|
|
||||||
|
|
||||||
ignored: '*.txt',
|
|
||||||
ignoreInitial: false,
|
|
||||||
followSymlinks: true,
|
|
||||||
cwd: '.',
|
|
||||||
disableGlobbing: false,
|
|
||||||
|
|
||||||
usePolling: false,
|
|
||||||
interval: 100,
|
|
||||||
binaryInterval: 300,
|
|
||||||
alwaysStat: false,
|
|
||||||
depth: 99,
|
|
||||||
awaitWriteFinish: {
|
|
||||||
stabilityThreshold: 2000,
|
|
||||||
pollInterval: 100
|
|
||||||
},
|
|
||||||
|
|
||||||
ignorePermissionErrors: false,
|
|
||||||
atomic: true // or a custom 'atomicity delay', in milliseconds (default 100)
|
|
||||||
});
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
`chokidar.watch(paths, [options])`
|
|
||||||
|
|
||||||
* `paths` (string or array of strings). Paths to files, dirs to be watched
|
|
||||||
recursively, or glob patterns.
|
|
||||||
- Note: globs must not contain windows separators (`\`),
|
|
||||||
because that's how they work by the standard —
|
|
||||||
you'll need to replace them with forward slashes (`/`).
|
|
||||||
- Note 2: for additional glob documentation, check out low-level
|
|
||||||
library: [picomatch](https://github.com/micromatch/picomatch).
|
|
||||||
* `options` (object) Options object as defined below:
|
|
||||||
|
|
||||||
#### Persistence
|
|
||||||
|
|
||||||
* `persistent` (default: `true`). Indicates whether the process
|
|
||||||
should continue to run as long as files are being watched. If set to
|
|
||||||
`false` when using `fsevents` to watch, no more events will be emitted
|
|
||||||
after `ready`, even if the process continues to run.
|
|
||||||
|
|
||||||
#### Path filtering
|
|
||||||
|
|
||||||
* `ignored` ([anymatch](https://github.com/es128/anymatch)-compatible definition)
|
|
||||||
Defines files/paths to be ignored. The whole relative or absolute path is
|
|
||||||
tested, not just filename. If a function with two arguments is provided, it
|
|
||||||
gets called twice per path - once with a single argument (the path), second
|
|
||||||
time with two arguments (the path and the
|
|
||||||
[`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats)
|
|
||||||
object of that path).
|
|
||||||
* `ignoreInitial` (default: `false`). If set to `false` then `add`/`addDir` events are also emitted for matching paths while
|
|
||||||
instantiating the watching as chokidar discovers these file paths (before the `ready` event).
|
|
||||||
* `followSymlinks` (default: `true`). When `false`, only the
|
|
||||||
symlinks themselves will be watched for changes instead of following
|
|
||||||
the link references and bubbling events through the link's path.
|
|
||||||
* `cwd` (no default). The base directory from which watch `paths` are to be
|
|
||||||
derived. Paths emitted with events will be relative to this.
|
|
||||||
* `disableGlobbing` (default: `false`). If set to `true` then the strings passed to `.watch()` and `.add()` are treated as
|
|
||||||
literal path names, even if they look like globs.
|
|
||||||
|
|
||||||
#### Performance
|
|
||||||
|
|
||||||
* `usePolling` (default: `false`).
|
|
||||||
Whether to use fs.watchFile (backed by polling), or fs.watch. If polling
|
|
||||||
leads to high CPU utilization, consider setting this to `false`. It is
|
|
||||||
typically necessary to **set this to `true` to successfully watch files over
|
|
||||||
a network**, and it may be necessary to successfully watch files in other
|
|
||||||
non-standard situations. Setting to `true` explicitly on MacOS overrides the
|
|
||||||
`useFsEvents` default. You may also set the CHOKIDAR_USEPOLLING env variable
|
|
||||||
to true (1) or false (0) in order to override this option.
|
|
||||||
* _Polling-specific settings_ (effective when `usePolling: true`)
|
|
||||||
* `interval` (default: `100`). Interval of file system polling, in milliseconds. You may also
|
|
||||||
set the CHOKIDAR_INTERVAL env variable to override this option.
|
|
||||||
* `binaryInterval` (default: `300`). Interval of file system
|
|
||||||
polling for binary files.
|
|
||||||
([see list of binary extensions](https://github.com/sindresorhus/binary-extensions/blob/master/binary-extensions.json))
|
|
||||||
* `useFsEvents` (default: `true` on MacOS). Whether to use the
|
|
||||||
`fsevents` watching interface if available. When set to `true` explicitly
|
|
||||||
and `fsevents` is available this supercedes the `usePolling` setting. When
|
|
||||||
set to `false` on MacOS, `usePolling: true` becomes the default.
|
|
||||||
* `alwaysStat` (default: `false`). If relying upon the
|
|
||||||
[`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats)
|
|
||||||
object that may get passed with `add`, `addDir`, and `change` events, set
|
|
||||||
this to `true` to ensure it is provided even in cases where it wasn't
|
|
||||||
already available from the underlying watch events.
|
|
||||||
* `depth` (default: `undefined`). If set, limits how many levels of
|
|
||||||
subdirectories will be traversed.
|
|
||||||
* `awaitWriteFinish` (default: `false`).
|
|
||||||
By default, the `add` event will fire when a file first appears on disk, before
|
|
||||||
the entire file has been written. Furthermore, in some cases some `change`
|
|
||||||
events will be emitted while the file is being written. In some cases,
|
|
||||||
especially when watching for large files there will be a need to wait for the
|
|
||||||
write operation to finish before responding to a file creation or modification.
|
|
||||||
Setting `awaitWriteFinish` to `true` (or a truthy value) will poll file size,
|
|
||||||
holding its `add` and `change` events until the size does not change for a
|
|
||||||
configurable amount of time. The appropriate duration setting is heavily
|
|
||||||
dependent on the OS and hardware. For accurate detection this parameter should
|
|
||||||
be relatively high, making file watching much less responsive.
|
|
||||||
Use with caution.
|
|
||||||
* *`options.awaitWriteFinish` can be set to an object in order to adjust
|
|
||||||
timing params:*
|
|
||||||
* `awaitWriteFinish.stabilityThreshold` (default: 2000). Amount of time in
|
|
||||||
milliseconds for a file size to remain constant before emitting its event.
|
|
||||||
* `awaitWriteFinish.pollInterval` (default: 100). File size polling interval, in milliseconds.
|
|
||||||
|
|
||||||
#### Errors
|
|
||||||
|
|
||||||
* `ignorePermissionErrors` (default: `false`). Indicates whether to watch files
|
|
||||||
that don't have read permissions if possible. If watching fails due to `EPERM`
|
|
||||||
or `EACCES` with this set to `true`, the errors will be suppressed silently.
|
|
||||||
* `atomic` (default: `true` if `useFsEvents` and `usePolling` are `false`).
|
|
||||||
Automatically filters out artifacts that occur when using editors that use
|
|
||||||
"atomic writes" instead of writing directly to the source file. If a file is
|
|
||||||
re-added within 100 ms of being deleted, Chokidar emits a `change` event
|
|
||||||
rather than `unlink` then `add`. If the default of 100 ms does not work well
|
|
||||||
for you, you can override it by setting `atomic` to a custom value, in
|
|
||||||
milliseconds.
|
|
||||||
|
|
||||||
### Methods & Events
|
|
||||||
|
|
||||||
`chokidar.watch()` produces an instance of `FSWatcher`. Methods of `FSWatcher`:
|
|
||||||
|
|
||||||
* `.add(path / paths)`: Add files, directories, or glob patterns for tracking.
|
|
||||||
Takes an array of strings or just one string.
|
|
||||||
* `.on(event, callback)`: Listen for an FS event.
|
|
||||||
Available events: `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `ready`,
|
|
||||||
`raw`, `error`.
|
|
||||||
Additionally `all` is available which gets emitted with the underlying event
|
|
||||||
name and path for every event other than `ready`, `raw`, and `error`. `raw` is internal, use it carefully.
|
|
||||||
* `.unwatch(path / paths)`: Stop watching files, directories, or glob patterns.
|
|
||||||
Takes an array of strings or just one string.
|
|
||||||
* `.close()`: **async** Removes all listeners from watched files. Asynchronous, returns Promise. Use with `await` to ensure bugs don't happen.
|
|
||||||
* `.getWatched()`: Returns an object representing all the paths on the file
|
|
||||||
system being watched by this `FSWatcher` instance. The object's keys are all the
|
|
||||||
directories (using absolute paths unless the `cwd` option was used), and the
|
|
||||||
values are arrays of the names of the items contained in each directory.
|
|
||||||
|
|
||||||
## CLI
|
|
||||||
|
|
||||||
If you need a CLI interface for your file watching, check out
|
|
||||||
[chokidar-cli](https://github.com/open-cli-tools/chokidar-cli), allowing you to
|
|
||||||
execute a command on each change, or get a stdio stream of change events.
|
|
||||||
|
|
||||||
## Install Troubleshooting
|
|
||||||
|
|
||||||
* `npm WARN optional dep failed, continuing fsevents@n.n.n`
|
|
||||||
* This message is normal part of how `npm` handles optional dependencies and is
|
|
||||||
not indicative of a problem. Even if accompanied by other related error messages,
|
|
||||||
Chokidar should function properly.
|
|
||||||
|
|
||||||
* `TypeError: fsevents is not a constructor`
|
|
||||||
* Update chokidar by doing `rm -rf node_modules package-lock.json yarn.lock && npm install`, or update your dependency that uses chokidar.
|
|
||||||
|
|
||||||
* Chokidar is producing `ENOSP` error on Linux, like this:
|
|
||||||
* `bash: cannot set terminal process group (-1): Inappropriate ioctl for device bash: no job control in this shell`
|
|
||||||
`Error: watch /home/ ENOSPC`
|
|
||||||
* This means Chokidar ran out of file handles and you'll need to increase their count by executing the following command in Terminal:
|
|
||||||
`echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p`
|
|
||||||
|
|
||||||
## Changelog
|
|
||||||
|
|
||||||
For more detailed changelog, see [`full_changelog.md`](.github/full_changelog.md).
|
|
||||||
- **v3.5 (Jan 6, 2021):** Support for ARM Macs with Apple Silicon. Fixes for deleted symlinks.
|
|
||||||
- **v3.4 (Apr 26, 2020):** Support for directory-based symlinks. Fixes for macos file replacement.
|
|
||||||
- **v3.3 (Nov 2, 2019):** `FSWatcher#close()` method became async. That fixes IO race conditions related to close method.
|
|
||||||
- **v3.2 (Oct 1, 2019):** Improve Linux RAM usage by 50%. Race condition fixes. Windows glob fixes. Improve stability by using tight range of dependency versions.
|
|
||||||
- **v3.1 (Sep 16, 2019):** dotfiles are no longer filtered out by default. Use `ignored` option if needed. Improve initial Linux scan time by 50%.
|
|
||||||
- **v3 (Apr 30, 2019):** massive CPU & RAM consumption improvements; reduces deps / package size by a factor of 17x and bumps Node.js requirement to v8.16 and higher.
|
|
||||||
- **v2 (Dec 29, 2017):** Globs are now posix-style-only; without windows support. Tons of bugfixes.
|
|
||||||
- **v1 (Apr 7, 2015):** Glob support, symlink support, tons of bugfixes. Node 0.8+ is supported
|
|
||||||
- **v0.1 (Apr 20, 2012):** Initial release, extracted from [Brunch](https://github.com/brunch/brunch/blob/9847a065aea300da99bd0753f90354cde9de1261/src/helpers.coffee#L66)
|
|
||||||
|
|
||||||
## Also
|
|
||||||
|
|
||||||
Why was chokidar named this way? What's the meaning behind it?
|
|
||||||
|
|
||||||
>Chowkidar is a transliteration of a Hindi word meaning 'watchman, gatekeeper', चौकीदार. This ultimately comes from Sanskrit _ चतुष्क_ (crossway, quadrangle, consisting-of-four). This word is also used in other languages like Urdu as (چوکیدار) which is widely used in Pakistan and India.
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
MIT (c) Paul Miller (<https://paulmillr.com>), see [LICENSE](LICENSE) file.
|
|
|
@ -1,973 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const { EventEmitter } = require('events');
|
|
||||||
const fs = require('fs');
|
|
||||||
const sysPath = require('path');
|
|
||||||
const { promisify } = require('util');
|
|
||||||
const readdirp = require('readdirp');
|
|
||||||
const anymatch = require('anymatch').default;
|
|
||||||
const globParent = require('glob-parent');
|
|
||||||
const isGlob = require('is-glob');
|
|
||||||
const braces = require('braces');
|
|
||||||
const normalizePath = require('normalize-path');
|
|
||||||
|
|
||||||
const NodeFsHandler = require('./lib/nodefs-handler');
|
|
||||||
const FsEventsHandler = require('./lib/fsevents-handler');
|
|
||||||
const {
|
|
||||||
EV_ALL,
|
|
||||||
EV_READY,
|
|
||||||
EV_ADD,
|
|
||||||
EV_CHANGE,
|
|
||||||
EV_UNLINK,
|
|
||||||
EV_ADD_DIR,
|
|
||||||
EV_UNLINK_DIR,
|
|
||||||
EV_RAW,
|
|
||||||
EV_ERROR,
|
|
||||||
|
|
||||||
STR_CLOSE,
|
|
||||||
STR_END,
|
|
||||||
|
|
||||||
BACK_SLASH_RE,
|
|
||||||
DOUBLE_SLASH_RE,
|
|
||||||
SLASH_OR_BACK_SLASH_RE,
|
|
||||||
DOT_RE,
|
|
||||||
REPLACER_RE,
|
|
||||||
|
|
||||||
SLASH,
|
|
||||||
SLASH_SLASH,
|
|
||||||
BRACE_START,
|
|
||||||
BANG,
|
|
||||||
ONE_DOT,
|
|
||||||
TWO_DOTS,
|
|
||||||
GLOBSTAR,
|
|
||||||
SLASH_GLOBSTAR,
|
|
||||||
ANYMATCH_OPTS,
|
|
||||||
STRING_TYPE,
|
|
||||||
FUNCTION_TYPE,
|
|
||||||
EMPTY_STR,
|
|
||||||
EMPTY_FN,
|
|
||||||
|
|
||||||
isWindows,
|
|
||||||
isMacos,
|
|
||||||
isIBMi
|
|
||||||
} = require('./lib/constants');
|
|
||||||
|
|
||||||
const stat = promisify(fs.stat);
|
|
||||||
const readdir = promisify(fs.readdir);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {String} Path
|
|
||||||
* @typedef {'all'|'add'|'addDir'|'change'|'unlink'|'unlinkDir'|'raw'|'error'|'ready'} EventName
|
|
||||||
* @typedef {'readdir'|'watch'|'add'|'remove'|'change'} ThrottleType
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @typedef {Object} WatchHelpers
|
|
||||||
* @property {Boolean} followSymlinks
|
|
||||||
* @property {'stat'|'lstat'} statMethod
|
|
||||||
* @property {Path} path
|
|
||||||
* @property {Path} watchPath
|
|
||||||
* @property {Function} entryPath
|
|
||||||
* @property {Boolean} hasGlob
|
|
||||||
* @property {Object} globFilter
|
|
||||||
* @property {Function} filterPath
|
|
||||||
* @property {Function} filterDir
|
|
||||||
*/
|
|
||||||
|
|
||||||
const arrify = (value = []) => Array.isArray(value) ? value : [value];
|
|
||||||
const flatten = (list, result = []) => {
|
|
||||||
list.forEach(item => {
|
|
||||||
if (Array.isArray(item)) {
|
|
||||||
flatten(item, result);
|
|
||||||
} else {
|
|
||||||
result.push(item);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
const unifyPaths = (paths_) => {
|
|
||||||
/**
|
|
||||||
* @type {Array<String>}
|
|
||||||
*/
|
|
||||||
const paths = flatten(arrify(paths_));
|
|
||||||
if (!paths.every(p => typeof p === STRING_TYPE)) {
|
|
||||||
throw new TypeError(`Non-string provided as watch path: ${paths}`);
|
|
||||||
}
|
|
||||||
return paths.map(normalizePathToUnix);
|
|
||||||
};
|
|
||||||
|
|
||||||
// If SLASH_SLASH occurs at the beginning of path, it is not replaced
|
|
||||||
// because "//StoragePC/DrivePool/Movies" is a valid network path
|
|
||||||
const toUnix = (string) => {
|
|
||||||
let str = string.replace(BACK_SLASH_RE, SLASH);
|
|
||||||
let prepend = false;
|
|
||||||
if (str.startsWith(SLASH_SLASH)) {
|
|
||||||
prepend = true;
|
|
||||||
}
|
|
||||||
while (str.match(DOUBLE_SLASH_RE)) {
|
|
||||||
str = str.replace(DOUBLE_SLASH_RE, SLASH);
|
|
||||||
}
|
|
||||||
if (prepend) {
|
|
||||||
str = SLASH + str;
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Our version of upath.normalize
|
|
||||||
// TODO: this is not equal to path-normalize module - investigate why
|
|
||||||
const normalizePathToUnix = (path) => toUnix(sysPath.normalize(toUnix(path)));
|
|
||||||
|
|
||||||
const normalizeIgnored = (cwd = EMPTY_STR) => (path) => {
|
|
||||||
if (typeof path !== STRING_TYPE) return path;
|
|
||||||
return normalizePathToUnix(sysPath.isAbsolute(path) ? path : sysPath.join(cwd, path));
|
|
||||||
};
|
|
||||||
|
|
||||||
const getAbsolutePath = (path, cwd) => {
|
|
||||||
if (sysPath.isAbsolute(path)) {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
if (path.startsWith(BANG)) {
|
|
||||||
return BANG + sysPath.join(cwd, path.slice(1));
|
|
||||||
}
|
|
||||||
return sysPath.join(cwd, path);
|
|
||||||
};
|
|
||||||
|
|
||||||
const undef = (opts, key) => opts[key] === undefined;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Directory entry.
|
|
||||||
* @property {Path} path
|
|
||||||
* @property {Set<Path>} items
|
|
||||||
*/
|
|
||||||
class DirEntry {
|
|
||||||
/**
|
|
||||||
* @param {Path} dir
|
|
||||||
* @param {Function} removeWatcher
|
|
||||||
*/
|
|
||||||
constructor(dir, removeWatcher) {
|
|
||||||
this.path = dir;
|
|
||||||
this._removeWatcher = removeWatcher;
|
|
||||||
/** @type {Set<Path>} */
|
|
||||||
this.items = new Set();
|
|
||||||
}
|
|
||||||
|
|
||||||
add(item) {
|
|
||||||
const {items} = this;
|
|
||||||
if (!items) return;
|
|
||||||
if (item !== ONE_DOT && item !== TWO_DOTS) items.add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
async remove(item) {
|
|
||||||
const {items} = this;
|
|
||||||
if (!items) return;
|
|
||||||
items.delete(item);
|
|
||||||
if (items.size > 0) return;
|
|
||||||
|
|
||||||
const dir = this.path;
|
|
||||||
try {
|
|
||||||
await readdir(dir);
|
|
||||||
} catch (err) {
|
|
||||||
if (this._removeWatcher) {
|
|
||||||
this._removeWatcher(sysPath.dirname(dir), sysPath.basename(dir));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
has(item) {
|
|
||||||
const {items} = this;
|
|
||||||
if (!items) return;
|
|
||||||
return items.has(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns {Array<String>}
|
|
||||||
*/
|
|
||||||
getChildren() {
|
|
||||||
const {items} = this;
|
|
||||||
if (!items) return;
|
|
||||||
return [...items.values()];
|
|
||||||
}
|
|
||||||
|
|
||||||
dispose() {
|
|
||||||
this.items.clear();
|
|
||||||
delete this.path;
|
|
||||||
delete this._removeWatcher;
|
|
||||||
delete this.items;
|
|
||||||
Object.freeze(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const STAT_METHOD_F = 'stat';
|
|
||||||
const STAT_METHOD_L = 'lstat';
|
|
||||||
class WatchHelper {
|
|
||||||
constructor(path, watchPath, follow, fsw) {
|
|
||||||
this.fsw = fsw;
|
|
||||||
this.path = path = path.replace(REPLACER_RE, EMPTY_STR);
|
|
||||||
this.watchPath = watchPath;
|
|
||||||
this.fullWatchPath = sysPath.resolve(watchPath);
|
|
||||||
this.hasGlob = watchPath !== path;
|
|
||||||
/** @type {object|boolean} */
|
|
||||||
if (path === EMPTY_STR) this.hasGlob = false;
|
|
||||||
this.globSymlink = this.hasGlob && follow ? undefined : false;
|
|
||||||
this.globFilter = this.hasGlob ? anymatch(path, undefined, ANYMATCH_OPTS) : false;
|
|
||||||
this.dirParts = this.getDirParts(path);
|
|
||||||
this.dirParts.forEach((parts) => {
|
|
||||||
if (parts.length > 1) parts.pop();
|
|
||||||
});
|
|
||||||
this.followSymlinks = follow;
|
|
||||||
this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkGlobSymlink(entry) {
|
|
||||||
// only need to resolve once
|
|
||||||
// first entry should always have entry.parentDir === EMPTY_STR
|
|
||||||
if (this.globSymlink === undefined) {
|
|
||||||
this.globSymlink = entry.fullParentDir === this.fullWatchPath ?
|
|
||||||
false : {realPath: entry.fullParentDir, linkPath: this.fullWatchPath};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.globSymlink) {
|
|
||||||
return entry.fullPath.replace(this.globSymlink.realPath, this.globSymlink.linkPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry.fullPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
entryPath(entry) {
|
|
||||||
return sysPath.join(this.watchPath,
|
|
||||||
sysPath.relative(this.watchPath, this.checkGlobSymlink(entry))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
filterPath(entry) {
|
|
||||||
const {stats} = entry;
|
|
||||||
if (stats && stats.isSymbolicLink()) return this.filterDir(entry);
|
|
||||||
const resolvedPath = this.entryPath(entry);
|
|
||||||
const matchesGlob = this.hasGlob && typeof this.globFilter === FUNCTION_TYPE ?
|
|
||||||
this.globFilter(resolvedPath) : true;
|
|
||||||
return matchesGlob &&
|
|
||||||
this.fsw._isntIgnored(resolvedPath, stats) &&
|
|
||||||
this.fsw._hasReadPermissions(stats);
|
|
||||||
}
|
|
||||||
|
|
||||||
getDirParts(path) {
|
|
||||||
if (!this.hasGlob) return [];
|
|
||||||
const parts = [];
|
|
||||||
const expandedPath = path.includes(BRACE_START) ? braces.expand(path) : [path];
|
|
||||||
expandedPath.forEach((path) => {
|
|
||||||
parts.push(sysPath.relative(this.watchPath, path).split(SLASH_OR_BACK_SLASH_RE));
|
|
||||||
});
|
|
||||||
return parts;
|
|
||||||
}
|
|
||||||
|
|
||||||
filterDir(entry) {
|
|
||||||
if (this.hasGlob) {
|
|
||||||
const entryParts = this.getDirParts(this.checkGlobSymlink(entry));
|
|
||||||
let globstar = false;
|
|
||||||
this.unmatchedGlob = !this.dirParts.some((parts) => {
|
|
||||||
return parts.every((part, i) => {
|
|
||||||
if (part === GLOBSTAR) globstar = true;
|
|
||||||
return globstar || !entryParts[0][i] || anymatch(part, entryParts[0][i], ANYMATCH_OPTS);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return !this.unmatchedGlob && this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Watches files & directories for changes. Emitted events:
|
|
||||||
* `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
|
|
||||||
*
|
|
||||||
* new FSWatcher()
|
|
||||||
* .add(directories)
|
|
||||||
* .on('add', path => log('File', path, 'was added'))
|
|
||||||
*/
|
|
||||||
class FSWatcher extends EventEmitter {
|
|
||||||
// Not indenting methods for history sake; for now.
|
|
||||||
constructor(_opts) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
const opts = {};
|
|
||||||
if (_opts) Object.assign(opts, _opts); // for frozen objects
|
|
||||||
|
|
||||||
/** @type {Map<String, DirEntry>} */
|
|
||||||
this._watched = new Map();
|
|
||||||
/** @type {Map<String, Array>} */
|
|
||||||
this._closers = new Map();
|
|
||||||
/** @type {Set<String>} */
|
|
||||||
this._ignoredPaths = new Set();
|
|
||||||
|
|
||||||
/** @type {Map<ThrottleType, Map>} */
|
|
||||||
this._throttled = new Map();
|
|
||||||
|
|
||||||
/** @type {Map<Path, String|Boolean>} */
|
|
||||||
this._symlinkPaths = new Map();
|
|
||||||
|
|
||||||
this._streams = new Set();
|
|
||||||
this.closed = false;
|
|
||||||
|
|
||||||
// Set up default options.
|
|
||||||
if (undef(opts, 'persistent')) opts.persistent = true;
|
|
||||||
if (undef(opts, 'ignoreInitial')) opts.ignoreInitial = false;
|
|
||||||
if (undef(opts, 'ignorePermissionErrors')) opts.ignorePermissionErrors = false;
|
|
||||||
if (undef(opts, 'interval')) opts.interval = 100;
|
|
||||||
if (undef(opts, 'binaryInterval')) opts.binaryInterval = 300;
|
|
||||||
if (undef(opts, 'disableGlobbing')) opts.disableGlobbing = false;
|
|
||||||
opts.enableBinaryInterval = opts.binaryInterval !== opts.interval;
|
|
||||||
|
|
||||||
// Enable fsevents on OS X when polling isn't explicitly enabled.
|
|
||||||
if (undef(opts, 'useFsEvents')) opts.useFsEvents = !opts.usePolling;
|
|
||||||
|
|
||||||
// If we can't use fsevents, ensure the options reflect it's disabled.
|
|
||||||
const canUseFsEvents = FsEventsHandler.canUse();
|
|
||||||
if (!canUseFsEvents) opts.useFsEvents = false;
|
|
||||||
|
|
||||||
// Use polling on Mac if not using fsevents.
|
|
||||||
// Other platforms use non-polling fs_watch.
|
|
||||||
if (undef(opts, 'usePolling') && !opts.useFsEvents) {
|
|
||||||
opts.usePolling = isMacos;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Always default to polling on IBM i because fs.watch() is not available on IBM i.
|
|
||||||
if(isIBMi) {
|
|
||||||
opts.usePolling = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Global override (useful for end-developers that need to force polling for all
|
|
||||||
// instances of chokidar, regardless of usage/dependency depth)
|
|
||||||
const envPoll = process.env.CHOKIDAR_USEPOLLING;
|
|
||||||
if (envPoll !== undefined) {
|
|
||||||
const envLower = envPoll.toLowerCase();
|
|
||||||
|
|
||||||
if (envLower === 'false' || envLower === '0') {
|
|
||||||
opts.usePolling = false;
|
|
||||||
} else if (envLower === 'true' || envLower === '1') {
|
|
||||||
opts.usePolling = true;
|
|
||||||
} else {
|
|
||||||
opts.usePolling = !!envLower;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
||||||
if (envInterval) {
|
|
||||||
opts.interval = Number.parseInt(envInterval, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Editor atomic write normalization enabled by default with fs.watch
|
|
||||||
if (undef(opts, 'atomic')) opts.atomic = !opts.usePolling && !opts.useFsEvents;
|
|
||||||
if (opts.atomic) this._pendingUnlinks = new Map();
|
|
||||||
|
|
||||||
if (undef(opts, 'followSymlinks')) opts.followSymlinks = true;
|
|
||||||
|
|
||||||
if (undef(opts, 'awaitWriteFinish')) opts.awaitWriteFinish = false;
|
|
||||||
if (opts.awaitWriteFinish === true) opts.awaitWriteFinish = {};
|
|
||||||
const awf = opts.awaitWriteFinish;
|
|
||||||
if (awf) {
|
|
||||||
if (!awf.stabilityThreshold) awf.stabilityThreshold = 2000;
|
|
||||||
if (!awf.pollInterval) awf.pollInterval = 100;
|
|
||||||
this._pendingWrites = new Map();
|
|
||||||
}
|
|
||||||
if (opts.ignored) opts.ignored = arrify(opts.ignored);
|
|
||||||
|
|
||||||
let readyCalls = 0;
|
|
||||||
this._emitReady = () => {
|
|
||||||
readyCalls++;
|
|
||||||
if (readyCalls >= this._readyCount) {
|
|
||||||
this._emitReady = EMPTY_FN;
|
|
||||||
this._readyEmitted = true;
|
|
||||||
// use process.nextTick to allow time for listener to be bound
|
|
||||||
process.nextTick(() => this.emit(EV_READY));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this._emitRaw = (...args) => this.emit(EV_RAW, ...args);
|
|
||||||
this._readyEmitted = false;
|
|
||||||
this.options = opts;
|
|
||||||
|
|
||||||
// Initialize with proper watcher.
|
|
||||||
if (opts.useFsEvents) {
|
|
||||||
this._fsEventsHandler = new FsEventsHandler(this);
|
|
||||||
} else {
|
|
||||||
this._nodeFsHandler = new NodeFsHandler(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// You’re frozen when your heart’s not open.
|
|
||||||
Object.freeze(opts);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Public methods
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds paths to be watched on an existing FSWatcher instance
|
|
||||||
* @param {Path|Array<Path>} paths_
|
|
||||||
* @param {String=} _origAdd private; for handling non-existent paths to be watched
|
|
||||||
* @param {Boolean=} _internal private; indicates a non-user add
|
|
||||||
* @returns {FSWatcher} for chaining
|
|
||||||
*/
|
|
||||||
add(paths_, _origAdd, _internal) {
|
|
||||||
const {cwd, disableGlobbing} = this.options;
|
|
||||||
this.closed = false;
|
|
||||||
let paths = unifyPaths(paths_);
|
|
||||||
if (cwd) {
|
|
||||||
paths = paths.map((path) => {
|
|
||||||
const absPath = getAbsolutePath(path, cwd);
|
|
||||||
|
|
||||||
// Check `path` instead of `absPath` because the cwd portion can't be a glob
|
|
||||||
if (disableGlobbing || !isGlob(path)) {
|
|
||||||
return absPath;
|
|
||||||
}
|
|
||||||
return normalizePath(absPath);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// set aside negated glob strings
|
|
||||||
paths = paths.filter((path) => {
|
|
||||||
if (path.startsWith(BANG)) {
|
|
||||||
this._ignoredPaths.add(path.slice(1));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if a path is being added that was previously ignored, stop ignoring it
|
|
||||||
this._ignoredPaths.delete(path);
|
|
||||||
this._ignoredPaths.delete(path + SLASH_GLOBSTAR);
|
|
||||||
|
|
||||||
// reset the cached userIgnored anymatch fn
|
|
||||||
// to make ignoredPaths changes effective
|
|
||||||
this._userIgnored = undefined;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.options.useFsEvents && this._fsEventsHandler) {
|
|
||||||
if (!this._readyCount) this._readyCount = paths.length;
|
|
||||||
if (this.options.persistent) this._readyCount += paths.length;
|
|
||||||
paths.forEach((path) => this._fsEventsHandler._addToFsEvents(path));
|
|
||||||
} else {
|
|
||||||
if (!this._readyCount) this._readyCount = 0;
|
|
||||||
this._readyCount += paths.length;
|
|
||||||
Promise.all(
|
|
||||||
paths.map(async path => {
|
|
||||||
const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, 0, 0, _origAdd);
|
|
||||||
if (res) this._emitReady();
|
|
||||||
return res;
|
|
||||||
})
|
|
||||||
).then(results => {
|
|
||||||
if (this.closed) return;
|
|
||||||
results.filter(item => item).forEach(item => {
|
|
||||||
this.add(sysPath.dirname(item), sysPath.basename(_origAdd || item));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Close watchers or start ignoring events from specified paths.
|
|
||||||
* @param {Path|Array<Path>} paths_ - string or array of strings, file/directory paths and/or globs
|
|
||||||
* @returns {FSWatcher} for chaining
|
|
||||||
*/
|
|
||||||
unwatch(paths_) {
|
|
||||||
if (this.closed) return this;
|
|
||||||
const paths = unifyPaths(paths_);
|
|
||||||
const {cwd} = this.options;
|
|
||||||
|
|
||||||
paths.forEach((path) => {
|
|
||||||
// convert to absolute path unless relative path already matches
|
|
||||||
if (!sysPath.isAbsolute(path) && !this._closers.has(path)) {
|
|
||||||
if (cwd) path = sysPath.join(cwd, path);
|
|
||||||
path = sysPath.resolve(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._closePath(path);
|
|
||||||
|
|
||||||
this._ignoredPaths.add(path);
|
|
||||||
if (this._watched.has(path)) {
|
|
||||||
this._ignoredPaths.add(path + SLASH_GLOBSTAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset the cached userIgnored anymatch fn
|
|
||||||
// to make ignoredPaths changes effective
|
|
||||||
this._userIgnored = undefined;
|
|
||||||
});
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Close watchers and remove all listeners from watched paths.
|
|
||||||
* @returns {Promise<void>}.
|
|
||||||
*/
|
|
||||||
close() {
|
|
||||||
if (this.closed) return this._closePromise;
|
|
||||||
this.closed = true;
|
|
||||||
|
|
||||||
// Memory management.
|
|
||||||
this.removeAllListeners();
|
|
||||||
const closers = [];
|
|
||||||
this._closers.forEach(closerList => closerList.forEach(closer => {
|
|
||||||
const promise = closer();
|
|
||||||
if (promise instanceof Promise) closers.push(promise);
|
|
||||||
}));
|
|
||||||
this._streams.forEach(stream => stream.destroy());
|
|
||||||
this._userIgnored = undefined;
|
|
||||||
this._readyCount = 0;
|
|
||||||
this._readyEmitted = false;
|
|
||||||
this._watched.forEach(dirent => dirent.dispose());
|
|
||||||
['closers', 'watched', 'streams', 'symlinkPaths', 'throttled'].forEach(key => {
|
|
||||||
this[`_${key}`].clear();
|
|
||||||
});
|
|
||||||
|
|
||||||
this._closePromise = closers.length ? Promise.all(closers).then(() => undefined) : Promise.resolve();
|
|
||||||
return this._closePromise;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Expose list of watched paths
|
|
||||||
* @returns {Object} for chaining
|
|
||||||
*/
|
|
||||||
getWatched() {
|
|
||||||
const watchList = {};
|
|
||||||
this._watched.forEach((entry, dir) => {
|
|
||||||
const key = this.options.cwd ? sysPath.relative(this.options.cwd, dir) : dir;
|
|
||||||
watchList[key || ONE_DOT] = entry.getChildren().sort();
|
|
||||||
});
|
|
||||||
return watchList;
|
|
||||||
}
|
|
||||||
|
|
||||||
emitWithAll(event, args) {
|
|
||||||
this.emit(...args);
|
|
||||||
if (event !== EV_ERROR) this.emit(EV_ALL, ...args);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Common helpers
|
|
||||||
// --------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Normalize and emit events.
|
|
||||||
* Calling _emit DOES NOT MEAN emit() would be called!
|
|
||||||
* @param {EventName} event Type of event
|
|
||||||
* @param {Path} path File or directory path
|
|
||||||
* @param {*=} val1 arguments to be passed with event
|
|
||||||
* @param {*=} val2
|
|
||||||
* @param {*=} val3
|
|
||||||
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
||||||
*/
|
|
||||||
async _emit(event, path, val1, val2, val3) {
|
|
||||||
if (this.closed) return;
|
|
||||||
|
|
||||||
const opts = this.options;
|
|
||||||
if (isWindows) path = sysPath.normalize(path);
|
|
||||||
if (opts.cwd) path = sysPath.relative(opts.cwd, path);
|
|
||||||
/** @type Array<any> */
|
|
||||||
const args = [event, path];
|
|
||||||
if (val3 !== undefined) args.push(val1, val2, val3);
|
|
||||||
else if (val2 !== undefined) args.push(val1, val2);
|
|
||||||
else if (val1 !== undefined) args.push(val1);
|
|
||||||
|
|
||||||
const awf = opts.awaitWriteFinish;
|
|
||||||
let pw;
|
|
||||||
if (awf && (pw = this._pendingWrites.get(path))) {
|
|
||||||
pw.lastChange = new Date();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opts.atomic) {
|
|
||||||
if (event === EV_UNLINK) {
|
|
||||||
this._pendingUnlinks.set(path, args);
|
|
||||||
setTimeout(() => {
|
|
||||||
this._pendingUnlinks.forEach((entry, path) => {
|
|
||||||
this.emit(...entry);
|
|
||||||
this.emit(EV_ALL, ...entry);
|
|
||||||
this._pendingUnlinks.delete(path);
|
|
||||||
});
|
|
||||||
}, typeof opts.atomic === 'number' ? opts.atomic : 100);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
if (event === EV_ADD && this._pendingUnlinks.has(path)) {
|
|
||||||
event = args[0] = EV_CHANGE;
|
|
||||||
this._pendingUnlinks.delete(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (awf && (event === EV_ADD || event === EV_CHANGE) && this._readyEmitted) {
|
|
||||||
const awfEmit = (err, stats) => {
|
|
||||||
if (err) {
|
|
||||||
event = args[0] = EV_ERROR;
|
|
||||||
args[1] = err;
|
|
||||||
this.emitWithAll(event, args);
|
|
||||||
} else if (stats) {
|
|
||||||
// if stats doesn't exist the file must have been deleted
|
|
||||||
if (args.length > 2) {
|
|
||||||
args[2] = stats;
|
|
||||||
} else {
|
|
||||||
args.push(stats);
|
|
||||||
}
|
|
||||||
this.emitWithAll(event, args);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event === EV_CHANGE) {
|
|
||||||
const isThrottled = !this._throttle(EV_CHANGE, path, 50);
|
|
||||||
if (isThrottled) return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opts.alwaysStat && val1 === undefined &&
|
|
||||||
(event === EV_ADD || event === EV_ADD_DIR || event === EV_CHANGE)
|
|
||||||
) {
|
|
||||||
const fullPath = opts.cwd ? sysPath.join(opts.cwd, path) : path;
|
|
||||||
let stats;
|
|
||||||
try {
|
|
||||||
stats = await stat(fullPath);
|
|
||||||
} catch (err) {}
|
|
||||||
// Suppress event when fs_stat fails, to avoid sending undefined 'stat'
|
|
||||||
if (!stats || this.closed) return;
|
|
||||||
args.push(stats);
|
|
||||||
}
|
|
||||||
this.emitWithAll(event, args);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common handler for errors
|
|
||||||
* @param {Error} error
|
|
||||||
* @returns {Error|Boolean} The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
||||||
*/
|
|
||||||
_handleError(error) {
|
|
||||||
const code = error && error.code;
|
|
||||||
if (error && code !== 'ENOENT' && code !== 'ENOTDIR' &&
|
|
||||||
(!this.options.ignorePermissionErrors || (code !== 'EPERM' && code !== 'EACCES'))
|
|
||||||
) {
|
|
||||||
this.emit(EV_ERROR, error);
|
|
||||||
}
|
|
||||||
return error || this.closed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper utility for throttling
|
|
||||||
* @param {ThrottleType} actionType type being throttled
|
|
||||||
* @param {Path} path being acted upon
|
|
||||||
* @param {Number} timeout duration of time to suppress duplicate actions
|
|
||||||
* @returns {Object|false} tracking object or false if action should be suppressed
|
|
||||||
*/
|
|
||||||
_throttle(actionType, path, timeout) {
|
|
||||||
if (!this._throttled.has(actionType)) {
|
|
||||||
this._throttled.set(actionType, new Map());
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @type {Map<Path, Object>} */
|
|
||||||
const action = this._throttled.get(actionType);
|
|
||||||
/** @type {Object} */
|
|
||||||
const actionPath = action.get(path);
|
|
||||||
|
|
||||||
if (actionPath) {
|
|
||||||
actionPath.count++;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let timeoutObject;
|
|
||||||
const clear = () => {
|
|
||||||
const item = action.get(path);
|
|
||||||
const count = item ? item.count : 0;
|
|
||||||
action.delete(path);
|
|
||||||
clearTimeout(timeoutObject);
|
|
||||||
if (item) clearTimeout(item.timeoutObject);
|
|
||||||
return count;
|
|
||||||
};
|
|
||||||
timeoutObject = setTimeout(clear, timeout);
|
|
||||||
const thr = {timeoutObject, clear, count: 0};
|
|
||||||
action.set(path, thr);
|
|
||||||
return thr;
|
|
||||||
}
|
|
||||||
|
|
||||||
_incrReadyCount() {
|
|
||||||
return this._readyCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Awaits write operation to finish.
|
|
||||||
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
|
||||||
* @param {Path} path being acted upon
|
|
||||||
* @param {Number} threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
|
||||||
* @param {EventName} event
|
|
||||||
* @param {Function} awfEmit Callback to be called when ready for event to be emitted.
|
|
||||||
*/
|
|
||||||
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
|
||||||
let timeoutHandler;
|
|
||||||
|
|
||||||
let fullPath = path;
|
|
||||||
if (this.options.cwd && !sysPath.isAbsolute(path)) {
|
|
||||||
fullPath = sysPath.join(this.options.cwd, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
const now = new Date();
|
|
||||||
|
|
||||||
const awaitWriteFinish = (prevStat) => {
|
|
||||||
fs.stat(fullPath, (err, curStat) => {
|
|
||||||
if (err || !this._pendingWrites.has(path)) {
|
|
||||||
if (err && err.code !== 'ENOENT') awfEmit(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const now = Number(new Date());
|
|
||||||
|
|
||||||
if (prevStat && curStat.size !== prevStat.size) {
|
|
||||||
this._pendingWrites.get(path).lastChange = now;
|
|
||||||
}
|
|
||||||
const pw = this._pendingWrites.get(path);
|
|
||||||
const df = now - pw.lastChange;
|
|
||||||
|
|
||||||
if (df >= threshold) {
|
|
||||||
this._pendingWrites.delete(path);
|
|
||||||
awfEmit(undefined, curStat);
|
|
||||||
} else {
|
|
||||||
timeoutHandler = setTimeout(
|
|
||||||
awaitWriteFinish,
|
|
||||||
this.options.awaitWriteFinish.pollInterval,
|
|
||||||
curStat
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!this._pendingWrites.has(path)) {
|
|
||||||
this._pendingWrites.set(path, {
|
|
||||||
lastChange: now,
|
|
||||||
cancelWait: () => {
|
|
||||||
this._pendingWrites.delete(path);
|
|
||||||
clearTimeout(timeoutHandler);
|
|
||||||
return event;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
timeoutHandler = setTimeout(
|
|
||||||
awaitWriteFinish,
|
|
||||||
this.options.awaitWriteFinish.pollInterval
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_getGlobIgnored() {
|
|
||||||
return [...this._ignoredPaths.values()];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether user has asked to ignore this path.
|
|
||||||
* @param {Path} path filepath or dir
|
|
||||||
* @param {fs.Stats=} stats result of fs.stat
|
|
||||||
* @returns {Boolean}
|
|
||||||
*/
|
|
||||||
_isIgnored(path, stats) {
|
|
||||||
if (this.options.atomic && DOT_RE.test(path)) return true;
|
|
||||||
if (!this._userIgnored) {
|
|
||||||
const {cwd} = this.options;
|
|
||||||
const ign = this.options.ignored;
|
|
||||||
|
|
||||||
const ignored = ign && ign.map(normalizeIgnored(cwd));
|
|
||||||
const paths = arrify(ignored)
|
|
||||||
.filter((path) => typeof path === STRING_TYPE && !isGlob(path))
|
|
||||||
.map((path) => path + SLASH_GLOBSTAR);
|
|
||||||
const list = this._getGlobIgnored().map(normalizeIgnored(cwd)).concat(ignored, paths);
|
|
||||||
this._userIgnored = anymatch(list, undefined, ANYMATCH_OPTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this._userIgnored([path, stats]);
|
|
||||||
}
|
|
||||||
|
|
||||||
_isntIgnored(path, stat) {
|
|
||||||
return !this._isIgnored(path, stat);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a set of common helpers and properties relating to symlink and glob handling.
|
|
||||||
* @param {Path} path file, directory, or glob pattern being watched
|
|
||||||
* @param {Number=} depth at any depth > 0, this isn't a glob
|
|
||||||
* @returns {WatchHelper} object containing helpers for this path
|
|
||||||
*/
|
|
||||||
_getWatchHelpers(path, depth) {
|
|
||||||
const watchPath = depth || this.options.disableGlobbing || !isGlob(path) ? path : globParent(path);
|
|
||||||
const follow = this.options.followSymlinks;
|
|
||||||
|
|
||||||
return new WatchHelper(path, watchPath, follow, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Directory helpers
|
|
||||||
// -----------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides directory tracking objects
|
|
||||||
* @param {String} directory path of the directory
|
|
||||||
* @returns {DirEntry} the directory's tracking object
|
|
||||||
*/
|
|
||||||
_getWatchedDir(directory) {
|
|
||||||
if (!this._boundRemove) this._boundRemove = this._remove.bind(this);
|
|
||||||
const dir = sysPath.resolve(directory);
|
|
||||||
if (!this._watched.has(dir)) this._watched.set(dir, new DirEntry(dir, this._boundRemove));
|
|
||||||
return this._watched.get(dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
// File helpers
|
|
||||||
// ------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check for read permissions.
|
|
||||||
* Based on this answer on SO: https://stackoverflow.com/a/11781404/1358405
|
|
||||||
* @param {fs.Stats} stats - object, result of fs_stat
|
|
||||||
* @returns {Boolean} indicates whether the file can be read
|
|
||||||
*/
|
|
||||||
_hasReadPermissions(stats) {
|
|
||||||
if (this.options.ignorePermissionErrors) return true;
|
|
||||||
|
|
||||||
// stats.mode may be bigint
|
|
||||||
const md = stats && Number.parseInt(stats.mode, 10);
|
|
||||||
const st = md & 0o777;
|
|
||||||
const it = Number.parseInt(st.toString(8)[0], 10);
|
|
||||||
return Boolean(4 & it);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles emitting unlink events for
|
|
||||||
* files and directories, and via recursion, for
|
|
||||||
* files and directories within directories that are unlinked
|
|
||||||
* @param {String} directory within which the following item is located
|
|
||||||
* @param {String} item base path of item/directory
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
_remove(directory, item, isDirectory) {
|
|
||||||
// if what is being deleted is a directory, get that directory's paths
|
|
||||||
// for recursive deleting and cleaning of watched object
|
|
||||||
// if it is not a directory, nestedDirectoryChildren will be empty array
|
|
||||||
const path = sysPath.join(directory, item);
|
|
||||||
const fullPath = sysPath.resolve(path);
|
|
||||||
isDirectory = isDirectory != null
|
|
||||||
? isDirectory
|
|
||||||
: this._watched.has(path) || this._watched.has(fullPath);
|
|
||||||
|
|
||||||
// prevent duplicate handling in case of arriving here nearly simultaneously
|
|
||||||
// via multiple paths (such as _handleFile and _handleDir)
|
|
||||||
if (!this._throttle('remove', path, 100)) return;
|
|
||||||
|
|
||||||
// if the only watched file is removed, watch for its return
|
|
||||||
if (!isDirectory && !this.options.useFsEvents && this._watched.size === 1) {
|
|
||||||
this.add(directory, item, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This will create a new entry in the watched object in either case
|
|
||||||
// so we got to do the directory check beforehand
|
|
||||||
const wp = this._getWatchedDir(path);
|
|
||||||
const nestedDirectoryChildren = wp.getChildren();
|
|
||||||
|
|
||||||
// Recursively remove children directories / files.
|
|
||||||
nestedDirectoryChildren.forEach(nested => this._remove(path, nested));
|
|
||||||
|
|
||||||
// Check if item was on the watched list and remove it
|
|
||||||
const parent = this._getWatchedDir(directory);
|
|
||||||
const wasTracked = parent.has(item);
|
|
||||||
parent.remove(item);
|
|
||||||
|
|
||||||
// Fixes issue #1042 -> Relative paths were detected and added as symlinks
|
|
||||||
// (https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L612),
|
|
||||||
// but never removed from the map in case the path was deleted.
|
|
||||||
// This leads to an incorrect state if the path was recreated:
|
|
||||||
// https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L553
|
|
||||||
if (this._symlinkPaths.has(fullPath)) {
|
|
||||||
this._symlinkPaths.delete(fullPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we wait for this file to be fully written, cancel the wait.
|
|
||||||
let relPath = path;
|
|
||||||
if (this.options.cwd) relPath = sysPath.relative(this.options.cwd, path);
|
|
||||||
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
||||||
const event = this._pendingWrites.get(relPath).cancelWait();
|
|
||||||
if (event === EV_ADD) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The Entry will either be a directory that just got removed
|
|
||||||
// or a bogus entry to a file, in either case we have to remove it
|
|
||||||
this._watched.delete(path);
|
|
||||||
this._watched.delete(fullPath);
|
|
||||||
const eventName = isDirectory ? EV_UNLINK_DIR : EV_UNLINK;
|
|
||||||
if (wasTracked && !this._isIgnored(path)) this._emit(eventName, path);
|
|
||||||
|
|
||||||
// Avoid conflicts if we later create another file with the same name
|
|
||||||
if (!this.options.useFsEvents) {
|
|
||||||
this._closePath(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Closes all watchers for a path
|
|
||||||
* @param {Path} path
|
|
||||||
*/
|
|
||||||
_closePath(path) {
|
|
||||||
this._closeFile(path)
|
|
||||||
const dir = sysPath.dirname(path);
|
|
||||||
this._getWatchedDir(dir).remove(sysPath.basename(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Closes only file-specific watchers
|
|
||||||
* @param {Path} path
|
|
||||||
*/
|
|
||||||
_closeFile(path) {
|
|
||||||
const closers = this._closers.get(path);
|
|
||||||
if (!closers) return;
|
|
||||||
closers.forEach(closer => closer());
|
|
||||||
this._closers.delete(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {Path} path
|
|
||||||
* @param {Function} closer
|
|
||||||
*/
|
|
||||||
_addPathCloser(path, closer) {
|
|
||||||
if (!closer) return;
|
|
||||||
let list = this._closers.get(path);
|
|
||||||
if (!list) {
|
|
||||||
list = [];
|
|
||||||
this._closers.set(path, list);
|
|
||||||
}
|
|
||||||
list.push(closer);
|
|
||||||
}
|
|
||||||
|
|
||||||
_readdirp(root, opts) {
|
|
||||||
if (this.closed) return;
|
|
||||||
const options = {type: EV_ALL, alwaysStat: true, lstat: true, ...opts};
|
|
||||||
let stream = readdirp(root, options);
|
|
||||||
this._streams.add(stream);
|
|
||||||
stream.once(STR_CLOSE, () => {
|
|
||||||
stream = undefined;
|
|
||||||
});
|
|
||||||
stream.once(STR_END, () => {
|
|
||||||
if (stream) {
|
|
||||||
this._streams.delete(stream);
|
|
||||||
stream = undefined;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Export FSWatcher class
|
|
||||||
exports.FSWatcher = FSWatcher;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates watcher with paths to be tracked.
|
|
||||||
* @param {String|Array<String>} paths file/directory paths and/or globs
|
|
||||||
* @param {Object=} options chokidar opts
|
|
||||||
* @returns an instance of FSWatcher for chaining.
|
|
||||||
*/
|
|
||||||
const watch = (paths, options) => {
|
|
||||||
const watcher = new FSWatcher(options);
|
|
||||||
watcher.add(paths);
|
|
||||||
return watcher;
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.watch = watch;
|
|
|
@ -1,66 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const {sep} = require('path');
|
|
||||||
const {platform} = process;
|
|
||||||
const os = require('os');
|
|
||||||
|
|
||||||
exports.EV_ALL = 'all';
|
|
||||||
exports.EV_READY = 'ready';
|
|
||||||
exports.EV_ADD = 'add';
|
|
||||||
exports.EV_CHANGE = 'change';
|
|
||||||
exports.EV_ADD_DIR = 'addDir';
|
|
||||||
exports.EV_UNLINK = 'unlink';
|
|
||||||
exports.EV_UNLINK_DIR = 'unlinkDir';
|
|
||||||
exports.EV_RAW = 'raw';
|
|
||||||
exports.EV_ERROR = 'error';
|
|
||||||
|
|
||||||
exports.STR_DATA = 'data';
|
|
||||||
exports.STR_END = 'end';
|
|
||||||
exports.STR_CLOSE = 'close';
|
|
||||||
|
|
||||||
exports.FSEVENT_CREATED = 'created';
|
|
||||||
exports.FSEVENT_MODIFIED = 'modified';
|
|
||||||
exports.FSEVENT_DELETED = 'deleted';
|
|
||||||
exports.FSEVENT_MOVED = 'moved';
|
|
||||||
exports.FSEVENT_CLONED = 'cloned';
|
|
||||||
exports.FSEVENT_UNKNOWN = 'unknown';
|
|
||||||
exports.FSEVENT_FLAG_MUST_SCAN_SUBDIRS = 1;
|
|
||||||
exports.FSEVENT_TYPE_FILE = 'file';
|
|
||||||
exports.FSEVENT_TYPE_DIRECTORY = 'directory';
|
|
||||||
exports.FSEVENT_TYPE_SYMLINK = 'symlink';
|
|
||||||
|
|
||||||
exports.KEY_LISTENERS = 'listeners';
|
|
||||||
exports.KEY_ERR = 'errHandlers';
|
|
||||||
exports.KEY_RAW = 'rawEmitters';
|
|
||||||
exports.HANDLER_KEYS = [exports.KEY_LISTENERS, exports.KEY_ERR, exports.KEY_RAW];
|
|
||||||
|
|
||||||
exports.DOT_SLASH = `.${sep}`;
|
|
||||||
|
|
||||||
exports.BACK_SLASH_RE = /\\/g;
|
|
||||||
exports.DOUBLE_SLASH_RE = /\/\//;
|
|
||||||
exports.SLASH_OR_BACK_SLASH_RE = /[/\\]/;
|
|
||||||
exports.DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
|
|
||||||
exports.REPLACER_RE = /^\.[/\\]/;
|
|
||||||
|
|
||||||
exports.SLASH = '/';
|
|
||||||
exports.SLASH_SLASH = '//';
|
|
||||||
exports.BRACE_START = '{';
|
|
||||||
exports.BANG = '!';
|
|
||||||
exports.ONE_DOT = '.';
|
|
||||||
exports.TWO_DOTS = '..';
|
|
||||||
exports.STAR = '*';
|
|
||||||
exports.GLOBSTAR = '**';
|
|
||||||
exports.ROOT_GLOBSTAR = '/**/*';
|
|
||||||
exports.SLASH_GLOBSTAR = '/**';
|
|
||||||
exports.DIR_SUFFIX = 'Dir';
|
|
||||||
exports.ANYMATCH_OPTS = {dot: true};
|
|
||||||
exports.STRING_TYPE = 'string';
|
|
||||||
exports.FUNCTION_TYPE = 'function';
|
|
||||||
exports.EMPTY_STR = '';
|
|
||||||
exports.EMPTY_FN = () => {};
|
|
||||||
exports.IDENTITY_FN = val => val;
|
|
||||||
|
|
||||||
exports.isWindows = platform === 'win32';
|
|
||||||
exports.isMacos = platform === 'darwin';
|
|
||||||
exports.isLinux = platform === 'linux';
|
|
||||||
exports.isIBMi = os.type() === 'OS400';
|
|
|
@ -1,526 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
const sysPath = require('path');
|
|
||||||
const { promisify } = require('util');
|
|
||||||
|
|
||||||
let fsevents;
|
|
||||||
try {
|
|
||||||
fsevents = require('fsevents');
|
|
||||||
} catch (error) {
|
|
||||||
if (process.env.CHOKIDAR_PRINT_FSEVENTS_REQUIRE_ERROR) console.error(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fsevents) {
|
|
||||||
// TODO: real check
|
|
||||||
const mtch = process.version.match(/v(\d+)\.(\d+)/);
|
|
||||||
if (mtch && mtch[1] && mtch[2]) {
|
|
||||||
const maj = Number.parseInt(mtch[1], 10);
|
|
||||||
const min = Number.parseInt(mtch[2], 10);
|
|
||||||
if (maj === 8 && min < 16) {
|
|
||||||
fsevents = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const {
|
|
||||||
EV_ADD,
|
|
||||||
EV_CHANGE,
|
|
||||||
EV_ADD_DIR,
|
|
||||||
EV_UNLINK,
|
|
||||||
EV_ERROR,
|
|
||||||
STR_DATA,
|
|
||||||
STR_END,
|
|
||||||
FSEVENT_CREATED,
|
|
||||||
FSEVENT_MODIFIED,
|
|
||||||
FSEVENT_DELETED,
|
|
||||||
FSEVENT_MOVED,
|
|
||||||
// FSEVENT_CLONED,
|
|
||||||
FSEVENT_UNKNOWN,
|
|
||||||
FSEVENT_FLAG_MUST_SCAN_SUBDIRS,
|
|
||||||
FSEVENT_TYPE_FILE,
|
|
||||||
FSEVENT_TYPE_DIRECTORY,
|
|
||||||
FSEVENT_TYPE_SYMLINK,
|
|
||||||
|
|
||||||
ROOT_GLOBSTAR,
|
|
||||||
DIR_SUFFIX,
|
|
||||||
DOT_SLASH,
|
|
||||||
FUNCTION_TYPE,
|
|
||||||
EMPTY_FN,
|
|
||||||
IDENTITY_FN
|
|
||||||
} = require('./constants');
|
|
||||||
|
|
||||||
const Depth = (value) => isNaN(value) ? {} : {depth: value};
|
|
||||||
|
|
||||||
const stat = promisify(fs.stat);
|
|
||||||
const lstat = promisify(fs.lstat);
|
|
||||||
const realpath = promisify(fs.realpath);
|
|
||||||
|
|
||||||
const statMethods = { stat, lstat };
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {String} Path
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {Object} FsEventsWatchContainer
|
|
||||||
* @property {Set<Function>} listeners
|
|
||||||
* @property {Function} rawEmitter
|
|
||||||
* @property {{stop: Function}} watcher
|
|
||||||
*/
|
|
||||||
|
|
||||||
// fsevents instance helper functions
|
|
||||||
/**
|
|
||||||
* Object to hold per-process fsevents instances (may be shared across chokidar FSWatcher instances)
|
|
||||||
* @type {Map<Path,FsEventsWatchContainer>}
|
|
||||||
*/
|
|
||||||
const FSEventsWatchers = new Map();
|
|
||||||
|
|
||||||
// Threshold of duplicate path prefixes at which to start
|
|
||||||
// consolidating going forward
|
|
||||||
const consolidateThreshhold = 10;
|
|
||||||
|
|
||||||
const wrongEventFlags = new Set([
|
|
||||||
69888, 70400, 71424, 72704, 73472, 131328, 131840, 262912
|
|
||||||
]);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates the fsevents interface
|
|
||||||
* @param {Path} path path to be watched
|
|
||||||
* @param {Function} callback called when fsevents is bound and ready
|
|
||||||
* @returns {{stop: Function}} new fsevents instance
|
|
||||||
*/
|
|
||||||
const createFSEventsInstance = (path, callback) => {
|
|
||||||
const stop = fsevents.watch(path, callback);
|
|
||||||
return {stop};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates the fsevents interface or binds listeners to an existing one covering
|
|
||||||
* the same file tree.
|
|
||||||
* @param {Path} path - to be watched
|
|
||||||
* @param {Path} realPath - real path for symlinks
|
|
||||||
* @param {Function} listener - called when fsevents emits events
|
|
||||||
* @param {Function} rawEmitter - passes data to listeners of the 'raw' event
|
|
||||||
* @returns {Function} closer
|
|
||||||
*/
|
|
||||||
function setFSEventsListener(path, realPath, listener, rawEmitter) {
|
|
||||||
let watchPath = sysPath.extname(realPath) ? sysPath.dirname(realPath) : realPath;
|
|
||||||
|
|
||||||
const parentPath = sysPath.dirname(watchPath);
|
|
||||||
let cont = FSEventsWatchers.get(watchPath);
|
|
||||||
|
|
||||||
// If we've accumulated a substantial number of paths that
|
|
||||||
// could have been consolidated by watching one directory
|
|
||||||
// above the current one, create a watcher on the parent
|
|
||||||
// path instead, so that we do consolidate going forward.
|
|
||||||
if (couldConsolidate(parentPath)) {
|
|
||||||
watchPath = parentPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
const resolvedPath = sysPath.resolve(path);
|
|
||||||
const hasSymlink = resolvedPath !== realPath;
|
|
||||||
|
|
||||||
const filteredListener = (fullPath, flags, info) => {
|
|
||||||
if (hasSymlink) fullPath = fullPath.replace(realPath, resolvedPath);
|
|
||||||
if (
|
|
||||||
fullPath === resolvedPath ||
|
|
||||||
!fullPath.indexOf(resolvedPath + sysPath.sep)
|
|
||||||
) listener(fullPath, flags, info);
|
|
||||||
};
|
|
||||||
|
|
||||||
// check if there is already a watcher on a parent path
|
|
||||||
// modifies `watchPath` to the parent path when it finds a match
|
|
||||||
let watchedParent = false;
|
|
||||||
for (const watchedPath of FSEventsWatchers.keys()) {
|
|
||||||
if (realPath.indexOf(sysPath.resolve(watchedPath) + sysPath.sep) === 0) {
|
|
||||||
watchPath = watchedPath;
|
|
||||||
cont = FSEventsWatchers.get(watchPath);
|
|
||||||
watchedParent = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cont || watchedParent) {
|
|
||||||
cont.listeners.add(filteredListener);
|
|
||||||
} else {
|
|
||||||
cont = {
|
|
||||||
listeners: new Set([filteredListener]),
|
|
||||||
rawEmitter,
|
|
||||||
watcher: createFSEventsInstance(watchPath, (fullPath, flags) => {
|
|
||||||
if (!cont.listeners.size) return;
|
|
||||||
if (flags & FSEVENT_FLAG_MUST_SCAN_SUBDIRS) return;
|
|
||||||
const info = fsevents.getInfo(fullPath, flags);
|
|
||||||
cont.listeners.forEach(list => {
|
|
||||||
list(fullPath, flags, info);
|
|
||||||
});
|
|
||||||
|
|
||||||
cont.rawEmitter(info.event, fullPath, info);
|
|
||||||
})
|
|
||||||
};
|
|
||||||
FSEventsWatchers.set(watchPath, cont);
|
|
||||||
}
|
|
||||||
|
|
||||||
// removes this instance's listeners and closes the underlying fsevents
|
|
||||||
// instance if there are no more listeners left
|
|
||||||
return () => {
|
|
||||||
const lst = cont.listeners;
|
|
||||||
|
|
||||||
lst.delete(filteredListener);
|
|
||||||
if (!lst.size) {
|
|
||||||
FSEventsWatchers.delete(watchPath);
|
|
||||||
if (cont.watcher) return cont.watcher.stop().then(() => {
|
|
||||||
cont.rawEmitter = cont.watcher = undefined;
|
|
||||||
Object.freeze(cont);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decide whether or not we should start a new higher-level
|
|
||||||
// parent watcher
|
|
||||||
const couldConsolidate = (path) => {
|
|
||||||
let count = 0;
|
|
||||||
for (const watchPath of FSEventsWatchers.keys()) {
|
|
||||||
if (watchPath.indexOf(path) === 0) {
|
|
||||||
count++;
|
|
||||||
if (count >= consolidateThreshhold) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
// returns boolean indicating whether fsevents can be used
|
|
||||||
const canUse = () => fsevents && FSEventsWatchers.size < 128;
|
|
||||||
|
|
||||||
// determines subdirectory traversal levels from root to path
|
|
||||||
const calcDepth = (path, root) => {
|
|
||||||
let i = 0;
|
|
||||||
while (!path.indexOf(root) && (path = sysPath.dirname(path)) !== root) i++;
|
|
||||||
return i;
|
|
||||||
};
|
|
||||||
|
|
||||||
// returns boolean indicating whether the fsevents' event info has the same type
|
|
||||||
// as the one returned by fs.stat
|
|
||||||
const sameTypes = (info, stats) => (
|
|
||||||
info.type === FSEVENT_TYPE_DIRECTORY && stats.isDirectory() ||
|
|
||||||
info.type === FSEVENT_TYPE_SYMLINK && stats.isSymbolicLink() ||
|
|
||||||
info.type === FSEVENT_TYPE_FILE && stats.isFile()
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @mixin
|
|
||||||
*/
|
|
||||||
class FsEventsHandler {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {import('../index').FSWatcher} fsw
|
|
||||||
*/
|
|
||||||
constructor(fsw) {
|
|
||||||
this.fsw = fsw;
|
|
||||||
}
|
|
||||||
checkIgnored(path, stats) {
|
|
||||||
const ipaths = this.fsw._ignoredPaths;
|
|
||||||
if (this.fsw._isIgnored(path, stats)) {
|
|
||||||
ipaths.add(path);
|
|
||||||
if (stats && stats.isDirectory()) {
|
|
||||||
ipaths.add(path + ROOT_GLOBSTAR);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ipaths.delete(path);
|
|
||||||
ipaths.delete(path + ROOT_GLOBSTAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts) {
|
|
||||||
const event = watchedDir.has(item) ? EV_CHANGE : EV_ADD;
|
|
||||||
this.handleEvent(event, path, fullPath, realPath, parent, watchedDir, item, info, opts);
|
|
||||||
}
|
|
||||||
|
|
||||||
async checkExists(path, fullPath, realPath, parent, watchedDir, item, info, opts) {
|
|
||||||
try {
|
|
||||||
const stats = await stat(path)
|
|
||||||
if (this.fsw.closed) return;
|
|
||||||
if (sameTypes(info, stats)) {
|
|
||||||
this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
|
|
||||||
} else {
|
|
||||||
this.handleEvent(EV_UNLINK, path, fullPath, realPath, parent, watchedDir, item, info, opts);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
if (error.code === 'EACCES') {
|
|
||||||
this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
|
|
||||||
} else {
|
|
||||||
this.handleEvent(EV_UNLINK, path, fullPath, realPath, parent, watchedDir, item, info, opts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleEvent(event, path, fullPath, realPath, parent, watchedDir, item, info, opts) {
|
|
||||||
if (this.fsw.closed || this.checkIgnored(path)) return;
|
|
||||||
|
|
||||||
if (event === EV_UNLINK) {
|
|
||||||
const isDirectory = info.type === FSEVENT_TYPE_DIRECTORY
|
|
||||||
// suppress unlink events on never before seen files
|
|
||||||
if (isDirectory || watchedDir.has(item)) {
|
|
||||||
this.fsw._remove(parent, item, isDirectory);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (event === EV_ADD) {
|
|
||||||
// track new directories
|
|
||||||
if (info.type === FSEVENT_TYPE_DIRECTORY) this.fsw._getWatchedDir(path);
|
|
||||||
|
|
||||||
if (info.type === FSEVENT_TYPE_SYMLINK && opts.followSymlinks) {
|
|
||||||
// push symlinks back to the top of the stack to get handled
|
|
||||||
const curDepth = opts.depth === undefined ?
|
|
||||||
undefined : calcDepth(fullPath, realPath) + 1;
|
|
||||||
return this._addToFsEvents(path, false, true, curDepth);
|
|
||||||
}
|
|
||||||
|
|
||||||
// track new paths
|
|
||||||
// (other than symlinks being followed, which will be tracked soon)
|
|
||||||
this.fsw._getWatchedDir(parent).add(item);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @type {'add'|'addDir'|'unlink'|'unlinkDir'}
|
|
||||||
*/
|
|
||||||
const eventName = info.type === FSEVENT_TYPE_DIRECTORY ? event + DIR_SUFFIX : event;
|
|
||||||
this.fsw._emit(eventName, path);
|
|
||||||
if (eventName === EV_ADD_DIR) this._addToFsEvents(path, false, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle symlinks encountered during directory scan
|
|
||||||
* @param {String} watchPath - file/dir path to be watched with fsevents
|
|
||||||
* @param {String} realPath - real path (in case of symlinks)
|
|
||||||
* @param {Function} transform - path transformer
|
|
||||||
* @param {Function} globFilter - path filter in case a glob pattern was provided
|
|
||||||
* @returns {Function} closer for the watcher instance
|
|
||||||
*/
|
|
||||||
_watchWithFsEvents(watchPath, realPath, transform, globFilter) {
|
|
||||||
if (this.fsw.closed || this.fsw._isIgnored(watchPath)) return;
|
|
||||||
const opts = this.fsw.options;
|
|
||||||
const watchCallback = async (fullPath, flags, info) => {
|
|
||||||
if (this.fsw.closed) return;
|
|
||||||
if (
|
|
||||||
opts.depth !== undefined &&
|
|
||||||
calcDepth(fullPath, realPath) > opts.depth
|
|
||||||
) return;
|
|
||||||
const path = transform(sysPath.join(
|
|
||||||
watchPath, sysPath.relative(watchPath, fullPath)
|
|
||||||
));
|
|
||||||
if (globFilter && !globFilter(path)) return;
|
|
||||||
// ensure directories are tracked
|
|
||||||
const parent = sysPath.dirname(path);
|
|
||||||
const item = sysPath.basename(path);
|
|
||||||
const watchedDir = this.fsw._getWatchedDir(
|
|
||||||
info.type === FSEVENT_TYPE_DIRECTORY ? path : parent
|
|
||||||
);
|
|
||||||
|
|
||||||
// correct for wrong events emitted
|
|
||||||
if (wrongEventFlags.has(flags) || info.event === FSEVENT_UNKNOWN) {
|
|
||||||
if (typeof opts.ignored === FUNCTION_TYPE) {
|
|
||||||
let stats;
|
|
||||||
try {
|
|
||||||
stats = await stat(path);
|
|
||||||
} catch (error) {}
|
|
||||||
if (this.fsw.closed) return;
|
|
||||||
if (this.checkIgnored(path, stats)) return;
|
|
||||||
if (sameTypes(info, stats)) {
|
|
||||||
this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
|
|
||||||
} else {
|
|
||||||
this.handleEvent(EV_UNLINK, path, fullPath, realPath, parent, watchedDir, item, info, opts);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.checkExists(path, fullPath, realPath, parent, watchedDir, item, info, opts);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
switch (info.event) {
|
|
||||||
case FSEVENT_CREATED:
|
|
||||||
case FSEVENT_MODIFIED:
|
|
||||||
return this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
|
|
||||||
case FSEVENT_DELETED:
|
|
||||||
case FSEVENT_MOVED:
|
|
||||||
return this.checkExists(path, fullPath, realPath, parent, watchedDir, item, info, opts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const closer = setFSEventsListener(
|
|
||||||
watchPath,
|
|
||||||
realPath,
|
|
||||||
watchCallback,
|
|
||||||
this.fsw._emitRaw
|
|
||||||
);
|
|
||||||
|
|
||||||
this.fsw._emitReady();
|
|
||||||
return closer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle symlinks encountered during directory scan
|
|
||||||
* @param {String} linkPath path to symlink
|
|
||||||
* @param {String} fullPath absolute path to the symlink
|
|
||||||
* @param {Function} transform pre-existing path transformer
|
|
||||||
* @param {Number} curDepth level of subdirectories traversed to where symlink is
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async _handleFsEventsSymlink(linkPath, fullPath, transform, curDepth) {
|
|
||||||
// don't follow the same symlink more than once
|
|
||||||
if (this.fsw.closed || this.fsw._symlinkPaths.has(fullPath)) return;
|
|
||||||
|
|
||||||
this.fsw._symlinkPaths.set(fullPath, true);
|
|
||||||
this.fsw._incrReadyCount();
|
|
||||||
|
|
||||||
try {
|
|
||||||
const linkTarget = await realpath(linkPath);
|
|
||||||
if (this.fsw.closed) return;
|
|
||||||
if (this.fsw._isIgnored(linkTarget)) {
|
|
||||||
return this.fsw._emitReady();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.fsw._incrReadyCount();
|
|
||||||
|
|
||||||
// add the linkTarget for watching with a wrapper for transform
|
|
||||||
// that causes emitted paths to incorporate the link's path
|
|
||||||
this._addToFsEvents(linkTarget || linkPath, (path) => {
|
|
||||||
let aliasedPath = linkPath;
|
|
||||||
if (linkTarget && linkTarget !== DOT_SLASH) {
|
|
||||||
aliasedPath = path.replace(linkTarget, linkPath);
|
|
||||||
} else if (path !== DOT_SLASH) {
|
|
||||||
aliasedPath = sysPath.join(linkPath, path);
|
|
||||||
}
|
|
||||||
return transform(aliasedPath);
|
|
||||||
}, false, curDepth);
|
|
||||||
} catch(error) {
|
|
||||||
if (this.fsw._handleError(error)) {
|
|
||||||
return this.fsw._emitReady();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {Path} newPath
|
|
||||||
* @param {fs.Stats} stats
|
|
||||||
*/
|
|
||||||
emitAdd(newPath, stats, processPath, opts, forceAdd) {
|
|
||||||
const pp = processPath(newPath);
|
|
||||||
const isDir = stats.isDirectory();
|
|
||||||
const dirObj = this.fsw._getWatchedDir(sysPath.dirname(pp));
|
|
||||||
const base = sysPath.basename(pp);
|
|
||||||
|
|
||||||
// ensure empty dirs get tracked
|
|
||||||
if (isDir) this.fsw._getWatchedDir(pp);
|
|
||||||
if (dirObj.has(base)) return;
|
|
||||||
dirObj.add(base);
|
|
||||||
|
|
||||||
if (!opts.ignoreInitial || forceAdd === true) {
|
|
||||||
this.fsw._emit(isDir ? EV_ADD_DIR : EV_ADD, pp, stats);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
initWatch(realPath, path, wh, processPath) {
|
|
||||||
if (this.fsw.closed) return;
|
|
||||||
const closer = this._watchWithFsEvents(
|
|
||||||
wh.watchPath,
|
|
||||||
sysPath.resolve(realPath || wh.watchPath),
|
|
||||||
processPath,
|
|
||||||
wh.globFilter
|
|
||||||
);
|
|
||||||
this.fsw._addPathCloser(path, closer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle added path with fsevents
|
|
||||||
* @param {String} path file/dir path or glob pattern
|
|
||||||
* @param {Function|Boolean=} transform converts working path to what the user expects
|
|
||||||
* @param {Boolean=} forceAdd ensure add is emitted
|
|
||||||
* @param {Number=} priorDepth Level of subdirectories already traversed.
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async _addToFsEvents(path, transform, forceAdd, priorDepth) {
|
|
||||||
if (this.fsw.closed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const opts = this.fsw.options;
|
|
||||||
const processPath = typeof transform === FUNCTION_TYPE ? transform : IDENTITY_FN;
|
|
||||||
|
|
||||||
const wh = this.fsw._getWatchHelpers(path);
|
|
||||||
|
|
||||||
// evaluate what is at the path we're being asked to watch
|
|
||||||
try {
|
|
||||||
const stats = await statMethods[wh.statMethod](wh.watchPath);
|
|
||||||
if (this.fsw.closed) return;
|
|
||||||
if (this.fsw._isIgnored(wh.watchPath, stats)) {
|
|
||||||
throw null;
|
|
||||||
}
|
|
||||||
if (stats.isDirectory()) {
|
|
||||||
// emit addDir unless this is a glob parent
|
|
||||||
if (!wh.globFilter) this.emitAdd(processPath(path), stats, processPath, opts, forceAdd);
|
|
||||||
|
|
||||||
// don't recurse further if it would exceed depth setting
|
|
||||||
if (priorDepth && priorDepth > opts.depth) return;
|
|
||||||
|
|
||||||
// scan the contents of the dir
|
|
||||||
this.fsw._readdirp(wh.watchPath, {
|
|
||||||
fileFilter: entry => wh.filterPath(entry),
|
|
||||||
directoryFilter: entry => wh.filterDir(entry),
|
|
||||||
...Depth(opts.depth - (priorDepth || 0))
|
|
||||||
}).on(STR_DATA, (entry) => {
|
|
||||||
// need to check filterPath on dirs b/c filterDir is less restrictive
|
|
||||||
if (this.fsw.closed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (entry.stats.isDirectory() && !wh.filterPath(entry)) return;
|
|
||||||
|
|
||||||
const joinedPath = sysPath.join(wh.watchPath, entry.path);
|
|
||||||
const {fullPath} = entry;
|
|
||||||
|
|
||||||
if (wh.followSymlinks && entry.stats.isSymbolicLink()) {
|
|
||||||
// preserve the current depth here since it can't be derived from
|
|
||||||
// real paths past the symlink
|
|
||||||
const curDepth = opts.depth === undefined ?
|
|
||||||
undefined : calcDepth(joinedPath, sysPath.resolve(wh.watchPath)) + 1;
|
|
||||||
|
|
||||||
this._handleFsEventsSymlink(joinedPath, fullPath, processPath, curDepth);
|
|
||||||
} else {
|
|
||||||
this.emitAdd(joinedPath, entry.stats, processPath, opts, forceAdd);
|
|
||||||
}
|
|
||||||
}).on(EV_ERROR, EMPTY_FN).on(STR_END, () => {
|
|
||||||
this.fsw._emitReady();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.emitAdd(wh.watchPath, stats, processPath, opts, forceAdd);
|
|
||||||
this.fsw._emitReady();
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
if (!error || this.fsw._handleError(error)) {
|
|
||||||
// TODO: Strange thing: "should not choke on an ignored watch path" will be failed without 2 ready calls -__-
|
|
||||||
this.fsw._emitReady();
|
|
||||||
this.fsw._emitReady();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opts.persistent && forceAdd !== true) {
|
|
||||||
if (typeof transform === FUNCTION_TYPE) {
|
|
||||||
// realpath has already been resolved
|
|
||||||
this.initWatch(undefined, path, wh, processPath);
|
|
||||||
} else {
|
|
||||||
let realPath;
|
|
||||||
try {
|
|
||||||
realPath = await realpath(wh.watchPath);
|
|
||||||
} catch (e) {}
|
|
||||||
this.initWatch(realPath, path, wh, processPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = FsEventsHandler;
|
|
||||||
module.exports.canUse = canUse;
|
|
|
@ -1,654 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
const sysPath = require('path');
|
|
||||||
const { promisify } = require('util');
|
|
||||||
const isBinaryPath = require('is-binary-path');
|
|
||||||
const {
|
|
||||||
isWindows,
|
|
||||||
isLinux,
|
|
||||||
EMPTY_FN,
|
|
||||||
EMPTY_STR,
|
|
||||||
KEY_LISTENERS,
|
|
||||||
KEY_ERR,
|
|
||||||
KEY_RAW,
|
|
||||||
HANDLER_KEYS,
|
|
||||||
EV_CHANGE,
|
|
||||||
EV_ADD,
|
|
||||||
EV_ADD_DIR,
|
|
||||||
EV_ERROR,
|
|
||||||
STR_DATA,
|
|
||||||
STR_END,
|
|
||||||
BRACE_START,
|
|
||||||
STAR
|
|
||||||
} = require('./constants');
|
|
||||||
|
|
||||||
const THROTTLE_MODE_WATCH = 'watch';
|
|
||||||
|
|
||||||
const open = promisify(fs.open);
|
|
||||||
const stat = promisify(fs.stat);
|
|
||||||
const lstat = promisify(fs.lstat);
|
|
||||||
const close = promisify(fs.close);
|
|
||||||
const fsrealpath = promisify(fs.realpath);
|
|
||||||
|
|
||||||
const statMethods = { lstat, stat };
|
|
||||||
|
|
||||||
// TODO: emit errors properly. Example: EMFILE on Macos.
|
|
||||||
const foreach = (val, fn) => {
|
|
||||||
if (val instanceof Set) {
|
|
||||||
val.forEach(fn);
|
|
||||||
} else {
|
|
||||||
fn(val);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const addAndConvert = (main, prop, item) => {
|
|
||||||
let container = main[prop];
|
|
||||||
if (!(container instanceof Set)) {
|
|
||||||
main[prop] = container = new Set([container]);
|
|
||||||
}
|
|
||||||
container.add(item);
|
|
||||||
};
|
|
||||||
|
|
||||||
const clearItem = cont => key => {
|
|
||||||
const set = cont[key];
|
|
||||||
if (set instanceof Set) {
|
|
||||||
set.clear();
|
|
||||||
} else {
|
|
||||||
delete cont[key];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const delFromSet = (main, prop, item) => {
|
|
||||||
const container = main[prop];
|
|
||||||
if (container instanceof Set) {
|
|
||||||
container.delete(item);
|
|
||||||
} else if (container === item) {
|
|
||||||
delete main[prop];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {String} Path
|
|
||||||
*/
|
|
||||||
|
|
||||||
// fs_watch helpers
|
|
||||||
|
|
||||||
// object to hold per-process fs_watch instances
|
|
||||||
// (may be shared across chokidar FSWatcher instances)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {Object} FsWatchContainer
|
|
||||||
* @property {Set} listeners
|
|
||||||
* @property {Set} errHandlers
|
|
||||||
* @property {Set} rawEmitters
|
|
||||||
* @property {fs.FSWatcher=} watcher
|
|
||||||
* @property {Boolean=} watcherUnusable
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {Map<String,FsWatchContainer>}
|
|
||||||
*/
|
|
||||||
const FsWatchInstances = new Map();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates the fs_watch interface
|
|
||||||
* @param {String} path to be watched
|
|
||||||
* @param {Object} options to be passed to fs_watch
|
|
||||||
* @param {Function} listener main event handler
|
|
||||||
* @param {Function} errHandler emits info about errors
|
|
||||||
* @param {Function} emitRaw emits raw event data
|
|
||||||
* @returns {fs.FSWatcher} new fsevents instance
|
|
||||||
*/
|
|
||||||
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
|
||||||
const handleEvent = (rawEvent, evPath) => {
|
|
||||||
listener(path);
|
|
||||||
emitRaw(rawEvent, evPath, {watchedPath: path});
|
|
||||||
|
|
||||||
// emit based on events occurring for files from a directory's watcher in
|
|
||||||
// case the file's watcher misses it (and rely on throttling to de-dupe)
|
|
||||||
if (evPath && path !== evPath) {
|
|
||||||
fsWatchBroadcast(
|
|
||||||
sysPath.resolve(path, evPath), KEY_LISTENERS, sysPath.join(path, evPath)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
return fs.watch(path, options, handleEvent);
|
|
||||||
} catch (error) {
|
|
||||||
errHandler(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper for passing fs_watch event data to a collection of listeners
|
|
||||||
* @param {Path} fullPath absolute path bound to fs_watch instance
|
|
||||||
* @param {String} type listener type
|
|
||||||
* @param {*=} val1 arguments to be passed to listeners
|
|
||||||
* @param {*=} val2
|
|
||||||
* @param {*=} val3
|
|
||||||
*/
|
|
||||||
const fsWatchBroadcast = (fullPath, type, val1, val2, val3) => {
|
|
||||||
const cont = FsWatchInstances.get(fullPath);
|
|
||||||
if (!cont) return;
|
|
||||||
foreach(cont[type], (listener) => {
|
|
||||||
listener(val1, val2, val3);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates the fs_watch interface or binds listeners
|
|
||||||
* to an existing one covering the same file system entry
|
|
||||||
* @param {String} path
|
|
||||||
* @param {String} fullPath absolute path
|
|
||||||
* @param {Object} options to be passed to fs_watch
|
|
||||||
* @param {Object} handlers container for event listener functions
|
|
||||||
*/
|
|
||||||
const setFsWatchListener = (path, fullPath, options, handlers) => {
|
|
||||||
const {listener, errHandler, rawEmitter} = handlers;
|
|
||||||
let cont = FsWatchInstances.get(fullPath);
|
|
||||||
|
|
||||||
/** @type {fs.FSWatcher=} */
|
|
||||||
let watcher;
|
|
||||||
if (!options.persistent) {
|
|
||||||
watcher = createFsWatchInstance(
|
|
||||||
path, options, listener, errHandler, rawEmitter
|
|
||||||
);
|
|
||||||
return watcher.close.bind(watcher);
|
|
||||||
}
|
|
||||||
if (cont) {
|
|
||||||
addAndConvert(cont, KEY_LISTENERS, listener);
|
|
||||||
addAndConvert(cont, KEY_ERR, errHandler);
|
|
||||||
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
||||||
} else {
|
|
||||||
watcher = createFsWatchInstance(
|
|
||||||
path,
|
|
||||||
options,
|
|
||||||
fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
|
|
||||||
errHandler, // no need to use broadcast here
|
|
||||||
fsWatchBroadcast.bind(null, fullPath, KEY_RAW)
|
|
||||||
);
|
|
||||||
if (!watcher) return;
|
|
||||||
watcher.on(EV_ERROR, async (error) => {
|
|
||||||
const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
|
||||||
cont.watcherUnusable = true; // documented since Node 10.4.1
|
|
||||||
// Workaround for https://github.com/joyent/node/issues/4337
|
|
||||||
if (isWindows && error.code === 'EPERM') {
|
|
||||||
try {
|
|
||||||
const fd = await open(path, 'r');
|
|
||||||
await close(fd);
|
|
||||||
broadcastErr(error);
|
|
||||||
} catch (err) {}
|
|
||||||
} else {
|
|
||||||
broadcastErr(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
cont = {
|
|
||||||
listeners: listener,
|
|
||||||
errHandlers: errHandler,
|
|
||||||
rawEmitters: rawEmitter,
|
|
||||||
watcher
|
|
||||||
};
|
|
||||||
FsWatchInstances.set(fullPath, cont);
|
|
||||||
}
|
|
||||||
// const index = cont.listeners.indexOf(listener);
|
|
||||||
|
|
||||||
// removes this instance's listeners and closes the underlying fs_watch
|
|
||||||
// instance if there are no more listeners left
|
|
||||||
return () => {
|
|
||||||
delFromSet(cont, KEY_LISTENERS, listener);
|
|
||||||
delFromSet(cont, KEY_ERR, errHandler);
|
|
||||||
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
||||||
if (isEmptySet(cont.listeners)) {
|
|
||||||
// Check to protect against issue gh-730.
|
|
||||||
// if (cont.watcherUnusable) {
|
|
||||||
cont.watcher.close();
|
|
||||||
// }
|
|
||||||
FsWatchInstances.delete(fullPath);
|
|
||||||
HANDLER_KEYS.forEach(clearItem(cont));
|
|
||||||
cont.watcher = undefined;
|
|
||||||
Object.freeze(cont);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// fs_watchFile helpers
|
|
||||||
|
|
||||||
// object to hold per-process fs_watchFile instances
|
|
||||||
// (may be shared across chokidar FSWatcher instances)
|
|
||||||
const FsWatchFileInstances = new Map();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates the fs_watchFile interface or binds listeners
|
|
||||||
* to an existing one covering the same file system entry
|
|
||||||
* @param {String} path to be watched
|
|
||||||
* @param {String} fullPath absolute path
|
|
||||||
* @param {Object} options options to be passed to fs_watchFile
|
|
||||||
* @param {Object} handlers container for event listener functions
|
|
||||||
* @returns {Function} closer
|
|
||||||
*/
|
|
||||||
const setFsWatchFileListener = (path, fullPath, options, handlers) => {
|
|
||||||
const {listener, rawEmitter} = handlers;
|
|
||||||
let cont = FsWatchFileInstances.get(fullPath);
|
|
||||||
|
|
||||||
/* eslint-disable no-unused-vars, prefer-destructuring */
|
|
||||||
let listeners = new Set();
|
|
||||||
let rawEmitters = new Set();
|
|
||||||
|
|
||||||
const copts = cont && cont.options;
|
|
||||||
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
|
||||||
// "Upgrade" the watcher to persistence or a quicker interval.
|
|
||||||
// This creates some unlikely edge case issues if the user mixes
|
|
||||||
// settings in a very weird way, but solving for those cases
|
|
||||||
// doesn't seem worthwhile for the added complexity.
|
|
||||||
listeners = cont.listeners;
|
|
||||||
rawEmitters = cont.rawEmitters;
|
|
||||||
fs.unwatchFile(fullPath);
|
|
||||||
cont = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* eslint-enable no-unused-vars, prefer-destructuring */
|
|
||||||
|
|
||||||
if (cont) {
|
|
||||||
addAndConvert(cont, KEY_LISTENERS, listener);
|
|
||||||
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
||||||
} else {
|
|
||||||
// TODO
|
|
||||||
// listeners.add(listener);
|
|
||||||
// rawEmitters.add(rawEmitter);
|
|
||||||
cont = {
|
|
||||||
listeners: listener,
|
|
||||||
rawEmitters: rawEmitter,
|
|
||||||
options,
|
|
||||||
watcher: fs.watchFile(fullPath, options, (curr, prev) => {
|
|
||||||
foreach(cont.rawEmitters, (rawEmitter) => {
|
|
||||||
rawEmitter(EV_CHANGE, fullPath, {curr, prev});
|
|
||||||
});
|
|
||||||
const currmtime = curr.mtimeMs;
|
|
||||||
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
|
||||||
foreach(cont.listeners, (listener) => listener(path, curr));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
};
|
|
||||||
FsWatchFileInstances.set(fullPath, cont);
|
|
||||||
}
|
|
||||||
// const index = cont.listeners.indexOf(listener);
|
|
||||||
|
|
||||||
// Removes this instance's listeners and closes the underlying fs_watchFile
|
|
||||||
// instance if there are no more listeners left.
|
|
||||||
return () => {
|
|
||||||
delFromSet(cont, KEY_LISTENERS, listener);
|
|
||||||
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
||||||
if (isEmptySet(cont.listeners)) {
|
|
||||||
FsWatchFileInstances.delete(fullPath);
|
|
||||||
fs.unwatchFile(fullPath);
|
|
||||||
cont.options = cont.watcher = undefined;
|
|
||||||
Object.freeze(cont);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @mixin
|
|
||||||
*/
|
|
||||||
class NodeFsHandler {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {import("../index").FSWatcher} fsW
|
|
||||||
*/
|
|
||||||
constructor(fsW) {
|
|
||||||
this.fsw = fsW;
|
|
||||||
this._boundHandleError = (error) => fsW._handleError(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Watch file for changes with fs_watchFile or fs_watch.
|
|
||||||
* @param {String} path to file or dir
|
|
||||||
* @param {Function} listener on fs change
|
|
||||||
* @returns {Function} closer for the watcher instance
|
|
||||||
*/
|
|
||||||
_watchWithNodeFs(path, listener) {
|
|
||||||
const opts = this.fsw.options;
|
|
||||||
const directory = sysPath.dirname(path);
|
|
||||||
const basename = sysPath.basename(path);
|
|
||||||
const parent = this.fsw._getWatchedDir(directory);
|
|
||||||
parent.add(basename);
|
|
||||||
const absolutePath = sysPath.resolve(path);
|
|
||||||
const options = {persistent: opts.persistent};
|
|
||||||
if (!listener) listener = EMPTY_FN;
|
|
||||||
|
|
||||||
let closer;
|
|
||||||
if (opts.usePolling) {
|
|
||||||
options.interval = opts.enableBinaryInterval && isBinaryPath(basename) ?
|
|
||||||
opts.binaryInterval : opts.interval;
|
|
||||||
closer = setFsWatchFileListener(path, absolutePath, options, {
|
|
||||||
listener,
|
|
||||||
rawEmitter: this.fsw._emitRaw
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
closer = setFsWatchListener(path, absolutePath, options, {
|
|
||||||
listener,
|
|
||||||
errHandler: this._boundHandleError,
|
|
||||||
rawEmitter: this.fsw._emitRaw
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return closer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Watch a file and emit add event if warranted.
|
|
||||||
* @param {Path} file Path
|
|
||||||
* @param {fs.Stats} stats result of fs_stat
|
|
||||||
* @param {Boolean} initialAdd was the file added at watch instantiation?
|
|
||||||
* @returns {Function} closer for the watcher instance
|
|
||||||
*/
|
|
||||||
_handleFile(file, stats, initialAdd) {
|
|
||||||
if (this.fsw.closed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const dirname = sysPath.dirname(file);
|
|
||||||
const basename = sysPath.basename(file);
|
|
||||||
const parent = this.fsw._getWatchedDir(dirname);
|
|
||||||
// stats is always present
|
|
||||||
let prevStats = stats;
|
|
||||||
|
|
||||||
// if the file is already being watched, do nothing
|
|
||||||
if (parent.has(basename)) return;
|
|
||||||
|
|
||||||
const listener = async (path, newStats) => {
|
|
||||||
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5)) return;
|
|
||||||
if (!newStats || newStats.mtimeMs === 0) {
|
|
||||||
try {
|
|
||||||
const newStats = await stat(file);
|
|
||||||
if (this.fsw.closed) return;
|
|
||||||
// Check that change event was not fired because of changed only accessTime.
|
|
||||||
const at = newStats.atimeMs;
|
|
||||||
const mt = newStats.mtimeMs;
|
|
||||||
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
|
||||||
this.fsw._emit(EV_CHANGE, file, newStats);
|
|
||||||
}
|
|
||||||
if (isLinux && prevStats.ino !== newStats.ino) {
|
|
||||||
this.fsw._closeFile(path)
|
|
||||||
prevStats = newStats;
|
|
||||||
this.fsw._addPathCloser(path, this._watchWithNodeFs(file, listener));
|
|
||||||
} else {
|
|
||||||
prevStats = newStats;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Fix issues where mtime is null but file is still present
|
|
||||||
this.fsw._remove(dirname, basename);
|
|
||||||
}
|
|
||||||
// add is about to be emitted if file not already tracked in parent
|
|
||||||
} else if (parent.has(basename)) {
|
|
||||||
// Check that change event was not fired because of changed only accessTime.
|
|
||||||
const at = newStats.atimeMs;
|
|
||||||
const mt = newStats.mtimeMs;
|
|
||||||
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
|
||||||
this.fsw._emit(EV_CHANGE, file, newStats);
|
|
||||||
}
|
|
||||||
prevStats = newStats;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// kick off the watcher
|
|
||||||
const closer = this._watchWithNodeFs(file, listener);
|
|
||||||
|
|
||||||
// emit an add event if we're supposed to
|
|
||||||
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
|
|
||||||
if (!this.fsw._throttle(EV_ADD, file, 0)) return;
|
|
||||||
this.fsw._emit(EV_ADD, file, stats);
|
|
||||||
}
|
|
||||||
|
|
||||||
return closer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle symlinks encountered while reading a dir.
|
|
||||||
* @param {Object} entry returned by readdirp
|
|
||||||
* @param {String} directory path of dir being read
|
|
||||||
* @param {String} path of this item
|
|
||||||
* @param {String} item basename of this item
|
|
||||||
* @returns {Promise<Boolean>} true if no more processing is needed for this entry.
|
|
||||||
*/
|
|
||||||
async _handleSymlink(entry, directory, path, item) {
|
|
||||||
if (this.fsw.closed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const full = entry.fullPath;
|
|
||||||
const dir = this.fsw._getWatchedDir(directory);
|
|
||||||
|
|
||||||
if (!this.fsw.options.followSymlinks) {
|
|
||||||
// watch symlink directly (don't follow) and detect changes
|
|
||||||
this.fsw._incrReadyCount();
|
|
||||||
|
|
||||||
let linkPath;
|
|
||||||
try {
|
|
||||||
linkPath = await fsrealpath(path);
|
|
||||||
} catch (e) {
|
|
||||||
this.fsw._emitReady();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.fsw.closed) return;
|
|
||||||
if (dir.has(item)) {
|
|
||||||
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
||||||
this.fsw._symlinkPaths.set(full, linkPath);
|
|
||||||
this.fsw._emit(EV_CHANGE, path, entry.stats);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dir.add(item);
|
|
||||||
this.fsw._symlinkPaths.set(full, linkPath);
|
|
||||||
this.fsw._emit(EV_ADD, path, entry.stats);
|
|
||||||
}
|
|
||||||
this.fsw._emitReady();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't follow the same symlink more than once
|
|
||||||
if (this.fsw._symlinkPaths.has(full)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.fsw._symlinkPaths.set(full, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
|
||||||
// Normalize the directory name on Windows
|
|
||||||
directory = sysPath.join(directory, EMPTY_STR);
|
|
||||||
|
|
||||||
if (!wh.hasGlob) {
|
|
||||||
throttler = this.fsw._throttle('readdir', directory, 1000);
|
|
||||||
if (!throttler) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const previous = this.fsw._getWatchedDir(wh.path);
|
|
||||||
const current = new Set();
|
|
||||||
|
|
||||||
let stream = this.fsw._readdirp(directory, {
|
|
||||||
fileFilter: entry => wh.filterPath(entry),
|
|
||||||
directoryFilter: entry => wh.filterDir(entry),
|
|
||||||
depth: 0
|
|
||||||
}).on(STR_DATA, async (entry) => {
|
|
||||||
if (this.fsw.closed) {
|
|
||||||
stream = undefined;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const item = entry.path;
|
|
||||||
let path = sysPath.join(directory, item);
|
|
||||||
current.add(item);
|
|
||||||
|
|
||||||
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.fsw.closed) {
|
|
||||||
stream = undefined;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Files that present in current directory snapshot
|
|
||||||
// but absent in previous are added to watch list and
|
|
||||||
// emit `add` event.
|
|
||||||
if (item === target || !target && !previous.has(item)) {
|
|
||||||
this.fsw._incrReadyCount();
|
|
||||||
|
|
||||||
// ensure relativeness of path is preserved in case of watcher reuse
|
|
||||||
path = sysPath.join(dir, sysPath.relative(dir, path));
|
|
||||||
|
|
||||||
this._addToNodeFs(path, initialAdd, wh, depth + 1);
|
|
||||||
}
|
|
||||||
}).on(EV_ERROR, this._boundHandleError);
|
|
||||||
|
|
||||||
return new Promise(resolve =>
|
|
||||||
stream.once(STR_END, () => {
|
|
||||||
if (this.fsw.closed) {
|
|
||||||
stream = undefined;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const wasThrottled = throttler ? throttler.clear() : false;
|
|
||||||
|
|
||||||
resolve();
|
|
||||||
|
|
||||||
// Files that absent in current directory snapshot
|
|
||||||
// but present in previous emit `remove` event
|
|
||||||
// and are removed from @watched[directory].
|
|
||||||
previous.getChildren().filter((item) => {
|
|
||||||
return item !== directory &&
|
|
||||||
!current.has(item) &&
|
|
||||||
// in case of intersecting globs;
|
|
||||||
// a path may have been filtered out of this readdir, but
|
|
||||||
// shouldn't be removed because it matches a different glob
|
|
||||||
(!wh.hasGlob || wh.filterPath({
|
|
||||||
fullPath: sysPath.resolve(directory, item)
|
|
||||||
}));
|
|
||||||
}).forEach((item) => {
|
|
||||||
this.fsw._remove(directory, item);
|
|
||||||
});
|
|
||||||
|
|
||||||
stream = undefined;
|
|
||||||
|
|
||||||
// one more time for any missed in case changes came in extremely quickly
|
|
||||||
if (wasThrottled) this._handleRead(directory, false, wh, target, dir, depth, throttler);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
|
||||||
* @param {String} dir fs path
|
|
||||||
* @param {fs.Stats} stats
|
|
||||||
* @param {Boolean} initialAdd
|
|
||||||
* @param {Number} depth relative to user-supplied path
|
|
||||||
* @param {String} target child path targeted for watch
|
|
||||||
* @param {Object} wh Common watch helpers for this path
|
|
||||||
* @param {String} realpath
|
|
||||||
* @returns {Promise<Function>} closer for the watcher instance.
|
|
||||||
*/
|
|
||||||
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
|
|
||||||
const parentDir = this.fsw._getWatchedDir(sysPath.dirname(dir));
|
|
||||||
const tracked = parentDir.has(sysPath.basename(dir));
|
|
||||||
if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
|
|
||||||
if (!wh.hasGlob || wh.globFilter(dir)) this.fsw._emit(EV_ADD_DIR, dir, stats);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensure dir is tracked (harmless if redundant)
|
|
||||||
parentDir.add(sysPath.basename(dir));
|
|
||||||
this.fsw._getWatchedDir(dir);
|
|
||||||
let throttler;
|
|
||||||
let closer;
|
|
||||||
|
|
||||||
const oDepth = this.fsw.options.depth;
|
|
||||||
if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
|
|
||||||
if (!target) {
|
|
||||||
await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
|
|
||||||
if (this.fsw.closed) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
|
|
||||||
// if current directory is removed, do nothing
|
|
||||||
if (stats && stats.mtimeMs === 0) return;
|
|
||||||
|
|
||||||
this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return closer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle added file, directory, or glob pattern.
|
|
||||||
* Delegates call to _handleFile / _handleDir after checks.
|
|
||||||
* @param {String} path to file or ir
|
|
||||||
* @param {Boolean} initialAdd was the file added at watch instantiation?
|
|
||||||
* @param {Object} priorWh depth relative to user-supplied path
|
|
||||||
* @param {Number} depth Child path actually targeted for watch
|
|
||||||
* @param {String=} target Child path actually targeted for watch
|
|
||||||
* @returns {Promise}
|
|
||||||
*/
|
|
||||||
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
|
||||||
const ready = this.fsw._emitReady;
|
|
||||||
if (this.fsw._isIgnored(path) || this.fsw.closed) {
|
|
||||||
ready();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const wh = this.fsw._getWatchHelpers(path, depth);
|
|
||||||
if (!wh.hasGlob && priorWh) {
|
|
||||||
wh.hasGlob = priorWh.hasGlob;
|
|
||||||
wh.globFilter = priorWh.globFilter;
|
|
||||||
wh.filterPath = entry => priorWh.filterPath(entry);
|
|
||||||
wh.filterDir = entry => priorWh.filterDir(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
// evaluate what is at the path we're being asked to watch
|
|
||||||
try {
|
|
||||||
const stats = await statMethods[wh.statMethod](wh.watchPath);
|
|
||||||
if (this.fsw.closed) return;
|
|
||||||
if (this.fsw._isIgnored(wh.watchPath, stats)) {
|
|
||||||
ready();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const follow = this.fsw.options.followSymlinks && !path.includes(STAR) && !path.includes(BRACE_START);
|
|
||||||
let closer;
|
|
||||||
if (stats.isDirectory()) {
|
|
||||||
const absPath = sysPath.resolve(path);
|
|
||||||
const targetPath = follow ? await fsrealpath(path) : path;
|
|
||||||
if (this.fsw.closed) return;
|
|
||||||
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
|
||||||
if (this.fsw.closed) return;
|
|
||||||
// preserve this symlink's target path
|
|
||||||
if (absPath !== targetPath && targetPath !== undefined) {
|
|
||||||
this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
||||||
}
|
|
||||||
} else if (stats.isSymbolicLink()) {
|
|
||||||
const targetPath = follow ? await fsrealpath(path) : path;
|
|
||||||
if (this.fsw.closed) return;
|
|
||||||
const parent = sysPath.dirname(wh.watchPath);
|
|
||||||
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
||||||
this.fsw._emit(EV_ADD, wh.watchPath, stats);
|
|
||||||
closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
|
|
||||||
if (this.fsw.closed) return;
|
|
||||||
|
|
||||||
// preserve this symlink's target path
|
|
||||||
if (targetPath !== undefined) {
|
|
||||||
this.fsw._symlinkPaths.set(sysPath.resolve(path), targetPath);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
||||||
}
|
|
||||||
ready();
|
|
||||||
|
|
||||||
this.fsw._addPathCloser(path, closer);
|
|
||||||
return false;
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
if (this.fsw._handleError(error)) {
|
|
||||||
ready();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = NodeFsHandler;
|
|
|
@ -1,70 +0,0 @@
|
||||||
{
|
|
||||||
"name": "chokidar",
|
|
||||||
"description": "Minimal and efficient cross-platform file watching library",
|
|
||||||
"version": "3.6.0",
|
|
||||||
"homepage": "https://github.com/paulmillr/chokidar",
|
|
||||||
"author": "Paul Miller (https://paulmillr.com)",
|
|
||||||
"contributors": [
|
|
||||||
"Paul Miller (https://paulmillr.com)",
|
|
||||||
"Elan Shanker"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 8.10.0"
|
|
||||||
},
|
|
||||||
"main": "index.js",
|
|
||||||
"types": "./types/index.d.ts",
|
|
||||||
"dependencies": {
|
|
||||||
"anymatch": "~3.1.2",
|
|
||||||
"braces": "~3.0.2",
|
|
||||||
"glob-parent": "~5.1.2",
|
|
||||||
"is-binary-path": "~2.1.0",
|
|
||||||
"is-glob": "~4.0.1",
|
|
||||||
"normalize-path": "~3.0.0",
|
|
||||||
"readdirp": "~3.6.0"
|
|
||||||
},
|
|
||||||
"optionalDependencies": {
|
|
||||||
"fsevents": "~2.3.2"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/node": "^14",
|
|
||||||
"chai": "^4.3",
|
|
||||||
"dtslint": "^3.3.0",
|
|
||||||
"eslint": "^7.0.0",
|
|
||||||
"mocha": "^7.0.0",
|
|
||||||
"rimraf": "^3.0.0",
|
|
||||||
"sinon": "^9.0.1",
|
|
||||||
"sinon-chai": "^3.3.0",
|
|
||||||
"typescript": "^4.4.3",
|
|
||||||
"upath": "^1.2.0"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"index.js",
|
|
||||||
"lib/*.js",
|
|
||||||
"types/index.d.ts"
|
|
||||||
],
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/paulmillr/chokidar.git"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/paulmillr/chokidar/issues"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"scripts": {
|
|
||||||
"dtslint": "dtslint types",
|
|
||||||
"lint": "eslint --report-unused-disable-directives --ignore-path .gitignore .",
|
|
||||||
"build": "npm ls",
|
|
||||||
"mocha": "mocha --exit --timeout 90000",
|
|
||||||
"test": "npm run lint && npm run mocha"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"fs",
|
|
||||||
"watch",
|
|
||||||
"watchFile",
|
|
||||||
"watcher",
|
|
||||||
"watching",
|
|
||||||
"file",
|
|
||||||
"fsevents"
|
|
||||||
],
|
|
||||||
"funding": "https://paulmillr.com/funding/"
|
|
||||||
}
|
|
|
@ -1,192 +0,0 @@
|
||||||
// TypeScript Version: 3.0
|
|
||||||
|
|
||||||
/// <reference types="node" />
|
|
||||||
|
|
||||||
import * as fs from "fs";
|
|
||||||
import { EventEmitter } from "events";
|
|
||||||
import { Matcher } from 'anymatch';
|
|
||||||
|
|
||||||
export class FSWatcher extends EventEmitter implements fs.FSWatcher {
|
|
||||||
options: WatchOptions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new FSWatcher instance with optional WatchOptions parameter.
|
|
||||||
*/
|
|
||||||
constructor(options?: WatchOptions);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add files, directories, or glob patterns for tracking. Takes an array of strings or just one
|
|
||||||
* string.
|
|
||||||
*/
|
|
||||||
add(paths: string | ReadonlyArray<string>): this;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop watching files, directories, or glob patterns. Takes an array of strings or just one
|
|
||||||
* string.
|
|
||||||
*/
|
|
||||||
unwatch(paths: string | ReadonlyArray<string>): this;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an object representing all the paths on the file system being watched by this
|
|
||||||
* `FSWatcher` instance. The object's keys are all the directories (using absolute paths unless
|
|
||||||
* the `cwd` option was used), and the values are arrays of the names of the items contained in
|
|
||||||
* each directory.
|
|
||||||
*/
|
|
||||||
getWatched(): {
|
|
||||||
[directory: string]: string[];
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes all listeners from watched files.
|
|
||||||
*/
|
|
||||||
close(): Promise<void>;
|
|
||||||
|
|
||||||
on(event: 'add'|'addDir'|'change', listener: (path: string, stats?: fs.Stats) => void): this;
|
|
||||||
|
|
||||||
on(event: 'all', listener: (eventName: 'add'|'addDir'|'change'|'unlink'|'unlinkDir', path: string, stats?: fs.Stats) => void): this;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error occurred
|
|
||||||
*/
|
|
||||||
on(event: 'error', listener: (error: Error) => void): this;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exposes the native Node `fs.FSWatcher events`
|
|
||||||
*/
|
|
||||||
on(event: 'raw', listener: (eventName: string, path: string, details: any) => void): this;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fires when the initial scan is complete
|
|
||||||
*/
|
|
||||||
on(event: 'ready', listener: () => void): this;
|
|
||||||
|
|
||||||
on(event: 'unlink'|'unlinkDir', listener: (path: string) => void): this;
|
|
||||||
|
|
||||||
on(event: string, listener: (...args: any[]) => void): this;
|
|
||||||
|
|
||||||
ref(): this;
|
|
||||||
|
|
||||||
unref(): this;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WatchOptions {
|
|
||||||
/**
|
|
||||||
* Indicates whether the process should continue to run as long as files are being watched. If
|
|
||||||
* set to `false` when using `fsevents` to watch, no more events will be emitted after `ready`,
|
|
||||||
* even if the process continues to run.
|
|
||||||
*/
|
|
||||||
persistent?: boolean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ([anymatch](https://github.com/micromatch/anymatch)-compatible definition) Defines files/paths to
|
|
||||||
* be ignored. The whole relative or absolute path is tested, not just filename. If a function
|
|
||||||
* with two arguments is provided, it gets called twice per path - once with a single argument
|
|
||||||
* (the path), second time with two arguments (the path and the
|
|
||||||
* [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object of that path).
|
|
||||||
*/
|
|
||||||
ignored?: Matcher;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If set to `false` then `add`/`addDir` events are also emitted for matching paths while
|
|
||||||
* instantiating the watching as chokidar discovers these file paths (before the `ready` event).
|
|
||||||
*/
|
|
||||||
ignoreInitial?: boolean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When `false`, only the symlinks themselves will be watched for changes instead of following
|
|
||||||
* the link references and bubbling events through the link's path.
|
|
||||||
*/
|
|
||||||
followSymlinks?: boolean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The base directory from which watch `paths` are to be derived. Paths emitted with events will
|
|
||||||
* be relative to this.
|
|
||||||
*/
|
|
||||||
cwd?: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If set to true then the strings passed to .watch() and .add() are treated as literal path
|
|
||||||
* names, even if they look like globs. Default: false.
|
|
||||||
*/
|
|
||||||
disableGlobbing?: boolean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether to use fs.watchFile (backed by polling), or fs.watch. If polling leads to high CPU
|
|
||||||
* utilization, consider setting this to `false`. It is typically necessary to **set this to
|
|
||||||
* `true` to successfully watch files over a network**, and it may be necessary to successfully
|
|
||||||
* watch files in other non-standard situations. Setting to `true` explicitly on OS X overrides
|
|
||||||
* the `useFsEvents` default.
|
|
||||||
*/
|
|
||||||
usePolling?: boolean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether to use the `fsevents` watching interface if available. When set to `true` explicitly
|
|
||||||
* and `fsevents` is available this supercedes the `usePolling` setting. When set to `false` on
|
|
||||||
* OS X, `usePolling: true` becomes the default.
|
|
||||||
*/
|
|
||||||
useFsEvents?: boolean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If relying upon the [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object that
|
|
||||||
* may get passed with `add`, `addDir`, and `change` events, set this to `true` to ensure it is
|
|
||||||
* provided even in cases where it wasn't already available from the underlying watch events.
|
|
||||||
*/
|
|
||||||
alwaysStat?: boolean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If set, limits how many levels of subdirectories will be traversed.
|
|
||||||
*/
|
|
||||||
depth?: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interval of file system polling.
|
|
||||||
*/
|
|
||||||
interval?: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interval of file system polling for binary files. ([see list of binary extensions](https://gi
|
|
||||||
* thub.com/sindresorhus/binary-extensions/blob/master/binary-extensions.json))
|
|
||||||
*/
|
|
||||||
binaryInterval?: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates whether to watch files that don't have read permissions if possible. If watching
|
|
||||||
* fails due to `EPERM` or `EACCES` with this set to `true`, the errors will be suppressed
|
|
||||||
* silently.
|
|
||||||
*/
|
|
||||||
ignorePermissionErrors?: boolean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* `true` if `useFsEvents` and `usePolling` are `false`). Automatically filters out artifacts
|
|
||||||
* that occur when using editors that use "atomic writes" instead of writing directly to the
|
|
||||||
* source file. If a file is re-added within 100 ms of being deleted, Chokidar emits a `change`
|
|
||||||
* event rather than `unlink` then `add`. If the default of 100 ms does not work well for you,
|
|
||||||
* you can override it by setting `atomic` to a custom value, in milliseconds.
|
|
||||||
*/
|
|
||||||
atomic?: boolean | number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* can be set to an object in order to adjust timing params:
|
|
||||||
*/
|
|
||||||
awaitWriteFinish?: AwaitWriteFinishOptions | boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AwaitWriteFinishOptions {
|
|
||||||
/**
|
|
||||||
* Amount of time in milliseconds for a file size to remain constant before emitting its event.
|
|
||||||
*/
|
|
||||||
stabilityThreshold?: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* File size polling interval.
|
|
||||||
*/
|
|
||||||
pollInterval?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* produces an instance of `FSWatcher`.
|
|
||||||
*/
|
|
||||||
export function watch(
|
|
||||||
paths: string | ReadonlyArray<string>,
|
|
||||||
options?: WatchOptions
|
|
||||||
): FSWatcher;
|
|
|
@ -1,4 +0,0 @@
|
||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- 0.4
|
|
||||||
- 0.6
|
|
|
@ -1,18 +0,0 @@
|
||||||
This software is released under the MIT license:
|
|
||||||
|
|
||||||
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,62 +0,0 @@
|
||||||
concat-map
|
|
||||||
==========
|
|
||||||
|
|
||||||
Concatenative mapdashery.
|
|
||||||
|
|
||||||
[![browser support](http://ci.testling.com/substack/node-concat-map.png)](http://ci.testling.com/substack/node-concat-map)
|
|
||||||
|
|
||||||
[![build status](https://secure.travis-ci.org/substack/node-concat-map.png)](http://travis-ci.org/substack/node-concat-map)
|
|
||||||
|
|
||||||
example
|
|
||||||
=======
|
|
||||||
|
|
||||||
``` js
|
|
||||||
var concatMap = require('concat-map');
|
|
||||||
var xs = [ 1, 2, 3, 4, 5, 6 ];
|
|
||||||
var ys = concatMap(xs, function (x) {
|
|
||||||
return x % 2 ? [ x - 0.1, x, x + 0.1 ] : [];
|
|
||||||
});
|
|
||||||
console.dir(ys);
|
|
||||||
```
|
|
||||||
|
|
||||||
***
|
|
||||||
|
|
||||||
```
|
|
||||||
[ 0.9, 1, 1.1, 2.9, 3, 3.1, 4.9, 5, 5.1 ]
|
|
||||||
```
|
|
||||||
|
|
||||||
methods
|
|
||||||
=======
|
|
||||||
|
|
||||||
``` js
|
|
||||||
var concatMap = require('concat-map')
|
|
||||||
```
|
|
||||||
|
|
||||||
concatMap(xs, fn)
|
|
||||||
-----------------
|
|
||||||
|
|
||||||
Return an array of concatenated elements by calling `fn(x, i)` for each element
|
|
||||||
`x` and each index `i` in the array `xs`.
|
|
||||||
|
|
||||||
When `fn(x, i)` returns an array, its result will be concatenated with the
|
|
||||||
result array. If `fn(x, i)` returns anything else, that value will be pushed
|
|
||||||
onto the end of the result array.
|
|
||||||
|
|
||||||
install
|
|
||||||
=======
|
|
||||||
|
|
||||||
With [npm](http://npmjs.org) do:
|
|
||||||
|
|
||||||
```
|
|
||||||
npm install concat-map
|
|
||||||
```
|
|
||||||
|
|
||||||
license
|
|
||||||
=======
|
|
||||||
|
|
||||||
MIT
|
|
||||||
|
|
||||||
notes
|
|
||||||
=====
|
|
||||||
|
|
||||||
This module was written while sitting high above the ground in a tree.
|
|
|
@ -1,6 +0,0 @@
|
||||||
var concatMap = require('../');
|
|
||||||
var xs = [ 1, 2, 3, 4, 5, 6 ];
|
|
||||||
var ys = concatMap(xs, function (x) {
|
|
||||||
return x % 2 ? [ x - 0.1, x, x + 0.1 ] : [];
|
|
||||||
});
|
|
||||||
console.dir(ys);
|
|
|
@ -1,13 +0,0 @@
|
||||||
module.exports = function (xs, fn) {
|
|
||||||
var res = [];
|
|
||||||
for (var i = 0; i < xs.length; i++) {
|
|
||||||
var x = fn(xs[i], i);
|
|
||||||
if (isArray(x)) res.push.apply(res, x);
|
|
||||||
else res.push(x);
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
};
|
|
||||||
|
|
||||||
var isArray = Array.isArray || function (xs) {
|
|
||||||
return Object.prototype.toString.call(xs) === '[object Array]';
|
|
||||||
};
|
|
|
@ -1,43 +0,0 @@
|
||||||
{
|
|
||||||
"name" : "concat-map",
|
|
||||||
"description" : "concatenative mapdashery",
|
|
||||||
"version" : "0.0.1",
|
|
||||||
"repository" : {
|
|
||||||
"type" : "git",
|
|
||||||
"url" : "git://github.com/substack/node-concat-map.git"
|
|
||||||
},
|
|
||||||
"main" : "index.js",
|
|
||||||
"keywords" : [
|
|
||||||
"concat",
|
|
||||||
"concatMap",
|
|
||||||
"map",
|
|
||||||
"functional",
|
|
||||||
"higher-order"
|
|
||||||
],
|
|
||||||
"directories" : {
|
|
||||||
"example" : "example",
|
|
||||||
"test" : "test"
|
|
||||||
},
|
|
||||||
"scripts" : {
|
|
||||||
"test" : "tape test/*.js"
|
|
||||||
},
|
|
||||||
"devDependencies" : {
|
|
||||||
"tape" : "~2.4.0"
|
|
||||||
},
|
|
||||||
"license" : "MIT",
|
|
||||||
"author" : {
|
|
||||||
"name" : "James Halliday",
|
|
||||||
"email" : "mail@substack.net",
|
|
||||||
"url" : "http://substack.net"
|
|
||||||
},
|
|
||||||
"testling" : {
|
|
||||||
"files" : "test/*.js",
|
|
||||||
"browsers" : {
|
|
||||||
"ie" : [ 6, 7, 8, 9 ],
|
|
||||||
"ff" : [ 3.5, 10, 15.0 ],
|
|
||||||
"chrome" : [ 10, 22 ],
|
|
||||||
"safari" : [ 5.1 ],
|
|
||||||
"opera" : [ 12 ]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
var concatMap = require('../');
|
|
||||||
var test = require('tape');
|
|
||||||
|
|
||||||
test('empty or not', function (t) {
|
|
||||||
var xs = [ 1, 2, 3, 4, 5, 6 ];
|
|
||||||
var ixes = [];
|
|
||||||
var ys = concatMap(xs, function (x, ix) {
|
|
||||||
ixes.push(ix);
|
|
||||||
return x % 2 ? [ x - 0.1, x, x + 0.1 ] : [];
|
|
||||||
});
|
|
||||||
t.same(ys, [ 0.9, 1, 1.1, 2.9, 3, 3.1, 4.9, 5, 5.1 ]);
|
|
||||||
t.same(ixes, [ 0, 1, 2, 3, 4, 5 ]);
|
|
||||||
t.end();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('always something', function (t) {
|
|
||||||
var xs = [ 'a', 'b', 'c', 'd' ];
|
|
||||||
var ys = concatMap(xs, function (x) {
|
|
||||||
return x === 'b' ? [ 'B', 'B', 'B' ] : [ x ];
|
|
||||||
});
|
|
||||||
t.same(ys, [ 'a', 'B', 'B', 'B', 'c', 'd' ]);
|
|
||||||
t.end();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('scalars', function (t) {
|
|
||||||
var xs = [ 'a', 'b', 'c', 'd' ];
|
|
||||||
var ys = concatMap(xs, function (x) {
|
|
||||||
return x === 'b' ? [ 'B', 'B', 'B' ] : x;
|
|
||||||
});
|
|
||||||
t.same(ys, [ 'a', 'B', 'B', 'B', 'c', 'd' ]);
|
|
||||||
t.end();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('undefs', function (t) {
|
|
||||||
var xs = [ 'a', 'b', 'c', 'd' ];
|
|
||||||
var ys = concatMap(xs, function () {});
|
|
||||||
t.same(ys, [ undefined, undefined, undefined, undefined ]);
|
|
||||||
t.end();
|
|
||||||
});
|
|
|
@ -1,20 +0,0 @@
|
||||||
(The MIT License)
|
|
||||||
|
|
||||||
Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
|
|
||||||
Copyright (c) 2018-2021 Josh Junon
|
|
||||||
|
|
||||||
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,481 +0,0 @@
|
||||||
# debug
|
|
||||||
[![Build Status](https://travis-ci.org/debug-js/debug.svg?branch=master)](https://travis-ci.org/debug-js/debug) [![Coverage Status](https://coveralls.io/repos/github/debug-js/debug/badge.svg?branch=master)](https://coveralls.io/github/debug-js/debug?branch=master) [![Slack](https://visionmedia-community-slackin.now.sh/badge.svg)](https://visionmedia-community-slackin.now.sh/) [![OpenCollective](https://opencollective.com/debug/backers/badge.svg)](#backers)
|
|
||||||
[![OpenCollective](https://opencollective.com/debug/sponsors/badge.svg)](#sponsors)
|
|
||||||
|
|
||||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091486-fa38524c-7c37-11e7-895f-e7ec8e1039b6.png">
|
|
||||||
|
|
||||||
A tiny JavaScript debugging utility modelled after Node.js core's debugging
|
|
||||||
technique. Works in Node.js and web browsers.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ npm install debug
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
`debug` exposes a function; simply pass this function the name of your module, and it will return a decorated version of `console.error` for you to pass debug statements to. This will allow you to toggle the debug output for different parts of your module as well as the module as a whole.
|
|
||||||
|
|
||||||
Example [_app.js_](./examples/node/app.js):
|
|
||||||
|
|
||||||
```js
|
|
||||||
var debug = require('debug')('http')
|
|
||||||
, http = require('http')
|
|
||||||
, name = 'My App';
|
|
||||||
|
|
||||||
// fake app
|
|
||||||
|
|
||||||
debug('booting %o', name);
|
|
||||||
|
|
||||||
http.createServer(function(req, res){
|
|
||||||
debug(req.method + ' ' + req.url);
|
|
||||||
res.end('hello\n');
|
|
||||||
}).listen(3000, function(){
|
|
||||||
debug('listening');
|
|
||||||
});
|
|
||||||
|
|
||||||
// fake worker of some kind
|
|
||||||
|
|
||||||
require('./worker');
|
|
||||||
```
|
|
||||||
|
|
||||||
Example [_worker.js_](./examples/node/worker.js):
|
|
||||||
|
|
||||||
```js
|
|
||||||
var a = require('debug')('worker:a')
|
|
||||||
, b = require('debug')('worker:b');
|
|
||||||
|
|
||||||
function work() {
|
|
||||||
a('doing lots of uninteresting work');
|
|
||||||
setTimeout(work, Math.random() * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
work();
|
|
||||||
|
|
||||||
function workb() {
|
|
||||||
b('doing some work');
|
|
||||||
setTimeout(workb, Math.random() * 2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
workb();
|
|
||||||
```
|
|
||||||
|
|
||||||
The `DEBUG` environment variable is then used to enable these based on space or
|
|
||||||
comma-delimited names.
|
|
||||||
|
|
||||||
Here are some examples:
|
|
||||||
|
|
||||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 04 pm" src="https://user-images.githubusercontent.com/71256/29091703-a6302cdc-7c38-11e7-8304-7c0b3bc600cd.png">
|
|
||||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 38 pm" src="https://user-images.githubusercontent.com/71256/29091700-a62a6888-7c38-11e7-800b-db911291ca2b.png">
|
|
||||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 25 pm" src="https://user-images.githubusercontent.com/71256/29091701-a62ea114-7c38-11e7-826a-2692bedca740.png">
|
|
||||||
|
|
||||||
#### Windows command prompt notes
|
|
||||||
|
|
||||||
##### CMD
|
|
||||||
|
|
||||||
On Windows the environment variable is set using the `set` command.
|
|
||||||
|
|
||||||
```cmd
|
|
||||||
set DEBUG=*,-not_this
|
|
||||||
```
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```cmd
|
|
||||||
set DEBUG=* & node app.js
|
|
||||||
```
|
|
||||||
|
|
||||||
##### PowerShell (VS Code default)
|
|
||||||
|
|
||||||
PowerShell uses different syntax to set environment variables.
|
|
||||||
|
|
||||||
```cmd
|
|
||||||
$env:DEBUG = "*,-not_this"
|
|
||||||
```
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```cmd
|
|
||||||
$env:DEBUG='app';node app.js
|
|
||||||
```
|
|
||||||
|
|
||||||
Then, run the program to be debugged as usual.
|
|
||||||
|
|
||||||
npm script example:
|
|
||||||
```js
|
|
||||||
"windowsDebug": "@powershell -Command $env:DEBUG='*';node app.js",
|
|
||||||
```
|
|
||||||
|
|
||||||
## Namespace Colors
|
|
||||||
|
|
||||||
Every debug instance has a color generated for it based on its namespace name.
|
|
||||||
This helps when visually parsing the debug output to identify which debug instance
|
|
||||||
a debug line belongs to.
|
|
||||||
|
|
||||||
#### Node.js
|
|
||||||
|
|
||||||
In Node.js, colors are enabled when stderr is a TTY. You also _should_ install
|
|
||||||
the [`supports-color`](https://npmjs.org/supports-color) module alongside debug,
|
|
||||||
otherwise debug will only use a small handful of basic colors.
|
|
||||||
|
|
||||||
<img width="521" src="https://user-images.githubusercontent.com/71256/29092181-47f6a9e6-7c3a-11e7-9a14-1928d8a711cd.png">
|
|
||||||
|
|
||||||
#### Web Browser
|
|
||||||
|
|
||||||
Colors are also enabled on "Web Inspectors" that understand the `%c` formatting
|
|
||||||
option. These are WebKit web inspectors, Firefox ([since version
|
|
||||||
31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/))
|
|
||||||
and the Firebug plugin for Firefox (any version).
|
|
||||||
|
|
||||||
<img width="524" src="https://user-images.githubusercontent.com/71256/29092033-b65f9f2e-7c39-11e7-8e32-f6f0d8e865c1.png">
|
|
||||||
|
|
||||||
|
|
||||||
## Millisecond diff
|
|
||||||
|
|
||||||
When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls.
|
|
||||||
|
|
||||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091486-fa38524c-7c37-11e7-895f-e7ec8e1039b6.png">
|
|
||||||
|
|
||||||
When stdout is not a TTY, `Date#toISOString()` is used, making it more useful for logging the debug information as shown below:
|
|
||||||
|
|
||||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091956-6bd78372-7c39-11e7-8c55-c948396d6edd.png">
|
|
||||||
|
|
||||||
|
|
||||||
## Conventions
|
|
||||||
|
|
||||||
If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". If you append a "*" to the end of your name, it will always be enabled regardless of the setting of the DEBUG environment variable. You can then use it for normal output as well as debug output.
|
|
||||||
|
|
||||||
## Wildcards
|
|
||||||
|
|
||||||
The `*` character may be used as a wildcard. Suppose for example your library has
|
|
||||||
debuggers named "connect:bodyParser", "connect:compress", "connect:session",
|
|
||||||
instead of listing all three with
|
|
||||||
`DEBUG=connect:bodyParser,connect:compress,connect:session`, you may simply do
|
|
||||||
`DEBUG=connect:*`, or to run everything using this module simply use `DEBUG=*`.
|
|
||||||
|
|
||||||
You can also exclude specific debuggers by prefixing them with a "-" character.
|
|
||||||
For example, `DEBUG=*,-connect:*` would include all debuggers except those
|
|
||||||
starting with "connect:".
|
|
||||||
|
|
||||||
## Environment Variables
|
|
||||||
|
|
||||||
When running through Node.js, you can set a few environment variables that will
|
|
||||||
change the behavior of the debug logging:
|
|
||||||
|
|
||||||
| Name | Purpose |
|
|
||||||
|-----------|-------------------------------------------------|
|
|
||||||
| `DEBUG` | Enables/disables specific debugging namespaces. |
|
|
||||||
| `DEBUG_HIDE_DATE` | Hide date from debug output (non-TTY). |
|
|
||||||
| `DEBUG_COLORS`| Whether or not to use colors in the debug output. |
|
|
||||||
| `DEBUG_DEPTH` | Object inspection depth. |
|
|
||||||
| `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. |
|
|
||||||
|
|
||||||
|
|
||||||
__Note:__ The environment variables beginning with `DEBUG_` end up being
|
|
||||||
converted into an Options object that gets used with `%o`/`%O` formatters.
|
|
||||||
See the Node.js documentation for
|
|
||||||
[`util.inspect()`](https://nodejs.org/api/util.html#util_util_inspect_object_options)
|
|
||||||
for the complete list.
|
|
||||||
|
|
||||||
## Formatters
|
|
||||||
|
|
||||||
Debug uses [printf-style](https://wikipedia.org/wiki/Printf_format_string) formatting.
|
|
||||||
Below are the officially supported formatters:
|
|
||||||
|
|
||||||
| Formatter | Representation |
|
|
||||||
|-----------|----------------|
|
|
||||||
| `%O` | Pretty-print an Object on multiple lines. |
|
|
||||||
| `%o` | Pretty-print an Object all on a single line. |
|
|
||||||
| `%s` | String. |
|
|
||||||
| `%d` | Number (both integer and float). |
|
|
||||||
| `%j` | JSON. Replaced with the string '[Circular]' if the argument contains circular references. |
|
|
||||||
| `%%` | Single percent sign ('%'). This does not consume an argument. |
|
|
||||||
|
|
||||||
|
|
||||||
### Custom formatters
|
|
||||||
|
|
||||||
You can add custom formatters by extending the `debug.formatters` object.
|
|
||||||
For example, if you wanted to add support for rendering a Buffer as hex with
|
|
||||||
`%h`, you could do something like:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const createDebug = require('debug')
|
|
||||||
createDebug.formatters.h = (v) => {
|
|
||||||
return v.toString('hex')
|
|
||||||
}
|
|
||||||
|
|
||||||
// …elsewhere
|
|
||||||
const debug = createDebug('foo')
|
|
||||||
debug('this is hex: %h', new Buffer('hello world'))
|
|
||||||
// foo this is hex: 68656c6c6f20776f726c6421 +0ms
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Browser Support
|
|
||||||
|
|
||||||
You can build a browser-ready script using [browserify](https://github.com/substack/node-browserify),
|
|
||||||
or just use the [browserify-as-a-service](https://wzrd.in/) [build](https://wzrd.in/standalone/debug@latest),
|
|
||||||
if you don't want to build it yourself.
|
|
||||||
|
|
||||||
Debug's enable state is currently persisted by `localStorage`.
|
|
||||||
Consider the situation shown below where you have `worker:a` and `worker:b`,
|
|
||||||
and wish to debug both. You can enable this using `localStorage.debug`:
|
|
||||||
|
|
||||||
```js
|
|
||||||
localStorage.debug = 'worker:*'
|
|
||||||
```
|
|
||||||
|
|
||||||
And then refresh the page.
|
|
||||||
|
|
||||||
```js
|
|
||||||
a = debug('worker:a');
|
|
||||||
b = debug('worker:b');
|
|
||||||
|
|
||||||
setInterval(function(){
|
|
||||||
a('doing some work');
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
setInterval(function(){
|
|
||||||
b('doing some work');
|
|
||||||
}, 1200);
|
|
||||||
```
|
|
||||||
|
|
||||||
In Chromium-based web browsers (e.g. Brave, Chrome, and Electron), the JavaScript console will—by default—only show messages logged by `debug` if the "Verbose" log level is _enabled_.
|
|
||||||
|
|
||||||
<img width="647" src="https://user-images.githubusercontent.com/7143133/152083257-29034707-c42c-4959-8add-3cee850e6fcf.png">
|
|
||||||
|
|
||||||
## Output streams
|
|
||||||
|
|
||||||
By default `debug` will log to stderr, however this can be configured per-namespace by overriding the `log` method:
|
|
||||||
|
|
||||||
Example [_stdout.js_](./examples/node/stdout.js):
|
|
||||||
|
|
||||||
```js
|
|
||||||
var debug = require('debug');
|
|
||||||
var error = debug('app:error');
|
|
||||||
|
|
||||||
// by default stderr is used
|
|
||||||
error('goes to stderr!');
|
|
||||||
|
|
||||||
var log = debug('app:log');
|
|
||||||
// set this namespace to log via console.log
|
|
||||||
log.log = console.log.bind(console); // don't forget to bind to console!
|
|
||||||
log('goes to stdout');
|
|
||||||
error('still goes to stderr!');
|
|
||||||
|
|
||||||
// set all output to go via console.info
|
|
||||||
// overrides all per-namespace log settings
|
|
||||||
debug.log = console.info.bind(console);
|
|
||||||
error('now goes to stdout via console.info');
|
|
||||||
log('still goes to stdout, but via console.info now');
|
|
||||||
```
|
|
||||||
|
|
||||||
## Extend
|
|
||||||
You can simply extend debugger
|
|
||||||
```js
|
|
||||||
const log = require('debug')('auth');
|
|
||||||
|
|
||||||
//creates new debug instance with extended namespace
|
|
||||||
const logSign = log.extend('sign');
|
|
||||||
const logLogin = log.extend('login');
|
|
||||||
|
|
||||||
log('hello'); // auth hello
|
|
||||||
logSign('hello'); //auth:sign hello
|
|
||||||
logLogin('hello'); //auth:login hello
|
|
||||||
```
|
|
||||||
|
|
||||||
## Set dynamically
|
|
||||||
|
|
||||||
You can also enable debug dynamically by calling the `enable()` method :
|
|
||||||
|
|
||||||
```js
|
|
||||||
let debug = require('debug');
|
|
||||||
|
|
||||||
console.log(1, debug.enabled('test'));
|
|
||||||
|
|
||||||
debug.enable('test');
|
|
||||||
console.log(2, debug.enabled('test'));
|
|
||||||
|
|
||||||
debug.disable();
|
|
||||||
console.log(3, debug.enabled('test'));
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
print :
|
|
||||||
```
|
|
||||||
1 false
|
|
||||||
2 true
|
|
||||||
3 false
|
|
||||||
```
|
|
||||||
|
|
||||||
Usage :
|
|
||||||
`enable(namespaces)`
|
|
||||||
`namespaces` can include modes separated by a colon and wildcards.
|
|
||||||
|
|
||||||
Note that calling `enable()` completely overrides previously set DEBUG variable :
|
|
||||||
|
|
||||||
```
|
|
||||||
$ DEBUG=foo node -e 'var dbg = require("debug"); dbg.enable("bar"); console.log(dbg.enabled("foo"))'
|
|
||||||
=> false
|
|
||||||
```
|
|
||||||
|
|
||||||
`disable()`
|
|
||||||
|
|
||||||
Will disable all namespaces. The functions returns the namespaces currently
|
|
||||||
enabled (and skipped). This can be useful if you want to disable debugging
|
|
||||||
temporarily without knowing what was enabled to begin with.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
|
||||||
let debug = require('debug');
|
|
||||||
debug.enable('foo:*,-foo:bar');
|
|
||||||
let namespaces = debug.disable();
|
|
||||||
debug.enable(namespaces);
|
|
||||||
```
|
|
||||||
|
|
||||||
Note: There is no guarantee that the string will be identical to the initial
|
|
||||||
enable string, but semantically they will be identical.
|
|
||||||
|
|
||||||
## Checking whether a debug target is enabled
|
|
||||||
|
|
||||||
After you've created a debug instance, you can determine whether or not it is
|
|
||||||
enabled by checking the `enabled` property:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const debug = require('debug')('http');
|
|
||||||
|
|
||||||
if (debug.enabled) {
|
|
||||||
// do stuff...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also manually toggle this property to force the debug instance to be
|
|
||||||
enabled or disabled.
|
|
||||||
|
|
||||||
## Usage in child processes
|
|
||||||
|
|
||||||
Due to the way `debug` detects if the output is a TTY or not, colors are not shown in child processes when `stderr` is piped. A solution is to pass the `DEBUG_COLORS=1` environment variable to the child process.
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
worker = fork(WORKER_WRAP_PATH, [workerPath], {
|
|
||||||
stdio: [
|
|
||||||
/* stdin: */ 0,
|
|
||||||
/* stdout: */ 'pipe',
|
|
||||||
/* stderr: */ 'pipe',
|
|
||||||
'ipc',
|
|
||||||
],
|
|
||||||
env: Object.assign({}, process.env, {
|
|
||||||
DEBUG_COLORS: 1 // without this settings, colors won't be shown
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
worker.stderr.pipe(process.stderr, { end: false });
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Authors
|
|
||||||
|
|
||||||
- TJ Holowaychuk
|
|
||||||
- Nathan Rajlich
|
|
||||||
- Andrew Rhyne
|
|
||||||
- Josh Junon
|
|
||||||
|
|
||||||
## Backers
|
|
||||||
|
|
||||||
Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/debug#backer)]
|
|
||||||
|
|
||||||
<a href="https://opencollective.com/debug/backer/0/website" target="_blank"><img src="https://opencollective.com/debug/backer/0/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/1/website" target="_blank"><img src="https://opencollective.com/debug/backer/1/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/2/website" target="_blank"><img src="https://opencollective.com/debug/backer/2/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/3/website" target="_blank"><img src="https://opencollective.com/debug/backer/3/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/4/website" target="_blank"><img src="https://opencollective.com/debug/backer/4/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/5/website" target="_blank"><img src="https://opencollective.com/debug/backer/5/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/6/website" target="_blank"><img src="https://opencollective.com/debug/backer/6/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/7/website" target="_blank"><img src="https://opencollective.com/debug/backer/7/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/8/website" target="_blank"><img src="https://opencollective.com/debug/backer/8/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/9/website" target="_blank"><img src="https://opencollective.com/debug/backer/9/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/10/website" target="_blank"><img src="https://opencollective.com/debug/backer/10/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/11/website" target="_blank"><img src="https://opencollective.com/debug/backer/11/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/12/website" target="_blank"><img src="https://opencollective.com/debug/backer/12/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/13/website" target="_blank"><img src="https://opencollective.com/debug/backer/13/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/14/website" target="_blank"><img src="https://opencollective.com/debug/backer/14/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/15/website" target="_blank"><img src="https://opencollective.com/debug/backer/15/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/16/website" target="_blank"><img src="https://opencollective.com/debug/backer/16/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/17/website" target="_blank"><img src="https://opencollective.com/debug/backer/17/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/18/website" target="_blank"><img src="https://opencollective.com/debug/backer/18/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/19/website" target="_blank"><img src="https://opencollective.com/debug/backer/19/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/20/website" target="_blank"><img src="https://opencollective.com/debug/backer/20/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/21/website" target="_blank"><img src="https://opencollective.com/debug/backer/21/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/22/website" target="_blank"><img src="https://opencollective.com/debug/backer/22/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/23/website" target="_blank"><img src="https://opencollective.com/debug/backer/23/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/24/website" target="_blank"><img src="https://opencollective.com/debug/backer/24/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/25/website" target="_blank"><img src="https://opencollective.com/debug/backer/25/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/26/website" target="_blank"><img src="https://opencollective.com/debug/backer/26/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/27/website" target="_blank"><img src="https://opencollective.com/debug/backer/27/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/28/website" target="_blank"><img src="https://opencollective.com/debug/backer/28/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/29/website" target="_blank"><img src="https://opencollective.com/debug/backer/29/avatar.svg"></a>
|
|
||||||
|
|
||||||
|
|
||||||
## Sponsors
|
|
||||||
|
|
||||||
Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/debug#sponsor)]
|
|
||||||
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/0/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/0/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/1/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/1/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/2/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/2/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/3/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/3/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/4/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/4/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/5/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/5/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/6/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/6/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/7/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/7/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/8/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/8/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/9/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/9/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/10/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/10/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/11/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/11/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/12/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/12/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/13/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/13/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/14/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/14/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/15/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/15/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/16/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/16/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/17/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/17/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/18/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/18/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/19/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/19/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/20/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/20/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/21/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/21/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/22/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/22/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/23/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/23/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/24/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/24/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/25/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/25/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/26/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/26/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/27/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/27/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/28/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/28/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/29/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/29/avatar.svg"></a>
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
(The MIT License)
|
|
||||||
|
|
||||||
Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
|
|
||||||
Copyright (c) 2018-2021 Josh Junon
|
|
||||||
|
|
||||||
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,60 +0,0 @@
|
||||||
{
|
|
||||||
"name": "debug",
|
|
||||||
"version": "4.3.5",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/debug-js/debug.git"
|
|
||||||
},
|
|
||||||
"description": "Lightweight debugging utility for Node.js and the browser",
|
|
||||||
"keywords": [
|
|
||||||
"debug",
|
|
||||||
"log",
|
|
||||||
"debugger"
|
|
||||||
],
|
|
||||||
"files": [
|
|
||||||
"src",
|
|
||||||
"LICENSE",
|
|
||||||
"README.md"
|
|
||||||
],
|
|
||||||
"author": "Josh Junon (https://github.com/qix-)",
|
|
||||||
"contributors": [
|
|
||||||
"TJ Holowaychuk <tj@vision-media.ca>",
|
|
||||||
"Nathan Rajlich <nathan@tootallnate.net> (http://n8.io)",
|
|
||||||
"Andrew Rhyne <rhyneandrew@gmail.com>"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"scripts": {
|
|
||||||
"lint": "xo",
|
|
||||||
"test": "npm run test:node && npm run test:browser && npm run lint",
|
|
||||||
"test:node": "istanbul cover _mocha -- test.js test.node.js",
|
|
||||||
"test:browser": "karma start --single-run",
|
|
||||||
"test:coverage": "cat ./coverage/lcov.info | coveralls"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"ms": "2.1.2"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"brfs": "^2.0.1",
|
|
||||||
"browserify": "^16.2.3",
|
|
||||||
"coveralls": "^3.0.2",
|
|
||||||
"istanbul": "^0.4.5",
|
|
||||||
"karma": "^3.1.4",
|
|
||||||
"karma-browserify": "^6.0.0",
|
|
||||||
"karma-chrome-launcher": "^2.2.0",
|
|
||||||
"karma-mocha": "^1.3.0",
|
|
||||||
"mocha": "^5.2.0",
|
|
||||||
"mocha-lcov-reporter": "^1.2.0",
|
|
||||||
"sinon": "^14.0.0",
|
|
||||||
"xo": "^0.23.0"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"supports-color": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"main": "./src/index.js",
|
|
||||||
"browser": "./src/browser.js",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=6.0"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,269 +0,0 @@
|
||||||
/* eslint-env browser */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the web browser implementation of `debug()`.
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.formatArgs = formatArgs;
|
|
||||||
exports.save = save;
|
|
||||||
exports.load = load;
|
|
||||||
exports.useColors = useColors;
|
|
||||||
exports.storage = localstorage();
|
|
||||||
exports.destroy = (() => {
|
|
||||||
let warned = false;
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
if (!warned) {
|
|
||||||
warned = true;
|
|
||||||
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Colors.
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.colors = [
|
|
||||||
'#0000CC',
|
|
||||||
'#0000FF',
|
|
||||||
'#0033CC',
|
|
||||||
'#0033FF',
|
|
||||||
'#0066CC',
|
|
||||||
'#0066FF',
|
|
||||||
'#0099CC',
|
|
||||||
'#0099FF',
|
|
||||||
'#00CC00',
|
|
||||||
'#00CC33',
|
|
||||||
'#00CC66',
|
|
||||||
'#00CC99',
|
|
||||||
'#00CCCC',
|
|
||||||
'#00CCFF',
|
|
||||||
'#3300CC',
|
|
||||||
'#3300FF',
|
|
||||||
'#3333CC',
|
|
||||||
'#3333FF',
|
|
||||||
'#3366CC',
|
|
||||||
'#3366FF',
|
|
||||||
'#3399CC',
|
|
||||||
'#3399FF',
|
|
||||||
'#33CC00',
|
|
||||||
'#33CC33',
|
|
||||||
'#33CC66',
|
|
||||||
'#33CC99',
|
|
||||||
'#33CCCC',
|
|
||||||
'#33CCFF',
|
|
||||||
'#6600CC',
|
|
||||||
'#6600FF',
|
|
||||||
'#6633CC',
|
|
||||||
'#6633FF',
|
|
||||||
'#66CC00',
|
|
||||||
'#66CC33',
|
|
||||||
'#9900CC',
|
|
||||||
'#9900FF',
|
|
||||||
'#9933CC',
|
|
||||||
'#9933FF',
|
|
||||||
'#99CC00',
|
|
||||||
'#99CC33',
|
|
||||||
'#CC0000',
|
|
||||||
'#CC0033',
|
|
||||||
'#CC0066',
|
|
||||||
'#CC0099',
|
|
||||||
'#CC00CC',
|
|
||||||
'#CC00FF',
|
|
||||||
'#CC3300',
|
|
||||||
'#CC3333',
|
|
||||||
'#CC3366',
|
|
||||||
'#CC3399',
|
|
||||||
'#CC33CC',
|
|
||||||
'#CC33FF',
|
|
||||||
'#CC6600',
|
|
||||||
'#CC6633',
|
|
||||||
'#CC9900',
|
|
||||||
'#CC9933',
|
|
||||||
'#CCCC00',
|
|
||||||
'#CCCC33',
|
|
||||||
'#FF0000',
|
|
||||||
'#FF0033',
|
|
||||||
'#FF0066',
|
|
||||||
'#FF0099',
|
|
||||||
'#FF00CC',
|
|
||||||
'#FF00FF',
|
|
||||||
'#FF3300',
|
|
||||||
'#FF3333',
|
|
||||||
'#FF3366',
|
|
||||||
'#FF3399',
|
|
||||||
'#FF33CC',
|
|
||||||
'#FF33FF',
|
|
||||||
'#FF6600',
|
|
||||||
'#FF6633',
|
|
||||||
'#FF9900',
|
|
||||||
'#FF9933',
|
|
||||||
'#FFCC00',
|
|
||||||
'#FFCC33'
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
|
||||||
* and the Firebug extension (any Firefox version) are known
|
|
||||||
* to support "%c" CSS customizations.
|
|
||||||
*
|
|
||||||
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
|
||||||
*/
|
|
||||||
|
|
||||||
// eslint-disable-next-line complexity
|
|
||||||
function useColors() {
|
|
||||||
// NB: In an Electron preload script, document will be defined but not fully
|
|
||||||
// initialized. Since we know we're in Chrome, we'll just detect this case
|
|
||||||
// explicitly
|
|
||||||
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Internet Explorer and Edge do not support colors.
|
|
||||||
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
|
||||||
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
|
||||||
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
|
||||||
// Is firebug? http://stackoverflow.com/a/398120/376773
|
|
||||||
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
|
||||||
// Is firefox >= v31?
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
||||||
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
|
||||||
// Double check webkit in userAgent just in case we are in a worker
|
|
||||||
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Colorize log arguments if enabled.
|
|
||||||
*
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
function formatArgs(args) {
|
|
||||||
args[0] = (this.useColors ? '%c' : '') +
|
|
||||||
this.namespace +
|
|
||||||
(this.useColors ? ' %c' : ' ') +
|
|
||||||
args[0] +
|
|
||||||
(this.useColors ? '%c ' : ' ') +
|
|
||||||
'+' + module.exports.humanize(this.diff);
|
|
||||||
|
|
||||||
if (!this.useColors) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const c = 'color: ' + this.color;
|
|
||||||
args.splice(1, 0, c, 'color: inherit');
|
|
||||||
|
|
||||||
// The final "%c" is somewhat tricky, because there could be other
|
|
||||||
// arguments passed either before or after the %c, so we need to
|
|
||||||
// figure out the correct index to insert the CSS into
|
|
||||||
let index = 0;
|
|
||||||
let lastC = 0;
|
|
||||||
args[0].replace(/%[a-zA-Z%]/g, match => {
|
|
||||||
if (match === '%%') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
if (match === '%c') {
|
|
||||||
// We only are interested in the *last* %c
|
|
||||||
// (the user may have provided their own)
|
|
||||||
lastC = index;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
args.splice(lastC, 0, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invokes `console.debug()` when available.
|
|
||||||
* No-op when `console.debug` is not a "function".
|
|
||||||
* If `console.debug` is not available, falls back
|
|
||||||
* to `console.log`.
|
|
||||||
*
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
exports.log = console.debug || console.log || (() => {});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save `namespaces`.
|
|
||||||
*
|
|
||||||
* @param {String} namespaces
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
function save(namespaces) {
|
|
||||||
try {
|
|
||||||
if (namespaces) {
|
|
||||||
exports.storage.setItem('debug', namespaces);
|
|
||||||
} else {
|
|
||||||
exports.storage.removeItem('debug');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Swallow
|
|
||||||
// XXX (@Qix-) should we be logging these?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load `namespaces`.
|
|
||||||
*
|
|
||||||
* @return {String} returns the previously persisted debug modes
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
function load() {
|
|
||||||
let r;
|
|
||||||
try {
|
|
||||||
r = exports.storage.getItem('debug');
|
|
||||||
} catch (error) {
|
|
||||||
// Swallow
|
|
||||||
// XXX (@Qix-) should we be logging these?
|
|
||||||
}
|
|
||||||
|
|
||||||
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
|
||||||
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
|
||||||
r = process.env.DEBUG;
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Localstorage attempts to return the localstorage.
|
|
||||||
*
|
|
||||||
* This is necessary because safari throws
|
|
||||||
* when a user disables cookies/localstorage
|
|
||||||
* and you attempt to access it.
|
|
||||||
*
|
|
||||||
* @return {LocalStorage}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
function localstorage() {
|
|
||||||
try {
|
|
||||||
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
|
||||||
// The Browser also has localStorage in the global context.
|
|
||||||
return localStorage;
|
|
||||||
} catch (error) {
|
|
||||||
// Swallow
|
|
||||||
// XXX (@Qix-) should we be logging these?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = require('./common')(exports);
|
|
||||||
|
|
||||||
const {formatters} = module.exports;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
|
||||||
*/
|
|
||||||
|
|
||||||
formatters.j = function (v) {
|
|
||||||
try {
|
|
||||||
return JSON.stringify(v);
|
|
||||||
} catch (error) {
|
|
||||||
return '[UnexpectedJSONParseError]: ' + error.message;
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,274 +0,0 @@
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the common logic for both the Node.js and web browser
|
|
||||||
* implementations of `debug()`.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function setup(env) {
|
|
||||||
createDebug.debug = createDebug;
|
|
||||||
createDebug.default = createDebug;
|
|
||||||
createDebug.coerce = coerce;
|
|
||||||
createDebug.disable = disable;
|
|
||||||
createDebug.enable = enable;
|
|
||||||
createDebug.enabled = enabled;
|
|
||||||
createDebug.humanize = require('ms');
|
|
||||||
createDebug.destroy = destroy;
|
|
||||||
|
|
||||||
Object.keys(env).forEach(key => {
|
|
||||||
createDebug[key] = env[key];
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The currently active debug mode names, and names to skip.
|
|
||||||
*/
|
|
||||||
|
|
||||||
createDebug.names = [];
|
|
||||||
createDebug.skips = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map of special "%n" handling functions, for the debug "format" argument.
|
|
||||||
*
|
|
||||||
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
|
||||||
*/
|
|
||||||
createDebug.formatters = {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Selects a color for a debug namespace
|
|
||||||
* @param {String} namespace The namespace string for the debug instance to be colored
|
|
||||||
* @return {Number|String} An ANSI color code for the given namespace
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
function selectColor(namespace) {
|
|
||||||
let hash = 0;
|
|
||||||
|
|
||||||
for (let i = 0; i < namespace.length; i++) {
|
|
||||||
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
|
||||||
hash |= 0; // Convert to 32bit integer
|
|
||||||
}
|
|
||||||
|
|
||||||
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
||||||
}
|
|
||||||
createDebug.selectColor = selectColor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a debugger with the given `namespace`.
|
|
||||||
*
|
|
||||||
* @param {String} namespace
|
|
||||||
* @return {Function}
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
function createDebug(namespace) {
|
|
||||||
let prevTime;
|
|
||||||
let enableOverride = null;
|
|
||||||
let namespacesCache;
|
|
||||||
let enabledCache;
|
|
||||||
|
|
||||||
function debug(...args) {
|
|
||||||
// Disabled?
|
|
||||||
if (!debug.enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const self = debug;
|
|
||||||
|
|
||||||
// Set `diff` timestamp
|
|
||||||
const curr = Number(new Date());
|
|
||||||
const ms = curr - (prevTime || curr);
|
|
||||||
self.diff = ms;
|
|
||||||
self.prev = prevTime;
|
|
||||||
self.curr = curr;
|
|
||||||
prevTime = curr;
|
|
||||||
|
|
||||||
args[0] = createDebug.coerce(args[0]);
|
|
||||||
|
|
||||||
if (typeof args[0] !== 'string') {
|
|
||||||
// Anything else let's inspect with %O
|
|
||||||
args.unshift('%O');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply any `formatters` transformations
|
|
||||||
let index = 0;
|
|
||||||
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
||||||
// If we encounter an escaped % then don't increase the array index
|
|
||||||
if (match === '%%') {
|
|
||||||
return '%';
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
const formatter = createDebug.formatters[format];
|
|
||||||
if (typeof formatter === 'function') {
|
|
||||||
const val = args[index];
|
|
||||||
match = formatter.call(self, val);
|
|
||||||
|
|
||||||
// Now we need to remove `args[index]` since it's inlined in the `format`
|
|
||||||
args.splice(index, 1);
|
|
||||||
index--;
|
|
||||||
}
|
|
||||||
return match;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Apply env-specific formatting (colors, etc.)
|
|
||||||
createDebug.formatArgs.call(self, args);
|
|
||||||
|
|
||||||
const logFn = self.log || createDebug.log;
|
|
||||||
logFn.apply(self, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
debug.namespace = namespace;
|
|
||||||
debug.useColors = createDebug.useColors();
|
|
||||||
debug.color = createDebug.selectColor(namespace);
|
|
||||||
debug.extend = extend;
|
|
||||||
debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
|
|
||||||
|
|
||||||
Object.defineProperty(debug, 'enabled', {
|
|
||||||
enumerable: true,
|
|
||||||
configurable: false,
|
|
||||||
get: () => {
|
|
||||||
if (enableOverride !== null) {
|
|
||||||
return enableOverride;
|
|
||||||
}
|
|
||||||
if (namespacesCache !== createDebug.namespaces) {
|
|
||||||
namespacesCache = createDebug.namespaces;
|
|
||||||
enabledCache = createDebug.enabled(namespace);
|
|
||||||
}
|
|
||||||
|
|
||||||
return enabledCache;
|
|
||||||
},
|
|
||||||
set: v => {
|
|
||||||
enableOverride = v;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Env-specific initialization logic for debug instances
|
|
||||||
if (typeof createDebug.init === 'function') {
|
|
||||||
createDebug.init(debug);
|
|
||||||
}
|
|
||||||
|
|
||||||
return debug;
|
|
||||||
}
|
|
||||||
|
|
||||||
function extend(namespace, delimiter) {
|
|
||||||
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
|
||||||
newDebug.log = this.log;
|
|
||||||
return newDebug;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables a debug mode by namespaces. This can include modes
|
|
||||||
* separated by a colon and wildcards.
|
|
||||||
*
|
|
||||||
* @param {String} namespaces
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
function enable(namespaces) {
|
|
||||||
createDebug.save(namespaces);
|
|
||||||
createDebug.namespaces = namespaces;
|
|
||||||
|
|
||||||
createDebug.names = [];
|
|
||||||
createDebug.skips = [];
|
|
||||||
|
|
||||||
let i;
|
|
||||||
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
|
||||||
const len = split.length;
|
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
if (!split[i]) {
|
|
||||||
// ignore empty strings
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespaces = split[i].replace(/\*/g, '.*?');
|
|
||||||
|
|
||||||
if (namespaces[0] === '-') {
|
|
||||||
createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
|
|
||||||
} else {
|
|
||||||
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disable debug output.
|
|
||||||
*
|
|
||||||
* @return {String} namespaces
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
function disable() {
|
|
||||||
const namespaces = [
|
|
||||||
...createDebug.names.map(toNamespace),
|
|
||||||
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
|
|
||||||
].join(',');
|
|
||||||
createDebug.enable('');
|
|
||||||
return namespaces;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the given mode name is enabled, false otherwise.
|
|
||||||
*
|
|
||||||
* @param {String} name
|
|
||||||
* @return {Boolean}
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
function enabled(name) {
|
|
||||||
if (name[name.length - 1] === '*') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let i;
|
|
||||||
let len;
|
|
||||||
|
|
||||||
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
|
||||||
if (createDebug.skips[i].test(name)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
|
||||||
if (createDebug.names[i].test(name)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert regexp to namespace
|
|
||||||
*
|
|
||||||
* @param {RegExp} regxep
|
|
||||||
* @return {String} namespace
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
function toNamespace(regexp) {
|
|
||||||
return regexp.toString()
|
|
||||||
.substring(2, regexp.toString().length - 2)
|
|
||||||
.replace(/\.\*\?$/, '*');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Coerce `val`.
|
|
||||||
*
|
|
||||||
* @param {Mixed} val
|
|
||||||
* @return {Mixed}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
function coerce(val) {
|
|
||||||
if (val instanceof Error) {
|
|
||||||
return val.stack || val.message;
|
|
||||||
}
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* XXX DO NOT USE. This is a temporary stub function.
|
|
||||||
* XXX It WILL be removed in the next major release.
|
|
||||||
*/
|
|
||||||
function destroy() {
|
|
||||||
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
||||||
}
|
|
||||||
|
|
||||||
createDebug.enable(createDebug.load());
|
|
||||||
|
|
||||||
return createDebug;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = setup;
|
|
|
@ -1,10 +0,0 @@
|
||||||
/**
|
|
||||||
* Detect Electron renderer / nwjs process, which is node, but we should
|
|
||||||
* treat as a browser.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
|
|
||||||
module.exports = require('./browser.js');
|
|
||||||
} else {
|
|
||||||
module.exports = require('./node.js');
|
|
||||||
}
|
|
|
@ -1,263 +0,0 @@
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const tty = require('tty');
|
|
||||||
const util = require('util');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the Node.js implementation of `debug()`.
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.init = init;
|
|
||||||
exports.log = log;
|
|
||||||
exports.formatArgs = formatArgs;
|
|
||||||
exports.save = save;
|
|
||||||
exports.load = load;
|
|
||||||
exports.useColors = useColors;
|
|
||||||
exports.destroy = util.deprecate(
|
|
||||||
() => {},
|
|
||||||
'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Colors.
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.colors = [6, 2, 3, 4, 5, 1];
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
|
|
||||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
||||||
const supportsColor = require('supports-color');
|
|
||||||
|
|
||||||
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
|
||||||
exports.colors = [
|
|
||||||
20,
|
|
||||||
21,
|
|
||||||
26,
|
|
||||||
27,
|
|
||||||
32,
|
|
||||||
33,
|
|
||||||
38,
|
|
||||||
39,
|
|
||||||
40,
|
|
||||||
41,
|
|
||||||
42,
|
|
||||||
43,
|
|
||||||
44,
|
|
||||||
45,
|
|
||||||
56,
|
|
||||||
57,
|
|
||||||
62,
|
|
||||||
63,
|
|
||||||
68,
|
|
||||||
69,
|
|
||||||
74,
|
|
||||||
75,
|
|
||||||
76,
|
|
||||||
77,
|
|
||||||
78,
|
|
||||||
79,
|
|
||||||
80,
|
|
||||||
81,
|
|
||||||
92,
|
|
||||||
93,
|
|
||||||
98,
|
|
||||||
99,
|
|
||||||
112,
|
|
||||||
113,
|
|
||||||
128,
|
|
||||||
129,
|
|
||||||
134,
|
|
||||||
135,
|
|
||||||
148,
|
|
||||||
149,
|
|
||||||
160,
|
|
||||||
161,
|
|
||||||
162,
|
|
||||||
163,
|
|
||||||
164,
|
|
||||||
165,
|
|
||||||
166,
|
|
||||||
167,
|
|
||||||
168,
|
|
||||||
169,
|
|
||||||
170,
|
|
||||||
171,
|
|
||||||
172,
|
|
||||||
173,
|
|
||||||
178,
|
|
||||||
179,
|
|
||||||
184,
|
|
||||||
185,
|
|
||||||
196,
|
|
||||||
197,
|
|
||||||
198,
|
|
||||||
199,
|
|
||||||
200,
|
|
||||||
201,
|
|
||||||
202,
|
|
||||||
203,
|
|
||||||
204,
|
|
||||||
205,
|
|
||||||
206,
|
|
||||||
207,
|
|
||||||
208,
|
|
||||||
209,
|
|
||||||
214,
|
|
||||||
215,
|
|
||||||
220,
|
|
||||||
221
|
|
||||||
];
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Swallow - we only care if `supports-color` is available; it doesn't have to be.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build up the default `inspectOpts` object from the environment variables.
|
|
||||||
*
|
|
||||||
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.inspectOpts = Object.keys(process.env).filter(key => {
|
|
||||||
return /^debug_/i.test(key);
|
|
||||||
}).reduce((obj, key) => {
|
|
||||||
// Camel-case
|
|
||||||
const prop = key
|
|
||||||
.substring(6)
|
|
||||||
.toLowerCase()
|
|
||||||
.replace(/_([a-z])/g, (_, k) => {
|
|
||||||
return k.toUpperCase();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Coerce string value into JS value
|
|
||||||
let val = process.env[key];
|
|
||||||
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
|
||||||
val = true;
|
|
||||||
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
|
||||||
val = false;
|
|
||||||
} else if (val === 'null') {
|
|
||||||
val = null;
|
|
||||||
} else {
|
|
||||||
val = Number(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
obj[prop] = val;
|
|
||||||
return obj;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is stdout a TTY? Colored output is enabled when `true`.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function useColors() {
|
|
||||||
return 'colors' in exports.inspectOpts ?
|
|
||||||
Boolean(exports.inspectOpts.colors) :
|
|
||||||
tty.isatty(process.stderr.fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds ANSI color escape codes if enabled.
|
|
||||||
*
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
function formatArgs(args) {
|
|
||||||
const {namespace: name, useColors} = this;
|
|
||||||
|
|
||||||
if (useColors) {
|
|
||||||
const c = this.color;
|
|
||||||
const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
|
|
||||||
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
|
|
||||||
|
|
||||||
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
|
|
||||||
args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
|
|
||||||
} else {
|
|
||||||
args[0] = getDate() + name + ' ' + args[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDate() {
|
|
||||||
if (exports.inspectOpts.hideDate) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
return new Date().toISOString() + ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invokes `util.formatWithOptions()` with the specified arguments and writes to stderr.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function log(...args) {
|
|
||||||
return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + '\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save `namespaces`.
|
|
||||||
*
|
|
||||||
* @param {String} namespaces
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
function save(namespaces) {
|
|
||||||
if (namespaces) {
|
|
||||||
process.env.DEBUG = namespaces;
|
|
||||||
} else {
|
|
||||||
// If you set a process.env field to null or undefined, it gets cast to the
|
|
||||||
// string 'null' or 'undefined'. Just delete instead.
|
|
||||||
delete process.env.DEBUG;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load `namespaces`.
|
|
||||||
*
|
|
||||||
* @return {String} returns the previously persisted debug modes
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
function load() {
|
|
||||||
return process.env.DEBUG;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Init logic for `debug` instances.
|
|
||||||
*
|
|
||||||
* Create a new `inspectOpts` object in case `useColors` is set
|
|
||||||
* differently for a particular `debug` instance.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function init(debug) {
|
|
||||||
debug.inspectOpts = {};
|
|
||||||
|
|
||||||
const keys = Object.keys(exports.inspectOpts);
|
|
||||||
for (let i = 0; i < keys.length; i++) {
|
|
||||||
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = require('./common')(exports);
|
|
||||||
|
|
||||||
const {formatters} = module.exports;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map %o to `util.inspect()`, all on a single line.
|
|
||||||
*/
|
|
||||||
|
|
||||||
formatters.o = function (v) {
|
|
||||||
this.inspectOpts.colors = this.useColors;
|
|
||||||
return util.inspect(v, this.inspectOpts)
|
|
||||||
.split('\n')
|
|
||||||
.map(str => str.trim())
|
|
||||||
.join(' ');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
formatters.O = function (v) {
|
|
||||||
this.inspectOpts.colors = this.useColors;
|
|
||||||
return util.inspect(v, this.inspectOpts);
|
|
||||||
};
|
|
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2014-present, Jon Schlinkert.
|
|
||||||
|
|
||||||
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,237 +0,0 @@
|
||||||
# fill-range [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/fill-range.svg?style=flat)](https://www.npmjs.com/package/fill-range) [![NPM monthly downloads](https://img.shields.io/npm/dm/fill-range.svg?style=flat)](https://npmjs.org/package/fill-range) [![NPM total downloads](https://img.shields.io/npm/dt/fill-range.svg?style=flat)](https://npmjs.org/package/fill-range) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/fill-range.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/fill-range)
|
|
||||||
|
|
||||||
> Fill in a range of numbers or letters, optionally passing an increment or `step` to use, or create a regex-compatible range with `options.toRegex`
|
|
||||||
|
|
||||||
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
Install with [npm](https://www.npmjs.com/):
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install --save fill-range
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Expands numbers and letters, optionally using a `step` as the last argument. _(Numbers may be defined as JavaScript numbers or strings)_.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const fill = require('fill-range');
|
|
||||||
// fill(from, to[, step, options]);
|
|
||||||
|
|
||||||
console.log(fill('1', '10')); //=> ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
|
|
||||||
console.log(fill('1', '10', { toRegex: true })); //=> [1-9]|10
|
|
||||||
```
|
|
||||||
|
|
||||||
**Params**
|
|
||||||
|
|
||||||
* `from`: **{String|Number}** the number or letter to start with
|
|
||||||
* `to`: **{String|Number}** the number or letter to end with
|
|
||||||
* `step`: **{String|Number|Object|Function}** Optionally pass a [step](#optionsstep) to use.
|
|
||||||
* `options`: **{Object|Function}**: See all available [options](#options)
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
By default, an array of values is returned.
|
|
||||||
|
|
||||||
**Alphabetical ranges**
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(fill('a', 'e')); //=> ['a', 'b', 'c', 'd', 'e']
|
|
||||||
console.log(fill('A', 'E')); //=> [ 'A', 'B', 'C', 'D', 'E' ]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Numerical ranges**
|
|
||||||
|
|
||||||
Numbers can be defined as actual numbers or strings.
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ]
|
|
||||||
console.log(fill('1', '5')); //=> [ 1, 2, 3, 4, 5 ]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Negative ranges**
|
|
||||||
|
|
||||||
Numbers can be defined as actual numbers or strings.
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(fill('-5', '-1')); //=> [ '-5', '-4', '-3', '-2', '-1' ]
|
|
||||||
console.log(fill('-5', '5')); //=> [ '-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5' ]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Steps (increments)**
|
|
||||||
|
|
||||||
```js
|
|
||||||
// numerical ranges with increments
|
|
||||||
console.log(fill('0', '25', 4)); //=> [ '0', '4', '8', '12', '16', '20', '24' ]
|
|
||||||
console.log(fill('0', '25', 5)); //=> [ '0', '5', '10', '15', '20', '25' ]
|
|
||||||
console.log(fill('0', '25', 6)); //=> [ '0', '6', '12', '18', '24' ]
|
|
||||||
|
|
||||||
// alphabetical ranges with increments
|
|
||||||
console.log(fill('a', 'z', 4)); //=> [ 'a', 'e', 'i', 'm', 'q', 'u', 'y' ]
|
|
||||||
console.log(fill('a', 'z', 5)); //=> [ 'a', 'f', 'k', 'p', 'u', 'z' ]
|
|
||||||
console.log(fill('a', 'z', 6)); //=> [ 'a', 'g', 'm', 's', 'y' ]
|
|
||||||
```
|
|
||||||
|
|
||||||
## Options
|
|
||||||
|
|
||||||
### options.step
|
|
||||||
|
|
||||||
**Type**: `number` (formatted as a string or number)
|
|
||||||
|
|
||||||
**Default**: `undefined`
|
|
||||||
|
|
||||||
**Description**: The increment to use for the range. Can be used with letters or numbers.
|
|
||||||
|
|
||||||
**Example(s)**
|
|
||||||
|
|
||||||
```js
|
|
||||||
// numbers
|
|
||||||
console.log(fill('1', '10', 2)); //=> [ '1', '3', '5', '7', '9' ]
|
|
||||||
console.log(fill('1', '10', 3)); //=> [ '1', '4', '7', '10' ]
|
|
||||||
console.log(fill('1', '10', 4)); //=> [ '1', '5', '9' ]
|
|
||||||
|
|
||||||
// letters
|
|
||||||
console.log(fill('a', 'z', 5)); //=> [ 'a', 'f', 'k', 'p', 'u', 'z' ]
|
|
||||||
console.log(fill('a', 'z', 7)); //=> [ 'a', 'h', 'o', 'v' ]
|
|
||||||
console.log(fill('a', 'z', 9)); //=> [ 'a', 'j', 's' ]
|
|
||||||
```
|
|
||||||
|
|
||||||
### options.strictRanges
|
|
||||||
|
|
||||||
**Type**: `boolean`
|
|
||||||
|
|
||||||
**Default**: `false`
|
|
||||||
|
|
||||||
**Description**: By default, `null` is returned when an invalid range is passed. Enable this option to throw a `RangeError` on invalid ranges.
|
|
||||||
|
|
||||||
**Example(s)**
|
|
||||||
|
|
||||||
The following are all invalid:
|
|
||||||
|
|
||||||
```js
|
|
||||||
fill('1.1', '2'); // decimals not supported in ranges
|
|
||||||
fill('a', '2'); // incompatible range values
|
|
||||||
fill(1, 10, 'foo'); // invalid "step" argument
|
|
||||||
```
|
|
||||||
|
|
||||||
### options.stringify
|
|
||||||
|
|
||||||
**Type**: `boolean`
|
|
||||||
|
|
||||||
**Default**: `undefined`
|
|
||||||
|
|
||||||
**Description**: Cast all returned values to strings. By default, integers are returned as numbers.
|
|
||||||
|
|
||||||
**Example(s)**
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ]
|
|
||||||
console.log(fill(1, 5, { stringify: true })); //=> [ '1', '2', '3', '4', '5' ]
|
|
||||||
```
|
|
||||||
|
|
||||||
### options.toRegex
|
|
||||||
|
|
||||||
**Type**: `boolean`
|
|
||||||
|
|
||||||
**Default**: `undefined`
|
|
||||||
|
|
||||||
**Description**: Create a regex-compatible source string, instead of expanding values to an array.
|
|
||||||
|
|
||||||
**Example(s)**
|
|
||||||
|
|
||||||
```js
|
|
||||||
// alphabetical range
|
|
||||||
console.log(fill('a', 'e', { toRegex: true })); //=> '[a-e]'
|
|
||||||
// alphabetical with step
|
|
||||||
console.log(fill('a', 'z', 3, { toRegex: true })); //=> 'a|d|g|j|m|p|s|v|y'
|
|
||||||
// numerical range
|
|
||||||
console.log(fill('1', '100', { toRegex: true })); //=> '[1-9]|[1-9][0-9]|100'
|
|
||||||
// numerical range with zero padding
|
|
||||||
console.log(fill('000001', '100000', { toRegex: true }));
|
|
||||||
//=> '0{5}[1-9]|0{4}[1-9][0-9]|0{3}[1-9][0-9]{2}|0{2}[1-9][0-9]{3}|0[1-9][0-9]{4}|100000'
|
|
||||||
```
|
|
||||||
|
|
||||||
### options.transform
|
|
||||||
|
|
||||||
**Type**: `function`
|
|
||||||
|
|
||||||
**Default**: `undefined`
|
|
||||||
|
|
||||||
**Description**: Customize each value in the returned array (or [string](#optionstoRegex)). _(you can also pass this function as the last argument to `fill()`)_.
|
|
||||||
|
|
||||||
**Example(s)**
|
|
||||||
|
|
||||||
```js
|
|
||||||
// add zero padding
|
|
||||||
console.log(fill(1, 5, value => String(value).padStart(4, '0')));
|
|
||||||
//=> ['0001', '0002', '0003', '0004', '0005']
|
|
||||||
```
|
|
||||||
|
|
||||||
## About
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary><strong>Contributing</strong></summary>
|
|
||||||
|
|
||||||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary><strong>Running Tests</strong></summary>
|
|
||||||
|
|
||||||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install && npm test
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary><strong>Building docs</strong></summary>
|
|
||||||
|
|
||||||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
|
||||||
|
|
||||||
To generate the readme, run the following command:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install -g verbose/verb#dev verb-generate-readme && verb
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### Contributors
|
|
||||||
|
|
||||||
| **Commits** | **Contributor** |
|
|
||||||
| --- | --- |
|
|
||||||
| 116 | [jonschlinkert](https://github.com/jonschlinkert) |
|
|
||||||
| 4 | [paulmillr](https://github.com/paulmillr) |
|
|
||||||
| 2 | [realityking](https://github.com/realityking) |
|
|
||||||
| 2 | [bluelovers](https://github.com/bluelovers) |
|
|
||||||
| 1 | [edorivai](https://github.com/edorivai) |
|
|
||||||
| 1 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |
|
|
||||||
|
|
||||||
### Author
|
|
||||||
|
|
||||||
**Jon Schlinkert**
|
|
||||||
|
|
||||||
* [GitHub Profile](https://github.com/jonschlinkert)
|
|
||||||
* [Twitter Profile](https://twitter.com/jonschlinkert)
|
|
||||||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
|
||||||
|
|
||||||
Please consider supporting me on Patreon, or [start your own Patreon page](https://patreon.com/invite/bxpbvm)!
|
|
||||||
|
|
||||||
<a href="https://www.patreon.com/jonschlinkert">
|
|
||||||
<img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" height="50">
|
|
||||||
</a>
|
|
||||||
|
|
||||||
### License
|
|
||||||
|
|
||||||
Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
|
|
||||||
Released under the [MIT License](LICENSE).
|
|
||||||
|
|
||||||
***
|
|
||||||
|
|
||||||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 08, 2019._
|
|
|
@ -1,248 +0,0 @@
|
||||||
/*!
|
|
||||||
* fill-range <https://github.com/jonschlinkert/fill-range>
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014-present, Jon Schlinkert.
|
|
||||||
* Licensed under the MIT License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const util = require('util');
|
|
||||||
const toRegexRange = require('to-regex-range');
|
|
||||||
|
|
||||||
const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
|
|
||||||
|
|
||||||
const transform = toNumber => {
|
|
||||||
return value => toNumber === true ? Number(value) : String(value);
|
|
||||||
};
|
|
||||||
|
|
||||||
const isValidValue = value => {
|
|
||||||
return typeof value === 'number' || (typeof value === 'string' && value !== '');
|
|
||||||
};
|
|
||||||
|
|
||||||
const isNumber = num => Number.isInteger(+num);
|
|
||||||
|
|
||||||
const zeros = input => {
|
|
||||||
let value = `${input}`;
|
|
||||||
let index = -1;
|
|
||||||
if (value[0] === '-') value = value.slice(1);
|
|
||||||
if (value === '0') return false;
|
|
||||||
while (value[++index] === '0');
|
|
||||||
return index > 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
const stringify = (start, end, options) => {
|
|
||||||
if (typeof start === 'string' || typeof end === 'string') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return options.stringify === true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const pad = (input, maxLength, toNumber) => {
|
|
||||||
if (maxLength > 0) {
|
|
||||||
let dash = input[0] === '-' ? '-' : '';
|
|
||||||
if (dash) input = input.slice(1);
|
|
||||||
input = (dash + input.padStart(dash ? maxLength - 1 : maxLength, '0'));
|
|
||||||
}
|
|
||||||
if (toNumber === false) {
|
|
||||||
return String(input);
|
|
||||||
}
|
|
||||||
return input;
|
|
||||||
};
|
|
||||||
|
|
||||||
const toMaxLen = (input, maxLength) => {
|
|
||||||
let negative = input[0] === '-' ? '-' : '';
|
|
||||||
if (negative) {
|
|
||||||
input = input.slice(1);
|
|
||||||
maxLength--;
|
|
||||||
}
|
|
||||||
while (input.length < maxLength) input = '0' + input;
|
|
||||||
return negative ? ('-' + input) : input;
|
|
||||||
};
|
|
||||||
|
|
||||||
const toSequence = (parts, options, maxLen) => {
|
|
||||||
parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
||||||
parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
||||||
|
|
||||||
let prefix = options.capture ? '' : '?:';
|
|
||||||
let positives = '';
|
|
||||||
let negatives = '';
|
|
||||||
let result;
|
|
||||||
|
|
||||||
if (parts.positives.length) {
|
|
||||||
positives = parts.positives.map(v => toMaxLen(String(v), maxLen)).join('|');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parts.negatives.length) {
|
|
||||||
negatives = `-(${prefix}${parts.negatives.map(v => toMaxLen(String(v), maxLen)).join('|')})`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (positives && negatives) {
|
|
||||||
result = `${positives}|${negatives}`;
|
|
||||||
} else {
|
|
||||||
result = positives || negatives;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.wrap) {
|
|
||||||
return `(${prefix}${result})`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
const toRange = (a, b, isNumbers, options) => {
|
|
||||||
if (isNumbers) {
|
|
||||||
return toRegexRange(a, b, { wrap: false, ...options });
|
|
||||||
}
|
|
||||||
|
|
||||||
let start = String.fromCharCode(a);
|
|
||||||
if (a === b) return start;
|
|
||||||
|
|
||||||
let stop = String.fromCharCode(b);
|
|
||||||
return `[${start}-${stop}]`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const toRegex = (start, end, options) => {
|
|
||||||
if (Array.isArray(start)) {
|
|
||||||
let wrap = options.wrap === true;
|
|
||||||
let prefix = options.capture ? '' : '?:';
|
|
||||||
return wrap ? `(${prefix}${start.join('|')})` : start.join('|');
|
|
||||||
}
|
|
||||||
return toRegexRange(start, end, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
const rangeError = (...args) => {
|
|
||||||
return new RangeError('Invalid range arguments: ' + util.inspect(...args));
|
|
||||||
};
|
|
||||||
|
|
||||||
const invalidRange = (start, end, options) => {
|
|
||||||
if (options.strictRanges === true) throw rangeError([start, end]);
|
|
||||||
return [];
|
|
||||||
};
|
|
||||||
|
|
||||||
const invalidStep = (step, options) => {
|
|
||||||
if (options.strictRanges === true) {
|
|
||||||
throw new TypeError(`Expected step "${step}" to be a number`);
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
};
|
|
||||||
|
|
||||||
const fillNumbers = (start, end, step = 1, options = {}) => {
|
|
||||||
let a = Number(start);
|
|
||||||
let b = Number(end);
|
|
||||||
|
|
||||||
if (!Number.isInteger(a) || !Number.isInteger(b)) {
|
|
||||||
if (options.strictRanges === true) throw rangeError([start, end]);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// fix negative zero
|
|
||||||
if (a === 0) a = 0;
|
|
||||||
if (b === 0) b = 0;
|
|
||||||
|
|
||||||
let descending = a > b;
|
|
||||||
let startString = String(start);
|
|
||||||
let endString = String(end);
|
|
||||||
let stepString = String(step);
|
|
||||||
step = Math.max(Math.abs(step), 1);
|
|
||||||
|
|
||||||
let padded = zeros(startString) || zeros(endString) || zeros(stepString);
|
|
||||||
let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0;
|
|
||||||
let toNumber = padded === false && stringify(start, end, options) === false;
|
|
||||||
let format = options.transform || transform(toNumber);
|
|
||||||
|
|
||||||
if (options.toRegex && step === 1) {
|
|
||||||
return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
let parts = { negatives: [], positives: [] };
|
|
||||||
let push = num => parts[num < 0 ? 'negatives' : 'positives'].push(Math.abs(num));
|
|
||||||
let range = [];
|
|
||||||
let index = 0;
|
|
||||||
|
|
||||||
while (descending ? a >= b : a <= b) {
|
|
||||||
if (options.toRegex === true && step > 1) {
|
|
||||||
push(a);
|
|
||||||
} else {
|
|
||||||
range.push(pad(format(a, index), maxLen, toNumber));
|
|
||||||
}
|
|
||||||
a = descending ? a - step : a + step;
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.toRegex === true) {
|
|
||||||
return step > 1
|
|
||||||
? toSequence(parts, options, maxLen)
|
|
||||||
: toRegex(range, null, { wrap: false, ...options });
|
|
||||||
}
|
|
||||||
|
|
||||||
return range;
|
|
||||||
};
|
|
||||||
|
|
||||||
const fillLetters = (start, end, step = 1, options = {}) => {
|
|
||||||
if ((!isNumber(start) && start.length > 1) || (!isNumber(end) && end.length > 1)) {
|
|
||||||
return invalidRange(start, end, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
let format = options.transform || (val => String.fromCharCode(val));
|
|
||||||
let a = `${start}`.charCodeAt(0);
|
|
||||||
let b = `${end}`.charCodeAt(0);
|
|
||||||
|
|
||||||
let descending = a > b;
|
|
||||||
let min = Math.min(a, b);
|
|
||||||
let max = Math.max(a, b);
|
|
||||||
|
|
||||||
if (options.toRegex && step === 1) {
|
|
||||||
return toRange(min, max, false, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
let range = [];
|
|
||||||
let index = 0;
|
|
||||||
|
|
||||||
while (descending ? a >= b : a <= b) {
|
|
||||||
range.push(format(a, index));
|
|
||||||
a = descending ? a - step : a + step;
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.toRegex === true) {
|
|
||||||
return toRegex(range, null, { wrap: false, options });
|
|
||||||
}
|
|
||||||
|
|
||||||
return range;
|
|
||||||
};
|
|
||||||
|
|
||||||
const fill = (start, end, step, options = {}) => {
|
|
||||||
if (end == null && isValidValue(start)) {
|
|
||||||
return [start];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isValidValue(start) || !isValidValue(end)) {
|
|
||||||
return invalidRange(start, end, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof step === 'function') {
|
|
||||||
return fill(start, end, 1, { transform: step });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isObject(step)) {
|
|
||||||
return fill(start, end, 0, step);
|
|
||||||
}
|
|
||||||
|
|
||||||
let opts = { ...options };
|
|
||||||
if (opts.capture === true) opts.wrap = true;
|
|
||||||
step = step || opts.step || 1;
|
|
||||||
|
|
||||||
if (!isNumber(step)) {
|
|
||||||
if (step != null && !isObject(step)) return invalidStep(step, opts);
|
|
||||||
return fill(start, end, 1, step);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNumber(start) && isNumber(end)) {
|
|
||||||
return fillNumbers(start, end, step, opts);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fillLetters(start, end, Math.max(Math.abs(step), 1), opts);
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = fill;
|
|
|
@ -1,74 +0,0 @@
|
||||||
{
|
|
||||||
"name": "fill-range",
|
|
||||||
"description": "Fill in a range of numbers or letters, optionally passing an increment or `step` to use, or create a regex-compatible range with `options.toRegex`",
|
|
||||||
"version": "7.1.1",
|
|
||||||
"homepage": "https://github.com/jonschlinkert/fill-range",
|
|
||||||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
|
|
||||||
"contributors": [
|
|
||||||
"Edo Rivai (edo.rivai.nl)",
|
|
||||||
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
|
|
||||||
"Paul Miller (paulmillr.com)",
|
|
||||||
"Rouven Weßling (www.rouvenwessling.de)",
|
|
||||||
"(https://github.com/wtgtybhertgeghgtwtg)"
|
|
||||||
],
|
|
||||||
"repository": "jonschlinkert/fill-range",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/jonschlinkert/fill-range/issues"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"files": [
|
|
||||||
"index.js"
|
|
||||||
],
|
|
||||||
"main": "index.js",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"lint": "eslint --cache --cache-location node_modules/.cache/.eslintcache --report-unused-disable-directives --ignore-path .gitignore .",
|
|
||||||
"mocha": "mocha --reporter dot",
|
|
||||||
"test": "npm run lint && npm run mocha",
|
|
||||||
"test:ci": "npm run test:cover",
|
|
||||||
"test:cover": "nyc npm run mocha"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"to-regex-range": "^5.0.1"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"gulp-format-md": "^2.0.0",
|
|
||||||
"mocha": "^6.1.1",
|
|
||||||
"nyc": "^15.1.0"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"alpha",
|
|
||||||
"alphabetical",
|
|
||||||
"array",
|
|
||||||
"bash",
|
|
||||||
"brace",
|
|
||||||
"expand",
|
|
||||||
"expansion",
|
|
||||||
"fill",
|
|
||||||
"glob",
|
|
||||||
"match",
|
|
||||||
"matches",
|
|
||||||
"matching",
|
|
||||||
"number",
|
|
||||||
"numerical",
|
|
||||||
"range",
|
|
||||||
"ranges",
|
|
||||||
"regex",
|
|
||||||
"sh"
|
|
||||||
],
|
|
||||||
"verb": {
|
|
||||||
"toc": false,
|
|
||||||
"layout": "default",
|
|
||||||
"tasks": [
|
|
||||||
"readme"
|
|
||||||
],
|
|
||||||
"plugins": [
|
|
||||||
"gulp-format-md"
|
|
||||||
],
|
|
||||||
"lint": {
|
|
||||||
"reflinks": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,110 +0,0 @@
|
||||||
### [5.1.2](https://github.com/gulpjs/glob-parent/compare/v5.1.1...v5.1.2) (2021-03-06)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* eliminate ReDoS ([#36](https://github.com/gulpjs/glob-parent/issues/36)) ([f923116](https://github.com/gulpjs/glob-parent/commit/f9231168b0041fea3f8f954b3cceb56269fc6366))
|
|
||||||
|
|
||||||
### [5.1.1](https://github.com/gulpjs/glob-parent/compare/v5.1.0...v5.1.1) (2021-01-27)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* unescape exclamation mark ([#26](https://github.com/gulpjs/glob-parent/issues/26)) ([a98874f](https://github.com/gulpjs/glob-parent/commit/a98874f1a59e407f4fb1beb0db4efa8392da60bb))
|
|
||||||
|
|
||||||
## [5.1.0](https://github.com/gulpjs/glob-parent/compare/v5.0.0...v5.1.0) (2021-01-27)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* add `flipBackslashes` option to disable auto conversion of slashes (closes [#24](https://github.com/gulpjs/glob-parent/issues/24)) ([#25](https://github.com/gulpjs/glob-parent/issues/25)) ([eecf91d](https://github.com/gulpjs/glob-parent/commit/eecf91d5e3834ed78aee39c4eaaae654d76b87b3))
|
|
||||||
|
|
||||||
## [5.0.0](https://github.com/gulpjs/glob-parent/compare/v4.0.0...v5.0.0) (2021-01-27)
|
|
||||||
|
|
||||||
|
|
||||||
### ⚠ BREAKING CHANGES
|
|
||||||
|
|
||||||
* Drop support for node <6 & bump dependencies
|
|
||||||
|
|
||||||
### Miscellaneous Chores
|
|
||||||
|
|
||||||
* Drop support for node <6 & bump dependencies ([896c0c0](https://github.com/gulpjs/glob-parent/commit/896c0c00b4e7362f60b96e7fc295ae929245255a))
|
|
||||||
|
|
||||||
## [4.0.0](https://github.com/gulpjs/glob-parent/compare/v3.1.0...v4.0.0) (2021-01-27)
|
|
||||||
|
|
||||||
|
|
||||||
### ⚠ BREAKING CHANGES
|
|
||||||
|
|
||||||
* question marks are valid path characters on Windows so avoid flagging as a glob when alone
|
|
||||||
* Update is-glob dependency
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* hoist regexps and strings for performance gains ([4a80667](https://github.com/gulpjs/glob-parent/commit/4a80667c69355c76a572a5892b0f133c8e1f457e))
|
|
||||||
* question marks are valid path characters on Windows so avoid flagging as a glob when alone ([2a551dd](https://github.com/gulpjs/glob-parent/commit/2a551dd0dc3235e78bf3c94843d4107072d17841))
|
|
||||||
* Update is-glob dependency ([e41fcd8](https://github.com/gulpjs/glob-parent/commit/e41fcd895d1f7bc617dba45c9d935a7949b9c281))
|
|
||||||
|
|
||||||
## [3.1.0](https://github.com/gulpjs/glob-parent/compare/v3.0.1...v3.1.0) (2021-01-27)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* allow basic win32 backslash use ([272afa5](https://github.com/gulpjs/glob-parent/commit/272afa5fd070fc0f796386a5993d4ee4a846988b))
|
|
||||||
* handle extglobs (parentheses) containing separators ([7db1bdb](https://github.com/gulpjs/glob-parent/commit/7db1bdb0756e55fd14619e8ce31aa31b17b117fd))
|
|
||||||
* new approach to braces/brackets handling ([8269bd8](https://github.com/gulpjs/glob-parent/commit/8269bd89290d99fac9395a354fb56fdcdb80f0be))
|
|
||||||
* pre-process braces/brackets sections ([9ef8a87](https://github.com/gulpjs/glob-parent/commit/9ef8a87f66b1a43d0591e7a8e4fc5a18415ee388))
|
|
||||||
* preserve escaped brace/bracket at end of string ([8cfb0ba](https://github.com/gulpjs/glob-parent/commit/8cfb0ba84202d51571340dcbaf61b79d16a26c76))
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* trailing escaped square brackets ([99ec9fe](https://github.com/gulpjs/glob-parent/commit/99ec9fecc60ee488ded20a94dd4f18b4f55c4ccf))
|
|
||||||
|
|
||||||
### [3.0.1](https://github.com/gulpjs/glob-parent/compare/v3.0.0...v3.0.1) (2021-01-27)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* use path-dirname ponyfill ([cdbea5f](https://github.com/gulpjs/glob-parent/commit/cdbea5f32a58a54e001a75ddd7c0fccd4776aacc))
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* unescape glob-escaped dirnames on output ([598c533](https://github.com/gulpjs/glob-parent/commit/598c533bdf49c1428bc063aa9b8db40c5a86b030))
|
|
||||||
|
|
||||||
## [3.0.0](https://github.com/gulpjs/glob-parent/compare/v2.0.0...v3.0.0) (2021-01-27)
|
|
||||||
|
|
||||||
|
|
||||||
### ⚠ BREAKING CHANGES
|
|
||||||
|
|
||||||
* update is-glob dependency
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* update is-glob dependency ([5c5f8ef](https://github.com/gulpjs/glob-parent/commit/5c5f8efcee362a8e7638cf8220666acd8784f6bd))
|
|
||||||
|
|
||||||
## [2.0.0](https://github.com/gulpjs/glob-parent/compare/v1.3.0...v2.0.0) (2021-01-27)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* move up to dirname regardless of glob characters ([f97fb83](https://github.com/gulpjs/glob-parent/commit/f97fb83be2e0a9fc8d3b760e789d2ecadd6aa0c2))
|
|
||||||
|
|
||||||
## [1.3.0](https://github.com/gulpjs/glob-parent/compare/v1.2.0...v1.3.0) (2021-01-27)
|
|
||||||
|
|
||||||
## [1.2.0](https://github.com/gulpjs/glob-parent/compare/v1.1.0...v1.2.0) (2021-01-27)
|
|
||||||
|
|
||||||
|
|
||||||
### Reverts
|
|
||||||
|
|
||||||
* feat: make regex test strings smaller ([dc80fa9](https://github.com/gulpjs/glob-parent/commit/dc80fa9658dca20549cfeba44bbd37d5246fcce0))
|
|
||||||
|
|
||||||
## [1.1.0](https://github.com/gulpjs/glob-parent/compare/v1.0.0...v1.1.0) (2021-01-27)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* make regex test strings smaller ([cd83220](https://github.com/gulpjs/glob-parent/commit/cd832208638f45169f986d80fcf66e401f35d233))
|
|
||||||
|
|
||||||
## 1.0.0 (2021-01-27)
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
The ISC License
|
|
||||||
|
|
||||||
Copyright (c) 2015, 2019 Elan Shanker
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
||||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
@ -1,137 +0,0 @@
|
||||||
<p align="center">
|
|
||||||
<a href="https://gulpjs.com">
|
|
||||||
<img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
# glob-parent
|
|
||||||
|
|
||||||
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Azure Pipelines Build Status][azure-pipelines-image]][azure-pipelines-url] [![Travis Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url]
|
|
||||||
|
|
||||||
Extract the non-magic parent path from a glob string.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```js
|
|
||||||
var globParent = require('glob-parent');
|
|
||||||
|
|
||||||
globParent('path/to/*.js'); // 'path/to'
|
|
||||||
globParent('/root/path/to/*.js'); // '/root/path/to'
|
|
||||||
globParent('/*.js'); // '/'
|
|
||||||
globParent('*.js'); // '.'
|
|
||||||
globParent('**/*.js'); // '.'
|
|
||||||
globParent('path/{to,from}'); // 'path'
|
|
||||||
globParent('path/!(to|from)'); // 'path'
|
|
||||||
globParent('path/?(to|from)'); // 'path'
|
|
||||||
globParent('path/+(to|from)'); // 'path'
|
|
||||||
globParent('path/*(to|from)'); // 'path'
|
|
||||||
globParent('path/@(to|from)'); // 'path'
|
|
||||||
globParent('path/**/*'); // 'path'
|
|
||||||
|
|
||||||
// if provided a non-glob path, returns the nearest dir
|
|
||||||
globParent('path/foo/bar.js'); // 'path/foo'
|
|
||||||
globParent('path/foo/'); // 'path/foo'
|
|
||||||
globParent('path/foo'); // 'path' (see issue #3 for details)
|
|
||||||
```
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
### `globParent(maybeGlobString, [options])`
|
|
||||||
|
|
||||||
Takes a string and returns the part of the path before the glob begins. Be aware of Escaping rules and Limitations below.
|
|
||||||
|
|
||||||
#### options
|
|
||||||
|
|
||||||
```js
|
|
||||||
{
|
|
||||||
// Disables the automatic conversion of slashes for Windows
|
|
||||||
flipBackslashes: true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Escaping
|
|
||||||
|
|
||||||
The following characters have special significance in glob patterns and must be escaped if you want them to be treated as regular path characters:
|
|
||||||
|
|
||||||
- `?` (question mark) unless used as a path segment alone
|
|
||||||
- `*` (asterisk)
|
|
||||||
- `|` (pipe)
|
|
||||||
- `(` (opening parenthesis)
|
|
||||||
- `)` (closing parenthesis)
|
|
||||||
- `{` (opening curly brace)
|
|
||||||
- `}` (closing curly brace)
|
|
||||||
- `[` (opening bracket)
|
|
||||||
- `]` (closing bracket)
|
|
||||||
|
|
||||||
**Example**
|
|
||||||
|
|
||||||
```js
|
|
||||||
globParent('foo/[bar]/') // 'foo'
|
|
||||||
globParent('foo/\\[bar]/') // 'foo/[bar]'
|
|
||||||
```
|
|
||||||
|
|
||||||
## Limitations
|
|
||||||
|
|
||||||
### Braces & Brackets
|
|
||||||
This library attempts a quick and imperfect method of determining which path
|
|
||||||
parts have glob magic without fully parsing/lexing the pattern. There are some
|
|
||||||
advanced use cases that can trip it up, such as nested braces where the outer
|
|
||||||
pair is escaped and the inner one contains a path separator. If you find
|
|
||||||
yourself in the unlikely circumstance of being affected by this or need to
|
|
||||||
ensure higher-fidelity glob handling in your library, it is recommended that you
|
|
||||||
pre-process your input with [expand-braces] and/or [expand-brackets].
|
|
||||||
|
|
||||||
### Windows
|
|
||||||
Backslashes are not valid path separators for globs. If a path with backslashes
|
|
||||||
is provided anyway, for simple cases, glob-parent will replace the path
|
|
||||||
separator for you and return the non-glob parent path (now with
|
|
||||||
forward-slashes, which are still valid as Windows path separators).
|
|
||||||
|
|
||||||
This cannot be used in conjunction with escape characters.
|
|
||||||
|
|
||||||
```js
|
|
||||||
// BAD
|
|
||||||
globParent('C:\\Program Files \\(x86\\)\\*.ext') // 'C:/Program Files /(x86/)'
|
|
||||||
|
|
||||||
// GOOD
|
|
||||||
globParent('C:/Program Files\\(x86\\)/*.ext') // 'C:/Program Files (x86)'
|
|
||||||
```
|
|
||||||
|
|
||||||
If you are using escape characters for a pattern without path parts (i.e.
|
|
||||||
relative to `cwd`), prefix with `./` to avoid confusing glob-parent.
|
|
||||||
|
|
||||||
```js
|
|
||||||
// BAD
|
|
||||||
globParent('foo \\[bar]') // 'foo '
|
|
||||||
globParent('foo \\[bar]*') // 'foo '
|
|
||||||
|
|
||||||
// GOOD
|
|
||||||
globParent('./foo \\[bar]') // 'foo [bar]'
|
|
||||||
globParent('./foo \\[bar]*') // '.'
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
ISC
|
|
||||||
|
|
||||||
[expand-braces]: https://github.com/jonschlinkert/expand-braces
|
|
||||||
[expand-brackets]: https://github.com/jonschlinkert/expand-brackets
|
|
||||||
|
|
||||||
[downloads-image]: https://img.shields.io/npm/dm/glob-parent.svg
|
|
||||||
[npm-url]: https://www.npmjs.com/package/glob-parent
|
|
||||||
[npm-image]: https://img.shields.io/npm/v/glob-parent.svg
|
|
||||||
|
|
||||||
[azure-pipelines-url]: https://dev.azure.com/gulpjs/gulp/_build/latest?definitionId=2&branchName=master
|
|
||||||
[azure-pipelines-image]: https://dev.azure.com/gulpjs/gulp/_apis/build/status/glob-parent?branchName=master
|
|
||||||
|
|
||||||
[travis-url]: https://travis-ci.org/gulpjs/glob-parent
|
|
||||||
[travis-image]: https://img.shields.io/travis/gulpjs/glob-parent.svg?label=travis-ci
|
|
||||||
|
|
||||||
[appveyor-url]: https://ci.appveyor.com/project/gulpjs/glob-parent
|
|
||||||
[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/glob-parent.svg?label=appveyor
|
|
||||||
|
|
||||||
[coveralls-url]: https://coveralls.io/r/gulpjs/glob-parent
|
|
||||||
[coveralls-image]: https://img.shields.io/coveralls/gulpjs/glob-parent/master.svg
|
|
||||||
|
|
||||||
[gitter-url]: https://gitter.im/gulpjs/gulp
|
|
||||||
[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg
|
|
|
@ -1,42 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var isGlob = require('is-glob');
|
|
||||||
var pathPosixDirname = require('path').posix.dirname;
|
|
||||||
var isWin32 = require('os').platform() === 'win32';
|
|
||||||
|
|
||||||
var slash = '/';
|
|
||||||
var backslash = /\\/g;
|
|
||||||
var enclosure = /[\{\[].*[\}\]]$/;
|
|
||||||
var globby = /(^|[^\\])([\{\[]|\([^\)]+$)/;
|
|
||||||
var escaped = /\\([\!\*\?\|\[\]\(\)\{\}])/g;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} str
|
|
||||||
* @param {Object} opts
|
|
||||||
* @param {boolean} [opts.flipBackslashes=true]
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
module.exports = function globParent(str, opts) {
|
|
||||||
var options = Object.assign({ flipBackslashes: true }, opts);
|
|
||||||
|
|
||||||
// flip windows path separators
|
|
||||||
if (options.flipBackslashes && isWin32 && str.indexOf(slash) < 0) {
|
|
||||||
str = str.replace(backslash, slash);
|
|
||||||
}
|
|
||||||
|
|
||||||
// special case for strings ending in enclosure containing path separator
|
|
||||||
if (enclosure.test(str)) {
|
|
||||||
str += slash;
|
|
||||||
}
|
|
||||||
|
|
||||||
// preserves full path in case of trailing path separator
|
|
||||||
str += 'a';
|
|
||||||
|
|
||||||
// remove path parts that are globby
|
|
||||||
do {
|
|
||||||
str = pathPosixDirname(str);
|
|
||||||
} while (isGlob(str) || globby.test(str));
|
|
||||||
|
|
||||||
// remove escape chars and return result
|
|
||||||
return str.replace(escaped, '$1');
|
|
||||||
};
|
|
|
@ -1,48 +0,0 @@
|
||||||
{
|
|
||||||
"name": "glob-parent",
|
|
||||||
"version": "5.1.2",
|
|
||||||
"description": "Extract the non-magic parent path from a glob string.",
|
|
||||||
"author": "Gulp Team <team@gulpjs.com> (https://gulpjs.com/)",
|
|
||||||
"contributors": [
|
|
||||||
"Elan Shanker (https://github.com/es128)",
|
|
||||||
"Blaine Bublitz <blaine.bublitz@gmail.com>"
|
|
||||||
],
|
|
||||||
"repository": "gulpjs/glob-parent",
|
|
||||||
"license": "ISC",
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 6"
|
|
||||||
},
|
|
||||||
"main": "index.js",
|
|
||||||
"files": [
|
|
||||||
"LICENSE",
|
|
||||||
"index.js"
|
|
||||||
],
|
|
||||||
"scripts": {
|
|
||||||
"lint": "eslint .",
|
|
||||||
"pretest": "npm run lint",
|
|
||||||
"test": "nyc mocha --async-only",
|
|
||||||
"azure-pipelines": "nyc mocha --async-only --reporter xunit -O output=test.xunit",
|
|
||||||
"coveralls": "nyc report --reporter=text-lcov | coveralls"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"is-glob": "^4.0.1"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"coveralls": "^3.0.11",
|
|
||||||
"eslint": "^2.13.1",
|
|
||||||
"eslint-config-gulp": "^3.0.1",
|
|
||||||
"expect": "^1.20.2",
|
|
||||||
"mocha": "^6.0.2",
|
|
||||||
"nyc": "^13.3.0"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"glob",
|
|
||||||
"parent",
|
|
||||||
"strip",
|
|
||||||
"path",
|
|
||||||
"dirname",
|
|
||||||
"directory",
|
|
||||||
"base",
|
|
||||||
"wildcard"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
'use strict';
|
|
||||||
module.exports = (flag, argv) => {
|
|
||||||
argv = argv || process.argv;
|
|
||||||
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
|
|
||||||
const pos = argv.indexOf(prefix + flag);
|
|
||||||
const terminatorPos = argv.indexOf('--');
|
|
||||||
return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
|
|
||||||
};
|
|
|
@ -1,9 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.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,44 +0,0 @@
|
||||||
{
|
|
||||||
"name": "has-flag",
|
|
||||||
"version": "3.0.0",
|
|
||||||
"description": "Check if argv has a specific flag",
|
|
||||||
"license": "MIT",
|
|
||||||
"repository": "sindresorhus/has-flag",
|
|
||||||
"author": {
|
|
||||||
"name": "Sindre Sorhus",
|
|
||||||
"email": "sindresorhus@gmail.com",
|
|
||||||
"url": "sindresorhus.com"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "xo && ava"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"index.js"
|
|
||||||
],
|
|
||||||
"keywords": [
|
|
||||||
"has",
|
|
||||||
"check",
|
|
||||||
"detect",
|
|
||||||
"contains",
|
|
||||||
"find",
|
|
||||||
"flag",
|
|
||||||
"cli",
|
|
||||||
"command-line",
|
|
||||||
"argv",
|
|
||||||
"process",
|
|
||||||
"arg",
|
|
||||||
"args",
|
|
||||||
"argument",
|
|
||||||
"arguments",
|
|
||||||
"getopt",
|
|
||||||
"minimist",
|
|
||||||
"optimist"
|
|
||||||
],
|
|
||||||
"devDependencies": {
|
|
||||||
"ava": "*",
|
|
||||||
"xo": "*"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
# has-flag [![Build Status](https://travis-ci.org/sindresorhus/has-flag.svg?branch=master)](https://travis-ci.org/sindresorhus/has-flag)
|
|
||||||
|
|
||||||
> Check if [`argv`](https://nodejs.org/docs/latest/api/process.html#process_process_argv) has a specific flag
|
|
||||||
|
|
||||||
Correctly stops looking after an `--` argument terminator.
|
|
||||||
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
```
|
|
||||||
$ npm install has-flag
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```js
|
|
||||||
// foo.js
|
|
||||||
const hasFlag = require('has-flag');
|
|
||||||
|
|
||||||
hasFlag('unicorn');
|
|
||||||
//=> true
|
|
||||||
|
|
||||||
hasFlag('--unicorn');
|
|
||||||
//=> true
|
|
||||||
|
|
||||||
hasFlag('f');
|
|
||||||
//=> true
|
|
||||||
|
|
||||||
hasFlag('-f');
|
|
||||||
//=> true
|
|
||||||
|
|
||||||
hasFlag('foo=bar');
|
|
||||||
//=> true
|
|
||||||
|
|
||||||
hasFlag('foo');
|
|
||||||
//=> false
|
|
||||||
|
|
||||||
hasFlag('rainbow');
|
|
||||||
//=> false
|
|
||||||
```
|
|
||||||
|
|
||||||
```
|
|
||||||
$ node foo.js -f --unicorn --foo=bar -- --rainbow
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
### hasFlag(flag, [argv])
|
|
||||||
|
|
||||||
Returns a boolean for whether the flag exists.
|
|
||||||
|
|
||||||
#### flag
|
|
||||||
|
|
||||||
Type: `string`
|
|
||||||
|
|
||||||
CLI flag to look for. The `--` prefix is optional.
|
|
||||||
|
|
||||||
#### argv
|
|
||||||
|
|
||||||
Type: `string[]`<br>
|
|
||||||
Default: `process.argv`
|
|
||||||
|
|
||||||
CLI arguments.
|
|
||||||
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
|
|
@ -1,14 +0,0 @@
|
||||||
ISC License (ISC)
|
|
||||||
Copyright (c) 2016, Mark Wubben
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
||||||
with or without fee is hereby granted, provided that the above copyright notice
|
|
||||||
and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
||||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
||||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
||||||
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
||||||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
||||||
THIS SOFTWARE.
|
|
|
@ -1,26 +0,0 @@
|
||||||
# ignore-by-default
|
|
||||||
|
|
||||||
This is a package aimed at Node.js development tools. It provides a list of
|
|
||||||
directories that should probably be ignored by such tools, e.g. when watching
|
|
||||||
for file changes.
|
|
||||||
|
|
||||||
It's used by [AVA](https://www.npmjs.com/package/ava) and
|
|
||||||
[nodemon](https://www.npmjs.com/package/nodemon).
|
|
||||||
|
|
||||||
[Please contribute!](./CONTRIBUTING.md)
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```
|
|
||||||
npm install --save ignore-by-default
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
The `ignore-by-default` module exports a `directories()` function, which will
|
|
||||||
return an array of directory names. These are the ones you should ignore.
|
|
||||||
|
|
||||||
```js
|
|
||||||
// ['.git', '.sass_cache', …]
|
|
||||||
var ignoredDirectories = require('ignore-by-default').directories()
|
|
||||||
```
|
|
|
@ -1,12 +0,0 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
exports.directories = function () {
|
|
||||||
return [
|
|
||||||
'.git', // Git repository files, see <https://git-scm.com/>
|
|
||||||
'.nyc_output', // Temporary directory where nyc stores coverage data, see <https://github.com/bcoe/nyc>
|
|
||||||
'.sass-cache', // Cache folder for node-sass, see <https://github.com/sass/node-sass>
|
|
||||||
'bower_components', // Where Bower packages are installed, see <http://bower.io/>
|
|
||||||
'coverage', // Standard output directory for code coverage reports, see <https://github.com/gotwarlost/istanbul>
|
|
||||||
'node_modules' // Where Node modules are installed, see <https://nodejs.org/>
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
{
|
|
||||||
"name": "ignore-by-default",
|
|
||||||
"version": "1.0.1",
|
|
||||||
"description": "A list of directories you should ignore by default",
|
|
||||||
"main": "index.js",
|
|
||||||
"files": [
|
|
||||||
"index.js"
|
|
||||||
],
|
|
||||||
"scripts": {
|
|
||||||
"test": "standard && node test.js"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/novemberborn/ignore-by-default.git"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"ignore",
|
|
||||||
"chokidar",
|
|
||||||
"watcher",
|
|
||||||
"exclude",
|
|
||||||
"glob",
|
|
||||||
"pattern"
|
|
||||||
],
|
|
||||||
"author": "Mark Wubben (https://novemberborn.net/)",
|
|
||||||
"license": "ISC",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/novemberborn/ignore-by-default/issues"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/novemberborn/ignore-by-default#readme",
|
|
||||||
"devDependencies": {
|
|
||||||
"figures": "^1.4.0",
|
|
||||||
"standard": "^6.0.4"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
/**
|
|
||||||
Check if a file path is a binary file.
|
|
||||||
|
|
||||||
@example
|
|
||||||
```
|
|
||||||
import isBinaryPath = require('is-binary-path');
|
|
||||||
|
|
||||||
isBinaryPath('source/unicorn.png');
|
|
||||||
//=> true
|
|
||||||
|
|
||||||
isBinaryPath('source/unicorn.txt');
|
|
||||||
//=> false
|
|
||||||
```
|
|
||||||
*/
|
|
||||||
declare function isBinaryPath(filePath: string): boolean;
|
|
||||||
|
|
||||||
export = isBinaryPath;
|
|
|
@ -1,7 +0,0 @@
|
||||||
'use strict';
|
|
||||||
const path = require('path');
|
|
||||||
const binaryExtensions = require('binary-extensions');
|
|
||||||
|
|
||||||
const extensions = new Set(binaryExtensions);
|
|
||||||
|
|
||||||
module.exports = filePath => extensions.has(path.extname(filePath).slice(1).toLowerCase());
|
|
|
@ -1,9 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2019 Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com), Paul Miller (https://paulmillr.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,40 +0,0 @@
|
||||||
{
|
|
||||||
"name": "is-binary-path",
|
|
||||||
"version": "2.1.0",
|
|
||||||
"description": "Check if a file path is a binary file",
|
|
||||||
"license": "MIT",
|
|
||||||
"repository": "sindresorhus/is-binary-path",
|
|
||||||
"author": {
|
|
||||||
"name": "Sindre Sorhus",
|
|
||||||
"email": "sindresorhus@gmail.com",
|
|
||||||
"url": "sindresorhus.com"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "xo && ava && tsd"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"index.js",
|
|
||||||
"index.d.ts"
|
|
||||||
],
|
|
||||||
"keywords": [
|
|
||||||
"binary",
|
|
||||||
"extensions",
|
|
||||||
"extension",
|
|
||||||
"file",
|
|
||||||
"path",
|
|
||||||
"check",
|
|
||||||
"detect",
|
|
||||||
"is"
|
|
||||||
],
|
|
||||||
"dependencies": {
|
|
||||||
"binary-extensions": "^2.0.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"ava": "^1.4.1",
|
|
||||||
"tsd": "^0.7.2",
|
|
||||||
"xo": "^0.24.0"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
# is-binary-path [![Build Status](https://travis-ci.org/sindresorhus/is-binary-path.svg?branch=master)](https://travis-ci.org/sindresorhus/is-binary-path)
|
|
||||||
|
|
||||||
> Check if a file path is a binary file
|
|
||||||
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
```
|
|
||||||
$ npm install is-binary-path
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```js
|
|
||||||
const isBinaryPath = require('is-binary-path');
|
|
||||||
|
|
||||||
isBinaryPath('source/unicorn.png');
|
|
||||||
//=> true
|
|
||||||
|
|
||||||
isBinaryPath('source/unicorn.txt');
|
|
||||||
//=> false
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Related
|
|
||||||
|
|
||||||
- [binary-extensions](https://github.com/sindresorhus/binary-extensions) - List of binary file extensions
|
|
||||||
- [is-text-path](https://github.com/sindresorhus/is-text-path) - Check if a filepath is a text file
|
|
||||||
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
MIT © [Sindre Sorhus](https://sindresorhus.com), [Paul Miller](https://paulmillr.com)
|
|
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2014-2016, Jon Schlinkert
|
|
||||||
|
|
||||||
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,107 +0,0 @@
|
||||||
# is-extglob [![NPM version](https://img.shields.io/npm/v/is-extglob.svg?style=flat)](https://www.npmjs.com/package/is-extglob) [![NPM downloads](https://img.shields.io/npm/dm/is-extglob.svg?style=flat)](https://npmjs.org/package/is-extglob) [![Build Status](https://img.shields.io/travis/jonschlinkert/is-extglob.svg?style=flat)](https://travis-ci.org/jonschlinkert/is-extglob)
|
|
||||||
|
|
||||||
> Returns true if a string has an extglob.
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
Install with [npm](https://www.npmjs.com/):
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install --save is-extglob
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```js
|
|
||||||
var isExtglob = require('is-extglob');
|
|
||||||
```
|
|
||||||
|
|
||||||
**True**
|
|
||||||
|
|
||||||
```js
|
|
||||||
isExtglob('?(abc)');
|
|
||||||
isExtglob('@(abc)');
|
|
||||||
isExtglob('!(abc)');
|
|
||||||
isExtglob('*(abc)');
|
|
||||||
isExtglob('+(abc)');
|
|
||||||
```
|
|
||||||
|
|
||||||
**False**
|
|
||||||
|
|
||||||
Escaped extglobs:
|
|
||||||
|
|
||||||
```js
|
|
||||||
isExtglob('\\?(abc)');
|
|
||||||
isExtglob('\\@(abc)');
|
|
||||||
isExtglob('\\!(abc)');
|
|
||||||
isExtglob('\\*(abc)');
|
|
||||||
isExtglob('\\+(abc)');
|
|
||||||
```
|
|
||||||
|
|
||||||
Everything else...
|
|
||||||
|
|
||||||
```js
|
|
||||||
isExtglob('foo.js');
|
|
||||||
isExtglob('!foo.js');
|
|
||||||
isExtglob('*.js');
|
|
||||||
isExtglob('**/abc.js');
|
|
||||||
isExtglob('abc/*.js');
|
|
||||||
isExtglob('abc/(aaa|bbb).js');
|
|
||||||
isExtglob('abc/[a-z].js');
|
|
||||||
isExtglob('abc/{a,b}.js');
|
|
||||||
isExtglob('abc/?.js');
|
|
||||||
isExtglob('abc.js');
|
|
||||||
isExtglob('abc/def/ghi.js');
|
|
||||||
```
|
|
||||||
|
|
||||||
## History
|
|
||||||
|
|
||||||
**v2.0**
|
|
||||||
|
|
||||||
Adds support for escaping. Escaped exglobs no longer return true.
|
|
||||||
|
|
||||||
## About
|
|
||||||
|
|
||||||
### Related projects
|
|
||||||
|
|
||||||
* [has-glob](https://www.npmjs.com/package/has-glob): Returns `true` if an array has a glob pattern. | [homepage](https://github.com/jonschlinkert/has-glob "Returns `true` if an array has a glob pattern.")
|
|
||||||
* [is-glob](https://www.npmjs.com/package/is-glob): Returns `true` if the given string looks like a glob pattern or an extglob pattern… [more](https://github.com/jonschlinkert/is-glob) | [homepage](https://github.com/jonschlinkert/is-glob "Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a bet")
|
|
||||||
* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | [homepage](https://github.com/jonschlinkert/micromatch "Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch.")
|
|
||||||
|
|
||||||
### Contributing
|
|
||||||
|
|
||||||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
|
||||||
|
|
||||||
### Building docs
|
|
||||||
|
|
||||||
_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
|
|
||||||
|
|
||||||
To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install -g verb verb-generate-readme && verb
|
|
||||||
```
|
|
||||||
|
|
||||||
### Running tests
|
|
||||||
|
|
||||||
Install dev dependencies:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install -d && npm test
|
|
||||||
```
|
|
||||||
|
|
||||||
### Author
|
|
||||||
|
|
||||||
**Jon Schlinkert**
|
|
||||||
|
|
||||||
* [github/jonschlinkert](https://github.com/jonschlinkert)
|
|
||||||
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
|
|
||||||
|
|
||||||
### License
|
|
||||||
|
|
||||||
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
|
|
||||||
Released under the [MIT license](https://github.com/jonschlinkert/is-extglob/blob/master/LICENSE).
|
|
||||||
|
|
||||||
***
|
|
||||||
|
|
||||||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.31, on October 12, 2016._
|
|
|
@ -1,20 +0,0 @@
|
||||||
/*!
|
|
||||||
* is-extglob <https://github.com/jonschlinkert/is-extglob>
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014-2016, Jon Schlinkert.
|
|
||||||
* Licensed under the MIT License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = function isExtglob(str) {
|
|
||||||
if (typeof str !== 'string' || str === '') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var match;
|
|
||||||
while ((match = /(\\).|([@?!+*]\(.*\))/g.exec(str))) {
|
|
||||||
if (match[2]) return true;
|
|
||||||
str = str.slice(match.index + match[0].length);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
|
|
@ -1,69 +0,0 @@
|
||||||
{
|
|
||||||
"name": "is-extglob",
|
|
||||||
"description": "Returns true if a string has an extglob.",
|
|
||||||
"version": "2.1.1",
|
|
||||||
"homepage": "https://github.com/jonschlinkert/is-extglob",
|
|
||||||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
|
|
||||||
"repository": "jonschlinkert/is-extglob",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/jonschlinkert/is-extglob/issues"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"files": [
|
|
||||||
"index.js"
|
|
||||||
],
|
|
||||||
"main": "index.js",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.10.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "mocha"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"gulp-format-md": "^0.1.10",
|
|
||||||
"mocha": "^3.0.2"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"bash",
|
|
||||||
"braces",
|
|
||||||
"check",
|
|
||||||
"exec",
|
|
||||||
"expression",
|
|
||||||
"extglob",
|
|
||||||
"glob",
|
|
||||||
"globbing",
|
|
||||||
"globstar",
|
|
||||||
"is",
|
|
||||||
"match",
|
|
||||||
"matches",
|
|
||||||
"pattern",
|
|
||||||
"regex",
|
|
||||||
"regular",
|
|
||||||
"string",
|
|
||||||
"test"
|
|
||||||
],
|
|
||||||
"verb": {
|
|
||||||
"toc": false,
|
|
||||||
"layout": "default",
|
|
||||||
"tasks": [
|
|
||||||
"readme"
|
|
||||||
],
|
|
||||||
"plugins": [
|
|
||||||
"gulp-format-md"
|
|
||||||
],
|
|
||||||
"related": {
|
|
||||||
"list": [
|
|
||||||
"has-glob",
|
|
||||||
"is-glob",
|
|
||||||
"micromatch"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"reflinks": [
|
|
||||||
"verb",
|
|
||||||
"verb-generate-readme"
|
|
||||||
],
|
|
||||||
"lint": {
|
|
||||||
"reflinks": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2014-2017, Jon Schlinkert.
|
|
||||||
|
|
||||||
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,206 +0,0 @@
|
||||||
# is-glob [![NPM version](https://img.shields.io/npm/v/is-glob.svg?style=flat)](https://www.npmjs.com/package/is-glob) [![NPM monthly downloads](https://img.shields.io/npm/dm/is-glob.svg?style=flat)](https://npmjs.org/package/is-glob) [![NPM total downloads](https://img.shields.io/npm/dt/is-glob.svg?style=flat)](https://npmjs.org/package/is-glob) [![Build Status](https://img.shields.io/github/workflow/status/micromatch/is-glob/dev)](https://github.com/micromatch/is-glob/actions)
|
|
||||||
|
|
||||||
> Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a better user experience.
|
|
||||||
|
|
||||||
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
Install with [npm](https://www.npmjs.com/):
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install --save is-glob
|
|
||||||
```
|
|
||||||
|
|
||||||
You might also be interested in [is-valid-glob](https://github.com/jonschlinkert/is-valid-glob) and [has-glob](https://github.com/jonschlinkert/has-glob).
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```js
|
|
||||||
var isGlob = require('is-glob');
|
|
||||||
```
|
|
||||||
|
|
||||||
### Default behavior
|
|
||||||
|
|
||||||
**True**
|
|
||||||
|
|
||||||
Patterns that have glob characters or regex patterns will return `true`:
|
|
||||||
|
|
||||||
```js
|
|
||||||
isGlob('!foo.js');
|
|
||||||
isGlob('*.js');
|
|
||||||
isGlob('**/abc.js');
|
|
||||||
isGlob('abc/*.js');
|
|
||||||
isGlob('abc/(aaa|bbb).js');
|
|
||||||
isGlob('abc/[a-z].js');
|
|
||||||
isGlob('abc/{a,b}.js');
|
|
||||||
//=> true
|
|
||||||
```
|
|
||||||
|
|
||||||
Extglobs
|
|
||||||
|
|
||||||
```js
|
|
||||||
isGlob('abc/@(a).js');
|
|
||||||
isGlob('abc/!(a).js');
|
|
||||||
isGlob('abc/+(a).js');
|
|
||||||
isGlob('abc/*(a).js');
|
|
||||||
isGlob('abc/?(a).js');
|
|
||||||
//=> true
|
|
||||||
```
|
|
||||||
|
|
||||||
**False**
|
|
||||||
|
|
||||||
Escaped globs or extglobs return `false`:
|
|
||||||
|
|
||||||
```js
|
|
||||||
isGlob('abc/\\@(a).js');
|
|
||||||
isGlob('abc/\\!(a).js');
|
|
||||||
isGlob('abc/\\+(a).js');
|
|
||||||
isGlob('abc/\\*(a).js');
|
|
||||||
isGlob('abc/\\?(a).js');
|
|
||||||
isGlob('\\!foo.js');
|
|
||||||
isGlob('\\*.js');
|
|
||||||
isGlob('\\*\\*/abc.js');
|
|
||||||
isGlob('abc/\\*.js');
|
|
||||||
isGlob('abc/\\(aaa|bbb).js');
|
|
||||||
isGlob('abc/\\[a-z].js');
|
|
||||||
isGlob('abc/\\{a,b}.js');
|
|
||||||
//=> false
|
|
||||||
```
|
|
||||||
|
|
||||||
Patterns that do not have glob patterns return `false`:
|
|
||||||
|
|
||||||
```js
|
|
||||||
isGlob('abc.js');
|
|
||||||
isGlob('abc/def/ghi.js');
|
|
||||||
isGlob('foo.js');
|
|
||||||
isGlob('abc/@.js');
|
|
||||||
isGlob('abc/+.js');
|
|
||||||
isGlob('abc/?.js');
|
|
||||||
isGlob();
|
|
||||||
isGlob(null);
|
|
||||||
//=> false
|
|
||||||
```
|
|
||||||
|
|
||||||
Arrays are also `false` (If you want to check if an array has a glob pattern, use [has-glob](https://github.com/jonschlinkert/has-glob)):
|
|
||||||
|
|
||||||
```js
|
|
||||||
isGlob(['**/*.js']);
|
|
||||||
isGlob(['foo.js']);
|
|
||||||
//=> false
|
|
||||||
```
|
|
||||||
|
|
||||||
### Option strict
|
|
||||||
|
|
||||||
When `options.strict === false` the behavior is less strict in determining if a pattern is a glob. Meaning that
|
|
||||||
some patterns that would return `false` may return `true`. This is done so that matching libraries like [micromatch](https://github.com/micromatch/micromatch) have a chance at determining if the pattern is a glob or not.
|
|
||||||
|
|
||||||
**True**
|
|
||||||
|
|
||||||
Patterns that have glob characters or regex patterns will return `true`:
|
|
||||||
|
|
||||||
```js
|
|
||||||
isGlob('!foo.js', {strict: false});
|
|
||||||
isGlob('*.js', {strict: false});
|
|
||||||
isGlob('**/abc.js', {strict: false});
|
|
||||||
isGlob('abc/*.js', {strict: false});
|
|
||||||
isGlob('abc/(aaa|bbb).js', {strict: false});
|
|
||||||
isGlob('abc/[a-z].js', {strict: false});
|
|
||||||
isGlob('abc/{a,b}.js', {strict: false});
|
|
||||||
//=> true
|
|
||||||
```
|
|
||||||
|
|
||||||
Extglobs
|
|
||||||
|
|
||||||
```js
|
|
||||||
isGlob('abc/@(a).js', {strict: false});
|
|
||||||
isGlob('abc/!(a).js', {strict: false});
|
|
||||||
isGlob('abc/+(a).js', {strict: false});
|
|
||||||
isGlob('abc/*(a).js', {strict: false});
|
|
||||||
isGlob('abc/?(a).js', {strict: false});
|
|
||||||
//=> true
|
|
||||||
```
|
|
||||||
|
|
||||||
**False**
|
|
||||||
|
|
||||||
Escaped globs or extglobs return `false`:
|
|
||||||
|
|
||||||
```js
|
|
||||||
isGlob('\\!foo.js', {strict: false});
|
|
||||||
isGlob('\\*.js', {strict: false});
|
|
||||||
isGlob('\\*\\*/abc.js', {strict: false});
|
|
||||||
isGlob('abc/\\*.js', {strict: false});
|
|
||||||
isGlob('abc/\\(aaa|bbb).js', {strict: false});
|
|
||||||
isGlob('abc/\\[a-z].js', {strict: false});
|
|
||||||
isGlob('abc/\\{a,b}.js', {strict: false});
|
|
||||||
//=> false
|
|
||||||
```
|
|
||||||
|
|
||||||
## About
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary><strong>Contributing</strong></summary>
|
|
||||||
|
|
||||||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary><strong>Running Tests</strong></summary>
|
|
||||||
|
|
||||||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install && npm test
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary><strong>Building docs</strong></summary>
|
|
||||||
|
|
||||||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
|
||||||
|
|
||||||
To generate the readme, run the following command:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install -g verbose/verb#dev verb-generate-readme && verb
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### Related projects
|
|
||||||
|
|
||||||
You might also be interested in these projects:
|
|
||||||
|
|
||||||
* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit")
|
|
||||||
* [base](https://www.npmjs.com/package/base): Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks | [homepage](https://github.com/node-base/base "Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks")
|
|
||||||
* [update](https://www.npmjs.com/package/update): Be scalable! Update is a new, open source developer framework and CLI for automating updates… [more](https://github.com/update/update) | [homepage](https://github.com/update/update "Be scalable! Update is a new, open source developer framework and CLI for automating updates of any kind in code projects.")
|
|
||||||
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.")
|
|
||||||
|
|
||||||
### Contributors
|
|
||||||
|
|
||||||
| **Commits** | **Contributor** |
|
|
||||||
| --- | --- |
|
|
||||||
| 47 | [jonschlinkert](https://github.com/jonschlinkert) |
|
|
||||||
| 5 | [doowb](https://github.com/doowb) |
|
|
||||||
| 1 | [phated](https://github.com/phated) |
|
|
||||||
| 1 | [danhper](https://github.com/danhper) |
|
|
||||||
| 1 | [paulmillr](https://github.com/paulmillr) |
|
|
||||||
|
|
||||||
### Author
|
|
||||||
|
|
||||||
**Jon Schlinkert**
|
|
||||||
|
|
||||||
* [GitHub Profile](https://github.com/jonschlinkert)
|
|
||||||
* [Twitter Profile](https://twitter.com/jonschlinkert)
|
|
||||||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
|
||||||
|
|
||||||
### License
|
|
||||||
|
|
||||||
Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
|
|
||||||
Released under the [MIT License](LICENSE).
|
|
||||||
|
|
||||||
***
|
|
||||||
|
|
||||||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on March 27, 2019._
|
|
|
@ -1,150 +0,0 @@
|
||||||
/*!
|
|
||||||
* is-glob <https://github.com/jonschlinkert/is-glob>
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
||||||
* Released under the MIT License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var isExtglob = require('is-extglob');
|
|
||||||
var chars = { '{': '}', '(': ')', '[': ']'};
|
|
||||||
var strictCheck = function(str) {
|
|
||||||
if (str[0] === '!') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
var index = 0;
|
|
||||||
var pipeIndex = -2;
|
|
||||||
var closeSquareIndex = -2;
|
|
||||||
var closeCurlyIndex = -2;
|
|
||||||
var closeParenIndex = -2;
|
|
||||||
var backSlashIndex = -2;
|
|
||||||
while (index < str.length) {
|
|
||||||
if (str[index] === '*') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str[index + 1] === '?' && /[\].+)]/.test(str[index])) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (closeSquareIndex !== -1 && str[index] === '[' && str[index + 1] !== ']') {
|
|
||||||
if (closeSquareIndex < index) {
|
|
||||||
closeSquareIndex = str.indexOf(']', index);
|
|
||||||
}
|
|
||||||
if (closeSquareIndex > index) {
|
|
||||||
if (backSlashIndex === -1 || backSlashIndex > closeSquareIndex) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
backSlashIndex = str.indexOf('\\', index);
|
|
||||||
if (backSlashIndex === -1 || backSlashIndex > closeSquareIndex) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (closeCurlyIndex !== -1 && str[index] === '{' && str[index + 1] !== '}') {
|
|
||||||
closeCurlyIndex = str.indexOf('}', index);
|
|
||||||
if (closeCurlyIndex > index) {
|
|
||||||
backSlashIndex = str.indexOf('\\', index);
|
|
||||||
if (backSlashIndex === -1 || backSlashIndex > closeCurlyIndex) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (closeParenIndex !== -1 && str[index] === '(' && str[index + 1] === '?' && /[:!=]/.test(str[index + 2]) && str[index + 3] !== ')') {
|
|
||||||
closeParenIndex = str.indexOf(')', index);
|
|
||||||
if (closeParenIndex > index) {
|
|
||||||
backSlashIndex = str.indexOf('\\', index);
|
|
||||||
if (backSlashIndex === -1 || backSlashIndex > closeParenIndex) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pipeIndex !== -1 && str[index] === '(' && str[index + 1] !== '|') {
|
|
||||||
if (pipeIndex < index) {
|
|
||||||
pipeIndex = str.indexOf('|', index);
|
|
||||||
}
|
|
||||||
if (pipeIndex !== -1 && str[pipeIndex + 1] !== ')') {
|
|
||||||
closeParenIndex = str.indexOf(')', pipeIndex);
|
|
||||||
if (closeParenIndex > pipeIndex) {
|
|
||||||
backSlashIndex = str.indexOf('\\', pipeIndex);
|
|
||||||
if (backSlashIndex === -1 || backSlashIndex > closeParenIndex) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str[index] === '\\') {
|
|
||||||
var open = str[index + 1];
|
|
||||||
index += 2;
|
|
||||||
var close = chars[open];
|
|
||||||
|
|
||||||
if (close) {
|
|
||||||
var n = str.indexOf(close, index);
|
|
||||||
if (n !== -1) {
|
|
||||||
index = n + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str[index] === '!') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
var relaxedCheck = function(str) {
|
|
||||||
if (str[0] === '!') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
var index = 0;
|
|
||||||
while (index < str.length) {
|
|
||||||
if (/[*?{}()[\]]/.test(str[index])) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str[index] === '\\') {
|
|
||||||
var open = str[index + 1];
|
|
||||||
index += 2;
|
|
||||||
var close = chars[open];
|
|
||||||
|
|
||||||
if (close) {
|
|
||||||
var n = str.indexOf(close, index);
|
|
||||||
if (n !== -1) {
|
|
||||||
index = n + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str[index] === '!') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = function isGlob(str, options) {
|
|
||||||
if (typeof str !== 'string' || str === '') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isExtglob(str)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var check = strictCheck;
|
|
||||||
|
|
||||||
// optionally relax check
|
|
||||||
if (options && options.strict === false) {
|
|
||||||
check = relaxedCheck;
|
|
||||||
}
|
|
||||||
|
|
||||||
return check(str);
|
|
||||||
};
|
|
|
@ -1,81 +0,0 @@
|
||||||
{
|
|
||||||
"name": "is-glob",
|
|
||||||
"description": "Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a better user experience.",
|
|
||||||
"version": "4.0.3",
|
|
||||||
"homepage": "https://github.com/micromatch/is-glob",
|
|
||||||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
|
|
||||||
"contributors": [
|
|
||||||
"Brian Woodward (https://twitter.com/doowb)",
|
|
||||||
"Daniel Perez (https://tuvistavie.com)",
|
|
||||||
"Jon Schlinkert (http://twitter.com/jonschlinkert)"
|
|
||||||
],
|
|
||||||
"repository": "micromatch/is-glob",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/micromatch/is-glob/issues"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"files": [
|
|
||||||
"index.js"
|
|
||||||
],
|
|
||||||
"main": "index.js",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.10.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "mocha && node benchmark.js"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"is-extglob": "^2.1.1"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"gulp-format-md": "^0.1.10",
|
|
||||||
"mocha": "^3.0.2"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"bash",
|
|
||||||
"braces",
|
|
||||||
"check",
|
|
||||||
"exec",
|
|
||||||
"expression",
|
|
||||||
"extglob",
|
|
||||||
"glob",
|
|
||||||
"globbing",
|
|
||||||
"globstar",
|
|
||||||
"is",
|
|
||||||
"match",
|
|
||||||
"matches",
|
|
||||||
"pattern",
|
|
||||||
"regex",
|
|
||||||
"regular",
|
|
||||||
"string",
|
|
||||||
"test"
|
|
||||||
],
|
|
||||||
"verb": {
|
|
||||||
"layout": "default",
|
|
||||||
"plugins": [
|
|
||||||
"gulp-format-md"
|
|
||||||
],
|
|
||||||
"related": {
|
|
||||||
"list": [
|
|
||||||
"assemble",
|
|
||||||
"base",
|
|
||||||
"update",
|
|
||||||
"verb"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"reflinks": [
|
|
||||||
"assemble",
|
|
||||||
"bach",
|
|
||||||
"base",
|
|
||||||
"composer",
|
|
||||||
"gulp",
|
|
||||||
"has-glob",
|
|
||||||
"is-valid-glob",
|
|
||||||
"micromatch",
|
|
||||||
"npm",
|
|
||||||
"scaffold",
|
|
||||||
"verb",
|
|
||||||
"vinyl"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2014-present, Jon Schlinkert.
|
|
||||||
|
|
||||||
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,187 +0,0 @@
|
||||||
# is-number [![NPM version](https://img.shields.io/npm/v/is-number.svg?style=flat)](https://www.npmjs.com/package/is-number) [![NPM monthly downloads](https://img.shields.io/npm/dm/is-number.svg?style=flat)](https://npmjs.org/package/is-number) [![NPM total downloads](https://img.shields.io/npm/dt/is-number.svg?style=flat)](https://npmjs.org/package/is-number) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/is-number.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/is-number)
|
|
||||||
|
|
||||||
> Returns true if the value is a finite number.
|
|
||||||
|
|
||||||
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
Install with [npm](https://www.npmjs.com/):
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install --save is-number
|
|
||||||
```
|
|
||||||
|
|
||||||
## Why is this needed?
|
|
||||||
|
|
||||||
In JavaScript, it's not always as straightforward as it should be to reliably check if a value is a number. It's common for devs to use `+`, `-`, or `Number()` to cast a string value to a number (for example, when values are returned from user input, regex matches, parsers, etc). But there are many non-intuitive edge cases that yield unexpected results:
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.log(+[]); //=> 0
|
|
||||||
console.log(+''); //=> 0
|
|
||||||
console.log(+' '); //=> 0
|
|
||||||
console.log(typeof NaN); //=> 'number'
|
|
||||||
```
|
|
||||||
|
|
||||||
This library offers a performant way to smooth out edge cases like these.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```js
|
|
||||||
const isNumber = require('is-number');
|
|
||||||
```
|
|
||||||
|
|
||||||
See the [tests](./test.js) for more examples.
|
|
||||||
|
|
||||||
### true
|
|
||||||
|
|
||||||
```js
|
|
||||||
isNumber(5e3); // true
|
|
||||||
isNumber(0xff); // true
|
|
||||||
isNumber(-1.1); // true
|
|
||||||
isNumber(0); // true
|
|
||||||
isNumber(1); // true
|
|
||||||
isNumber(1.1); // true
|
|
||||||
isNumber(10); // true
|
|
||||||
isNumber(10.10); // true
|
|
||||||
isNumber(100); // true
|
|
||||||
isNumber('-1.1'); // true
|
|
||||||
isNumber('0'); // true
|
|
||||||
isNumber('012'); // true
|
|
||||||
isNumber('0xff'); // true
|
|
||||||
isNumber('1'); // true
|
|
||||||
isNumber('1.1'); // true
|
|
||||||
isNumber('10'); // true
|
|
||||||
isNumber('10.10'); // true
|
|
||||||
isNumber('100'); // true
|
|
||||||
isNumber('5e3'); // true
|
|
||||||
isNumber(parseInt('012')); // true
|
|
||||||
isNumber(parseFloat('012')); // true
|
|
||||||
```
|
|
||||||
|
|
||||||
### False
|
|
||||||
|
|
||||||
Everything else is false, as you would expect:
|
|
||||||
|
|
||||||
```js
|
|
||||||
isNumber(Infinity); // false
|
|
||||||
isNumber(NaN); // false
|
|
||||||
isNumber(null); // false
|
|
||||||
isNumber(undefined); // false
|
|
||||||
isNumber(''); // false
|
|
||||||
isNumber(' '); // false
|
|
||||||
isNumber('foo'); // false
|
|
||||||
isNumber([1]); // false
|
|
||||||
isNumber([]); // false
|
|
||||||
isNumber(function () {}); // false
|
|
||||||
isNumber({}); // false
|
|
||||||
```
|
|
||||||
|
|
||||||
## Release history
|
|
||||||
|
|
||||||
### 7.0.0
|
|
||||||
|
|
||||||
* Refactor. Now uses `.isFinite` if it exists.
|
|
||||||
* Performance is about the same as v6.0 when the value is a string or number. But it's now 3x-4x faster when the value is not a string or number.
|
|
||||||
|
|
||||||
### 6.0.0
|
|
||||||
|
|
||||||
* Optimizations, thanks to @benaadams.
|
|
||||||
|
|
||||||
### 5.0.0
|
|
||||||
|
|
||||||
**Breaking changes**
|
|
||||||
|
|
||||||
* removed support for `instanceof Number` and `instanceof String`
|
|
||||||
|
|
||||||
## Benchmarks
|
|
||||||
|
|
||||||
As with all benchmarks, take these with a grain of salt. See the [benchmarks](./benchmark/index.js) for more detail.
|
|
||||||
|
|
||||||
```
|
|
||||||
# all
|
|
||||||
v7.0 x 413,222 ops/sec ±2.02% (86 runs sampled)
|
|
||||||
v6.0 x 111,061 ops/sec ±1.29% (85 runs sampled)
|
|
||||||
parseFloat x 317,596 ops/sec ±1.36% (86 runs sampled)
|
|
||||||
fastest is 'v7.0'
|
|
||||||
|
|
||||||
# string
|
|
||||||
v7.0 x 3,054,496 ops/sec ±1.05% (89 runs sampled)
|
|
||||||
v6.0 x 2,957,781 ops/sec ±0.98% (88 runs sampled)
|
|
||||||
parseFloat x 3,071,060 ops/sec ±1.13% (88 runs sampled)
|
|
||||||
fastest is 'parseFloat,v7.0'
|
|
||||||
|
|
||||||
# number
|
|
||||||
v7.0 x 3,146,895 ops/sec ±0.89% (89 runs sampled)
|
|
||||||
v6.0 x 3,214,038 ops/sec ±1.07% (89 runs sampled)
|
|
||||||
parseFloat x 3,077,588 ops/sec ±1.07% (87 runs sampled)
|
|
||||||
fastest is 'v6.0'
|
|
||||||
```
|
|
||||||
|
|
||||||
## About
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary><strong>Contributing</strong></summary>
|
|
||||||
|
|
||||||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary><strong>Running Tests</strong></summary>
|
|
||||||
|
|
||||||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install && npm test
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary><strong>Building docs</strong></summary>
|
|
||||||
|
|
||||||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
|
||||||
|
|
||||||
To generate the readme, run the following command:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ npm install -g verbose/verb#dev verb-generate-readme && verb
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### Related projects
|
|
||||||
|
|
||||||
You might also be interested in these projects:
|
|
||||||
|
|
||||||
* [is-plain-object](https://www.npmjs.com/package/is-plain-object): Returns true if an object was created by the `Object` constructor. | [homepage](https://github.com/jonschlinkert/is-plain-object "Returns true if an object was created by the `Object` constructor.")
|
|
||||||
* [is-primitive](https://www.npmjs.com/package/is-primitive): Returns `true` if the value is a primitive. | [homepage](https://github.com/jonschlinkert/is-primitive "Returns `true` if the value is a primitive. ")
|
|
||||||
* [isobject](https://www.npmjs.com/package/isobject): Returns true if the value is an object and not an array or null. | [homepage](https://github.com/jonschlinkert/isobject "Returns true if the value is an object and not an array or null.")
|
|
||||||
* [kind-of](https://www.npmjs.com/package/kind-of): Get the native type of a value. | [homepage](https://github.com/jonschlinkert/kind-of "Get the native type of a value.")
|
|
||||||
|
|
||||||
### Contributors
|
|
||||||
|
|
||||||
| **Commits** | **Contributor** |
|
|
||||||
| --- | --- |
|
|
||||||
| 49 | [jonschlinkert](https://github.com/jonschlinkert) |
|
|
||||||
| 5 | [charlike-old](https://github.com/charlike-old) |
|
|
||||||
| 1 | [benaadams](https://github.com/benaadams) |
|
|
||||||
| 1 | [realityking](https://github.com/realityking) |
|
|
||||||
|
|
||||||
### Author
|
|
||||||
|
|
||||||
**Jon Schlinkert**
|
|
||||||
|
|
||||||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
|
||||||
* [GitHub Profile](https://github.com/jonschlinkert)
|
|
||||||
* [Twitter Profile](https://twitter.com/jonschlinkert)
|
|
||||||
|
|
||||||
### License
|
|
||||||
|
|
||||||
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
|
|
||||||
Released under the [MIT License](LICENSE).
|
|
||||||
|
|
||||||
***
|
|
||||||
|
|
||||||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 15, 2018._
|
|
|
@ -1,18 +0,0 @@
|
||||||
/*!
|
|
||||||
* is-number <https://github.com/jonschlinkert/is-number>
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014-present, Jon Schlinkert.
|
|
||||||
* Released under the MIT License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = function(num) {
|
|
||||||
if (typeof num === 'number') {
|
|
||||||
return num - num === 0;
|
|
||||||
}
|
|
||||||
if (typeof num === 'string' && num.trim() !== '') {
|
|
||||||
return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
|
@ -1,82 +0,0 @@
|
||||||
{
|
|
||||||
"name": "is-number",
|
|
||||||
"description": "Returns true if a number or string value is a finite number. Useful for regex matches, parsing, user input, etc.",
|
|
||||||
"version": "7.0.0",
|
|
||||||
"homepage": "https://github.com/jonschlinkert/is-number",
|
|
||||||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
|
|
||||||
"contributors": [
|
|
||||||
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
|
|
||||||
"Olsten Larck (https://i.am.charlike.online)",
|
|
||||||
"Rouven Weßling (www.rouvenwessling.de)"
|
|
||||||
],
|
|
||||||
"repository": "jonschlinkert/is-number",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/jonschlinkert/is-number/issues"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"files": [
|
|
||||||
"index.js"
|
|
||||||
],
|
|
||||||
"main": "index.js",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.12.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "mocha"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"ansi": "^0.3.1",
|
|
||||||
"benchmark": "^2.1.4",
|
|
||||||
"gulp-format-md": "^1.0.0",
|
|
||||||
"mocha": "^3.5.3"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"cast",
|
|
||||||
"check",
|
|
||||||
"coerce",
|
|
||||||
"coercion",
|
|
||||||
"finite",
|
|
||||||
"integer",
|
|
||||||
"is",
|
|
||||||
"isnan",
|
|
||||||
"is-nan",
|
|
||||||
"is-num",
|
|
||||||
"is-number",
|
|
||||||
"isnumber",
|
|
||||||
"isfinite",
|
|
||||||
"istype",
|
|
||||||
"kind",
|
|
||||||
"math",
|
|
||||||
"nan",
|
|
||||||
"num",
|
|
||||||
"number",
|
|
||||||
"numeric",
|
|
||||||
"parseFloat",
|
|
||||||
"parseInt",
|
|
||||||
"test",
|
|
||||||
"type",
|
|
||||||
"typeof",
|
|
||||||
"value"
|
|
||||||
],
|
|
||||||
"verb": {
|
|
||||||
"toc": false,
|
|
||||||
"layout": "default",
|
|
||||||
"tasks": [
|
|
||||||
"readme"
|
|
||||||
],
|
|
||||||
"related": {
|
|
||||||
"list": [
|
|
||||||
"is-plain-object",
|
|
||||||
"is-primitive",
|
|
||||||
"isobject",
|
|
||||||
"kind-of"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"plugins": [
|
|
||||||
"gulp-format-md"
|
|
||||||
],
|
|
||||||
"lint": {
|
|
||||||
"reflinks": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
The ISC License
|
|
||||||
|
|
||||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
||||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
@ -1,230 +0,0 @@
|
||||||
# minimatch
|
|
||||||
|
|
||||||
A minimal matching utility.
|
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.org/isaacs/minimatch.svg?branch=master)](http://travis-ci.org/isaacs/minimatch)
|
|
||||||
|
|
||||||
|
|
||||||
This is the matching library used internally by npm.
|
|
||||||
|
|
||||||
It works by converting glob expressions into JavaScript `RegExp`
|
|
||||||
objects.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var minimatch = require("minimatch")
|
|
||||||
|
|
||||||
minimatch("bar.foo", "*.foo") // true!
|
|
||||||
minimatch("bar.foo", "*.bar") // false!
|
|
||||||
minimatch("bar.foo", "*.+(bar|foo)", { debug: true }) // true, and noisy!
|
|
||||||
```
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
Supports these glob features:
|
|
||||||
|
|
||||||
* Brace Expansion
|
|
||||||
* Extended glob matching
|
|
||||||
* "Globstar" `**` matching
|
|
||||||
|
|
||||||
See:
|
|
||||||
|
|
||||||
* `man sh`
|
|
||||||
* `man bash`
|
|
||||||
* `man 3 fnmatch`
|
|
||||||
* `man 5 gitignore`
|
|
||||||
|
|
||||||
## Minimatch Class
|
|
||||||
|
|
||||||
Create a minimatch object by instantiating the `minimatch.Minimatch` class.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var Minimatch = require("minimatch").Minimatch
|
|
||||||
var mm = new Minimatch(pattern, options)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Properties
|
|
||||||
|
|
||||||
* `pattern` The original pattern the minimatch object represents.
|
|
||||||
* `options` The options supplied to the constructor.
|
|
||||||
* `set` A 2-dimensional array of regexp or string expressions.
|
|
||||||
Each row in the
|
|
||||||
array corresponds to a brace-expanded pattern. Each item in the row
|
|
||||||
corresponds to a single path-part. For example, the pattern
|
|
||||||
`{a,b/c}/d` would expand to a set of patterns like:
|
|
||||||
|
|
||||||
[ [ a, d ]
|
|
||||||
, [ b, c, d ] ]
|
|
||||||
|
|
||||||
If a portion of the pattern doesn't have any "magic" in it
|
|
||||||
(that is, it's something like `"foo"` rather than `fo*o?`), then it
|
|
||||||
will be left as a string rather than converted to a regular
|
|
||||||
expression.
|
|
||||||
|
|
||||||
* `regexp` Created by the `makeRe` method. A single regular expression
|
|
||||||
expressing the entire pattern. This is useful in cases where you wish
|
|
||||||
to use the pattern somewhat like `fnmatch(3)` with `FNM_PATH` enabled.
|
|
||||||
* `negate` True if the pattern is negated.
|
|
||||||
* `comment` True if the pattern is a comment.
|
|
||||||
* `empty` True if the pattern is `""`.
|
|
||||||
|
|
||||||
### Methods
|
|
||||||
|
|
||||||
* `makeRe` Generate the `regexp` member if necessary, and return it.
|
|
||||||
Will return `false` if the pattern is invalid.
|
|
||||||
* `match(fname)` Return true if the filename matches the pattern, or
|
|
||||||
false otherwise.
|
|
||||||
* `matchOne(fileArray, patternArray, partial)` Take a `/`-split
|
|
||||||
filename, and match it against a single row in the `regExpSet`. This
|
|
||||||
method is mainly for internal use, but is exposed so that it can be
|
|
||||||
used by a glob-walker that needs to avoid excessive filesystem calls.
|
|
||||||
|
|
||||||
All other methods are internal, and will be called as necessary.
|
|
||||||
|
|
||||||
### minimatch(path, pattern, options)
|
|
||||||
|
|
||||||
Main export. Tests a path against the pattern using the options.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var isJS = minimatch(file, "*.js", { matchBase: true })
|
|
||||||
```
|
|
||||||
|
|
||||||
### minimatch.filter(pattern, options)
|
|
||||||
|
|
||||||
Returns a function that tests its
|
|
||||||
supplied argument, suitable for use with `Array.filter`. Example:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var javascripts = fileList.filter(minimatch.filter("*.js", {matchBase: true}))
|
|
||||||
```
|
|
||||||
|
|
||||||
### minimatch.match(list, pattern, options)
|
|
||||||
|
|
||||||
Match against the list of
|
|
||||||
files, in the style of fnmatch or glob. If nothing is matched, and
|
|
||||||
options.nonull is set, then return a list containing the pattern itself.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var javascripts = minimatch.match(fileList, "*.js", {matchBase: true}))
|
|
||||||
```
|
|
||||||
|
|
||||||
### minimatch.makeRe(pattern, options)
|
|
||||||
|
|
||||||
Make a regular expression object from the pattern.
|
|
||||||
|
|
||||||
## Options
|
|
||||||
|
|
||||||
All options are `false` by default.
|
|
||||||
|
|
||||||
### debug
|
|
||||||
|
|
||||||
Dump a ton of stuff to stderr.
|
|
||||||
|
|
||||||
### nobrace
|
|
||||||
|
|
||||||
Do not expand `{a,b}` and `{1..3}` brace sets.
|
|
||||||
|
|
||||||
### noglobstar
|
|
||||||
|
|
||||||
Disable `**` matching against multiple folder names.
|
|
||||||
|
|
||||||
### dot
|
|
||||||
|
|
||||||
Allow patterns to match filenames starting with a period, even if
|
|
||||||
the pattern does not explicitly have a period in that spot.
|
|
||||||
|
|
||||||
Note that by default, `a/**/b` will **not** match `a/.d/b`, unless `dot`
|
|
||||||
is set.
|
|
||||||
|
|
||||||
### noext
|
|
||||||
|
|
||||||
Disable "extglob" style patterns like `+(a|b)`.
|
|
||||||
|
|
||||||
### nocase
|
|
||||||
|
|
||||||
Perform a case-insensitive match.
|
|
||||||
|
|
||||||
### nonull
|
|
||||||
|
|
||||||
When a match is not found by `minimatch.match`, return a list containing
|
|
||||||
the pattern itself if this option is set. When not set, an empty list
|
|
||||||
is returned if there are no matches.
|
|
||||||
|
|
||||||
### matchBase
|
|
||||||
|
|
||||||
If set, then patterns without slashes will be matched
|
|
||||||
against the basename of the path if it contains slashes. For example,
|
|
||||||
`a?b` would match the path `/xyz/123/acb`, but not `/xyz/acb/123`.
|
|
||||||
|
|
||||||
### nocomment
|
|
||||||
|
|
||||||
Suppress the behavior of treating `#` at the start of a pattern as a
|
|
||||||
comment.
|
|
||||||
|
|
||||||
### nonegate
|
|
||||||
|
|
||||||
Suppress the behavior of treating a leading `!` character as negation.
|
|
||||||
|
|
||||||
### flipNegate
|
|
||||||
|
|
||||||
Returns from negate expressions the same as if they were not negated.
|
|
||||||
(Ie, true on a hit, false on a miss.)
|
|
||||||
|
|
||||||
### partial
|
|
||||||
|
|
||||||
Compare a partial path to a pattern. As long as the parts of the path that
|
|
||||||
are present are not contradicted by the pattern, it will be treated as a
|
|
||||||
match. This is useful in applications where you're walking through a
|
|
||||||
folder structure, and don't yet have the full path, but want to ensure that
|
|
||||||
you do not walk down paths that can never be a match.
|
|
||||||
|
|
||||||
For example,
|
|
||||||
|
|
||||||
```js
|
|
||||||
minimatch('/a/b', '/a/*/c/d', { partial: true }) // true, might be /a/b/c/d
|
|
||||||
minimatch('/a/b', '/**/d', { partial: true }) // true, might be /a/b/.../d
|
|
||||||
minimatch('/x/y/z', '/a/**/z', { partial: true }) // false, because x !== a
|
|
||||||
```
|
|
||||||
|
|
||||||
### allowWindowsEscape
|
|
||||||
|
|
||||||
Windows path separator `\` is by default converted to `/`, which
|
|
||||||
prohibits the usage of `\` as a escape character. This flag skips that
|
|
||||||
behavior and allows using the escape character.
|
|
||||||
|
|
||||||
## Comparisons to other fnmatch/glob implementations
|
|
||||||
|
|
||||||
While strict compliance with the existing standards is a worthwhile
|
|
||||||
goal, some discrepancies exist between minimatch and other
|
|
||||||
implementations, and are intentional.
|
|
||||||
|
|
||||||
If the pattern starts with a `!` character, then it is negated. Set the
|
|
||||||
`nonegate` flag to suppress this behavior, and treat leading `!`
|
|
||||||
characters normally. This is perhaps relevant if you wish to start the
|
|
||||||
pattern with a negative extglob pattern like `!(a|B)`. Multiple `!`
|
|
||||||
characters at the start of a pattern will negate the pattern multiple
|
|
||||||
times.
|
|
||||||
|
|
||||||
If a pattern starts with `#`, then it is treated as a comment, and
|
|
||||||
will not match anything. Use `\#` to match a literal `#` at the
|
|
||||||
start of a line, or set the `nocomment` flag to suppress this behavior.
|
|
||||||
|
|
||||||
The double-star character `**` is supported by default, unless the
|
|
||||||
`noglobstar` flag is set. This is supported in the manner of bsdglob
|
|
||||||
and bash 4.1, where `**` only has special significance if it is the only
|
|
||||||
thing in a path part. That is, `a/**/b` will match `a/x/y/b`, but
|
|
||||||
`a/**b` will not.
|
|
||||||
|
|
||||||
If an escaped pattern has no matches, and the `nonull` flag is set,
|
|
||||||
then minimatch.match returns the pattern as-provided, rather than
|
|
||||||
interpreting the character escapes. For example,
|
|
||||||
`minimatch.match([], "\\*a\\?")` will return `"\\*a\\?"` rather than
|
|
||||||
`"*a?"`. This is akin to setting the `nullglob` option in bash, except
|
|
||||||
that it does not resolve escaped pattern characters.
|
|
||||||
|
|
||||||
If brace expansion is not disabled, then it is performed before any
|
|
||||||
other interpretation of the glob pattern. Thus, a pattern like
|
|
||||||
`+(a|{b),c)}`, which would not be valid in bash or zsh, is expanded
|
|
||||||
**first** into the set of `+(a|b)` and `+(a|c)`, and those patterns are
|
|
||||||
checked for validity. Since those two are valid, matching proceeds.
|
|
|
@ -1,947 +0,0 @@
|
||||||
module.exports = minimatch
|
|
||||||
minimatch.Minimatch = Minimatch
|
|
||||||
|
|
||||||
var path = (function () { try { return require('path') } catch (e) {}}()) || {
|
|
||||||
sep: '/'
|
|
||||||
}
|
|
||||||
minimatch.sep = path.sep
|
|
||||||
|
|
||||||
var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
|
|
||||||
var expand = require('brace-expansion')
|
|
||||||
|
|
||||||
var plTypes = {
|
|
||||||
'!': { open: '(?:(?!(?:', close: '))[^/]*?)'},
|
|
||||||
'?': { open: '(?:', close: ')?' },
|
|
||||||
'+': { open: '(?:', close: ')+' },
|
|
||||||
'*': { open: '(?:', close: ')*' },
|
|
||||||
'@': { open: '(?:', close: ')' }
|
|
||||||
}
|
|
||||||
|
|
||||||
// any single thing other than /
|
|
||||||
// don't need to escape / when using new RegExp()
|
|
||||||
var qmark = '[^/]'
|
|
||||||
|
|
||||||
// * => any number of characters
|
|
||||||
var star = qmark + '*?'
|
|
||||||
|
|
||||||
// ** when dots are allowed. Anything goes, except .. and .
|
|
||||||
// not (^ or / followed by one or two dots followed by $ or /),
|
|
||||||
// followed by anything, any number of times.
|
|
||||||
var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'
|
|
||||||
|
|
||||||
// not a ^ or / followed by a dot,
|
|
||||||
// followed by anything, any number of times.
|
|
||||||
var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'
|
|
||||||
|
|
||||||
// characters that need to be escaped in RegExp.
|
|
||||||
var reSpecials = charSet('().*{}+?[]^$\\!')
|
|
||||||
|
|
||||||
// "abc" -> { a:true, b:true, c:true }
|
|
||||||
function charSet (s) {
|
|
||||||
return s.split('').reduce(function (set, c) {
|
|
||||||
set[c] = true
|
|
||||||
return set
|
|
||||||
}, {})
|
|
||||||
}
|
|
||||||
|
|
||||||
// normalizes slashes.
|
|
||||||
var slashSplit = /\/+/
|
|
||||||
|
|
||||||
minimatch.filter = filter
|
|
||||||
function filter (pattern, options) {
|
|
||||||
options = options || {}
|
|
||||||
return function (p, i, list) {
|
|
||||||
return minimatch(p, pattern, options)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function ext (a, b) {
|
|
||||||
b = b || {}
|
|
||||||
var t = {}
|
|
||||||
Object.keys(a).forEach(function (k) {
|
|
||||||
t[k] = a[k]
|
|
||||||
})
|
|
||||||
Object.keys(b).forEach(function (k) {
|
|
||||||
t[k] = b[k]
|
|
||||||
})
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
minimatch.defaults = function (def) {
|
|
||||||
if (!def || typeof def !== 'object' || !Object.keys(def).length) {
|
|
||||||
return minimatch
|
|
||||||
}
|
|
||||||
|
|
||||||
var orig = minimatch
|
|
||||||
|
|
||||||
var m = function minimatch (p, pattern, options) {
|
|
||||||
return orig(p, pattern, ext(def, options))
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Minimatch = function Minimatch (pattern, options) {
|
|
||||||
return new orig.Minimatch(pattern, ext(def, options))
|
|
||||||
}
|
|
||||||
m.Minimatch.defaults = function defaults (options) {
|
|
||||||
return orig.defaults(ext(def, options)).Minimatch
|
|
||||||
}
|
|
||||||
|
|
||||||
m.filter = function filter (pattern, options) {
|
|
||||||
return orig.filter(pattern, ext(def, options))
|
|
||||||
}
|
|
||||||
|
|
||||||
m.defaults = function defaults (options) {
|
|
||||||
return orig.defaults(ext(def, options))
|
|
||||||
}
|
|
||||||
|
|
||||||
m.makeRe = function makeRe (pattern, options) {
|
|
||||||
return orig.makeRe(pattern, ext(def, options))
|
|
||||||
}
|
|
||||||
|
|
||||||
m.braceExpand = function braceExpand (pattern, options) {
|
|
||||||
return orig.braceExpand(pattern, ext(def, options))
|
|
||||||
}
|
|
||||||
|
|
||||||
m.match = function (list, pattern, options) {
|
|
||||||
return orig.match(list, pattern, ext(def, options))
|
|
||||||
}
|
|
||||||
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|
||||||
Minimatch.defaults = function (def) {
|
|
||||||
return minimatch.defaults(def).Minimatch
|
|
||||||
}
|
|
||||||
|
|
||||||
function minimatch (p, pattern, options) {
|
|
||||||
assertValidPattern(pattern)
|
|
||||||
|
|
||||||
if (!options) options = {}
|
|
||||||
|
|
||||||
// shortcut: comments match nothing.
|
|
||||||
if (!options.nocomment && pattern.charAt(0) === '#') {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Minimatch(pattern, options).match(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
function Minimatch (pattern, options) {
|
|
||||||
if (!(this instanceof Minimatch)) {
|
|
||||||
return new Minimatch(pattern, options)
|
|
||||||
}
|
|
||||||
|
|
||||||
assertValidPattern(pattern)
|
|
||||||
|
|
||||||
if (!options) options = {}
|
|
||||||
|
|
||||||
pattern = pattern.trim()
|
|
||||||
|
|
||||||
// windows support: need to use /, not \
|
|
||||||
if (!options.allowWindowsEscape && path.sep !== '/') {
|
|
||||||
pattern = pattern.split(path.sep).join('/')
|
|
||||||
}
|
|
||||||
|
|
||||||
this.options = options
|
|
||||||
this.set = []
|
|
||||||
this.pattern = pattern
|
|
||||||
this.regexp = null
|
|
||||||
this.negate = false
|
|
||||||
this.comment = false
|
|
||||||
this.empty = false
|
|
||||||
this.partial = !!options.partial
|
|
||||||
|
|
||||||
// make the set of regexps etc.
|
|
||||||
this.make()
|
|
||||||
}
|
|
||||||
|
|
||||||
Minimatch.prototype.debug = function () {}
|
|
||||||
|
|
||||||
Minimatch.prototype.make = make
|
|
||||||
function make () {
|
|
||||||
var pattern = this.pattern
|
|
||||||
var options = this.options
|
|
||||||
|
|
||||||
// empty patterns and comments match nothing.
|
|
||||||
if (!options.nocomment && pattern.charAt(0) === '#') {
|
|
||||||
this.comment = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!pattern) {
|
|
||||||
this.empty = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// step 1: figure out negation, etc.
|
|
||||||
this.parseNegate()
|
|
||||||
|
|
||||||
// step 2: expand braces
|
|
||||||
var set = this.globSet = this.braceExpand()
|
|
||||||
|
|
||||||
if (options.debug) this.debug = function debug() { console.error.apply(console, arguments) }
|
|
||||||
|
|
||||||
this.debug(this.pattern, set)
|
|
||||||
|
|
||||||
// step 3: now we have a set, so turn each one into a series of path-portion
|
|
||||||
// matching patterns.
|
|
||||||
// These will be regexps, except in the case of "**", which is
|
|
||||||
// set to the GLOBSTAR object for globstar behavior,
|
|
||||||
// and will not contain any / characters
|
|
||||||
set = this.globParts = set.map(function (s) {
|
|
||||||
return s.split(slashSplit)
|
|
||||||
})
|
|
||||||
|
|
||||||
this.debug(this.pattern, set)
|
|
||||||
|
|
||||||
// glob --> regexps
|
|
||||||
set = set.map(function (s, si, set) {
|
|
||||||
return s.map(this.parse, this)
|
|
||||||
}, this)
|
|
||||||
|
|
||||||
this.debug(this.pattern, set)
|
|
||||||
|
|
||||||
// filter out everything that didn't compile properly.
|
|
||||||
set = set.filter(function (s) {
|
|
||||||
return s.indexOf(false) === -1
|
|
||||||
})
|
|
||||||
|
|
||||||
this.debug(this.pattern, set)
|
|
||||||
|
|
||||||
this.set = set
|
|
||||||
}
|
|
||||||
|
|
||||||
Minimatch.prototype.parseNegate = parseNegate
|
|
||||||
function parseNegate () {
|
|
||||||
var pattern = this.pattern
|
|
||||||
var negate = false
|
|
||||||
var options = this.options
|
|
||||||
var negateOffset = 0
|
|
||||||
|
|
||||||
if (options.nonegate) return
|
|
||||||
|
|
||||||
for (var i = 0, l = pattern.length
|
|
||||||
; i < l && pattern.charAt(i) === '!'
|
|
||||||
; i++) {
|
|
||||||
negate = !negate
|
|
||||||
negateOffset++
|
|
||||||
}
|
|
||||||
|
|
||||||
if (negateOffset) this.pattern = pattern.substr(negateOffset)
|
|
||||||
this.negate = negate
|
|
||||||
}
|
|
||||||
|
|
||||||
// Brace expansion:
|
|
||||||
// a{b,c}d -> abd acd
|
|
||||||
// a{b,}c -> abc ac
|
|
||||||
// a{0..3}d -> a0d a1d a2d a3d
|
|
||||||
// a{b,c{d,e}f}g -> abg acdfg acefg
|
|
||||||
// a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
|
|
||||||
//
|
|
||||||
// Invalid sets are not expanded.
|
|
||||||
// a{2..}b -> a{2..}b
|
|
||||||
// a{b}c -> a{b}c
|
|
||||||
minimatch.braceExpand = function (pattern, options) {
|
|
||||||
return braceExpand(pattern, options)
|
|
||||||
}
|
|
||||||
|
|
||||||
Minimatch.prototype.braceExpand = braceExpand
|
|
||||||
|
|
||||||
function braceExpand (pattern, options) {
|
|
||||||
if (!options) {
|
|
||||||
if (this instanceof Minimatch) {
|
|
||||||
options = this.options
|
|
||||||
} else {
|
|
||||||
options = {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pattern = typeof pattern === 'undefined'
|
|
||||||
? this.pattern : pattern
|
|
||||||
|
|
||||||
assertValidPattern(pattern)
|
|
||||||
|
|
||||||
// Thanks to Yeting Li <https://github.com/yetingli> for
|
|
||||||
// improving this regexp to avoid a ReDOS vulnerability.
|
|
||||||
if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
|
|
||||||
// shortcut. no need to expand.
|
|
||||||
return [pattern]
|
|
||||||
}
|
|
||||||
|
|
||||||
return expand(pattern)
|
|
||||||
}
|
|
||||||
|
|
||||||
var MAX_PATTERN_LENGTH = 1024 * 64
|
|
||||||
var assertValidPattern = function (pattern) {
|
|
||||||
if (typeof pattern !== 'string') {
|
|
||||||
throw new TypeError('invalid pattern')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pattern.length > MAX_PATTERN_LENGTH) {
|
|
||||||
throw new TypeError('pattern is too long')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse a component of the expanded set.
|
|
||||||
// At this point, no pattern may contain "/" in it
|
|
||||||
// so we're going to return a 2d array, where each entry is the full
|
|
||||||
// pattern, split on '/', and then turned into a regular expression.
|
|
||||||
// A regexp is made at the end which joins each array with an
|
|
||||||
// escaped /, and another full one which joins each regexp with |.
|
|
||||||
//
|
|
||||||
// Following the lead of Bash 4.1, note that "**" only has special meaning
|
|
||||||
// when it is the *only* thing in a path portion. Otherwise, any series
|
|
||||||
// of * is equivalent to a single *. Globstar behavior is enabled by
|
|
||||||
// default, and can be disabled by setting options.noglobstar.
|
|
||||||
Minimatch.prototype.parse = parse
|
|
||||||
var SUBPARSE = {}
|
|
||||||
function parse (pattern, isSub) {
|
|
||||||
assertValidPattern(pattern)
|
|
||||||
|
|
||||||
var options = this.options
|
|
||||||
|
|
||||||
// shortcuts
|
|
||||||
if (pattern === '**') {
|
|
||||||
if (!options.noglobstar)
|
|
||||||
return GLOBSTAR
|
|
||||||
else
|
|
||||||
pattern = '*'
|
|
||||||
}
|
|
||||||
if (pattern === '') return ''
|
|
||||||
|
|
||||||
var re = ''
|
|
||||||
var hasMagic = !!options.nocase
|
|
||||||
var escaping = false
|
|
||||||
// ? => one single character
|
|
||||||
var patternListStack = []
|
|
||||||
var negativeLists = []
|
|
||||||
var stateChar
|
|
||||||
var inClass = false
|
|
||||||
var reClassStart = -1
|
|
||||||
var classStart = -1
|
|
||||||
// . and .. never match anything that doesn't start with .,
|
|
||||||
// even when options.dot is set.
|
|
||||||
var patternStart = pattern.charAt(0) === '.' ? '' // anything
|
|
||||||
// not (start or / followed by . or .. followed by / or end)
|
|
||||||
: options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))'
|
|
||||||
: '(?!\\.)'
|
|
||||||
var self = this
|
|
||||||
|
|
||||||
function clearStateChar () {
|
|
||||||
if (stateChar) {
|
|
||||||
// we had some state-tracking character
|
|
||||||
// that wasn't consumed by this pass.
|
|
||||||
switch (stateChar) {
|
|
||||||
case '*':
|
|
||||||
re += star
|
|
||||||
hasMagic = true
|
|
||||||
break
|
|
||||||
case '?':
|
|
||||||
re += qmark
|
|
||||||
hasMagic = true
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
re += '\\' + stateChar
|
|
||||||
break
|
|
||||||
}
|
|
||||||
self.debug('clearStateChar %j %j', stateChar, re)
|
|
||||||
stateChar = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0, len = pattern.length, c
|
|
||||||
; (i < len) && (c = pattern.charAt(i))
|
|
||||||
; i++) {
|
|
||||||
this.debug('%s\t%s %s %j', pattern, i, re, c)
|
|
||||||
|
|
||||||
// skip over any that are escaped.
|
|
||||||
if (escaping && reSpecials[c]) {
|
|
||||||
re += '\\' + c
|
|
||||||
escaping = false
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (c) {
|
|
||||||
/* istanbul ignore next */
|
|
||||||
case '/': {
|
|
||||||
// completely not allowed, even escaped.
|
|
||||||
// Should already be path-split by now.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
case '\\':
|
|
||||||
clearStateChar()
|
|
||||||
escaping = true
|
|
||||||
continue
|
|
||||||
|
|
||||||
// the various stateChar values
|
|
||||||
// for the "extglob" stuff.
|
|
||||||
case '?':
|
|
||||||
case '*':
|
|
||||||
case '+':
|
|
||||||
case '@':
|
|
||||||
case '!':
|
|
||||||
this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c)
|
|
||||||
|
|
||||||
// all of those are literals inside a class, except that
|
|
||||||
// the glob [!a] means [^a] in regexp
|
|
||||||
if (inClass) {
|
|
||||||
this.debug(' in class')
|
|
||||||
if (c === '!' && i === classStart + 1) c = '^'
|
|
||||||
re += c
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we already have a stateChar, then it means
|
|
||||||
// that there was something like ** or +? in there.
|
|
||||||
// Handle the stateChar, then proceed with this one.
|
|
||||||
self.debug('call clearStateChar %j', stateChar)
|
|
||||||
clearStateChar()
|
|
||||||
stateChar = c
|
|
||||||
// if extglob is disabled, then +(asdf|foo) isn't a thing.
|
|
||||||
// just clear the statechar *now*, rather than even diving into
|
|
||||||
// the patternList stuff.
|
|
||||||
if (options.noext) clearStateChar()
|
|
||||||
continue
|
|
||||||
|
|
||||||
case '(':
|
|
||||||
if (inClass) {
|
|
||||||
re += '('
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!stateChar) {
|
|
||||||
re += '\\('
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
patternListStack.push({
|
|
||||||
type: stateChar,
|
|
||||||
start: i - 1,
|
|
||||||
reStart: re.length,
|
|
||||||
open: plTypes[stateChar].open,
|
|
||||||
close: plTypes[stateChar].close
|
|
||||||
})
|
|
||||||
// negation is (?:(?!js)[^/]*)
|
|
||||||
re += stateChar === '!' ? '(?:(?!(?:' : '(?:'
|
|
||||||
this.debug('plType %j %j', stateChar, re)
|
|
||||||
stateChar = false
|
|
||||||
continue
|
|
||||||
|
|
||||||
case ')':
|
|
||||||
if (inClass || !patternListStack.length) {
|
|
||||||
re += '\\)'
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
clearStateChar()
|
|
||||||
hasMagic = true
|
|
||||||
var pl = patternListStack.pop()
|
|
||||||
// negation is (?:(?!js)[^/]*)
|
|
||||||
// The others are (?:<pattern>)<type>
|
|
||||||
re += pl.close
|
|
||||||
if (pl.type === '!') {
|
|
||||||
negativeLists.push(pl)
|
|
||||||
}
|
|
||||||
pl.reEnd = re.length
|
|
||||||
continue
|
|
||||||
|
|
||||||
case '|':
|
|
||||||
if (inClass || !patternListStack.length || escaping) {
|
|
||||||
re += '\\|'
|
|
||||||
escaping = false
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
clearStateChar()
|
|
||||||
re += '|'
|
|
||||||
continue
|
|
||||||
|
|
||||||
// these are mostly the same in regexp and glob
|
|
||||||
case '[':
|
|
||||||
// swallow any state-tracking char before the [
|
|
||||||
clearStateChar()
|
|
||||||
|
|
||||||
if (inClass) {
|
|
||||||
re += '\\' + c
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
inClass = true
|
|
||||||
classStart = i
|
|
||||||
reClassStart = re.length
|
|
||||||
re += c
|
|
||||||
continue
|
|
||||||
|
|
||||||
case ']':
|
|
||||||
// a right bracket shall lose its special
|
|
||||||
// meaning and represent itself in
|
|
||||||
// a bracket expression if it occurs
|
|
||||||
// first in the list. -- POSIX.2 2.8.3.2
|
|
||||||
if (i === classStart + 1 || !inClass) {
|
|
||||||
re += '\\' + c
|
|
||||||
escaping = false
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle the case where we left a class open.
|
|
||||||
// "[z-a]" is valid, equivalent to "\[z-a\]"
|
|
||||||
// split where the last [ was, make sure we don't have
|
|
||||||
// an invalid re. if so, re-walk the contents of the
|
|
||||||
// would-be class to re-translate any characters that
|
|
||||||
// were passed through as-is
|
|
||||||
// TODO: It would probably be faster to determine this
|
|
||||||
// without a try/catch and a new RegExp, but it's tricky
|
|
||||||
// to do safely. For now, this is safe and works.
|
|
||||||
var cs = pattern.substring(classStart + 1, i)
|
|
||||||
try {
|
|
||||||
RegExp('[' + cs + ']')
|
|
||||||
} catch (er) {
|
|
||||||
// not a valid class!
|
|
||||||
var sp = this.parse(cs, SUBPARSE)
|
|
||||||
re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
|
|
||||||
hasMagic = hasMagic || sp[1]
|
|
||||||
inClass = false
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// finish up the class.
|
|
||||||
hasMagic = true
|
|
||||||
inClass = false
|
|
||||||
re += c
|
|
||||||
continue
|
|
||||||
|
|
||||||
default:
|
|
||||||
// swallow any state char that wasn't consumed
|
|
||||||
clearStateChar()
|
|
||||||
|
|
||||||
if (escaping) {
|
|
||||||
// no need
|
|
||||||
escaping = false
|
|
||||||
} else if (reSpecials[c]
|
|
||||||
&& !(c === '^' && inClass)) {
|
|
||||||
re += '\\'
|
|
||||||
}
|
|
||||||
|
|
||||||
re += c
|
|
||||||
|
|
||||||
} // switch
|
|
||||||
} // for
|
|
||||||
|
|
||||||
// handle the case where we left a class open.
|
|
||||||
// "[abc" is valid, equivalent to "\[abc"
|
|
||||||
if (inClass) {
|
|
||||||
// split where the last [ was, and escape it
|
|
||||||
// this is a huge pita. We now have to re-walk
|
|
||||||
// the contents of the would-be class to re-translate
|
|
||||||
// any characters that were passed through as-is
|
|
||||||
cs = pattern.substr(classStart + 1)
|
|
||||||
sp = this.parse(cs, SUBPARSE)
|
|
||||||
re = re.substr(0, reClassStart) + '\\[' + sp[0]
|
|
||||||
hasMagic = hasMagic || sp[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle the case where we had a +( thing at the *end*
|
|
||||||
// of the pattern.
|
|
||||||
// each pattern list stack adds 3 chars, and we need to go through
|
|
||||||
// and escape any | chars that were passed through as-is for the regexp.
|
|
||||||
// Go through and escape them, taking care not to double-escape any
|
|
||||||
// | chars that were already escaped.
|
|
||||||
for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
|
|
||||||
var tail = re.slice(pl.reStart + pl.open.length)
|
|
||||||
this.debug('setting tail', re, pl)
|
|
||||||
// maybe some even number of \, then maybe 1 \, followed by a |
|
|
||||||
tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
|
|
||||||
if (!$2) {
|
|
||||||
// the | isn't already escaped, so escape it.
|
|
||||||
$2 = '\\'
|
|
||||||
}
|
|
||||||
|
|
||||||
// need to escape all those slashes *again*, without escaping the
|
|
||||||
// one that we need for escaping the | character. As it works out,
|
|
||||||
// escaping an even number of slashes can be done by simply repeating
|
|
||||||
// it exactly after itself. That's why this trick works.
|
|
||||||
//
|
|
||||||
// I am sorry that you have to see this.
|
|
||||||
return $1 + $1 + $2 + '|'
|
|
||||||
})
|
|
||||||
|
|
||||||
this.debug('tail=%j\n %s', tail, tail, pl, re)
|
|
||||||
var t = pl.type === '*' ? star
|
|
||||||
: pl.type === '?' ? qmark
|
|
||||||
: '\\' + pl.type
|
|
||||||
|
|
||||||
hasMagic = true
|
|
||||||
re = re.slice(0, pl.reStart) + t + '\\(' + tail
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle trailing things that only matter at the very end.
|
|
||||||
clearStateChar()
|
|
||||||
if (escaping) {
|
|
||||||
// trailing \\
|
|
||||||
re += '\\\\'
|
|
||||||
}
|
|
||||||
|
|
||||||
// only need to apply the nodot start if the re starts with
|
|
||||||
// something that could conceivably capture a dot
|
|
||||||
var addPatternStart = false
|
|
||||||
switch (re.charAt(0)) {
|
|
||||||
case '[': case '.': case '(': addPatternStart = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hack to work around lack of negative lookbehind in JS
|
|
||||||
// A pattern like: *.!(x).!(y|z) needs to ensure that a name
|
|
||||||
// like 'a.xyz.yz' doesn't match. So, the first negative
|
|
||||||
// lookahead, has to look ALL the way ahead, to the end of
|
|
||||||
// the pattern.
|
|
||||||
for (var n = negativeLists.length - 1; n > -1; n--) {
|
|
||||||
var nl = negativeLists[n]
|
|
||||||
|
|
||||||
var nlBefore = re.slice(0, nl.reStart)
|
|
||||||
var nlFirst = re.slice(nl.reStart, nl.reEnd - 8)
|
|
||||||
var nlLast = re.slice(nl.reEnd - 8, nl.reEnd)
|
|
||||||
var nlAfter = re.slice(nl.reEnd)
|
|
||||||
|
|
||||||
nlLast += nlAfter
|
|
||||||
|
|
||||||
// Handle nested stuff like *(*.js|!(*.json)), where open parens
|
|
||||||
// mean that we should *not* include the ) in the bit that is considered
|
|
||||||
// "after" the negated section.
|
|
||||||
var openParensBefore = nlBefore.split('(').length - 1
|
|
||||||
var cleanAfter = nlAfter
|
|
||||||
for (i = 0; i < openParensBefore; i++) {
|
|
||||||
cleanAfter = cleanAfter.replace(/\)[+*?]?/, '')
|
|
||||||
}
|
|
||||||
nlAfter = cleanAfter
|
|
||||||
|
|
||||||
var dollar = ''
|
|
||||||
if (nlAfter === '' && isSub !== SUBPARSE) {
|
|
||||||
dollar = '$'
|
|
||||||
}
|
|
||||||
var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast
|
|
||||||
re = newRe
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the re is not "" at this point, then we need to make sure
|
|
||||||
// it doesn't match against an empty path part.
|
|
||||||
// Otherwise a/* will match a/, which it should not.
|
|
||||||
if (re !== '' && hasMagic) {
|
|
||||||
re = '(?=.)' + re
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addPatternStart) {
|
|
||||||
re = patternStart + re
|
|
||||||
}
|
|
||||||
|
|
||||||
// parsing just a piece of a larger pattern.
|
|
||||||
if (isSub === SUBPARSE) {
|
|
||||||
return [re, hasMagic]
|
|
||||||
}
|
|
||||||
|
|
||||||
// skip the regexp for non-magical patterns
|
|
||||||
// unescape anything in it, though, so that it'll be
|
|
||||||
// an exact match against a file etc.
|
|
||||||
if (!hasMagic) {
|
|
||||||
return globUnescape(pattern)
|
|
||||||
}
|
|
||||||
|
|
||||||
var flags = options.nocase ? 'i' : ''
|
|
||||||
try {
|
|
||||||
var regExp = new RegExp('^' + re + '$', flags)
|
|
||||||
} catch (er) /* istanbul ignore next - should be impossible */ {
|
|
||||||
// If it was an invalid regular expression, then it can't match
|
|
||||||
// anything. This trick looks for a character after the end of
|
|
||||||
// the string, which is of course impossible, except in multi-line
|
|
||||||
// mode, but it's not a /m regex.
|
|
||||||
return new RegExp('$.')
|
|
||||||
}
|
|
||||||
|
|
||||||
regExp._glob = pattern
|
|
||||||
regExp._src = re
|
|
||||||
|
|
||||||
return regExp
|
|
||||||
}
|
|
||||||
|
|
||||||
minimatch.makeRe = function (pattern, options) {
|
|
||||||
return new Minimatch(pattern, options || {}).makeRe()
|
|
||||||
}
|
|
||||||
|
|
||||||
Minimatch.prototype.makeRe = makeRe
|
|
||||||
function makeRe () {
|
|
||||||
if (this.regexp || this.regexp === false) return this.regexp
|
|
||||||
|
|
||||||
// at this point, this.set is a 2d array of partial
|
|
||||||
// pattern strings, or "**".
|
|
||||||
//
|
|
||||||
// It's better to use .match(). This function shouldn't
|
|
||||||
// be used, really, but it's pretty convenient sometimes,
|
|
||||||
// when you just want to work with a regex.
|
|
||||||
var set = this.set
|
|
||||||
|
|
||||||
if (!set.length) {
|
|
||||||
this.regexp = false
|
|
||||||
return this.regexp
|
|
||||||
}
|
|
||||||
var options = this.options
|
|
||||||
|
|
||||||
var twoStar = options.noglobstar ? star
|
|
||||||
: options.dot ? twoStarDot
|
|
||||||
: twoStarNoDot
|
|
||||||
var flags = options.nocase ? 'i' : ''
|
|
||||||
|
|
||||||
var re = set.map(function (pattern) {
|
|
||||||
return pattern.map(function (p) {
|
|
||||||
return (p === GLOBSTAR) ? twoStar
|
|
||||||
: (typeof p === 'string') ? regExpEscape(p)
|
|
||||||
: p._src
|
|
||||||
}).join('\\\/')
|
|
||||||
}).join('|')
|
|
||||||
|
|
||||||
// must match entire pattern
|
|
||||||
// ending in a * or ** will make it less strict.
|
|
||||||
re = '^(?:' + re + ')$'
|
|
||||||
|
|
||||||
// can match anything, as long as it's not this.
|
|
||||||
if (this.negate) re = '^(?!' + re + ').*$'
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.regexp = new RegExp(re, flags)
|
|
||||||
} catch (ex) /* istanbul ignore next - should be impossible */ {
|
|
||||||
this.regexp = false
|
|
||||||
}
|
|
||||||
return this.regexp
|
|
||||||
}
|
|
||||||
|
|
||||||
minimatch.match = function (list, pattern, options) {
|
|
||||||
options = options || {}
|
|
||||||
var mm = new Minimatch(pattern, options)
|
|
||||||
list = list.filter(function (f) {
|
|
||||||
return mm.match(f)
|
|
||||||
})
|
|
||||||
if (mm.options.nonull && !list.length) {
|
|
||||||
list.push(pattern)
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
|
|
||||||
Minimatch.prototype.match = function match (f, partial) {
|
|
||||||
if (typeof partial === 'undefined') partial = this.partial
|
|
||||||
this.debug('match', f, this.pattern)
|
|
||||||
// short-circuit in the case of busted things.
|
|
||||||
// comments, etc.
|
|
||||||
if (this.comment) return false
|
|
||||||
if (this.empty) return f === ''
|
|
||||||
|
|
||||||
if (f === '/' && partial) return true
|
|
||||||
|
|
||||||
var options = this.options
|
|
||||||
|
|
||||||
// windows: need to use /, not \
|
|
||||||
if (path.sep !== '/') {
|
|
||||||
f = f.split(path.sep).join('/')
|
|
||||||
}
|
|
||||||
|
|
||||||
// treat the test path as a set of pathparts.
|
|
||||||
f = f.split(slashSplit)
|
|
||||||
this.debug(this.pattern, 'split', f)
|
|
||||||
|
|
||||||
// just ONE of the pattern sets in this.set needs to match
|
|
||||||
// in order for it to be valid. If negating, then just one
|
|
||||||
// match means that we have failed.
|
|
||||||
// Either way, return on the first hit.
|
|
||||||
|
|
||||||
var set = this.set
|
|
||||||
this.debug(this.pattern, 'set', set)
|
|
||||||
|
|
||||||
// Find the basename of the path by looking for the last non-empty segment
|
|
||||||
var filename
|
|
||||||
var i
|
|
||||||
for (i = f.length - 1; i >= 0; i--) {
|
|
||||||
filename = f[i]
|
|
||||||
if (filename) break
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < set.length; i++) {
|
|
||||||
var pattern = set[i]
|
|
||||||
var file = f
|
|
||||||
if (options.matchBase && pattern.length === 1) {
|
|
||||||
file = [filename]
|
|
||||||
}
|
|
||||||
var hit = this.matchOne(file, pattern, partial)
|
|
||||||
if (hit) {
|
|
||||||
if (options.flipNegate) return true
|
|
||||||
return !this.negate
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// didn't get any hits. this is success if it's a negative
|
|
||||||
// pattern, failure otherwise.
|
|
||||||
if (options.flipNegate) return false
|
|
||||||
return this.negate
|
|
||||||
}
|
|
||||||
|
|
||||||
// set partial to true to test if, for example,
|
|
||||||
// "/a/b" matches the start of "/*/b/*/d"
|
|
||||||
// Partial means, if you run out of file before you run
|
|
||||||
// out of pattern, then that's fine, as long as all
|
|
||||||
// the parts match.
|
|
||||||
Minimatch.prototype.matchOne = function (file, pattern, partial) {
|
|
||||||
var options = this.options
|
|
||||||
|
|
||||||
this.debug('matchOne',
|
|
||||||
{ 'this': this, file: file, pattern: pattern })
|
|
||||||
|
|
||||||
this.debug('matchOne', file.length, pattern.length)
|
|
||||||
|
|
||||||
for (var fi = 0,
|
|
||||||
pi = 0,
|
|
||||||
fl = file.length,
|
|
||||||
pl = pattern.length
|
|
||||||
; (fi < fl) && (pi < pl)
|
|
||||||
; fi++, pi++) {
|
|
||||||
this.debug('matchOne loop')
|
|
||||||
var p = pattern[pi]
|
|
||||||
var f = file[fi]
|
|
||||||
|
|
||||||
this.debug(pattern, p, f)
|
|
||||||
|
|
||||||
// should be impossible.
|
|
||||||
// some invalid regexp stuff in the set.
|
|
||||||
/* istanbul ignore if */
|
|
||||||
if (p === false) return false
|
|
||||||
|
|
||||||
if (p === GLOBSTAR) {
|
|
||||||
this.debug('GLOBSTAR', [pattern, p, f])
|
|
||||||
|
|
||||||
// "**"
|
|
||||||
// a/**/b/**/c would match the following:
|
|
||||||
// a/b/x/y/z/c
|
|
||||||
// a/x/y/z/b/c
|
|
||||||
// a/b/x/b/x/c
|
|
||||||
// a/b/c
|
|
||||||
// To do this, take the rest of the pattern after
|
|
||||||
// the **, and see if it would match the file remainder.
|
|
||||||
// If so, return success.
|
|
||||||
// If not, the ** "swallows" a segment, and try again.
|
|
||||||
// This is recursively awful.
|
|
||||||
//
|
|
||||||
// a/**/b/**/c matching a/b/x/y/z/c
|
|
||||||
// - a matches a
|
|
||||||
// - doublestar
|
|
||||||
// - matchOne(b/x/y/z/c, b/**/c)
|
|
||||||
// - b matches b
|
|
||||||
// - doublestar
|
|
||||||
// - matchOne(x/y/z/c, c) -> no
|
|
||||||
// - matchOne(y/z/c, c) -> no
|
|
||||||
// - matchOne(z/c, c) -> no
|
|
||||||
// - matchOne(c, c) yes, hit
|
|
||||||
var fr = fi
|
|
||||||
var pr = pi + 1
|
|
||||||
if (pr === pl) {
|
|
||||||
this.debug('** at the end')
|
|
||||||
// a ** at the end will just swallow the rest.
|
|
||||||
// We have found a match.
|
|
||||||
// however, it will not swallow /.x, unless
|
|
||||||
// options.dot is set.
|
|
||||||
// . and .. are *never* matched by **, for explosively
|
|
||||||
// exponential reasons.
|
|
||||||
for (; fi < fl; fi++) {
|
|
||||||
if (file[fi] === '.' || file[fi] === '..' ||
|
|
||||||
(!options.dot && file[fi].charAt(0) === '.')) return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// ok, let's see if we can swallow whatever we can.
|
|
||||||
while (fr < fl) {
|
|
||||||
var swallowee = file[fr]
|
|
||||||
|
|
||||||
this.debug('\nglobstar while', file, fr, pattern, pr, swallowee)
|
|
||||||
|
|
||||||
// XXX remove this slice. Just pass the start index.
|
|
||||||
if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
|
|
||||||
this.debug('globstar found match!', fr, fl, swallowee)
|
|
||||||
// found a match.
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
// can't swallow "." or ".." ever.
|
|
||||||
// can only swallow ".foo" when explicitly asked.
|
|
||||||
if (swallowee === '.' || swallowee === '..' ||
|
|
||||||
(!options.dot && swallowee.charAt(0) === '.')) {
|
|
||||||
this.debug('dot detected!', file, fr, pattern, pr)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
// ** swallows a segment, and continue.
|
|
||||||
this.debug('globstar swallow a segment, and continue')
|
|
||||||
fr++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// no match was found.
|
|
||||||
// However, in partial mode, we can't say this is necessarily over.
|
|
||||||
// If there's more *pattern* left, then
|
|
||||||
/* istanbul ignore if */
|
|
||||||
if (partial) {
|
|
||||||
// ran out of file
|
|
||||||
this.debug('\n>>> no match, partial?', file, fr, pattern, pr)
|
|
||||||
if (fr === fl) return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// something other than **
|
|
||||||
// non-magic patterns just have to match exactly
|
|
||||||
// patterns with magic have been turned into regexps.
|
|
||||||
var hit
|
|
||||||
if (typeof p === 'string') {
|
|
||||||
hit = f === p
|
|
||||||
this.debug('string match', p, f, hit)
|
|
||||||
} else {
|
|
||||||
hit = f.match(p)
|
|
||||||
this.debug('pattern match', p, f, hit)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hit) return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: ending in / means that we'll get a final ""
|
|
||||||
// at the end of the pattern. This can only match a
|
|
||||||
// corresponding "" at the end of the file.
|
|
||||||
// If the file ends in /, then it can only match a
|
|
||||||
// a pattern that ends in /, unless the pattern just
|
|
||||||
// doesn't have any more for it. But, a/b/ should *not*
|
|
||||||
// match "a/b/*", even though "" matches against the
|
|
||||||
// [^/]*? pattern, except in partial mode, where it might
|
|
||||||
// simply not be reached yet.
|
|
||||||
// However, a/b/ should still satisfy a/*
|
|
||||||
|
|
||||||
// now either we fell off the end of the pattern, or we're done.
|
|
||||||
if (fi === fl && pi === pl) {
|
|
||||||
// ran out of pattern and filename at the same time.
|
|
||||||
// an exact hit!
|
|
||||||
return true
|
|
||||||
} else if (fi === fl) {
|
|
||||||
// ran out of file, but still had pattern left.
|
|
||||||
// this is ok if we're doing the match as part of
|
|
||||||
// a glob fs traversal.
|
|
||||||
return partial
|
|
||||||
} else /* istanbul ignore else */ if (pi === pl) {
|
|
||||||
// ran out of pattern, still have file left.
|
|
||||||
// this is only acceptable if we're on the very last
|
|
||||||
// empty segment of a file with a trailing slash.
|
|
||||||
// a/* should match a/b/
|
|
||||||
return (fi === fl - 1) && (file[fi] === '')
|
|
||||||
}
|
|
||||||
|
|
||||||
// should be unreachable.
|
|
||||||
/* istanbul ignore next */
|
|
||||||
throw new Error('wtf?')
|
|
||||||
}
|
|
||||||
|
|
||||||
// replace stuff like \* with *
|
|
||||||
function globUnescape (s) {
|
|
||||||
return s.replace(/\\(.)/g, '$1')
|
|
||||||
}
|
|
||||||
|
|
||||||
function regExpEscape (s) {
|
|
||||||
return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
{
|
|
||||||
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me)",
|
|
||||||
"name": "minimatch",
|
|
||||||
"description": "a glob matcher in javascript",
|
|
||||||
"version": "3.1.2",
|
|
||||||
"publishConfig": {
|
|
||||||
"tag": "v3-legacy"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/isaacs/minimatch.git"
|
|
||||||
},
|
|
||||||
"main": "minimatch.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "tap",
|
|
||||||
"preversion": "npm test",
|
|
||||||
"postversion": "npm publish",
|
|
||||||
"postpublish": "git push origin --all; git push origin --tags"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": "*"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"brace-expansion": "^1.1.7"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"tap": "^15.1.6"
|
|
||||||
},
|
|
||||||
"license": "ISC",
|
|
||||||
"files": [
|
|
||||||
"minimatch.js"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,162 +0,0 @@
|
||||||
/**
|
|
||||||
* Helpers.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var s = 1000;
|
|
||||||
var m = s * 60;
|
|
||||||
var h = m * 60;
|
|
||||||
var d = h * 24;
|
|
||||||
var w = d * 7;
|
|
||||||
var y = d * 365.25;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse or format the given `val`.
|
|
||||||
*
|
|
||||||
* Options:
|
|
||||||
*
|
|
||||||
* - `long` verbose formatting [false]
|
|
||||||
*
|
|
||||||
* @param {String|Number} val
|
|
||||||
* @param {Object} [options]
|
|
||||||
* @throws {Error} throw an error if val is not a non-empty string or a number
|
|
||||||
* @return {String|Number}
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = function(val, options) {
|
|
||||||
options = options || {};
|
|
||||||
var type = typeof val;
|
|
||||||
if (type === 'string' && val.length > 0) {
|
|
||||||
return parse(val);
|
|
||||||
} else if (type === 'number' && isFinite(val)) {
|
|
||||||
return options.long ? fmtLong(val) : fmtShort(val);
|
|
||||||
}
|
|
||||||
throw new Error(
|
|
||||||
'val is not a non-empty string or a valid number. val=' +
|
|
||||||
JSON.stringify(val)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the given `str` and return milliseconds.
|
|
||||||
*
|
|
||||||
* @param {String} str
|
|
||||||
* @return {Number}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
function parse(str) {
|
|
||||||
str = String(str);
|
|
||||||
if (str.length > 100) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
||||||
str
|
|
||||||
);
|
|
||||||
if (!match) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var n = parseFloat(match[1]);
|
|
||||||
var type = (match[2] || 'ms').toLowerCase();
|
|
||||||
switch (type) {
|
|
||||||
case 'years':
|
|
||||||
case 'year':
|
|
||||||
case 'yrs':
|
|
||||||
case 'yr':
|
|
||||||
case 'y':
|
|
||||||
return n * y;
|
|
||||||
case 'weeks':
|
|
||||||
case 'week':
|
|
||||||
case 'w':
|
|
||||||
return n * w;
|
|
||||||
case 'days':
|
|
||||||
case 'day':
|
|
||||||
case 'd':
|
|
||||||
return n * d;
|
|
||||||
case 'hours':
|
|
||||||
case 'hour':
|
|
||||||
case 'hrs':
|
|
||||||
case 'hr':
|
|
||||||
case 'h':
|
|
||||||
return n * h;
|
|
||||||
case 'minutes':
|
|
||||||
case 'minute':
|
|
||||||
case 'mins':
|
|
||||||
case 'min':
|
|
||||||
case 'm':
|
|
||||||
return n * m;
|
|
||||||
case 'seconds':
|
|
||||||
case 'second':
|
|
||||||
case 'secs':
|
|
||||||
case 'sec':
|
|
||||||
case 's':
|
|
||||||
return n * s;
|
|
||||||
case 'milliseconds':
|
|
||||||
case 'millisecond':
|
|
||||||
case 'msecs':
|
|
||||||
case 'msec':
|
|
||||||
case 'ms':
|
|
||||||
return n;
|
|
||||||
default:
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Short format for `ms`.
|
|
||||||
*
|
|
||||||
* @param {Number} ms
|
|
||||||
* @return {String}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
function fmtShort(ms) {
|
|
||||||
var msAbs = Math.abs(ms);
|
|
||||||
if (msAbs >= d) {
|
|
||||||
return Math.round(ms / d) + 'd';
|
|
||||||
}
|
|
||||||
if (msAbs >= h) {
|
|
||||||
return Math.round(ms / h) + 'h';
|
|
||||||
}
|
|
||||||
if (msAbs >= m) {
|
|
||||||
return Math.round(ms / m) + 'm';
|
|
||||||
}
|
|
||||||
if (msAbs >= s) {
|
|
||||||
return Math.round(ms / s) + 's';
|
|
||||||
}
|
|
||||||
return ms + 'ms';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Long format for `ms`.
|
|
||||||
*
|
|
||||||
* @param {Number} ms
|
|
||||||
* @return {String}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
function fmtLong(ms) {
|
|
||||||
var msAbs = Math.abs(ms);
|
|
||||||
if (msAbs >= d) {
|
|
||||||
return plural(ms, msAbs, d, 'day');
|
|
||||||
}
|
|
||||||
if (msAbs >= h) {
|
|
||||||
return plural(ms, msAbs, h, 'hour');
|
|
||||||
}
|
|
||||||
if (msAbs >= m) {
|
|
||||||
return plural(ms, msAbs, m, 'minute');
|
|
||||||
}
|
|
||||||
if (msAbs >= s) {
|
|
||||||
return plural(ms, msAbs, s, 'second');
|
|
||||||
}
|
|
||||||
return ms + ' ms';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pluralization helper.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function plural(ms, msAbs, n, name) {
|
|
||||||
var isPlural = msAbs >= n * 1.5;
|
|
||||||
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2016 Zeit, Inc.
|
|
||||||
|
|
||||||
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