├── .gitignore ├── package.json ├── test.js ├── makedoc.js ├── README.md └── data.json /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minimatch-cheat-sheet", 3 | "version": "0.0.0", 4 | "description": "minimatch cheat sheet", 5 | "author": "motemen ", 6 | "devDependencies": { 7 | "minimatch": "^3.0.4", 8 | "chai": "^4.2.0", 9 | "tap": "^12.0.1", 10 | "lodash": "^4.17.11" 11 | }, 12 | "scripts": { 13 | "test": "node test", 14 | "makedoc": "node makedoc > README.md" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | var minimatch = require('minimatch'); 2 | var tap = require('tap'); 3 | var _ = require('lodash'); 4 | 5 | var data = require('./data.json'); 6 | 7 | _.forEach(data, function (entry) { 8 | tap.test('# ' + entry.section + '\n' + entry.description.join('\n'), function (t) { 9 | entry.examples.forEach(function (e) { 10 | var p = e[0], oks = e[1], ngs = e[2]; 11 | oks.forEach(function (ok) { 12 | t.ok(+minimatch(ok, p), '"' + p + '" =~ "' + ok + '"'); 13 | }); 14 | ngs.forEach(function (ng) { 15 | t.ok(!minimatch(ng, p), '"' + p + '" !~ "' + ng + '"'); 16 | }); 17 | }); 18 | 19 | t.end(); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /makedoc.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | 3 | var data = require('./data.json'); 4 | 5 | function codify (str) { 6 | if (str.indexOf('|') === -1) { 7 | return '`' + str + '`'; 8 | } else { 9 | return '' + str.replace(/\|/, '|') + ''; 10 | } 11 | } 12 | 13 | console.log('# minimatch-cheat-sheet'); 14 | console.log(''); 15 | console.log('A cheat sheet for [minimatch](https://github.com/isaacs/minimatch).'); 16 | console.log(''); 17 | 18 | _.forEach(data, function (entry) { 19 | console.log('## ' + entry.section); 20 | console.log(''); 21 | 22 | entry.description.forEach(function (desc) { 23 | console.log('- ' + desc); 24 | }); 25 | console.log(''); 26 | 27 | console.log('| Pattern | Matches | Does not match |'); 28 | console.log('| ------- | ------- | -------------- |'); 29 | entry.examples.forEach(function (ex) { 30 | var row = [ 31 | codify(ex[0]), 32 | ex[1].map(codify).join(', '), 33 | ex[2].map(codify).join(', '), 34 | ].join(' | '); 35 | console.log('| ' + row + ' |'); 36 | }); 37 | console.log(''); 38 | }); 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # minimatch-cheat-sheet 2 | 3 | A cheat sheet for [minimatch](https://github.com/isaacs/minimatch). 4 | 5 | ## Basic 6 | 7 | - `*` matches any string, not including than path separator 8 | - `**` matches any string, including path separators 9 | - `?` matches single character other than path separator 10 | 11 | | Pattern | Matches | Does not match | 12 | | ------- | ------- | -------------- | 13 | | `xxx.*` | `xxx.yyy`, `xxx.y.z` | `abcxxx.yyy`, `xxx.y/z` | 14 | | `xxx/*/yyy` | `xxx/abc/yyy` | `xxx/yyy`, `xxx/abc/def/yyy`, `xxx/.abc/yyy` | 15 | | `xxx/**/yyy` | `xxx/abc/yyy`, `xxx/yyy`, `xxx/abc/def/yyy` | `xxx/.abc/yyy` | 16 | | `xxx/**yyy` | `xxx/yyy` | `xxx/abc/yyy`, `xxx/abc/def/yyy`, `xxx/.abc/yyy` | 17 | | `x?y` | `xAy` | `xy`, `xABy`, `x/y` | 18 | 19 | ## Braces 20 | 21 | - `{foo,bar}` matches "foo" and "bar" 22 | - `{1..3}` matches "1", "2" and "3" 23 | 24 | | Pattern | Matches | Does not match | 25 | | ------- | ------- | -------------- | 26 | | `{foo,bar}` | `foo`, `bar` | `baz` | 27 | | `{x,y/*}/z` | `x/z`, `y/a/z` | `y/z` | 28 | | `foo{1..3}` | `foo1`, `foo2`, `foo3` | `foo`, `foo0` | 29 | 30 | ## Negation 31 | 32 | - `!`-prefixed patterns invert match 33 | 34 | | Pattern | Matches | Does not match | 35 | | ------- | ------- | -------------- | 36 | | `!abc` | `a`, `xyz` | `abc` | 37 | 38 | ## Comments 39 | 40 | - `#`-prefixed patterns are treated as comments and match nothing 41 | - `\#` to escape 42 | 43 | | Pattern | Matches | Does not match | 44 | | ------- | ------- | -------------- | 45 | | `#abc` | | `abc`, `#abc` | 46 | | `\#abc` | `#abc` | `abc` | 47 | 48 | ## Extglob 49 | 50 | - `+(pattern)` matches one or more repetition of pattern (like `/(pattern)+/`) 51 | - `*(pattern)` matches zero or more repetition of pattern (like `/(pattern)*/`) 52 | - `?(pattern)` matches zero or one repetition of pattern (like `/(pattern)?/`) 53 | - `@(pattern)` matches pattern (like `/(pattern)/`) 54 | - `!(pattern)` matches anything except the pattern (like `/(?!pattern)/`) 55 | - pattern can be joined by `|` (like `/(foo|bar)/`) 56 | 57 | | Pattern | Matches | Does not match | 58 | | ------- | ------- | -------------- | 59 | | `a+(xy)` | `axy`, `axyxy` | `a` | 60 | | `a*(xy)` | `a`, `axy`, `axyxy` | | 61 | | `a@(xy)` | `axy` | `a`, `axyxy` | 62 | | `a!(xy)` | `ax` | `axy`, `axyz` | 63 | | a+(x|y*z) | `axx`, `ayzxyzxx`, `axyAAAz` | `axy`, `a` | 64 | 65 | -------------------------------------------------------------------------------- /data.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "section": "Basic", 4 | "description": [ 5 | "`*` matches any string, not including than path separator", 6 | "`**` matches any string, including path separators", 7 | "`?` matches single character other than path separator" 8 | ], 9 | "examples": [ 10 | [ 11 | "xxx.*", 12 | [ 13 | "xxx.yyy", 14 | "xxx.y.z" 15 | ], 16 | [ 17 | "abcxxx.yyy", 18 | "xxx.y/z" 19 | ] 20 | ], 21 | [ 22 | "xxx/*/yyy", 23 | [ 24 | "xxx/abc/yyy" 25 | ], 26 | [ 27 | "xxx/yyy", 28 | "xxx/abc/def/yyy", 29 | "xxx/.abc/yyy" 30 | ] 31 | ], 32 | [ 33 | "xxx/**/yyy", 34 | [ 35 | "xxx/abc/yyy", 36 | "xxx/yyy", 37 | "xxx/abc/def/yyy" 38 | ], 39 | [ 40 | "xxx/.abc/yyy" 41 | ] 42 | ], 43 | [ 44 | "xxx/**yyy", 45 | [ 46 | "xxx/yyy" 47 | ], 48 | [ 49 | "xxx/abc/yyy", 50 | "xxx/abc/def/yyy", 51 | "xxx/.abc/yyy" 52 | ] 53 | ], 54 | [ 55 | "x?y", 56 | [ 57 | "xAy" 58 | ], 59 | [ 60 | "xy", 61 | "xABy", 62 | "x/y" 63 | ] 64 | ] 65 | ] 66 | }, 67 | { 68 | "section": "Braces", 69 | "description": [ 70 | "`{foo,bar}` matches \"foo\" and \"bar\"", 71 | "`{1..3}` matches \"1\", \"2\" and \"3\"" 72 | ], 73 | "examples": [ 74 | [ 75 | "{foo,bar}", 76 | [ 77 | "foo", 78 | "bar" 79 | ], 80 | [ 81 | "baz" 82 | ] 83 | ], 84 | [ 85 | "{x,y/*}/z", 86 | [ 87 | "x/z", 88 | "y/a/z" 89 | ], 90 | [ 91 | "y/z" 92 | ] 93 | ], 94 | [ 95 | "foo{1..3}", 96 | [ 97 | "foo1", 98 | "foo2", 99 | "foo3" 100 | ], 101 | [ 102 | "foo", 103 | "foo0" 104 | ] 105 | ] 106 | ] 107 | }, 108 | { 109 | "section": "Negation", 110 | "description": [ 111 | "`!`-prefixed patterns invert match" 112 | ], 113 | "examples": [ 114 | [ 115 | "!abc", 116 | [ 117 | "a", 118 | "xyz" 119 | ], 120 | [ 121 | "abc" 122 | ] 123 | ] 124 | ] 125 | }, 126 | { 127 | "section": "Comments", 128 | "description": [ 129 | "`#`-prefixed patterns are treated as comments and match nothing", 130 | "`\\#` to escape" 131 | ], 132 | "examples": [ 133 | [ 134 | "#abc", 135 | [], 136 | [ 137 | "abc", 138 | "#abc" 139 | ] 140 | ], 141 | [ 142 | "\\#abc", 143 | [ 144 | "#abc" 145 | ], 146 | [ 147 | "abc" 148 | ] 149 | ] 150 | ] 151 | }, 152 | { 153 | "section": "Extglob", 154 | "description": [ 155 | "`+(pattern)` matches one or more repetition of pattern (like `/(pattern)+/`)", 156 | "`*(pattern)` matches zero or more repetition of pattern (like `/(pattern)*/`)", 157 | "`?(pattern)` matches zero or one repetition of pattern (like `/(pattern)?/`)", 158 | "`@(pattern)` matches pattern (like `/(pattern)/`)", 159 | "`!(pattern)` matches anything except the pattern (like `/(?!pattern)/`)", 160 | "pattern can be joined by `|` (like `/(foo|bar)/`)" 161 | ], 162 | "examples": [ 163 | [ 164 | "a+(xy)", 165 | [ 166 | "axy", 167 | "axyxy" 168 | ], 169 | [ 170 | "a" 171 | ] 172 | ], 173 | [ 174 | "a*(xy)", 175 | [ 176 | "a", 177 | "axy", 178 | "axyxy" 179 | ], 180 | [] 181 | ], 182 | [ 183 | "a@(xy)", 184 | [ 185 | "axy" 186 | ], 187 | [ 188 | "a", 189 | "axyxy" 190 | ] 191 | ], 192 | [ 193 | "a!(xy)", 194 | [ 195 | "ax" 196 | ], 197 | [ 198 | "axy", 199 | "axyz" 200 | ] 201 | ], 202 | [ 203 | "a+(x|y*z)", 204 | [ 205 | "axx", 206 | "ayzxyzxx", 207 | "axyAAAz" 208 | ], 209 | [ 210 | "axy", 211 | "a" 212 | ] 213 | ] 214 | ] 215 | } 216 | ] 217 | --------------------------------------------------------------------------------