From a0197b7ae3c4a177c5b852498f8230416cf69a46 Mon Sep 17 00:00:00 2001 From: Henri Binsztok <808274+hbbio@users.noreply.github.com> Date: Fri, 24 May 2024 19:19:55 +0800 Subject: [PATCH] cellify: errorsAsValues option --- src/cellify.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cellify.ts b/src/cellify.ts index 3070e9a..4ee386a 100644 --- a/src/cellify.ts +++ b/src/cellify.ts @@ -73,6 +73,7 @@ export const cellify = ( export type UncellifyOptions = { getter: (c: AnyCell) => Pending | CellResult; + errorsAsValues?: boolean; }; /** @@ -85,7 +86,10 @@ export const uncellify = async ( options: UncellifyOptions = { getter: (cell) => cell.value } ): Promise> => { const value = v instanceof Cell ? await options.getter(v) : v; - if (value instanceof Error) throw value; + if (value instanceof Error) { + if (options?.errorsAsValues) return value as Uncellified; + throw value; + } if (Array.isArray(value)) return Promise.all( value.map((_element) => uncellify(_element, options))