How to use the svgo.extendDefaultPlugins function in svgo

To help you get started, we’ve selected a few svgo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github go-gitea / gitea / build / generate-svg.js View on Github external
async function processFile(file, {prefix, fullName} = {}) {
  let name;

  if (fullName) {
    name = fullName;
  } else {
    name = parse(file).name;
    if (prefix) name = `${prefix}-${name}`;
    if (prefix === 'octicon') name = name.replace(/-[0-9]+$/, ''); // chop of '-16' on octicons
  }

  const {data} = optimize(await readFile(file, 'utf8'), {
    plugins: extendDefaultPlugins([
      'removeXMLNS',
      'removeDimensions',
      {
        name: 'addClassesToSVGElement',
        params: {classNames: ['svg', name]},
      },
      {
        name: 'addAttributesToSVGElement',
        params: {attributes: [{'width': '16'}, {'height': '16'}, {'aria-hidden': 'true'}]},
      },
    ]),
  });
  await writeFile(resolve(outputDir, `${name}.svg`), data);
}
github go-gitea / gitea / build / generate-images.js View on Github external
async function generate(svg, outputFile, {size, bg}) {
  if (outputFile.endsWith('.svg')) {
    const {data} = optimize(svg, {
      plugins: extendDefaultPlugins([
        'removeDimensions',
        {
          name: 'addAttributesToSVGElement',
          params: {attributes: [{width: size}, {height: size}]}
        },
      ]),
    });
    await writeFile(outputFile, data);
    return;
  }

  const {objects, options} = await loadSvg(svg);
  const canvas = new fabric.Canvas();
  canvas.setDimensions({width: size, height: size});
  const ctx = canvas.getContext('2d');
  ctx.scale(options.width ? (size / options.width) : 1, options.height ? (size / options.height) : 1);