Skip to content

Commit

Permalink
Crafter: parse author object
Browse files Browse the repository at this point in the history
  • Loading branch information
dmstern committed Nov 26, 2018
1 parent a9607b4 commit 8b4b2c1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
23 changes: 22 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"fs-extra": "^7.0.0",
"morgan": "^1.9.0",
"node-emoji": "^1.8.1",
"parse-authors": "^0.2.4",
"pm2": "^3.0.3",
"showdown": "^1.8.6",
"tar": "^4.4.6",
Expand Down
2 changes: 1 addition & 1 deletion server/mock/schoenes-module.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"repository": "https://github.com/bla/blubb",
"license": "ISC",
"contributors": [
"daniel <mail@daniel.com>", "Kater Findus <findus@schweden.com>", "Alter Petterson", {
"daniel <mail@daniel.com>", "Kater Findus <findus@schweden.com> (http://pettersson.com)", "Alter Petterson", {
"name": "Anton Peter",
"email": "test"
},
Expand Down
24 changes: 7 additions & 17 deletions types/Crafter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IAuthor } from './package-json';
import Searchable from './Searchable';
import Package from './Package';
import vuetifyColors from 'vuetify/es5/util/colors';
import * as parseAuthors from 'parse-authors';

const forbiddenColors = ['shades', 'grey', 'blueGrey'];

Expand Down Expand Up @@ -29,9 +30,9 @@ export default class Crafter extends Searchable {
});
private static allCrafters: Crafter[] = [];

public readonly name: string;
public readonly email?: string;
public readonly url?: string;
public readonly name: string = '';
public readonly email: string = '';
public readonly url: string = '';

private backgroundColor?: string;

Expand All @@ -53,22 +54,11 @@ export default class Crafter extends Searchable {
super();
if (author) {
if (typeof author === 'string') {
const authorParts = author.split('<');
if (authorParts.length === 2) {
this.name = authorParts[0].trim();
this.email = authorParts[1]
.slice(0, authorParts[1].length - 1)
.trim();
} else {
this.name = author;
}
const authorObject = parseAuthors(author)[0];
Object.assign(this, authorObject);
} else {
this.name = author.name;
this.email = author.email;
this.url = author.url;
Object.assign(this, author);
}
} else {
this.name = 'Unknown';
}
const alreadyCreatedCrafter = Crafter.allCrafters.find((crafter) =>
crafter.equals(this),
Expand Down

0 comments on commit 8b4b2c1

Please sign in to comment.