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 --- package.json | 1 + src/models/Recipe.js | 16 ++++++++++++++-- yarn.lock | 10 ++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1c0aad789..fc0954e94 100644 --- a/package.json +++ b/package.json @@ -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", 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 []; + } } diff --git a/yarn.lock b/yarn.lock index 3bb344a2d..0bedbac27 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" -- cgit v1.2.3-54-g00ecf