micromatch / braces

Faster brace expansion for node.js. Besides being faster, braces is not subject to DoS attacks like minimatch, is more accurate, and has more complete support for Bash 4.3.
https://github.com/jonschlinkert
MIT License
220 stars 61 forks source link

need escape `\` backslash or `{` #4

Closed tunnckoCore closed 9 years ago

tunnckoCore commented 9 years ago

We need something like this

writeFixture('fixture.js', 'benchmark/fixtures/a/{b,{c,d},e/d}/*.\{js,md,txt\}');
//=> [
  "benchmark/fixtures/a/b/*.{js,md,txt}",
  "benchmark/fixtures/a/c/*.{js,md,txt}",
  "benchmark/fixtures/a/e/d/*.{js,md,txt}",
  "benchmark/fixtures/a/d/*.{js,md,txt}"
]

then we can pass the string to globbing lib, eg micromatch.

With single slash it removes it, with two \\, not works. The result is

//=> [
  "benchmark/fixtures/a/b/*.\\{js,md,txt\\}",
  "benchmark/fixtures/a/c/*.\\{js,md,txt\\}",
  "benchmark/fixtures/a/e/d/*.\\{js,md,txt\\}",
  "benchmark/fixtures/a/d/*.\\{js,md,txt\\}"
]
tunnckoCore commented 9 years ago

@jonschlinkert I realize that we have this feature with {"js,md,txt"} syntax. Actually, need to escape \ (backslash).

tunnckoCore commented 9 years ago

hm...

tunnckoCore commented 9 years ago

I want/expect this result:

[
   'a/b/*.{js,md,txt}',
   'a/c/*.{js,md,txt}',
   'a/e/d/*.{js,md,txt}',
   'a/d/*.{js,md,txt}'
]

how?

var braces = require('braces');
braces('a/{b,{c,d},e/d}/*.{"js,md,txt"}')
//=> [ 'a/{b,{c,d},e/d}/*.{js,md,txt}' ]

expand nothing.

jonschlinkert commented 9 years ago

What is the use case?

Sent from my iPhone

On Jan 17, 2015, at 9:48 AM, Charlike Mike Reagent notifications@github.com wrote:

I want/expect this result:

[ 'a/b/.{js,md,txt}', 'a/c/.{js,md,txt}', 'a/e/d/.{js,md,txt}', 'a/d/.{js,md,txt}' ] how?

var braces = require('braces'); braces('a/{b,{c,d},e/d}/.{"js,md,txt"}') //=> [ 'a/{b,{c,d},e/d}/.{js,md,txt}' ] expand nothing.

— Reply to this email directly or view it on GitHub.

tunnckoCore commented 9 years ago

Generating fixtures, lol.

Because (shown above)

writeFixture('short.js', 'fixtures/a/{b,{c,d},e/d}/*.{js,md,txt}');

results

[
  "fixtures/a/b/*.js",
  "fixtures/a/c/*.js",
  "fixtures/a/e/d/*.js",
  "fixtures/a/d/*.js",
  "fixtures/a/b/*.md",
  "fixtures/a/c/*.md",
  "fixtures/a/e/d/*.md",
  "fixtures/a/d/*.md",
  "fixtures/a/b/*.txt",
  "fixtures/a/c/*.txt",
  "fixtures/a/e/d/*.txt",
  "fixtures/a/d/*.txt"
]

too much, in one side; on other hand purpose is to pass it then to matching lib (or glob-fs, cuz im workin on somthing) huh..

Okey, again, lol. In one hand, we can use one pattern to generate file system fixtures and in another hand with same pattern to generate string fixtures (patterns) that we can pass to matching lib.

Or in short: reusing (same) patterns

:-1: for me today ;d

tunnckoCore commented 9 years ago
writeFixture('short.js', 'fixtures/a/{b,{c,d},e/d}/*.{"js,md,txt"}');
fixtures/a/b/file-a-b.js
fixtures/a/b/file-a-b.md
fixtures/a/b/file-a-b.txt

fixtures/a/c/file-a-c.js
fixtures/a/c/file-a-c.md
fixtures/a/c/file-a-c.txt

fixtures/a/d/file-a-d.js
fixtures/a/d/file-a-d.md
fixtures/a/d/file-a-d.txt

fixtures/a/e/d/file-a-e-d.js
fixtures/a/e/d/file-a-e-d.md
fixtures/a/e/d/file-a-e-d.txt
module.exports = [
  [
     'fixtures/a/b/*.{js,md,txt}',
     'fixtures/a/c/*.{js,md,txt}',
     'fixtures/a/e/d/*.{js,md,txt}',
     'fixtures/a/d/*.{js,md,txt}'
  ]
];

then we can "reuse" the pattern

With one pattern, two jobs.

jonschlinkert commented 9 years ago

Try using the makeRe option. I'll link to it in a bit

Sent from my iPhone

On Jan 17, 2015, at 12:58 PM, Charlike Mike Reagent notifications@github.com wrote:

writeFixture('short.js', 'fixtures/a/{b,{c,d},e/d}/*.{"js,md,txt"}'); (step one) generates file system files and folders, structured fixtures/a/b/file-a-b.js fixtures/a/c/file-a-c.js fixtures/a/e/d/file-a-e-d.js fixtures/a/d/file-a-d.js

fixtures/a/b/file-a-b.md fixtures/a/c/file-a-c.md fixtures/a/e/d/file-a-e-d.md fixtures/a/d/file-a-d.md

fixtures/a/b/file-a-b.txt fixtures/a/c/file-a-c.txt fixtures/a/e/d/file-a-e-d.txt fixtures/a/d/file-a-d.txt (step two) creates short.js with content module.exports = [ [ 'fixtures/a/b/.{js,md,txt}', 'fixtures/a/c/.{js,md,txt}', 'fixtures/a/e/d/.{js,md,txt}', 'fixtures/a/d/.{js,md,txt}' ] ]; then we can "reuse" the (semi-expanded) pattern

— Reply to this email directly or view it on GitHub.

jonschlinkert commented 9 years ago

are you using a single backslash, or two? when you escape in a string you need \\. see https://github.com/jonschlinkert/braces/blob/master/test/test.js#L154-L181.

Seems like there might be a better way to do what you're trying to achieve. If not, then we can add as a feature request.

jonschlinkert commented 9 years ago

Generating fixtures,

and yeah, I got that lol. What I meant earlier was, why are you trying to "half" expand the globs? it seems over-engineered. Just make two patterns for each test - one to create the fixtures and one to match them.

tunnckoCore commented 9 years ago

it seems over-engineered

Maybe, lol. Nevermind, I'll clear the situation in my head ;d

Thanks!