const parseDataUrl = require('data-urls');

module.exports = function resolveDataUrl(dataUrl) {
  try {
    const result = parseDataUrl(dataUrl);

    const assetConfig = {
      contentType: result.mimeType.essence,
      encoding: result.mimeType.parameters.get('charset') || 'utf-8',
      rawSrc: result.body,
    };

    return assetConfig;
  } catch (err) {
    return null;
  }
};

const parseDataUrl = require('data-urls');

module.exports = function resolveDataUrl(dataUrl) {
  try {
    const result = parseDataUrl(dataUrl);

    const assetConfig = {
      contentType: result.mimeType.essence,
      encoding: result.mimeType.parameters.get('charset') || 'utf-8',
      rawSrc: Buffer.from(result.body),
    };

    return assetConfig;
  } catch (err) {
    return null;
  }
};

Apply Buffer.from on the body of the return value of data-urls https://github.com/jsdom/data-urls/releases/tag/v3.0.0