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
1 parent
7f8219f
commit c688ee4
Showing
7 changed files
with
1,759 additions
and
4 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,85 @@ | ||
import type { FolderTheme } from '../../../core'; | ||
import type { | ||
LucodearFolderIcon, | ||
LucodearFolderTheme, | ||
} from '../../core/models'; | ||
|
||
export type IconDefinition = { | ||
name: string; | ||
label?: string; | ||
theme?: string; | ||
}; | ||
|
||
export const filterDuplicates = <T extends { name: string }>(icons: T[]) => { | ||
// duplicates have the same name | ||
return icons.filter((icon, index, self) => { | ||
return index === self.findIndex((i) => i.name === icon.name); | ||
}); | ||
}; | ||
|
||
export const getFolders = ( | ||
icons: LucodearFolderTheme[] | FolderTheme[] | ||
): IconDefinition[] => { | ||
return filterDuplicates( | ||
icons | ||
.map((theme) => { | ||
const folders = []; | ||
if (theme.icons && theme.icons.length > 0) { | ||
folders.push( | ||
...theme.icons | ||
.filter((i) => i.clone === undefined) | ||
.map((i) => ({ | ||
name: i.name, | ||
theme: (i as LucodearFolderIcon).theme, | ||
})) | ||
); | ||
} | ||
return [...folders]; | ||
}) | ||
.reduce((a, b) => a.concat(b)) | ||
).map((i) => ({ | ||
name: i.name, | ||
label: i.name.replace('folder-', ''), | ||
theme: i.theme, | ||
})); | ||
}; | ||
|
||
export const getFiles = (icons: IconDefinition[]): IconDefinition[] => { | ||
return filterDuplicates(icons).map((i) => ({ | ||
name: i.name, | ||
label: i.name.replace('file-', ''), | ||
theme: i.theme, | ||
})); | ||
}; | ||
|
||
export type Theme = { | ||
name: string; | ||
hasFiles: boolean; | ||
hasFolders: boolean; | ||
}; | ||
|
||
export function getThemes( | ||
folderIcons: { theme?: string }[], | ||
filesIcons: { theme?: string }[] | ||
): Theme[] { | ||
const notUndefined = <T>(i: T | undefined): i is T => i !== undefined; | ||
|
||
const folderThemes: string[] = folderIcons | ||
.map((i) => i.theme) | ||
.filter(notUndefined); | ||
const fileThemes: string[] = filesIcons | ||
.map((i) => i.theme) | ||
.filter(notUndefined); | ||
|
||
const themes: Theme[] = [...new Set([...folderThemes, ...fileThemes])].map( | ||
(theme) => { | ||
return { | ||
name: theme, | ||
hasFiles: fileThemes.includes(theme), | ||
hasFolders: folderThemes.includes(theme), | ||
}; | ||
} | ||
); | ||
|
||
return themes; | ||
} |
Oops, something went wrong.