node-monkey
Advanced tools
Comparing version 0.2.3 to 0.2.4
# NodeMonkey API | ||
Assuming: | ||
```js | ||
var nomo = require('node-monkey'); | ||
``` | ||
@@ -54,2 +58,2 @@ ## nomo.setConfig(config) | ||
## nomo.revertConsole() | ||
Like `replaceConsole()` you should generally never need to call this. You may do so if you want the console functions to return to their normal function and just dump data out to the terminal. | ||
Like `replaceConsole()` you should generally never need to call this. You may do so if you want the console functions to return to their normal function and just dump data out to the terminal. |
24
index.js
@@ -74,2 +74,22 @@ require('./src/cycle.js'); | ||
prepSendData: function(data) { | ||
// Decycle | ||
var sendData = JSON.decycle(data); | ||
// Replace function()'s with placeholders | ||
(function freplace(rdata) { | ||
for(var prop in rdata) { | ||
if(_.isFunction(rdata[prop])) { | ||
// At some point in the future this could replace it with a version of the function capable of making | ||
// using a command to actually call the function over the websocket. | ||
rdata[prop] = rdata[prop].toString(); | ||
} else if(_.isObject(rdata[prop])) { | ||
freplace(rdata[prop]); | ||
} | ||
} | ||
})(sendData); | ||
return sendData; | ||
}, | ||
consoleMsg: function(type, data) { | ||
@@ -91,3 +111,5 @@ var that = this; | ||
// Send to open sockets if there is at least one, otherwise buffer | ||
var consoleData = {type: type, data: JSON.decycle(Array.prototype.slice.call(data)), callerData: callerData}; | ||
var sendData = this.prepSendData(Array.prototype.slice.call(data)); | ||
var consoleData = {type: type, data: sendData, callerData: callerData}; | ||
if(!this.iosrv || !_.keys(this.iosrv.sockets.sockets).length) { | ||
@@ -94,0 +116,0 @@ this.clog('No clients - buffering'); |
@@ -5,5 +5,5 @@ { | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "A Node.js module for inspecting, profiling and debugging Node.js applications through a web browser", | ||
"keywords": ["inspect", "debug", "console.log", "profile"], | ||
"keywords": ["inspect", "debug", "debugging", "console", "log", "profile", "profiler"], | ||
"homepage": "https://github.com/jwarkentin/node-monkey", | ||
@@ -10,0 +10,0 @@ "bugs": "https://github.com/jwarkentin/node-monkey/issues", |
@@ -11,4 +11,6 @@ NodeMonkey | ||
Version 0.2.0 also introduces code profiling functionality and the ability to send commands to your Node.js application from your web browser. | ||
Version 0.2.1 introduces major changes and cleanup. You can now register your own commands that can then be run from the browser. | ||
Version 0.2.1 introduces major changes and cleanup. You can now register your own commands that can be run from the browser's Javascript console. | ||
-- | ||
The motivation for this project came from trying to debug a Node.js server I wrote that used websockets. | ||
@@ -24,2 +26,7 @@ I found it problematic trying to inspect objects with the terminal. | ||
Compatibility | ||
------------- | ||
Any browser with a Javasript console and websocket soupport! | ||
Installation | ||
@@ -44,7 +51,7 @@ ------------ | ||
* [NodeMonkey API](https://github.com/jwarkentin/node-monkey/blob/master/doc/nomo.md) | ||
* [Profiler API](https://github.com/jwarkentin/node-monkey/blob/master/doc/profiler.md) | ||
* [NodeMonkey API](doc/nomo.md) | ||
* [Profiler API](doc/profiler.md) | ||
Usage | ||
----- | ||
Quick Usage | ||
----------- | ||
@@ -63,3 +70,4 @@ Using NodeMonkey is extremely easy. | ||
As an alternative to viewing output through this page, you can also view output in the console of your own web application by including the following lines: | ||
As an alternative to viewing output through this page, you can also view output in the console of your own web application by including the following lines | ||
(adjust the host and port as necessary, this is based on the defaults): | ||
@@ -66,0 +74,0 @@ ```html |
@@ -19,2 +19,20 @@ (function() { | ||
} else { | ||
// Replace function placeholder's with actual functions | ||
(function freplace(rdata) { | ||
for(var prop in rdata) { | ||
if(typeof(rdata[prop]) == 'string' && rdata[prop].substr(0, 9) == 'function ') { | ||
// At some point in the future this could either call .toString() on the function or replace it with a version | ||
// of the function capable of making using a command to actually call the function over the websocket. | ||
try { | ||
eval('rdata[prop] = ' + rdata[prop]); | ||
} catch(err) { | ||
rdata[prop] = function() {}; | ||
} | ||
} else if(_.isObject(rdata[prop])) { | ||
freplace(rdata[prop]); | ||
} | ||
} | ||
})(data.data); | ||
data.data = JSON.retrocycle(data.data); | ||
@@ -21,0 +39,0 @@ |
@@ -103,5 +103,3 @@ /* | ||
return nu; | ||
case 'number': | ||
case 'string': | ||
case 'boolean': | ||
default: | ||
return value; | ||
@@ -108,0 +106,0 @@ } |
11
test.js
@@ -13,3 +13,14 @@ var clog = console.log; | ||
// Test sending functions | ||
console.log({ | ||
testfunc: function() {}, | ||
nestedArray: [ | ||
function() {}, | ||
function() {}, | ||
function() {}, | ||
{ nested: function() {} } | ||
] | ||
}); | ||
// | ||
@@ -16,0 +27,0 @@ // -- Test profiling -- |
- console.trace() functionality | ||
- Catch unhandled exceptions and pass them through before dying | ||
- Pass data through to client, even if there's a fatal exception | ||
- Send full object representation, including function()'s | ||
- Replace object's functions with a call that sends a command, runs the function and returns the result | ||
@@ -6,0 +5,0 @@ - Is it possible to rebuild full objects including inheritance? |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37969
548
152