Licence
MIT
Version
1.0.1
Deps
1
Size
35 kB
Vulns
0
Weekly
0
DeprecatedThis package is deprecated
darky.js
How to Install
At the beginning install the library in Your project via npm or Yarn:
$ npm install darky
$ yarn add darky
Getting Started
Connect using script tag in HTML:
<script src="/directory/to/library/folder/darky.js"></script>
Or CommonJS/ES6 import:
const Darky = require('darky'); // CommonJS
import Darky from 'darky'; // ES6
Next use library with:
• Vanilla JavaScript e.g:
const darky = new Darky({
// options...
});
Functions
• Switch between light and dark mode:
darky.toggle();
• Switch mode automatically (based on time, location and sun position):
darky.auto();
• Reset localStorage data:
darky.reset();
Options
| Name | Type | Default | Description | Available options |
|---|---|---|---|---|
| lightClass | string | |
Class added to body when light mode is active | Name of the class |
| darkClass | string | dark |
Class added to body when dark mode is active | Name of the class |
| cache | boolean | true |
cache location coordinates in local storage for one day | true (enable), false (disable) |
| cacheClear | boolean | true |
clear location coordinates in local storage everyday at midnight | true (enable), false (disable) |
| auto | boolean | true |
enable smart switch on script init | true (enable), false (disable) |
| onAuto | function | null |
callback on smart switch | () => { // code } |
| onLight | function | null |
callback when dark mode is disabled | () => { // code } |
| onDark | function | null |
callback when dark mode is enabled | () => { // code } |
| onToggle | function | null |
callback on dark/light mode toggle | () => { // code } |
| onCacheClear | function | null |
callback when location coordinates and midnight time in local storage cleared | () => { // code } |
| onReset | function | null |
callback on localStorage reset | () => { // code } |
Event
smartDark event will output sun position times and user geolocation latitude & longitude
License
This project is licensed under the MIT License 2018-present Jakub Biesiada