UNPKG

hypnos

Version:

Module for determining if device is sleeping

1 lines 968 B
(function(t,e){if(typeof define==="function"&&define.amd){define([],e)}else if(typeof exports==="object"){module.exports=e()}else{t.Hypnos=e()}})(this,function(){function t(t){this.opts={};this.options(t);this._defaults={delay:1500,error:500}}t.prototype.isSleeping=function(t){var e=this;if(typeof t!=="function"){throw new Error("Hypnos module should be provided with callback function")}var o=new Date;setTimeout(function(){var s=new Date;t(s.valueOf()-o.valueOf()-e.opts.delay>e.opts.error)},this.opts.delay)};t.prototype.options=function(t){var e=false;if(typeof t!=="undefined"){if(typeof t!=="object"){throw new Error("Hypnos: The argument passed to options method should be "+"an object")}this.opts=t}else{e=true}for(var o in this._defaults){if(this._defaults.hasOwnProperty(o)){if(typeof this.opts[o]==="undefined"){this.opts[o]=this._defaults[o]}}}if(e){var s={};for(var o in this.opts)if(this.opts.hasOwnProperty(o)){s[o]=this.opts[o]}return s}};return t});