Security News
RubyGems.org Adds New Maintainer Role
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.
Simple tool to transform svg
files and Strings into Object
or JSON
.
Useful to manipulate SVG
with js
, to store in noSQL databses.
yarn add svgson
const { parse, stringify } = require('svgson')
// ----------------------------
// Convert SVG to JSON AST
// ----------------------------
parse(`
<svg>
<line
stroke= "#bada55"
stroke-width= "2"
stroke-linecap= "round"
x1= "70"
y1= "80"
x2= "250"
y2= "150">
</line>
</svg>`).then((json) => {
console.log(JSON.stringify(json, null, 2))
/*
{
name: 'svg',
type: 'element',
value: '',
attributes: {},
children: [
{
name: 'line',
type: 'element',
value: '',
attributes: {
stroke: '#bada55',
'stroke-width': '2',
'stroke-linecap': 'round',
x1: '70',
y1: '80',
x2: '250',
y2: '150'
},
children: []
}
]
}
*/
// -------------------------------
// Convert JSON AST back to SVG
// -------------------------------
const mysvg = stringify(json)
/* returns the SVG as string */
})
umd
usage
const svgson = require('svgson') svgson .parse( `<svg> <line stroke= "#bada55" stroke-width= "2" stroke-linecap= "round" x1= "70" y1= "80" x2= "250" y2= "150"> </line> </svg>` ) .then(function(json) { console.log(JSON.stringify(json, null, 2) ) mysvg = svgson.stringify(json)
Test in browser here
svgson.parse(input[, options])
Returns: Promise
input
Type: String
options.transformNode
Function to apply on each node when parsing, useful when need to reshape nodes or set default attributes.
Type: Function
that returns the node
Default:
function(node){
return node
}
options.camelcase
Apply camelCase
into attributes
Type: Boolean
Default: false
Added in
3.1.0
svgson.parseSync(input[, options])
This function is a synchronous version of svgson.parse
. The arguments are the same, but unlike svgson.parse
, the return value is not wrapped in a Promise
.
Returns: Object
[Object]
svg = svgson.stringify(ast[, options])
Returns: String
ast
svgson
parsed result.
Type: Object
[Object]
options.transformAttr
Function to apply on each attribute when stringifying.
Type: Function
that returns the key/attribute string with the ability to use the escape function on it.
Default:
function(key, value, escape) {
return `${key}="${escape(value)}"`
}
options.selfClose
Type: Boolean
Default: true
Pretty Printing
In order to generate pretty formatted SVG output, use pretty
npm module:
pretty = require('pretty')
formatted = pretty(svg)
svgson-cli Transform SVG into Object
from the Command Line
element-to-path Convert SVG element into path
path-that-svg Convert entire SVG with path
svg-path-tools Tools to manipulate SVG path
(d)
MIT © Lionel T
FAQs
Transform svg files into Objects
The npm package svgson receives a total of 12,998 weekly downloads. As such, svgson popularity was classified as popular.
We found that svgson 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
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.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.