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

favicon-badge-notify

v1.1.5

Published

favicon badge notify

Downloads

197

Readme

🟠 Favicon Badge Notify

npm npm bundle size npm GitHub license

:books: Introduction

Favicon Badge Notify implemented as custom function.

:rocket: Examples

Check our Reactjs 👉 example

Check our Vuejs 👉 example

Check our Solidjs 👉 example

:package: Installation

# install with yarn
yarn add favicon-badge-notify
# install with npm
npm install favicon-badge-notify
# install with pnpm 
pnpm add favicon-badge-notify

:sparkles: Reactjs example

import { useState, useEffect } from 'react'
import { Helmet } from "react-helmet"

import useFaviconBadgeNotify from 'favicon-badge-notify'
import faviconSvg from "./assets/favicon.svg";

function ReactFaviconBadgeNotify() {
  const [count, setCount] = useState(0)
  const [favicon, setFavicon] = useState(faviconSvg)
  const { drawBadge, destroyBadge } = useFaviconBadgeNotify({
    src: faviconSvg,
    badgeValue: count,
  })

  useEffect(() => {
    drawBadge().then(badge => setFavicon(badge));

    return () => destroyBadge();
  }, [count]);

  return (
    <div className="App">
      <Helmet>
        <link rel="icon" type="image/png" sizes="128x128" href={favicon}></link>
      </Helmet>
      <header className="App-header">
        <p className="buttons">
          <button type="button" className="increase" onClick={() => setCount((count) => count + 1)}>
            increase
          </button>
          <span>{count}</span>
          <button type="button" className="decrease" onClick={() => count - 1 >= 0 && setCount((count) => count - 1)}>
            decrease
          </button>
        </p>
      </header>
    </div>
  )
}

export default ReactFaviconBadgeNotify

:sparkles: Vuejs example

<script setup lang="ts">
import { reactive, onBeforeUnmount, watch } from 'vue';
import { Head } from '@vueuse/head';
import useFaviconBadgeNotify from 'favicon-badge-notify';

const state = reactive({
  favicon: '/favicon.svg',
  count: 0
});

const setFavicon = (val: string) => state.favicon = val;
const setCount = (val: number) => state.count = val;

const { drawBadge, destroyBadge } = useFaviconBadgeNotify({
  src: state.favicon
});

watch(
  () => state.count,
  (count, prevCount) => {
    drawBadge(count).then((badge) => setFavicon(badge));
  }
);

onBeforeUnmount(() => {
  destroyBadge();
});
</script>

<template>
  <Head>
    <link rel="icon" type="image/png" sizes="128x128" :href="state.favicon" />
  </Head>
  <p class="buttons">
    <button type="button" class="increase" @click="setCount(state.count + 1)">increase</button>
    <span>{{ state.count }}</span>
    <button type="button" class="decrease" @click="state.count - 1 >= 0 && setCount(state.count - 1)">
      decrease
    </button>
  </p>
</template>

:sparkles: Solidjs example

import { Component, createEffect, createSignal } from 'solid-js';
import { MetaProvider, Link } from '@solidjs/meta';

import useFaviconBadgeNotify from 'favicon-badge-notify';
import faviconSvg from './assets/favicon.svg';

const SolidFaviconBadgeNotify: Component = () => {
  const [count, setCount] = createSignal<number>(0);
  const [favicon, setFavicon] = createSignal<string>(faviconSvg);
  const { drawBadge, destroyBadge } = useFaviconBadgeNotify({
    src: faviconSvg
  });

  createEffect(() => {
    drawBadge(count()).then((badge: any) => setFavicon(badge));

    return () => destroyBadge();
  }, [count()]);

  return (
    <div class={styles.App}>
      <MetaProvider>
        <Link rel="icon" type="image/png" sizes="128x128" href={favicon()} />
      </MetaProvider>
      <header class={styles.header}>
        <p class={styles.buttons}>
          <button type="button" class={styles.increase} onClick={() => setCount(count() + 1)}>
            increase
          </button>
          <span>{count}</span>
          <button
            type="button"
            class={styles.decrease}
            onClick={() => count() - 1 >= 0 && setCount(count() - 1)}>
            decrease
          </button>
        </p>
      </header>
    </div>
  );
};

export default SolidFaviconBadgeNotify;

📄 License