Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details โ†’
Socket
Book a DemoInstallSign in
Socket

tuple-result

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tuple-result - npm Package Compare versions

Comparing version
0.0.2
to
0.0.3
+1
-1
dist/cjs/index.js

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

"use strict";var E=(r,t,n)=>new Promise((w,l)=>{var p=e=>{try{i(n.next(e))}catch(o){l(o)}},h=e=>{try{i(n.throw(e))}catch(o){l(o)}},i=e=>e.done?w(e.value):Promise.resolve(e.value).then(p,h);i((n=n.apply(r,t)).next())});class a extends Array{constructor(t){super(3),this[0]=!0,this[1]=void 0,this[2]=t}get value(){return this[2]}get error(){return this[1]}isOk(){return!0}isErr(){return!1}unwrap(){return this[2]}}class c extends Array{constructor(t){super(3),this[0]=!1,this[1]=t,this[2]=void 0}get value(){return this[2]}get error(){return this[1]}isOk(){return!1}isErr(){return!0}unwrap(){const t=this[1];throw t instanceof Error?t:typeof t=="string"?new Error(t):new Error("Unknown error")}}function u(r){return new a(r)}function s(r){return new c(r)}function O(r){return r instanceof a}function k(r){return r instanceof c}function y(r){return r.unwrap()}function d(r){if(r[0])return r[2];throw new Error("Expected an Ok result")}function v(r){if(!r[0])return r[1];throw new Error("Expected an Err result")}function f(r,t){return r[0]?r[2]:t}function m(r){return f(r,null)}function x(r,t){return r[0]?u(t(r[2])):s(r[1])}function g(r,t){return r[0]?u(r[2]):s(t(r[1]))}function z(r){return r[0]?[!0,r[2]]:[!1,r[1]]}function A(r){return r[0]?u(r[1]):s(r[1])}function R(r,...t){try{const n=r(...t);return u(n)}catch(n){return s(n)}}function N(r){return E(this,null,function*(){try{const t=yield r;return u(t)}catch(t){return s(t)}})}exports.Err=s,exports.ErrResult=c,exports.Ok=u,exports.OkResult=a,exports.deserialize=A,exports.isErr=k,exports.isOk=O,exports.mapErr=g,exports.mapOk=x,exports.serialize=z,exports.t=R,exports.tAsync=N,exports.unwrap=y,exports.unwrapErr=v,exports.unwrapOk=d,exports.unwrapOr=f,exports.unwrapOrNull=m;
"use strict";var E=(r,t,n)=>new Promise((w,l)=>{var p=e=>{try{i(n.next(e))}catch(o){l(o)}},h=e=>{try{i(n.throw(e))}catch(o){l(o)}},i=e=>e.done?w(e.value):Promise.resolve(e.value).then(p,h);i((n=n.apply(r,t)).next())});class a extends Array{constructor(t){super(3),this[0]=!0,this[1]=void 0,this[2]=t}get value(){return this[2]}get error(){return this[1]}isOk(){return!0}isErr(){return!1}unwrap(){return this[2]}}class c extends Array{constructor(t){super(3),this[0]=!1,this[1]=t,this[2]=void 0}get value(){return this[2]}get error(){return this[1]}isOk(){return!1}isErr(){return!0}unwrap(){const t=this[1];throw t instanceof Error?t:typeof t=="string"?new Error(t):new Error("Unknown error")}}function u(r){return new a(r)}const O=u;function s(r){return new c(r)}const k=s;function y(r){return r instanceof a}function d(r){return r instanceof c}function v(r){return r.unwrap()}function m(r){if(r[0])return r[2];throw new Error("Expected an Ok result")}function x(r){if(!r[0])return r[1];throw new Error("Expected an Err result")}function f(r,t){return r[0]?r[2]:t}function g(r){return f(r,null)}function z(r,t){return r[0]?u(t(r[2])):s(r[1])}function A(r,t){return r[0]?u(r[2]):s(t(r[1]))}function R(r){return r[0]?[!0,r[2]]:[!1,r[1]]}function N(r){return r[0]?u(r[1]):s(r[1])}function P(r,...t){try{const n=r(...t);return u(n)}catch(n){return s(n)}}function T(r){return E(this,null,function*(){try{const t=yield r;return u(t)}catch(t){return s(t)}})}exports.Err=s,exports.ErrResult=c,exports.Ok=u,exports.OkResult=a,exports.deserialize=N,exports.err=k,exports.isErr=d,exports.isOk=y,exports.mapErr=A,exports.mapOk=z,exports.ok=O,exports.serialize=R,exports.t=P,exports.tAsync=T,exports.unwrap=v,exports.unwrapErr=x,exports.unwrapOk=m,exports.unwrapOr=f,exports.unwrapOrNull=g;

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

