Skip to content

Commit

Permalink
refactor: remove useless prefix/suffix parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mjeanroy committed Aug 10, 2019
1 parent 3699f8a commit 6f40a18
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 61 deletions.
27 changes: 12 additions & 15 deletions src/dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,46 +72,43 @@ module.exports = class Dependency {
/**
* Serialize dependency as a string.
*
* @param {string} prefix Optional prefix prepended to the output string.
* @param {suffix} suffix Optional suffix appended to the output string.
* @param {string} joiner Optional character used to join all the lines.
* @return {string} The dependency correctly formatted.
*/
text(prefix = '', suffix = '', joiner = EOL) {
text() {
const lines = [];

lines.push(`${prefix}Name: ${this.name}${suffix}`);
lines.push(`${prefix}Version: ${this.version}${suffix}`);
lines.push(`${prefix}License: ${this.license}${suffix}`);
lines.push(`${prefix}Private: ${this.private}${suffix}`);
lines.push(`Name: ${this.name}`);
lines.push(`Version: ${this.version}`);
lines.push(`License: ${this.license}`);
lines.push(`Private: ${this.private}`);

if (this.description) {
lines.push(`${prefix}Description: ${this.description || false}${suffix}`);
lines.push(`Description: ${this.description || false}`);
}

if (this.repository) {
lines.push(`${prefix}Repository: ${this.repository.url}${suffix}`);
lines.push(`Repository: ${this.repository.url}`);
}

if (this.homepage) {
lines.push(`${prefix}Homepage: ${this.homepage}${suffix}`);
lines.push(`Homepage: ${this.homepage}`);
}

if (this.author) {
lines.push(`${prefix}Author: ${this.author.text()}${suffix}`);
lines.push(`Author: ${this.author.text()}`);
}

if (!_.isEmpty(this.contributors)) {
lines.push(`${prefix}Contributors:${suffix}`);
lines.push(`Contributors:`);

const allContributors = _.chain(this.contributors)
.map((contributor) => contributor.text())
.map((line) => `${prefix} ${line}${suffix}`)
.map((line) => ` ${line}`)
.value();

lines.push(...allContributors);
}

return lines.join(joiner);
return lines.join(EOL);
}
};
4 changes: 2 additions & 2 deletions src/person.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = class Person {
* @param {string} suffix Optional suffix appended to the output string.
* @return {string} The person as a string.
*/
text(prefix = '', suffix = '') {
text() {
let text = `${this.name}`;

if (this.email) {
Expand All @@ -92,6 +92,6 @@ module.exports = class Person {
text += ` (${this.url})`;
}

return `${prefix}${text}${suffix}`;
return text;
}
};
32 changes: 0 additions & 32 deletions test/dependency.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,36 +297,4 @@ describe('Dependency', () => {
` ${pkg.contributors[1].name}`,
]));
});

it('should format dependency with prefix and suffix', () => {
const pkg = {
name: 'foo',
version: '1.0.0',
license: 'MIT',
description: 'Desc',
homepage: 'https://github.com/mjeanroy',
repository: {type: 'GIT', url: 'git@github.com/mjeanroy'},
author: {name: 'Mickael Jeanroy', email: 'mickael.jeanroy@gmail.com'},
contributors: [
{name: 'Mickael Jeanroy', email: 'mickael.jeanroy@gmail.com'},
{name: 'John Doe'},
],
};

const dependency = new Dependency(pkg);

expect(dependency.text(' * ', ' --')).toEqual(join([
` * Name: ${pkg.name} --`,
` * Version: ${pkg.version} --`,
` * License: ${pkg.license} --`,
` * Private: false --`,
` * Description: ${pkg.description} --`,
` * Repository: ${pkg.repository.url} --`,
` * Homepage: ${pkg.homepage} --`,
` * Author: ${pkg.author.name} <${pkg.author.email}> --`,
` * Contributors: --`,
` * ${pkg.contributors[0].name} <${pkg.contributors[0].email}> --`,
` * ${pkg.contributors[1].name} --`,
]));
});
});
12 changes: 0 additions & 12 deletions test/person.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,4 @@ describe('Person', () => {
'Mickael Jeanroy <mickael.jeanroy@gmail.com> (https://mjeanroy.com)'
);
});

it('should format person with a suffix and a prefix', () => {
const person = new Person({
name: 'Mickael Jeanroy',
email: 'mickael.jeanroy@gmail.com',
url: 'https://mjeanroy.com',
});

expect(person.text('-- ', ' --')).toBe(
'-- Mickael Jeanroy <mickael.jeanroy@gmail.com> (https://mjeanroy.com) --'
);
});
});

0 comments on commit 6f40a18

Please sign in to comment.