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) .default(defaultNoteFrontmatter)
.unknown(true) .unknown(true)
const loadYaml = (rawYaml: string): unknown => {
try {
return load(rawYaml)
} catch {
return undefined
}
}
type ParserResult = type ParserResult =
| { | {
error: undefined error: undefined
@ -87,9 +79,10 @@ type ParserResult =
} }
export const parseRawFrontmatterFromYaml = (rawYaml: string): ParserResult => { export const parseRawFrontmatterFromYaml = (rawYaml: string): ParserResult => {
const rawNoteFrontmatter = loadYaml(rawYaml) try {
if (rawNoteFrontmatter === undefined) { const rawNoteFrontmatter = load(rawYaml)
return schema.validate(rawNoteFrontmatter, { convert: true })
} catch {
return { error: new Error('Invalid YAML'), value: undefined } return { error: new Error('Invalid YAML'), value: undefined }
} }
return schema.validate(rawNoteFrontmatter, { convert: true })
} }