File tree 3 files changed +31
-4
lines changed
3 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -36,10 +36,19 @@ globParent('path/foo'); // 'path' (see issue #3 for details)
36
36
37
37
## API
38
38
39
- ### ` globParent(maybeGlobString) `
39
+ ### ` globParent(maybeGlobString, [options] ) `
40
40
41
41
Takes a string and returns the part of the path before the glob begins. Be aware of Escaping rules and Limitations below.
42
42
43
+ #### options
44
+
45
+ ``` js
46
+ {
47
+ // Disables the automatic conversion of slashes for Windows
48
+ flipBackslashes: true
49
+ }
50
+ ```
51
+
43
52
## Escaping
44
53
45
54
The following characters have special significance in glob patterns and must be escaped if you want them to be treated as regular path characters:
Original file line number Diff line number Diff line change @@ -10,9 +10,16 @@ var enclosure = /[\{\[].*[\/]*.*[\}\]]$/;
10
10
var globby = / ( ^ | [ ^ \\ ] ) ( [ \{ \[ ] | \( [ ^ \) ] + $ ) / ;
11
11
var escaped = / \\ ( [ \* \? \| \[ \] \( \) \{ \} ] ) / g;
12
12
13
- module . exports = function globParent ( str ) {
13
+ /**
14
+ * @param {string } str
15
+ * @param {Object } opts
16
+ * @param {boolean } [opts.flipBackslashes=true]
17
+ */
18
+ module . exports = function globParent ( str , opts ) {
19
+ var options = Object . assign ( { flipBackslashes : true } , opts ) ;
20
+
14
21
// flip windows path separators
15
- if ( isWin32 && str . indexOf ( slash ) < 0 ) {
22
+ if ( options . flipBackslashes && isWin32 && str . indexOf ( slash ) < 0 ) {
16
23
str = str . replace ( backslash , slash ) ;
17
24
}
18
25
Original file line number Diff line number Diff line change @@ -84,7 +84,12 @@ describe('glob-parent', function() {
84
84
assert . equal ( gp ( '\\{foo,bar}/' ) , '{foo,bar}' ) ;
85
85
assert . equal ( gp ( '\\{foo,bar\\}/' ) , '{foo,bar}' ) ;
86
86
assert . equal ( gp ( '{foo,bar\\}/' ) , '.' ) ;
87
- if ( ! isWin32 ) {
87
+
88
+ if ( isWin32 ) {
89
+ // On Windows we are trying to flip backslashes foo-\\( → foo-/(
90
+ assert . equal ( gp ( 'foo-\\(bar\\).md' ) , 'foo-' ) ;
91
+ } else {
92
+ assert . equal ( gp ( 'foo-\\(bar\\).md' ) , '.' ) ;
88
93
assert . equal ( gp ( '\\[bar]' ) , '[bar]' ) ;
89
94
assert . equal ( gp ( '[bar\\]' ) , '.' ) ;
90
95
assert . equal ( gp ( '\\{foo,bar\\}' ) , '{foo,bar}' ) ;
@@ -135,6 +140,12 @@ describe('glob-parent', function() {
135
140
136
141
done ( ) ;
137
142
} ) ;
143
+
144
+ it ( 'should respect disabled auto flip backslashes' , function ( done ) {
145
+ assert . equal ( gp ( 'foo-\\(bar\\).md' , { flipBackslashes : false } ) , '.' ) ;
146
+
147
+ done ( ) ;
148
+ } ) ;
138
149
} ) ;
139
150
140
151
describe ( 'glob2base test patterns' , function ( ) {
You can’t perform that action at this time.
0 commit comments