Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-error-as-value

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-error-as-value - npm Package Compare versions

Comparing version 0.3.11 to 0.3.12

.idea/jsLibraryMappings.xml

15

lib/globals.d.ts

@@ -1,1 +0,14 @@

export {};
type Success<T> = import(".").Success<T>;
type Failure<E extends Error> = import(".").Failure<E>;
type Result<T, E extends Error> = import(".").Result<T, E>;
declare class ResultIs {
static success: <T>(data: T) => Success<T>;
static failure: <E extends Error>(failure: E) => Failure<E>;
}
declare function withResult<T, E extends Error, R>(
fn: (...args: T[]) => R
): (
...args: T[]
) => R extends Promise<infer u> ? Promise<Result<u, E>> : Result<R, E>;

22

lib/index.d.ts

@@ -1,22 +0,22 @@

export declare type Failure<T = void, E extends Error = Error> = {
export declare type Failure<E extends Error = Error> = {
data: null;
error: E;
successOrThrow(): T;
successOrDefault<D>(defaultValue: D): D;
transformOnFailure<E2 extends Error>(fn: (fail: E) => E2): Failure<T, E2>;
transformOnSuccess<N>(fn: (data: never) => N): Failure<T, E>;
unwrap(): void;
unwrapOr<D>(defaultValue: D): D;
transformOnFailure<E2 extends Error>(fn: (fail: E) => E2): Failure<E2>;
transformOnSuccess<N>(fn: (data: never) => N): Failure<E>;
};
export declare type Success<T = void> = {
export declare type Success<T> = {
data: T;
error: null;
successOrThrow(): T;
successOrDefault<D>(defaultValue: D): T;
unwrap(): T;
unwrapOr<D>(defaultValue: D): T;
transformOnFailure<E2 extends Error>(fn: (fail: never) => E2): Success<T>;
transformOnSuccess<N>(fn: (data: T) => N): Success<N>;
};
export declare type Result<T = void, E extends Error = Error> = Failure<T, E> | Success<T>;
export declare type Result<T, E extends Error = Error> = Failure<E> | Success<T>;
export declare type ResultIs = {
success<T>(data?: T): Success<T>;
failure<T = void, E extends Error = Error>(failure: E): Failure<T, E>;
success<T>(data: T): Success<T>;
failure<E extends Error>(failure: E): Failure<E>;
};
export declare const ResultIs: ResultIs;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResultIs = void 0;
function failure(error) {
return {
data: null,
error: error,
successOrThrow: function () {
throw error;
},
successOrDefault: function (defaultValue) {
return defaultValue;
},
transformOnFailure: function (fn) {
return failure(fn(error));
},
transformOnSuccess: function () {
return this;
}
};
}
function success(data) {
if (data === void 0) { data = undefined; }
return {
data: data,
error: null,
successOrThrow: function () {
return data;
},
successOrDefault: function () {
return data;
},
transformOnFailure: function () {
return this;
},
transformOnSuccess: function (fn) {
return success(fn(data));
}
};
}
var failure = function (error) { return ({
data: null,
error: error,
unwrap: function () {
throw error;
},
unwrapOr: function (defaultValue) {
return defaultValue;
},
transformOnFailure: function (fn) {
return failure(fn(error));
},
transformOnSuccess: function () {
return this;
}
}); };
var success = function (data) { return ({
data: data,
error: null,
unwrap: function () {
return data;
},
unwrapOr: function () {
return data;
},
transformOnFailure: function () {
return this;
},
transformOnSuccess: function (fn) {
return success(fn(data));
}
}); };
exports.ResultIs = {

@@ -42,0 +37,0 @@ success: success,

@@ -1,6 +0,1 @@

import { Result } from "./index";
interface ParsedBudget {
hello: string;
}
export declare const parseBudgetXlsx: () => Result<ParsedBudget>;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseBudgetXlsx = void 0;
var index_1 = require("./index");
var parseBudgetXlsx = function () {
var fn = function () {
if ("" === "") {
return index_1.ResultIs.failure(new Error());
return index_1.ResultIs.success("hello");
}
return index_1.ResultIs.success({
hello: "world"
});
return index_1.ResultIs.failure(new Error());
};
exports.parseBudgetXlsx = parseBudgetXlsx;
var y = (0, exports.parseBudgetXlsx)();
console.log(y);
var _a = fn(), data = _a.data, error = _a.error;
if (error) {
data;
}
else {
data;
}

@@ -17,3 +17,3 @@ "use strict";

try {
var data = fn.bind(fn).apply(void 0, args);
var data = fn.apply(void 0, args);
if ((0, exports.isPromise)(data)) {

@@ -20,0 +20,0 @@ return data

{
"name": "ts-error-as-value",
"version": "0.3.11",
"version": "0.3.12",
"description": "Errors as values in typescript",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -0,1 +1,2 @@

export { withResult } from "./with-result";

@@ -2,0 +3,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc