node-result
Advanced tools
Comparing version 1.0.4 to 1.1.0
declare type ResultError = Error; | ||
declare type ResultData = null | void | string | number | boolean | object | any[]; | ||
declare type ErrorProcessing = (error: ResultError) => ResultData; | ||
declare type ErrorProcessingAsync = (error: ResultError) => Promise<ResultData>; | ||
export declare class Result { | ||
@@ -8,2 +10,4 @@ #private; | ||
unwrapAsync(): Promise<ResultData>; | ||
onError(func: ErrorProcessing): ResultData; | ||
onErrorAsync(func: ErrorProcessingAsync): Promise<ResultData>; | ||
} | ||
@@ -10,0 +14,0 @@ export declare const ResultOk: (data: ResultData) => Result; |
@@ -20,4 +20,16 @@ export class Result { | ||
} | ||
onError(func) { | ||
if (this.#error !== null) { | ||
return func(this.#error); | ||
} | ||
return this.#data; | ||
} | ||
async onErrorAsync(func) { | ||
if (this.#error !== null) { | ||
return func(this.#error); | ||
} | ||
return Promise.resolve(this.#data); | ||
} | ||
} | ||
export const ResultOk = (data) => new Result(null, data); | ||
export const ResultFail = (error) => new Result(error, void 0); |
{ | ||
"name": "node-result", | ||
"type": "module", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "result", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3518
49