@siteimprove/alfa-option 0.89.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.
- package/CHANGELOG.md +169 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/maybe.d.ts +15 -0
- package/dist/maybe.js +12 -0
- package/dist/none.d.ts +21 -0
- package/dist/none.js +101 -0
- package/dist/option.d.ts +74 -0
- package/dist/option.js +34 -0
- package/dist/some.d.ts +71 -0
- package/dist/some.js +131 -0
- package/package.json +45 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# @siteimprove/alfa-option
|
|
2
|
+
|
|
3
|
+
## 0.89.3
|
|
4
|
+
|
|
5
|
+
## 0.89.2
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- **Changed:** Trying to fix a problem in generating provenance statements ([#1674](https://github.com/Siteimprove/alfa/pull/1674))
|
|
10
|
+
|
|
11
|
+
## 0.89.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- **Added:** Trying to publish Alfa packages on the npm registry ([#1673](https://github.com/Siteimprove/alfa/pull/1673))
|
|
16
|
+
|
|
17
|
+
## 0.89.0
|
|
18
|
+
|
|
19
|
+
## 0.88.0
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- **Fixed:** The publish flow was updated to a new version. ([`a2f19cf9a6c7c72b8bf085597e4f1a95ac3e4eb2`](https://github.com/Siteimprove/alfa/commit/a2f19cf9a6c7c72b8bf085597e4f1a95ac3e4eb2))
|
|
24
|
+
|
|
25
|
+
Some 0.87.\* versions were generating uninstallable package. This should be fixed now.
|
|
26
|
+
|
|
27
|
+
## 0.87.12
|
|
28
|
+
|
|
29
|
+
## 0.87.11
|
|
30
|
+
|
|
31
|
+
## 0.87.10
|
|
32
|
+
|
|
33
|
+
## 0.87.7
|
|
34
|
+
|
|
35
|
+
## 0.87.6
|
|
36
|
+
|
|
37
|
+
## 0.87.5
|
|
38
|
+
|
|
39
|
+
## 0.87.4
|
|
40
|
+
|
|
41
|
+
## 0.87.3
|
|
42
|
+
|
|
43
|
+
## 0.87.2
|
|
44
|
+
|
|
45
|
+
## 0.87.1
|
|
46
|
+
|
|
47
|
+
## 0.87.0
|
|
48
|
+
|
|
49
|
+
### Minor Changes
|
|
50
|
+
|
|
51
|
+
- **Breaking:** Optional serialization type parameters have been removed. ([#1651](https://github.com/Siteimprove/alfa/pull/1651))
|
|
52
|
+
|
|
53
|
+
## 0.86.2
|
|
54
|
+
|
|
55
|
+
## 0.86.1
|
|
56
|
+
|
|
57
|
+
## 0.86.0
|
|
58
|
+
|
|
59
|
+
### Minor Changes
|
|
60
|
+
|
|
61
|
+
- **Breaking:** TS resolution has been changed to `Node16`, target to `es2022`. ([#1636](https://github.com/Siteimprove/alfa/pull/1636))
|
|
62
|
+
|
|
63
|
+
- **Breaking:** Alfa is now distributed as ESM rather than CJS modules; projects using it must be ESM or use dynamic `import()`. ([#1636](https://github.com/Siteimprove/alfa/pull/1636))
|
|
64
|
+
|
|
65
|
+
⚠️ This is the last of a series of changes on the internal structure and build process of distributed packages that was started with v0.85.0.
|
|
66
|
+
|
|
67
|
+
## 0.85.1
|
|
68
|
+
|
|
69
|
+
## 0.85.0
|
|
70
|
+
|
|
71
|
+
### Minor Changes
|
|
72
|
+
|
|
73
|
+
- **Breaking:** The .js files are now built in the `dist` folder rather than in `src`. ([#1628](https://github.com/Siteimprove/alfa/pull/1628))
|
|
74
|
+
|
|
75
|
+
⚠️ This is the first of a series of changes on the internal structure and build process of distributed packages. It is probably better to not use this version and wait until more of these internal changes have been done to jump directly to the final result. We are internally releasing these changes for validation purpose only.
|
|
76
|
+
|
|
77
|
+
This should not impact consumers, the `package.json` files should be set correctly to consume these files.
|
|
78
|
+
|
|
79
|
+
## 0.84.0
|
|
80
|
+
|
|
81
|
+
### Minor Changes
|
|
82
|
+
|
|
83
|
+
- **Changed:** Types have been tightened a bit. ([#1634](https://github.com/Siteimprove/alfa/pull/1634))
|
|
84
|
+
|
|
85
|
+
This was needed to update to TypeScript 5.5, due to the improved [inferrence of type predicates](https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#inferred-type-predicates)
|
|
86
|
+
|
|
87
|
+
## 0.83.1
|
|
88
|
+
|
|
89
|
+
## 0.83.0
|
|
90
|
+
|
|
91
|
+
## 0.82.0
|
|
92
|
+
|
|
93
|
+
### Minor Changes
|
|
94
|
+
|
|
95
|
+
- **Added:** Serialization options are now accepted, and passed on, by `toJSON()` on these types. ([#1622](https://github.com/Siteimprove/alfa/pull/1622))
|
|
96
|
+
|
|
97
|
+
- **Breaking:** Node 18 is no longer supported. ([#1618](https://github.com/Siteimprove/alfa/pull/1618))
|
|
98
|
+
|
|
99
|
+
## 0.81.0
|
|
100
|
+
|
|
101
|
+
### Patch Changes
|
|
102
|
+
|
|
103
|
+
- **Added:** Each package now contains its internal dependency graph in its `docs` directory. ([#1610](https://github.com/Siteimprove/alfa/pull/1610))
|
|
104
|
+
|
|
105
|
+
## 0.80.0
|
|
106
|
+
|
|
107
|
+
## 0.79.1
|
|
108
|
+
|
|
109
|
+
## 0.79.0
|
|
110
|
+
|
|
111
|
+
## 0.78.2
|
|
112
|
+
|
|
113
|
+
## 0.78.1
|
|
114
|
+
|
|
115
|
+
## 0.78.0
|
|
116
|
+
|
|
117
|
+
## 0.77.0
|
|
118
|
+
|
|
119
|
+
## 0.76.0
|
|
120
|
+
|
|
121
|
+
## 0.75.2
|
|
122
|
+
|
|
123
|
+
## 0.75.1
|
|
124
|
+
|
|
125
|
+
## 0.75.0
|
|
126
|
+
|
|
127
|
+
## 0.74.0
|
|
128
|
+
|
|
129
|
+
## 0.73.0
|
|
130
|
+
|
|
131
|
+
## 0.72.0
|
|
132
|
+
|
|
133
|
+
## 0.71.1
|
|
134
|
+
|
|
135
|
+
## 0.71.0
|
|
136
|
+
|
|
137
|
+
## 0.70.0
|
|
138
|
+
|
|
139
|
+
## 0.69.0
|
|
140
|
+
|
|
141
|
+
## 0.68.0
|
|
142
|
+
|
|
143
|
+
## 0.67.0
|
|
144
|
+
|
|
145
|
+
## 0.66.0
|
|
146
|
+
|
|
147
|
+
## 0.65.1
|
|
148
|
+
|
|
149
|
+
## 0.65.0
|
|
150
|
+
|
|
151
|
+
## 0.64.0
|
|
152
|
+
|
|
153
|
+
## 0.63.3
|
|
154
|
+
|
|
155
|
+
## 0.63.2
|
|
156
|
+
|
|
157
|
+
## 0.63.1
|
|
158
|
+
|
|
159
|
+
## 0.63.0
|
|
160
|
+
|
|
161
|
+
### Minor Changes
|
|
162
|
+
|
|
163
|
+
- **Breaking:** Moved `Maybe` type out of `Option` namespace ([#1402](https://github.com/Siteimprove/alfa/pull/1402))
|
|
164
|
+
|
|
165
|
+
The type was moved while adding the function `Maybe.toOption`. The type is an internal convenience type that is only used when it's not possible or practical to use `Option`. To migrate, import `Maybe` from the `alfa-option` package and replace `Option.Maybe` with `Maybe`.
|
|
166
|
+
|
|
167
|
+
## 0.62.2
|
|
168
|
+
|
|
169
|
+
## 0.62.1
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/maybe.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Option } from "./option.js";
|
|
2
|
+
/**
|
|
3
|
+
* @remarks
|
|
4
|
+
* Should only be used when it's not possible or practical to use `Option<T>`
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export type Maybe<T> = T | Option<T>;
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare namespace Maybe {
|
|
13
|
+
function toOption<T>(maybe: Maybe<T>): Option<T>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=maybe.d.ts.map
|
package/dist/maybe.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Option } from "./option.js";
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export var Maybe;
|
|
6
|
+
(function (Maybe) {
|
|
7
|
+
function toOption(maybe) {
|
|
8
|
+
return Option.isOption(maybe) ? maybe : Option.of(maybe);
|
|
9
|
+
}
|
|
10
|
+
Maybe.toOption = toOption;
|
|
11
|
+
})(Maybe || (Maybe = {}));
|
|
12
|
+
//# sourceMappingURL=maybe.js.map
|
package/dist/none.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type * as json from "@siteimprove/alfa-json";
|
|
2
|
+
import type { Option } from "./option.js";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface None extends Option<never> {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare const None: None;
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare namespace None {
|
|
16
|
+
interface JSON {
|
|
17
|
+
[key: string]: json.JSON;
|
|
18
|
+
type: "none";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=none.d.ts.map
|
package/dist/none.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Comparable, Comparison } from "@siteimprove/alfa-comparable";
|
|
2
|
+
const { compareComparable } = Comparable;
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export const None = new (class None {
|
|
7
|
+
isSome() {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
isNone() {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
map() {
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
forEach() {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
apply() {
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
flatMap() {
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
flatten() {
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
reduce(reducer, accumulator) {
|
|
29
|
+
return accumulator;
|
|
30
|
+
}
|
|
31
|
+
filter() {
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
reject() {
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
includes() {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
some() {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
none() {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
every() {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
and() {
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
andThen() {
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
or(option) {
|
|
56
|
+
return option;
|
|
57
|
+
}
|
|
58
|
+
orElse(option) {
|
|
59
|
+
return option();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
getUnsafe(message = "Attempted to .getUnsafe() from None") {
|
|
65
|
+
throw new Error(message);
|
|
66
|
+
}
|
|
67
|
+
getOr(value) {
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
getOrElse(value) {
|
|
71
|
+
return value();
|
|
72
|
+
}
|
|
73
|
+
tee() {
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
compare(option) {
|
|
77
|
+
return this.compareWith(option, compareComparable);
|
|
78
|
+
}
|
|
79
|
+
compareWith(option) {
|
|
80
|
+
return option.isNone() ? Comparison.Equal : Comparison.Less;
|
|
81
|
+
}
|
|
82
|
+
equals(value) {
|
|
83
|
+
return value instanceof None;
|
|
84
|
+
}
|
|
85
|
+
hash(hash) {
|
|
86
|
+
hash.writeBoolean(false);
|
|
87
|
+
}
|
|
88
|
+
*[Symbol.iterator]() { }
|
|
89
|
+
toArray() {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
toJSON() {
|
|
93
|
+
return {
|
|
94
|
+
type: "none",
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
toString() {
|
|
98
|
+
return "None";
|
|
99
|
+
}
|
|
100
|
+
})();
|
|
101
|
+
//# sourceMappingURL=none.js.map
|
package/dist/option.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Callback } from "@siteimprove/alfa-callback";
|
|
2
|
+
import type { Comparable, Comparison } from "@siteimprove/alfa-comparable";
|
|
3
|
+
import { type Comparer } from "@siteimprove/alfa-comparable";
|
|
4
|
+
import type { Equatable } from "@siteimprove/alfa-equatable";
|
|
5
|
+
import type { Foldable } from "@siteimprove/alfa-foldable";
|
|
6
|
+
import type { Hashable } from "@siteimprove/alfa-hash";
|
|
7
|
+
import type { Serializable } from "@siteimprove/alfa-json";
|
|
8
|
+
import type { Mapper } from "@siteimprove/alfa-mapper";
|
|
9
|
+
import type { Monad } from "@siteimprove/alfa-monad";
|
|
10
|
+
import type { Predicate } from "@siteimprove/alfa-predicate";
|
|
11
|
+
import type { Reducer } from "@siteimprove/alfa-reducer";
|
|
12
|
+
import type { Refinement } from "@siteimprove/alfa-refinement";
|
|
13
|
+
import type { Thunk } from "@siteimprove/alfa-thunk";
|
|
14
|
+
import { None } from "./none.js";
|
|
15
|
+
import { Some } from "./some.js";
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export interface Option<T> extends Monad<T>, Foldable<T>, Iterable<T>, Equatable, Hashable, Serializable<Option.JSON<T>> {
|
|
20
|
+
isSome(): this is Some<T>;
|
|
21
|
+
isNone(): this is None;
|
|
22
|
+
map<U>(mapper: Mapper<T, U>): Option<U>;
|
|
23
|
+
forEach(mapper: Mapper<T, void>): void;
|
|
24
|
+
apply<U>(mapper: Option<Mapper<T, U>>): Option<U>;
|
|
25
|
+
flatMap<U>(mapper: Mapper<T, Option<U>>): Option<U>;
|
|
26
|
+
flatten<T>(this: Option<Option<T>>): Option<T>;
|
|
27
|
+
reduce<U>(reducer: Reducer<T, U>, accumulator: U): U;
|
|
28
|
+
filter<U extends T>(refinement: Refinement<T, U>): Option<U>;
|
|
29
|
+
filter(predicate: Predicate<T>): Option<T>;
|
|
30
|
+
reject<U extends T>(refinement: Refinement<T, U>): Option<Exclude<T, U>>;
|
|
31
|
+
reject(predicate: Predicate<T>): Option<T>;
|
|
32
|
+
includes(value: T): boolean;
|
|
33
|
+
some<U extends T>(refinement: Refinement<T, U>): this is Some<U>;
|
|
34
|
+
some(predicate: Predicate<T>): boolean;
|
|
35
|
+
none<U extends T>(refinement: Refinement<T, U>): this is Option<Exclude<T, U>>;
|
|
36
|
+
none(predicate: Predicate<T>): boolean;
|
|
37
|
+
every<U extends T>(refinement: Refinement<T, U>): this is Option<U>;
|
|
38
|
+
every(predicate: Predicate<T>): boolean;
|
|
39
|
+
and<U>(option: Option<U>): Option<U>;
|
|
40
|
+
andThen<U>(option: Mapper<T, Option<U>>): Option<U>;
|
|
41
|
+
or<U>(option: Option<U>): Option<T | U>;
|
|
42
|
+
orElse<U>(option: Thunk<Option<U>>): Option<T | U>;
|
|
43
|
+
/**
|
|
44
|
+
* This may throw an exception. Use only when you can provide an external
|
|
45
|
+
* guarantee that it won't be used on None. E.g. in tests, or when some
|
|
46
|
+
* condition exists that TypeScript cannot see (document it!)
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
getUnsafe(message?: string): T;
|
|
51
|
+
getOr<U>(value: U): T | U;
|
|
52
|
+
getOrElse<U>(value: Thunk<U>): T | U;
|
|
53
|
+
tee(callback: Callback<T>): Option<T>;
|
|
54
|
+
compare<T>(this: Option<Comparable<T>>, option: Option<T>): Comparison;
|
|
55
|
+
compareWith<U = T>(option: Option<U>, comparer: Comparer<T, U>): Comparison;
|
|
56
|
+
toArray(): Array<T>;
|
|
57
|
+
toJSON(options?: Serializable.Options): Option.JSON<T>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
export declare namespace Option {
|
|
63
|
+
type JSON<T> = Some.JSON<T> | None.JSON;
|
|
64
|
+
function isOption<T>(value: Iterable<T>): value is Option<T>;
|
|
65
|
+
function isOption<T>(value: unknown): value is Option<T>;
|
|
66
|
+
function isSome<T>(value: Iterable<T>): value is Some<T>;
|
|
67
|
+
function isSome<T>(value: unknown): value is Some<T>;
|
|
68
|
+
function isNone<T>(value: Iterable<T>): value is None;
|
|
69
|
+
function isNone(value: unknown): value is None;
|
|
70
|
+
function of<T>(value: T): Some<T>;
|
|
71
|
+
function empty<T>(): None;
|
|
72
|
+
function from<T>(value: T | null | undefined): Option<NonNullable<T>>;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=option.d.ts.map
|
package/dist/option.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {} from "@siteimprove/alfa-comparable";
|
|
2
|
+
import { None } from "./none.js";
|
|
3
|
+
import { Some } from "./some.js";
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export var Option;
|
|
8
|
+
(function (Option) {
|
|
9
|
+
function isOption(value) {
|
|
10
|
+
return isSome(value) || isNone(value);
|
|
11
|
+
}
|
|
12
|
+
Option.isOption = isOption;
|
|
13
|
+
function isSome(value) {
|
|
14
|
+
return Some.isSome(value);
|
|
15
|
+
}
|
|
16
|
+
Option.isSome = isSome;
|
|
17
|
+
function isNone(value) {
|
|
18
|
+
return value === None;
|
|
19
|
+
}
|
|
20
|
+
Option.isNone = isNone;
|
|
21
|
+
function of(value) {
|
|
22
|
+
return Some.of(value);
|
|
23
|
+
}
|
|
24
|
+
Option.of = of;
|
|
25
|
+
function empty() {
|
|
26
|
+
return None;
|
|
27
|
+
}
|
|
28
|
+
Option.empty = empty;
|
|
29
|
+
function from(value) {
|
|
30
|
+
return value === null || value === undefined ? None : Some.of(value);
|
|
31
|
+
}
|
|
32
|
+
Option.from = from;
|
|
33
|
+
})(Option || (Option = {}));
|
|
34
|
+
//# sourceMappingURL=option.js.map
|
package/dist/some.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Callback } from "@siteimprove/alfa-callback";
|
|
2
|
+
import { Comparable, type Comparer, Comparison } from "@siteimprove/alfa-comparable";
|
|
3
|
+
import type { Hash } from "@siteimprove/alfa-hash";
|
|
4
|
+
import { Serializable } from "@siteimprove/alfa-json";
|
|
5
|
+
import type { Mapper } from "@siteimprove/alfa-mapper";
|
|
6
|
+
import { Predicate } from "@siteimprove/alfa-predicate";
|
|
7
|
+
import type { Reducer } from "@siteimprove/alfa-reducer";
|
|
8
|
+
import type { Refinement } from "@siteimprove/alfa-refinement";
|
|
9
|
+
import type * as json from "@siteimprove/alfa-json";
|
|
10
|
+
import type { Option } from "./option.js";
|
|
11
|
+
import { None } from "./none.js";
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare class Some<T> implements Option<T> {
|
|
16
|
+
static of<T>(value: T): Some<T>;
|
|
17
|
+
private readonly _value;
|
|
18
|
+
private constructor();
|
|
19
|
+
isSome(): this is Some<T>;
|
|
20
|
+
isNone(): this is None;
|
|
21
|
+
map<U>(mapper: Mapper<T, U>): Some<U>;
|
|
22
|
+
forEach(mapper: Mapper<T, void>): void;
|
|
23
|
+
apply<U>(mapper: Option<Mapper<T, U>>): Option<U>;
|
|
24
|
+
flatMap<U>(mapper: Mapper<T, Option<U>>): Option<U>;
|
|
25
|
+
flatten<T>(this: Some<Option<T>>): Option<T>;
|
|
26
|
+
reduce<U>(reducer: Reducer<T, U>, accumulator: U): U;
|
|
27
|
+
filter<U extends T>(refinement: Refinement<T, U>): Option<U>;
|
|
28
|
+
filter(predicate: Predicate<T>): Option<T>;
|
|
29
|
+
reject<U extends T>(refinement: Refinement<T, U>): Option<Exclude<T, U>>;
|
|
30
|
+
reject(predicate: Predicate<T>): Option<T>;
|
|
31
|
+
includes(value: T): boolean;
|
|
32
|
+
some<U extends T>(refinement: Refinement<T, U>): this is Some<U>;
|
|
33
|
+
some(predicate: Predicate<T>): boolean;
|
|
34
|
+
none<U extends T>(refinement: Refinement<T, U>): this is Some<Exclude<T, U>>;
|
|
35
|
+
none(predicate: Predicate<T>): boolean;
|
|
36
|
+
every<U extends T>(refinement: Refinement<T, U>): this is Some<U>;
|
|
37
|
+
every(predicate: Predicate<T>): boolean;
|
|
38
|
+
and<U>(option: Option<U>): Option<U>;
|
|
39
|
+
andThen<U>(option: Mapper<T, Option<U>>): Option<U>;
|
|
40
|
+
or(): Some<T>;
|
|
41
|
+
orElse(): Some<T>;
|
|
42
|
+
get(): T;
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
getUnsafe(): T;
|
|
47
|
+
getOr(): T;
|
|
48
|
+
getOrElse(): T;
|
|
49
|
+
tee(callback: Callback<T>): this;
|
|
50
|
+
compare<T>(this: Option<Comparable<T>>, option: Option<T>): Comparison;
|
|
51
|
+
compareWith<U = T>(option: Option<U>, comparer: Comparer<T, U>): Comparison;
|
|
52
|
+
equals(value: unknown): value is this;
|
|
53
|
+
hash(hash: Hash): void;
|
|
54
|
+
[Symbol.iterator](): Iterator<T>;
|
|
55
|
+
toArray(): [T];
|
|
56
|
+
toJSON(options?: Serializable.Options): Some.JSON<T>;
|
|
57
|
+
toString(): string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
export declare namespace Some {
|
|
63
|
+
interface JSON<T> {
|
|
64
|
+
[key: string]: json.JSON;
|
|
65
|
+
type: "some";
|
|
66
|
+
value: Serializable.ToJSON<T>;
|
|
67
|
+
}
|
|
68
|
+
function isSome<T>(value: Iterable<T>): value is Some<T>;
|
|
69
|
+
function isSome<T>(value: unknown): value is Some<T>;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=some.d.ts.map
|
package/dist/some.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Comparable, Comparison, } from "@siteimprove/alfa-comparable";
|
|
2
|
+
import { Equatable } from "@siteimprove/alfa-equatable";
|
|
3
|
+
import { Serializable } from "@siteimprove/alfa-json";
|
|
4
|
+
import { Predicate } from "@siteimprove/alfa-predicate";
|
|
5
|
+
import { None } from "./none.js";
|
|
6
|
+
const { not, test } = Predicate;
|
|
7
|
+
const { compareComparable } = Comparable;
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export class Some {
|
|
12
|
+
static of(value) {
|
|
13
|
+
return new Some(value);
|
|
14
|
+
}
|
|
15
|
+
_value;
|
|
16
|
+
constructor(value) {
|
|
17
|
+
this._value = value;
|
|
18
|
+
}
|
|
19
|
+
isSome() {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
isNone() {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
map(mapper) {
|
|
26
|
+
return new Some(mapper(this._value));
|
|
27
|
+
}
|
|
28
|
+
forEach(mapper) {
|
|
29
|
+
mapper(this._value);
|
|
30
|
+
}
|
|
31
|
+
apply(mapper) {
|
|
32
|
+
return mapper.map((mapper) => mapper(this._value));
|
|
33
|
+
}
|
|
34
|
+
flatMap(mapper) {
|
|
35
|
+
return mapper(this._value);
|
|
36
|
+
}
|
|
37
|
+
flatten() {
|
|
38
|
+
return this._value;
|
|
39
|
+
}
|
|
40
|
+
reduce(reducer, accumulator) {
|
|
41
|
+
return reducer(accumulator, this._value);
|
|
42
|
+
}
|
|
43
|
+
filter(predicate) {
|
|
44
|
+
return test(predicate, this._value) ? this : None;
|
|
45
|
+
}
|
|
46
|
+
reject(predicate) {
|
|
47
|
+
return this.filter(not(predicate));
|
|
48
|
+
}
|
|
49
|
+
includes(value) {
|
|
50
|
+
return Equatable.equals(value, this._value);
|
|
51
|
+
}
|
|
52
|
+
some(predicate) {
|
|
53
|
+
return test(predicate, this._value);
|
|
54
|
+
}
|
|
55
|
+
none(predicate) {
|
|
56
|
+
return test(not(predicate), this._value);
|
|
57
|
+
}
|
|
58
|
+
every(predicate) {
|
|
59
|
+
return test(predicate, this._value);
|
|
60
|
+
}
|
|
61
|
+
and(option) {
|
|
62
|
+
return option;
|
|
63
|
+
}
|
|
64
|
+
andThen(option) {
|
|
65
|
+
return option(this._value);
|
|
66
|
+
}
|
|
67
|
+
or() {
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
orElse() {
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
get() {
|
|
74
|
+
return this._value;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
getUnsafe() {
|
|
80
|
+
return this._value;
|
|
81
|
+
}
|
|
82
|
+
getOr() {
|
|
83
|
+
return this._value;
|
|
84
|
+
}
|
|
85
|
+
getOrElse() {
|
|
86
|
+
return this._value;
|
|
87
|
+
}
|
|
88
|
+
tee(callback) {
|
|
89
|
+
callback(this._value);
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
compare(option) {
|
|
93
|
+
return this.compareWith(option, compareComparable);
|
|
94
|
+
}
|
|
95
|
+
compareWith(option, comparer) {
|
|
96
|
+
return option.isSome()
|
|
97
|
+
? comparer(this._value, option._value)
|
|
98
|
+
: Comparison.Greater;
|
|
99
|
+
}
|
|
100
|
+
equals(value) {
|
|
101
|
+
return value instanceof Some && Equatable.equals(value._value, this._value);
|
|
102
|
+
}
|
|
103
|
+
hash(hash) {
|
|
104
|
+
hash.writeBoolean(true).writeUnknown(this._value);
|
|
105
|
+
}
|
|
106
|
+
*[Symbol.iterator]() {
|
|
107
|
+
yield this._value;
|
|
108
|
+
}
|
|
109
|
+
toArray() {
|
|
110
|
+
return [this._value];
|
|
111
|
+
}
|
|
112
|
+
toJSON(options) {
|
|
113
|
+
return {
|
|
114
|
+
type: "some",
|
|
115
|
+
value: Serializable.toJSON(this._value, options),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
toString() {
|
|
119
|
+
return `Some { ${this._value} }`;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @public
|
|
124
|
+
*/
|
|
125
|
+
(function (Some) {
|
|
126
|
+
function isSome(value) {
|
|
127
|
+
return value instanceof Some;
|
|
128
|
+
}
|
|
129
|
+
Some.isSome = isSome;
|
|
130
|
+
})(Some || (Some = {}));
|
|
131
|
+
//# sourceMappingURL=some.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json.schemastore.org/package",
|
|
3
|
+
"name": "@siteimprove/alfa-option",
|
|
4
|
+
"homepage": "https://alfa.siteimprove.com",
|
|
5
|
+
"version": "0.89.5",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"description": "An implementation of optional values, which are values that may or may not be present",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "github:Siteimprove/alfa",
|
|
11
|
+
"directory": "packages/alfa-option"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/siteimprove/alfa/issues",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=20.0.0"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/**/*.js",
|
|
22
|
+
"dist/**/*.d.ts"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@siteimprove/alfa-callback": "^0.89.5",
|
|
26
|
+
"@siteimprove/alfa-comparable": "^0.89.5",
|
|
27
|
+
"@siteimprove/alfa-equatable": "^0.89.5",
|
|
28
|
+
"@siteimprove/alfa-foldable": "^0.89.5",
|
|
29
|
+
"@siteimprove/alfa-hash": "^0.89.5",
|
|
30
|
+
"@siteimprove/alfa-json": "^0.89.5",
|
|
31
|
+
"@siteimprove/alfa-mapper": "^0.89.5",
|
|
32
|
+
"@siteimprove/alfa-monad": "^0.89.5",
|
|
33
|
+
"@siteimprove/alfa-predicate": "^0.89.5",
|
|
34
|
+
"@siteimprove/alfa-reducer": "^0.89.5",
|
|
35
|
+
"@siteimprove/alfa-refinement": "^0.89.5",
|
|
36
|
+
"@siteimprove/alfa-thunk": "^0.89.5"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@siteimprove/alfa-test": "^0.89.5"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"registry": "https://npm.pkg.github.com/"
|
|
44
|
+
}
|
|
45
|
+
}
|