Skip to content

Commit

Permalink
add caseSensitiveMatch option
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperchupuDev committed Sep 8, 2024
1 parent f70ce4d commit 0488df3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ globSync({ patterns: ['src/**/*.ts', '!**/*.d.ts'], deep: 3 });
- `absolute`: Whether to return absolute paths. Defaults to `false`.
- `dot`: Whether to allow entries starting with a dot. Defaults to `false`.
- `deep`: Maximum depth of a directory. Defaults to `Infinity`.
- `caseSensitiveMatch`: Whether to match in case-sensitive mode. Defaults to `true`.
- `expandDirectories`: Whether to expand directories. Disable to best match `fast-glob`. Defaults to `true`.
- `onlyDirectories`: Enable to only return directories. Disables `onlyFiles` if set. Defaults to `false`.
- `onlyFiles`: Enable to only return files. Defaults to `true`.
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface GlobOptions {
ignore?: string[];
dot?: boolean;
deep?: number;
caseSensitiveMatch?: boolean;
expandDirectories?: boolean;
onlyDirectories?: boolean;
onlyFiles?: boolean;
Expand Down Expand Up @@ -105,8 +106,8 @@ function getRelativePath(path: string, cwd: string, root: string) {
}

function processPath(path: string, cwd: string, root: string, isDirectory: boolean, absolute?: boolean) {
const relativePath = absolute ? path.slice(root.length + 1) : path;
//if (absolute) console.log({ path, cwd, root, relativePath });
const relativePath = (absolute ? path.slice(root.length + 1) : path) || './';

if (root === cwd) {
return isDirectory ? relativePath.slice(0, -1) : relativePath;
}
Expand All @@ -127,11 +128,13 @@ function crawl(options: GlobOptions, cwd: string, sync: boolean) {

const matcher = picomatch(processed.match, {
dot: options.dot,
nocase: options.caseSensitiveMatch === false,
ignore: processed.ignore
});

const exclude = picomatch(processed.ignore, {
dot: options.dot
dot: options.dot,
nocase: options.caseSensitiveMatch === false
});

const fdirOptions: Partial<FdirOptions> = {
Expand Down
15 changes: 15 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ test('ignore option', async () => {
assert.deepEqual(files.sort(), ['a/a.txt']);
});

test('caseSensitiveMatch', async () => {
const files = await glob({ patterns: ['**/A.TXT'], caseSensitiveMatch: false, cwd });
assert.deepEqual(files.sort(), ['a/a.txt', 'b/a.txt']);
});

test('caseSensitiveMatch (default)', async () => {
const files = await glob({ patterns: ['**/A.TXT'], cwd });
assert.deepEqual(files.sort(), []);
});

test('caseSensitiveMatch with ignore', async () => {
const files = await glob({ patterns: ['**/A.TXT'], ignore: ['B/**'], caseSensitiveMatch: false, cwd });
assert.deepEqual(files.sort(), ['a/a.txt']);
});

test('onlyDirectories option', async () => {
const files = await glob({ patterns: ['a'], onlyDirectories: true, cwd });
assert.deepEqual(files.sort(), ['a/']);
Expand Down

0 comments on commit 0488df3

Please sign in to comment.