refactor(commons): remove redundant method

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-06-11 12:47:50 +02:00
parent 5443510a79
commit 20197d36df

View file

@ -66,14 +66,6 @@ const schema = Joi.object<RawNoteFrontmatter>({
.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 })
}