Git Product home page Git Product logo

Comments (2)

tigt avatar tigt commented on June 1, 2024

To fix your problem, you would change the code to look more like this:

var miniSvgDataUri = require("mini-svg-data-uri");
var svg = '<svg version="1.1" id="level1" xmlns="http://www.w3.org/2000/svg" x="0" y="0" viewBox="0 0 16 20" xml:space="preserve"><style>.st0{fill:#020203}.st1{fill:#010202}</style><path class="st0" d="M16 4v15c0 .6-.4 1-1 1H1c-.6 0-1-.4-1-1V4c0-.6.4-1 1-1h2v1H1v15h14V4h-2V3h2c.6 0 1 .4 1 1z"/><path class="st0" d="M10 2c0-1.1-.9-2-2-2S6 .9 6 2H4v3h8V2h-2zM3.7 7H14v1H3.7z"/><circle class="st1" cx="2.6" cy="7.5" r=".6"/><path class="st0" d="M3.7 16H14v1H3.7z"/><circle class="st1" cx="2.6" cy="16.5" r=".6"/><g><path class="st0" d="M3.7 10H14v1H3.7z"/><circle class="st1" cx="2.6" cy="10.5" r=".6"/></g><g><path class="st0" d="M3.7 13H14v1H3.7z"/><circle class="st1" cx="2.6" cy="13.5" r=".6"/></g></svg>';
var optimizedSVGDataURI = miniSvgDataUri(svg);

You’re not the only person to be confused by the different function names (see #12), so clearly I should update the readme.

By the way, your SVG could be optimized even better by running it repeatedly through SVGOMG first. That would make your input to this tool look like:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 20"><path d="M16 4v15c0 .6-.4 1-1 1H1c-.6 0-1-.4-1-1V4c0-.6.4-1 1-1h2v1H1v15h14V4h-2V3h2c.6 0 1 .4 1 1z" class="st0"/><path d="M10 2c0-1.1-.9-2-2-2S6 .9 6 2H4v3h8V2h-2zM3.7 7H14v1H3.7z" class="st0"/><circle cx="2.6" cy="7.5" r=".6" class="st1"/><path d="M3.7 16H14v1H3.7z" class="st0"/><circle cx="2.6" cy="16.5" r=".6" class="st1"/><path d="M3.7 10H14v1H3.7z" class="st0"/><circle cx="2.6" cy="10.5" r=".6" class="st1"/><path d="M3.7 13H14v1H3.7z" class="st0"/><circle cx="2.6" cy="13.5" r=".6" class="st1"/></svg>

And you could remove the class attributes to make it even smaller!

from mini-svg-data-uri.

madamadami avatar madamadami commented on June 1, 2024

Thank you very much, now I got it!

from mini-svg-data-uri.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.