@ekz/option 1.2.3 → 1.2.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/README.md +70 -57
- package/index.d.ts +3 -3
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -51,33 +51,44 @@ Some('bar').forEach(x => {
|
|
|
51
51
|
|
|
52
52
|
### Table of Contents
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
54
|
+
* [Option](#option)
|
|
55
|
+
* [Parameters](#parameters)
|
|
56
|
+
* [get](#get)
|
|
57
|
+
* [isEmpty](#isempty)
|
|
58
|
+
* [isDefined](#isdefined)
|
|
59
|
+
* [map](#map)
|
|
60
|
+
* [Parameters](#parameters-1)
|
|
61
|
+
* [mapNullable](#mapnullable)
|
|
62
|
+
* [Parameters](#parameters-2)
|
|
63
|
+
* [flatMap](#flatmap)
|
|
64
|
+
* [Parameters](#parameters-3)
|
|
65
|
+
* [forEach](#foreach)
|
|
66
|
+
* [Parameters](#parameters-4)
|
|
67
|
+
* [filter](#filter)
|
|
68
|
+
* [Parameters](#parameters-5)
|
|
69
|
+
* [getOrElse](#getorelse)
|
|
70
|
+
* [Parameters](#parameters-6)
|
|
71
|
+
* [getOrReturn](#getorreturn)
|
|
72
|
+
* [Parameters](#parameters-7)
|
|
73
|
+
* [getOrUndefined](#getorundefined)
|
|
74
|
+
* [equals](#equals)
|
|
75
|
+
* [Parameters](#parameters-8)
|
|
76
|
+
* [toJSON](#tojson)
|
|
77
|
+
* [of](#of)
|
|
78
|
+
* [Parameters](#parameters-9)
|
|
79
|
+
* [None](#none)
|
|
80
|
+
* [Some](#some)
|
|
81
|
+
* [None](#none-1)
|
|
82
|
+
* [Some](#some-1)
|
|
83
|
+
* [Parameters](#parameters-10)
|
|
73
84
|
|
|
74
85
|
## Option
|
|
75
86
|
|
|
76
87
|
Represents optional values. Instances of Option are either an instance of Some or the object None.
|
|
77
88
|
|
|
78
|
-
|
|
89
|
+
### Parameters
|
|
79
90
|
|
|
80
|
-
|
|
91
|
+
* `$privateToken` **any** 
|
|
81
92
|
|
|
82
93
|
### get
|
|
83
94
|
|
|
@@ -95,135 +106,137 @@ Type: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Glob
|
|
|
95
106
|
|
|
96
107
|
Returns true if the option is an instance of Some, false otherwise.
|
|
97
108
|
|
|
98
|
-
|
|
109
|
+
Type: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
|
|
110
|
+
|
|
111
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 
|
|
99
112
|
|
|
100
113
|
### map
|
|
101
114
|
|
|
102
115
|
Returns a Some containing the result of applying f to this Option's value if this Option is nonempty.
|
|
103
116
|
|
|
104
|
-
|
|
117
|
+
#### Parameters
|
|
105
118
|
|
|
106
|
-
|
|
119
|
+
* `f` **function (A): B** 
|
|
107
120
|
|
|
108
|
-
Returns **[Option](#option)
|
|
121
|
+
Returns **[Option](#option)\<B>** 
|
|
109
122
|
|
|
110
123
|
### mapNullable
|
|
111
124
|
|
|
112
125
|
Like map, but if resulting value is null, then returns None.
|
|
113
126
|
|
|
114
|
-
|
|
127
|
+
#### Parameters
|
|
115
128
|
|
|
116
|
-
|
|
129
|
+
* `f` **function (A): B?** 
|
|
117
130
|
|
|
118
|
-
Returns **[Option](#option)
|
|
131
|
+
Returns **[Option](#option)\<B>** 
|
|
119
132
|
|
|
120
133
|
### flatMap
|
|
121
134
|
|
|
122
135
|
Returns the result of applying f to this Option's value if this Option is nonempty. Returns None if this Option is empty. Slightly different from map in that f is expected to return an Option (which could be None).
|
|
123
136
|
|
|
124
|
-
|
|
137
|
+
#### Parameters
|
|
125
138
|
|
|
126
|
-
|
|
139
|
+
* `f` **function (A): [Option](#option)\<B>** 
|
|
127
140
|
|
|
128
|
-
Returns **[Option](#option)
|
|
141
|
+
Returns **[Option](#option)\<B>** 
|
|
129
142
|
|
|
130
143
|
### forEach
|
|
131
144
|
|
|
132
145
|
Apply the given procedure f to the option's value, if it is nonempty.
|
|
133
146
|
|
|
134
|
-
|
|
147
|
+
#### Parameters
|
|
135
148
|
|
|
136
|
-
|
|
149
|
+
* `f` **function (A): any** 
|
|
137
150
|
|
|
138
|
-
Returns **void
|
|
151
|
+
Returns **void** 
|
|
139
152
|
|
|
140
153
|
### filter
|
|
141
154
|
|
|
142
155
|
Returns this Option if it is nonempty and applying the predicate to this Option's value returns true.
|
|
143
156
|
|
|
144
|
-
|
|
157
|
+
#### Parameters
|
|
145
158
|
|
|
146
|
-
|
|
159
|
+
* `predicate` **function (A): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 
|
|
147
160
|
|
|
148
|
-
Returns **[Option](#option)
|
|
161
|
+
Returns **[Option](#option)\<A>** 
|
|
149
162
|
|
|
150
163
|
### getOrElse
|
|
151
164
|
|
|
152
165
|
Returns the option's value if the option is nonempty, otherwise return the result of evaluating other.
|
|
153
166
|
|
|
154
|
-
|
|
167
|
+
#### Parameters
|
|
155
168
|
|
|
156
|
-
|
|
169
|
+
* `other` **function (): B** 
|
|
157
170
|
|
|
158
|
-
Returns **(A | B)
|
|
171
|
+
Returns **(A | B)** 
|
|
159
172
|
|
|
160
173
|
### getOrReturn
|
|
161
174
|
|
|
162
175
|
Returns the option's value if the option is nonempty, otherwise return other.
|
|
163
176
|
|
|
164
|
-
|
|
177
|
+
#### Parameters
|
|
165
178
|
|
|
166
|
-
|
|
179
|
+
* `other` **B** 
|
|
167
180
|
|
|
168
|
-
Returns **(A | B)
|
|
181
|
+
Returns **(A | B)** 
|
|
169
182
|
|
|
170
183
|
### getOrUndefined
|
|
171
184
|
|
|
172
185
|
Returns the option's value if the option is nonempty, otherwise returns undefined.
|
|
173
186
|
|
|
174
|
-
Returns **(A | void)
|
|
187
|
+
Returns **(A | void)** 
|
|
175
188
|
|
|
176
189
|
### equals
|
|
177
190
|
|
|
178
191
|
Compares the option's value with other option's value and returns true when they match. None always matches other None.
|
|
179
192
|
|
|
180
|
-
|
|
193
|
+
#### Parameters
|
|
181
194
|
|
|
182
|
-
|
|
195
|
+
* `other` **[Option](#option)\<B>** 
|
|
183
196
|
|
|
184
|
-
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
|
|
197
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 
|
|
185
198
|
|
|
186
199
|
### toJSON
|
|
187
200
|
|
|
188
201
|
Returns value if present, null otherwise. If value contains a method `toJSON`,
|
|
189
202
|
returns the result of method call.
|
|
190
203
|
|
|
191
|
-
Returns **any
|
|
204
|
+
Returns **any** 
|
|
192
205
|
|
|
193
206
|
### of
|
|
194
207
|
|
|
195
208
|
An Option factory which creates Some(x) if the argument is not null, and None if it is null.
|
|
196
209
|
|
|
197
|
-
|
|
210
|
+
#### Parameters
|
|
198
211
|
|
|
199
|
-
|
|
212
|
+
* `value` **V??** 
|
|
200
213
|
|
|
201
|
-
Returns **[Option](#option)
|
|
214
|
+
Returns **[Option](#option)\<V>** 
|
|
202
215
|
|
|
203
216
|
### None
|
|
204
217
|
|
|
205
218
|
The empty None object
|
|
206
219
|
|
|
207
|
-
Type: [Option](#option)
|
|
220
|
+
Type: [Option](#option)\<any>
|
|
208
221
|
|
|
209
222
|
### Some
|
|
210
223
|
|
|
211
224
|
Creates Some(x). Note that Some(null) is valid.
|
|
212
225
|
|
|
213
|
-
Type: function (value: A): [Option](#option)
|
|
226
|
+
Type: function (value: A): [Option](#option)\<A>
|
|
214
227
|
|
|
215
228
|
## None
|
|
216
229
|
|
|
217
230
|
The empty None object.
|
|
218
231
|
|
|
219
|
-
Type: [Option](#option)
|
|
232
|
+
Type: [Option](#option)\<any>
|
|
220
233
|
|
|
221
234
|
## Some
|
|
222
235
|
|
|
223
236
|
Creates Some(x). Note that Some(null) is valid.
|
|
224
237
|
|
|
225
|
-
|
|
238
|
+
### Parameters
|
|
226
239
|
|
|
227
|
-
|
|
240
|
+
* `value` **A** 
|
|
228
241
|
|
|
229
|
-
Returns **[Option](#option)
|
|
242
|
+
Returns **[Option](#option)\<A>** 
|
package/index.d.ts
CHANGED
|
@@ -6,17 +6,17 @@ declare module '@ekz/option' {
|
|
|
6
6
|
readonly isEmpty: boolean;
|
|
7
7
|
readonly isDefined: boolean;
|
|
8
8
|
map<B>(f: (value: A) => B): Option<B>;
|
|
9
|
-
mapNullable<B>(f: (value: A) => B | null | void): Option<B>;
|
|
9
|
+
mapNullable<B>(f: (value: A) => B | null | void | undefined): Option<B>;
|
|
10
10
|
flatMap<B>(f: (value: A) => Option<B>): Option<B>;
|
|
11
11
|
forEach(f: (value: A) => any): void;
|
|
12
12
|
filter(predicate: (value: A) => boolean): Option<A>;
|
|
13
13
|
getOrElse<B>(other: () => B): A | B;
|
|
14
14
|
getOrReturn<B>(other: B): A | B;
|
|
15
|
-
getOrUndefined(): A |
|
|
15
|
+
getOrUndefined(): A | undefined;
|
|
16
16
|
equals<B>(other: Option<B>): boolean;
|
|
17
17
|
toJSON(): unknown;
|
|
18
18
|
|
|
19
|
-
static of<V>(value?: V | null | void): Option<V>;
|
|
19
|
+
static of<V>(value?: V | null | void | undefined): Option<V>;
|
|
20
20
|
|
|
21
21
|
static None: Option<never>;
|
|
22
22
|
static Some<A>(value: A): Option<A>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ekz/option",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
|
+
"packageManager": "yarn@4.3.1",
|
|
4
5
|
"description": "Option/Maybe type to be used with flow.js",
|
|
5
6
|
"types": "index.d.ts",
|
|
6
7
|
"keywords": [
|
|
@@ -24,7 +25,6 @@
|
|
|
24
25
|
"homepage": "https://github.com/erkez/flow-option#readme",
|
|
25
26
|
"main": "lib/index.js",
|
|
26
27
|
"license": "MIT",
|
|
27
|
-
"private": false,
|
|
28
28
|
"files": [
|
|
29
29
|
"index.d.ts",
|
|
30
30
|
"lib",
|
|
@@ -33,15 +33,15 @@
|
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"babel-cli": "^6.26.0",
|
|
36
|
-
"babel-preset-env": "^1.
|
|
36
|
+
"babel-preset-env": "^1.7.0",
|
|
37
37
|
"babel-preset-flow": "^6.23.0",
|
|
38
|
-
"documentation": "^
|
|
39
|
-
"flow-bin": "^0.
|
|
40
|
-
"flow-copy-source": "^
|
|
38
|
+
"documentation": "^14.0.3",
|
|
39
|
+
"flow-bin": "^0.241.0",
|
|
40
|
+
"flow-copy-source": "^2.0.9"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "babel src/ -d lib/ && flow-copy-source -v src lib",
|
|
44
44
|
"docs": "documentation readme src/index.js --section=API",
|
|
45
45
|
"prepublish": "yarn run docs && yarn run build"
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
}
|