Compare commits
16 Commits
v0.0.2
...
renovate/c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eba8a150dd | ||
|
|
74852c481a | ||
|
|
be5ea204ce | ||
|
|
4c3e60cf85
|
||
|
|
c04b7d5c8c | ||
|
|
a4f857e71e
|
||
|
|
ecfbfc7ea4
|
||
|
|
ae87a2da7b
|
||
|
|
02490a2502
|
||
|
|
3444a1c5da
|
||
|
|
f19a5ec2b1
|
||
|
|
0895f7c1c2 | ||
|
|
d003151b0f | ||
|
|
731ff705a2
|
||
|
|
138dc210e1
|
||
|
|
65a4f3de22 |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -1,5 +1,17 @@
|
||||
# lilbetter.js
|
||||
|
||||
## 0.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- ecfbfc7: Created the tryAsync (tryA) and trySync (tryS) functions, said can be used for wrapping and calling functions that can throw error. Said error can then be handled using in a Go-like fashion.
|
||||
|
||||
## 0.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 138dc21: Populated package.json
|
||||
|
||||
## 0.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"alwaysStrict": true
|
||||
},
|
||||
"include": [
|
||||
"./src/**/*.js",
|
||||
"./src/**/*",
|
||||
"./test/**/*.js",
|
||||
"./eslint.config.js",
|
||||
"./commitlint.config.cjs"
|
||||
|
||||
86
package.json
86
package.json
@@ -1,29 +1,61 @@
|
||||
{
|
||||
"name": "lilbetter.js",
|
||||
"version": "0.0.2",
|
||||
"description": "",
|
||||
"main": "./src/index.js",
|
||||
"scripts": {
|
||||
"test": "vitest",
|
||||
"prepare": "husky install",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix",
|
||||
"release": "changeset publish"
|
||||
},
|
||||
"type": "module",
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@changesets/cli": "^2.27.1",
|
||||
"@commitlint/config-conventional": "^18.4.4",
|
||||
"@commitlint/types": "^18.4.4",
|
||||
"@eslegant/js": "0.0.0-next-20230910004746",
|
||||
"eslint": "^8.56.0",
|
||||
"husky": "^8.0.3",
|
||||
"vitest": "^1.2.1"
|
||||
}
|
||||
"name": "lilbetter.js",
|
||||
"version": "0.1.0",
|
||||
"description": "",
|
||||
"main": "./src/index.js",
|
||||
"browser": "./src/index.js",
|
||||
"source": "./src/index.js",
|
||||
"module": "./src/index.js",
|
||||
"homepage": "https://github.com/LoredDev/lilbetter.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/LoredDev/lilbetter.js"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./src/index.js",
|
||||
"default": "./src/index.js",
|
||||
"types": "./src/index.d.ts"
|
||||
},
|
||||
"./try": {
|
||||
"import": "./src/try.js",
|
||||
"default": "./src/try.js",
|
||||
"types": "./src/try.d.ts"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"./src/**/*.js",
|
||||
"./src/**/*.d.ts"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "vitest",
|
||||
"prepare": "husky install",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix",
|
||||
"release": "changeset publish"
|
||||
},
|
||||
"type": "module",
|
||||
"keywords": [],
|
||||
"author": {
|
||||
"email": "contact.guz013@gmail.com",
|
||||
"name": "Gustavo \"Guz\" L. de Mello",
|
||||
"url": "https://guz.one"
|
||||
},
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18",
|
||||
"pnpm": ">=8"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@changesets/cli": "^2.27.1",
|
||||
"@commitlint/config-conventional": "^18.4.4",
|
||||
"@commitlint/types": "^18.4.4",
|
||||
"@eslegant/js": "0.0.0-next-20230910004746",
|
||||
"eslint": "^8.56.0",
|
||||
"husky": "^8.0.3",
|
||||
"vitest": "^1.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
382
pnpm-lock.yaml
generated
382
pnpm-lock.yaml
generated
@@ -10,10 +10,10 @@ devDependencies:
|
||||
version: 2.27.1
|
||||
'@commitlint/config-conventional':
|
||||
specifier: ^18.4.4
|
||||
version: 18.4.4
|
||||
version: 18.6.2
|
||||
'@commitlint/types':
|
||||
specifier: ^18.4.4
|
||||
version: 18.4.4
|
||||
version: 18.6.1
|
||||
'@eslegant/js':
|
||||
specifier: 0.0.0-next-20230910004746
|
||||
version: 0.0.0-next-20230910004746(eslint-plugin-import@2.29.1)(eslint@8.56.0)(typescript@5.3.3)
|
||||
@@ -246,15 +246,16 @@ packages:
|
||||
prettier: 2.8.8
|
||||
dev: true
|
||||
|
||||
/@commitlint/config-conventional@18.4.4:
|
||||
resolution: {integrity: sha512-Bz3sPQSboBN+Et/KyZrR+OJ3z9PrHDw7Bls0/hv94PmuHBtMq1dCGxS9XzTGzxeMNlytCC4kxF083tbhPljl3Q==}
|
||||
/@commitlint/config-conventional@18.6.2:
|
||||
resolution: {integrity: sha512-PcgSYg1AKGQIwDQKbaHtJsfqYy4uJTC7crLVZ83lfjcPaec4Pry2vLeaWej7ao2KsT20l9dWoMPpEGg8LWdUuA==}
|
||||
engines: {node: '>=v18'}
|
||||
dependencies:
|
||||
'@commitlint/types': 18.6.1
|
||||
conventional-changelog-conventionalcommits: 7.0.2
|
||||
dev: true
|
||||
|
||||
/@commitlint/types@18.4.4:
|
||||
resolution: {integrity: sha512-/FykLtodD8gKs3+VNkAUwofu4LBHankclj+I8fB2jTRvG6PV7k/OUt4P+VbM7ip853qS4F0g7Z6hLNa6JeMcAQ==}
|
||||
/@commitlint/types@18.6.1:
|
||||
resolution: {integrity: sha512-gwRLBLra/Dozj2OywopeuHj2ac26gjGkz2cZ+86cTJOdtWfiRRr4+e77ZDAGc6MDWxaWheI+mAV5TLWWRwqrFg==}
|
||||
engines: {node: '>=v18'}
|
||||
dependencies:
|
||||
chalk: 4.1.2
|
||||
@@ -1070,6 +1071,14 @@ packages:
|
||||
is-array-buffer: 3.0.2
|
||||
dev: true
|
||||
|
||||
/array-buffer-byte-length@1.0.1:
|
||||
resolution: {integrity: sha512-ahC5W1xgou+KTXix4sAO8Ki12Q+jf4i0+tmk3sC+zgcynshkHxzpXdImBehiUYKKKDwvfFiJl1tZt6ewscS1Mg==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.7
|
||||
is-array-buffer: 3.0.4
|
||||
dev: true
|
||||
|
||||
/array-ify@1.0.0:
|
||||
resolution: {integrity: sha512-c5AMf34bKdvPhQ7tBGhqkgKNUzMr4WUs+WDtC2ZUGOUncbxKMTvqxYctiseW3+L4bA8ec+GcZ6/A/FW4m8ukng==}
|
||||
dev: true
|
||||
@@ -1078,10 +1087,10 @@ packages:
|
||||
resolution: {integrity: sha512-dlcsNBIiWhPkHdOEEKnehA+RNUWDc4UqFtnIXU4uuYDPtA4LDkr7qip2p0VvFAEXNDr0yWZ9PJyIRiGjRLQzwQ==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.5
|
||||
call-bind: 1.0.7
|
||||
define-properties: 1.2.1
|
||||
es-abstract: 1.22.3
|
||||
get-intrinsic: 1.2.2
|
||||
es-abstract: 1.22.4
|
||||
get-intrinsic: 1.2.4
|
||||
is-string: 1.0.7
|
||||
dev: true
|
||||
|
||||
@@ -1090,15 +1099,26 @@ packages:
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/array.prototype.findlastindex@1.2.3:
|
||||
resolution: {integrity: sha512-LzLoiOMAxvy+Gd3BAq3B7VeIgPdo+Q8hthvKtXybMvRV0jrXfJM/t8mw7nNlpEcVlVUnCnM2KSX4XU5HmpodOA==}
|
||||
/array.prototype.filter@1.0.3:
|
||||
resolution: {integrity: sha512-VizNcj/RGJiUyQBgzwxzE5oHdeuXY5hSbbmKMlphj1cy1Vl7Pn2asCGbSrru6hSQjmCzqTBPVWAF/whmEOVHbw==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.5
|
||||
call-bind: 1.0.7
|
||||
define-properties: 1.2.1
|
||||
es-abstract: 1.22.3
|
||||
es-abstract: 1.22.4
|
||||
es-array-method-boxes-properly: 1.0.0
|
||||
is-string: 1.0.7
|
||||
dev: true
|
||||
|
||||
/array.prototype.findlastindex@1.2.4:
|
||||
resolution: {integrity: sha512-hzvSHUshSpCflDR1QMUBLHGHP1VIEBegT4pix9H/Z92Xw3ySoy6c2qh7lJWTJnRJ8JCZ9bJNCgTyYaJGcJu6xQ==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.7
|
||||
define-properties: 1.2.1
|
||||
es-abstract: 1.22.4
|
||||
es-errors: 1.3.0
|
||||
es-shim-unscopables: 1.0.2
|
||||
get-intrinsic: 1.2.2
|
||||
dev: true
|
||||
|
||||
/array.prototype.flat@1.3.2:
|
||||
@@ -1115,9 +1135,9 @@ packages:
|
||||
resolution: {integrity: sha512-Ewyx0c9PmpcsByhSW4r+9zDU7sGjFc86qf/kKtuSCRdhfbk0SNLLkaT5qvcHnRGgc5NP/ly/y+qkXkqONX54CQ==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.5
|
||||
call-bind: 1.0.7
|
||||
define-properties: 1.2.1
|
||||
es-abstract: 1.22.3
|
||||
es-abstract: 1.22.4
|
||||
es-shim-unscopables: 1.0.2
|
||||
dev: true
|
||||
|
||||
@@ -1134,6 +1154,20 @@ packages:
|
||||
is-shared-array-buffer: 1.0.2
|
||||
dev: true
|
||||
|
||||
/arraybuffer.prototype.slice@1.0.3:
|
||||
resolution: {integrity: sha512-bMxMKAjg13EBSVscxTaYA4mRc5t1UAXa2kXiGTNfZ079HIWXEkKmkgFrh/nJqamaLSrXO5H4WFFkPEaLJWbs3A==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
array-buffer-byte-length: 1.0.1
|
||||
call-bind: 1.0.7
|
||||
define-properties: 1.2.1
|
||||
es-abstract: 1.22.4
|
||||
es-errors: 1.3.0
|
||||
get-intrinsic: 1.2.4
|
||||
is-array-buffer: 3.0.4
|
||||
is-shared-array-buffer: 1.0.3
|
||||
dev: true
|
||||
|
||||
/arrify@1.0.1:
|
||||
resolution: {integrity: sha512-3CYzex9M9FGQjCGMGyi6/31c8GJbgb0qGyrx5HWxPd0aCwh4cB2YjMb2Xf9UuoogrMrlO9cTqnB5rI5GHZTcUA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
@@ -1154,6 +1188,13 @@ packages:
|
||||
engines: {node: '>= 0.4'}
|
||||
dev: true
|
||||
|
||||
/available-typed-arrays@1.0.7:
|
||||
resolution: {integrity: sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
possible-typed-array-names: 1.0.0
|
||||
dev: true
|
||||
|
||||
/balanced-match@1.0.2:
|
||||
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
|
||||
dev: true
|
||||
@@ -1226,6 +1267,17 @@ packages:
|
||||
set-function-length: 1.2.0
|
||||
dev: true
|
||||
|
||||
/call-bind@1.0.7:
|
||||
resolution: {integrity: sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
es-define-property: 1.0.0
|
||||
es-errors: 1.3.0
|
||||
function-bind: 1.1.2
|
||||
get-intrinsic: 1.2.4
|
||||
set-function-length: 1.2.1
|
||||
dev: true
|
||||
|
||||
/callsites@3.1.0:
|
||||
resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==}
|
||||
engines: {node: '>=6'}
|
||||
@@ -1468,6 +1520,15 @@ packages:
|
||||
has-property-descriptors: 1.0.1
|
||||
dev: true
|
||||
|
||||
/define-data-property@1.1.4:
|
||||
resolution: {integrity: sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
es-define-property: 1.0.0
|
||||
es-errors: 1.3.0
|
||||
gopd: 1.0.1
|
||||
dev: true
|
||||
|
||||
/define-properties@1.2.1:
|
||||
resolution: {integrity: sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@@ -1590,6 +1651,69 @@ packages:
|
||||
which-typed-array: 1.1.13
|
||||
dev: true
|
||||
|
||||
/es-abstract@1.22.4:
|
||||
resolution: {integrity: sha512-vZYJlk2u6qHYxBOTjAeg7qUxHdNfih64Uu2J8QqWgXZ2cri0ZpJAkzDUK/q593+mvKwlxyaxr6F1Q+3LKoQRgg==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
array-buffer-byte-length: 1.0.1
|
||||
arraybuffer.prototype.slice: 1.0.3
|
||||
available-typed-arrays: 1.0.7
|
||||
call-bind: 1.0.7
|
||||
es-define-property: 1.0.0
|
||||
es-errors: 1.3.0
|
||||
es-set-tostringtag: 2.0.3
|
||||
es-to-primitive: 1.2.1
|
||||
function.prototype.name: 1.1.6
|
||||
get-intrinsic: 1.2.4
|
||||
get-symbol-description: 1.0.2
|
||||
globalthis: 1.0.3
|
||||
gopd: 1.0.1
|
||||
has-property-descriptors: 1.0.2
|
||||
has-proto: 1.0.3
|
||||
has-symbols: 1.0.3
|
||||
hasown: 2.0.1
|
||||
internal-slot: 1.0.7
|
||||
is-array-buffer: 3.0.4
|
||||
is-callable: 1.2.7
|
||||
is-negative-zero: 2.0.3
|
||||
is-regex: 1.1.4
|
||||
is-shared-array-buffer: 1.0.3
|
||||
is-string: 1.0.7
|
||||
is-typed-array: 1.1.13
|
||||
is-weakref: 1.0.2
|
||||
object-inspect: 1.13.1
|
||||
object-keys: 1.1.1
|
||||
object.assign: 4.1.5
|
||||
regexp.prototype.flags: 1.5.2
|
||||
safe-array-concat: 1.1.0
|
||||
safe-regex-test: 1.0.3
|
||||
string.prototype.trim: 1.2.8
|
||||
string.prototype.trimend: 1.0.7
|
||||
string.prototype.trimstart: 1.0.7
|
||||
typed-array-buffer: 1.0.2
|
||||
typed-array-byte-length: 1.0.1
|
||||
typed-array-byte-offset: 1.0.2
|
||||
typed-array-length: 1.0.5
|
||||
unbox-primitive: 1.0.2
|
||||
which-typed-array: 1.1.14
|
||||
dev: true
|
||||
|
||||
/es-array-method-boxes-properly@1.0.0:
|
||||
resolution: {integrity: sha512-wd6JXUmyHmt8T5a2xreUwKcGPq6f1f+WwIJkijUqiGcJz1qqnZgP6XIK+QyIWU5lT7imeNxUll48bziG+TSYcA==}
|
||||
dev: true
|
||||
|
||||
/es-define-property@1.0.0:
|
||||
resolution: {integrity: sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
get-intrinsic: 1.2.4
|
||||
dev: true
|
||||
|
||||
/es-errors@1.3.0:
|
||||
resolution: {integrity: sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dev: true
|
||||
|
||||
/es-set-tostringtag@2.0.2:
|
||||
resolution: {integrity: sha512-BuDyupZt65P9D2D2vA/zqcI3G5xRsklm5N3xCwuiy+/vKy8i0ifdsQP1sLgO4tZDSCaQUSnmC48khknGMV3D2Q==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@@ -1599,6 +1723,15 @@ packages:
|
||||
hasown: 2.0.0
|
||||
dev: true
|
||||
|
||||
/es-set-tostringtag@2.0.3:
|
||||
resolution: {integrity: sha512-3T8uNMC3OQTHkFUsFq8r/BwAXLHvU/9O9mE0fBc/MY5iq/8H7ncvO947LmYA6ldWw9Uh8Yhf25zu6n7nML5QWQ==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
get-intrinsic: 1.2.4
|
||||
has-tostringtag: 1.0.2
|
||||
hasown: 2.0.1
|
||||
dev: true
|
||||
|
||||
/es-shim-unscopables@1.0.2:
|
||||
resolution: {integrity: sha512-J3yBRXCzDu4ULnQwxyToo/OjdMx6akgVC7K6few0a7F/0wLtmKKN7I73AH5T2836UuXRqN7Qg+IIUw/+YJksRw==}
|
||||
dependencies:
|
||||
@@ -1795,7 +1928,7 @@ packages:
|
||||
dependencies:
|
||||
'@typescript-eslint/parser': 6.19.0(eslint@8.56.0)(typescript@5.3.3)
|
||||
array-includes: 3.1.7
|
||||
array.prototype.findlastindex: 1.2.3
|
||||
array.prototype.findlastindex: 1.2.4
|
||||
array.prototype.flat: 1.3.2
|
||||
array.prototype.flatmap: 1.3.2
|
||||
debug: 3.2.7
|
||||
@@ -1803,12 +1936,12 @@ packages:
|
||||
eslint: 8.56.0
|
||||
eslint-import-resolver-node: 0.3.9
|
||||
eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.19.0)(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.56.0)
|
||||
hasown: 2.0.0
|
||||
hasown: 2.0.1
|
||||
is-core-module: 2.13.1
|
||||
is-glob: 4.0.3
|
||||
minimatch: 3.1.2
|
||||
object.fromentries: 2.0.7
|
||||
object.groupby: 1.0.1
|
||||
object.groupby: 1.0.2
|
||||
object.values: 1.1.7
|
||||
semver: 6.3.1
|
||||
tsconfig-paths: 3.15.0
|
||||
@@ -2211,6 +2344,17 @@ packages:
|
||||
hasown: 2.0.0
|
||||
dev: true
|
||||
|
||||
/get-intrinsic@1.2.4:
|
||||
resolution: {integrity: sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
es-errors: 1.3.0
|
||||
function-bind: 1.1.2
|
||||
has-proto: 1.0.3
|
||||
has-symbols: 1.0.3
|
||||
hasown: 2.0.1
|
||||
dev: true
|
||||
|
||||
/get-stream@8.0.1:
|
||||
resolution: {integrity: sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA==}
|
||||
engines: {node: '>=16'}
|
||||
@@ -2224,6 +2368,15 @@ packages:
|
||||
get-intrinsic: 1.2.2
|
||||
dev: true
|
||||
|
||||
/get-symbol-description@1.0.2:
|
||||
resolution: {integrity: sha512-g0QYk1dZBxGwk+Ngc+ltRH2IBp2f7zBkBMBJZCDerh6EhlhSR6+9irMCuT/09zD6qkarHUSn529sK/yL4S27mg==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.7
|
||||
es-errors: 1.3.0
|
||||
get-intrinsic: 1.2.4
|
||||
dev: true
|
||||
|
||||
/get-tsconfig@4.7.2:
|
||||
resolution: {integrity: sha512-wuMsz4leaj5hbGgg4IvDU0bqJagpftG5l5cXIAvo8uZrqn0NJqwtfupTN00VnkQJPcIRrxYrm1Ue24btpCha2A==}
|
||||
dependencies:
|
||||
@@ -2324,11 +2477,22 @@ packages:
|
||||
get-intrinsic: 1.2.2
|
||||
dev: true
|
||||
|
||||
/has-property-descriptors@1.0.2:
|
||||
resolution: {integrity: sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==}
|
||||
dependencies:
|
||||
es-define-property: 1.0.0
|
||||
dev: true
|
||||
|
||||
/has-proto@1.0.1:
|
||||
resolution: {integrity: sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dev: true
|
||||
|
||||
/has-proto@1.0.3:
|
||||
resolution: {integrity: sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dev: true
|
||||
|
||||
/has-symbols@1.0.3:
|
||||
resolution: {integrity: sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@@ -2341,6 +2505,13 @@ packages:
|
||||
has-symbols: 1.0.3
|
||||
dev: true
|
||||
|
||||
/has-tostringtag@1.0.2:
|
||||
resolution: {integrity: sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
has-symbols: 1.0.3
|
||||
dev: true
|
||||
|
||||
/hasown@2.0.0:
|
||||
resolution: {integrity: sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@@ -2348,6 +2519,13 @@ packages:
|
||||
function-bind: 1.1.2
|
||||
dev: true
|
||||
|
||||
/hasown@2.0.1:
|
||||
resolution: {integrity: sha512-1/th4MHjnwncwXsIW6QMzlvYL9kG5e/CpVvLRZe4XPa8TOUNbCELqmvhDmnkNsAjwaG4+I8gJJL0JBvTTLO9qA==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
function-bind: 1.1.2
|
||||
dev: true
|
||||
|
||||
/hosted-git-info@2.8.9:
|
||||
resolution: {integrity: sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==}
|
||||
dev: true
|
||||
@@ -2417,6 +2595,15 @@ packages:
|
||||
side-channel: 1.0.4
|
||||
dev: true
|
||||
|
||||
/internal-slot@1.0.7:
|
||||
resolution: {integrity: sha512-NGnrKwXzSms2qUUih/ILZ5JBqNTSa1+ZmP6flaIp6KmSElgE9qdndzS3cqjrDovwFdmwsGsLdeFgB6suw+1e9g==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
es-errors: 1.3.0
|
||||
hasown: 2.0.1
|
||||
side-channel: 1.0.5
|
||||
dev: true
|
||||
|
||||
/is-array-buffer@3.0.2:
|
||||
resolution: {integrity: sha512-y+FyyR/w8vfIRq4eQcM1EYgSTnmHXPqaF+IgzgraytCFq5Xh8lllDVmAZolPJiZttZLeFSINPYMaEJ7/vWUa1w==}
|
||||
dependencies:
|
||||
@@ -2425,6 +2612,14 @@ packages:
|
||||
is-typed-array: 1.1.12
|
||||
dev: true
|
||||
|
||||
/is-array-buffer@3.0.4:
|
||||
resolution: {integrity: sha512-wcjaerHw0ydZwfhiKbXJWLDY8A7yV7KhjQOpb83hGgGfId/aQa4TOvwyzn2PuswW2gPCYEL/nEAiSVpdOj1lXw==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.7
|
||||
get-intrinsic: 1.2.4
|
||||
dev: true
|
||||
|
||||
/is-arrayish@0.2.1:
|
||||
resolution: {integrity: sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==}
|
||||
dev: true
|
||||
@@ -2490,6 +2685,11 @@ packages:
|
||||
engines: {node: '>= 0.4'}
|
||||
dev: true
|
||||
|
||||
/is-negative-zero@2.0.3:
|
||||
resolution: {integrity: sha512-5KoIu2Ngpyek75jXodFvnafB6DJgr3u8uuK0LEZJjrU19DrMD3EVERaR8sjz8CCGgpZvxPl9SuE1GMVPFHx1mw==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dev: true
|
||||
|
||||
/is-number-object@1.0.7:
|
||||
resolution: {integrity: sha512-k1U0IRzLMo7ZlYIfzRu23Oh6MiIFasgpb9X76eqfFZAqwH44UI4KTBvBYIZ1dSL9ZzChTB9ShHfLkR4pdW5krQ==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@@ -2531,6 +2731,13 @@ packages:
|
||||
call-bind: 1.0.5
|
||||
dev: true
|
||||
|
||||
/is-shared-array-buffer@1.0.3:
|
||||
resolution: {integrity: sha512-nA2hv5XIhLR3uVzDDfCIknerhx8XUKnstuOERPNNIinXG7v9u+ohXF67vxm4TPTEPU6lm61ZkwP3c9PCB97rhg==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.7
|
||||
dev: true
|
||||
|
||||
/is-stream@3.0.0:
|
||||
resolution: {integrity: sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==}
|
||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||
@@ -2564,6 +2771,13 @@ packages:
|
||||
which-typed-array: 1.1.13
|
||||
dev: true
|
||||
|
||||
/is-typed-array@1.1.13:
|
||||
resolution: {integrity: sha512-uZ25/bUAlUY5fR4OKT4rZQEBrzQWYV9ZJYGGsUmEJ6thodVJ1HX64ePQ6Z0qPWP+m+Uq6e9UugrE38jeYsDSMw==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
which-typed-array: 1.1.14
|
||||
dev: true
|
||||
|
||||
/is-weakref@1.0.2:
|
||||
resolution: {integrity: sha512-qctsuLZmIQ0+vSSMfoVvyFe2+GSEvnmZ2ezTup1SBse9+twCCeial6EEi3Nc2KFcf6+qz2FBPnjXsk8xhKSaPQ==}
|
||||
dependencies:
|
||||
@@ -2919,27 +3133,28 @@ packages:
|
||||
resolution: {integrity: sha512-UPbPHML6sL8PI/mOqPwsH4G6iyXcCGzLin8KvEPenOZN5lpCNBZZQ+V62vdjB1mQHrmqGQt5/OJzemUA+KJmEA==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.5
|
||||
call-bind: 1.0.7
|
||||
define-properties: 1.2.1
|
||||
es-abstract: 1.22.3
|
||||
es-abstract: 1.22.4
|
||||
dev: true
|
||||
|
||||
/object.groupby@1.0.1:
|
||||
resolution: {integrity: sha512-HqaQtqLnp/8Bn4GL16cj+CUYbnpe1bh0TtEaWvybszDG4tgxCJuRpV8VGuvNaI1fAnI4lUJzDG55MXcOH4JZcQ==}
|
||||
/object.groupby@1.0.2:
|
||||
resolution: {integrity: sha512-bzBq58S+x+uo0VjurFT0UktpKHOZmv4/xePiOA1nbB9pMqpGK7rUPNgf+1YC+7mE+0HzhTMqNUuCqvKhj6FnBw==}
|
||||
dependencies:
|
||||
call-bind: 1.0.5
|
||||
array.prototype.filter: 1.0.3
|
||||
call-bind: 1.0.7
|
||||
define-properties: 1.2.1
|
||||
es-abstract: 1.22.3
|
||||
get-intrinsic: 1.2.2
|
||||
es-abstract: 1.22.4
|
||||
es-errors: 1.3.0
|
||||
dev: true
|
||||
|
||||
/object.values@1.1.7:
|
||||
resolution: {integrity: sha512-aU6xnDFYT3x17e/f0IiiwlGPTy2jzMySGfUB4fq6z7CV8l85CWHDk5ErhyhpfDHhrOMwGFhSQkhMGHaIotA6Ng==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.5
|
||||
call-bind: 1.0.7
|
||||
define-properties: 1.2.1
|
||||
es-abstract: 1.22.3
|
||||
es-abstract: 1.22.4
|
||||
dev: true
|
||||
|
||||
/once@1.4.0:
|
||||
@@ -3116,6 +3331,11 @@ packages:
|
||||
engines: {node: '>=4'}
|
||||
dev: true
|
||||
|
||||
/possible-typed-array-names@1.0.0:
|
||||
resolution: {integrity: sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dev: true
|
||||
|
||||
/postcss@8.4.33:
|
||||
resolution: {integrity: sha512-Kkpbhhdjw2qQs2O2DGX+8m5OVqEcbB9HRBvuYM9pgrjEFUg30A9LmXNlTAUj4S9kgtGyrMbTzVjH7E+s5Re2yg==}
|
||||
engines: {node: ^10 || ^12 || >=14}
|
||||
@@ -3232,6 +3452,16 @@ packages:
|
||||
set-function-name: 2.0.1
|
||||
dev: true
|
||||
|
||||
/regexp.prototype.flags@1.5.2:
|
||||
resolution: {integrity: sha512-NcDiDkTLuPR+++OCKB0nWafEmhg/Da8aUPLPMQbK+bxKKCm1/S5he+AqYa4PlMCVBalb4/yxIRub6qkEx5yJbw==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.7
|
||||
define-properties: 1.2.1
|
||||
es-errors: 1.3.0
|
||||
set-function-name: 2.0.2
|
||||
dev: true
|
||||
|
||||
/regjsparser@0.10.0:
|
||||
resolution: {integrity: sha512-qx+xQGZVsy55CH0a1hiVwHmqjLryfh7wQyF5HO07XJ9f7dQMY/gPQHhlyDkIzJKC+x2fUCpCcUODUUUFrm7SHA==}
|
||||
hasBin: true
|
||||
@@ -3331,6 +3561,15 @@ packages:
|
||||
is-regex: 1.1.4
|
||||
dev: true
|
||||
|
||||
/safe-regex-test@1.0.3:
|
||||
resolution: {integrity: sha512-CdASjNJPvRa7roO6Ra/gLYBTzYzzPyyBXxIMdGW3USQLyjWEls2RgW5UBTXaQVp+OrpeCK3bLem8smtmheoRuw==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.7
|
||||
es-errors: 1.3.0
|
||||
is-regex: 1.1.4
|
||||
dev: true
|
||||
|
||||
/safe-regex@2.1.1:
|
||||
resolution: {integrity: sha512-rx+x8AMzKb5Q5lQ95Zoi6ZbJqwCLkqi3XuJXp5P3rT8OEc6sZCJG5AE5dU3lsgRr/F4Bs31jSlVN+j5KrsGu9A==}
|
||||
dependencies:
|
||||
@@ -3374,6 +3613,18 @@ packages:
|
||||
has-property-descriptors: 1.0.1
|
||||
dev: true
|
||||
|
||||
/set-function-length@1.2.1:
|
||||
resolution: {integrity: sha512-j4t6ccc+VsKwYHso+kElc5neZpjtq9EnRICFZtWyBsLojhmeF/ZBd/elqm22WJh/BziDe/SBiOeAt0m2mfLD0g==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
define-data-property: 1.1.4
|
||||
es-errors: 1.3.0
|
||||
function-bind: 1.1.2
|
||||
get-intrinsic: 1.2.4
|
||||
gopd: 1.0.1
|
||||
has-property-descriptors: 1.0.2
|
||||
dev: true
|
||||
|
||||
/set-function-name@2.0.1:
|
||||
resolution: {integrity: sha512-tMNCiqYVkXIZgc2Hnoy2IvC/f8ezc5koaRFkCjrpWzGpCd3qbZXPzVy9MAZzK1ch/X0jvSkojys3oqJN0qCmdA==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@@ -3383,6 +3634,16 @@ packages:
|
||||
has-property-descriptors: 1.0.1
|
||||
dev: true
|
||||
|
||||
/set-function-name@2.0.2:
|
||||
resolution: {integrity: sha512-7PGFlmtwsEADb0WYyvCMa1t+yke6daIG4Wirafur5kcf+MhUnPms1UeR0CKQdTZD81yESwMHbtn+TR+dMviakQ==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
define-data-property: 1.1.4
|
||||
es-errors: 1.3.0
|
||||
functions-have-names: 1.2.3
|
||||
has-property-descriptors: 1.0.2
|
||||
dev: true
|
||||
|
||||
/shebang-command@1.2.0:
|
||||
resolution: {integrity: sha512-EV3L1+UQWGor21OmnvojK36mhg+TyIKDh3iFBKBohr5xeXIhNBcx8oWdgkTEEQ+BEFFYdLRuqMfd5L84N1V5Vg==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
@@ -3415,6 +3676,16 @@ packages:
|
||||
object-inspect: 1.13.1
|
||||
dev: true
|
||||
|
||||
/side-channel@1.0.5:
|
||||
resolution: {integrity: sha512-QcgiIWV4WV7qWExbN5llt6frQB/lBven9pqliLXfGPB+K9ZYXxDozp0wLkHS24kWCm+6YXH/f0HhnObZnZOBnQ==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.7
|
||||
es-errors: 1.3.0
|
||||
get-intrinsic: 1.2.4
|
||||
object-inspect: 1.13.1
|
||||
dev: true
|
||||
|
||||
/siginfo@2.0.0:
|
||||
resolution: {integrity: sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==}
|
||||
dev: true
|
||||
@@ -3727,6 +3998,15 @@ packages:
|
||||
is-typed-array: 1.1.12
|
||||
dev: true
|
||||
|
||||
/typed-array-buffer@1.0.2:
|
||||
resolution: {integrity: sha512-gEymJYKZtKXzzBzM4jqa9w6Q1Jjm7x2d+sh19AdsD4wqnMPDYyvwpsIc2Q/835kHuo3BEQ7CjelGhfTsoBb2MQ==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.7
|
||||
es-errors: 1.3.0
|
||||
is-typed-array: 1.1.13
|
||||
dev: true
|
||||
|
||||
/typed-array-byte-length@1.0.0:
|
||||
resolution: {integrity: sha512-Or/+kvLxNpeQ9DtSydonMxCx+9ZXOswtwJn17SNLvhptaXYDJvkFFP5zbfU/uLmvnBJlI4yrnXRxpdWH/M5tNA==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@@ -3737,6 +4017,17 @@ packages:
|
||||
is-typed-array: 1.1.12
|
||||
dev: true
|
||||
|
||||
/typed-array-byte-length@1.0.1:
|
||||
resolution: {integrity: sha512-3iMJ9q0ao7WE9tWcaYKIptkNBuOIcZCCT0d4MRvuuH88fEoEH62IuQe0OtraD3ebQEoTRk8XCBoknUNc1Y67pw==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.7
|
||||
for-each: 0.3.3
|
||||
gopd: 1.0.1
|
||||
has-proto: 1.0.3
|
||||
is-typed-array: 1.1.13
|
||||
dev: true
|
||||
|
||||
/typed-array-byte-offset@1.0.0:
|
||||
resolution: {integrity: sha512-RD97prjEt9EL8YgAgpOkf3O4IF9lhJFr9g0htQkm0rchFp/Vx7LW5Q8fSXXub7BXAODyUQohRMyOc3faCPd0hg==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@@ -3748,6 +4039,18 @@ packages:
|
||||
is-typed-array: 1.1.12
|
||||
dev: true
|
||||
|
||||
/typed-array-byte-offset@1.0.2:
|
||||
resolution: {integrity: sha512-Ous0vodHa56FviZucS2E63zkgtgrACj7omjwd/8lTEMEPFFyjfixMZ1ZXenpgCFBBt4EC1J2XsyVS2gkG0eTFA==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
available-typed-arrays: 1.0.7
|
||||
call-bind: 1.0.7
|
||||
for-each: 0.3.3
|
||||
gopd: 1.0.1
|
||||
has-proto: 1.0.3
|
||||
is-typed-array: 1.1.13
|
||||
dev: true
|
||||
|
||||
/typed-array-length@1.0.4:
|
||||
resolution: {integrity: sha512-KjZypGq+I/H7HI5HlOoGHkWUUGq+Q0TPhQurLbyrVrvnKTBgzLhIJ7j6J/XTQOi0d1RjyZ0wdas8bKs2p0x3Ng==}
|
||||
dependencies:
|
||||
@@ -3756,6 +4059,18 @@ packages:
|
||||
is-typed-array: 1.1.12
|
||||
dev: true
|
||||
|
||||
/typed-array-length@1.0.5:
|
||||
resolution: {integrity: sha512-yMi0PlwuznKHxKmcpoOdeLwxBoVPkqZxd7q2FgMkmD3bNwvF5VW0+UlUQ1k1vmktTu4Yu13Q0RIxEP8+B+wloA==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
call-bind: 1.0.7
|
||||
for-each: 0.3.3
|
||||
gopd: 1.0.1
|
||||
has-proto: 1.0.3
|
||||
is-typed-array: 1.1.13
|
||||
possible-typed-array-names: 1.0.0
|
||||
dev: true
|
||||
|
||||
/typescript@5.3.3:
|
||||
resolution: {integrity: sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==}
|
||||
engines: {node: '>=14.17'}
|
||||
@@ -3955,6 +4270,17 @@ packages:
|
||||
has-tostringtag: 1.0.0
|
||||
dev: true
|
||||
|
||||
/which-typed-array@1.1.14:
|
||||
resolution: {integrity: sha512-VnXFiIW8yNn9kIHN88xvZ4yOWchftKDsRJ8fEPacX/wl1lOvBrhsJ/OeJCXq7B0AaijRuqgzSKalJoPk+D8MPg==}
|
||||
engines: {node: '>= 0.4'}
|
||||
dependencies:
|
||||
available-typed-arrays: 1.0.7
|
||||
call-bind: 1.0.7
|
||||
for-each: 0.3.3
|
||||
gopd: 1.0.1
|
||||
has-tostringtag: 1.0.2
|
||||
dev: true
|
||||
|
||||
/which@1.3.1:
|
||||
resolution: {integrity: sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==}
|
||||
hasBin: true
|
||||
|
||||
3
src/index.d.ts
vendored
Normal file
3
src/index.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
export * from './try.d.ts';
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/*
|
||||
* Placeholder file
|
||||
*/
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Hello, world!');
|
||||
|
||||
export * from './try.js';
|
||||
|
||||
|
||||
94
src/try.d.ts
vendored
Normal file
94
src/try.d.ts
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
|
||||
/**
|
||||
* The WrappedResult type returned by the wrapped function in {@link trySync}
|
||||
* and {@link tryAsync}.
|
||||
*
|
||||
* **If a error occurred, the result is undefined**.
|
||||
* If there's not a error, error will be null and the result will be defined.
|
||||
*/
|
||||
type WrappedResult<R> = [R, null] | [undefined, Error];
|
||||
|
||||
/**
|
||||
* The returned function from {@link tryAsync}.
|
||||
*
|
||||
* @param args - The arguments of the function.
|
||||
* - The arguments of the wrapped function.
|
||||
* @returns
|
||||
* - The final tuple containing the Error object (if one occured) and the resulting value.
|
||||
*/
|
||||
type WrappedAsyncFunction<F> = (...args: Parameters<F>) =>
|
||||
Promise<WrappedResult<Awaited<ReturnType<F>>>>;
|
||||
|
||||
/**
|
||||
* Function-sugar/Syntax-sugar for handling functions that can throw errors. Wrapping then
|
||||
* into a try-catch block / "curried function" that returns a "tuple as array" of error and
|
||||
* value, which can be used for handling the error using a Go-like fashion. **This function
|
||||
* is for asynchronous operations,** for synchronous ones, see {@link trySync}.
|
||||
*
|
||||
* **If there's a error, the result is undefined**.
|
||||
* If there's not a error, error will be null and the result will be defined.
|
||||
*
|
||||
* @param func
|
||||
* - The function to be executed.
|
||||
* @returns
|
||||
* - The function to be immediately called with the wrapped function's arguments.
|
||||
* @example
|
||||
* const [error, res] = await tryAsync(fetch)("https://example.com");
|
||||
* if (error !== null) {
|
||||
* // error handling...
|
||||
* console.log(error);
|
||||
* }
|
||||
* // continue the logic...
|
||||
*/
|
||||
function tryAsync<
|
||||
F extends (...args: Parameters<F>) => (ReturnType<F> extends Promise
|
||||
? ReturnType<F>
|
||||
: Promise<ReturnType<F>>
|
||||
),
|
||||
>(func: F): WrappedAsyncFunction<F>;
|
||||
|
||||
/**
|
||||
* The returned function from {@link trySync}.
|
||||
*
|
||||
* @param args
|
||||
* - The arguments of the wrapped function.
|
||||
* @returns
|
||||
* - The final tuple containing the Error object (if one occured) and the resulting value.
|
||||
*/
|
||||
type WrappedFunction<F> = (...args: Parameters<F>) =>
|
||||
WrappedResult<ReturnType<F>>;
|
||||
|
||||
/**
|
||||
* Function-sugar/Syntax-sugar for handling functions that can throw errors. Wrapping then
|
||||
* into a try-catch block / "curried function" that returns a "tuple as array" of error and
|
||||
* value, which can be used for handling the error using a Go-like fashion. **This function
|
||||
* is for synchronous operations,** for asynchronous ones, see {@link tryAsync}.
|
||||
*
|
||||
* **If there's a error, the result is undefined**.
|
||||
* If there's not a error, error will be null and the result will be defined.
|
||||
*
|
||||
* @param func
|
||||
* - The function to be executed.
|
||||
* @returns
|
||||
* - The function to be immediately called with the wrapped function's arguments.
|
||||
* @example
|
||||
* const [error, json] = trySync(JSON.parse)('{ "hello": "world" }');
|
||||
* if (error !== null) {
|
||||
* // error handling...
|
||||
* console.log(error);
|
||||
* }
|
||||
* // continue the logic...
|
||||
*/
|
||||
function trySync<
|
||||
F extends (...args: Parameters<F>) => ReturnType<F>,
|
||||
>(func: F): WrappedFunction<F>;
|
||||
|
||||
export {
|
||||
type WrappedAsyncFunction,
|
||||
type WrappedFunction,
|
||||
type WrappedResult,
|
||||
tryAsync as tryA,
|
||||
tryAsync,
|
||||
trySync as tryS,
|
||||
trySync,
|
||||
};
|
||||
133
src/try.js
Normal file
133
src/try.js
Normal file
@@ -0,0 +1,133 @@
|
||||
/* eslint-disable no-secrets/no-secrets */
|
||||
|
||||
/**
|
||||
* The WrappedResult type returned by the wrapped function in {@link trySync}
|
||||
* and {@link tryAsync}.
|
||||
*
|
||||
* **If a error occurred, the result is undefined**.
|
||||
* If there's not a error, error will be null and the result will be defined.
|
||||
*
|
||||
* @typedef {[R, null] | [undefined, Error]} WrappedResult<R>
|
||||
* @template R
|
||||
*/
|
||||
|
||||
/**
|
||||
* The returned function from {@link tryAsync}.
|
||||
*
|
||||
* @typedef {(...args: Parameters<F>) => Promise<WrappedResult<Awaited<ReturnType<F>>>>}
|
||||
* WrappedAsyncFunction
|
||||
* @template {(...args: Parameters<F>) => ReturnType<F>} F
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function-sugar/Syntax-sugar for handling functions that can throw errors. Wrapping then
|
||||
* into a try-catch block / "curried function" that returns a "tuple as array" of error and
|
||||
* value, which can be used for handling the error using a Go-like fashion. **This function
|
||||
* is for asynchronous operations,** for synchronous ones, see {@link trySync}.
|
||||
*
|
||||
* **If there's a error, the result is undefined**.
|
||||
* If there's not a error, error will be null and the result will be defined.
|
||||
*
|
||||
* @template {(...args: Parameters<F>) => Promise<Awaited<ReturnType<F>>>} F
|
||||
* @param {F} func
|
||||
* - The function to be executed.
|
||||
* @returns {WrappedAsyncFunction<F>}
|
||||
* - The function to be immediately called with the wrapped function's arguments.
|
||||
* @example
|
||||
* const [error, res] = await tryAsync(fetch)("https://example.com");
|
||||
* if (error !== null) {
|
||||
* // error handling...
|
||||
* console.log(error);
|
||||
* }
|
||||
* // continue the logic...
|
||||
*/
|
||||
function tryAsync(func) {
|
||||
/**
|
||||
* The returned function from {@link tryAsync}.
|
||||
*
|
||||
* @param {Parameters<F>} args - The arguments of the function.
|
||||
* - The arguments of the wrapped function.
|
||||
* @returns {Promise<WrappedResult<Awaited<ReturnType<F>>>>}
|
||||
* - The final tuple containing the Error object (if one occured) and the resulting value.
|
||||
*/
|
||||
return async (...args) => {
|
||||
try {
|
||||
return [await func(...args), null];
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error) return [undefined, error];
|
||||
|
||||
const errObj = new Error(error?.toString
|
||||
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
||||
? `Stringified error to: ${error.toString()}`
|
||||
: 'Could not stringify error',
|
||||
{ cause: { value: error } });
|
||||
|
||||
return [undefined, errObj];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The returned function from {@link trySync}.
|
||||
*
|
||||
* @typedef {(...args: Parameters<F>) => WrappedResult<ReturnType<F>>} WrappedFunction
|
||||
* @template {(...args: Parameters<F>) => ReturnType<F>} F
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function-sugar/Syntax-sugar for handling functions that can throw errors. Wrapping then
|
||||
* into a try-catch block / "curried function" that returns a "tuple as array" of error and
|
||||
* value, which can be used for handling the error using a Go-like fashion. **This function
|
||||
* is for synchronous operations,** for asynchronous ones, see {@link tryAsync}.
|
||||
*
|
||||
* **If there's a error, the result is undefined**.
|
||||
* If there's not a error, error will be null and the result will be defined.
|
||||
*
|
||||
* @template {(...args: Parameters<F>) => ReturnType<F>} F
|
||||
* @param {F} func
|
||||
* - The function to be executed.
|
||||
* @returns {WrappedFunction<F>}
|
||||
* - The function to be immediately called with the wrapped function's arguments.
|
||||
* @example
|
||||
* const [error, json] = trySync(JSON.parse)('{ "hello": "world" }');
|
||||
* if (error !== null) {
|
||||
* // error handling...
|
||||
* console.log(error);
|
||||
* }
|
||||
* // continue the logic...
|
||||
*/
|
||||
function trySync(func) {
|
||||
/**
|
||||
* The returned function from {@link trySync}.
|
||||
*
|
||||
* @param {Parameters<F>} args
|
||||
* - The arguments of the wrapped function.
|
||||
* @returns {WrappedResult<ReturnType<F>>}
|
||||
* - The final tuple containing the Error object (if one occured) and the resulting value.
|
||||
*/
|
||||
return (...args) => {
|
||||
try {
|
||||
return [func(...args), null];
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error) return [undefined, error];
|
||||
|
||||
const errObj = new Error(error?.toString
|
||||
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
||||
? `Stringified error to: ${error.toString()}`
|
||||
: 'Could not stringify error',
|
||||
{ cause: { value: error } });
|
||||
|
||||
return [undefined, errObj];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export {
|
||||
tryAsync as tryA,
|
||||
tryAsync,
|
||||
trySync as tryS,
|
||||
trySync,
|
||||
};
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
// eslint-disable-next-line n/no-unpublished-import
|
||||
import { expect, test } from 'vitest';
|
||||
|
||||
test('placeholder', () => {
|
||||
expect(1).toBe(1);
|
||||
});
|
||||
|
||||
35
test/try.test.js
Normal file
35
test/try.test.js
Normal file
@@ -0,0 +1,35 @@
|
||||
/* eslint-disable import/no-relative-parent-imports */
|
||||
// eslint-disable-next-line n/no-unpublished-import
|
||||
import { describe, it } from 'vitest';
|
||||
|
||||
import { tryA, tryS } from '../src/index.js';
|
||||
|
||||
describe.concurrent('Return values', () => {
|
||||
it('JSON parsing [Sync, Success]', ({ expect }) => {
|
||||
const [json, error] = tryS(JSON.parse)('{ "hello": "world" }');
|
||||
|
||||
expect(error).toBe(null);
|
||||
expect(json).toEqual({ hello: 'world' });
|
||||
});
|
||||
it('JSON parsing [Sync, Error]', ({ expect }) => {
|
||||
const [json, error] = tryS(JSON.parse)('{ "hello: "world" }');
|
||||
|
||||
expect(error?.name).toEqual('SyntaxError');
|
||||
expect(error).toBeInstanceOf(Error);
|
||||
expect(json).toBe(undefined);
|
||||
});
|
||||
it('Fetch function [Async, Success]', async ({ expect }) => {
|
||||
const [res, error] = await tryA(fetch)('https://example.com');
|
||||
|
||||
expect(error).toBe(null);
|
||||
expect(res?.status).toBe(200);
|
||||
});
|
||||
it('Fetch function [Async, Error]', async ({ expect }) => {
|
||||
const [res, error] = await tryA(fetch)('htps://example.com');
|
||||
|
||||
expect(error?.name).toEqual('TypeError');
|
||||
expect(error).toBeInstanceOf(Error);
|
||||
expect(res).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user