Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
*.jpg binary
*.gif binary
*.png binary
*.jpeg binary
*.jpeg binary
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ validation-status.json
validation-report.json

# misc
TODO.md
TODO.md
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ Released under the MIT license.

***

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on November 22, 2015._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on November 22, 2015._
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
"toString",
"url"
]
}
}
18 changes: 8 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@

module.exports = function (author) {
if (typeof author !== 'object') {
throw new Error('expected an author to be an object');
throw new TypeError('expected an author to be an object');
}

var tmpl = {name: ['', ''], email: ['<', '>'], url: ['(', ')']};
var str = '';

if (author.url) author.url = stripSlash(author.url);

for (var key in tmpl) {
if (author[key]) {
str += tmpl[key][0] + author[key] + tmpl[key][1] + ' ';
}
}
return str.trim();
var name = author.name || "";
var url = author.url || author.web;
url = url ? (" (" + url.trim() + ")") : "";
var email = author.email || author.mail;
email = email ? (" <" + email.trim() + ">") : "";
return (name.trim() + email + url).trim();

};

function stripSlash(str) {
Expand Down
58 changes: 43 additions & 15 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,71 @@ require('should');
var stringify = require('./');

describe('author', function () {
it('should stringify name:', function () {
it('should stringify name', function () {
var author = {name: 'Jon Schlinkert'};
stringify(author).should.equal('Jon Schlinkert');
});

it('should stringify email:', function () {
it('should stringify email', function () {
var author = {email: 'jon.schlinkert@sellside.com'};
stringify(author).should.equal('<jon.schlinkert@sellside.com>');
});

it('should stringify url:', function () {
it('should stringify url', function () {
var author = {url: 'https://github.com/jonschlinkert'};
stringify(author).should.equal('(https://github.com/jonschlinkert)');
});

it('should strip trailing slashes from URL:', function () {
it('should strip trailing slashes from URL', function () {
var author = {url: 'https://github.com/jonschlinkert/'};
stringify(author).should.equal('(https://github.com/jonschlinkert)');
});

it('should stringify name and url:', function () {
var author = {name: 'Jon Schlinkert', url: 'https://github.com/jonschlinkert'};
stringify(author).should.equal('Jon Schlinkert (https://github.com/jonschlinkert)');
it('should stringify name and url', function () {
var author = {
name: 'Jon Schlinkert',
url: 'https://github.com/jonschlinkert'
};
stringify(author).should.equal(
'Jon Schlinkert (https://github.com/jonschlinkert)'
);
});

it('should stringify name and email:', function () {
it('should stringify name and email', function () {
var author = {name: 'Jon Schlinkert', email: 'jon.schlinkert@sellside.com'};
stringify(author).should.equal('Jon Schlinkert <jon.schlinkert@sellside.com>');
stringify(author).should.equal(
'Jon Schlinkert <jon.schlinkert@sellside.com>'
);
});

it('should stringify email and url:', function () {
var author = {email: 'jon.schlinkert@sellside.com', url: 'https://github.com/jonschlinkert'};
stringify(author).should.equal('<jon.schlinkert@sellside.com> (https://github.com/jonschlinkert)');
it('should stringify email and url', function () {
var author = {
email: 'jon.schlinkert@sellside.com',
url: 'https://github.com/jonschlinkert'
};
stringify(author).should.equal(
'<jon.schlinkert@sellside.com> (https://github.com/jonschlinkert)'
);
});

it('should stringify name, email and url:', function () {
var author = {name: 'Jon Schlinkert', email: 'jon.schlinkert@sellside.com', url: 'https://github.com/jonschlinkert'};
stringify(author).should.equal('Jon Schlinkert <jon.schlinkert@sellside.com> (https://github.com/jonschlinkert)');
it('should stringify name, email and url', function () {
var author = {
name: 'Jon Schlinkert',
email: 'jon@sellside.com',
url: 'https://github.com/jonschlinkert'
};
stringify(author).should.equal(
'Jon Schlinkert <jon@sellside.com> (https://github.com/jonschlinkert)'
);
});

it('should stringify old web and mail values', function () {
var author = {
mail: 'jon.schlinkert@sellside.com',
web: 'https://github.com/jonschlinkert'
};
stringify(author).should.equal(
'<jon.schlinkert@sellside.com> (https://github.com/jonschlinkert)'
);
});
});