You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 4.0 KiB

10 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # brace-expansion
  2. [Brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html),
  3. as known from sh/bash, in JavaScript.
  4. [![build status](https://secure.travis-ci.org/juliangruber/brace-expansion.svg)](http://travis-ci.org/juliangruber/brace-expansion)
  5. [![downloads](https://img.shields.io/npm/dm/brace-expansion.svg)](https://www.npmjs.org/package/brace-expansion)
  6. [![Greenkeeper badge](https://badges.greenkeeper.io/juliangruber/brace-expansion.svg)](https://greenkeeper.io/)
  7. [![testling badge](https://ci.testling.com/juliangruber/brace-expansion.png)](https://ci.testling.com/juliangruber/brace-expansion)
  8. ## Example
  9. ```js
  10. var expand = require('brace-expansion');
  11. expand('file-{a,b,c}.jpg')
  12. // => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']
  13. expand('-v{,,}')
  14. // => ['-v', '-v', '-v']
  15. expand('file{0..2}.jpg')
  16. // => ['file0.jpg', 'file1.jpg', 'file2.jpg']
  17. expand('file-{a..c}.jpg')
  18. // => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']
  19. expand('file{2..0}.jpg')
  20. // => ['file2.jpg', 'file1.jpg', 'file0.jpg']
  21. expand('file{0..4..2}.jpg')
  22. // => ['file0.jpg', 'file2.jpg', 'file4.jpg']
  23. expand('file-{a..e..2}.jpg')
  24. // => ['file-a.jpg', 'file-c.jpg', 'file-e.jpg']
  25. expand('file{00..10..5}.jpg')
  26. // => ['file00.jpg', 'file05.jpg', 'file10.jpg']
  27. expand('{{A..C},{a..c}}')
  28. // => ['A', 'B', 'C', 'a', 'b', 'c']
  29. expand('ppp{,config,oe{,conf}}')
  30. // => ['ppp', 'pppconfig', 'pppoe', 'pppoeconf']
  31. ```
  32. ## API
  33. ```js
  34. var expand = require('brace-expansion');
  35. ```
  36. ### var expanded = expand(str)
  37. Return an array of all possible and valid expansions of `str`. If none are
  38. found, `[str]` is returned.
  39. Valid expansions are:
  40. ```js
  41. /^(.*,)+(.+)?$/
  42. // {a,b,...}
  43. ```
  44. A comma separated list of options, like `{a,b}` or `{a,{b,c}}` or `{,a,}`.
  45. ```js
  46. /^-?\d+\.\.-?\d+(\.\.-?\d+)?$/
  47. // {x..y[..incr]}
  48. ```
  49. A numeric sequence from `x` to `y` inclusive, with optional increment.
  50. If `x` or `y` start with a leading `0`, all the numbers will be padded
  51. to have equal length. Negative numbers and backwards iteration work too.
  52. ```js
  53. /^-?\d+\.\.-?\d+(\.\.-?\d+)?$/
  54. // {x..y[..incr]}
  55. ```
  56. An alphabetic sequence from `x` to `y` inclusive, with optional increment.
  57. `x` and `y` must be exactly one character, and if given, `incr` must be a
  58. number.
  59. For compatibility reasons, the string `${` is not eligible for brace expansion.
  60. ## Installation
  61. With [npm](https://npmjs.org) do:
  62. ```bash
  63. npm install brace-expansion
  64. ```
  65. ## Contributors
  66. - [Julian Gruber](https://github.com/juliangruber)
  67. - [Isaac Z. Schlueter](https://github.com/isaacs)
  68. ## Sponsors
  69. This module is proudly supported by my [Sponsors](https://github.com/juliangruber/sponsors)!
  70. 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)!
  71. ## License
  72. (MIT)
  73. Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
  74. Permission is hereby granted, free of charge, to any person obtaining a copy of
  75. this software and associated documentation files (the "Software"), to deal in
  76. the Software without restriction, including without limitation the rights to
  77. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  78. of the Software, and to permit persons to whom the Software is furnished to do
  79. so, subject to the following conditions:
  80. The above copyright notice and this permission notice shall be included in all
  81. copies or substantial portions of the Software.
  82. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  83. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  84. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  85. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  86. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  87. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  88. SOFTWARE.