0
0
mirror of https://github.com/lipis/flag-icons.git synced 2024-11-23 18:07:28 +01:00

feat: enable prefixIds svgo plugin (#1110)

This commit is contained in:
Michael M 2023-07-24 20:53:33 +02:00 committed by GitHub
parent 7ed9083b64
commit f07a36d31d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,18 @@ module.exports = {
{
name: "preset-default",
},
{
name: "prefixIds",
params: {
delim: "-",
prefix: (_, info) => {
if (info.path != null && info.path.length > 0) {
return getBasename(info.path).split(".")[0];
}
return "prefix";
},
},
},
"convertStyleToAttrs",
"removeDimensions",
"removeScriptElement",
@ -10,3 +22,13 @@ module.exports = {
"sortAttrs",
],
};
/**
* extract basename from path
* @see https://github.com/svg/svgo/blob/main/plugins/prefixIds.js
*/
const getBasename = (path) => {
const matched = path.match(/[/\\]?([^/\\]+)$/);
if (matched) return matched[1];
return "";
};