var E=(r,t,n)=>new Promise((h,f)=>{var w=e=>{try{i(n.next(e))}catch(o){f(o)}},p=e=>{try{i(n.throw(e))}catch(o){f(o)}},i=e=>e.done?h(e.value):Promise.resolve(e.value).then(w,p);i((n=n.apply(r,t)).next())});class c extends Array{constructor(t){super(3),this[0]=!0,this[1]=void 0,this[2]=t}get value(){return this[2]}get error(){return this[1]}isOk(){return!0}isErr(){return!1}unwrap(){return this[2]}}class a extends Array{constructor(t){super(3),this[0]=!1,this[1]=t,this[2]=void 0}get value(){return this[2]}get error(){return this[1]}isOk(){return!1}isErr(){return!0}unwrap(){const t=this[1];throw t instanceof Error?t:typeof t=="string"?new Error(t):new Error("Unknown error")}}function u(r){return new c(r)}function s(r){return new a(r)}function y(r){return r instanceof c}function O(r){return r instanceof a}function d(r){return r.unwrap()}function k(r){if(r[0])return r[2];throw new Error("Expected an Ok result")}function v(r){if(!r[0])return r[1];throw new Error("Expected an Err result")}function l(r,t){return r[0]?r[2]:t}function x(r){return l(r,null)}function g(r,t){return r[0]?u(t(r[2])):s(r[1])}function m(r,t){return r[0]?u(r[2]):s(t(r[1]))}function A(r){return r[0]?[!0,r[2]]:[!1,r[1]]}function z(r){return r[0]?u(r[1]):s(r[1])}function P(r,...t){try{const n=r(...t);return u(n)}catch(n){return s(n)}}function R(r){return E(this,null,function*(){try{const t=yield r;return u(t)}catch(t){return s(t)}})}export{s as Err,a as ErrResult,u as Ok,c as OkResult,z as deserialize,O as isErr,y as isOk,m as mapErr,g as mapOk,A as serialize,P as t,R as tAsync,d as unwrap,v as unwrapErr,k as unwrapOk,l as unwrapOr,x as unwrapOrNull};
var E=(r,t,n)=>new Promise((h,f)=>{var w=e=>{try{o(n.next(e))}catch(i){f(i)}},p=e=>{try{o(n.throw(e))}catch(i){f(i)}},o=e=>e.done?h(e.value):Promise.resolve(e.value).then(w,p);o((n=n.apply(r,t)).next())});class c extends Array{constructor(t){super(3),this[0]=!0,this[1]=void 0,this[2]=t}get value(){return this[2]}get error(){return this[1]}isOk(){return!0}isErr(){return!1}unwrap(){return this[2]}}class a extends Array{constructor(t){super(3),this[0]=!1,this[1]=t,this[2]=void 0}get value(){return this[2]}get error(){return this[1]}isOk(){return!1}isErr(){return!0}unwrap(){const t=this[1];throw t instanceof Error?t:typeof t=="string"?new Error(t):new Error("Unknown error")}}function u(r){return new c(r)}const k=u;function s(r){return new a(r)}const y=s;function O(r){return r instanceof c}function d(r){return r instanceof a}function v(r){return r.unwrap()}function x(r){if(r[0])return r[2];throw new Error("Expected an Ok result")}function g(r){if(!r[0])return r[1];throw new Error("Expected an Err result")}function l(r,t){return r[0]?r[2]:t}function m(r){return l(r,null)}function A(r,t){return r[0]?u(t(r[2])):s(r[1])}function z(r,t){return r[0]?u(r[2]):s(t(r[1]))}function P(r){return r[0]?[!0,r[2]]:[!1,r[1]]}function R(r){return r[0]?u(r[1]):s(r[1])}function T(r,...t){try{const n=r(...t);return u(n)}catch(n){return s(n)}}function N(r){return E(this,null,function*(){try{const t=yield r;return u(t)}catch(t){return s(t)}})}export{s as Err,a as ErrResult,u as Ok,c as OkResult,R as deserialize,y as err,d as isErr,O as isOk,z as mapErr,A as mapOk,k as ok,P as serialize,T as t,N as tAsync,v as unwrap,g as unwrapErr,x as unwrapOk,l as unwrapOr,m as unwrapOrNull};

