2
0
mirror of https://github.com/iconify/iconify.git synced 2024-11-09 14:50:56 +00:00

feat(utils): add svgToData function

This commit is contained in:
Vjacheslav Trushkin 2023-03-09 10:47:03 +02:00
parent 2fc81ae9d8
commit 6e6fbe15a1
3 changed files with 10 additions and 3 deletions

View File

@ -3,7 +3,7 @@
"type": "module",
"description": "Common functions for working with Iconify icon sets used by various packages.",
"author": "Vjacheslav Trushkin",
"version": "2.1.4",
"version": "2.1.5",
"license": "MIT",
"bugs": "https://github.com/iconify/iconify/issues",
"homepage": "https://iconify.design/",

View File

@ -58,7 +58,7 @@ export { calculateSize } from './svg/size';
export { encodeSvgForCss } from './svg/encode-svg-for-css';
export { trimSVG } from './svg/trim';
export { iconToHTML } from './svg/html';
export { svgToURL } from './svg/url';
export { svgToURL, svgToData } from './svg/url';
// Colors
export { colorKeywords } from './colors/keywords';

View File

@ -18,9 +18,16 @@ export function encodeSVGforURL(svg: string): string {
);
}
/**
* Generate data: URL from SVG
*/
export function svgToData(svg: string): string {
return 'data:image/svg+xml,' + encodeSVGforURL(svg);
}
/**
* Generate url() from SVG
*/
export function svgToURL(svg: string): string {
return 'url("data:image/svg+xml,' + encodeSVGforURL(svg) + '")';
return 'url("' + svgToData(svg) + '")';
}