tomzx / arry

A set of methods to work on arrays.
MIT License
3 stars 1 forks source link

Support for glob syntax #1

Open tomzx opened 9 years ago

tomzx commented 9 years ago

Specifically:

Extension

See https://en.wikipedia.org/wiki/Glob_(programming)

tomzx commented 9 years ago

Glob Primer

"Globs" are the patterns you type when you do stuff like ls *.js on the command line, or put build/* in a .gitignore file.

Before parsing the path part patterns, braced sections are expanded into a set. Braced sections start with { and end with }, with any number of comma-delimited sections within. Braced sections may contain slash characters, so a{/b/c,bcd} would expand into a/b/c and abc.

The following characters have special magic meaning when used in a path portion:

Dots

If a file or directory path portion has a . as the first character, then it will not match any glob pattern unless that pattern's corresponding path part also has a . as its first character.

For example, the pattern a/.*/c would match the file at a/.b/c. However the pattern a/*/c would not, because * does not start with a dot character.

You can make glob treat dots as normal characters by setting dot:true in the options.

Basename Matching

If you set matchBase:true in the options, and the pattern has no slashes in it, then it will seek for any file anywhere in the tree with a matching basename. For example, *.js would match test/simple/basic.js.

Negation

The intent for negation would be for a pattern starting with ! to match everything that doesn't match the supplied pattern. However, the implementation is weird, and for the time being, this should be avoided. The behavior will change or be deprecated in version 5.

Empty Sets

If no matching files are found, then an empty array is returned. This differs from the shell, where the pattern itself is returned. For example:

$ echo a*s*d*f
a*s*d*f

To get the bash-style behavior, set the nonull:true in the options.

See Also:

Source: https://github.com/isaacs/node-glob/blob/master/README.md