Comparing version 0.9.0 to 0.9.1
28
index.js
var events = require('events'); | ||
var fJSON = require('fbbk-json'); | ||
var consolr = function(){ | ||
function Consolr(){ | ||
var self = this; | ||
this.debug = false; | ||
process.stdin.on('data', function(chunk){ | ||
// Pattern to try a match for ":event some_other_text even with spaces" | ||
var pattern = /(?:\:)(\w+)(?:\s)?([\w \.\,\"\{\}\:\'\[\]]+)?/gi; | ||
// Removes end of line and parses to string the content of the chunk | ||
var text = chunk.toString().replace(/(\r\n|\n|\r)/g, ""); | ||
var eventName = 'command'; | ||
if(matched = pattern.exec(text)){ | ||
@@ -15,9 +19,12 @@ eventName = matched[1]; | ||
} | ||
try { | ||
var json = fJSON.parse(text); | ||
text = json; | ||
}catch(ex){ | ||
if(self.debug){ | ||
console.log(ex); | ||
// For every input try to parse it to JSON format if it contains something | ||
if(text){ | ||
try { | ||
var json = fJSON.parse(text); | ||
text = json; | ||
}catch(ex){ | ||
if(self.debug){ | ||
console.log(ex); | ||
} | ||
} | ||
@@ -30,5 +37,4 @@ } | ||
consolr.prototype = new events.EventEmitter; | ||
Consolr.prototype = new events.EventEmitter; | ||
module.exports = new consolr(); | ||
module.exports = new Consolr(); |
{ | ||
"name": "consolr", | ||
"version": "0.9.0", | ||
"description": "A handler for the input from terminal (process.stdin) acting as events to handle internal server commands", | ||
"keywords": [], | ||
"version": "0.9.1", | ||
"description": "A utility to use with the input from terminal (process.stdin) while the application is running and emit events to handle internal server commands", | ||
"keywords": ["command", "utility", "terminal", "console"], | ||
"main": "index.js", | ||
@@ -14,2 +14,5 @@ "repository": "https://github.com/dnetix/consolr.git", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/dnetix/consolr/issues" | ||
}, | ||
"dependencies": { | ||
@@ -16,0 +19,0 @@ "fbbk-json": "0.0.8" |
# consolr | ||
A event handler for the input from terminal (process.stdin) acting as events to use as internal server commands in node.js | ||
A utility to use with the input from terminal (process.stdin) while the application is running and emit events to handle internal server commands | ||
I found it very useful while developing for example a chat application, using the event emitall and | ||
passing the message to all the connected sockets. In order to test, or in a production environment to make | ||
a global announcement. | ||
### Version | ||
@@ -18,3 +22,4 @@ 0.9.0 | ||
When you type some text on the prompt after running your app and press enter eg. | ||
After you run your node application this leaves you with a prompt, just type what you need and press enter. | ||
Simple example, running this code will allow you to exit the application typing exit. | ||
@@ -35,3 +40,5 @@ ```sh | ||
``` | ||
Custom events, to create custom events just type :yourcustomevent and then some text if you need it. eg. | ||
```sh | ||
@@ -51,5 +58,7 @@ :exit Closing the app | ||
Now accepts JSON code, for example (It also works on the predefined event) | ||
```sh | ||
:someevent {message: 'Testing JSON', key:'value'} | ||
``` | ||
```javascript | ||
@@ -63,2 +72,3 @@ var consolr = require('consolr'); | ||
### Development | ||
@@ -68,2 +78,3 @@ | ||
### Todos | ||
@@ -73,2 +84,3 @@ | ||
- Allow binary or another kind of input | ||
- Work with big inputs and multiline | ||
@@ -78,2 +90,2 @@ License | ||
MIT | ||
MIT |
@@ -6,3 +6,3 @@ var consolr = require('../index'); | ||
\nExample:\n:custom text that you want to send and ENTER \ | ||
\n\t :exit (To exit the program)"); | ||
\n:exit (To exit the program)"); | ||
@@ -21,4 +21,4 @@ consolr.on('command', function(command){ | ||
console.log(command); | ||
if(command.tocall){ | ||
console.log(command[command.tocall]); | ||
if(command.call){ | ||
console.log(command[command.call]); | ||
} | ||
@@ -25,0 +25,0 @@ }); |
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
4056
51
1
85