Skip to content

Commit

Permalink
Parse recipe author string
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Nov 3, 2017
1 parent 7343d47 commit a54c87b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -27,6 +27,7 @@
"license": "Apache-2.0",
"dependencies": {
"@paulcbetts/system-idle-time": "^1.0.4",
"address-rfc2822": "^2.0.1",
"auto-launch": "https://github.com/meetfranz/node-auto-launch.git",
"babel-polyfill": "^6.23.0",
"babel-runtime": "^6.23.0",
Expand Down
16 changes: 14 additions & 2 deletions src/models/Recipe.js
@@ -1,7 +1,8 @@
import emailParser from 'address-rfc2822';

export default class Recipe {
id = '';
name = '';
author = '';
description = '';
version = '1.0';
path = '';
Expand Down Expand Up @@ -30,7 +31,7 @@ export default class Recipe {

this.id = data.id || this.id;
this.name = data.name || this.name;
this.author = data.author || this.author;
this.rawAuthor = data.author || this.author;
this.description = data.description || this.description;
this.version = data.version || this.version;
this.path = data.path;
Expand All @@ -49,4 +50,15 @@ export default class Recipe {

this.message = data.config.message || this.message;
}

get author() {
try {
const addresses = emailParser.parse(this.rawAuthor);
return addresses.map(a => ({ email: a.address, name: a.phrase }));
} catch (err) {
console.warn(`Not a valid author for ${this.name}`);
}

return [];
}
}
10 changes: 10 additions & 0 deletions yarn.lock
Expand Up @@ -80,6 +80,12 @@ acorn@^5.1.1:
version "5.1.2"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.1.2.tgz#911cb53e036807cf0fa778dc5d370fbd864246d7"

address-rfc2822@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/address-rfc2822/-/address-rfc2822-2.0.1.tgz#1a1bdb942b5e20e2c1ba5d5f396d5824ff7ae6ea"
dependencies:
email-addresses "^3.0.0"

after@0.8.2:
version "0.8.2"
resolved "https://registry.yarnpkg.com/after/-/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f"
Expand Down Expand Up @@ -2049,6 +2055,10 @@ electron@^1.7.9:
electron-download "^3.0.1"
extract-zip "^1.0.3"

email-addresses@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/email-addresses/-/email-addresses-3.0.1.tgz#c1fc20c189e7f96d4012d375db5feaccdd24391c"

emojis-list@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389"
Expand Down

0 comments on commit a54c87b

Please sign in to comment.