-
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.
Changed module to be completely framework agnostic.
- Loading branch information
1 parent
96c632f
commit 7722266
Showing
10 changed files
with
263 additions
and
470 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
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 |
---|---|---|
@@ -1,2 +1,46 @@ | ||
export { default as FileIcon } from './FileIcon'; | ||
export { getIcon, getAllIcons, defaultIcon } from './utility'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import iconDefs from 'icon-definitions'; | ||
|
||
export interface Icon { | ||
name: string; | ||
extensions?: string[]; | ||
files?: string[]; | ||
svg: string; | ||
} | ||
|
||
const defaultIcon: Icon = iconDefs.defaultIcon; | ||
export { defaultIcon }; | ||
|
||
export function getIcon(filename: string): Icon { | ||
|
||
if (typeof filename === 'string') { | ||
|
||
// Check complete filename first | ||
let icon = iconDefs.icons.find(i => i.files && i.files.some(f => f.localeCompare(filename, undefined, { sensitivity: 'accent' }) === 0)); | ||
if (icon) return icon; | ||
|
||
// The extensions, can match multiple which leads to this quite inefficient way of matching. | ||
const matches = iconDefs.icons.filter(i => i.extensions && i.extensions.some(ext => filename.endsWith('.' + ext))); | ||
if (matches.length > 0) { | ||
let matchLength = 0; | ||
for (const match of matches) { | ||
for (const ext of match.extensions) { | ||
if (ext.length > matchLength && filename.endsWith('.' + ext)) { | ||
matchLength = ext.length; | ||
icon = match; | ||
} | ||
} | ||
} | ||
} | ||
if (icon) return icon; | ||
|
||
} | ||
|
||
// Finally fall back to default icon | ||
return defaultIcon; | ||
} | ||
|
||
export function getAllIcons(): Array<Icon> { | ||
return [defaultIcon, ...iconDefs.icons]; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.