Socket
Socket
Sign inDemoInstall

consolr

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

consolr - npm Package Compare versions

Comparing version 0.8.1 to 0.9.0

.npmignore

24

index.js
var events = require('events');
var fJSON = require('fbbk-json');
var consolr = function(){
var self = this;
this.debug = false;
process.stdin.on('data', function(chunk){
var pattern = /(?:\:)(\w+)(?:\s)?([\w \.\,\"]+)?/gi;
var pattern = /(?:\:)(\w+)(?:\s)?([\w \.\,\"\{\}\:\'\[\]]+)?/gi;
var text = chunk.toString().replace(/(\r\n|\n|\r)/g, "");
var eventName = 'command';
if(matched = pattern.exec(text)){
self.emit(matched[1], (matched[2] == undefined ? null : matched[2]));
}else{
self.emit('command', text);
eventName = matched[1];
text = matched[2];
}
try {
var json = fJSON.parse(text);
text = json;
}catch(ex){
if(self.debug){
console.log(ex);
}
}
self.emit(eventName, text);
});

@@ -18,2 +31,3 @@ };

module.exports = new consolr();
module.exports = new consolr();
{
"name": "consolr",
"version": "0.8.1",
"version": "0.9.0",
"description": "A handler for the input from terminal (process.stdin) acting as events to handle internal server commands",

@@ -13,3 +13,6 @@ "keywords": [],

"author": "Diego Calle",
"license": "MIT"
"license": "MIT",
"dependencies": {
"fbbk-json": "0.0.8"
}
}

@@ -6,3 +6,3 @@ # consolr

### Version
0.8.1
0.9.0

@@ -19,3 +19,8 @@ ### Installation

When you type some text on the prompt after running your app and press enter eg. exit
When you type some text on the prompt after running your app and press enter eg.
```sh
exit
```
```javascript

@@ -31,3 +36,7 @@ var consolr = require('consolr');

```
Custom events, to create custom events just type :yourcustomevent and then some text if you need it. eg. :exit Closing the app
Custom events, to create custom events just type :yourcustomevent and then some text if you need it. eg.
```sh
:exit Closing the app
```
```javascript

@@ -42,2 +51,14 @@ var consolr = require('consolr');

Now accepts JSON code, for example (It also works on the predefined event)
```sh
:someevent {message: 'Testing JSON', key:'value'}
```
```javascript
var consolr = require('consolr');
consolr.on('someevent', function(data){
console.log(data.message);
});
```
That way it will only show the message because it will pass a JSON object instead of only string
### Development

@@ -44,0 +65,0 @@

var consolr = require('../index');
consolr.debug = true;

@@ -12,7 +13,16 @@ console.log("Hello, To use this package just subscribe to the consolr event, or if you want custom events just start typing :YOUR_CUSTOM_EVENT \

consolr.on('custom', function(command){
console.log("Custom " + command);
console.log("Custom");
console.log(command);
});
consolr.on('json', function(command){
console.log("JSON");
console.log(command);
if(command.tocall){
console.log(command[command.tocall]);
}
});
consolr.on('exit', function(){
process.exit();
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc