@tempots/std 0.9.2 → 0.9.5

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.
Files changed (82) hide show
  1. package/README.md +3 -0
  2. package/package.json +2 -2
  3. package/dist/arrays.d.ts +0 -49
  4. package/dist/arrays.js +0 -249
  5. package/dist/async-result.d.ts +0 -37
  6. package/dist/async-result.js +0 -75
  7. package/dist/bigint.d.ts +0 -18
  8. package/dist/bigint.js +0 -110
  9. package/dist/booleans.d.ts +0 -23
  10. package/dist/booleans.js +0 -68
  11. package/dist/colors/cmyk.d.ts +0 -21
  12. package/dist/colors/cmyk.js +0 -54
  13. package/dist/colors/convert.d.ts +0 -283
  14. package/dist/colors/convert.js +0 -742
  15. package/dist/colors/hsl.d.ts +0 -24
  16. package/dist/colors/hsl.js +0 -56
  17. package/dist/colors/hsla.d.ts +0 -18
  18. package/dist/colors/hsla.js +0 -35
  19. package/dist/colors/hsluv.d.ts +0 -24
  20. package/dist/colors/hsluv.js +0 -56
  21. package/dist/colors/hsv.d.ts +0 -24
  22. package/dist/colors/hsv.js +0 -54
  23. package/dist/colors/lab.d.ts +0 -24
  24. package/dist/colors/lab.js +0 -54
  25. package/dist/colors/lch.d.ts +0 -19
  26. package/dist/colors/lch.js +0 -44
  27. package/dist/colors/luv.d.ts +0 -19
  28. package/dist/colors/luv.js +0 -45
  29. package/dist/colors/rgb.d.ts +0 -13
  30. package/dist/colors/rgb.js +0 -47
  31. package/dist/colors/rgba.d.ts +0 -12
  32. package/dist/colors/rgba.js +0 -44
  33. package/dist/colors/srgb.d.ts +0 -24
  34. package/dist/colors/srgb.js +0 -51
  35. package/dist/colors/xyz.d.ts +0 -19
  36. package/dist/colors/xyz.js +0 -41
  37. package/dist/edit.d.ts +0 -20
  38. package/dist/edit.js +0 -29
  39. package/dist/equals.d.ts +0 -3
  40. package/dist/equals.js +0 -122
  41. package/dist/functions.d.ts +0 -20
  42. package/dist/functions.js +0 -38
  43. package/dist/json.d.ts +0 -14
  44. package/dist/json.js +0 -33
  45. package/dist/match.d.ts +0 -16
  46. package/dist/match.js +0 -45
  47. package/dist/maybe.d.ts +0 -9
  48. package/dist/maybe.js +0 -25
  49. package/dist/memoize.d.ts +0 -1
  50. package/dist/memoize.js +0 -9
  51. package/dist/newtype.d.ts +0 -28
  52. package/dist/newtype.js +0 -29
  53. package/dist/numbers.d.ts +0 -104
  54. package/dist/numbers.js +0 -183
  55. package/dist/objects.d.ts +0 -9
  56. package/dist/objects.js +0 -33
  57. package/dist/ord.d.ts +0 -19
  58. package/dist/ord.js +0 -73
  59. package/dist/reg-exps.d.ts +0 -10
  60. package/dist/reg-exps.js +0 -43
  61. package/dist/result.d.ts +0 -31
  62. package/dist/result.js +0 -95
  63. package/dist/strings.d.ts +0 -314
  64. package/dist/strings.js +0 -685
  65. package/dist/types/assert.d.ts +0 -12
  66. package/dist/types/assert.js +0 -13
  67. package/dist/types/differentiate.d.ts +0 -13
  68. package/dist/types/differentiate.js +0 -14
  69. package/dist/types/functions.d.ts +0 -22
  70. package/dist/types/functions.js +0 -13
  71. package/dist/types/generic.d.ts +0 -9
  72. package/dist/types/generic.js +0 -13
  73. package/dist/types/objects.d.ts +0 -50
  74. package/dist/types/objects.js +0 -13
  75. package/dist/types/tuples.d.ts +0 -44
  76. package/dist/types/tuples.js +0 -24
  77. package/dist/types/utility.d.ts +0 -2
  78. package/dist/types/utility.js +0 -1
  79. package/dist/uuid.d.ts +0 -13
  80. package/dist/uuid.js +0 -56
  81. package/dist/validation.d.ts +0 -23
  82. package/dist/validation.js +0 -44
