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 🙏

© 2025 – Pkg Stats / Ryan Hefner

inject-favicon

v1.1.2

Published

CLI & helper function to inject HTML code snippet for favicons and manifest into an html file

Readme

inject-favicon

inject-favicon @ npm

A CLI & helper function to inject HTML code snippet for favicons and manifest into an html file.

The following is an example of the code snippet to be inserted as the last item of <HEAD>.

<meta name="theme-color" content="#123456">
<meta name="msapplication-TileColor" content="#123456">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#123456">
<link rel="manifest" href="/site.webmanifest">

Install as CLI

npm i -g inject-favicon

Usage

inject-favicon [-s|--search <dir>] [-u|--url <url>] [options] [ [-i|--input]
<input_file> ] [ [-o|--output] <output_file> ]

Options:
  --help              Show help                                        [boolean]
  --version           Show version number                              [boolean]
  -s, --search        Path to search for icons and manifest       [default: "."]
  -u, --url           Hosting path/URL of the icons               [default: "/"]
  -i, --input         Path to input html file            [default: "/dev/stdin"]
  -o, --output        Path to output html file          [default: "/dev/stdout"]
  --color             Default color for theme color, mask icon color and tile
                      color. Defauts to theme_color specified in manifest if
                      available.                                        [string]
  --theme-color       Theme color, used by Chrome and others            [string]
  --mask-color        Mask icon color used by Safari pinned tab icon    [string]
  --tile-color        Windows Start Screen pinned site tile color       [string]
  --icon              Glob for traditional favicon
                              [array] [default: ["favicon.png","favicon-*.png"]]
  --apple-touch-icon  Glob for apple touch icon
            [array] [default: ["apple-touch-icon.png","apple-touch-icon-*.png"]]
  --mask-icon         Glob for Safari mask icon
                                    [array] [default: ["safari-pinned-tab.svg"]]
  --manifest          Glob for Web App Manifest
               [array] [default: ["*.manifest","*.webmanifest","manifest.json"]]

Examples

# Reads stdin and wrties stdout by default
inject-favicon -s /path/to/favicons/dir < original.html > injected.html
curl -s example.com | inject-favicon -s /path/to/favicons/dir > my.html

# Specify the same file as input and output to make change in-place
inject-favicon -s /path/to/favicons/dir -i path/to/my/file.html -o path/to/my/file.html

# Disable generation HTML for apple-touch-icon
inject-favicon -s /path/to/favicons/dir --apple-touch-icon '' -i input.html -o output.html

# Fine tune with more options
inject-favicon \
  --search /path/to/favicons/dir \
  --url 'https://example.com' \
  --color '#123456' \
  --mask-color '#234567' \
  --tile-color '#345678' \
  --icon favicon.ico \
  --apple-touch-icon apple-touch-icon-precomposed.png \
  --apple-touch-icon 'apple-touch-icon-*-precomposed.png' \
  --manifest app.json

Install as package dependency

npm i inject-favicon

Usage & Examples

HTML string as arguments

API:

const { injectFavicon } = require('inject-favicon');
injectFavicon(html, opts);

Code Example:

const { injectFavicon } = require('inject-favicon');
const html = '<!doctype html><html><head><title>Hello World</title></head><body>Morning World</body></html>';
(async () => {
  const injectedHTML = await injectFavicon(html, {
    search: '~/favicons',
  });
  console.log(injectedHTML);
})()

Filename as arguments

API:

const injectFaviconFile = require('inject-favicon/cli');
injectFaviconFile(input, output, opts);

Code Example:

const injectFaviconFile = require('inject-favicon/cli');

const inputFilename = 'a.html';
const outputFilename = 'b.html';
injectFaviconFile(inputFilename, outputFilename, {
  search: '~/favicons',
});

Debug

Set environment variable DEBUG to * or inject-favicon.

LICENSE

MIT