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 🙏

© 2026 – Pkg Stats / Ryan Hefner

svg-inline-images

v1.0.0

Published

Tool for making SVG files self-contained

Readme

svg-inline-images

A Scalar Vector Graphics (SVG) document may contain images (via the <image> tag), which can point at external image files. In order to make a more portable .svg file, this tool converts them to data URLs so that the images are embedded inline.

To do this, svg-inline-images requires the Document Object Model (DOM). For headless (nodejs) use, this can be provided by jsdom. The DOM is unaltered, and the content of a new .svg file is returned as a string.

svg-inline-images has a single production dependency upon the mime-types package.

Installation

npm install svg-inline-images

Documentation

Function: svgElementInlineImages()

svgElementInlineImages(svgElement, fetchLite): Promise<string>

Defined in: svgInlineImages.ts:16

Inlines the images of an svg element

Parameters

svgElement

Element

an SVGElement

fetchLite

FetchLite

a fetch or fs.promises.readFile function, used to retrieve the image

Returns

Promise<string>

a promise which resolves to a string containing the svg content with images inlined.

Example

const svgElement = document.querySelector('svg');
const svgText = await svgElementInlineImages(svgElement, fetch);

Function: svgTextInlineImages()

svgTextInlineImages(svgText, fetchLite, document): Promise<string>

Defined in: svgInlineImages.ts:57

Inlines the images of an svg string

Parameters

svgText

string

the text of a .svg file, or the outerHTML of an svg element

fetchLite

FetchLite

a fetch or fs.promises.readFile function, used to retrieve the image

document

Document

Returns

Promise<string>

a promise which resolves to a string containing the svg content with images inlined.

Example

const svgText = await svgTextInlineImages('<svg></svg>', fetch, document);
const svgText = await svgTextInlineImages(
    '<svg></svg>',
    fs.promises.readFile,
    myJsDomDocument
);

Function: svgFileInlineImages()

svgFileInlineImages(path, fetchLite, document): Promise<string>

Defined in: svgInlineImages.ts:93

Inlines the images of an svg file

Parameters

path

string

the url or path to the svg file

fetchLite

FetchLite

a fetch or fs.promises.readFile function, used to retrieve the svg and image files

document

Document

Returns

Promise<string>

a promise which resolves to a string containing the svg content with images inlined.

Example

const svgText = await svgFileInlineImages(
    'http://example.com/myFile.svg',
    fetch,
    document
);
const svgText = await svgFileInlineImages(
    'myFile.svg',
    fs.promises.readFile,
    myJsDomDocument
);

Type Alias: FetchLite()

FetchLite = (path) => Promise<FetchLiteResponse>

Defined in: fetchLite.ts:18

A paired down fetch type compatible with both fetch functions and fs.promises.readFile

In browser you would typically literally pass fetch as a parameter, in order to use your browser's fetch function. However, because usually fetch does not support file:// urls, it may be desirable when working headlessly in nodejs to pass fs.promises.readFile instead. Alternatively, in a nodejs application, it might make sense to use node-fetch or nodejs's native fetch implementation. Finally, you could of course provide another/your own implementation of FetchLite.

By requiring fetchLite as a parameter, and providing it, we can ensure the correct dependency is injected for whatever JavaScript environment we are in.

Parameters

path

string

The url or path of the file we are fetching

Returns

Promise<FetchLiteResponse>

A promise from which the fetched file can ultimately be obtained as an ArrayBufferLike object

Type Alias: FetchLiteResponse

FetchLiteResponse = Buffer<ArrayBufferLike> | { arrayBuffer: () => Promise<ArrayBufferLike>; }

Defined in: fetchLite.ts:20