0.0.1 • Published 9 years ago

mp-debugger v0.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
9 years ago

#Debugger Simple modular object to debbug code (ex. showing in console, creating logs etc.)

Usage

Include js combined file.

<script src="dist/debugger.js"></script>

Add code before your js files to avoid error when you don`t include debbuger files in production version.

if(typeof DEBUGGER == "undefined") DEBUGGER = {run: function(){},addMethod: function(){}};

Run debbuger method

DEBUGGER.run(methodName,vars[,moduleName]);

Arguments:

ArgumentTypeDescription
methodNamestringMethod name
varsmixedVars which are passed to method
moduleNamestringModule name from you call debugger method- is used to simply know where you call method- e.g. method log show in console this property

Example

DEBUGGER.run("info","Some message");

Add methods

To add your own methods call addMethod on object.

DEBUGGER.addMethod(methodName,content [, requiredvars]);

Arguments:

ArgumentTypeDescription
methodNamestringMethod name
contentfunctionMethod, argument is 'vars' which are passed in call method
requiredvarsarrayAll required vars which must contain 'vars' object, not required when you pass only one var

If you dont pass object in call function, debugger create object with 'default' property. Futhermore add 'moduleNameCall' property- moduleName in call method.

Example:

DEBUGGER.addMethod("log", function(Vars){
  
	this.print(Vars.moduleNameCall, Vars.default, "log");
	return true; // all method must return bool var
		
});

 ...
 
DEBUGGER.run("log","Some message"); // string "Some message" is added to Vars.default property

Methods utils

In 'this' object you can use utils methods like:

this.print()

Print messages in console, special debug bar or log file.

this.print(module, message[, type='log', plain=false]);
ArgumentTypeDefaultDescription
modulestring-Module name
messagestring-Show error in console
typestringlogMessage type {log,warn,info,error}
plainboolfalseDon`t print module name

this.setObject()

Save an object for later.

this.setObject(key, object[, methodName='debuger:setObject']);
ArgumentTypeDefaultDescription
keystring-Key
objectmixed-Object to save
methodNamestringdebuger:setObjectMessage type {log,warn,info,error}

this.getObject()

Get previously saved objects.

this.getObject(key, [, methodName='debuger:setObject']);
ArgumentTypeDefaultDescription
keystring-Key
methodNamestringdebuger:setObjectMethod name

this.deleteObject()

Delete an saved object.

this.deleteObject(key [, methodName='debuger:setObject']);
ArgumentTypeDefaultDescription
keystring-Key
methodNamestringdebuger:deleteObjectMethod name

Available default methods

List of methods:

MethodArgumentsDescription
logmessage(string)Show log in console
errormessage(string)Show error in console
warnmessage(string)Show warn in console
infomessage(string)Show info in console
startTimerid(string)Start timer with passed id
stopTimerid(string)Stop timer with passed id and return time in ms
isLibraryLibrary(string)Check if in global scobe is attached library

To do

  • Add debugger method where you can show messages, errors etc... Now you must open console.
  • Add method setConfig which you can set if message shoud show in console or in bar.
  • Add some aliases to different libraries (like fps graph etc).
  • Add method to log and write in file all messages.