From 8ab1cddd0e54553e2dff9cf8e91117dbeafa13f3 Mon Sep 17 00:00:00 2001 From: werther Date: Fri, 30 Sep 2022 09:50:07 +0200 Subject: [PATCH 1/3] add getIcons functionality to library --- library/library.js | 1 + 1 file changed, 1 insertion(+) diff --git a/library/library.js b/library/library.js index 41d0827..8913ecb 100644 --- a/library/library.js +++ b/library/library.js @@ -27,6 +27,7 @@ const library = { } return iconLibrary[name]; }, + getIcons: () => iconLibrary, }; export default library; From dc07baa1e1cddad1796e1a93ffca7feb21174486 Mon Sep 17 00:00:00 2001 From: werther Date: Fri, 30 Sep 2022 10:02:11 +0200 Subject: [PATCH 2/3] Changed library handling of naming. Added naming to library --- library/library.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/library/library.js b/library/library.js index 8913ecb..5d13691 100644 --- a/library/library.js +++ b/library/library.js @@ -1,4 +1,5 @@ -const iconLibrary = {}; +const iconLibraryAlternativeName = {}; +const iconLibraryName = {}; const library = { add: (...icons) => { @@ -8,26 +9,26 @@ const library = { // first check if icon is a valid icon if (!name || !height || !width || !svgContent) { console.error(`Trying to add unsupported icon to library "${name}"`); - } else if (iconLibrary[name] && iconLibrary[name]) { + } else if (iconLibraryName[name]) { console.error(`Adding icon twice ${name}`); } else { - if (!iconLibrary[name]) { - iconLibrary[name] = {}; - } - const iconObj = { height, width, svgContent }; - iconLibrary[name] = iconObj; - iconLibrary[name.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase())] = iconObj; + const alternativeName = name.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase()); + const iconObj = { + name, alternativeName, height, width, svgContent, + }; + iconLibraryName[name] = iconObj; + iconLibraryAlternativeName[alternativeName] = iconObj; } }); }, getIcon: (name) => { - if (!iconLibrary[name]) { + if (!iconLibraryName[name] && !iconLibraryAlternativeName[name]) { console.error(`Trying to load icon that was not put into iconLibrary before "${name}"`); return undefined; } - return iconLibrary[name]; + return iconLibraryName[name] || iconLibraryAlternativeName[name]; }, - getIcons: () => iconLibrary, + getIcons: () => iconLibraryName, }; export default library; From 6994b24f191c71f7f9a48bec01ea0787db877ba5 Mon Sep 17 00:00:00 2001 From: werther Date: Fri, 30 Sep 2022 10:20:16 +0200 Subject: [PATCH 3/3] Fixed bug in regex affecting a couple of SVGs --- build/generate_js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/generate_js.js b/build/generate_js.js index b69fe38..8aebdad 100644 --- a/build/generate_js.js +++ b/build/generate_js.js @@ -5,7 +5,7 @@ const fs = require('fs').promises; const fsr = require('fs'); const path = require('path'); -const regex = /(.*)<\/svg>/m; +const regex = /(.*)<\/svg>/m; const svgSourceFolder = './svg/'; const jsTargetFolder = './generated_js/';