1.2.0 • Published 5 years ago

night.js v1.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

night.js

NPM version NPM downloads

How to Install

At the beginning install the library in your project via npm or Yarn:

$ npm install night.js
$ yarn add night.js

Getting Started

Connect using script tag in HTML:

<script src="/directory/to/library/folder/night.js"></script>

Or CommonJS/ES6 import:

const Night = require('night.js'); // CommonJS
import Night from 'night.js'; // ES6

Next use library with:

Vanilla JavaScript e.g:

const night = new Night({
  // options...
});

Functions

Switch between light and dark mode:

night.toggle();

• Switch mode automatically (based on time, location and sun position):

night.auto();

• Reset localStorage data:

night.reset();

Options

NameTypeDefaultDescriptionAvailable options
lightClassstringClass added to body when light mode is activeName of the class
darkClassstringdarkClass added to body when dark mode is activeName of the class
cachebooleantrueCache location coordinates in local storage for one daytrue (enable), false (disable)
cacheClearbooleantrueClear location coordinates in local storage everyday at midnighttrue (enable), false (disable)
autobooleantrueEnable smart switch on script inittrue (enable), false (disable)
onAutofunctionnullCallback on smart switch() => { // code }
onLightfunctionnullCallback when dark mode is disabled() => { // code }
onDarkfunctionnullCallback when dark mode is enabled() => { // code }
onTogglefunctionnullCallback on dark/light mode toggle() => { // code }
onDeniedfunctionnullCallback on geolocation permission denied() => { // code }
onCacheClearfunctionnullCallback when location coordinates and midnight time in local storage cleared() => { // code }
onResetfunctionnullCallback on localStorage reset() => { // code }

Events

smartDark event will output sun position times and user geolocation latitude & longitude

smartDarkError event will output message when permission to geolocation is denied

License

This project is licensed under the MIT License © 2018-present Jakub Biesiada

1.2.0

5 years ago

1.2.0-beta.2

5 years ago

1.2.0-beta.1

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.4-beta.1

5 years ago

1.1.4-beta.0

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.1.0-beta.1

6 years ago