File tree 2 files changed +53
-0
lines changed
2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,13 @@ const {
47
47
validateString,
48
48
} = require ( 'internal/validators' ) ;
49
49
50
+
51
+ let minimatch ;
52
+ function lazyMinimatch ( ) {
53
+ minimatch ??= require ( 'internal/deps/minimatch/index' ) ;
54
+ return minimatch ;
55
+ }
56
+
50
57
const platformIsWin32 = ( process . platform === 'win32' ) ;
51
58
52
59
function isPathSeparator ( code ) {
@@ -153,6 +160,23 @@ function _format(sep, pathObject) {
153
160
return dir === pathObject . root ? `${ dir } ${ base } ` : `${ dir } ${ sep } ${ base } ` ;
154
161
}
155
162
163
+
164
+ /**
165
+ * @param {string } path
166
+ * @returns {Function }
167
+ */
168
+ function glob ( pattern ) {
169
+ return lazyMinimatch ( ) . filter ( pattern ) ;
170
+ }
171
+
172
+ /**
173
+ * @param {string } path
174
+ * @returns {RegExp }
175
+ */
176
+ function globToRegExp ( pattern ) {
177
+ return lazyMinimatch ( ) . makeRe ( pattern ) ;
178
+ }
179
+
156
180
const win32 = {
157
181
/**
158
182
* path.resolve([from ...], to)
@@ -1064,6 +1088,8 @@ const win32 = {
1064
1088
1065
1089
return ret ;
1066
1090
} ,
1091
+ glob,
1092
+ globToRegExp,
1067
1093
1068
1094
sep : '\\' ,
1069
1095
delimiter : ';' ,
@@ -1530,6 +1556,8 @@ const posix = {
1530
1556
1531
1557
return ret ;
1532
1558
} ,
1559
+ glob,
1560
+ globToRegExp,
1533
1561
1534
1562
sep : '/' ,
1535
1563
delimiter : ':' ,
Original file line number Diff line number Diff line change
1
+ import { describe , it } from 'node:test' ;
2
+ import * as assert from 'node:assert' ;
3
+ import * as path from 'node:path' ;
4
+
5
+ describe ( 'path.glob' , ( ) => {
6
+ it ( 'should return a filter function' , ( ) => {
7
+ const fn = path . glob ( '*.js' ) ;
8
+ assert . strictEqual ( typeof fn , 'function' ) ;
9
+ } ) ;
10
+ it ( 'should return a filter function that matches the glob' , ( ) => {
11
+ const fn = path . glob ( '*.js' ) ;
12
+ assert . strictEqual ( fn ( 'foo.js' ) , true ) ;
13
+ } ) ;
14
+ } ) ;
15
+
16
+ describe ( 'path.globToRegExp' , ( ) => {
17
+ it ( 'should return a RegExp' , ( ) => {
18
+ const re = path . globToRegExp ( 'foo' ) ;
19
+ assert . strictEqual ( re instanceof RegExp , true ) ;
20
+ } ) ;
21
+ it ( 'should return a RegExp that matches the glob' , ( ) => {
22
+ const re = path . globToRegExp ( '*.js' ) ;
23
+ assert . strictEqual ( re . test ( 'foo.js' ) , true ) ;
24
+ } )
25
+ } ) ;
You can’t perform that action at this time.
0 commit comments