You've already forked simple-icons
mirror of
https://github.com/simple-icons/simple-icons.git
synced 2025-07-02 22:16:54 +02:00
Use getter for svg
instead of path
in packaged javascript version of icons (#6505)
* Use getter for 'svg' instead of 'path' in packaged javascript version of icons * Use variable to avoid calling `escape` twice * Convert title to HTML friendly in build script * Update tests * Only friendly title for SVG content * Add equality test for SVG contents * Add missing import * Test using icons template * Fix lint error * Fix lint error in utils * Read files synchronicly in tests * Remove done from tests, make them pass * Remove uneeded imports * Remove replacements in tests * Update with changes in develop * Drop uneeded requirement * Space between requirements * Simplify encoding utility * Fix syntax error * Apply @ericcornelissen's suggestions * Apply @ericcornelissen's suggestions
This commit is contained in:
@ -10,6 +10,12 @@ module.exports = {
|
||||
*/
|
||||
getIconSlug: (icon) => icon.slug || module.exports.titleToSlug(icon.title),
|
||||
|
||||
/**
|
||||
* Extract the path from an icon SVG content.
|
||||
* @param {Object} svg The icon SVG content
|
||||
**/
|
||||
svgToPath: (svg) => svg.match(/<path\s+d="([^"]*)/)[1],
|
||||
|
||||
/**
|
||||
* Converts a brand title into a slug/filename.
|
||||
* @param {String} title The title to convert
|
||||
@ -43,4 +49,20 @@ module.exports = {
|
||||
/&(quot|amp|lt|gt);/g,
|
||||
(_, ref) => ({ quot: '"', amp: '&', lt: '<', gt: '>' }[ref]),
|
||||
),
|
||||
|
||||
/**
|
||||
* Converts a brand title (as it is seen in simple-icons.json) into a brand
|
||||
* title in HTML/SVG friendly format.
|
||||
* @param {String} brandTitle The title to convert
|
||||
*/
|
||||
titleToHtmlFriendly: (brandTitle) =>
|
||||
brandTitle
|
||||
.replace(/&/g, '&')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/./g, (char) => {
|
||||
const charCode = char.charCodeAt(0);
|
||||
return charCode > 127 ? `&#${charCode};` : char;
|
||||
}),
|
||||
};
|
||||
|
Reference in New Issue
Block a user