Skip to content

Commit

Permalink
Removes a dependency on underscore.
Browse files Browse the repository at this point in the history
We were using it for one function, which was super lame.
  • Loading branch information
nathanbowser committed Aug 24, 2012
1 parent dd2dfb8 commit 1ca87e1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var jade = require('jade')
, _ = require('underscore')
, nodemailer = require('nodemailer')
, fs = require('fs')
, utils = require('./utils')
, path = require('path')

module.exports = Balloon

function Balloon(config) {
this.transport = nodemailer.createTransport("SES", config.auth)
_.defaults(config, {
utils.defaults(config, {
templateDirectory: path.join(__dirname, 'templates')
})

Expand All @@ -26,7 +26,7 @@ Balloon.prototype.send = function (template, model, params, callback) {
if (err) {
// don't know yet
} else {
_.defaults(params, {
utils.defaults(params, {
html: result
})
self.transport.sendMail(params, function (err, responseStatus) {
Expand Down
9 changes: 9 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

exports.defaults = function (obj) {
Array.prototype.slice.apply(arguments).slice(1).forEach(function (source) {
for (var p in source) {
if (obj[p] == null) obj[p] = source[p]
}
})
return obj
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"license": "MIT",
"dependencies": {
"jade": "~0.27.2",
"nodemailer": "~0.3.22",
"underscore": "~1.3.3"
"nodemailer": "~0.3.22"
},
"devDependencies": {
"mocha": "~1.3.2",
Expand Down
19 changes: 19 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var mocha = require('mocha')
, utils = require('../lib/utils')
, assert = require('assert')

describe('balloon utils', function () {

it('sets defaults of an object', function () {
var result,
opts = {zero: 0, one: 1, empty: '', nan: NaN, string: "str"}

utils.defaults(opts, {zero: 1, one: 2, two: 3})
assert.equal(opts.zero, 0)
assert.equal(opts.one, 1)
assert.equal(opts.two, 3)
assert.equal(opts.empty, '')
assert.equal(opts.string, 'str')
})

})

0 comments on commit 1ca87e1

Please sign in to comment.