From 3af9e39254c66bf7a86e3b73e8e3a87344f8c98d Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Fri, 23 Dec 2022 10:37:54 -0500 Subject: [PATCH] add types for font-awesome-v5-icons Possibly temporary, see soul-wish/font-awesome-v5-icons#25 --- helpers/functions.icons.js | 2 +- helpers/functions.icons.ts | 4 ++-- types/moduleTypes.d.ts | 17 +++++++++++++++++ types/moduleTypes.ts | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 types/moduleTypes.d.ts create mode 100644 types/moduleTypes.ts diff --git a/helpers/functions.icons.js b/helpers/functions.icons.js index fbfd1ce7..b8728aa2 100644 --- a/helpers/functions.icons.js +++ b/helpers/functions.icons.js @@ -2,7 +2,7 @@ import faIcons from "font-awesome-v5-icons"; let solidIcons = []; export const getSolidIconClasses = async () => { if (solidIcons.length === 0) { - const allIcons = await faIcons.getList(); + const allIcons = await faIcons.getListByKeys(["name", "styles"]); const list = []; for (const icon of allIcons) { if (icon.styles.includes("solid")) { diff --git a/helpers/functions.icons.ts b/helpers/functions.icons.ts index 54b9f35d..657e7671 100644 --- a/helpers/functions.icons.ts +++ b/helpers/functions.icons.ts @@ -4,12 +4,12 @@ let solidIcons: string[] = []; export const getSolidIconClasses = async () => { if (solidIcons.length === 0) { - const allIcons = await faIcons.getList(); + const allIcons = await faIcons.getListByKeys(["name", "styles"]); const list: string[] = []; for (const icon of allIcons) { - if ((icon.styles as string[]).includes("solid")) { + if (icon.styles.includes("solid")) { list.push(icon.name); } } diff --git a/types/moduleTypes.d.ts b/types/moduleTypes.d.ts new file mode 100644 index 00000000..9c489213 --- /dev/null +++ b/types/moduleTypes.d.ts @@ -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; + function getListByKeys(arrayOfNeededKeys: FontAwesomeV5Keys[]): Promise; +} diff --git a/types/moduleTypes.ts b/types/moduleTypes.ts new file mode 100644 index 00000000..0e7b40f4 --- /dev/null +++ b/types/moduleTypes.ts @@ -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; + + /** + * Returns a promise with a full list of Font Awesome icons with needed keys only. + * @param arrayOfNeededKeys + */ + export function getListByKeys( + arrayOfNeededKeys: FontAwesomeV5Keys[] + ): Promise; +}