@teaui/result 1.17.16

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.
@@ -0,0 +1,11 @@
1
+ export type Ok<T> = {
2
+ readonly ok: true;
3
+ readonly value: T;
4
+ };
5
+ export type Err<E> = {
6
+ readonly ok: false;
7
+ readonly error: E;
8
+ };
9
+ export type Result<T, E = Error> = Ok<T> | Err<E>;
10
+ export declare function ok<T>(value: T): Ok<T>;
11
+ export declare function err<E>(error: E): Err<E>;
package/.dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export function ok(value) {
2
+ return { ok: true, value };
3
+ }
4
+ export function err(error) {
5
+ return { ok: false, error };
6
+ }
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,EAAE,CAAI,KAAQ;IAC5B,OAAO,EAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAC,CAAA;AAC1B,CAAC;AAED,MAAM,UAAU,GAAG,CAAI,KAAQ;IAC7B,OAAO,EAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAC,CAAA;AAC3B,CAAC"}
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ TeaUI
2
+ Copyright (c) 2023, Colin T.A. Gray
3
+ https://github.com/colinta/teaui
4
+
5
+ With code from multiple sources
6
+ see https://github.com/colinta/teaui/blob/master/packages/core/LICENSE
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # @teaui/result
2
+
3
+ Dependency-free Result types and constructors. Independent of TeaUI rendering and networking.
4
+
5
+ ```ts
6
+ import {ok, err, type Result} from '@teaui/result'
7
+
8
+ function parsePort(value: string): Result<number, string> {
9
+ const port = Number(value)
10
+ return Number.isInteger(port) && port >= 0 && port <= 65535
11
+ ? ok(port)
12
+ : err('Invalid port')
13
+ }
14
+
15
+ const result = parsePort('9123')
16
+ if (result.ok) {
17
+ console.log(result.value)
18
+ } else {
19
+ console.error(result.error)
20
+ }
21
+ ```
22
+
23
+ Exports `Result<T, E = Error>`, `Ok<T>`, `Err<E>`, `ok(value)`, and `err(error)`.
24
+ The error type need not extend `Error`. Results are plain discriminated unions,
25
+ not wrapper classes.
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@teaui/result",
3
+ "description": "Dependency-free Result types and constructors",
4
+ "author": "Colin T.A. Gray <colinta@colinta.com>",
5
+ "version": "1.17.16",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/colinta/teaui"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "types": "./.dist/index.d.ts",
15
+ "import": "./.dist/index.js",
16
+ "default": "./.dist/index.js"
17
+ }
18
+ },
19
+ "main": ".dist/index.js",
20
+ "types": ".dist/index.d.ts",
21
+ "files": [
22
+ ".dist/"
23
+ ],
24
+ "devDependencies": {
25
+ "@teaui/shared": "1.18.16"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "scripts": {
31
+ "clean": "rm -rf .dist/",
32
+ "_build": "pnpm clean && pnpm tsc",
33
+ "build": "node ../../shared/check.js",
34
+ "typecheck": "tsc -p tsconfig.check.json --noEmit",
35
+ "test": "vitest run",
36
+ "test:watch": "vitest"
37
+ }
38
+ }