@nlozgachev/pipelined 0.11.0 → 0.13.0
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/LICENCE +28 -0
- package/README.md +1 -1
- package/{types/src/Types/NonEmptyList.d.ts → dist/NonEmptyList-BlGFjor5.d.mts} +4 -3
- package/dist/NonEmptyList-BlGFjor5.d.ts +30 -0
- package/dist/Task-BB8Wmc1J.d.ts +677 -0
- package/dist/Task-ChKyH0pF.d.mts +677 -0
- package/dist/chunk-DBIC62UV.mjs +6 -0
- package/dist/chunk-QPTGO5AS.mjs +150 -0
- package/dist/composition.d.mts +495 -0
- package/dist/composition.d.ts +495 -0
- package/dist/composition.js +188 -0
- package/dist/composition.mjs +135 -0
- package/dist/core.d.mts +2170 -0
- package/dist/core.d.ts +2170 -0
- package/dist/core.js +698 -0
- package/dist/core.mjs +517 -0
- package/dist/types.d.mts +54 -0
- package/{types/src/Types/Brand.d.ts → dist/types.d.ts} +6 -4
- package/dist/types.js +41 -0
- package/dist/types.mjs +14 -0
- package/dist/utils.d.mts +1285 -0
- package/dist/utils.d.ts +1285 -0
- package/dist/utils.js +722 -0
- package/dist/utils.mjs +553 -0
- package/package.json +63 -69
- package/esm/mod.js +0 -3
- package/esm/package.json +0 -3
- package/esm/src/Composition/compose.js +0 -3
- package/esm/src/Composition/converge.js +0 -3
- package/esm/src/Composition/curry.js +0 -42
- package/esm/src/Composition/flip.js +0 -20
- package/esm/src/Composition/flow.js +0 -8
- package/esm/src/Composition/fn.js +0 -85
- package/esm/src/Composition/index.js +0 -13
- package/esm/src/Composition/juxt.js +0 -3
- package/esm/src/Composition/memoize.js +0 -66
- package/esm/src/Composition/not.js +0 -25
- package/esm/src/Composition/on.js +0 -12
- package/esm/src/Composition/pipe.js +0 -3
- package/esm/src/Composition/tap.js +0 -33
- package/esm/src/Composition/uncurry.js +0 -32
- package/esm/src/Core/Deferred.js +0 -30
- package/esm/src/Core/InternalTypes.js +0 -1
- package/esm/src/Core/Lens.js +0 -98
- package/esm/src/Core/Logged.js +0 -111
- package/esm/src/Core/Option.js +0 -191
- package/esm/src/Core/Optional.js +0 -160
- package/esm/src/Core/Predicate.js +0 -133
- package/esm/src/Core/Reader.js +0 -134
- package/esm/src/Core/Refinement.js +0 -115
- package/esm/src/Core/RemoteData.js +0 -211
- package/esm/src/Core/Result.js +0 -170
- package/esm/src/Core/State.js +0 -181
- package/esm/src/Core/Task.js +0 -223
- package/esm/src/Core/TaskOption.js +0 -106
- package/esm/src/Core/TaskResult.js +0 -127
- package/esm/src/Core/TaskValidation.js +0 -128
- package/esm/src/Core/These.js +0 -245
- package/esm/src/Core/Validation.js +0 -212
- package/esm/src/Core/index.js +0 -17
- package/esm/src/Types/Brand.js +0 -28
- package/esm/src/Types/NonEmptyList.js +0 -14
- package/esm/src/Types/index.js +0 -2
- package/esm/src/Utils/Arr.js +0 -570
- package/esm/src/Utils/Num.js +0 -124
- package/esm/src/Utils/Rec.js +0 -215
- package/esm/src/Utils/Str.js +0 -134
- package/esm/src/Utils/index.js +0 -4
- package/script/mod.js +0 -19
- package/script/package.json +0 -3
- package/script/src/Composition/compose.js +0 -6
- package/script/src/Composition/converge.js +0 -6
- package/script/src/Composition/curry.js +0 -48
- package/script/src/Composition/flip.js +0 -24
- package/script/src/Composition/flow.js +0 -11
- package/script/src/Composition/fn.js +0 -98
- package/script/src/Composition/index.js +0 -29
- package/script/src/Composition/juxt.js +0 -6
- package/script/src/Composition/memoize.js +0 -71
- package/script/src/Composition/not.js +0 -29
- package/script/src/Composition/on.js +0 -16
- package/script/src/Composition/pipe.js +0 -6
- package/script/src/Composition/tap.js +0 -37
- package/script/src/Composition/uncurry.js +0 -38
- package/script/src/Core/Deferred.js +0 -33
- package/script/src/Core/InternalTypes.js +0 -2
- package/script/src/Core/Lens.js +0 -101
- package/script/src/Core/Logged.js +0 -114
- package/script/src/Core/Option.js +0 -194
- package/script/src/Core/Optional.js +0 -163
- package/script/src/Core/Predicate.js +0 -136
- package/script/src/Core/Reader.js +0 -137
- package/script/src/Core/Refinement.js +0 -118
- package/script/src/Core/RemoteData.js +0 -214
- package/script/src/Core/Result.js +0 -173
- package/script/src/Core/State.js +0 -184
- package/script/src/Core/Task.js +0 -226
- package/script/src/Core/TaskOption.js +0 -109
- package/script/src/Core/TaskResult.js +0 -130
- package/script/src/Core/TaskValidation.js +0 -131
- package/script/src/Core/These.js +0 -248
- package/script/src/Core/Validation.js +0 -215
- package/script/src/Core/index.js +0 -33
- package/script/src/Types/Brand.js +0 -31
- package/script/src/Types/NonEmptyList.js +0 -18
- package/script/src/Types/index.js +0 -18
- package/script/src/Utils/Arr.js +0 -573
- package/script/src/Utils/Num.js +0 -127
- package/script/src/Utils/Rec.js +0 -218
- package/script/src/Utils/Str.js +0 -137
- package/script/src/Utils/index.js +0 -20
- package/types/mod.d.ts +0 -4
- package/types/mod.d.ts.map +0 -1
- package/types/src/Composition/compose.d.ts +0 -33
- package/types/src/Composition/compose.d.ts.map +0 -1
- package/types/src/Composition/converge.d.ts +0 -21
- package/types/src/Composition/converge.d.ts.map +0 -1
- package/types/src/Composition/curry.d.ts +0 -43
- package/types/src/Composition/curry.d.ts.map +0 -1
- package/types/src/Composition/flip.d.ts +0 -21
- package/types/src/Composition/flip.d.ts.map +0 -1
- package/types/src/Composition/flow.d.ts +0 -56
- package/types/src/Composition/flow.d.ts.map +0 -1
- package/types/src/Composition/fn.d.ts +0 -76
- package/types/src/Composition/fn.d.ts.map +0 -1
- package/types/src/Composition/index.d.ts +0 -14
- package/types/src/Composition/index.d.ts.map +0 -1
- package/types/src/Composition/juxt.d.ts +0 -18
- package/types/src/Composition/juxt.d.ts.map +0 -1
- package/types/src/Composition/memoize.d.ts +0 -46
- package/types/src/Composition/memoize.d.ts.map +0 -1
- package/types/src/Composition/not.d.ts +0 -26
- package/types/src/Composition/not.d.ts.map +0 -1
- package/types/src/Composition/on.d.ts +0 -13
- package/types/src/Composition/on.d.ts.map +0 -1
- package/types/src/Composition/pipe.d.ts +0 -56
- package/types/src/Composition/pipe.d.ts.map +0 -1
- package/types/src/Composition/tap.d.ts +0 -31
- package/types/src/Composition/tap.d.ts.map +0 -1
- package/types/src/Composition/uncurry.d.ts +0 -54
- package/types/src/Composition/uncurry.d.ts.map +0 -1
- package/types/src/Core/Deferred.d.ts +0 -49
- package/types/src/Core/Deferred.d.ts.map +0 -1
- package/types/src/Core/InternalTypes.d.ts +0 -23
- package/types/src/Core/InternalTypes.d.ts.map +0 -1
- package/types/src/Core/Lens.d.ts +0 -118
- package/types/src/Core/Lens.d.ts.map +0 -1
- package/types/src/Core/Logged.d.ts +0 -126
- package/types/src/Core/Logged.d.ts.map +0 -1
- package/types/src/Core/Option.d.ts +0 -209
- package/types/src/Core/Option.d.ts.map +0 -1
- package/types/src/Core/Optional.d.ts +0 -158
- package/types/src/Core/Optional.d.ts.map +0 -1
- package/types/src/Core/Predicate.d.ts +0 -161
- package/types/src/Core/Predicate.d.ts.map +0 -1
- package/types/src/Core/Reader.d.ts +0 -156
- package/types/src/Core/Reader.d.ts.map +0 -1
- package/types/src/Core/Refinement.d.ts +0 -138
- package/types/src/Core/Refinement.d.ts.map +0 -1
- package/types/src/Core/RemoteData.d.ts +0 -197
- package/types/src/Core/RemoteData.d.ts.map +0 -1
- package/types/src/Core/Result.d.ts +0 -182
- package/types/src/Core/Result.d.ts.map +0 -1
- package/types/src/Core/State.d.ts +0 -192
- package/types/src/Core/State.d.ts.map +0 -1
- package/types/src/Core/Task.d.ts +0 -219
- package/types/src/Core/Task.d.ts.map +0 -1
- package/types/src/Core/TaskOption.d.ts +0 -121
- package/types/src/Core/TaskOption.d.ts.map +0 -1
- package/types/src/Core/TaskResult.d.ts +0 -119
- package/types/src/Core/TaskResult.d.ts.map +0 -1
- package/types/src/Core/TaskValidation.d.ts +0 -144
- package/types/src/Core/TaskValidation.d.ts.map +0 -1
- package/types/src/Core/These.d.ts +0 -225
- package/types/src/Core/These.d.ts.map +0 -1
- package/types/src/Core/Validation.d.ts +0 -203
- package/types/src/Core/Validation.d.ts.map +0 -1
- package/types/src/Core/index.d.ts +0 -18
- package/types/src/Core/index.d.ts.map +0 -1
- package/types/src/Types/Brand.d.ts.map +0 -1
- package/types/src/Types/NonEmptyList.d.ts.map +0 -1
- package/types/src/Types/index.d.ts +0 -3
- package/types/src/Types/index.d.ts.map +0 -1
- package/types/src/Utils/Arr.d.ts +0 -403
- package/types/src/Utils/Arr.d.ts.map +0 -1
- package/types/src/Utils/Num.d.ts +0 -110
- package/types/src/Utils/Num.d.ts.map +0 -1
- package/types/src/Utils/Rec.d.ts +0 -143
- package/types/src/Utils/Rec.d.ts.map +0 -1
- package/types/src/Utils/Str.d.ts +0 -128
- package/types/src/Utils/Str.d.ts.map +0 -1
- package/types/src/Utils/index.d.ts +0 -5
- package/types/src/Utils/index.d.ts.map +0 -1
package/esm/src/Utils/Rec.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { Option } from "../Core/Option.js";
|
|
2
|
-
/**
|
|
3
|
-
* Functional record/object utilities that compose well with pipe.
|
|
4
|
-
* All functions are data-last and curried where applicable.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* pipe(
|
|
9
|
-
* { a: 1, b: 2, c: 3 },
|
|
10
|
-
* Rec.filter(n => n > 1),
|
|
11
|
-
* Rec.map(n => n * 10)
|
|
12
|
-
* ); // { b: 20, c: 30 }
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export var Rec;
|
|
16
|
-
(function (Rec) {
|
|
17
|
-
/**
|
|
18
|
-
* Transforms each value in a record.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* pipe({ a: 1, b: 2 }, Rec.map(n => n * 2)); // { a: 2, b: 4 }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
Rec.map = (f) => (data) => {
|
|
26
|
-
const keys = Object.keys(data);
|
|
27
|
-
const vals = Object.values(data);
|
|
28
|
-
const result = {};
|
|
29
|
-
for (let i = 0; i < keys.length; i++) {
|
|
30
|
-
result[keys[i]] = f(vals[i]);
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Transforms each value in a record, also receiving the key.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```ts
|
|
39
|
-
* pipe({ a: 1, b: 2 }, Rec.mapWithKey((k, v) => `${k}:${v}`));
|
|
40
|
-
* // { a: "a:1", b: "b:2" }
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
Rec.mapWithKey = (f) => (data) => {
|
|
44
|
-
const keys = Object.keys(data);
|
|
45
|
-
const vals = Object.values(data);
|
|
46
|
-
const result = {};
|
|
47
|
-
for (let i = 0; i < keys.length; i++) {
|
|
48
|
-
result[keys[i]] = f(keys[i], vals[i]);
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Filters values in a record by a predicate.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* pipe({ a: 1, b: 2, c: 3 }, Rec.filter(n => n > 1)); // { b: 2, c: 3 }
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
Rec.filter = (predicate) => (data) => {
|
|
61
|
-
const keys = Object.keys(data);
|
|
62
|
-
const vals = Object.values(data);
|
|
63
|
-
const result = {};
|
|
64
|
-
for (let i = 0; i < keys.length; i++) {
|
|
65
|
-
if (predicate(vals[i]))
|
|
66
|
-
result[keys[i]] = vals[i];
|
|
67
|
-
}
|
|
68
|
-
return result;
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Filters values in a record by a predicate that also receives the key.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts
|
|
75
|
-
* pipe({ a: 1, b: 2 }, Rec.filterWithKey((k, v) => k !== "a" && v > 0));
|
|
76
|
-
* // { b: 2 }
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
Rec.filterWithKey = (predicate) => (data) => {
|
|
80
|
-
const keys = Object.keys(data);
|
|
81
|
-
const vals = Object.values(data);
|
|
82
|
-
const result = {};
|
|
83
|
-
for (let i = 0; i < keys.length; i++) {
|
|
84
|
-
if (predicate(keys[i], vals[i]))
|
|
85
|
-
result[keys[i]] = vals[i];
|
|
86
|
-
}
|
|
87
|
-
return result;
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Looks up a value by key, returning Option.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```ts
|
|
94
|
-
* pipe({ a: 1, b: 2 }, Rec.lookup("a")); // Some(1)
|
|
95
|
-
* pipe({ a: 1, b: 2 }, Rec.lookup("c")); // None
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
Rec.lookup = (key) => (data) => Object.prototype.hasOwnProperty.call(data, key) ? Option.some(data[key]) : Option.none();
|
|
99
|
-
/**
|
|
100
|
-
* Returns all keys of a record.
|
|
101
|
-
*/
|
|
102
|
-
Rec.keys = (data) => Object.keys(data);
|
|
103
|
-
/**
|
|
104
|
-
* Returns all values of a record.
|
|
105
|
-
*/
|
|
106
|
-
Rec.values = (data) => Object.values(data);
|
|
107
|
-
/**
|
|
108
|
-
* Returns all key-value pairs of a record.
|
|
109
|
-
*/
|
|
110
|
-
Rec.entries = (data) => Object.entries(data);
|
|
111
|
-
/**
|
|
112
|
-
* Creates a record from key-value pairs.
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* ```ts
|
|
116
|
-
* Rec.fromEntries([["a", 1], ["b", 2]]); // { a: 1, b: 2 }
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
Rec.fromEntries = (data) => Object.fromEntries(data);
|
|
120
|
-
/**
|
|
121
|
-
* Picks specific keys from a record.
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```ts
|
|
125
|
-
* pipe({ a: 1, b: 2, c: 3 }, Rec.pick("a", "c")); // { a: 1, c: 3 }
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
Rec.pick = (...pickedKeys) => (data) => {
|
|
129
|
-
const result = {};
|
|
130
|
-
for (const key of pickedKeys) {
|
|
131
|
-
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
132
|
-
result[key] = data[key];
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return result;
|
|
136
|
-
};
|
|
137
|
-
/**
|
|
138
|
-
* Omits specific keys from a record.
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* ```ts
|
|
142
|
-
* pipe({ a: 1, b: 2, c: 3 }, Rec.omit("b")); // { a: 1, c: 3 }
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
Rec.omit = (...omittedKeys) => (data) => {
|
|
146
|
-
const omitSet = new Set(omittedKeys);
|
|
147
|
-
const result = {};
|
|
148
|
-
for (const key of Object.keys(data)) {
|
|
149
|
-
if (!omitSet.has(key)) {
|
|
150
|
-
result[key] = data[key];
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return result;
|
|
154
|
-
};
|
|
155
|
-
/**
|
|
156
|
-
* Merges two records. Values from the second record take precedence.
|
|
157
|
-
*
|
|
158
|
-
* @example
|
|
159
|
-
* ```ts
|
|
160
|
-
* pipe({ a: 1, b: 2 }, Rec.merge({ b: 3, c: 4 })); // { a: 1, b: 3, c: 4 }
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
Rec.merge = (other) => (data) => ({
|
|
164
|
-
...data,
|
|
165
|
-
...other,
|
|
166
|
-
});
|
|
167
|
-
/**
|
|
168
|
-
* Returns true if the record has no keys.
|
|
169
|
-
*/
|
|
170
|
-
Rec.isEmpty = (data) => Object.keys(data).length === 0;
|
|
171
|
-
/**
|
|
172
|
-
* Returns the number of keys in a record.
|
|
173
|
-
*/
|
|
174
|
-
Rec.size = (data) => Object.keys(data).length;
|
|
175
|
-
/**
|
|
176
|
-
* Transforms each key while preserving values.
|
|
177
|
-
* If two keys map to the same new key, the last one wins.
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* ```ts
|
|
181
|
-
* pipe({ firstName: "Alice", lastName: "Smith" }, Rec.mapKeys(k => k.toUpperCase()));
|
|
182
|
-
* // { FIRSTNAME: "Alice", LASTNAME: "Smith" }
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
Rec.mapKeys = (f) => (data) => {
|
|
186
|
-
const keys = Object.keys(data);
|
|
187
|
-
const vals = Object.values(data);
|
|
188
|
-
const result = {};
|
|
189
|
-
for (let i = 0; i < keys.length; i++) {
|
|
190
|
-
result[f(keys[i])] = vals[i];
|
|
191
|
-
}
|
|
192
|
-
return result;
|
|
193
|
-
};
|
|
194
|
-
/**
|
|
195
|
-
* Removes all `None` values from a `Record<string, Option<A>>`, returning a plain `Record<string, A>`.
|
|
196
|
-
* Useful when building records from fallible lookups.
|
|
197
|
-
*
|
|
198
|
-
* @example
|
|
199
|
-
* ```ts
|
|
200
|
-
* Rec.compact({ a: Option.some(1), b: Option.none(), c: Option.some(3) });
|
|
201
|
-
* // { a: 1, c: 3 }
|
|
202
|
-
* ```
|
|
203
|
-
*/
|
|
204
|
-
Rec.compact = (data) => {
|
|
205
|
-
const keys = Object.keys(data);
|
|
206
|
-
const vals = Object.values(data);
|
|
207
|
-
const result = {};
|
|
208
|
-
for (let i = 0; i < keys.length; i++) {
|
|
209
|
-
const v = vals[i];
|
|
210
|
-
if (v.kind === "Some")
|
|
211
|
-
result[keys[i]] = v.value;
|
|
212
|
-
}
|
|
213
|
-
return result;
|
|
214
|
-
};
|
|
215
|
-
})(Rec || (Rec = {}));
|
package/esm/src/Utils/Str.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { Option } from "../Core/Option.js";
|
|
2
|
-
/**
|
|
3
|
-
* String utilities. All transformation functions are data-last and curried so they
|
|
4
|
-
* compose naturally with `pipe`. Safe parsers return `Option` instead of `NaN`.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* import { Str } from "@nlozgachev/pipelined/utils";
|
|
9
|
-
* import { pipe } from "@nlozgachev/pipelined/composition";
|
|
10
|
-
*
|
|
11
|
-
* pipe(" Hello, World! ", Str.trim, Str.toLowerCase); // "hello, world!"
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
export var Str;
|
|
15
|
-
(function (Str) {
|
|
16
|
-
/**
|
|
17
|
-
* Splits a string by a separator. Data-last: use in `pipe`.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* pipe("a,b,c", Str.split(",")); // ["a", "b", "c"]
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
Str.split = (separator) => (s) => s.split(separator);
|
|
25
|
-
/**
|
|
26
|
-
* Removes leading and trailing whitespace from a string.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* pipe(" hello ", Str.trim); // "hello"
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
Str.trim = (s) => s.trim();
|
|
34
|
-
/**
|
|
35
|
-
* Returns `true` when the string contains the given substring.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```ts
|
|
39
|
-
* pipe("hello world", Str.includes("world")); // true
|
|
40
|
-
* pipe("hello world", Str.includes("xyz")); // false
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
Str.includes = (substring) => (s) => s.includes(substring);
|
|
44
|
-
/**
|
|
45
|
-
* Returns `true` when the string starts with the given prefix.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```ts
|
|
49
|
-
* pipe("hello world", Str.startsWith("hello")); // true
|
|
50
|
-
* pipe("hello world", Str.startsWith("world")); // false
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
Str.startsWith = (prefix) => (s) => s.startsWith(prefix);
|
|
54
|
-
/**
|
|
55
|
-
* Returns `true` when the string ends with the given suffix.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```ts
|
|
59
|
-
* pipe("hello world", Str.endsWith("world")); // true
|
|
60
|
-
* pipe("hello world", Str.endsWith("hello")); // false
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
Str.endsWith = (suffix) => (s) => s.endsWith(suffix);
|
|
64
|
-
/**
|
|
65
|
-
* Converts a string to uppercase.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```ts
|
|
69
|
-
* pipe("hello", Str.toUpperCase); // "HELLO"
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
Str.toUpperCase = (s) => s.toUpperCase();
|
|
73
|
-
/**
|
|
74
|
-
* Converts a string to lowercase.
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```ts
|
|
78
|
-
* pipe("HELLO", Str.toLowerCase); // "hello"
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
Str.toLowerCase = (s) => s.toLowerCase();
|
|
82
|
-
/**
|
|
83
|
-
* Splits a string into lines, normalising `\r\n` and `\r` line endings.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```ts
|
|
87
|
-
* Str.lines("one\ntwo\nthree"); // ["one", "two", "three"]
|
|
88
|
-
* Str.lines("a\r\nb"); // ["a", "b"]
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
Str.lines = (s) => s.split(/\r?\n|\r/);
|
|
92
|
-
/**
|
|
93
|
-
* Splits a string into words on any whitespace boundary, filtering out empty strings.
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```ts
|
|
97
|
-
* Str.words(" hello world "); // ["hello", "world"]
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
Str.words = (s) => s.trim().split(/\s+/).filter(Boolean);
|
|
101
|
-
/**
|
|
102
|
-
* Safe number parsers that return `Option` instead of `NaN`.
|
|
103
|
-
*/
|
|
104
|
-
Str.parse = {
|
|
105
|
-
/**
|
|
106
|
-
* Parses a string as an integer (base 10). Returns `None` if the result is `NaN`.
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```ts
|
|
110
|
-
* Str.parse.int("42"); // Some(42)
|
|
111
|
-
* Str.parse.int("3.7"); // Some(3)
|
|
112
|
-
* Str.parse.int("abc"); // None
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
int: (s) => {
|
|
116
|
-
const n = parseInt(s, 10);
|
|
117
|
-
return isNaN(n) ? Option.none() : Option.some(n);
|
|
118
|
-
},
|
|
119
|
-
/**
|
|
120
|
-
* Parses a string as a floating-point number. Returns `None` if the result is `NaN`.
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```ts
|
|
124
|
-
* Str.parse.float("3.14"); // Some(3.14)
|
|
125
|
-
* Str.parse.float("42"); // Some(42)
|
|
126
|
-
* Str.parse.float("abc"); // None
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
float: (s) => {
|
|
130
|
-
const n = parseFloat(s);
|
|
131
|
-
return isNaN(n) ? Option.none() : Option.some(n);
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
})(Str || (Str = {}));
|
package/esm/src/Utils/index.js
DELETED
package/script/mod.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./src/Composition/index.js"), exports);
|
|
18
|
-
__exportStar(require("./src/Core/index.js"), exports);
|
|
19
|
-
__exportStar(require("./src/Composition/index.js"), exports);
|
package/script/package.json
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.curry4 = exports.curry3 = exports.curry = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Converts a multi-argument function into a curried function.
|
|
6
|
-
* The inverse of `uncurry`.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const add = (a: number, b: number) => a + b;
|
|
11
|
-
* const curriedAdd = curry(add);
|
|
12
|
-
* curriedAdd(1)(2); // 3
|
|
13
|
-
*
|
|
14
|
-
* // Partial application
|
|
15
|
-
* const addTen = curriedAdd(10);
|
|
16
|
-
* addTen(5); // 15
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @see {@link uncurry} for the inverse operation
|
|
20
|
-
* @see {@link curry3} for 3-argument functions
|
|
21
|
-
* @see {@link curry4} for 4-argument functions
|
|
22
|
-
*/
|
|
23
|
-
const curry = (f) => (a) => (b) => f(a, b);
|
|
24
|
-
exports.curry = curry;
|
|
25
|
-
/**
|
|
26
|
-
* Converts a 3-argument function into a curried function.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* const add3 = (a: number, b: number, c: number) => a + b + c;
|
|
31
|
-
* const curriedAdd3 = curry3(add3);
|
|
32
|
-
* curriedAdd3(1)(2)(3); // 6
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
const curry3 = (f) => (a) => (b) => (c) => f(a, b, c);
|
|
36
|
-
exports.curry3 = curry3;
|
|
37
|
-
/**
|
|
38
|
-
* Converts a 4-argument function into a curried function.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* const add4 = (a: number, b: number, c: number, d: number) => a + b + c + d;
|
|
43
|
-
* const curriedAdd4 = curry4(add4);
|
|
44
|
-
* curriedAdd4(1)(2)(3)(4); // 10
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
const curry4 = (f) => (a) => (b) => (c) => (d) => f(a, b, c, d);
|
|
48
|
-
exports.curry4 = curry4;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flip = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Flips the order of arguments for a curried binary function.
|
|
6
|
-
* Converts a data-last function to data-first.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* // Original data-last (for pipe)
|
|
11
|
-
* pipe(
|
|
12
|
-
* Option.some(5),
|
|
13
|
-
* Option.map(n => n * 2)
|
|
14
|
-
* ); // Some(10)
|
|
15
|
-
*
|
|
16
|
-
* // Flipped to data-first
|
|
17
|
-
* const mapFirst = flip(Option.map);
|
|
18
|
-
* mapFirst(Option.some(5))(n => n * 2); // Some(10)
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @see {@link uncurry} for converting curried functions to multi-argument functions
|
|
22
|
-
*/
|
|
23
|
-
const flip = (f) => (b) => (a) => f(a)(b);
|
|
24
|
-
exports.flip = flip;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flow = flow;
|
|
4
|
-
function flow(...fns) {
|
|
5
|
-
return (...args) => {
|
|
6
|
-
if (fns.length === 0)
|
|
7
|
-
return args[0];
|
|
8
|
-
const [first, ...rest] = fns;
|
|
9
|
-
return rest.reduce((acc, fn) => fn(acc), first(...args));
|
|
10
|
-
};
|
|
11
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.once = exports.or = exports.and = exports.constVoid = exports.constUndefined = exports.constNull = exports.constFalse = exports.constTrue = exports.constant = exports.identity = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Returns the value unchanged. The identity function.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* identity(42); // 42
|
|
10
|
-
* pipe(Option.some(5), Option.fold(() => 0, identity)); // 5
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
const identity = (a) => a;
|
|
14
|
-
exports.identity = identity;
|
|
15
|
-
/**
|
|
16
|
-
* Creates a function that always returns the given value, ignoring its argument.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* const always42 = constant(42);
|
|
21
|
-
* always42(); // 42
|
|
22
|
-
* [1, 2, 3].map(constant("x")); // ["x", "x", "x"]
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
const constant = (a) => () => a;
|
|
26
|
-
exports.constant = constant;
|
|
27
|
-
/** Always returns `true`. */
|
|
28
|
-
const constTrue = () => true;
|
|
29
|
-
exports.constTrue = constTrue;
|
|
30
|
-
/** Always returns `false`. */
|
|
31
|
-
const constFalse = () => false;
|
|
32
|
-
exports.constFalse = constFalse;
|
|
33
|
-
/** Always returns `null`. */
|
|
34
|
-
const constNull = () => null;
|
|
35
|
-
exports.constNull = constNull;
|
|
36
|
-
/** Always returns `undefined`. */
|
|
37
|
-
const constUndefined = () => undefined;
|
|
38
|
-
exports.constUndefined = constUndefined;
|
|
39
|
-
/** Always returns `void`. */
|
|
40
|
-
const constVoid = () => { };
|
|
41
|
-
exports.constVoid = constVoid;
|
|
42
|
-
/**
|
|
43
|
-
* Combines two predicates with logical AND.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* const isPositive = (n: number) => n > 0;
|
|
48
|
-
* const isEven = (n: number) => n % 2 === 0;
|
|
49
|
-
* const isPositiveEven = and(isPositive, isEven);
|
|
50
|
-
*
|
|
51
|
-
* isPositiveEven(4); // true
|
|
52
|
-
* isPositiveEven(-2); // false
|
|
53
|
-
* isPositiveEven(3); // false
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
const and = (p1, p2) => (...args) => p1(...args) && p2(...args);
|
|
57
|
-
exports.and = and;
|
|
58
|
-
/**
|
|
59
|
-
* Combines two predicates with logical OR.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```ts
|
|
63
|
-
* const isNegative = (n: number) => n < 0;
|
|
64
|
-
* const isZero = (n: number) => n === 0;
|
|
65
|
-
* const isNonPositive = or(isNegative, isZero);
|
|
66
|
-
*
|
|
67
|
-
* isNonPositive(-1); // true
|
|
68
|
-
* isNonPositive(0); // true
|
|
69
|
-
* isNonPositive(1); // false
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
const or = (p1, p2) => (...args) => p1(...args) || p2(...args);
|
|
73
|
-
exports.or = or;
|
|
74
|
-
/**
|
|
75
|
-
* Creates a function that executes at most once.
|
|
76
|
-
* Subsequent calls return the cached result from the first execution.
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```ts
|
|
80
|
-
* let count = 0;
|
|
81
|
-
* const initOnce = once(() => { count++; return "initialized"; });
|
|
82
|
-
*
|
|
83
|
-
* initOnce(); // "initialized", count === 1
|
|
84
|
-
* initOnce(); // "initialized", count === 1 (not called again)
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
const once = (f) => {
|
|
88
|
-
let called = false;
|
|
89
|
-
let result;
|
|
90
|
-
return () => {
|
|
91
|
-
if (!called) {
|
|
92
|
-
result = f();
|
|
93
|
-
called = true;
|
|
94
|
-
}
|
|
95
|
-
return result;
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
exports.once = once;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./compose.js"), exports);
|
|
18
|
-
__exportStar(require("./converge.js"), exports);
|
|
19
|
-
__exportStar(require("./curry.js"), exports);
|
|
20
|
-
__exportStar(require("./flip.js"), exports);
|
|
21
|
-
__exportStar(require("./fn.js"), exports);
|
|
22
|
-
__exportStar(require("./flow.js"), exports);
|
|
23
|
-
__exportStar(require("./juxt.js"), exports);
|
|
24
|
-
__exportStar(require("./memoize.js"), exports);
|
|
25
|
-
__exportStar(require("./not.js"), exports);
|
|
26
|
-
__exportStar(require("./on.js"), exports);
|
|
27
|
-
__exportStar(require("./pipe.js"), exports);
|
|
28
|
-
__exportStar(require("./tap.js"), exports);
|
|
29
|
-
__exportStar(require("./uncurry.js"), exports);
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.memoizeWeak = exports.memoize = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Creates a memoized version of a function that caches results.
|
|
6
|
-
* Subsequent calls with the same argument return the cached result.
|
|
7
|
-
*
|
|
8
|
-
* By default, uses the argument directly as the cache key.
|
|
9
|
-
* For complex arguments, provide a custom `keyFn` to generate cache keys.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* // Basic usage
|
|
14
|
-
* const expensive = memoize((n: number) => {
|
|
15
|
-
* console.log("Computing...");
|
|
16
|
-
* return n * 2;
|
|
17
|
-
* });
|
|
18
|
-
*
|
|
19
|
-
* expensive(5); // logs "Computing...", returns 10
|
|
20
|
-
* expensive(5); // returns 10 (cached, no log)
|
|
21
|
-
* expensive(3); // logs "Computing...", returns 6
|
|
22
|
-
*
|
|
23
|
-
* // With custom key function for objects
|
|
24
|
-
* const fetchUser = memoize(
|
|
25
|
-
* (opts: { id: string }) => fetch(`/users/${opts.id}`),
|
|
26
|
-
* opts => opts.id
|
|
27
|
-
* );
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
const memoize = (f, keyFn = (a) => a) => {
|
|
31
|
-
const cache = new Map();
|
|
32
|
-
return (a) => {
|
|
33
|
-
const key = keyFn(a);
|
|
34
|
-
if (cache.has(key)) {
|
|
35
|
-
return cache.get(key);
|
|
36
|
-
}
|
|
37
|
-
const result = f(a);
|
|
38
|
-
cache.set(key, result);
|
|
39
|
-
return result;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
exports.memoize = memoize;
|
|
43
|
-
/**
|
|
44
|
-
* Creates a memoized version of a function using WeakMap.
|
|
45
|
-
* Only works with object arguments, but allows garbage collection
|
|
46
|
-
* of cached values when keys are no longer referenced.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* const processUser = memoizeWeak((user: User) => {
|
|
51
|
-
* return expensiveOperation(user);
|
|
52
|
-
* });
|
|
53
|
-
*
|
|
54
|
-
* const user = { id: 1, name: "Alice" };
|
|
55
|
-
* processUser(user); // computed
|
|
56
|
-
* processUser(user); // cached
|
|
57
|
-
* // When `user` is garbage collected, cached result is too
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
const memoizeWeak = (f) => {
|
|
61
|
-
const cache = new WeakMap();
|
|
62
|
-
return (a) => {
|
|
63
|
-
if (cache.has(a)) {
|
|
64
|
-
return cache.get(a);
|
|
65
|
-
}
|
|
66
|
-
const result = f(a);
|
|
67
|
-
cache.set(a, result);
|
|
68
|
-
return result;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
exports.memoizeWeak = memoizeWeak;
|