@t1xx1/tsfix 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tiziano Perego
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # Tsfix
@@ -0,0 +1,2 @@
1
+ export declare const assert: <T>(arg: T) => never;
2
+ export declare const assertUnreachable: (arg: never) => never;
package/dist/assert.js ADDED
@@ -0,0 +1,6 @@
1
+ export const assert = (arg) => {
2
+ throw new Error(`Assertion failed: ${arg}`);
3
+ };
4
+ export const assertUnreachable = (arg) => {
5
+ throw new Error(`Unreachable case: ${arg}`);
6
+ };
@@ -0,0 +1,4 @@
1
+ import './loose.js';
2
+ import './typescript.js';
3
+ export * from './assert.js';
4
+ export * from './trycatch.js';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import './loose.js';
2
+ import './typescript.js';
3
+ export * from './assert.js';
4
+ export * from './trycatch.js';
@@ -0,0 +1,5 @@
1
+ declare global {
2
+ type Loose<T> = T | (string & {});
3
+ type Strict<T> = T extends any ? (string extends T ? never : T) : never;
4
+ }
5
+ export {};
package/dist/loose.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ type Success<T> = {
2
+ data: T;
3
+ error: null;
4
+ };
5
+ type Failure<E> = {
6
+ data: null;
7
+ error: E;
8
+ };
9
+ export type Result<T, E> = Success<T> | Failure<E>;
10
+ export declare const tryCatch: <T, E = Error>(callback: () => Promise<T>) => Promise<Result<T, E>>;
11
+ export {};
@@ -0,0 +1,18 @@
1
+ /*
2
+ https://gist.github.com/t3dotgg/a486c4ae66d32bf17c09c73609dacc5b
3
+ https://gist.github.com/T1xx1/0793ede322ebcfcbb6fd0a4c298fe571
4
+ */
5
+ export const tryCatch = async (callback) => {
6
+ try {
7
+ return {
8
+ data: await callback(),
9
+ error: null,
10
+ };
11
+ }
12
+ catch (error) {
13
+ return {
14
+ data: null,
15
+ error: error,
16
+ };
17
+ }
18
+ };
@@ -0,0 +1,56 @@
1
+ declare global {
2
+ interface Array<T> {
3
+ includes(searchElement: Loose<T>, fromIndex?: number): boolean;
4
+ indexOf(searchElement: Loose<T>, fromIndex?: number): number;
5
+ lastIndexOf(searchElement: Loose<T>, fromIndex?: number): number;
6
+ }
7
+ interface ArrayConstructor {
8
+ isArray(arg: any): arg is unknown[];
9
+ }
10
+ interface Body {
11
+ json(): Promise<unknown>;
12
+ }
13
+ interface JSON {
14
+ parse(text: string, reviver?: (this: any, key: string, value: any) => any): unknown;
15
+ }
16
+ interface Map<K, V> {
17
+ has(key: Loose<K>): boolean;
18
+ }
19
+ interface MapConstructor {
20
+ new <K = unknown, V = unknown>(): Map<K, V>;
21
+ groupBy<K, T>(items: Iterable<T>, keySelector: (item: T, index: number) => K): Map<K, [T, ...T[]]>;
22
+ }
23
+ interface Node {
24
+ cloneNode(subtree?: boolean): this;
25
+ }
26
+ interface ObjectConstructor {
27
+ groupBy<K extends PropertyKey, T>(items: Iterable<T>, keySelector: (item: T, index: number) => K): Partial<Record<K, [T, ...T[]]>>;
28
+ }
29
+ interface Promise<T> {
30
+ catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>;
31
+ then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
32
+ }
33
+ interface ReadonlyArray<T> {
34
+ includes(searchElement: Loose<T>, fromIndex?: number): boolean;
35
+ indexOf(searchElement: Loose<T>, fromIndex?: number): number;
36
+ lastIndexOf(searchElement: Loose<T>, fromIndex?: number): number;
37
+ }
38
+ interface ReadonlyMap<K, V> {
39
+ has(key: Loose<K>): boolean;
40
+ }
41
+ interface ReadonlySet<T> {
42
+ has(value: Loose<T>): boolean;
43
+ }
44
+ interface Set<T> {
45
+ has(value: Loose<T>): boolean;
46
+ }
47
+ interface Storage {
48
+ [name: string & {}]: unknown;
49
+ }
50
+ interface TypedArray<T> {
51
+ includes(searchElement: Loose<T>, fromIndex?: number): boolean;
52
+ indexOf(searchElement: Loose<T>, fromIndex?: number): number;
53
+ lastIndexOf(searchElement: Loose<T>, fromIndex?: number): number;
54
+ }
55
+ }
56
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@t1xx1/tsfix",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "exports": {
6
+ "import": "./dist/index.js",
7
+ "types": "./dist/index.d.ts"
8
+ },
9
+ "scripts": {
10
+ "dev": "tsc -w",
11
+ "build": "tsc"
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "LICENSE",
16
+ "package.json",
17
+ "README.md"
18
+ ],
19
+ "devDependencies": {
20
+ "typescript": "^6.0.3"
21
+ },
22
+ "engines": {
23
+ "node": ">=24"
24
+ },
25
+ "packageManager": "pnpm@11.2.2"
26
+ }