loadicons
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/loadicons package

1.0.0 • Public • Published

loadIcons

Load SVG icon sprites safely and asynchronously

Installation

npm install --save-dev loadicons

Usage

Assuming you have a sprite sheet called sprite.svg that looks something like this:

<svg xmlns="http://www.w3.org/2000/svg">
  <symbol id="more" viewBox="0 0 36 36">
    <circle cx="18" cy="18" r="4.1"></circle>
    <circle cx="30" cy="18" r="4.1"></circle>
    <circle cx="6" cy="18" r="4.1"></circle>
  </symbol>
</svg>

You can load the sprite sheet with:

const loadIcons = require('loadicons');
loadIcons('sprite.svg', function(err, svg) {
  if (err) {
    console.error('Everything failed because ' + error);
  }
  else {
    console.log('SVG loaded!', svg);
  }
});

Then, you can use loaded icons with <use>:

<svg>
  <use xlink:href="#more" />
</svg>

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i loadicons

      Weekly Downloads

      282

      Version

      1.0.0

      License

      Apache-2.0

      Unpacked Size

      20.4 kB

      Total Files

      6

      Last publish

      Collaborators

      • garthdb
      • lazd
      • stevegill