1.0.2 • Published 6 years ago

watch-os-color-scheme v1.0.2

Weekly downloads
2
License
CC0-1.0
Repository
github
Last release
6 years ago

Watch OS Color Scheme

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.

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago