UNPKG

captainslog

Version:

Universal log wrapper for browser development. Runs on stardates.

1 lines 3.2 kB
!function(t){if("object"==typeof exports)module.exports=t();else if("function"==typeof define&&define.amd)define(t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.Captain=t()}}(function(){return function t(e,n,r){function o(s,a){if(!n[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);throw new Error("Cannot find module '"+s+"'")}var f=n[s]={exports:{}};e[s][0].call(f.exports,function(t){var n=e[s][1][t];return o(n?n:t)},f,f.exports,t,e,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(t,e,n){var r;e.exports=r=function(){function t(e){var n,r,o,i;switch(null==e&&(e=new Date),typeof e){case"number":this.stardate=e,i=Math.floor(e),r=Date.UTC(i,0,1,0,0,0,0),o=Date.UTC(i+1,0,1,0,0,0,0),this.date=new Date(r+(o-r)*(e-i));break;case"object":if(e instanceof Date)this.date=new Date(e),i=this.date.getUTCFullYear(),r=Date.UTC(i,0,1,0,0,0,0),o=Date.UTC(i+1,0,1,0,0,0,0),n=Date.UTC(i,this.date.getUTCMonth(),this.date.getUTCDate(),this.date.getUTCHours(),this.date.getUTCMinutes(),this.date.getUTCSeconds(),this.date.getUTCMilliseconds()),this.stardate=i+(n-r)/(o-r);else{if(!(e instanceof t))throw"Unable to convert "+e+" to StarDate";this.stardate=e.stardate,this.date=new Date(e.date)}break;default:throw"Unable to convert "+e+" to StarDate"}}return t.prototype.canonical=function(){return this.stardate.toFixed(15)},t.prototype["short"]=function(){return this.stardate.toFixed(3)},t}()},{}],2:[function(t,e,n){(function(n){"use strict";function r(){}function o(t){return t instanceof Error&&(t.stack?t=t.message&&t.stack.indexOf(t.message)===-1?"Error: "+t.message+"\n"+t.stack:t.stack:t.sourceURL&&(t=t.message+"\n"+t.sourceURL+":"+t.line)),t}function i(t){var e=n.console||{},i=e[t]||e.log||r,s=!1;try{s=!!i.apply}catch(a){}return s?function(){for(var t=[],n=0;n<arguments.length;n++)t.push(o(arguments[n]));return i.apply(e,t)}:function(t,e){i(t,null===e?"":e)}}function s(t){return this.settings={name:"string"==typeof t?t:f.name,debug:f.debug},this.history=[],this}var a=t("stardate"),u={log:i("log"),debug:i("debug"),warn:i("warn"),error:i("error")},f={name:"James T. Kirk",debug:!0};s.prototype.toggleDebug=function(t){return this.settings.debug=void 0===t?!this.settings.debug:!!t,this.settings.debug},s.prototype._entry=function(t,e,n){!n&&u[t]&&u[t].apply(this,e);var r={stardate:new a,type:t,message:e};return this.history.push(r),r},s.prototype.log=function(){return this._entry("log",arguments)},s.prototype.debug=function(){return this._entry("debug",arguments,!this.settings.debug)},s.prototype.warn=function(){return this._entry("warn",arguments)},s.prototype.error=function(){return this._entry("error",arguments)},s.prototype.read=function(){for(var t,e=0;e<this.history.length;e++)t=["Captain's log, star date: ",this.history[e].stardate.stardate,"\n",this.history[e].message],u[this.history[e].type]?u[this.history[e].type].apply(this,t):u.log.apply(this,t)},e.exports=s}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{stardate:1}]},{},[2])(2)});