1.0.2 • Published 7 years ago
watch-os-color-scheme v1.0.2
Watch OS Color Scheme
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-schemeWatch 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.