-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
cb9e944
commit c08ae10
Showing
13 changed files
with
202 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
attw | ||
barx | ||
cefc | ||
codecov | ||
commitlintrc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* @file Functional Tests - matchesGlob | ||
* @module pathe/lib/tests/functional/matchesGlob | ||
* @see https://github.com/nodejs/node/blob/v22.8.0/test/parallel/test-path-glob.js | ||
*/ | ||
|
||
import process from '#internal/process' | ||
import micromatch from 'micromatch' | ||
import type { MockInstance } from 'vitest' | ||
import testSubject from '../matches-glob' | ||
import toPosix from '../to-posix' | ||
|
||
describe('functional:lib/matchesGlob', () => { | ||
let spy: MockInstance<typeof micromatch['isMatch']> | ||
|
||
beforeEach(() => { | ||
spy = vi.spyOn(micromatch, 'isMatch') | ||
}) | ||
|
||
it.each<Parameters<typeof testSubject>>([ | ||
['foo/bar/baz', 'foo/**'], | ||
['foo/bar/baz', 'foo/*/!bar/*/baz'], | ||
['foo/bar/baz', 'foo/[!bcr]ar/baz'], | ||
['foo/bar/baz', 'foo/[bc-r]ar/baz'], | ||
['foo/bar/baz', 'foo/[bcr]ar/baz'], | ||
['foo/bar/baz/boo', 'foo/[bc-r]ar/baz/*', { ignore: 'f*' }], | ||
['foo/bar/baz/boo', 'foo/[bc-r]ar/baz/*'], | ||
['foo/bar1/baz', 'foo/bar[0-9]/baz'], | ||
['foo/bar5/baz', 'foo/bar[0-9]/baz'], | ||
['foo/barx/baz', 'foo/bar[a-z]/baz'], | ||
['foo\\bar1\\baz', ['foo/bar[0-9]/baz']], | ||
['foo\\bar1\\baz', ['foo\\bar[0-9]\\baz']], | ||
['foo\\bar5\\baz', ['foo/bar[0-9]/baz']], | ||
['foo\\bar5\\baz', ['foo\\bar[0-9]\\baz']], | ||
['foo\\bar\\baz', 'foo\\*\\!bar\\*\\baz'], | ||
['foo\\bar\\baz', 'foo\\[!bcr]ar\\baz'], | ||
['foo\\bar\\baz', ['foo/**']], | ||
['foo\\bar\\baz', ['foo/[bc-r]ar/baz']], | ||
['foo\\bar\\baz', ['foo/[bcr]ar/baz']], | ||
['foo\\bar\\baz', ['foo\\**']], | ||
['foo\\bar\\baz', ['foo\\[bc-r]ar\\baz']], | ||
['foo\\bar\\baz', ['foo\\[bcr]ar\\baz']], | ||
['foo\\bar\\baz\\boo', 'foo\\[bc-r]ar\\baz\\*', { ignore: 'f*' }], | ||
['foo\\bar\\baz\\boo', ['foo/[bc-r]ar/baz/*']], | ||
['foo\\bar\\baz\\boo', ['foo\\[bc-r]ar\\baz\\*']], | ||
['foo\\barx\\baz', ['foo/bar[a-z]/baz']], | ||
['foo\\barx\\baz', ['foo\\bar[a-z]\\baz']] | ||
])('should call `micromatch.isMatch` (%#)', (path, pattern, options) => { | ||
// Arrange | ||
const pat: typeof pattern = Array.isArray(pattern) | ||
? pattern | ||
: toPosix(pattern) | ||
|
||
// Act | ||
testSubject(path, pattern, options) | ||
|
||
// Expect | ||
expect(spy).toHaveBeenCalledOnce() | ||
expect(spy.mock.lastCall?.[0]).to.eq(toPosix(path)) | ||
expect(spy.mock.lastCall?.[1]).to.eq(pat) | ||
expect(spy.mock.lastCall?.[2]).to.eql({ ...options, cwd: process.cwd() }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* @file matchesGlob | ||
* @module pathe/lib/matchesGlob | ||
*/ | ||
|
||
import process from '#internal/process' | ||
import validateString from '#internal/validate-string' | ||
import micromatch from 'micromatch' | ||
import toPosix from './to-posix' | ||
|
||
/** | ||
* Check if `path` matches `pattern`. | ||
* | ||
* @see {@linkcode micromatch.Options} | ||
* @see {@linkcode micromatch.isMatch} | ||
* | ||
* @category | ||
* core | ||
* | ||
* @param {string} path | ||
* The path to glob-match against | ||
* @param {string | string[]} pattern | ||
* Glob patterns to use for matching | ||
* @param {micromatch.Options | null | undefined} [options] | ||
* Options for matching | ||
* @return {boolean} | ||
* `true` if `path` matches `pattern`, `false` otherwise | ||
*/ | ||
function matchesGlob( | ||
path: string, | ||
pattern: string | string[], | ||
options?: micromatch.Options | null | undefined | ||
): boolean { | ||
validateString(path, 'path') | ||
|
||
if (Array.isArray<string>(pattern)) { | ||
/** | ||
* Current index in {@linkcode pattern}. | ||
* | ||
* @var {number} i | ||
*/ | ||
let i: number = -1 | ||
|
||
while (++i < pattern.length) { | ||
/** | ||
* Current pattern. | ||
* | ||
* @const {string} pat | ||
*/ | ||
const pat: string = pattern[i]! | ||
|
||
validateString(pat, `pattern[${i}]`) | ||
pattern[i] = toPosix(pat) | ||
} | ||
} else { | ||
validateString(pattern, 'pattern') | ||
pattern = toPosix(pattern) | ||
} | ||
|
||
return micromatch.isMatch(toPosix(path), pattern, { | ||
...options, | ||
cwd: options?.cwd ?? process.cwd() | ||
}) | ||
} | ||
|
||
export default matchesGlob |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
declare global { | ||
interface ArrayConstructor { | ||
/** | ||
* Check if `value` is an array. | ||
* | ||
* @template {any} T | ||
* Array item type | ||
* | ||
* @param {unknown} value | ||
* Value to check | ||
* @return {value is ReadonlyArray<T> | T[]} | ||
* `true` if `value` is an array | ||
*/ | ||
isArray<T>(value: unknown): value is T[] | readonly T[] | ||
} | ||
} | ||
|
||
export {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters