@zokugun/xtry 0.11.4 → 0.11.6

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/README.md CHANGED
@@ -146,7 +146,7 @@ To minimize allocations when returning the same `Success` shape, you can reuse t
146
146
 
147
147
  ### Try helpers
148
148
 
149
- ```
149
+ ```typescript
150
150
  function xtry<T, E>(func: (() => MaybePromise<T>) | Promise<T>, handler?: (error: unknown) => void | E): MaybePromise<Result<T, E>>;
151
151
  function xtry<T, E>(iterable: (() => Iterable<T>) | Iterable<T>, handler?: (error: unknown) => void | E): Iterable<Result<T, E>>;
152
152
  function xtry<T, E>(iterable: (() => AsyncIterable<T>) | AsyncIterable<T>, handler?: (error: unknown) => void | E): AsyncIterable<Result<T, E>>;
package/lib/cjs/defer.cjs CHANGED
@@ -5,7 +5,8 @@ exports.xdeferAsync = xdeferAsync;
5
5
  exports.xdeferSync = xdeferSync;
6
6
  const result_js_1 = require("./result.cjs");
7
7
  const is_promise_like_js_1 = require("./utils/is-promise-like.cjs");
8
- function xdefer(callback, bind, ...args) {
8
+ /* eslint-enable @typescript-eslint/unified-signatures */
9
+ function xdefer(callback, thisArg, ...args) {
9
10
  // eslint-disable-next-line @typescript-eslint/promise-function-async
10
11
  return ((result) => {
11
12
  const finalize = (deferResult) => {
@@ -19,8 +20,8 @@ function xdefer(callback, bind, ...args) {
19
20
  };
20
21
  let deferredValue;
21
22
  if (callback instanceof Function) {
22
- if (bind) {
23
- deferredValue = Reflect.apply(callback, bind, args);
23
+ if (thisArg) {
24
+ deferredValue = Reflect.apply(callback, thisArg, args);
24
25
  }
25
26
  else {
26
27
  deferredValue = callback(...args);
@@ -35,14 +36,15 @@ function xdefer(callback, bind, ...args) {
35
36
  return finalize(deferredValue);
36
37
  });
37
38
  }
38
- function xdeferAsync(callback, bind, ...args) {
39
+ /* eslint-enable @typescript-eslint/unified-signatures */
40
+ function xdeferAsync(callback, thisArg, ...args) {
39
41
  return (async (result) => {
40
42
  let deferResult;
41
43
  if (callback instanceof Promise) {
42
44
  deferResult = await callback;
43
45
  }
44
- else if (bind) {
45
- deferResult = await callback.apply(bind, args);
46
+ else if (thisArg) {
47
+ deferResult = await callback.apply(thisArg, args);
46
48
  }
47
49
  else {
48
50
  deferResult = await callback(...args);
@@ -56,9 +58,10 @@ function xdeferAsync(callback, bind, ...args) {
56
58
  return result ?? (0, result_js_1.ok)();
57
59
  });
58
60
  }
59
- function xdeferSync(callback, bind, ...args) {
61
+ /* eslint-enable @typescript-eslint/unified-signatures */
62
+ function xdeferSync(callback, thisArg, ...args) {
60
63
  return ((result) => {
61
- const deferResult = bind ? callback.apply(bind, args) : callback(...args);
64
+ const deferResult = thisArg ? callback.apply(thisArg, args) : callback(...args);
62
65
  if (deferResult.fails) {
63
66
  if (result?.fails) {
64
67
  return result;
@@ -12,9 +12,17 @@ export type XDeferSync<E> = {
12
12
  <F>(result: Failure<F>): Failure<F>;
13
13
  <T, F>(result: Result<T, F>): Result<T, E | F>;
14
14
  };
15
- export declare function xdefer<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>, bind?: object, ...args: Args): XDeferSync<E>;
15
+ export declare function xdefer<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<void, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
16
+ export declare function xdefer<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
17
+ export declare function xdefer<E>(callback: Promise<Result<void, E>>): XDeferAsync<E>;
16
18
  export declare function xdefer<E>(callback: Promise<Result<unknown, E>>): XDeferAsync<E>;
17
- export declare function xdefer<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>, bind?: object, ...args: Args): XDeferAsync<E>;
19
+ export declare function xdefer<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<void, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
20
+ export declare function xdefer<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
21
+ export declare function xdeferAsync<E>(callback: Promise<Result<void, E>>): XDeferAsync<E>;
18
22
  export declare function xdeferAsync<E>(callback: Promise<Result<unknown, E>>): XDeferAsync<E>;
19
- export declare function xdeferAsync<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>, bind?: object, ...args: Args): XDeferAsync<E>;
20
- export declare function xdeferSync<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>, bind?: object, ...args: Args): XDeferSync<E>;
23
+ export declare function xdeferAsync<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<void, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
24
+ export declare function xdeferAsync<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
25
+ export declare function xdeferSync<E>(callback: NonPromiseCallback<Result<void, E>>): XDeferSync<E>;
26
+ export declare function xdeferSync<E>(callback: NonPromiseCallback<Result<unknown, E>>): XDeferSync<E>;
27
+ export declare function xdeferSync<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<void, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
28
+ export declare function xdeferSync<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
@@ -1,2 +1,3 @@
1
- export declare const parseJson: (...args: unknown[]) => import("./tryify.cjs").SyncFunctionResult<any, SyntaxError>;
2
- export declare const parseJSON: (...args: unknown[]) => import("./tryify.cjs").SyncFunctionResult<any, SyntaxError>;
1
+ import { type SyncFunctionResult } from "./tryify.cjs";
2
+ export declare const parseJson: (...args: unknown[]) => SyncFunctionResult<any, SyntaxError>;
3
+ export declare const parseJSON: (...args: unknown[]) => SyncFunctionResult<any, SyntaxError>;
@@ -1,5 +1,5 @@
1
+ export type Callback<T, Args extends unknown[] = []> = NonPromiseCallback<T, Args> | PromiseCallback<T, Args>;
2
+ export type MaybePromise<T> = T | Promise<T>;
1
3
  export type NotPromise<T> = Exclude<T, Promise<unknown>>;
2
4
  export type NonPromiseCallback<T, Args extends unknown[] = []> = (...args: Args) => NotPromise<T>;
3
5
  export type PromiseCallback<T, Args extends unknown[] = []> = ((...args: Args) => Promise<T>) | Promise<T>;
4
- export type Callback<T, Args extends unknown[] = []> = NonPromiseCallback<T, Args> | PromiseCallback<T, Args>;
5
- export type MaybePromise<T> = T | Promise<T>;
@@ -12,9 +12,17 @@ export type XDeferSync<E> = {
12
12
  <F>(result: Failure<F>): Failure<F>;
13
13
  <T, F>(result: Result<T, F>): Result<T, E | F>;
14
14
  };
15
- export declare function xdefer<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>, bind?: object, ...args: Args): XDeferSync<E>;
15
+ export declare function xdefer<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<void, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
16
+ export declare function xdefer<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
17
+ export declare function xdefer<E>(callback: Promise<Result<void, E>>): XDeferAsync<E>;
16
18
  export declare function xdefer<E>(callback: Promise<Result<unknown, E>>): XDeferAsync<E>;
17
- export declare function xdefer<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>, bind?: object, ...args: Args): XDeferAsync<E>;
19
+ export declare function xdefer<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<void, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
20
+ export declare function xdefer<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
21
+ export declare function xdeferAsync<E>(callback: Promise<Result<void, E>>): XDeferAsync<E>;
18
22
  export declare function xdeferAsync<E>(callback: Promise<Result<unknown, E>>): XDeferAsync<E>;
19
- export declare function xdeferAsync<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>, bind?: object, ...args: Args): XDeferAsync<E>;
20
- export declare function xdeferSync<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>, bind?: object, ...args: Args): XDeferSync<E>;
23
+ export declare function xdeferAsync<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<void, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
24
+ export declare function xdeferAsync<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
25
+ export declare function xdeferSync<E>(callback: NonPromiseCallback<Result<void, E>>): XDeferSync<E>;
26
+ export declare function xdeferSync<E>(callback: NonPromiseCallback<Result<unknown, E>>): XDeferSync<E>;
27
+ export declare function xdeferSync<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<void, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
28
+ export declare function xdeferSync<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
package/lib/esm/defer.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ok } from './result.mjs';
2
2
  import { isPromiseLike } from './utils/is-promise-like.mjs';
3
- export function xdefer(callback, bind, ...args) {
3
+ /* eslint-enable @typescript-eslint/unified-signatures */
4
+ export function xdefer(callback, thisArg, ...args) {
4
5
  // eslint-disable-next-line @typescript-eslint/promise-function-async
5
6
  return ((result) => {
6
7
  const finalize = (deferResult) => {
@@ -14,8 +15,8 @@ export function xdefer(callback, bind, ...args) {
14
15
  };
15
16
  let deferredValue;
16
17
  if (callback instanceof Function) {
17
- if (bind) {
18
- deferredValue = Reflect.apply(callback, bind, args);
18
+ if (thisArg) {
19
+ deferredValue = Reflect.apply(callback, thisArg, args);
19
20
  }
20
21
  else {
21
22
  deferredValue = callback(...args);
@@ -30,14 +31,15 @@ export function xdefer(callback, bind, ...args) {
30
31
  return finalize(deferredValue);
31
32
  });
32
33
  }
33
- export function xdeferAsync(callback, bind, ...args) {
34
+ /* eslint-enable @typescript-eslint/unified-signatures */
35
+ export function xdeferAsync(callback, thisArg, ...args) {
34
36
  return (async (result) => {
35
37
  let deferResult;
36
38
  if (callback instanceof Promise) {
37
39
  deferResult = await callback;
38
40
  }
39
- else if (bind) {
40
- deferResult = await callback.apply(bind, args);
41
+ else if (thisArg) {
42
+ deferResult = await callback.apply(thisArg, args);
41
43
  }
42
44
  else {
43
45
  deferResult = await callback(...args);
@@ -51,9 +53,10 @@ export function xdeferAsync(callback, bind, ...args) {
51
53
  return result ?? ok();
52
54
  });
53
55
  }
54
- export function xdeferSync(callback, bind, ...args) {
56
+ /* eslint-enable @typescript-eslint/unified-signatures */
57
+ export function xdeferSync(callback, thisArg, ...args) {
55
58
  return ((result) => {
56
- const deferResult = bind ? callback.apply(bind, args) : callback(...args);
59
+ const deferResult = thisArg ? callback.apply(thisArg, args) : callback(...args);
57
60
  if (deferResult.fails) {
58
61
  if (result?.fails) {
59
62
  return result;
@@ -1,2 +1,3 @@
1
- export declare const parseJson: (...args: unknown[]) => import("./tryify.mjs").SyncFunctionResult<any, SyntaxError>;
2
- export declare const parseJSON: (...args: unknown[]) => import("./tryify.mjs").SyncFunctionResult<any, SyntaxError>;
1
+ import { type SyncFunctionResult } from "./tryify.mjs";
2
+ export declare const parseJson: (...args: unknown[]) => SyncFunctionResult<any, SyntaxError>;
3
+ export declare const parseJSON: (...args: unknown[]) => SyncFunctionResult<any, SyntaxError>;
@@ -1,5 +1,5 @@
1
+ export type Callback<T, Args extends unknown[] = []> = NonPromiseCallback<T, Args> | PromiseCallback<T, Args>;
2
+ export type MaybePromise<T> = T | Promise<T>;
1
3
  export type NotPromise<T> = Exclude<T, Promise<unknown>>;
2
4
  export type NonPromiseCallback<T, Args extends unknown[] = []> = (...args: Args) => NotPromise<T>;
3
5
  export type PromiseCallback<T, Args extends unknown[] = []> = ((...args: Args) => Promise<T>) | Promise<T>;
4
- export type Callback<T, Args extends unknown[] = []> = NonPromiseCallback<T, Args> | PromiseCallback<T, Args>;
5
- export type MaybePromise<T> = T | Promise<T>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zokugun/xtry",
3
3
  "description": "simple try/catch wrapper returning Result",
4
- "version": "0.11.4",
4
+ "version": "0.11.6",
5
5
  "author": {
6
6
  "name": "Baptiste Augrain",
7
7
  "email": "daiyam@zokugun.org"
@@ -60,50 +60,61 @@
60
60
  }
61
61
  },
62
62
  "scripts": {
63
+ "audit:fix": "npm audit fix --min-release-age=0",
63
64
  "build": "npm run clean && npm run build:lib",
64
65
  "build:lib": "tsc-leda generate",
65
- "build:package": "tsc-leda update-package",
66
+ "build:package": "tsc-leda update-package && npm run lint:package",
66
67
  "ci:lint": "zizmor .",
67
68
  "ci:lint:fix": "zizmor . --fix=all",
68
- "ci:update": "PINACT_MIN_AGE=7 pinact run",
69
- "clean": "rimraf lib .test",
69
+ "clean": "rimraf .src .test lib",
70
70
  "compile:src": "tsc -p src",
71
71
  "compile:test": "tsc -p test",
72
- "deps:update": "taze",
73
72
  "lint": "xo",
73
+ "lint:all": "npm audit && npm run lint:package && npm run ci:lint && npm run lint",
74
74
  "lint:fix": "xo --fix",
75
+ "lint:package": "fixpack || true",
75
76
  "prepack": "npm run build",
76
- "prepare": "husky; fixpack || true",
77
+ "prepare": "husky; npm run lint:package",
77
78
  "release": "release-it",
78
79
  "test": "vitest run --reporter tree",
79
80
  "test:coverage": "vitest run --reporter tree --coverage --coverage.reporter text",
80
81
  "test:ui": "vitest --ui --coverage",
81
82
  "test:watch": "vitest",
83
+ "update:artifacts": "artifact update",
84
+ "update:ci": "PINACT_MIN_AGE=7 pinact run --update",
85
+ "update:deps": "taze --all",
82
86
  "watch:build": "tsc-watch -p src --onSuccess 'npm run build'",
83
87
  "watch:src": "tsc-watch -p src",
84
88
  "watch:test": "tsc-watch -p test"
85
89
  },
90
+ "dependencies": {},
86
91
  "devDependencies": {
87
- "@commitlint/cli": "19.8.1",
88
- "@commitlint/config-conventional": "19.8.1",
92
+ "@commitlint/cli": "20.5.3",
93
+ "@commitlint/config-conventional": "20.5.3",
89
94
  "@types/fs-extra": "11.0.4",
90
95
  "@types/node": "20.19.39",
91
- "@vitest/coverage-v8": "4.1.2",
92
- "@vitest/ui": "4.1.2",
93
- "@zokugun/fs-extra-plus": "0.3.6",
94
- "@zokugun/tsc-leda": "0.1.6",
96
+ "@vitest/coverage-v8": "4.1.5",
97
+ "@vitest/ui": "4.1.5",
98
+ "@zokugun/fs-extra-plus": "0.4.1",
99
+ "@zokugun/tsc-leda": "0.4.1",
95
100
  "fixpack": "4.0.0",
96
101
  "fs-extra": "11.3.4",
97
102
  "globby": "16.2.0",
98
103
  "husky": "9.1.7",
99
104
  "lint-staged": "16.4.0",
100
- "release-it": "20.0.0-1",
105
+ "release-it": "20.0.1",
106
+ "rimraf": "6.1.3",
101
107
  "taze": "19.11.0",
102
108
  "tsc-watch": "7.2.0",
103
109
  "typescript": "5.9.3",
104
- "vitest": "4.1.2",
110
+ "vitest": "4.1.5",
105
111
  "xo": "0.60.0"
106
112
  },
113
+ "overrides": {
114
+ "ajv": {
115
+ "fast-uri": "3.1.2"
116
+ }
117
+ },
107
118
  "keywords": [
108
119
  "catch",
109
120
  "error",