New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

svg-visitor

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-visitor

visit svg element use visitor pattern

latest
Source
npmnpm
Version
0.3.0
Version published
Maintainers
1
Created
Source

svg-visitor

visit svg element use visitor pattern

Install

npm install svg-visitor

Usage

import { svgVisitor } from 'svg-visitor';

const svgDom = document.getElementByTagName('svg')[0]

svgVisitor(svgDom, {
  rectVisitor: function (rectDom) {
    const fill = rectDom.getAttribute('fill')
    if (fill === '#f00') {
      rectDom.setAttribute('fill', "#0f0")
    }
  }
})

before

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" baseProfile="full" width="40" height="40" >
  <rect width="40" height="40" x="0" y="0" id="0" fill="#f00"></rect>
</svg>

after

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" baseProfile="full" width="40" height="40" >
  <rect width="40" height="40" x="0" y="0" id="0" fill="#0f0"></rect>
</svg>

API

import { svgVisitor } from 'svg-visitor';

const svgDom = document.getElementByTagName('svg')[0]

svgVisitor(svgDom, {
  // visit all svg element under svgDom
  visitor: function(dom){},
  // visit <rect>...</rect>
  rectVisitor: function (rectDom) {},
  // visit <circle>...</circle>
  circleVisitor: function (circleDom) {},
  ...
})

Test

npm run-script test

Keywords

svg-visitor

FAQs

Package last updated on 13 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts