From a54c87be1ce629cf13a5bfb9c2ba26958e0e4e74 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 3 Nov 2017 23:22:38 +0100 Subject: Parse recipe author string --- src/models/Recipe.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/models') diff --git a/src/models/Recipe.js b/src/models/Recipe.js index 43a3450b1..4b613a40c 100644 --- a/src/models/Recipe.js +++ b/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 = ''; @@ -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; @@ -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 []; + } } -- cgit v1.2.3-54-g00ecf