Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
svg-crowbar
Advanced tools
A library based on a Chrome-specific bookmarklet that extracts SVG nodes and accompanying styles from an HTML document and downloads them as an SVG file
A standalone 3.5Kb JS client library based on Chrome bookmarklet.
The library provides functionality to trigger a download of a given SVG file having all the styles inlined, to make it look the same when opened independently from the original HTML page.
It is also possible to use this library to convert an SVG to a PNG before downloading.
import downloadSvg from 'svg-crowbar';
downloadSvg(document.querySelector('svg'));
or
import { downloadPng } from 'svg-crowbar';
downloadPng(document.querySelector('svg'), 'my_svg', { css: 'internal' });
The downloadSVG
/downloadPNG
functions each have three arguments:
downloadSVG(svgElement, [filename], [options])
downloadPNG(svgElement, [filename], [options])
svgElement (required)
A DOM element selector for an SVG, e.g. document.querySelector('svg')
. An error is thrown if no valid SVG element was provided.
filename (optional)
A string to set the filename. This is determined by element id, class or page title, when not provided explicitly.
options (optional)
An object literal. It presently has just a single configurable property:
options.css (optional)
This setting determines how the SVG will be styled:
'inline'
Default value. Inlines all computed styles on every element in the SVG. This setting best ensures that the exported SVG is accurate cross-browser.
'internal'
Adds an internal block of styles containing only explicitly declared style rules (from document.styleSheets
). This can drastically reduce file-sizes and build time in exported SVGs, but could be less accurate as it does not include styles from the browser's user agent stylesheet, or from cross-origin stylesheets (e.g. external webfonts).
'none'
Doesn't add any CSS. This gives the smallest file-size, but you might need to manually add your own styles to exported SVGs to ensure an accurate output. You can do this by injecting a <style>
block into the selected SVG before exporting.
Example:
const svg = document.querySelector('svg');
// Add inline styles on SVG elements:
downloadSvg(svg, 'my_svg');
downloadSvg(svg, 'my_svg', { css: 'inline' });
// Add a <style> block in the SVG:
downloadSvg(svg, 'my_svg', { css: 'internal' });
// Do not add CSS:
downloadSvg(svg, 'my_svg', { css: 'none' });
Thanks to @richardwestenra there's UMD bundle available in the package: simply add
<script src="node_modules/svg-crowbar/dist/main.js"></script>
to get downloadSvg
and downloadPng
global function.
FAQs
A library based on a Chrome-specific bookmarklet that extracts SVG nodes and accompanying styles from an HTML document and downloads them as an SVG file
The npm package svg-crowbar receives a total of 494 weekly downloads. As such, svg-crowbar popularity was classified as not popular.
We found that svg-crowbar demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.