0423060b6c930d6f57715676d64936b70ef1b7672440d22f684fe810a102dd9498964069f30b3c04aed1926e9cd41106eda5cce494976fc2f51028639609f7 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # @isaacs/brace-expansion
  2. A hybrid CJS/ESM TypeScript fork of
  3. [brace-expansion](http://npm.im/brace-expansion).
  4. [Brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html),
  5. as known from sh/bash, in JavaScript.
  6. [![CI](https://github.com/juliangruber/brace-expansion/actions/workflows/ci.yml/badge.svg)](https://github.com/juliangruber/brace-expansion/actions/workflows/ci.yml)
  7. [![downloads](https://img.shields.io/npm/dm/brace-expansion.svg)](https://www.npmjs.org/package/brace-expansion)
  8. ## Example
  9. ```js
  10. import { expand } from '@isaacs/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. import { expand } from '@isaacs/brace-expansion'
  35. ```
  36. ### const 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.