From 74ee8edb555ef128112378f828c636bc04533b31 Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Tue, 28 Jan 2020 12:18:47 +0100 Subject: Fix remove attributes --- lib/Post.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/Post.ts') diff --git a/lib/Post.ts b/lib/Post.ts index 27a6cb9..f99ef83 100644 --- a/lib/Post.ts +++ b/lib/Post.ts @@ -38,13 +38,16 @@ export default class Post { getMeta(): Meta { const { attributes } = this.post; const author: string = attributes.author; - delete attributes.author; + if (!author) throw 'Error while parsing the author'; const title: string = attributes.title; - delete attributes.title; + if (!title) throw 'Error while parsing the title'; + const additionalMeta = Object.keys(attributes) + .filter((key) => key != 'title' && key != 'author') + .reduce((acc, key) => ({ ...acc, [key]: attributes[key] }), {}); return { author, title, - additionalMeta: attributes, + additionalMeta, }; } -- cgit 1.4.1