package/dist/numbers.d.ts DELETED
@@ -1,104 +0,0 @@
1
- export declare const TOLERANCE = 0.0001;
2
- /**
3
- Constant value employed to see if two `number` values are very close.
4
- **/
5
- export declare const EPSILON = 1e-9;
6
- /**
7
- Returns the angular distance between 2 angles.
8
- **/
9
- export declare function angleDifference(a: number, b: number, turn?: number): number;
10
- /**
11
- Rounds a number up to the specified number of decimals.
12
- **/
13
- export declare function ceilTo(v: number, decimals: number): number;
14
- /**
15
- `clamp` restricts a value within the specified range.
16
- ```ts
17
- log(clamp(1.3, 0, 1)) // prints 1
18
- log(clamp(0.8, 0, 1)) // prints 0.8
19
- log(clamp(-0.5, 0, 1)) // prints 0.0
20
- ```
21
- **/
22
- export declare function clamp(value: number, min: number, max: number): number;
23
- export declare function clampInt(value: number, min: number, max: number): number;
24
- /**
25
- Like clamp but you only pass one argument (`max`) that is used as the upper limit
26
- and the opposite (additive inverse or `-max`) as the lower limit.
27
- **/
28
- export declare function clampSym(v: number, max: number): number;
29
- /**
30
- It returns the comparison value (an integer number) between two `float` values.
31
- **/
32
- export declare function compare(a: number, b: number): number;
33
- /**
34
- Rounds a number down to the specified number of decimals.
35
- **/
36
- export declare function floorTo(v: number, decimals: number): number;
37
- /**
38
- `normalize` clamps the passwed value between 0 and 1.
39
- **/
40
- export declare function normalize(value: number): number;
41
- export declare function toHex(num: number, length?: number): string;
42
- /**
43
- `interpolate` returns a value between `a` and `b` for any value of `t` (normally between 0 and 1).
44
- **/
45
- export declare function interpolate(a: number, b: number, t: number): number;
46
- /**
47
- Interpolates values in a polar coordinate system looking for the narrowest delta angle.
48
- It can be either clock-wise or counter-clock-wise.
49
- **/
50
- export declare function interpolateAngle(a: number, b: number, t: number, turn?: number): number;
51
- /**
52
- Interpolates values in a polar coordinate system looking for the wideset delta angle.
53
- It can be either clock-wise or counter-clock-wise.
54
- **/
55
- export declare function interpolateAngleWidest(a: number, b: number, t: number, turn?: number): number;
56
- /**
57
- Interpolates values in a polar coordinate system always in clock-wise direction.
58
- **/
59
- export declare function interpolateAngleCW(a: number, b: number, t: number, turn?: number): number;
60
- /**
61
- Interpolates values in a polar coordinate system always in counter-clock-wise direction.
62
- **/
63
- export declare function interpolateAngleCCW(a: number, b: number, t: number, turn?: number): number;
64
- /**
65
- number numbers can sometime introduce tiny errors even for simple operations.
66
- `nearEquals` compares two floats using a tiny tollerance (last optional
67
- argument). By default it is defined as `EPSILON`.
68
- **/
69
- export declare function nearEquals(a: number, b: number, tollerance?: number): boolean;
70
- /**
71
- number numbers can sometime introduce tiny errors even for simple operations.
72
- `nearEqualAngles` compares two angles (default is 360deg) using a tiny
73
- tollerance (last optional argument). By default the tollerance is defined as
74
- `EPSILON`.
75
- **/
76
- export declare function nearEqualAngles(a: number, b: number, turn?: number, tollerance?: number): boolean;
77
- /**
78
- `nearZero` finds if the passed number is zero or very close to it. By default
79
- `EPSILON` is used as the tollerance value.
80
- **/
81
- export declare function nearZero(n: number, tollerance?: number): boolean;
82
- /**
83
- Computes the nth root (`index`) of `base`.
84
- **/
85
- export declare function root(base: number, index: number): number;
86
- /**
87
- Rounds a number to the specified number of decimals.
88
- **/
89
- export declare function roundTo(f: number, decimals: number): number;
90
- /**
91
- `sign` returns `-1` if `value` is a negative number, `1` otherwise.
92
- */
93
- export declare function sign<T extends number>(value: T): number;
94
- /**
95
- Passed two boundaries values (`min`, `max`), `wrap` ensures that the passed value `v` will
96
- be included in the boundaries. If the value exceeds `max`, the value is reduced by `min`
97
- repeatedely until it falls within the range. Similar and inverted treatment is performed if
98
- the value is below `min`.
99
- **/
100
- export declare function wrap(v: number, min: number, max: number): number;
101
- /**
102
- Similar to `wrap`, it works for numbers between 0 and `max`.
103
- **/
104
- export declare function wrapCircular(v: number, max: number): number;
package/dist/numbers.js DELETED
@@ -1,183 +0,0 @@
1
- import { lpad } from './strings';
2
- export const TOLERANCE = 10e-5;
3
- /**
4
- Constant value employed to see if two `number` values are very close.
5
- **/
6
- export const EPSILON = 1e-9;
7
- /**
8
- Returns the angular distance between 2 angles.
9
- **/
10
- export function angleDifference(a, b, turn = 360.0) {
11
- let r = (b - a) % turn;
12
- if (r < 0)
13
- r += turn;
14
- if (r > turn / 2)
15
- r -= turn;
16
- return r;
17
- }
18
- /**
19
- Rounds a number up to the specified number of decimals.
20
- **/
21
- export function ceilTo(v, decimals) {
22
- const p = Math.pow(10, decimals);
23
- return Math.ceil(v * p) / p;
24
- }
25
- /**
26
- `clamp` restricts a value within the specified range.
27
- ```ts
28
- log(clamp(1.3, 0, 1)) // prints 1
29
- log(clamp(0.8, 0, 1)) // prints 0.8
30
- log(clamp(-0.5, 0, 1)) // prints 0.0
31
- ```
32
- **/
33
- export function clamp(value, min, max) {
34
- return Math.min(Math.max(value, min), max);
35
- }
36
- export function clampInt(value, min, max) {
37
- return Math.trunc(clamp(value, min, max));
38
- }
39
- /**
40
- Like clamp but you only pass one argument (`max`) that is used as the upper limit
41
- and the opposite (additive inverse or `-max`) as the lower limit.
42
- **/
43
- export function clampSym(v, max) {
44
- return clamp(v, -max, max);
45
- }
46
- /**
47
- It returns the comparison value (an integer number) between two `float` values.
48
- **/
49
- export function compare(a, b) {
50
- return a < b ? -1 : a > b ? 1 : 0;
51
- }
52
- /**
53
- Rounds a number down to the specified number of decimals.
54
- **/
55
- export function floorTo(v, decimals) {
56
- const p = Math.pow(10, decimals);
57
- return Math.floor(v * p) / p;
58
- }
59
- /**
60
- `normalize` clamps the passwed value between 0 and 1.
61
- **/
62
- export function normalize(value) {
63
- return clamp(value, 0, 1);
64
- }
65
- export function toHex(num, length = 0) {
66
- return lpad(num.toString(16), '0', length);
67
- }
68
- /**
69
- `interpolate` returns a value between `a` and `b` for any value of `t` (normally between 0 and 1).
70
- **/
71
- export function interpolate(a, b, t) {
72
- return (b - a) * t + a;
73
- }
74
- /**
75
- Interpolates values in a polar coordinate system looking for the narrowest delta angle.
76
- It can be either clock-wise or counter-clock-wise.
77
- **/
78
- export function interpolateAngle(a, b, t, turn = 360.0) {
79
- return wrapCircular(interpolate(a, a + angleDifference(a, b, turn), t), turn);
80
- }
81
- /**
82
- Interpolates values in a polar coordinate system looking for the wideset delta angle.
83
- It can be either clock-wise or counter-clock-wise.
84
- **/
85
- export function interpolateAngleWidest(a, b, t, turn = 360) {
86
- return wrapCircular(interpolateAngle(a, b, t, turn) - turn / 2, turn);
87
- }
88
- /**
89
- Interpolates values in a polar coordinate system always in clock-wise direction.
90
- **/
91
- export function interpolateAngleCW(a, b, t, turn = 360) {
92
- a = wrapCircular(a, turn);
93
- b = wrapCircular(b, turn);
94
- if (b < a)
95
- b += turn;
96
- return wrapCircular(interpolate(a, b, t), turn);
97
- }
98
- /**
99
- Interpolates values in a polar coordinate system always in counter-clock-wise direction.
100
- **/
101
- export function interpolateAngleCCW(a, b, t, turn = 360) {
102
- a = wrapCircular(a, turn);
103
- b = wrapCircular(b, turn);
104
- if (b > a)
105
- b -= turn;
106
- return wrapCircular(interpolate(a, b, t), turn);
107
- }
108
- /**
109
- number numbers can sometime introduce tiny errors even for simple operations.
110
- `nearEquals` compares two floats using a tiny tollerance (last optional
111
- argument). By default it is defined as `EPSILON`.
112
- **/
113
- export function nearEquals(a, b, tollerance = EPSILON) {
114
- if (isFinite(a)) {
115
- if (!isFinite(b))
116
- return false;
117
- return Math.abs(a - b) <= tollerance;
118
- }
119
- if (isNaN(a))
120
- return isNaN(b);
121
- if (isNaN(b))
122
- return false;
123
- if (!isFinite(b))
124
- return (a > 0) === (b > 0);
125
- // a is Infinity and b is finite
126
- return false;
127
- }
128
- /**
129
- number numbers can sometime introduce tiny errors even for simple operations.
130
- `nearEqualAngles` compares two angles (default is 360deg) using a tiny
131
- tollerance (last optional argument). By default the tollerance is defined as
132
- `EPSILON`.
133
- **/
134
- export function nearEqualAngles(a, b, turn = 360.0, tollerance = EPSILON) {
135
- return Math.abs(angleDifference(a, b, turn)) <= tollerance;
136
- }
137
- /**
138
- `nearZero` finds if the passed number is zero or very close to it. By default
139
- `EPSILON` is used as the tollerance value.
140
- **/
141
- export function nearZero(n, tollerance = EPSILON) {
142
- return Math.abs(n) <= tollerance;
143
- }
144
- /**
145
- Computes the nth root (`index`) of `base`.
146
- **/
147
- export function root(base, index) {
148
- return Math.pow(base, 1 / index);
149
- }
150
- /**
151
- Rounds a number to the specified number of decimals.
152
- **/
153
- export function roundTo(f, decimals) {
154
- const p = Math.pow(10, decimals);
155
- return Math.fround(f * p) / p;
156
- }
157
- /**
158
- `sign` returns `-1` if `value` is a negative number, `1` otherwise.
159
- */
160
- export function sign(value) {
161
- return value < 0 ? -1 : 1;
162
- }
163
- /**
164
- Passed two boundaries values (`min`, `max`), `wrap` ensures that the passed value `v` will
165
- be included in the boundaries. If the value exceeds `max`, the value is reduced by `min`
166
- repeatedely until it falls within the range. Similar and inverted treatment is performed if
167
- the value is below `min`.
168
- **/
169
- export function wrap(v, min, max) {
170
- const range = max - min + 1;
171
- if (v < min)
172
- v += range * ((min - v) / range + 1);
173
- return min + ((v - min) % range);
174
- }
175
- /**
176
- Similar to `wrap`, it works for numbers between 0 and `max`.
177
- **/
178
- export function wrapCircular(v, max) {
179
- v = v % max;
180
- if (v < 0)
181
- v += max;
182
- return v;
183
- }
package/dist/objects.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { type TupleToUnion } from './types/tuples';
2
- import { type Merge } from './types/objects';
3
- import { type AnyKey } from './types/utility';
4
- export declare function keys<T extends object>(obj: T): Array<keyof T>;
5
- export declare function sameKeys<T extends object>(a: T, b: T): boolean;
6
- export declare function isObject(obj: unknown): obj is Record<AnyKey, unknown>;
7
- export declare function removeFields<T extends object, F extends Array<keyof T>>(ob: T, ...fields: F): Omit<T, TupleToUnion<F>>;
8
- export declare function merge<A extends Record<AnyKey, unknown>, B extends Record<AnyKey, unknown>>(a: A, b: B): Merge<A, B>;
9
- export declare function isEmpty(obj: object): boolean;
package/dist/objects.js DELETED
@@ -1,33 +0,0 @@
1
- export function keys(obj) {
2
- return Object.keys(obj);
3
- }
4
- export function sameKeys(a, b) {
5
- const ak = keys(a);
6
- const bk = keys(b);
7
- if (ak.length !== bk.length)
8
- return false;
9
- for (const k of ak) {
10
- if (!(k in b))
11
- return false;
12
- }
13
- return true;
14
- }
15
- export function isObject(obj) {
16
- return Object.prototype.toString.call(obj) === '[object Object]';
17
- }
18
- export function removeFields(ob, ...fields) {
19
- const ks = keys(ob);
20
- return ks.reduce((acc, key) => {
21
- if (!fields.includes(key))
22
- acc[key] = ob[key];
23
- return acc;
24
- }, {});
25
- }
26
- export function merge(a, b) {
27
- return Object.assign({}, a, b);
28
- }
29
- export function isEmpty(obj) {
30
- return (obj != null &&
31
- Object.keys(obj).length === 0 &&
32
- Object.getPrototypeOf(obj) === Object.prototype);
33
- }
package/dist/ord.d.ts DELETED
@@ -1,19 +0,0 @@
1
- export declare enum Ordering {
2
- LT = -1,
3
- EQ = 0,
4
- GT = 1
5
- }
6
- export type CompareOrd<T> = (a: T, b: T) => Ordering;
7
- export type Compare<T> = (a: T, b: T) => number;
8
- export declare class Ord<T> {
9
- readonly compare: CompareOrd<T>;
10
- static fromNumberComparison<T>(compare: (a: T, b: T) => number): Ord<T>;
11
- constructor(compare: CompareOrd<T>);
12
- max(a: T, b: T): T;
13
- min(a: T, b: T): T;
14
- equals(a: T, b: T): boolean;
15
- contramap<B>(f: (b: B) => T): Ord<B>;
16
- inverse(): Ord<T>;
17
- numberComparison(a0: T, a1: T): number;
18
- }
19
- export declare function fromNumberComparison<A>(f: (a: A, b: A) => number): (a: A, b: A) => Ordering;
package/dist/ord.js DELETED
@@ -1,73 +0,0 @@
1
- /*
2
- Copyright 2019 Google LLC
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- https://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
- export var Ordering;
14
- (function (Ordering) {
15
- Ordering[Ordering["LT"] = -1] = "LT";
16
- Ordering[Ordering["EQ"] = 0] = "EQ";
17
- Ordering[Ordering["GT"] = 1] = "GT";
18
- })(Ordering || (Ordering = {}));
19
- export class Ord {
20
- compare;
21
- static fromNumberComparison(compare) {
22
- return new Ord(fromNumberComparison(compare));
23
- }
24
- constructor(compare) {
25
- this.compare = compare;
26
- }
27
- max(a, b) {
28
- switch (this.compare(a, b)) {
29
- case Ordering.LT:
30
- case Ordering.EQ:
31
- return a;
32
- case Ordering.GT:
33
- return b;
34
- }
35
- }
36
- min(a, b) {
37
- switch (this.compare(a, b)) {
38
- case Ordering.GT:
39
- case Ordering.EQ:
40
- return a;
41
- case Ordering.LT:
42
- return b;
43
- }
44
- }
45
- equals(a, b) {
46
- switch (this.compare(a, b)) {
47
- case Ordering.EQ:
48
- return true;
49
- default:
50
- return false;
51
- }
52
- }
53
- contramap(f) {
54
- return new Ord((b0, b1) => this.compare(f(b0), f(b1)));
55
- }
56
- inverse() {
57
- return new Ord((a0, a1) => this.compare(a1, a0));
58
- }
59
- numberComparison(a0, a1) {
60
- return this.compare(a0, a1);
61
- }
62
- }
63
- export function fromNumberComparison(f) {
64
- return function compare(a, b) {
65
- const r = f(a, b);
66
- if (r < 0)
67
- return Ordering.LT;
68
- else if (r === 0)
69
- return Ordering.EQ;
70
- else
71
- return Ordering.GT;
72
- };
73
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * Utility module to manipulate `RegExp` instances.
3
- */
4
- /**
5
- * Map the function `f` on each occurance matched by the pattern.
6
- * @param f
7
- * @param pattern
8
- * @param subject
9
- */
10
- export declare function map(subject: string, pattern: RegExp, f: (...s: string[]) => string): string;
package/dist/reg-exps.js DELETED
@@ -1,43 +0,0 @@
1
- /*
2
- Copyright 2019 Google LLC
3
- Licensed under the Apache License, Version 2.0 (the "License")
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- https://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
- /**
14
- * Utility module to manipulate `RegExp` instances.
15
- */
16
- /**
17
- * Map the function `f` on each occurance matched by the pattern.
18
- * @param f
19
- * @param pattern
20
- * @param subject
21
- */
22
- export function map(subject, pattern, f) {
23
- const buff = [];
24
- let pos = 0;
25
- let result;
26
- if (pattern.global) {
27
- pattern.lastIndex = 0;
28
- while ((result = pattern.exec(subject)) !== null) {
29
- buff.push(subject.substring(pos, result.index));
30
- buff.push(f(...result));
31
- pos = result.index + result[0].length;
32
- }
33
- }
34
- else {
35
- while ((result = pattern.exec(subject.substring(pos))) !== null) {
36
- buff.push(subject.substring(pos, pos + result.index));
37
- buff.push(f(...result));
38
- pos += result.index + result[0].length;
39
- }
40
- }
41
- buff.push(subject.substring(pos));
42
- return buff.join('');
43
- }
package/dist/result.d.ts DELETED
@@ -1,31 +0,0 @@
1
- import { type AsyncResult } from './async-result';
2
- export interface Success<V> {
3
- type: 'success';
4
- value: V;
5
- }
6
- export interface Failure<E> {
7
- type: 'failure';
8
- error: E;
9
- }
10
- export type Result<V, E> = Success<V> | Failure<E>;
11
- export type PromiseResult<V, E> = PromiseLike<Result<V, E>>;
12
- export declare const Result: {
13
- success<V>(value: V): Result<V, any>;
14
- failure<E>(error: E): Result<any, E>;
15
- cmap: <V1, V2, E_1>(f: (value: V1) => V2) => (r: Result<V1, E_1>) => Result<V2, E_1>;
16
- map: <V1_1, V2_1, E_2>(r: Result<V1_1, E_2>, f: (value: V1_1) => V2_1) => Result<V2_1, E_2>;
17
- cflatMap: <V1_2, V2_2, E_3>(f: (value: V1_2) => Result<V2_2, E_3>) => (r: Result<V1_2, E_3>) => Result<V2_2, E_3>;
18
- flatMap: <V1_3, V2_3, E_4>(r: Result<V1_3, E_4>, f: (value: V1_3) => Result<V2_3, E_4>) => Result<V2_3, E_4>;
19
- toAsync<V_1, E_5>(r: Result<V_1, E_5>): AsyncResult<V_1, E_5>;
20
- isSuccess<V_2, E_6>(r: Result<V_2, E_6>): r is Success<V_2>;
21
- isFailure<V_3, E_7>(r: Result<V_3, E_7>): r is Failure<E_7>;
22
- getOrElse<V_4, E_8>(r: Result<V_4, E_8>, alt: V_4): V_4;
23
- getOrElseLazy<V_5, E_9>(r: Result<V_5, E_9>, altf: () => V_5): V_5;
24
- getOrNull<V_6, E_10>(r: Result<V_6, E_10>): V_6 | null;
25
- getOrUndefined<V_7, E_11>(r: Result<V_7, E_11>): V_7 | undefined;
26
- cmatch: <V1_4, V2_4, E_12>(success: (value: V1_4) => V2_4, failure: (error: E_12) => V2_4) => (r: Result<V1_4, E_12>) => V2_4;
27
- match: <V1_5, V2_5, E_13>(r: Result<V1_5, E_13>, success: (value: V1_5) => V2_5, failure: (error: E_13) => V2_5) => V2_5;
28
- whenSuccess: <V_8, E_14>(apply: (v: V_8) => void) => (r: Result<V_8, E_14>) => Result<V_8, E_14>;
29
- whenFailure: <V_9, E_15>(apply: (e: E_15) => void) => (r: Result<V_9, E_15>) => Result<V_9, E_15>;
30
- combine: <V_10, E_16>(r1: Result<V_10, E_16>, r2: Result<V_10, E_16>, combineV: (v1: V_10, v2: V_10) => V_10, combineE: (e1: E_16, e2: E_16) => E_16) => Result<V_10, E_16>;
31
- };
package/dist/result.js DELETED
@@ -1,95 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-redeclare
2
- export const Result = {
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- success(value) {
5
- return { type: 'success', value };
6
- },
7
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
- failure(error) {
9
- return { type: 'failure', error };
10
- },
11
- cmap: (f) => (r) => {
12
- if (r.type === 'success') {
13
- return Result.success(f(r.value));
14
- }
15
- else {
16
- return r;
17
- }
18
- },
19
- map: (r, f) => {
20
- if (r.type === 'success') {
21
- return Result.success(f(r.value));
22
- }
23
- else {
24
- return r;
25
- }
26
- },
27
- cflatMap: (f) => (r) => {
28
- if (r.type === 'success') {
29
- return f(r.value);
30
- }
31
- else {
32
- return r;
33
- }
34
- },
35
- flatMap: (r, f) => {
36
- if (r.type === 'success') {
37
- return f(r.value);
38
- }
39
- else {
40
- return r;
41
- }
42
- },
43
- toAsync(r) {
44
- return r;
45
- },
46
- isSuccess(r) {
47
- return r.type === 'success';
48
- },
49
- isFailure(r) {
50
- return r.type === 'failure';
51
- },
52
- getOrElse(r, alt) {
53
- return Result.isSuccess(r) ? r.value : alt;
54
- },
55
- getOrElseLazy(r, altf) {
56
- return Result.isSuccess(r) ? r.value : altf();
57
- },
58
- getOrNull(r) {
59
- return Result.isSuccess(r) ? r.value : null;
60
- },
61
- getOrUndefined(r) {
62
- return Result.isSuccess(r) ? r.value : undefined;
63
- },
64
- cmatch: (success, failure) => (r) => {
65
- if (Result.isSuccess(r)) {
66
- return success(r.value);
67
- }
68
- else {
69
- return failure(r.error);
70
- }
71
- },
72
- match: (r, success, failure) => {
73
- if (Result.isSuccess(r)) {
74
- return success(r.value);
75
- }
76
- else {
77
- return failure(r.error);
78
- }
79
- },
80
- whenSuccess: (apply) => (r) => {
81
- if (Result.isSuccess(r)) {
82
- apply(r.value);
83
- }
84
- return r;
85
- },
86
- whenFailure: (apply) => (r) => {
87
- if (Result.isFailure(r)) {
88
- apply(r.error);
89
- }
90
- return r;
91
- },
92
- combine: (r1, r2, combineV, combineE) => Result.match(r1, (v1) => Result.match(r2, (v2) => Result.success(combineV(v1, v2)), (e2) => Result.failure(e2)), (e1) => Result.match(r2,
93
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
94
- (_) => Result.failure(e1), (e2) => Result.failure(combineE(e1, e2))))
95
- };