add types for font-awesome-v5-icons

Possibly temporary, see soul-wish/font-awesome-v5-icons#25
deepsource-autofix-76c6eb20
Dan Gowans 2022-12-23 10:37:54 -05:00
parent bd3c183cc5
commit 3af9e39254
4 changed files with 55 additions and 3 deletions

View File

@ -2,7 +2,7 @@ import faIcons from "font-awesome-v5-icons";
let solidIcons = []; let solidIcons = [];
export const getSolidIconClasses = async () => { export const getSolidIconClasses = async () => {
if (solidIcons.length === 0) { if (solidIcons.length === 0) {
const allIcons = await faIcons.getList(); const allIcons = await faIcons.getListByKeys(["name", "styles"]);
const list = []; const list = [];
for (const icon of allIcons) { for (const icon of allIcons) {
if (icon.styles.includes("solid")) { if (icon.styles.includes("solid")) {

View File

@ -4,12 +4,12 @@ let solidIcons: string[] = [];
export const getSolidIconClasses = async () => { export const getSolidIconClasses = async () => {
if (solidIcons.length === 0) { if (solidIcons.length === 0) {
const allIcons = await faIcons.getList(); const allIcons = await faIcons.getListByKeys(["name", "styles"]);
const list: string[] = []; const list: string[] = [];
for (const icon of allIcons) { for (const icon of allIcons) {
if ((icon.styles as string[]).includes("solid")) { if (icon.styles.includes("solid")) {
list.push(icon.name); list.push(icon.name);
} }
} }

17
types/moduleTypes.d.ts vendored 100644
View File

@ -0,0 +1,17 @@
declare module "font-awesome-v5-icons" {
type FontAwesomeV5Styles = "solid" | "regular" | "brands";
type FontAwesomeV5Keys = "name" | "changes" | "label" | "search" | "styles" | "unicode" | "voted";
interface FontAwesomeV5Icon {
name?: string;
changes?: string[];
label?: string;
search?: {
terms: string[];
};
styles?: FontAwesomeV5Styles[];
unicode?: string;
voted?: boolean;
}
function getList(): Promise<FontAwesomeV5Icon[]>;
function getListByKeys(arrayOfNeededKeys: FontAwesomeV5Keys[]): Promise<FontAwesomeV5Icon[]>;
}

View File

@ -0,0 +1,35 @@
declare module "font-awesome-v5-icons" {
type FontAwesomeV5Styles = "solid" | "regular" | "brands";
type FontAwesomeV5Keys =
| "name"
| "changes"
| "label"
| "search"
| "styles"
| "unicode"
| "voted";
interface FontAwesomeV5Icon {
name?: string;
changes?: string[];
label?: string;
search?: { terms: string[] };
styles?: FontAwesomeV5Styles[];
unicode?: string;
voted?: boolean;
}
/**
* Returns a promise with a full list of actual Font Awesome v5 icons.
*/
export function getList(): Promise<FontAwesomeV5Icon[]>;
/**
* Returns a promise with a full list of Font Awesome icons with needed keys only.
* @param arrayOfNeededKeys
*/
export function getListByKeys(
arrayOfNeededKeys: FontAwesomeV5Keys[]
): Promise<FontAwesomeV5Icon[]>;
}