MCPcopy Create free account
hub / github.com/violentmonkey/violentmonkey / makeDataUri

Function makeDataUri

src/common/string.js:76–84  ·  view source on GitHub ↗
(raw, url)

Source from the content-addressed store, hash-verified

74 * @returns {?string}
75 */
76export function makeDataUri(raw, url) {
77 if (isDataUri(url)) return url;
78 if (/^(i,|image\/)/.test(raw)) { // workaround for bugs in old VM, see 2e135cf7
79 const i = raw.lastIndexOf(',');
80 const type = raw.startsWith('image/') ? raw.slice(0, i) : 'image/png';
81 return `data:${type};base64,${raw.slice(i + 1)}`;
82 }
83 return raw;
84}
85
86/**
87 * @param {VMReq.Response} response

Callers 1

loadIconFunction · 0.90

Calls 1

testMethod · 0.45

Tested by

no test coverage detected