-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: filter out .dotFiles by default
* chore: move test files in their correct folder * feat: filter out .dotFiles by default * chore: add utility maybeFilter * test: add a .dotFile to add more tests
- Loading branch information
Showing
12 changed files
with
83 additions
and
6 deletions.
There are no files selected for viewing
Empty file.
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
File renamed without changes.
File renamed without changes.
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
Binary file not shown.
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,17 @@ | ||
import { join } from 'path'; | ||
|
||
import { fileCollectionFromPath } from '../../fileCollectionFromPath'; | ||
import { maybeFilter } from '../maybeFilter'; | ||
|
||
test('maybeFilter', async () => { | ||
const files = ( | ||
await fileCollectionFromPath(join(__dirname, 'data/hidden'), { | ||
ignoreDotFiles: false, | ||
}) | ||
).files; | ||
const filtered = await maybeFilter(files); | ||
expect(filtered).toHaveLength(4); | ||
|
||
const notFiltered = await maybeFilter(files, { ignoreDotFiles: false }); | ||
expect(notFiltered).toHaveLength(9); | ||
}); |
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,28 @@ | ||
import { FileCollectionItem } from '../FileCollectionItem'; | ||
|
||
export type FilterOptions = { | ||
/** | ||
* Should we ignored files starting with dot | ||
* @default true | ||
*/ | ||
ignoreDotFiles?: boolean; | ||
}; | ||
|
||
/** | ||
* Utility function that allows to expand gzip and zip files without really expanding them | ||
* @param fileCollection | ||
* @param options | ||
* @returns | ||
*/ | ||
export async function maybeFilter( | ||
fileCollectionItems: FileCollectionItem[], | ||
options: FilterOptions = {}, | ||
): Promise<FileCollectionItem[]> { | ||
const { ignoreDotFiles = true } = options; | ||
if (ignoreDotFiles) { | ||
fileCollectionItems = fileCollectionItems.filter( | ||
(item) => !item.name.startsWith('.'), | ||
); | ||
} | ||
return fileCollectionItems; | ||
} |