forked from Shinonome/dots-hyprland
icons: add regex substitutions (#487)
This commit is contained in:
@@ -6,8 +6,23 @@ export function iconExists(iconName) {
|
||||
}
|
||||
|
||||
export function substitute(str) {
|
||||
if(userOptions.icons.substitutions[str]) return userOptions.icons.substitutions[str];
|
||||
// Normal substitutions
|
||||
if (userOptions.icons.substitutions[str])
|
||||
return userOptions.icons.substitutions[str];
|
||||
|
||||
if (!iconExists(str)) str = str.toLowerCase().replace(/\s+/g, '-'); // Turn into kebab-case
|
||||
// Regex substitutions
|
||||
for (let i = 0; i < userOptions.icons.regexSubstitutions.length; i++) {
|
||||
const substitution = userOptions.icons.regexSubstitutions[i];
|
||||
const replacedName = str.replace(
|
||||
substitution.regex,
|
||||
substitution.replace,
|
||||
);
|
||||
if (replacedName != str) return replacedName;
|
||||
}
|
||||
|
||||
// Guess: convert to kebab case
|
||||
if (!iconExists(str)) str = str.toLowerCase().replace(/\s+/g, "-");
|
||||
|
||||
// Original string
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user