From 20197d36df7f20fa8fb067de3f3c8a5b9ca56ec5 Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Sun, 11 Jun 2023 12:47:50 +0200 Subject: [PATCH] refactor(commons): remove redundant method Signed-off-by: Tilman Vatteroth --- .../parse-raw-frontmatter-from-yaml.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/commons/src/note-frontmatter-parser/parse-raw-frontmatter-from-yaml.ts b/commons/src/note-frontmatter-parser/parse-raw-frontmatter-from-yaml.ts index b7f87e8df..63b29b6ce 100644 --- a/commons/src/note-frontmatter-parser/parse-raw-frontmatter-from-yaml.ts +++ b/commons/src/note-frontmatter-parser/parse-raw-frontmatter-from-yaml.ts @@ -66,14 +66,6 @@ const schema = Joi.object({ .default(defaultNoteFrontmatter) .unknown(true) -const loadYaml = (rawYaml: string): unknown => { - try { - return load(rawYaml) - } catch { - return undefined - } -} - type ParserResult = | { error: undefined @@ -87,9 +79,10 @@ type ParserResult = } export const parseRawFrontmatterFromYaml = (rawYaml: string): ParserResult => { - const rawNoteFrontmatter = loadYaml(rawYaml) - if (rawNoteFrontmatter === undefined) { + try { + const rawNoteFrontmatter = load(rawYaml) + return schema.validate(rawNoteFrontmatter, { convert: true }) + } catch { return { error: new Error('Invalid YAML'), value: undefined } } - return schema.validate(rawNoteFrontmatter, { convert: true }) }