New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ts-res

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-res - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

1

build/index.js
export { Ok, Err } from "./main";
// TODO: test change

8

build/main.d.ts

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

import { ErrOverload, OkOverload } from "./types";
import { ErrType, Result } from "./types";
/**

@@ -28,3 +28,4 @@ * @method Ok - Returns a value with a type `T` of `Result<T, E>` signifying success of an operation. If the `T` type is `void` or `undefined` can be used without a value.

* */
export declare const Ok: OkOverload;
export declare function Ok<T>(): Result<T | undefined, never>;
export declare function Ok<T>(data: T): Result<T, never>;
/**

@@ -58,2 +59,3 @@ * @method Err - Returns a value with a type `E` of `Result<T, E>` signifying fail of an operation. If the `E` type is `void` or `undefined` can be used without a value.

* */
export declare const Err: ErrOverload;
export declare function Err<E extends ErrType>(): Result<never, E | undefined>;
export declare function Err<E extends ErrType>(error: E): Result<never, E>;

@@ -33,61 +33,7 @@ // --- Note ---

}
/**
* @method Ok - Returns a value with a type `T` of `Result<T, E>` signifying success of an operation. If the `T` type is `void` or `undefined` can be used without a value.
* @returns `{ok: true, data: T}` result object.
* @example
* ```ts
* function toNumber(str: string): Result<number, Error> {
* const parseResult = Number(str);
*
* if (isNaN(parseResult)) {
* return Err(new Error(`Couldn't convert ${str} to number`));
* }
*
* return Ok(parseResult);
* }
*
* function testFileRead(path: string): Result<void, void> {
* const data = fs.readFile(path);
*
* if (!data.length) {
* return Err();
* }
*
* return Ok();
* }
* ```
* */
export const Ok = (data) => {
export function Ok(data) {
return { ok: true, data, throw: throwErr, else: elseDo, or };
};
/**
* @method Err - Returns a value with a type `E` of `Result<T, E>` signifying fail of an operation. If the `E` type is `void` or `undefined` can be used without a value.
*
* *Note:* `E` type is constrained by `undefined | void | string | Error`, custom error type that extends native `Error` also satisfies type boundaries
* @returns `{ok: fale, error: E}` result object.
* @example
* ```ts
* function toNumber(str: string): Result<number, Error> {
* const parseResult = Number(str);
*
* if (isNaN(parseResult)) {
* return Err(new Error(`Couldn't convert ${str} to number`));
* }
*
* return Ok(parseResult);
* }
*
* function testFileRead(path: string): Result<void, void> {
* const data = fs.readFile(path);
*
* if (!data.length) {
* return Err();
* }
*
* return Ok();
* }
* ```
* */
export const Err = (error) => {
}
export function Err(error) {
return { ok: false, error, throw: throwErr, else: elseDo, or };
};
}

@@ -127,10 +127,2 @@ type ThrowType = <T, E extends ErrType>(this: Result<T, E>, message?: string) => T;

} & ResultMethods);
export type OkOverload = {
<T>(): Result<T | undefined, never>;
<T>(data: T): Result<T, never>;
};
export type ErrOverload = {
<E extends ErrType>(): Result<never, E | undefined>;
<E extends ErrType>(error: E): Result<never, E>;
};
export {};
export { Result } from "./types";
export { Ok, Err } from "./main";
// TODO: test change

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

import { ErrOverload, ErrType, OkOverload, Result } from "./types";
import { ErrType, Result } from "./types";

@@ -77,5 +77,7 @@ // --- Note ---

* */
export const Ok: OkOverload = <T>(data?: T): Result<T | undefined, never> => {
export function Ok<T>(): Result<T | undefined, never>;
export function Ok<T>(data: T): Result<T, never>;
export function Ok<T>(data?: T): Result<T | undefined, never> {
return { ok: true, data, throw: throwErr, else: elseDo, or };
};
}

@@ -110,6 +112,8 @@ /**

* */
export const Err: ErrOverload = <E extends ErrType>(
export function Err<E extends ErrType>(): Result<never, E | undefined>;
export function Err<E extends ErrType>(error: E): Result<never, E>;
export function Err<E extends ErrType>(
error?: E
): Result<never, E | undefined> => {
): Result<never, E | undefined> {
return { ok: false, error, throw: throwErr, else: elseDo, or };
};
}

@@ -137,11 +137,1 @@ type ThrowType = <T, E extends ErrType>(

| ({ ok: false; error: E } & ResultMethods);
export type OkOverload = {
<T>(): Result<T | undefined, never>;
<T>(data: T): Result<T, never>;
};
export type ErrOverload = {
<E extends ErrType>(): Result<never, E | undefined>;
<E extends ErrType>(error: E): Result<never, E>;
};
{
"name": "ts-res",
"version": "0.0.1",
"version": "0.0.2",
"description": "TypeScript Result",

@@ -9,2 +9,8 @@ "repository": "https://github.com/Slava-Ini/ts-result",

"types": "build/index.d.ts",
"tags": ["typescript", "result", "rust"],
"scripts": {
"clean": "rimraf dist && rimraf tsconfig.tsbuildinfo",
"build": "npm run clean && tsc",
"test": "jest"
},
"author": "Slava.In",

@@ -18,8 +24,3 @@ "license": "MIT",

"typescript": "^5.0.2"
},
"scripts": {
"clean": "rimraf dist && rimraf tsconfig.tsbuildinfo",
"build": "npm run clean && tsc",
"test": "jest"
}
}
}

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