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

inline-svg

v2.2.3

Published

Takes an inline image with an SVG as it's source and swaps it for an inline SVG

Downloads

13,396

Readme

Inline SVG

Build Status Code Climate npm Bower Dependency Status

Takes an inline <img> with an SVG as its source and swaps it for an inline <svg> so you can manipulate the style of it with CSS/JS etc.

How to use

Add the Inline SVG script to your page and initialise the script. You can currently pass three options to the script: svgSelector and initClass. If these are left out the script will use the defaults.

<script src="inlineSVG.min.js"></script>
<script>
inlineSVG.init({
  svgSelector: 'img.svg', // the class attached to all images that should be inlined
  initClass: 'js-inlinesvg', // class added to <html>
}, function () {
  console.log('All SVGs inlined');
});
</script>

The callback is optional and is only fired if all the images in the selection are successfully inlined. On the other hand the initClass is applied after the first successful replacement.

The script will look for any <img> with a class that matches the svgSelector parameter and replace it with the SVG's source. Doing this enables you to manipulate the SVG with CSS and JavaScript.

<img id="logo" class="svg" src="/images/logo.svg" alt="Some awesome company" />
svg:hover path {
  fill: #c00;
}

// or
#logo:hover path {
  fill: #c00;
}

Any additional attributes (height, width, data-*, etc) will be copied to the SVG. For increased accessibility the script will also copy across the <img> alt text and add in an aria-labelledby attribute and <title> element to the SVG. If you give the <img> a longdesc attribute, a <desc> will also be added as per the W3C's guidelines on SVG accessibility.

For a live demo check out this example on CodePen. The demo is still there it's just way out of date and needs updating.

Bower

If you're using Bower to manage your front-end dependencies you can include this plugin as a component. Include "inline-svg": "2.2.3" in your bower.json file and run bower install.

NPM

If you're using NPM to manage your dependencies you can include this plugin as a module. Just run npm install inline-svg.

Changelog

  • 05/05/16: 2.2.2 – Updated documentation.
  • 05/05/16: 2.2.2 – Fixed callback error if one is not defined.
  • 16/10/15: 2.2.1 – Fix for adding the initClass to the body each time an SVG is inlined.
  • 23/09/15: 2.2.0 – Fix in package.json for main field when using as a module and added callback support to know when replacement is complete.
  • 21/09/15: 2.1.5 – Removing to code that should never have made it to release.
  • 21/09/15: 2.1.4 – Version bump.
  • 21/09/15: 2.1.3 – Version bump.
  • 26/08/15: 2.1.2 – Removed localStorage. It just doesn't work that well when SVG's change etc.
  • 31/07/15: 2.1.1 – Added localStorage support to avoid making fresh HTTP request on every page load. When the contents of the SVG is loaded it is added to localStorage and then on repeat page loads the source is grabbed from localStorage.
  • 31/07/15: 2.0.1 - Major upgrade. Added AMD support and fixed a long standing issue that would result in a warning in Google Chrome as we weren't handling the GET requests asynchronously.
  • 18/06/15: 1.2.0 – Converted to a Node.js module
  • 19/03/15: 1.0.5 – Cleaning code to comply with Code Climate
  • 16/12/14: 1.0.4 – Updated README with new CodePen demo and added an extra line regarding browser support. Changed aria-label to aria-labelledby and also added role="img" for better accessibility.
  • 15/12/14: 1.0.3 – Updated bower.json version number.
  • 15/12/14: 1.0.2 – README updates to explain browser support.
  • 15/12/14: 1.0.1 – README updates to explain Bower integration.
  • 15/12/14: 1.0.0 – First major release: registered as a Bower plugin.