node-notifier
Advanced tools
Comparing version 2.0.6 to 3.0.0
@@ -20,3 +20,3 @@ /** | ||
return function (err, data) { | ||
cb(err, utils.parseCLIOutput(data)); | ||
cb(err, data); | ||
}; | ||
@@ -23,0 +23,0 @@ }; |
@@ -48,3 +48,2 @@ var child_process = require('child_process') | ||
} | ||
return args; | ||
@@ -69,75 +68,1 @@ }; | ||
}; | ||
// Parsing CLI lines and tables.. | ||
var tableLineObject = function (header, splittedLine) { | ||
var obj = {}, line; | ||
for(var i = 0, len = header.length; i < len; i++) { | ||
line = splittedLine[i].trim(); | ||
if (i === len-1) { | ||
line = new Date(line); | ||
} | ||
else if (line === "(null)") { | ||
line = null; | ||
} | ||
else if (!!parseInt(line, 10)) { | ||
line = parseInt(line, 10); | ||
} | ||
obj[header[i]] = line; | ||
} | ||
return obj; | ||
}; | ||
module.exports.parseCLIOutput = function (data) { | ||
if (!data) { | ||
return data; | ||
} | ||
var lines = data.trim().split("\n"), i, len, base = { | ||
response: [] | ||
}; | ||
// Check for single line. | ||
if (lines.length === 1 && lines[0].substring(0,1) === '*') { | ||
var msg = lines[0].substring(1).trim(); | ||
base.response.push(msg); | ||
var type = msg.substring(0, 4).toLowerCase(); | ||
// Set type | ||
if (type === "noti") { | ||
base.type = 'delivered'; | ||
} | ||
else if (type === "remo") { | ||
base.type = 'removed'; | ||
} | ||
return base; | ||
} | ||
// Multiple lines in listing | ||
if (lines.length > 0 && lines[0].substring(0,4).toLowerCase() === "grou") { | ||
var header = lines[0].split("\t"); | ||
for (i = 1, len = lines.length; i < len; i++) { | ||
base.response.push(tableLineObject(header, lines[i].split("\t"))); | ||
} | ||
base.type = 'list'; | ||
return base; | ||
} | ||
// Remove ALL | ||
if (lines.length > 0) { | ||
for (i = 0, len = lines.length; i < len; i++) { | ||
base.response.push(lines[i].substring(1).trim()); | ||
} | ||
base.type = 'removed'; | ||
return base; | ||
} | ||
return data; | ||
}; |
{ | ||
"name": "node-notifier", | ||
"version": "2.0.6", | ||
"version": "3.0.0", | ||
"description": "A Node.js module for sending notifications on mac, windows and linux", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
# node-notifier | ||
# node-notifier [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url] | ||
@@ -58,2 +58,12 @@ A node module for sending notification using node. Uses terminal-notifier on mac, | ||
--- | ||
### Note: Output parsing from Notification Center is deprecated as of `3.0.0`. | ||
**Parsing of output given by terminal-notifier is removed as of node-notifier `3.0.0`.** | ||
You can still use both `remove` and `list` but the output given will not be parsed into a object. | ||
--- | ||
### Example | ||
@@ -72,3 +82,2 @@ | ||
You can specify the second argument as a callback for getting ```error``` and ```response```. | ||
@@ -88,3 +97,20 @@ | ||
As of version `3.0.0`, you can also specify image used as icon or content image. | ||
```javascript | ||
notifier.notify({ | ||
"title": "Phil Coulson", | ||
"subtitle": "Agent of S.H.I.E.L.D.", | ||
"message": "If I come out, will you shoot me? 'Cause then I won't come out.", | ||
"sound": "Funk", // case sensitive | ||
"contentImage": __dirname + "/coulson.jpg", | ||
"open": "file://" + __dirname + "/coulson.jpg" | ||
}); | ||
``` | ||
The response will be given as an object. E.g., when running ```notifier.notify({list: "ALL"})```, this could be the response: | ||
**Note: Deprecated as of version `3.0.0`.** | ||
@@ -123,2 +149,4 @@ ``` | ||
## Usage NotifySend | ||
@@ -137,3 +165,3 @@ | ||
## Usage NotifySend | ||
## Usage Growl | ||
@@ -158,2 +186,22 @@ ```javascript | ||
1. Add tests for notify-send and growl | ||
1. Add tests for growl | ||
## Changelog | ||
### `v3.0.0` | ||
1. Updates terminal-notifier to version 1.6.0; adding support for appIcon and contentImage | ||
2. Removes parsing of output sent from notifier (Notification Center) | ||
## License | ||
[MIT License](http://en.wikipedia.org/wiki/MIT_License) | ||
[npm-url]: https://npmjs.org/package/node-notifier | ||
[npm-image]: https://badge.fury.io/js/node-notifier.png | ||
[travis-url]: http://travis-ci.org/mikaelbr/node-notifier | ||
[travis-image]: https://secure.travis-ci.org/mikaelbr/node-notifier.png?branch=master | ||
[depstat-url]: https://david-dm.org/mikaelbr/node-notifier | ||
[depstat-image]: https://david-dm.org/mikaelbr/node-notifier.png |
var NotificationCenter = require('../').NotificationCenter | ||
, should = require('should') | ||
, os = require('os') | ||
, fs = require('fs') | ||
, utils = require('../lib/utils') | ||
@@ -8,19 +9,30 @@ , assert = require('assert'); | ||
var notifier = new NotificationCenter(); | ||
var originalUtils = utils.command; | ||
(function () { | ||
if (os.type() !== 'Darwin') { | ||
return; | ||
} | ||
describe('node-notifier', function(){ | ||
before(function () { | ||
os.type = function () { | ||
return "Linux"; | ||
}; | ||
utils.isMacOSX = function (cb) { | ||
cb(false); | ||
}; | ||
}) | ||
describe('#notify()', function(){ | ||
before(function (done) { | ||
notifier.notify({ | ||
remove: "ALL" | ||
}, function () { done(); }); | ||
beforeEach(function () { | ||
utils.command = function (n, o, cb) { | ||
cb(null, ""); | ||
} | ||
}); | ||
after(function () { | ||
utils.command = originalUtils | ||
}); | ||
it('should notify with a message', function(done){ | ||
@@ -31,3 +43,3 @@ | ||
}, function (err, response) { | ||
response.type.should.equal("delivered"); | ||
(err === null).should.be.true; | ||
done(); | ||
@@ -45,4 +57,3 @@ }); | ||
}, function (err, response) { | ||
response.type.should.equal("delivered"); | ||
response.response[0].should.equal("Notification delivered."); | ||
(err === null).should.be.true; | ||
done(); | ||
@@ -54,6 +65,10 @@ }); | ||
it('should be able to list all notifications', function(done){ | ||
utils.command = function (n, o, cb) { | ||
cb(null, fs.readFileSync(__dirname + '/fixture/listAll.txt').toString()); | ||
} | ||
notifier.notify({ | ||
list: "ALL" | ||
}, function (err, response) { | ||
response.response.length.should.equal(3); | ||
response.should.be.ok; | ||
done(); | ||
@@ -65,11 +80,19 @@ }); | ||
it('should be able to remove all messages', function(done){ | ||
utils.command = function (n, o, cb) { | ||
cb(null, fs.readFileSync(__dirname + '/fixture/removeAll.txt').toString()); | ||
} | ||
notifier.notify({ | ||
remove: "ALL" | ||
}, function (err, response) { | ||
response.type.should.equal("removed"); | ||
response.should.be.ok; | ||
utils.command = function (n, o, cb) { | ||
cb(null, ""); | ||
} | ||
notifier.notify({ | ||
list: "ALL" | ||
}, function (err, response) { | ||
assert(!response); | ||
response.should.not.be.ok; | ||
done(); | ||
@@ -112,3 +135,3 @@ }); | ||
it('should escape all title andmessage', function (done) { | ||
it('should escape all title and message', function (done) { | ||
var expected = [ '-title', '"title \\"message\\""', | ||
@@ -115,0 +138,0 @@ '-message', '"body \\"message\\""', '-tullball', '"notValid"' ] |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
491332
23
201
493
1