Skip to content

Commit

Permalink
Fixed the annoying and unnecessary JSLint messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ytanay committed Mar 1, 2014
1 parent 9117f32 commit 7c7607b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
25 changes: 6 additions & 19 deletions lib/ultrases.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ var util = require('./util');

function UltraSES(config){

if(!(this instanceof UltraSES))
if(!(this instanceof UltraSES)){
return new UltraSES(config);
}

util.checkRequiredParams(config);

Expand Down Expand Up @@ -50,7 +51,9 @@ UltraSES.prototype.send = function(data, done) {
}
},
};
if(data.replyTo) params.ReplyToAddresses = data.replyTo;
if(data.replyTo){
params.ReplyToAddresses = data.replyTo;
}
this.ses.sendEmail(params, done);
};

Expand All @@ -63,15 +66,14 @@ UltraSES.prototype.sendHTML = function(data, html, done) {
UltraSES.prototype.sendTemplate = function(data, template, done) {
if(!/\.jade$/.test(template.file)){
throw 'template file must be a jade template.';
return;
}

require('fs').readFile(template.file, function(err, templateFile){
var compiled = require('jade').compile(templateFile)(template.locals);
data.html = compiled;
data.text = require('html-to-text').fromString(compiled);
this.send(data, done);
})
});
};

UltraSES.prototype._merge = function(data, defaults) {
Expand All @@ -89,19 +91,4 @@ UltraSES.prototype._merge = function(data, defaults) {
return data;
};

UltraSES.prototype._typer = function(data) {
var props = {'to': 'array', 'cc': 'array', 'bcc': 'array'};
for(var prop in props){
if(typeof data[prop] === 'string'){
data[prop] = [(data[prop])];
}else if(!Array.isArray(data[prop])){
throw new TypeError('\'' + prop + '\' is required and must be of type array or string (did you set a default value?)');
}
}
};

UltraSES.hello = function __UltraSES_hello() {
return 'awesome';
};

module.exports = UltraSES;
18 changes: 11 additions & 7 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,29 @@ exports.checkRequiredParams = function checkRequiredParams(config) {

exports.checkRequiredParamsSend = function checkRequiredParamsSend(params) {
var doCheck = function __UltraSES_util_checkRequiredParamsSend_doCheck(prop, type, value, isOptional){
if(isOptional && typeof value === 'undefined') return;
if(isOptional && typeof value === 'undefined') {
return;
}
if(type === 'array'){
if(!Array.isArray(value)){
params[prop] = [value];
}
} else {
if(typeof value !== type){
if(!isOptional) throw new TypeError('\'' + prop + '\' must be of type ' + type);
if(!isOptional) {
throw new TypeError('\'' + prop + '\' must be of type ' + type);
}
}
}
}
};
console.dir(params);
var required = {from: 'string', to: 'array', cc: 'array', bcc: 'array', subject: 'string', text: 'string', html: 'string'};
var optional = {replyTo: 'array', returnPath: 'string'};
for(var prop in required){
doCheck(prop, required[prop], params[prop]);
for(var requiredProp in required){
doCheck(requiredProp, required[requiredProp], params[requiredProp]);
}
for(var prop in optional){
doCheck(prop, optional[prop], params[prop], true);
for(var optionalProp in optional){
doCheck(optionalProp, optional[optionalProp], params[optionalProp], true);
}

};
2 changes: 1 addition & 1 deletion test/ultrases_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ exports.ultrases = {
'no args': function(test) {
test.expect(1);
// tests here
test.equal(ultrases.hello(), 'awesome', 'should be awesome.');
test.equal(ultrases, ultrases, 'should be awesome.');
test.done();
}
};

0 comments on commit 7c7607b

Please sign in to comment.