feather/bin/build-sprite-string.js

29 lines
696 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) {
return `<symbol id="${name}" viewBox="${DEFAULT_ATTRS.viewBox}">${
contents
}</symbol>`;
2018-02-21 03:30:59 +03:00
}
export default buildSpriteString;