pepka 0.12.3 → 0.13.0-b10
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 +10 -7
- package/dist/bundle.d.ts +474 -84
- package/dist/bundle.dev.js +114 -73
- package/dist/bundle.js +1 -1
- package/dist/es/curry.js +29 -1
- package/dist/es/index.js +1 -0
- package/dist/es/quick.js +8 -8
- package/dist/es/safe.js +70 -66
- package/dist/es/uncurry.js +3 -0
- package/dist/es/utils.js +1 -0
- package/dts-fix.js +11 -0
- package/package.json +15 -12
- package/rollup.config.js +2 -1
- package/src/curry.ts +55 -11
- package/src/index.ts +1 -0
- package/src/quick.ts +9 -9
- package/src/safe.ts +85 -96
- package/src/types.ts +10 -3
- package/src/uncurry.ts +11 -0
- package/src/utils.ts +1 -0
- package/tsconfig.json +2 -4
package/dist/bundle.dev.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __ = (
|
|
1
|
+
const __ = Symbol('Placeholder');
|
|
2
2
|
const countArgs = (s) => {
|
|
3
3
|
let i = 0;
|
|
4
4
|
for (const v of s)
|
|
@@ -37,10 +37,39 @@ const _curry = (fn, args, new_args) => {
|
|
|
37
37
|
};
|
|
38
38
|
const curry = ((fn) => ((...args) => fn.length > countArgs(args)
|
|
39
39
|
? _curry(fn, [], args)
|
|
40
|
-
: fn(...args)));
|
|
40
|
+
: fn(...args)));
|
|
41
|
+
const endlessph = (fn) => {
|
|
42
|
+
function _endlessph(a) {
|
|
43
|
+
return a === __ ? fn : fn(a);
|
|
44
|
+
}
|
|
45
|
+
return _endlessph;
|
|
46
|
+
};
|
|
47
|
+
function curry2(fn) {
|
|
48
|
+
function curried2(a, b) {
|
|
49
|
+
const withPlaceholder1 = a === __;
|
|
50
|
+
const aln = arguments.length;
|
|
51
|
+
if (aln === 1 && withPlaceholder1)
|
|
52
|
+
throw new Error('Senseless placeholder usage.');
|
|
53
|
+
return arguments.length > 1
|
|
54
|
+
? withPlaceholder1
|
|
55
|
+
? endlessph((a) => fn(a, b))
|
|
56
|
+
: fn(a, b)
|
|
57
|
+
: (b) => fn(a, b);
|
|
58
|
+
}
|
|
59
|
+
return curried2;
|
|
60
|
+
}
|
|
61
|
+
function curry3(fn) {
|
|
62
|
+
// type p0 = Parameters<Func>[0]
|
|
63
|
+
// type p1 = Parameters<Func>[1]
|
|
64
|
+
// type p2 = Parameters<Func>[2]
|
|
65
|
+
// type ReturnT = ReturnType<Func>
|
|
66
|
+
// TODO: optimize.
|
|
67
|
+
return curry(fn);
|
|
68
|
+
}
|
|
41
69
|
|
|
42
70
|
const undef = undefined;
|
|
43
71
|
const nul = null;
|
|
72
|
+
const inf = Infinity;
|
|
44
73
|
const to = (s) => typeof s;
|
|
45
74
|
const isNull = (s) => s === nul;
|
|
46
75
|
const isUndef = (s) => s === undef;
|
|
@@ -63,14 +92,14 @@ const type = (s) => {
|
|
|
63
92
|
: caseMap[t[0]] + t.slice(1);
|
|
64
93
|
};
|
|
65
94
|
|
|
66
|
-
const qappend =
|
|
67
|
-
const qassoc =
|
|
95
|
+
const qappend = curry2((s, xs) => { xs.push(s); return xs; });
|
|
96
|
+
const qassoc = curry3((prop, v, obj) => {
|
|
68
97
|
obj[prop] = v;
|
|
69
98
|
return obj;
|
|
70
99
|
});
|
|
71
|
-
const qreduce =
|
|
100
|
+
const qreduce = curry3((fn, accum, arr) => arr.reduce(fn, accum));
|
|
72
101
|
// strategy is for arrays: 1->clean, 2->merge, 3->push.
|
|
73
|
-
const mergeDeep$1 =
|
|
102
|
+
const mergeDeep$1 = curry3((strategy, o1, o2) => {
|
|
74
103
|
for (let k in o2) {
|
|
75
104
|
switch (type(o2[k])) {
|
|
76
105
|
case 'Array':
|
|
@@ -110,7 +139,7 @@ const qmergeDeep = mergeDeep$1(1);
|
|
|
110
139
|
const qmergeDeepX = mergeDeep$1(2);
|
|
111
140
|
const qmergeDeepAdd = mergeDeep$1(3);
|
|
112
141
|
/** qmapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
|
|
113
|
-
const qmapKeys =
|
|
142
|
+
const qmapKeys = curry2((keyMap, o) => {
|
|
114
143
|
let k, mapped, newKey, newValue;
|
|
115
144
|
for (k in keyMap) {
|
|
116
145
|
mapped = keyMap[k];
|
|
@@ -124,7 +153,7 @@ const qmapKeys = curry((keyMap, o) => {
|
|
|
124
153
|
}
|
|
125
154
|
return o;
|
|
126
155
|
});
|
|
127
|
-
const qfilter =
|
|
156
|
+
const qfilter = curry2((cond, data) => {
|
|
128
157
|
const isArr = isArray(data);
|
|
129
158
|
for (let k in data) {
|
|
130
159
|
if (!cond(data[k], k)) {
|
|
@@ -140,10 +169,13 @@ const qfilter = curry((cond, data) => {
|
|
|
140
169
|
return data;
|
|
141
170
|
});
|
|
142
171
|
/** @deprecated */
|
|
143
|
-
const qindexOf =
|
|
172
|
+
const qindexOf = curry2((x, xs) => xs.indexOf(x));
|
|
173
|
+
|
|
174
|
+
// TODO: possibly introduce a second argument limiting unfolding.
|
|
175
|
+
const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
|
|
144
176
|
|
|
145
177
|
// over, lensProp
|
|
146
|
-
const equals =
|
|
178
|
+
const equals = curry2((a, b) => {
|
|
147
179
|
const typea = type(a);
|
|
148
180
|
if (typea === type(b) && (typea === 'Object' || typea == 'Array')) {
|
|
149
181
|
if (isNull(a) || isNull(b)) {
|
|
@@ -165,16 +197,17 @@ const equals = curry((a, b) => {
|
|
|
165
197
|
return a === b;
|
|
166
198
|
});
|
|
167
199
|
const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
|
|
168
|
-
const when =
|
|
169
|
-
const compose = ((...fns) => (s =
|
|
200
|
+
const when = curry3((cond, pipe, s) => ifElse(cond, pipe, identity, s));
|
|
201
|
+
const compose = ((...fns) => (s = Symbol()) => {
|
|
170
202
|
for (let i = length(fns) - 1; i > -1; i--) {
|
|
171
203
|
s = s === __ ? fns[i]() : fns[i](s);
|
|
172
204
|
}
|
|
173
205
|
return s;
|
|
174
|
-
});
|
|
175
|
-
const bind =
|
|
176
|
-
const
|
|
177
|
-
const
|
|
206
|
+
});
|
|
207
|
+
const bind = curry2((fn, context) => fn.bind(context));
|
|
208
|
+
const _nth = (i, data) => data[i];
|
|
209
|
+
const nth = curry2(_nth);
|
|
210
|
+
const includes = curry2((s, ss) => {
|
|
178
211
|
if (isStr(ss)) {
|
|
179
212
|
return ss.includes(s);
|
|
180
213
|
}
|
|
@@ -187,11 +220,11 @@ const includes = curry((s, ss) => {
|
|
|
187
220
|
return false;
|
|
188
221
|
}
|
|
189
222
|
});
|
|
190
|
-
const slice =
|
|
223
|
+
const slice = curry3((from, to, o) => o.slice(from, (isNum(to) ? to : inf)));
|
|
191
224
|
const head = nth(0);
|
|
192
|
-
const tail = slice(1,
|
|
193
|
-
const add =
|
|
194
|
-
const subtract =
|
|
225
|
+
const tail = slice(1, inf); // typeshit.
|
|
226
|
+
const add = curry2((n, m) => n + m);
|
|
227
|
+
const subtract = curry2((n, m) => m - n);
|
|
195
228
|
const flip = (fn) => curry((b, a) => fn(a, b));
|
|
196
229
|
const isNil = (s) => isNull(s) || isUndef(s);
|
|
197
230
|
const length = (s) => s.length;
|
|
@@ -207,10 +240,10 @@ const complement = (fn) => (...args) => {
|
|
|
207
240
|
const keys = (o) => Object.keys(o);
|
|
208
241
|
const values = (o) => Object.values(o);
|
|
209
242
|
const toPairs = (o) => Object.entries(o);
|
|
210
|
-
const test =
|
|
211
|
-
const tap =
|
|
212
|
-
const append =
|
|
213
|
-
const split =
|
|
243
|
+
const test = curry2((re, s) => re.test(s));
|
|
244
|
+
const tap = curry2((fn, s) => { fn(s); return s; });
|
|
245
|
+
const append = curry2((s, xs) => [...xs, s]);
|
|
246
|
+
const split = curry2((s, xs) => xs.split(s));
|
|
214
247
|
const T = always(true);
|
|
215
248
|
const F = always(false);
|
|
216
249
|
const sizeof = (s) => {
|
|
@@ -223,10 +256,10 @@ const sizeof = (s) => {
|
|
|
223
256
|
else
|
|
224
257
|
return length(s);
|
|
225
258
|
};
|
|
226
|
-
const range =
|
|
259
|
+
const range = curry2((from, to) => genBy(add(from), to - from));
|
|
227
260
|
const uniq = (xs) => qreduce((accum, x) => includes(x, accum) ? accum : qappend(x, accum), [], xs);
|
|
228
|
-
const intersection =
|
|
229
|
-
const genBy =
|
|
261
|
+
const intersection = curry2((xs1, xs2) => xs1.filter(flip(includes)(xs2)));
|
|
262
|
+
const genBy = curry2((generator, length) => [...Array(length)].map((_, i) => generator(i)));
|
|
230
263
|
const once = (fn) => {
|
|
231
264
|
let done = false, cache;
|
|
232
265
|
return (...args) => {
|
|
@@ -240,50 +273,51 @@ const once = (fn) => {
|
|
|
240
273
|
};
|
|
241
274
|
};
|
|
242
275
|
const reverse = (xs) => compose((ln) => reduce((nxs, _, i) => qappend(xs[ln - i], nxs), [], xs), add(-1), length)(xs);
|
|
243
|
-
const gt =
|
|
244
|
-
const lt =
|
|
245
|
-
const gte =
|
|
246
|
-
const lte =
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
const
|
|
250
|
-
const
|
|
251
|
-
const indexOf = curry((x, xs) => findIndex(equals(x), xs));
|
|
276
|
+
const gt = curry2((a, b) => a > b);
|
|
277
|
+
const lt = curry2((a, b) => a < b);
|
|
278
|
+
const gte = curry2((a, b) => b >= a);
|
|
279
|
+
const lte = curry2((a, b) => b <= a);
|
|
280
|
+
const sort = curry2((sortFn, xs) => xs.sort(sortFn));
|
|
281
|
+
const find = curry2((fn, s) => s.find(fn));
|
|
282
|
+
const findIndex = curry2((fn, s) => s.findIndex(fn));
|
|
283
|
+
const indexOf = curry2((x, xs) => findIndex(equals(x), xs));
|
|
252
284
|
const explore = (caption, level = 'log') => tap((v) => console[level](caption, v));
|
|
253
|
-
const cond =
|
|
285
|
+
const cond = curry2((pairs, s) => {
|
|
254
286
|
for (const [cond, fn] of pairs) {
|
|
255
287
|
if (cond(s)) {
|
|
256
288
|
return fn(s);
|
|
257
289
|
}
|
|
258
290
|
}
|
|
259
291
|
});
|
|
260
|
-
const assoc =
|
|
292
|
+
const assoc = curry3((prop, v, obj) => ({
|
|
261
293
|
...obj,
|
|
262
294
|
[prop]: v
|
|
263
295
|
}));
|
|
264
|
-
const assocPath =
|
|
296
|
+
const assocPath = curry3((_path, v, o) => compose((first) => assoc(first, length(_path) < 2
|
|
265
297
|
? v
|
|
266
|
-
: assocPath(slice(1,
|
|
267
|
-
const all =
|
|
268
|
-
const any =
|
|
269
|
-
const allPass =
|
|
270
|
-
const anyPass =
|
|
271
|
-
const prop =
|
|
272
|
-
const propEq =
|
|
273
|
-
const propsEq =
|
|
274
|
-
const pathOr =
|
|
298
|
+
: assocPath(slice(1, inf, _path), v, isObj(o[first]) ? o[first] : {}), o), head)(_path));
|
|
299
|
+
const all = curry2((pred, xs) => xs.every(pred));
|
|
300
|
+
const any = curry2((pred, xs) => xs.some(pred));
|
|
301
|
+
const allPass = curry2((preds, x) => preds.every((pred) => pred(x)));
|
|
302
|
+
const anyPass = curry2((preds, x) => preds.some((pred) => pred(x)));
|
|
303
|
+
const prop = curry2((key, o) => o[key]);
|
|
304
|
+
const propEq = curry3((key, value, o) => equals(o[key], value));
|
|
305
|
+
const propsEq = curry3((key, o1, o2) => equals(o1[key], o2[key]));
|
|
306
|
+
const pathOr = curry3((_default, path, o) => ifElse(length, () => isNil(o)
|
|
275
307
|
? _default
|
|
276
|
-
: compose(ifElse(isNil, always(_default), (o) => pathOr(_default, slice(1,
|
|
308
|
+
: compose(ifElse(isNil, always(_default), (o) => pathOr(_default, slice(1, inf, path), o)), flip(prop)(o), head)(path), always(o), path));
|
|
277
309
|
const path = pathOr(undef);
|
|
278
|
-
const pathEq =
|
|
279
|
-
const pathsEq =
|
|
310
|
+
const pathEq = curry3((_path, value, o) => equals(path(_path, o), value));
|
|
311
|
+
const pathsEq = curry3((_path, o1, o2) => equals(path(_path, o1), path(_path, o2)));
|
|
280
312
|
const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/;
|
|
281
|
-
const clone = (s) => {
|
|
313
|
+
const clone = (s, shallow = false) => {
|
|
282
314
|
const t = type(s);
|
|
283
315
|
switch (t) {
|
|
284
316
|
case 'Null': return s;
|
|
285
|
-
case 'Array': return map(clone, s);
|
|
317
|
+
case 'Array': return shallow ? [...s] : map(clone, s);
|
|
286
318
|
case 'Object':
|
|
319
|
+
if (shallow)
|
|
320
|
+
return { ...s };
|
|
287
321
|
const out = {};
|
|
288
322
|
for (let k in s) {
|
|
289
323
|
out[k] = clone(s[k]);
|
|
@@ -295,12 +329,13 @@ const clone = (s) => {
|
|
|
295
329
|
case 'Symbol':
|
|
296
330
|
return s;
|
|
297
331
|
default:
|
|
298
|
-
return typed_arr_re.test(t) ?
|
|
332
|
+
return typed_arr_re.test(t) ? s.constructor.from(s) : s;
|
|
299
333
|
}
|
|
300
334
|
};
|
|
301
|
-
const
|
|
302
|
-
const
|
|
303
|
-
const
|
|
335
|
+
const cloneShallow = (s) => clone(s, true);
|
|
336
|
+
const reduce = curry3((fn, accum, arr) => qreduce(fn, clone(accum), arr));
|
|
337
|
+
const pickBy = curry2((cond, o) => filter(cond, o));
|
|
338
|
+
const pick = curry2((props, o) => {
|
|
304
339
|
const out = {};
|
|
305
340
|
for (const p of props) {
|
|
306
341
|
if (p in o) {
|
|
@@ -309,13 +344,13 @@ const pick = curry((props, o) => {
|
|
|
309
344
|
}
|
|
310
345
|
return out;
|
|
311
346
|
});
|
|
312
|
-
const omit =
|
|
347
|
+
const omit = curry2((props, o) => filter((_, k) => !includes(k, props), o));
|
|
313
348
|
const fromPairs = (pairs) => reduce((o, pair) => assoc(...pair, o), {}, pairs);
|
|
314
|
-
const concat =
|
|
315
|
-
const join =
|
|
316
|
-
const map =
|
|
317
|
-
const forEach =
|
|
318
|
-
const both =
|
|
349
|
+
const concat = curry2(((a, b) => a.concat(b)));
|
|
350
|
+
const join = curry2((delimeter, arr) => arr.join(delimeter));
|
|
351
|
+
const map = curry2((pipe, arr) => arr.map(pipe));
|
|
352
|
+
const forEach = curry2((pipe, arr) => arr.forEach(pipe));
|
|
353
|
+
const both = curry3((cond1, cond2, s) => cond2(s) && cond1(s));
|
|
319
354
|
const isEmpty = (s) => {
|
|
320
355
|
switch (type(s)) {
|
|
321
356
|
case 'String':
|
|
@@ -335,8 +370,8 @@ const empty = (s) => {
|
|
|
335
370
|
default: return undef;
|
|
336
371
|
}
|
|
337
372
|
};
|
|
338
|
-
const replace =
|
|
339
|
-
const filter =
|
|
373
|
+
const replace = curry3((a, b, where) => where.replace(a, b));
|
|
374
|
+
const filter = curry2((cond, data) => isArray(data)
|
|
340
375
|
? data.filter(cond)
|
|
341
376
|
: compose(fromPairs, filter(([k, v]) => cond(v, k)), toPairs)(data));
|
|
342
377
|
const memoize = (fn) => {
|
|
@@ -344,13 +379,13 @@ const memoize = (fn) => {
|
|
|
344
379
|
let cached = false;
|
|
345
380
|
return () => cached ? cache : (cached = true, cache = fn());
|
|
346
381
|
};
|
|
347
|
-
const mergeShallow =
|
|
348
|
-
const mergeDeep =
|
|
349
|
-
const mergeDeepX =
|
|
350
|
-
const mergeDeepAdd =
|
|
351
|
-
const overProp =
|
|
382
|
+
const mergeShallow = curry2((o1, o2) => Object.assign({}, o1, o2));
|
|
383
|
+
const mergeDeep = curry2((a, b) => qmergeDeep(clone(a), clone(b)));
|
|
384
|
+
const mergeDeepX = curry2((a, b) => qmergeDeepX(clone(a), clone(b)));
|
|
385
|
+
const mergeDeepAdd = curry2((a, b) => qmergeDeepAdd(clone(a), clone(b)));
|
|
386
|
+
const overProp = curry3((prop, pipe, data) => assoc(prop, pipe(data[prop]), data));
|
|
352
387
|
/** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
|
|
353
|
-
const mapKeys =
|
|
388
|
+
const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, Object.assign({}, o)));
|
|
354
389
|
// ASYNCS
|
|
355
390
|
/** One promise waits for another. */
|
|
356
391
|
const forEachSerial = (() => {
|
|
@@ -360,12 +395,13 @@ const forEachSerial = (() => {
|
|
|
360
395
|
await pipe(fn, items, ++i);
|
|
361
396
|
}
|
|
362
397
|
};
|
|
363
|
-
return
|
|
398
|
+
return curry2((fn, items) => pipe(fn, items, 0));
|
|
364
399
|
})();
|
|
365
400
|
/** Promise.all wrapper for functional pipelining. */
|
|
366
401
|
const waitAll = (promises) => Promise.all(promises);
|
|
402
|
+
const waitTap = curry2(async (fn, s) => { await fn(s); return s; });
|
|
367
403
|
/** Waits for all promises mapped by the fn. */
|
|
368
|
-
const forEachAsync =
|
|
404
|
+
const forEachAsync = curry2((fn, items) => Promise.all(items.map(fn)));
|
|
369
405
|
/** The same as compose, but waits for promises in chains and returns a Promise. */
|
|
370
406
|
const composeAsync = (() => {
|
|
371
407
|
const pipe = async (fns, data, i) => ~i ? await pipe(fns, await fns[i](data), --i) : data;
|
|
@@ -422,6 +458,9 @@ var pepka = /*#__PURE__*/Object.freeze({
|
|
|
422
458
|
__proto__: null,
|
|
423
459
|
__: __,
|
|
424
460
|
curry: curry,
|
|
461
|
+
curry2: curry2,
|
|
462
|
+
curry3: curry3,
|
|
463
|
+
uncurry: uncurry,
|
|
425
464
|
toLower: toLower,
|
|
426
465
|
toUpper: toUpper,
|
|
427
466
|
type: type,
|
|
@@ -486,6 +525,7 @@ var pepka = /*#__PURE__*/Object.freeze({
|
|
|
486
525
|
pathEq: pathEq,
|
|
487
526
|
pathsEq: pathsEq,
|
|
488
527
|
clone: clone,
|
|
528
|
+
cloneShallow: cloneShallow,
|
|
489
529
|
reduce: reduce,
|
|
490
530
|
pickBy: pickBy,
|
|
491
531
|
pick: pick,
|
|
@@ -509,6 +549,7 @@ var pepka = /*#__PURE__*/Object.freeze({
|
|
|
509
549
|
mapKeys: mapKeys,
|
|
510
550
|
forEachSerial: forEachSerial,
|
|
511
551
|
waitAll: waitAll,
|
|
552
|
+
waitTap: waitTap,
|
|
512
553
|
forEachAsync: forEachAsync,
|
|
513
554
|
composeAsync: composeAsync,
|
|
514
555
|
mirror: mirror,
|
package/dist/bundle.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";const e=Symbol("Placeholder"),r=r=>{let t=0;for(const s of r)s!==e&&t++;return t},t=(r,t)=>{const s=r.length,o=r.slice(),n=t.length;let p=n,c=0;for(;p&&c<s;c++)o[c]===e&&(o[c]=t[n-p],p--);for(c=s;p;c++,p--)o[c]=t[n-p];return o},s=(e,o,n)=>{const p=e.length-o.length-r(n);if(p<1)return e(...t(o,n));{const r=(...r)=>s(e,t(o,n),r);return r.$args_left=p,r}},o=e=>(...t)=>e.length>r(t)?s(e,[],t):e(...t),n=r=>function(t){return t===e?r:r(t)};function p(r){return function(t,s){const o=t===e,p=arguments.length;if(1===p&&o)throw new Error("Senseless placeholder usage.");return arguments.length>1?o?n((e=>r(e,s))):r(t,s):e=>r(t,e)}}function c(e){return o(e)}const a=void 0,x=1/0,l=e=>typeof e,i=e=>null===e,u=e=>"number"==l(e),f=e=>Array.isArray(e),h=e=>"function"===l(e),m={u:"U",b:"B",n:"N",s:"S",f:"F"},d=e=>{const r=l(e);return"object"===r?i(e)?"Null":e.constructor.name:m[r[0]]+r.slice(1)},y=p(((e,r)=>(r.push(e),r))),g=c(((e,r,t)=>(t[e]=r,t))),b=c(((e,r,t)=>t.reduce(e,r))),w=c(((e,r,t)=>{for(let s in t)switch(d(t[s])){case"Array":if(e>1&&"Array"===d(r[s]))switch(e){case 2:const o=r[s],n=t[s];for(const r in n)o[r]?w(e,o[r],n[r]):o[r]=n[r];break;case 3:r[s].push(...t[s])}else r[s]=t[s];break;case"Object":if("Object"===d(r[s])){w(e,r[s],t[s]);break}default:r[s]=t[s]}return r})),j=w(1),O=w(2),q=w(3),A=p(((e,r)=>{let t,s,o,n;for(t in e)s=e[t],[o,n]=h(s)?s(r):[s,r[t]],r[o]=n,t!==o&&delete r[t];return r})),E=p(((e,r)=>{const t=f(r);for(let s in r)e(r[s],s)||(t?r.splice(s,1):delete r[s]);return r})),S=p(((e,r)=>r.indexOf(e))),k=p(((e,r)=>{const t=d(e);if(t===d(r)&&("Object"===t||"Array"==t)){if(i(e)||i(r))return e===r;if(e===r)return!0;for(const t of[e,r])for(const s in t)if(!(t===r&&s in e||t===e&&s in r&&k(e[s],r[s])))return!1;return!0}return e===r})),P=o(((e,r,t,s)=>e(s)?r(s):t(s))),v=c(((e,r,t)=>P(e,r,X,t))),D=(...r)=>(t=Symbol())=>{for(let s=K(r)-1;s>-1;s--)t=t===e?r[s]():r[s](t);return t},N=p(((e,r)=>e.bind(r))),B=p(((e,r)=>r[e])),_=p(((e,r)=>{if((e=>"string"===l(e))(r))return r.includes(e);for(const t of r)if(k(t,e))return!0;return!1})),C=c(((e,r,t)=>t.slice(e,u(r)?r:x))),T=B(0),U=C(1,x),$=p(((e,r)=>e+r)),z=p(((e,r)=>r-e)),F=e=>o(((r,t)=>e(t,r))),I=e=>i(e)||(e=>e===a)(e),K=e=>e.length,L=e=>()=>e,X=e=>e,G=e=>!e,H=e=>(...r)=>{const t=e(...r);return h(t)&&t.$args_left?H(t):G(t)},J=e=>Object.entries(e),M=p(((e,r)=>e.test(r))),Q=p(((e,r)=>(e(r),r))),R=p(((e,r)=>[...r,e])),V=p(((e,r)=>r.split(e))),W=L(!0),Y=L(!1),Z=p(((e,r)=>re($(e),r-e))),ee=p(((e,r)=>e.filter(F(_)(r)))),re=p(((e,r)=>[...Array(r)].map(((r,t)=>e(t))))),te=p(((e,r)=>e>r)),se=p(((e,r)=>e<r)),oe=p(((e,r)=>r>=e)),ne=p(((e,r)=>r<=e)),pe=p(((e,r)=>r.sort(e))),ce=p(((e,r)=>r.find(e))),ae=p(((e,r)=>r.findIndex(e))),xe=p(((e,r)=>ae(k(e),r))),le=p(((e,r)=>{for(const[t,s]of e)if(t(r))return s(r)})),ie=c(((e,r,t)=>({...t,[e]:r}))),ue=c(((e,r,t)=>D((s=>{return ie(s,K(e)<2?r:ue(C(1,x,e),r,(o=t[s],i(o)||"object"!==l(o)?{}:t[s])),t);var o}),T)(e))),fe=p(((e,r)=>r.every(e))),he=p(((e,r)=>r.some(e))),me=p(((e,r)=>e.every((e=>e(r))))),de=p(((e,r)=>e.some((e=>e(r))))),ye=p(((e,r)=>r[e])),ge=c(((e,r,t)=>k(t[e],r))),be=c(((e,r,t)=>k(r[e],t[e]))),we=c(((e,r,t)=>P(K,(()=>I(t)?e:D(P(I,L(e),(t=>we(e,C(1,x,r),t))),F(ye)(t),T)(r)),L(t),r))),je=we(a),Oe=c(((e,r,t)=>k(je(e,t),r))),qe=c(((e,r,t)=>k(je(e,r),je(e,t)))),Ae=/^(.*?)(8|16|32|64)(Clamped)?Array$/,Ee=(e,r=!1)=>{const t=d(e);switch(t){case"Null":case"String":case"Number":case"Boolean":case"Symbol":return e;case"Array":return r?[...e]:_e(Ee,e);case"Object":if(r)return{...e};const s={};for(let r in e)s[r]=Ee(e[r]);return s;default:return Ae.test(t)?e.constructor.from(e):e}},Se=c(((e,r,t)=>b(e,Ee(r),t))),ke=p(((e,r)=>$e(e,r))),Pe=p(((e,r)=>{const t={};for(const s of e)s in r&&(t[s]=r[s]);return t})),ve=p(((e,r)=>$e(((r,t)=>!_(t,e)),r))),De=e=>Se(((e,r)=>ie(...r,e)),{},e),Ne=p(((e,r)=>e.concat(r))),Be=p(((e,r)=>r.join(e))),_e=p(((e,r)=>r.map(e))),Ce=p(((e,r)=>r.forEach(e))),Te=c(((e,r,t)=>r(t)&&e(t))),Ue=c(((e,r,t)=>t.replace(e,r))),$e=p(((e,r)=>f(r)?r.filter(e):D(De,$e((([r,t])=>e(t,r))),J)(r))),ze=p(((e,r)=>Object.assign({},e,r))),Fe=p(((e,r)=>j(Ee(e),Ee(r)))),Ie=p(((e,r)=>O(Ee(e),Ee(r)))),Ke=p(((e,r)=>q(Ee(e),Ee(r)))),Le=c(((e,r,t)=>ie(e,r(t[e]),t))),Xe=p(((e,r)=>A(e,Object.assign({},r)))),Ge=(()=>{const e=async(r,t,s)=>{s<t.length&&(await r(t[s]),await e(r,t,++s))};return p(((r,t)=>e(r,t,0)))})(),He=p((async(e,r)=>(await e(r),r))),Je=p(((e,r)=>Promise.all(r.map(e)))),Me=(()=>{const e=async(r,t,s)=>~s?await e(r,await r[s](t),--s):t;return(...r)=>t=>e(r,t,r.length-1)})(),Qe=X,Re=X,Ve=X;exports.F=Y,exports.T=W,exports.__=e,exports.add=$,exports.all=fe,exports.allPass=me,exports.always=L,exports.any=he,exports.anyPass=de,exports.append=R,exports.assoc=ie,exports.assocPath=ue,exports.bind=N,exports.both=Te,exports.clone=Ee,exports.cloneShallow=e=>Ee(e,!0),exports.complement=H,exports.compose=D,exports.composeAsync=Me,exports.concat=Ne,exports.cond=le,exports.curry=o,exports.curry2=p,exports.curry3=c,exports.echo=Ve,exports.empty=e=>{switch(d(e)){case"String":return"";case"Object":return{};case"Array":return[];default:return a}},exports.equals=k,exports.explore=(e,r="log")=>Q((t=>console[r](e,t))),exports.filter=$e,exports.find=ce,exports.findIndex=ae,exports.flip=F,exports.forEach=Ce,exports.forEachAsync=Je,exports.forEachSerial=Ge,exports.fromPairs=De,exports.genBy=re,exports.getTmpl=e=>{const r=[],t=[],s=e.length;let o,n,p=0,c=0,a=!1;for(p=0;p<s;p++)switch(o=e[p],o){case"{":a=!0,c=p;break;case"}":a=!1,r.push(""),t.push(e.slice(c+1,p));break;default:a||(n=r.length-1,n<0&&(r.push(""),n++),r[n]+=o)}return e=>{const s=[],o=r.length-1;for(const n in r)p=+n,s.push(r[p]),p!==o&&s.push(je(t[p].split("."),e));return s.join("")}},exports.gt=te,exports.gte=oe,exports.head=T,exports.identity=X,exports.ifElse=P,exports.includes=_,exports.indexOf=xe,exports.intersection=ee,exports.isEmpty=e=>{switch(d(e)){case"String":case"Array":return 0==K(e);case"Object":for(const r in e)return!1;return!0;default:return null}},exports.isNil=I,exports.join=Be,exports.keys=e=>Object.keys(e),exports.last=e=>e[K(e)-1],exports.length=K,exports.lt=se,exports.lte=ne,exports.map=_e,exports.mapKeys=Xe,exports.memoize=e=>{let r,t=!1;return()=>t?r:(t=!0,r=e())},exports.mergeDeep=Fe,exports.mergeDeepAdd=Ke,exports.mergeDeepX=Ie,exports.mergeShallow=ze,exports.mirror=Qe,exports.not=G,exports.nth=B,exports.omit=ve,exports.once=e=>{let r,t=!1;return(...s)=>t?r:(t=!0,r=e(...s))},exports.overProp=Le,exports.path=je,exports.pathEq=Oe,exports.pathOr=we,exports.pathsEq=qe,exports.pick=Pe,exports.pickBy=ke,exports.prop=ye,exports.propEq=ge,exports.propsEq=be,exports.qappend=y,exports.qassoc=g,exports.qfilter=E,exports.qindexOf=S,exports.qmapKeys=A,exports.qmergeDeep=j,exports.qmergeDeepAdd=q,exports.qmergeDeepX=O,exports.qreduce=b,exports.range=Z,exports.reduce=Se,exports.reflect=Re,exports.replace=Ue,exports.reverse=e=>D((r=>Se(((t,s,o)=>y(e[r-o],t)),[],e)),$(-1),K)(e),exports.sizeof=e=>{if("Object"===d(e)){let r=0;for(let t in e)r++;return r}return K(e)},exports.slice=C,exports.sort=pe,exports.split=V,exports.subtract=z,exports.tail=U,exports.tap=Q,exports.test=M,exports.toLower=e=>e.toLowerCase(),exports.toPairs=J,exports.toUpper=e=>e.toUpperCase(),exports.trim=e=>e.trim(),exports.type=d,exports.uncurry=e=>(...r)=>b(((e,r)=>e?e(r):e),e,r),exports.uniq=e=>b(((e,r)=>_(r,e)?e:y(r,e)),[],e),exports.values=e=>Object.values(e),exports.waitAll=e=>Promise.all(e),exports.waitTap=He,exports.when=v;
|
package/dist/es/curry.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const __ = (
|
|
1
|
+
export const __ = Symbol('Placeholder');
|
|
2
2
|
const countArgs = (s) => {
|
|
3
3
|
let i = 0;
|
|
4
4
|
for (const v of s)
|
|
@@ -38,3 +38,31 @@ const _curry = (fn, args, new_args) => {
|
|
|
38
38
|
export const curry = ((fn) => ((...args) => fn.length > countArgs(args)
|
|
39
39
|
? _curry(fn, [], args)
|
|
40
40
|
: fn(...args)));
|
|
41
|
+
const endlessph = (fn) => {
|
|
42
|
+
function _endlessph(a) {
|
|
43
|
+
return a === __ ? fn : fn(a);
|
|
44
|
+
}
|
|
45
|
+
return _endlessph;
|
|
46
|
+
};
|
|
47
|
+
export function curry2(fn) {
|
|
48
|
+
function curried2(a, b) {
|
|
49
|
+
const withPlaceholder1 = a === __;
|
|
50
|
+
const aln = arguments.length;
|
|
51
|
+
if (aln === 1 && withPlaceholder1)
|
|
52
|
+
throw new Error('Senseless placeholder usage.');
|
|
53
|
+
return arguments.length > 1
|
|
54
|
+
? withPlaceholder1
|
|
55
|
+
? endlessph((a) => fn(a, b))
|
|
56
|
+
: fn(a, b)
|
|
57
|
+
: (b) => fn(a, b);
|
|
58
|
+
}
|
|
59
|
+
return curried2;
|
|
60
|
+
}
|
|
61
|
+
export function curry3(fn) {
|
|
62
|
+
// type p0 = Parameters<Func>[0]
|
|
63
|
+
// type p1 = Parameters<Func>[1]
|
|
64
|
+
// type p2 = Parameters<Func>[2]
|
|
65
|
+
// type ReturnT = ReturnType<Func>
|
|
66
|
+
// TODO: optimize.
|
|
67
|
+
return curry(fn);
|
|
68
|
+
}
|
package/dist/es/index.js
CHANGED
package/dist/es/quick.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { curry2, curry3 } from "./curry";
|
|
2
2
|
import { type } from "./common";
|
|
3
3
|
import { isFunc, isArray } from "./utils";
|
|
4
|
-
export const qappend =
|
|
5
|
-
export const qassoc =
|
|
4
|
+
export const qappend = curry2((s, xs) => { xs.push(s); return xs; });
|
|
5
|
+
export const qassoc = curry3((prop, v, obj) => {
|
|
6
6
|
obj[prop] = v;
|
|
7
7
|
return obj;
|
|
8
8
|
});
|
|
9
|
-
export const qreduce =
|
|
9
|
+
export const qreduce = curry3((fn, accum, arr) => arr.reduce(fn, accum));
|
|
10
10
|
// strategy is for arrays: 1->clean, 2->merge, 3->push.
|
|
11
|
-
const mergeDeep =
|
|
11
|
+
const mergeDeep = curry3((strategy, o1, o2) => {
|
|
12
12
|
for (let k in o2) {
|
|
13
13
|
switch (type(o2[k])) {
|
|
14
14
|
case 'Array':
|
|
@@ -49,7 +49,7 @@ export const qmergeDeep = mergeDeep(1);
|
|
|
49
49
|
export const qmergeDeepX = mergeDeep(2);
|
|
50
50
|
export const qmergeDeepAdd = mergeDeep(3);
|
|
51
51
|
/** qmapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
|
|
52
|
-
export const qmapKeys =
|
|
52
|
+
export const qmapKeys = curry2((keyMap, o) => {
|
|
53
53
|
let k, mapped, newKey, newValue;
|
|
54
54
|
for (k in keyMap) {
|
|
55
55
|
mapped = keyMap[k];
|
|
@@ -63,7 +63,7 @@ export const qmapKeys = curry((keyMap, o) => {
|
|
|
63
63
|
}
|
|
64
64
|
return o;
|
|
65
65
|
});
|
|
66
|
-
export const qfilter =
|
|
66
|
+
export const qfilter = curry2((cond, data) => {
|
|
67
67
|
const isArr = isArray(data);
|
|
68
68
|
for (let k in data) {
|
|
69
69
|
if (!cond(data[k], k)) {
|
|
@@ -79,4 +79,4 @@ export const qfilter = curry((cond, data) => {
|
|
|
79
79
|
return data;
|
|
80
80
|
});
|
|
81
81
|
/** @deprecated */
|
|
82
|
-
export const qindexOf =
|
|
82
|
+
export const qindexOf = curry2((x, xs) => xs.indexOf(x));
|