File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,13 @@ const {
4747 validateString,
4848} = require ( 'internal/validators' ) ;
4949
50+
51+ let minimatch ;
52+ function lazyMinimatch ( ) {
53+ minimatch ??= require ( 'internal/deps/minimatch/index' ) ;
54+ return minimatch ;
55+ }
56+
5057const platformIsWin32 = ( process . platform === 'win32' ) ;
5158
5259function isPathSeparator ( code ) {
@@ -153,6 +160,23 @@ function _format(sep, pathObject) {
153160 return dir === pathObject . root ? `${ dir } ${ base } ` : `${ dir } ${ sep } ${ base } ` ;
154161}
155162
163+
164+ /**
165+ * @param {string } pattern
166+ * @returns {Function }
167+ */
168+ function glob ( pattern ) {
169+ return lazyMinimatch ( ) . filter ( pattern ) ;
170+ }
171+
172+ /**
173+ * @param {string } pattern
174+ * @returns {RegExp }
175+ */
176+ function globToRegExp ( pattern ) {
177+ return lazyMinimatch ( ) . makeRe ( pattern ) ;
178+ }
179+
156180const win32 = {
157181 /**
158182 * path.resolve([from ...], to)
@@ -1064,6 +1088,8 @@ const win32 = {
10641088
10651089 return ret ;
10661090 } ,
1091+ glob,
1092+ globToRegExp,
10671093
10681094 sep : '\\' ,
10691095 delimiter : ';' ,
@@ -1530,6 +1556,8 @@ const posix = {
15301556
15311557 return ret ;
15321558 } ,
1559+ glob,
1560+ globToRegExp,
15331561
15341562 sep : '/' ,
15351563 delimiter : ':' ,
Original file line number Diff line number Diff line change 1+ import '../common/index.mjs' ;
2+ import { describe , it } from 'node:test' ;
3+ import * as assert from 'node:assert' ;
4+ import * as path from 'node:path' ;
5+
6+ describe ( 'path.glob' , ( ) => {
7+ it ( 'should return a filter function' , ( ) => {
8+ const fn = path . glob ( '*.js' ) ;
9+ assert . strictEqual ( typeof fn , 'function' ) ;
10+ } ) ;
11+ it ( 'should return a filter function that matches the glob' , ( ) => {
12+ const fn = path . glob ( '*.js' ) ;
13+ assert . strictEqual ( fn ( 'foo.js' ) , true ) ;
14+ } ) ;
15+ } ) ;
16+
17+ describe ( 'path.globToRegExp' , ( ) => {
18+ it ( 'should return a RegExp' , ( ) => {
19+ const re = path . globToRegExp ( 'foo' ) ;
20+ assert . strictEqual ( re instanceof RegExp , true ) ;
21+ } ) ;
22+ it ( 'should return a RegExp that matches the glob' , ( ) => {
23+ const re = path . globToRegExp ( '*.js' ) ;
24+ assert . strictEqual ( re . test ( 'foo.js' ) , true ) ;
25+ } ) ;
26+ } ) ;
You can’t perform that action at this time.
0 commit comments