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

darkyjs

v1.2.1

Published

A light, easy-to-use JavaScript library that allows developers to quickly and efficiently implement dark mode on their websites. This library dynamically changes the CSS styles of your website to provide a night mode effect that reduces the light emitted

Downloads

11

Readme

Darky.js documentation

Darky.js is a light, easy-to-use JavaScript library that allows developers to quickly and efficiently implement dark mode on their websites. This library dynamically changes the CSS styles of your website to provide a night mode effect that reduces the light emitted by the screen.

How to use Darky

Include the Darky.js library in your HTML file and Instantiate a new Darky object to add a darkmode toggle to your webpage:

The easy way (JSDelivr CDN)

<script src="https://cdn.jsdelivr.net/npm/[email protected]/1.2.0/darky.min.js"></script>
<script>
    const darkmode = new Darky();
    darkmode.enable();
</script>

Or download Darky.js and host it yourself.

Using NPM

npm install darkyjs

Options

Here are the available options

  • bottom: (String) CSS value for the widget position from the bottom. Defaults to "32px".
  • right: (String) CSS value for the widget position from the right. Defaults to "32px".
  • left: (String) CSS value for the widget position from the left. Defaults to "unset".
  • time: (String) CSS value for transition time. Defaults to "300ms".
  • backgroundColor: (String) CSS value for the background color in dark mode. Defaults to "#fff".
  • buttonColorDark: (String) CSS value for the dark mode button color. Defaults to "#000".
  • buttonColorLight: (String) CSS value for the light mode button color. Defaults to "#fff".
  • label.dark: (String) HTML content for the dark mode button label. Defaults to a SVG moon icon.
  • label.light: (String) HTML content for the light mode button label. Defaults to a SVG sun icon.
  • saveInCookies: (Boolean) if set to true, the user's preference will be saved in a cookie. Defaults to false.
  • autoMatchOsTheme: (Boolean) if set to true, the color theme will automatically match the user's OS preference. Defaults to true.
  • onChnge: (Function) Provides a callback whenever darkmode is toggled on or off. Defaults to false.

Example

const options = {
    bottom: "32px",
    right: "32px",
    left: "unset",
    time: "300ms",
    backgroundColor: "#fff",
    buttonColorDark: "#000",
    buttonColorLight: "#fff",
    buttonShadow: "0 0.2rem 0.5rem 0.1rem rgba(0,0,0,0.4)",
    zIndex: 9998,
    label: {
        dark: '<svg xmlns="http://www.w3.org/2000/svg" class="icon light" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M14.828 14.828a4 4 0 1 0 -5.656 -5.656a4 4 0 0 0 5.656 5.656z"></path><path d="M6.343 17.657l-1.414 1.414"></path><path d="M6.343 6.343l-1.414 -1.414"></path><path d="M17.657 6.343l1.414 -1.414"></path><path d="M17.657 17.657l1.414 1.414"></path><path d="M4 12h-2"></path><path d="M12 4v-2"></path><path d="M20 12h2"></path><path d="M12 20v2"></path></svg>',
        light: '<svg xmlns="http://www.w3.org/2000/svg" class="icon dark" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z"></path></svg>',
    },
    saveInCookies: false,
    autoMatchOsTheme: true,
    onChange: false
}
const darkmode = new Darky(options);
darkmode.enable();

Methods

Use the following methods to interact with the Darky library:

  • darky.enable();: This method enables the Darky widget on your webpage.
  • darky.toggle();: This method toggles the darkmode on or off. When called, it checks the current mode and changes it to the opposite one.
  • darky.isEnabled();: This method checks if darkmode is currently enabled and returns a boolean value.

Example

const darkmode = new Darky();
darkmode.enable();      // Activates the Darky widget
darkmode.toggle();      // Toggles darkmode on/off
darkmode.isEnabled();   // Returns true if darkmode is enabled

Events

The following events are available:

  • onChange: This callback function fires whenever darkmode is toggled on or off and returns the result of the defined JS.

Example

const darkmode = new Darky(
    onChange: function() {
    console.log('Darkmode was toggled');
    // JS goes here
    }
);
darkmode.enable();

Overrides

By default the following elements are not converted to dark mode: img, picture, video. There are several ways to prevent an element from being converted:

  1. Add the class darkmode--ignore to the elements HTML:
<span class="darkmode--ignore">I AM NOT DARKMODE<span>
  1. Add the following CSS to the element:
.element {
    isolation: isolate;
}
  1. Revert the darkmode like so
.darkmode--enabled .element {
    mix-blend-mode: difference;
}