(url: string, sanitize: boolean)
| 15 | } |
| 16 | |
| 17 | export const getSvgContent = (url: string, sanitize: boolean): Promise<string> => { |
| 18 | /** |
| 19 | * See if we already have a request for this url |
| 20 | */ |
| 21 | const req = requests.get(url); |
| 22 | if (req) { |
| 23 | return req; |
| 24 | } |
| 25 | |
| 26 | if (typeof fetch !== 'undefined' && typeof document !== 'undefined') { |
| 27 | /** |
| 28 | * If the url is a data url of an svg, then try to parse it |
| 29 | * with the DOMParser. This works with content security policies enabled. |
| 30 | */ |
| 31 | if (isSvgDataUrl(url) && isEncodedDataUrl(url)) { |
| 32 | return Promise.resolve(getSvgByUrl(url)); |
| 33 | } |
| 34 | |
| 35 | return fetchSvg(url, sanitize); |
| 36 | } |
| 37 | |
| 38 | return Promise.resolve(safeFallback(url)); |
| 39 | }; |
| 40 | |
| 41 | function getSvgByUrl(url: string): string { |
| 42 | if (!parser) { |
no test coverage detected
searching dependent graphs…