Socket
Socket
Sign inDemoInstall

node-notifier

Package Overview
Dependencies
4
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.4 to 3.0.6

example/advanced.js

21

lib/notifiers/growl.js
/**
* Wrapper for the growler module
*/
var os = require('os')
, growler = require('growler');
var os = require('os'),
utils = require('../utils'),
growler = require('growler');

@@ -11,6 +12,6 @@ var Notifier = function (options) {

}
this.app = new growler.GrowlApplication('Gulp', options);
this.app = new growler.GrowlApplication('Node', options);
this.app.setNotifications({
Gulp: {}
Node: {}
});

@@ -23,9 +24,6 @@

options.title = options.title || 'Node Notification:';
options.text = options.message;
delete options.message;
app.sendNotification('Gulp', options, function (success, err) {
app.sendNotification('Node', options, function (success, err) {
return callback(err);
});
return this;
};

@@ -38,3 +36,6 @@

callback = callback || function () {};
if (!options.message) {
options = utils.mapToGrowl(options);
if (!options.text) {
callback(new Error('Message is required.'));

@@ -45,3 +46,3 @@ return this;

if (this.isRegistered) {
doNotification(app, options, callback);
return doNotification(app, options, callback);
return this;

@@ -48,0 +49,0 @@ }

@@ -28,30 +28,14 @@ /**

var notifySendFlags = {
"u": "urgency",
"urgency": "urgency",
"t": "expire-time",
"e": "expire-time",
"expire": "expire-time",
"expire-time": "expire-time",
"i": "icon",
"icon": "icon",
"c": "category",
"category": "category",
"h": "hint",
"hint": "hint"
}
var doNotification = function (options, callback) {
var initial, argsList;
var doNotification = function (options, callback) {
options = utils.mapToNotifySend(options);
options.title = options.title || 'Node Notification:';
var initial = [options.title, options.message];
initial = [options.title, options.message];
delete options.title;
delete options.message;
for (var key in options) {
if (options.hasOwnProperty(key) && (notifySendFlags[key] != key)) {
options[notifySendFlags[key]] = options[key];
delete options[key];
}
}
var argsList = utils.constructArgumentList(options, initial, "-", allowedArguments);
argsList = utils.constructArgumentList(options, initial, "-", allowedArguments);
utils.command(notifier, argsList, callback);

@@ -58,0 +42,0 @@ return this;

@@ -17,29 +17,26 @@ /**

this.isOSX = false;
}
, cbAnnotator = function (cb) {
return function (err, data) {
cb(err, data);
};
};
Notifier.prototype.notify = function (options, callback) {
var argsList = utils.constructArgumentList(options);
callback = cbAnnotator(callback || function (err, data) {});
options = utils.mapToMac(options);
if(this.isOSX) {
utils.command(notifier, argsList, callback);
return this;
}
var argsList = utils.constructArgumentList(options);
callback = callback || function (err, data) {};
var self = this;
utils.isMacOSX(function (error, errorMsg) {
if (error) {
return callback(new Error(errorMsg));
}
utils.command(notifier, argsList, callback);
self.isOSX = true;
});
if(this.isOSX) {
utils.command(notifier, argsList, callback);
return this;
}
var self = this;
utils.isMacOSX(function (error, errorMsg) {
if (error) {
return callback(new Error(errorMsg));
}
utils.command(notifier, argsList, callback);
self.isOSX = true;
});
return this;
};
module.exports = Notifier;
var cp = require('child_process')
, os = require('os')
, fs = require('fs')
, osVersionError = 'Incorrect OS. node-notify requires Mac OS 10.8 or higher'

@@ -15,2 +16,26 @@ , shellwords = require('shellwords')

var inArray = function (arr, val) {
for(var i = 0; i < arr.length; i++) {
if (arr[i] === val) {
return true;
}
}
return false;
};
var notifySendFlags = {
"u": "urgency",
"urgency": "urgency",
"t": "expire-time",
"e": "expire-time",
"expire": "expire-time",
"expire-time": "expire-time",
"i": "icon",
"icon": "icon",
"c": "category",
"category": "category",
"h": "hint",
"hint": "hint"
};
module.exports.command = function (notifier, options, cb) {

@@ -28,11 +53,72 @@ var notifyApp = cp.exec(shellwords.escape(notifier) + ' ' + options.join(' '), function (error, stdout, stderr) {

var inArray = function (arr, val) {
for(var i = 0; i < arr.length; i++) {
if (arr[i] === val) {
return true;
var mapAppIcon = function (options) {
if (options.appIcon) {
options.icon = options.appIcon;
delete options.appIcon;
}
return options;
};
var mapText = function (options) {
if (options.text) {
options.message = options.text;
delete options.text;
}
return options;
};
var mapIconShorthand = function (options) {
if (options.i) {
options.icon = options.i;
delete options.i;
}
return options;
};
module.exports.mapToNotifySend = function (options) {
options = mapAppIcon(options);
options = mapText(options);
for (var key in options) {
if (key === "message" || key === "title") continue;
if (options.hasOwnProperty(key) && (notifySendFlags[key] != key)) {
options[notifySendFlags[key]] = options[key];
delete options[key];
}
}
return false;
return options;
};
module.exports.mapToGrowl = function (options) {
options = mapAppIcon(options);
options = mapIconShorthand(options);
if (options.message) {
options.text = options.message;
delete options.message;
}
if (options.icon && !Buffer.isBuffer(options.icon)) {
options.icon = fs.readFileSync(options.icon);
}
return options;
};
module.exports.mapToMac = function (options) {
options = mapIconShorthand(options);
options = mapText(options);
if (options.icon) {
options.appIcon = options.icon;
delete options.icon;
}
return options;
};
module.exports.constructArgumentList = function (options, initial, keyExtra, allowedArguments) {

@@ -39,0 +125,0 @@ var args = [];

{
"name": "node-notifier",
"version": "3.0.4",
"version": "3.0.6",
"description": "A Node.js module for sending notifications on mac, windows and linux",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -24,3 +24,3 @@ # node-notifier [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url]

By default Notification Center will be used on Mac, notify-send will be used
on Linux, and Growl will be used if neither mac or linux.
on Linux, and Growl will be used if neither Mac 10.8 or Linux.

@@ -54,3 +54,8 @@ ## Install

### Mapping between notifiers
Common options between the modules (i.e. `icon`) is mapped. This means,
if you are using a Mac and someone on your project is using Linux, you
can both see icons.
## Usage NotificationCenter

@@ -110,2 +115,3 @@

"contentImage": __dirname + "/coulson.jpg",
"appIcon": __dirname + "/coulson.jpg",
"open": "file://" + __dirname + "/coulson.jpg"

@@ -116,2 +122,4 @@ });

See [terminal-notifier](https://github.com/alloy/terminal-notifier) for more options.
## Usage NotifySend

@@ -125,3 +133,4 @@

title: 'Foo',
message: 'Hello World'
message: 'Hello World',
icon: __dirname + "/coulson.jpg",
// .. and other notify-send flags

@@ -143,3 +152,4 @@ });

title: 'Foo',
message: 'Hello World'
message: 'Hello World',
icon: fs.readFileSync(__dirname + "/coulson.jpg")
// and other growl options like sticky etc.

@@ -155,2 +165,8 @@ });

### `v3.0.6`
1. Fixes typo: Changes Growl app name from `Gulp` to `Node`.
### `v3.0.5`
1. Maps common options between the different notifiers. Allowing for common usage with different notifiers.
### `v3.0.4`

@@ -157,0 +173,0 @@ 1. Fixes expires for notify-send (Issue #13)

@@ -1,5 +0,5 @@

var should = require('should')
, assert = require('assert')
, os = require('os')
;
var should = require('should'),
path = require('path'),
os = require('os'),
fs = require('fs');

@@ -72,2 +72,93 @@ var _ = require('../lib/utils');

describe('mapping', function () {
it('should map icon for notify-send', function () {
var expected = {
title: 'Foo',
message: 'Bar',
icon: 'foobar'
};
_.mapToNotifySend({
title: 'Foo',
message: 'Bar',
appIcon: 'foobar'
}).should.eql(expected);
_.mapToNotifySend({
title: 'Foo',
message: 'Bar',
i: 'foobar'
}).should.eql(expected);
});
it('should map short hand for notify-sned', function () {
var expected = {
urgency: 'a',
'expire-time': 'b',
category: 'c',
icon: 'd',
hint: 'e'
};
_.mapToNotifySend({
u: 'a',
e: 'b',
c: 'c',
i: 'd',
h: 'e'
}).should.eql(expected);
});
it('should map icon for notification center', function () {
var expected = {
title: 'Foo',
message: 'Bar',
appIcon: 'foobar'
};
_.mapToMac({
title: 'Foo',
message: 'Bar',
icon: 'foobar'
}).should.eql(expected);
_.mapToMac({
title: 'Foo',
message: 'Bar',
i: 'foobar'
}).should.eql(expected);
});
it('should map icon for growl', function () {
var icon = path.join(__dirname, 'fixture', 'coulson.jpg');
var iconRead = fs.readFileSync(icon);
var expected = {
title: 'Foo',
message: 'Bar',
icon: fs.readFileSync(icon)
};
var obj = _.mapToGrowl({
title: 'Foo',
message: 'Bar',
icon: icon
});
obj.should.have.property('icon');
(Buffer.isBuffer(obj.icon)).should.be.true;
var obj = _.mapToGrowl({
title: 'Foo',
message: 'Bar',
appIcon: icon
});
obj.should.have.property('icon');
(Buffer.isBuffer(obj.icon)).should.be.true;
});
});
});
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc