Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}).then((result) => {
/* eslint-disable ava/max-asserts */
t.deepEqual(['svg', 'ttf', 'eot', 'woff', 'woff2', 'css'], Object.keys(result));
t.true(isSvg(result.svg));
t.true(isTtf(result.ttf));
t.true(isEot(result.eot));
t.true(isWoff(result.woff));
t.true(isWoff2(result.woff2));
t.is(result.css.slice(0, 21), '/* custom template */');
/* eslint-enable ava/max-asserts */
return result;
}).catch(logError);
});
if (!rawContent) {
return null;
}
const detectedFileType = fileType(rawContent);
if (detectedFileType) {
/*
* If the file is XML, check if it's a specific
* type of XML such as a SVG.
*/
if (detectedFileType.mime === 'application/xml' &&
isSvg(rawContent)) {
// See: https://www.w3.org/TR/SVG/mimereg.html.
return 'image/svg+xml';
}
// Use the media types from `mime-db`, not `file-type`.
return getMediaTypeBasedOnFileExtension(detectedFileType.ext);
}
return null;
};
async ({ value }) => {
if (!isSvg(value)) throw new Error("This is not a valid svg code.");
svgo = svgo || getWorker(SvgoWorker);
svgr = svgr || getWorker(SvgrWorker);
let _value = await svgo.send({
value,
settings: {
...(settings.optimizeSvg ? settings : {}),
...nativeRequiredSettings
}
});
// set optimized value in state to be used by preview.
setOptimizedValue(_value);
_babelWorker = _babelWorker || getWorker(BabelWorker);
async ({ value }) => {
if (!isSvg(value)) throw new Error("This is not a valid svg code.");
svgr = svgr || getWorker(SvgrWorker);
svgo = svgo || getWorker(SvgoWorker);
let _value = value;
if (settings.optimizeSvg) {
_value = await svgo.send({
value,
settings
});
}
setOptimizedValue(_value);
_value = await svgr.send({
async ({ value }) => {
setSvg(isSvg(value));
const converter = new HtmlToJsx(settings);
return converter.convert(value);
},
[settings]
getTransformedValue = async (newValue: string) => {
if (!isSvg(newValue)) {
throw new Error("Please provide a valid SVG markup.");
}
return new Promise(resolve =>
convertSvgString(newValue, code => resolve(code))
);
};
convertHtmlToJsx = html => {
if (isSvg(html) && this.state.shouldOptimize) {
return new Promise(resolve => {
svgo.optimize(html, result => {
resolve(converter.convert(result.data));
});
});
}
return converter.convert(html);
};