node-result
Advanced tools
Comparing version 8.1.0 to 9.0.0
export { ResultError } from 'node-result-error'; | ||
export declare enum AtomOK { | ||
OK = "OK" | ||
} | ||
export declare enum AtomFAIL { | ||
FAIL = "FAIL" | ||
} | ||
declare type Atom = typeof AtomOK.OK | typeof AtomFAIL.FAIL; | ||
declare type ErrorProcessing<D, E> = (error: E) => D; | ||
@@ -7,5 +14,6 @@ declare type ErrorProcessingAsync<D, E> = (error: E) => Promise<D>; | ||
export declare class Result<D, E> { | ||
protected readonly error: E | null; | ||
protected readonly data: D; | ||
constructor(data: D, error?: E | null); | ||
protected readonly error: E; | ||
protected readonly atom: Atom; | ||
constructor(data: D, error: E, atom?: Atom); | ||
unwrap(): D | never; | ||
@@ -17,5 +25,5 @@ unwrapAsync(): Promise<D | E>; | ||
isFail(): boolean; | ||
isOkAndUnwrap(): [boolean, D | E]; | ||
isOkAndUnwrap(): [AtomOK, D] | [AtomFAIL, E]; | ||
} | ||
export declare class ResultOK<D> extends Result<D, null> { | ||
export declare class ResultOK<D> extends Result<D, undefined> { | ||
constructor(data: D); | ||
@@ -22,0 +30,0 @@ unwrap(): D; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tryCatchWrapperAsync = exports.tryCatchWrapper = exports.ResultFail = exports.ResultOk = exports.ResultFAIL = exports.ResultOK = exports.Result = exports.ResultError = void 0; | ||
exports.tryCatchWrapperAsync = exports.tryCatchWrapper = exports.ResultFail = exports.ResultOk = exports.ResultFAIL = exports.ResultOK = exports.Result = exports.AtomFAIL = exports.AtomOK = exports.ResultError = void 0; | ||
var node_result_error_1 = require("node-result-error"); | ||
Object.defineProperty(exports, "ResultError", { enumerable: true, get: function () { return node_result_error_1.ResultError; } }); | ||
var AtomOK; | ||
(function (AtomOK) { | ||
AtomOK["OK"] = "OK"; | ||
})(AtomOK = exports.AtomOK || (exports.AtomOK = {})); | ||
var AtomFAIL; | ||
(function (AtomFAIL) { | ||
AtomFAIL["FAIL"] = "FAIL"; | ||
})(AtomFAIL = exports.AtomFAIL || (exports.AtomFAIL = {})); | ||
class Result { | ||
constructor(data, error = null) { | ||
constructor(data, error, atom = AtomOK.OK) { | ||
this.data = data; | ||
this.error = error; | ||
this.data = data; | ||
this.atom = atom; | ||
} | ||
unwrap() { | ||
if (this.error !== null) { | ||
throw this.error; | ||
if (this.atom === AtomOK.OK) { | ||
return this.data; | ||
} | ||
return this.data; | ||
throw this.error; | ||
} | ||
unwrapAsync() { | ||
if (this.error !== null) { | ||
return Promise.reject(this.error); | ||
if (this.atom === AtomOK.OK) { | ||
return Promise.resolve(this.data); | ||
} | ||
return Promise.resolve(this.data); | ||
return Promise.reject(this.error); | ||
} | ||
onError(func) { | ||
if (this.error !== null) { | ||
return func(this.error); | ||
if (this.atom === AtomOK.OK) { | ||
return this.data; | ||
} | ||
return this.data; | ||
return func(this.error); | ||
} | ||
onErrorAsync(func) { | ||
if (this.error !== null) { | ||
return func(this.error); | ||
if (this.atom === AtomOK.OK) { | ||
return Promise.resolve(this.data); | ||
} | ||
return Promise.resolve(this.data); | ||
return func(this.error); | ||
} | ||
isOk() { | ||
return this.error === null; | ||
return this.atom === AtomOK.OK; | ||
} | ||
isFail() { | ||
return this.error !== null; | ||
return this.atom !== AtomOK.OK; | ||
} | ||
isOkAndUnwrap() { | ||
if (this.error === null) { | ||
return [true, this.data]; | ||
if (this.atom === AtomOK.OK) { | ||
return [AtomOK.OK, this.data]; | ||
} | ||
return [false, this.error]; | ||
return [AtomFAIL.FAIL, this.error]; | ||
} | ||
@@ -51,3 +60,3 @@ } | ||
constructor(data) { | ||
super(data, null); | ||
super(data, void 0, AtomOK.OK); | ||
} | ||
@@ -64,6 +73,6 @@ unwrap() { | ||
constructor(error) { | ||
super(void 0, error); | ||
super(void 0, error, AtomFAIL.FAIL); | ||
} | ||
unwrap() { | ||
throw super.error; | ||
throw this.error; | ||
} | ||
@@ -70,0 +79,0 @@ unwrapAsync() { |
{ | ||
"name": "node-result", | ||
"version": "8.1.0", | ||
"version": "9.0.0", | ||
"description": "result", | ||
@@ -5,0 +5,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
8636
160