@@ -46,2 +46,3 @@ /**

export declare function Ok<T, E>(value: T): OkResult<T, E>;
export declare const ok: typeof Ok;
/**

@@ -53,2 +54,3 @@ * Creates an error result containing the given error.

export declare function Err<T, E>(error: E): ErrResult<T, E>;
export declare const err: typeof Err;
/**

@@ -55,0 +57,0 @@ * Type guard to check if a result is successful.

{
"name": "tuple-result",
"version": "0.0.2",
"version": "0.0.3",
"private": false,

@@ -5,0 +5,0 @@ "description": "A minimal, functional, and tree-shakable Result library for TypeScript that prioritizes simplicity and serialization",

+16
-22

@@ -23,3 +23,3 @@ <h1 align="center">

- **๐Ÿ”ฎ Simple, declarative API**: Intuitive array destructuring with full type safety
- **๐Ÿƒ Lightweight & Tree Shakable**: Function-based design with zero dependencies
- **๐Ÿƒ Lightweight & Tree Shakable**: Core ~150B, Full library ~500B
- **โšก High Performance**: Minimal overhead with just a 3-element array

@@ -33,10 +33,4 @@ - **๐Ÿ” Easy Serialization**: Simple array format perfect for wire transmission

Build a minimal, functional Result library that prioritizes simplicity and serialization. While libraries like [ts-results](https://github.com/vultix/ts-results) and [neverthrow](https://github.com/supermacro/neverthrow) offer robust features, they often come with bloated class hierarchies that can't be easily serialized. `tuple-result` provides a simpler alternative - combining minimal overhead, easy serialization for APIs and frameworks like React Router, and functional helpers while adhering to the KISS principle.
Build a minimal, functional Result library that prioritizes simplicity and serialization. While libraries like [ts-results](https://github.com/vultix/ts-results) and [neverthrow](https://github.com/supermacro/neverthrow) offer robust features, their class-based implementations can create challenges with serialization and bundle size. `tuple-result` provides a functional alternative using simple arrays - combining minimal overhead (~150B core), easy serialization for APIs and frameworks like React Router, and helper functions while adhering to the KISS principle.
**Key Features:**
- **Minimal Core**: Just a 3-element array `[boolean, E, T]` with methods
- **Easy Serialization**: Perfect for APIs, Remix loaders, and network requests
- **Array Destructuring**: Intuitive `[ok, error, value]` pattern
- **Tree Shakable**: Import only what you need
### โš–๏ธ Alternatives

@@ -78,5 +72,17 @@

### 3. Safe Value Extraction
### 3. Wrapping Functions
```ts
import { t, tAsync } from 'tuple-result';
// Wrap synchronous functions
const result = t(() => JSON.parse('invalid')); // Err(SyntaxError)
// Wrap promises
const asyncResult = await tAsync(fetch('/api/data')); // Ok(Response) or Err(Error)
```
### 4. Safe Value Extraction
```ts
import { unwrapOr, unwrapErr } from 'tuple-result';

@@ -91,3 +97,3 @@

### 4. Transforming Results
### 5. Transforming Results

@@ -104,14 +110,2 @@ ```ts

### 5. Wrapping Functions
```ts
import { t, tAsync } from 'tuple-result';
// Wrap synchronous functions
const result = t(() => JSON.parse('invalid')); // Err(SyntaxError)
// Wrap promises
const asyncResult = await tAsync(fetch('/api/data')); // Ok(Response) or Err(Error)
```
### 6. Serialization

@@ -118,0 +112,0 @@