feather/bin/build-sprite-string.js

27 lines
688 B
JavaScript
Raw Normal View History

import DEFAULT_ATTRS from '../src/default-attrs.json';
2018-02-21 03:30:59 +03:00
/**
* Build an SVG sprite string containing SVG symbols.
* @param {Object} icons
* @returns {string}
2018-02-21 03:30:59 +03:00
*/
function buildSpriteString(icons) {
const symbols = Object.keys(icons)
.map(icon => toSvgSymbol(icon, icons[icon]))
.join('');
return `<svg xmlns="${DEFAULT_ATTRS.xmlns}"><defs>${symbols}</defs></svg>`;
2018-02-21 03:30:59 +03:00
}
/**
* Create an SVG symbol string.
* @param {string} name - Icon name
* @param {string} contents - SVG contents
* @returns {string}
2018-02-21 03:30:59 +03:00
*/
function toSvgSymbol(name, contents) {
2021-03-15 21:23:40 +03:00
return `<symbol id="${name}" viewBox="${DEFAULT_ATTRS.viewBox}">${contents}</symbol>`;
2018-02-21 03:30:59 +03:00
}
export default buildSpriteString;