From 493fd35100f350d7239f8080ff698693863498a5 Mon Sep 17 00:00:00 2001 From: dimaslanjaka Date: Sun, 23 Apr 2023 17:53:59 +0700 Subject: [PATCH] chore: separate type result --- lib/front_matter.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/front_matter.ts b/lib/front_matter.ts index a57fc5c..5f7015b 100644 --- a/lib/front_matter.ts +++ b/lib/front_matter.ts @@ -32,6 +32,15 @@ function split(str: string) { return { content: str }; } +export type ParseResult = Record & Partial<{ + _content: string; + title: string; + description: string; + thumbnail: string; + date: any; + updated: any; +}> + function parse(str: string, options: yaml.LoadOptions = {}) { if (typeof str !== 'string') throw new TypeError('str is required!'); @@ -40,15 +49,7 @@ function parse(str: string, options: yaml.LoadOptions = {}) { if (!raw) return { _content: str }; - let data: Partial<{ - [key: string]: any; - _content: string; - title: string; - description: string; - thumbnail: string; - date: any; - updated: any; - }>; + let data: ParseResult; if (splitData.separator.startsWith(';')) { data = parseJSON(raw);