2
0
mirror of https://github.com/iconify/iconify.git synced 2024-11-08 06:15:24 +00:00

chore: reuse splitSVGDefs for other tags in utils

This commit is contained in:
Vjacheslav Trushkin 2023-12-14 19:26:18 +02:00
parent 08d2a5b4b4
commit d037f7ae13
2 changed files with 13 additions and 7 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.12",
"version": "2.1.13",
"license": "MIT",
"bugs": "https://github.com/iconify/iconify/issues",
"homepage": "https://iconify.design/docs/libraries/utils/",

View File

@ -1,17 +1,23 @@
/**
* Extract definitions from SVG
*
* Can be used with other tags, but name kept for backwards compatibility.
* Should be used only with tags that cannot be nested, such as masks, clip paths, etc.
*/
interface SplitSVGDefsResult {
defs: string;
content: string;
}
/**
* Extract definitions from SVG
*/
export function splitSVGDefs(content: string): SplitSVGDefsResult {
export function splitSVGDefs(
content: string,
tag = 'defs'
): SplitSVGDefsResult {
let defs = '';
const index = content.indexOf('<defs');
const index = content.indexOf('<' + tag);
while (index >= 0) {
const start = content.indexOf('>', index);
const end = content.indexOf('</defs');
const end = content.indexOf('</' + tag);
if (start === -1 || end === -1) {
// Fail
break;