Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 2 Examples of "mini-svg-data-uri in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'mini-svg-data-uri' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

.then(nd => {
      nd.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
      const serializedString =  new window.XMLSerializer().serializeToString(nd);

      const xhtml = escapeXhtml(serializedString);
      const foreignObject = ``;
      const svgStr = `<svg height="${height}" width="${width}" xmlns="http://www.w3.org/2000/svg">${foreignObject}</svg>`;

      // Optimizing SVGs in data URIs
      // see https://codepen.io/tigt/post/optimizing-svgs-in-data-uris
      // the best way of encoding SVG in a data: URI is data:image/svg+xml,[actual data].
      // We don’t need the ;charset=utf-8 parameter because the given SVG is ASCII.
      return svgToMiniDataURI(svgStr);
    });
}
const getDataUri = filePath => {
  if (path.extname(filePath).toLowerCase() === '.svg') {
    const file = fs.readFileSync(filePath, 'utf-8')
    return svgDataUri(file)
  }

  const file = fs.readFileSync(filePath)
  return `data:${mimeLookup(filePath)};base64,${new Buffer(file).toString(
    'base64',
  )}`
}

Is your System Free of Underlying Vulnerabilities?
Find Out Now