UNPKG

@chubbyts/chubbyts-decode-encode

Version:

A simple decode/encode solution for json / jsonx / url-encoded / xml / yaml.

18 lines (17 loc) 558 B
import { parse } from 'yaml'; import { throwableToError } from '@chubbyts/chubbyts-throwable-to-error/dist/throwable-to-error'; import { DecodeError } from './index.js'; export const createYamlTypeDecoder = () => { return { decode: (encodedData) => { try { return parse(encodedData); } catch (e) { const error = throwableToError(e); throw new DecodeError(error.message, error.stack); } }, contentType: 'application/x-yaml', }; };