npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

parse-simple-svg-meta-pmb

v0.1.0

Published

Given the source of a simple SVG image, find basic info about its outermost SVG tag.

Downloads

17

Readme

parse-simple-svg-meta-pmb

Given the source of a simple SVG image, find basic info about its outermost SVG tag.

Not an XML parser

This package is not supposed to be an XML parser. It can understand only a very simple subset of SVG. The intent is to limit complexity low enough to allow using very defensive RegExps for parsing. The downside of this simplicity is that any fancy shenanigans in the SVG code will cause the parser to just give up and fail.

Examples of what's NOT supported:

  • ⛔ Namespaces on tags
  • ⛔ Anything about hierarchy or closing tags
  • ⛔ Reliable detection of malformed tags.
  • ⛔ Characters outside the Basic Latin block.
  • ⛔ Most control characters in the Basic Latin block.
  • ⛔ Reliably preserving whitespace in attribute values.
  • ⛔ Character entities (e.g. " or ')
  • ⛔ Length units other than px and user units.
  • ⛔ User units other than pixels.
  • ⛔ Lengths less than or equal to zero.

API

This module exports one function:

findSvgMeta(svg)

svg is the source code of your image as a string.

Returns a dictionary object with at least these properties:

  • widthPx, widthFrac, heightPx, heightFrac: Dimensions of the image.
    • If a dimension is given as absolute length, its …Px value will be set accordingly, and its …Frac value will be 0.
    • If a dimension is given as percentage, its …Frac value will be set to the fraction represented by the percentage, e.g. "42%"0.42.
    • Missing/empty width/height on the outermost SVG tag are defined in the SVG spec to mean 100% of the respective viewport dimension, so their …Frac will be 1 and their …Px will be 0.

Usage

see the tests.

Known issues

  • Needs more/better tests and docs.

 

License

ISC