@terrygonguet/utils 0.0.3 → 0.0.4
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/dist/async.js +6 -0
- package/dist/functional.js +164 -0
- package/dist/main.js +22 -0
- package/package.json +6 -1
- package/index.html +0 -13
- package/tsconfig.json +0 -25
- package/vite.config.js +0 -15
package/dist/async.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
var g = Object.defineProperty;
|
|
2
|
+
var p = (t, e, r) => e in t ? g(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var f = (t, e, r) => (p(t, typeof e != "symbol" ? e + "" : e, r), r);
|
|
4
|
+
const a = "@terrygonguet/utils/functional/maybe", _ = "@terrygonguet/utils/functional/maybe/Some", b = "@terrygonguet/utils/functional/maybe/None";
|
|
5
|
+
function i(t) {
|
|
6
|
+
return Object.create(
|
|
7
|
+
{
|
|
8
|
+
isSome: () => !0,
|
|
9
|
+
isNone: () => !1,
|
|
10
|
+
orDefault() {
|
|
11
|
+
return this.value;
|
|
12
|
+
},
|
|
13
|
+
map(e) {
|
|
14
|
+
return i(e(this.value));
|
|
15
|
+
},
|
|
16
|
+
flatMap(e) {
|
|
17
|
+
return e(this.value);
|
|
18
|
+
},
|
|
19
|
+
toJSON() {
|
|
20
|
+
return { $_kind: a, $_variant: _, value: this.value };
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
$_kind: { value: a, enumerable: !1, writable: !1 },
|
|
25
|
+
$_variant: { value: _, enumerable: !1, writable: !1 },
|
|
26
|
+
value: { value: t, writable: !1 }
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
const n = Object.create(
|
|
31
|
+
{
|
|
32
|
+
isSome: () => !1,
|
|
33
|
+
isNone: () => !0,
|
|
34
|
+
orDefault: $,
|
|
35
|
+
map: () => n,
|
|
36
|
+
flatMap: () => n,
|
|
37
|
+
toJSON: () => ({ $_kind: a, $_variant: b })
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
$_kind: { value: a, enumerable: !1, writable: !1 },
|
|
41
|
+
$_variant: { value: b, enumerable: !1, writable: !1 }
|
|
42
|
+
}
|
|
43
|
+
), k = {
|
|
44
|
+
Some: i,
|
|
45
|
+
None: n,
|
|
46
|
+
from(t) {
|
|
47
|
+
switch (t) {
|
|
48
|
+
case null:
|
|
49
|
+
case void 0:
|
|
50
|
+
return n;
|
|
51
|
+
default:
|
|
52
|
+
return i(t);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
JSONReviver(t, e) {
|
|
56
|
+
if ((e == null ? void 0 : e.$_kind) == a) {
|
|
57
|
+
const r = e == null ? void 0 : e.$_variant;
|
|
58
|
+
return r == _ ? i(e == null ? void 0 : e.value) : r == b ? n : e;
|
|
59
|
+
} else
|
|
60
|
+
return e;
|
|
61
|
+
}
|
|
62
|
+
}, s = "@terrygonguet/utils/functional/result", u = "@terrygonguet/utils/functional/result/Success", m = "@terrygonguet/utils/functional/result/Failure";
|
|
63
|
+
function l(t) {
|
|
64
|
+
return Object.create(
|
|
65
|
+
{
|
|
66
|
+
isSuccess: () => !0,
|
|
67
|
+
isFailure: () => !1,
|
|
68
|
+
map(e) {
|
|
69
|
+
return l(e(this.value));
|
|
70
|
+
},
|
|
71
|
+
flatMap(e) {
|
|
72
|
+
return e(this.value);
|
|
73
|
+
},
|
|
74
|
+
toJSON() {
|
|
75
|
+
return { $_kind: s, $_variant: u, value: this.value };
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
$_kind: { value: s, enumerable: !1, writable: !1 },
|
|
80
|
+
$_variant: { value: u, enumerable: !1, writable: !1 },
|
|
81
|
+
value: { value: t, writable: !1 }
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
function h(t) {
|
|
86
|
+
return Object.create(
|
|
87
|
+
{
|
|
88
|
+
isSuccess: () => !1,
|
|
89
|
+
isFailure: () => !0,
|
|
90
|
+
map() {
|
|
91
|
+
return this;
|
|
92
|
+
},
|
|
93
|
+
flatMap() {
|
|
94
|
+
return this;
|
|
95
|
+
},
|
|
96
|
+
toJSON() {
|
|
97
|
+
return { $_kind: s, $_variant: m, reason: this.reason };
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
$_kind: { value: s, enumerable: !1, writable: !1 },
|
|
102
|
+
$_variant: { value: u, enumerable: !1, writable: !1 },
|
|
103
|
+
reason: { value: t, writable: !1 }
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
const F = {
|
|
108
|
+
Success: l,
|
|
109
|
+
Failure: h,
|
|
110
|
+
try(t) {
|
|
111
|
+
return new S(t);
|
|
112
|
+
},
|
|
113
|
+
JSONReviver(t, e) {
|
|
114
|
+
if ((e == null ? void 0 : e.$_kind) == s) {
|
|
115
|
+
const r = e == null ? void 0 : e.$_variant;
|
|
116
|
+
return r == u ? l(e == null ? void 0 : e.value) : r == m ? h(e == null ? void 0 : e.reason) : e;
|
|
117
|
+
} else
|
|
118
|
+
return e;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
class S {
|
|
122
|
+
constructor(e) {
|
|
123
|
+
f(this, "tryFn");
|
|
124
|
+
f(this, "catchFn");
|
|
125
|
+
this.tryFn = e, this.catchFn = $;
|
|
126
|
+
}
|
|
127
|
+
catch(e) {
|
|
128
|
+
return this.catchFn = e, this;
|
|
129
|
+
}
|
|
130
|
+
exec() {
|
|
131
|
+
try {
|
|
132
|
+
return l(this.tryFn());
|
|
133
|
+
} catch (e) {
|
|
134
|
+
return h(this.catchFn(e));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
var N = d;
|
|
139
|
+
function d(t, e) {
|
|
140
|
+
if (!arguments.length)
|
|
141
|
+
throw new Error(
|
|
142
|
+
"expected at least one (and probably more) function arguments"
|
|
143
|
+
);
|
|
144
|
+
var r = arguments;
|
|
145
|
+
return function() {
|
|
146
|
+
for (var o = r[0].apply(this, arguments), y = r.length, c = 1; c < y; c++)
|
|
147
|
+
o = r[c].call(this, o);
|
|
148
|
+
return o;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function $(t) {
|
|
152
|
+
return t;
|
|
153
|
+
}
|
|
154
|
+
export {
|
|
155
|
+
h as Failure,
|
|
156
|
+
k as Maybe,
|
|
157
|
+
n as None,
|
|
158
|
+
F as Result,
|
|
159
|
+
i as Some,
|
|
160
|
+
l as Success,
|
|
161
|
+
S as TryCatch,
|
|
162
|
+
N as compose,
|
|
163
|
+
$ as identity
|
|
164
|
+
};
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function o(n, t, r) {
|
|
2
|
+
return Math.min(Math.max(n, t), r);
|
|
3
|
+
}
|
|
4
|
+
function c(n, t, r) {
|
|
5
|
+
try {
|
|
6
|
+
return JSON.parse(n, r);
|
|
7
|
+
} catch {
|
|
8
|
+
return t;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function f(...n) {
|
|
12
|
+
return function(t, r) {
|
|
13
|
+
for (const e of n)
|
|
14
|
+
r = e(t, r);
|
|
15
|
+
return r;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
o as clamp,
|
|
20
|
+
f as composeJSONRevivers,
|
|
21
|
+
c as safeParse
|
|
22
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrygonguet/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite",
|
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
"vite": "^4.3.9",
|
|
16
16
|
"vitest": "^0.32.0"
|
|
17
17
|
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/**/*.js",
|
|
20
|
+
"src/**/!(*.test).ts",
|
|
21
|
+
"types/**/!(*.test).d.ts"
|
|
22
|
+
],
|
|
18
23
|
"exports": {
|
|
19
24
|
".": {
|
|
20
25
|
"types": "./types/main.js",
|
package/index.html
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<title>Vite + TS</title>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div id="app"></div>
|
|
11
|
-
<script type="module" src="/src/main.ts"></script>
|
|
12
|
-
</body>
|
|
13
|
-
</html>
|
package/tsconfig.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"useDefineForClassFields": true,
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
7
|
-
"skipLibCheck": true,
|
|
8
|
-
|
|
9
|
-
/* Bundler mode */
|
|
10
|
-
"moduleResolution": "node16",
|
|
11
|
-
"allowImportingTsExtensions": true,
|
|
12
|
-
"allowSyntheticDefaultImports": true,
|
|
13
|
-
"resolveJsonModule": true,
|
|
14
|
-
"isolatedModules": true,
|
|
15
|
-
"declaration": true,
|
|
16
|
-
"emitDeclarationOnly": true,
|
|
17
|
-
"outDir": "./types",
|
|
18
|
-
|
|
19
|
-
/* Linting */
|
|
20
|
-
"strict": true,
|
|
21
|
-
"noUnusedLocals": true,
|
|
22
|
-
"noUnusedParameters": true
|
|
23
|
-
},
|
|
24
|
-
"include": ["src"]
|
|
25
|
-
}
|
package/vite.config.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { resolve } from "path"
|
|
2
|
-
import { defineConfig } from "vite"
|
|
3
|
-
|
|
4
|
-
export default defineConfig({
|
|
5
|
-
build: {
|
|
6
|
-
lib: {
|
|
7
|
-
formats: ["es"],
|
|
8
|
-
entry: {
|
|
9
|
-
main: resolve(__dirname, "src/main.ts"),
|
|
10
|
-
async: resolve(__dirname, "src/async.ts"),
|
|
11
|
-
functional: resolve(__dirname, "src/functional/index.ts"),
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
})
|