forked from material-extensions/vscode-material-icon-theme
-
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.
- Loading branch information
Showing
12 changed files
with
182 additions
and
145 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
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.
This file was deleted.
Oops, something went wrong.
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,95 @@ | ||
import { | ||
FileIconWithPatterns, | ||
FileIcon, | ||
Patterns, | ||
FileNamePattern, | ||
} from '../../models'; | ||
|
||
/** | ||
* Maps the patterns to an array of strings. | ||
* Each pattern is a function that generates file names based on a key. | ||
* | ||
* @param patterns The patterns to map. | ||
* @returns An array of strings generated by applying the patterns. | ||
*/ | ||
const mapPatterns = (patterns: Patterns): string[] => { | ||
return Object.entries(patterns).flatMap(([fileName, pattern]) => { | ||
switch (pattern) { | ||
case FileNamePattern.Ecmascript: | ||
return [ | ||
`${fileName}.js`, | ||
`${fileName}.mjs`, | ||
`${fileName}.cjs`, | ||
`${fileName}.ts`, | ||
`${fileName}.mts`, | ||
`${fileName}.cts`, | ||
]; | ||
|
||
case FileNamePattern.Configuration: | ||
return [ | ||
`${fileName}.json`, | ||
`${fileName}.jsonc`, | ||
`${fileName}.json5`, | ||
`${fileName}.yaml`, | ||
`${fileName}.yml`, | ||
`${fileName}.toml`, | ||
]; | ||
|
||
case FileNamePattern.NodeEcosystem: | ||
return [ | ||
`${fileName}.js`, | ||
`${fileName}.mjs`, | ||
`${fileName}.cjs`, | ||
`${fileName}.ts`, | ||
`${fileName}.mts`, | ||
`${fileName}.cts`, | ||
`${fileName}.json`, | ||
`${fileName}.jsonc`, | ||
`${fileName}.json5`, | ||
`${fileName}.yaml`, | ||
`${fileName}.yml`, | ||
`${fileName}.toml`, | ||
]; | ||
|
||
case FileNamePattern.Cosmiconfig: | ||
return [ | ||
`.${fileName}rc`, | ||
`.config/${fileName}rc`, | ||
`${fileName}.config`, | ||
`${fileName}.js`, | ||
`${fileName}.mjs`, | ||
`${fileName}.cjs`, | ||
`${fileName}.ts`, | ||
`${fileName}.mts`, | ||
`${fileName}.cts`, | ||
`${fileName}.json`, | ||
`${fileName}.jsonc`, | ||
`${fileName}.json5`, | ||
`${fileName}.yaml`, | ||
`${fileName}.yml`, | ||
`${fileName}.toml`, | ||
]; | ||
|
||
default: | ||
// Check if all potential pattern cases are handled | ||
const exhaustiveCheck: never = pattern; | ||
throw new Error(`Unhandled pattern: ${exhaustiveCheck}`); | ||
} | ||
}); | ||
}; | ||
|
||
/** | ||
* Parses the raw file icons by applying the patterns. | ||
* A pattern helps to generate file names based on a key. | ||
* | ||
* @param rawFileIcons - The list of file icons without applied patterns. | ||
* @returns The list of file icons with applied patterns. | ||
*/ | ||
export const parseByPattern = ( | ||
rawFileIcons: FileIconWithPatterns | ||
): FileIcon[] => { | ||
return rawFileIcons.map(({ patterns, fileNames = [], ...rest }) => ({ | ||
...rest, | ||
fileNames: patterns ? [...mapPatterns(patterns), ...fileNames] : fileNames, | ||
})); | ||
}; |
Oops, something went wrong.