watch-os-color-scheme

1.0.2 • Public • Published

Watch OS Color Scheme stylelint

NPM Version Build Status Support Chat

Watch OS Color Scheme lets you watch your OS color scheme, similar to the Media Queries @media (prefers-color-scheme) specification.

Usage

Add Watch OS Color Scheme to your project:

npm install watch-os-color-scheme

Watch the OS for color scheme changes:

const watchOsColorScheme = require('watch-os-color-scheme');
 
const stop = watchOsColorScheme(prefersColorScheme => {
  console.log({ prefersColorScheme }); // no-preference | light | dark
});
 
stop();

Watch OS Color Scheme takes 2 arguments; a callback and an interval; and it returns a stop function.

callback

The callback listener is called as the color scheme is initially detected and then each time the color scheme subsequently changes. It returns a single argument; a colorScheme string representing the preferred color scheme of the OS, which is either no-preference, light, or dark.

interval

The interval number indicates how often the color scheme should be polled in milliseconds.

stop

The stop function stops watching for color scheme changes.

Package Sidebar

Install

npm i watch-os-color-scheme

Weekly Downloads

3

Version

1.0.2

License

CC0-1.0

Unpacked Size

10.7 kB

Total Files

5

Last publish

Collaborators

  • jonathantneal