Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "svgson in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'svgson' 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.

function svgtopdf (el, options, pdf) {
  if (typeof el === 'string') {
    const svg = svgson.parseSync(fs.readFileSync(el, 'utf-8'))
    const [, , width, height] = svg.attributes.viewBox.split(' ').map(Number)
    const scale = 24 / Math.min(width, height)
    const pdfdoc = new PDFDocument({ size: [width * scale, height * scale] })
    pdfdoc.scale(scale)
    pdfdoc.pipe(fs.createWriteStream(el.replace('svg', 'pdf')))
    svgtopdf(svg, { fill: '#000' }, pdfdoc)
    pdfdoc.end()
  } else {
    for (const node of el.children) {
      const fillr = (node.attributes['fill-rule'] || 'nonzero').replace(/-*(zero|odd)$/, '-$1')
      const color = (val) => String(val).replace(/currentColor/i, options.color).replace(/none/i, '')
      const float = (key) => Number(node.attributes[key]) || 0
      const style = {}

      // Style
      pdf.fillColor(style.fill = color(node.attributes['fill'] || options.fill || options.color))
fs.readdirSync(SVG_DIR).map(async file => {
    console.log(`Converting ${file}...`)
    if (!ICON_PATTERN.test(file)) {
      return
    }
    let fileData = fs.readFileSync(path.resolve(SVG_DIR, file), 'utf8')
    let { error, data } = await svgo.optimize(fileData)
    if (error) {
      console.error(file, error)
      return
    }

    let { attributes, children } = await svgson(data)
    let { width, height, viewBox } = attributes
    if (!(width && height)) {
      if (!viewBox) {
        console.error(file, `doesn't contain a valid size declaration.`)
      }

      [width, height] = (viewBox.match(/0 0 (\d+) (\d+)/) || []).map(size => parseInt(size, 10))
    }

    if (!(width && height)) {
      console.error(file, `doesn't contain a valid size declaration.`)
    }

    let icon
    let paths
    if (children.every(({ name }) => name === 'path')) {
let [match, name] = file.match(ICON_PATTERN) || []
    if (!match) {
      return
    }

    if (!ICON_PATTERN.test(file)) {
      return
    }
    let fileData = fs.readFileSync(path.resolve(SVG_DIR, file), 'utf8')
    let { error, data } = await svgo.optimize(fileData)
    if (error) {
      console.error(file, error)
      return
    }

    let el = await svgson(data)
    console.log(`Converting ${file}...`)
    let { attributes, children } = el
    let { width, height, viewBox } = attributes
    if (!(width && height)) {
      if (!viewBox) {
        console.error(file, `doesn't contain a valid size declaration.`)
        console.error(width, height, viewBox)
      }

      ;[, width, height] = (viewBox.match(/0 0 (\d+) (\d+)/) || []).map(size =>
        parseInt(size, 10)
      )
    }

    if (!(width && height)) {
      console.error(file, `doesn't contain a valid size declaration.`)
fs.readdirSync(SVG_DIR).map(async file => {
    console.log(`Converting ${file}...`)
    if (!ICON_PATTERN.test(file)) {
      return
    }
    let fileData = fs.readFileSync(path.resolve(SVG_DIR, file), 'utf8')
    let { error, data } = await svgo.optimize(fileData)
    if (error) {
      console.error(file, error)
      return
    }

    let { attributes, children } = await parse(data)
    let { width, height, viewBox } = attributes
    if (!(width && height)) {
      if (!viewBox) {
        console.error(file, `doesn't contain a valid size declaration.`)
      }

      [width, height] = (viewBox.match(/0 0 (\d+) (\d+)/) || []).map(size => parseInt(size, 10))
    }

    if (!(width && height)) {
      console.error(file, `doesn't contain a valid size declaration.`)
    }

    let icon
    let paths
    if (children.every(({ name }) => name === 'path')) {
await asyncForEach(files, async filename => {
      const path = `${this.inputSvgsPath}\\${filename}`;
      const svg = fs.readFileSync(path, 'utf8');

      svgson.parse(svg).then(json => {
        const name = filename.split('.')[0];

        const layers = json.children
          .filter(({ name }) => name === 'path')
          .map(({ attributes }) => ({
            id: attributes.id.toLowerCase(),
            name: attributes.title || capitalize(attributes.id),
            d: attributes.d,
          }));

        const map = {
          id: name,
          name: capitalize(name.split('-').join(' ')),
          viewBox: `0 0 ${parseFloat(json.attributes.width)} ${parseFloat(json.attributes.height)}`,
          layers,
        };
fs.readFile(svgFile, 'utf8', (err, data) => {
    if (err) {
      console.error(`Unable to read file ${svgFile}`, err)
      return
    }
    console.log(`Parsing file ${svgFile}`)
    svgson.parse(data)
      .then(json => {
        const obj = {
          label: json.attributes['aria-label'],
          viewBox: json.attributes.viewBox,
          locations: json.children
            .filter(child => {
              if (child.name !== 'path') {
                console.warn(`<${child.name}> tag will be ignored`)
                return false
              }

              return true
            })
            .map(child => ({
              name: child.attributes.name,
              id: child.attributes.id,
let raw = children.map(child => {
        return stringify(child)
      }).join('')
      icon = {
let raw = children.map(child => {
        return stringify(child)
      }).join('')
      icon = {
export default async svg => {
  const parsed = await svgson(svg)
  const convertedToPath = elemToPath(parsed)
  return stringify(convertedToPath)
}

Is your System Free of Underlying Vulnerabilities?
Find Out Now