1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | function F() {
|
6 | return false;
|
7 | }
|
8 |
|
9 | function T() {
|
10 | return true;
|
11 | }
|
12 |
|
13 | function add(a, b) {
|
14 | if (arguments.length === 1) return _b => add(a, _b);
|
15 | return Number(a) + Number(b);
|
16 | }
|
17 |
|
18 | function curry(fn, args = []) {
|
19 | return (..._args) => (rest => rest.length >= fn.length ? fn(...rest) : curry(fn, rest))([...args, ..._args]);
|
20 | }
|
21 |
|
22 | function adjustFn(index, replaceFn, list) {
|
23 | const actualIndex = index < 0 ? list.length + index : index;
|
24 | if (index >= list.length || actualIndex < 0) return list;
|
25 | const clone = list.slice();
|
26 | clone[actualIndex] = replaceFn(clone[actualIndex]);
|
27 | return clone;
|
28 | }
|
29 |
|
30 | const adjust = curry(adjustFn);
|
31 |
|
32 | function all(predicate, list) {
|
33 | if (arguments.length === 1) return _list => all(predicate, _list);
|
34 |
|
35 | for (let i = 0; i < list.length; i++) {
|
36 | if (!predicate(list[i])) return false;
|
37 | }
|
38 |
|
39 | return true;
|
40 | }
|
41 |
|
42 | function allPass(predicates) {
|
43 | return input => {
|
44 | let counter = 0;
|
45 |
|
46 | while (counter < predicates.length) {
|
47 | if (!predicates[counter](input)) {
|
48 | return false;
|
49 | }
|
50 |
|
51 | counter++;
|
52 | }
|
53 |
|
54 | return true;
|
55 | };
|
56 | }
|
57 |
|
58 | function always(x) {
|
59 | return () => x;
|
60 | }
|
61 |
|
62 | function and(a, b) {
|
63 | if (arguments.length === 1) return _b => and(a, _b);
|
64 | return a && b;
|
65 | }
|
66 |
|
67 | function any(predicate, list) {
|
68 | if (arguments.length === 1) return _list => any(predicate, _list);
|
69 | let counter = 0;
|
70 |
|
71 | while (counter < list.length) {
|
72 | if (predicate(list[counter], counter)) {
|
73 | return true;
|
74 | }
|
75 |
|
76 | counter++;
|
77 | }
|
78 |
|
79 | return false;
|
80 | }
|
81 |
|
82 | function anyPass(predicates) {
|
83 | return input => {
|
84 | let counter = 0;
|
85 |
|
86 | while (counter < predicates.length) {
|
87 | if (predicates[counter](input)) {
|
88 | return true;
|
89 | }
|
90 |
|
91 | counter++;
|
92 | }
|
93 |
|
94 | return false;
|
95 | };
|
96 | }
|
97 |
|
98 | function append(x, input) {
|
99 | if (arguments.length === 1) return _input => append(x, _input);
|
100 | if (typeof input === 'string') return input.split('').concat(x);
|
101 | const clone = input.slice();
|
102 | clone.push(x);
|
103 | return clone;
|
104 | }
|
105 |
|
106 | const _isArray = Array.isArray;
|
107 |
|
108 | function __findHighestArity(spec, max = 0) {
|
109 | for (const key in spec) {
|
110 | if (spec.hasOwnProperty(key) === false || key === 'constructor') continue;
|
111 |
|
112 | if (typeof spec[key] === 'object') {
|
113 | max = Math.max(max, __findHighestArity(spec[key]));
|
114 | }
|
115 |
|
116 | if (typeof spec[key] === 'function') {
|
117 | max = Math.max(max, spec[key].length);
|
118 | }
|
119 | }
|
120 |
|
121 | return max;
|
122 | }
|
123 |
|
124 | function __filterUndefined() {
|
125 | const defined = [];
|
126 | let i = 0;
|
127 | const l = arguments.length;
|
128 |
|
129 | while (i < l) {
|
130 | if (typeof arguments[i] === 'undefined') break;
|
131 | defined[i] = arguments[i];
|
132 | i++;
|
133 | }
|
134 |
|
135 | return defined;
|
136 | }
|
137 |
|
138 | function __applySpecWithArity(spec, arity, cache) {
|
139 | const remaining = arity - cache.length;
|
140 | if (remaining === 1) return x => __applySpecWithArity(spec, arity, __filterUndefined(...cache, x));
|
141 | if (remaining === 2) return (x, y) => __applySpecWithArity(spec, arity, __filterUndefined(...cache, x, y));
|
142 | if (remaining === 3) return (x, y, z) => __applySpecWithArity(spec, arity, __filterUndefined(...cache, x, y, z));
|
143 | if (remaining === 4) return (x, y, z, a) => __applySpecWithArity(spec, arity, __filterUndefined(...cache, x, y, z, a));
|
144 | if (remaining > 4) return (...args) => __applySpecWithArity(spec, arity, __filterUndefined(...cache, ...args));
|
145 |
|
146 | if (_isArray(spec)) {
|
147 | const ret = [];
|
148 | let i = 0;
|
149 | const l = spec.length;
|
150 |
|
151 | for (; i < l; i++) {
|
152 | if (typeof spec[i] === 'object' || _isArray(spec[i])) {
|
153 | ret[i] = __applySpecWithArity(spec[i], arity, cache);
|
154 | }
|
155 |
|
156 | if (typeof spec[i] === 'function') {
|
157 | ret[i] = spec[i](...cache);
|
158 | }
|
159 | }
|
160 |
|
161 | return ret;
|
162 | }
|
163 |
|
164 | const ret = {};
|
165 |
|
166 | for (const key in spec) {
|
167 | if (spec.hasOwnProperty(key) === false || key === 'constructor') continue;
|
168 |
|
169 | if (typeof spec[key] === 'object') {
|
170 | ret[key] = __applySpecWithArity(spec[key], arity, cache);
|
171 | continue;
|
172 | }
|
173 |
|
174 | if (typeof spec[key] === 'function') {
|
175 | ret[key] = spec[key](...cache);
|
176 | }
|
177 | }
|
178 |
|
179 | return ret;
|
180 | }
|
181 |
|
182 | function applySpec(spec, ...args) {
|
183 | const arity = __findHighestArity(spec);
|
184 |
|
185 | if (arity === 0) {
|
186 | return () => ({});
|
187 | }
|
188 |
|
189 | const toReturn = __applySpecWithArity(spec, arity, args);
|
190 |
|
191 | return toReturn;
|
192 | }
|
193 |
|
194 | function assocFn(prop, newValue, obj) {
|
195 | return Object.assign({}, obj, {
|
196 | [prop]: newValue
|
197 | });
|
198 | }
|
199 |
|
200 | const assoc = curry(assocFn);
|
201 |
|
202 | function _isInteger(n) {
|
203 | return n << 0 === n;
|
204 | }
|
205 | var _isInteger$1 = Number.isInteger || _isInteger;
|
206 |
|
207 | function assocPathFn(path, newValue, input) {
|
208 | const pathArrValue = typeof path === 'string' ? path.split('.').map(x => _isInteger(Number(x)) ? Number(x) : x) : path;
|
209 |
|
210 | if (pathArrValue.length === 0) {
|
211 | return newValue;
|
212 | }
|
213 |
|
214 | const index = pathArrValue[0];
|
215 |
|
216 | if (pathArrValue.length > 1) {
|
217 | const condition = typeof input !== 'object' || input === null || !input.hasOwnProperty(index);
|
218 | const nextinput = condition ? _isInteger(pathArrValue[1]) ? [] : {} : input[index];
|
219 | newValue = assocPathFn(Array.prototype.slice.call(pathArrValue, 1), newValue, nextinput);
|
220 | }
|
221 |
|
222 | if (_isInteger(index) && _isArray(input)) {
|
223 | const arr = input.slice();
|
224 | arr[index] = newValue;
|
225 | return arr;
|
226 | }
|
227 |
|
228 | return assoc(index, newValue, input);
|
229 | }
|
230 |
|
231 | const assocPath = curry(assocPathFn);
|
232 |
|
233 | function both(f, g) {
|
234 | if (arguments.length === 1) return _g => both(f, _g);
|
235 | return (...input) => f(...input) && g(...input);
|
236 | }
|
237 |
|
238 | function chain(fn, list) {
|
239 | if (arguments.length === 1) {
|
240 | return _list => chain(fn, _list);
|
241 | }
|
242 |
|
243 | return [].concat(...list.map(fn));
|
244 | }
|
245 |
|
246 | function clampFn(min, max, input) {
|
247 | if (min > max) {
|
248 | throw new Error('min must not be greater than max in clamp(min, max, value)');
|
249 | }
|
250 |
|
251 | if (input >= min && input <= max) return input;
|
252 | if (input > max) return max;
|
253 | if (input < min) return min;
|
254 | }
|
255 |
|
256 | const clamp = curry(clampFn);
|
257 |
|
258 | function clone(input) {
|
259 | const out = _isArray(input) ? Array(input.length) : {};
|
260 | if (input && input.getTime) return new Date(input.getTime());
|
261 |
|
262 | for (const key in input) {
|
263 | const v = input[key];
|
264 | out[key] = typeof v === 'object' && v !== null ? v.getTime ? new Date(v.getTime()) : clone(v) : v;
|
265 | }
|
266 |
|
267 | return out;
|
268 | }
|
269 |
|
270 | function complement(fn) {
|
271 | return (...input) => !fn(...input);
|
272 | }
|
273 |
|
274 | function compose(...fns) {
|
275 | if (fns.length === 0) {
|
276 | throw new Error('compose requires at least one argument');
|
277 | }
|
278 |
|
279 | return (...args) => {
|
280 | const list = fns.slice();
|
281 |
|
282 | if (list.length > 0) {
|
283 | const fn = list.pop();
|
284 | let result = fn(...args);
|
285 |
|
286 | while (list.length > 0) {
|
287 | result = list.pop()(result);
|
288 | }
|
289 |
|
290 | return result;
|
291 | }
|
292 | };
|
293 | }
|
294 |
|
295 | function concat(x, y) {
|
296 | if (arguments.length === 1) return _y => concat(x, _y);
|
297 | return typeof x === 'string' ? `${x}${y}` : [...x, ...y];
|
298 | }
|
299 |
|
300 | function cond(conditions) {
|
301 | return input => {
|
302 | let done = false;
|
303 | let toReturn;
|
304 | conditions.forEach(([predicate, resultClosure]) => {
|
305 | if (!done && predicate(input)) {
|
306 | done = true;
|
307 | toReturn = resultClosure(input);
|
308 | }
|
309 | });
|
310 | return toReturn;
|
311 | };
|
312 | }
|
313 |
|
314 | function _curryN(n, cache, fn) {
|
315 | return function () {
|
316 | let ci = 0;
|
317 | let ai = 0;
|
318 | const cl = cache.length;
|
319 | const al = arguments.length;
|
320 | const args = new Array(cl + al);
|
321 |
|
322 | while (ci < cl) {
|
323 | args[ci] = cache[ci];
|
324 | ci++;
|
325 | }
|
326 |
|
327 | while (ai < al) {
|
328 | args[cl + ai] = arguments[ai];
|
329 | ai++;
|
330 | }
|
331 |
|
332 | const remaining = n - args.length;
|
333 | return args.length >= n ? fn.apply(this, args) : _arity(remaining, _curryN(n, args, fn));
|
334 | };
|
335 | }
|
336 |
|
337 | function _arity(n, fn) {
|
338 | switch (n) {
|
339 | case 0:
|
340 | return function () {
|
341 | return fn.apply(this, arguments);
|
342 | };
|
343 |
|
344 | case 1:
|
345 | return function (_1) {
|
346 | return fn.apply(this, arguments);
|
347 | };
|
348 |
|
349 | case 2:
|
350 | return function (_1, _2) {
|
351 | return fn.apply(this, arguments);
|
352 | };
|
353 |
|
354 | case 3:
|
355 | return function (_1, _2, _3) {
|
356 | return fn.apply(this, arguments);
|
357 | };
|
358 |
|
359 | case 4:
|
360 | return function (_1, _2, _3, _4) {
|
361 | return fn.apply(this, arguments);
|
362 | };
|
363 |
|
364 | case 5:
|
365 | return function (_1, _2, _3, _4, _5) {
|
366 | return fn.apply(this, arguments);
|
367 | };
|
368 |
|
369 | case 6:
|
370 | return function (_1, _2, _3, _4, _5, _6) {
|
371 | return fn.apply(this, arguments);
|
372 | };
|
373 |
|
374 | case 7:
|
375 | return function (_1, _2, _3, _4, _5, _6, _7) {
|
376 | return fn.apply(this, arguments);
|
377 | };
|
378 |
|
379 | case 8:
|
380 | return function (_1, _2, _3, _4, _5, _6, _7, _8) {
|
381 | return fn.apply(this, arguments);
|
382 | };
|
383 |
|
384 | case 9:
|
385 | return function (_1, _2, _3, _4, _5, _6, _7, _8, _9) {
|
386 | return fn.apply(this, arguments);
|
387 | };
|
388 |
|
389 | default:
|
390 | return function (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) {
|
391 | return fn.apply(this, arguments);
|
392 | };
|
393 | }
|
394 | }
|
395 |
|
396 | function curryN(n, fn) {
|
397 | if (arguments.length === 1) return _fn => curryN(n, _fn);
|
398 |
|
399 | if (n > 10) {
|
400 | throw new Error('First argument to _arity must be a non-negative integer no greater than ten');
|
401 | }
|
402 |
|
403 | return _arity(n, _curryN(n, [], fn));
|
404 | }
|
405 |
|
406 | const _keys = Object.keys;
|
407 |
|
408 | function mapArray(fn, list, isIndexed = false) {
|
409 | let index = 0;
|
410 | const willReturn = Array(list.length);
|
411 |
|
412 | while (index < list.length) {
|
413 | willReturn[index] = isIndexed ? fn(list[index], index) : fn(list[index]);
|
414 | index++;
|
415 | }
|
416 |
|
417 | return willReturn;
|
418 | }
|
419 | function mapObject(fn, obj) {
|
420 | let index = 0;
|
421 |
|
422 | const keys = _keys(obj);
|
423 |
|
424 | const len = keys.length;
|
425 | const willReturn = {};
|
426 |
|
427 | while (index < len) {
|
428 | const key = keys[index];
|
429 | willReturn[key] = fn(obj[key], key, obj);
|
430 | index++;
|
431 | }
|
432 |
|
433 | return willReturn;
|
434 | }
|
435 | function map(fn, list) {
|
436 | if (arguments.length === 1) return _list => map(fn, _list);
|
437 | if (list === undefined) return [];
|
438 | if (_isArray(list)) return mapArray(fn, list);
|
439 | return mapObject(fn, list);
|
440 | }
|
441 |
|
442 | function max(x, y) {
|
443 | if (arguments.length === 1) return _y => max(x, _y);
|
444 | return y > x ? y : x;
|
445 | }
|
446 |
|
447 | function reduceFn(reducer, acc, list) {
|
448 | if (!_isArray(list)) {
|
449 | throw new TypeError('reduce: list must be array or iterable');
|
450 | }
|
451 |
|
452 | let index = 0;
|
453 | const len = list.length;
|
454 |
|
455 | while (index < len) {
|
456 | acc = reducer(acc, list[index], index, list);
|
457 | index++;
|
458 | }
|
459 |
|
460 | return acc;
|
461 | }
|
462 |
|
463 | const reduce = curry(reduceFn);
|
464 |
|
465 | function converge(fn, transformers) {
|
466 | if (arguments.length === 1) return _transformers => converge(fn, _transformers);
|
467 | const highestArity = reduce((a, b) => max(a, b.length), 0, transformers);
|
468 | return curryN(highestArity, function () {
|
469 | return fn.apply(this, map(g => g.apply(this, arguments), transformers));
|
470 | });
|
471 | }
|
472 |
|
473 | const dec = x => x - 1;
|
474 |
|
475 | function isFalsy(input) {
|
476 | return input === undefined || input === null || Number.isNaN(input) === true;
|
477 | }
|
478 |
|
479 | function defaultTo(defaultArgument, input) {
|
480 | if (arguments.length === 1) {
|
481 | return _input => defaultTo(defaultArgument, _input);
|
482 | }
|
483 |
|
484 | return isFalsy(input) ? defaultArgument : input;
|
485 | }
|
486 |
|
487 | function type(input) {
|
488 | const typeOf = typeof input;
|
489 |
|
490 | if (input === null) {
|
491 | return 'Null';
|
492 | } else if (input === undefined) {
|
493 | return 'Undefined';
|
494 | } else if (typeOf === 'boolean') {
|
495 | return 'Boolean';
|
496 | } else if (typeOf === 'number') {
|
497 | return Number.isNaN(input) ? 'NaN' : 'Number';
|
498 | } else if (typeOf === 'string') {
|
499 | return 'String';
|
500 | } else if (_isArray(input)) {
|
501 | return 'Array';
|
502 | } else if (typeOf === 'symbol') {
|
503 | return 'Symbol';
|
504 | } else if (input instanceof RegExp) {
|
505 | return 'RegExp';
|
506 | }
|
507 |
|
508 | const asStr = input && input.toString ? input.toString() : '';
|
509 | if (['true', 'false'].includes(asStr)) return 'Boolean';
|
510 | if (!Number.isNaN(Number(asStr))) return 'Number';
|
511 | if (asStr.startsWith('async')) return 'Async';
|
512 | if (asStr === '[object Promise]') return 'Promise';
|
513 | if (typeOf === 'function') return 'Function';
|
514 | if (input instanceof String) return 'String';
|
515 | return 'Object';
|
516 | }
|
517 |
|
518 | function parseError(maybeError) {
|
519 | const typeofError = maybeError.__proto__.toString();
|
520 |
|
521 | if (!['Error', 'TypeError'].includes(typeofError)) return [];
|
522 | return [typeofError, maybeError.message];
|
523 | }
|
524 |
|
525 | function parseDate(maybeDate) {
|
526 | if (!maybeDate.toDateString) return [false];
|
527 | return [true, maybeDate.getTime()];
|
528 | }
|
529 |
|
530 | function parseRegex(maybeRegex) {
|
531 | if (maybeRegex.constructor !== RegExp) return [false];
|
532 | return [true, maybeRegex.toString()];
|
533 | }
|
534 |
|
535 | function equals(a, b) {
|
536 | if (arguments.length === 1) return _b => equals(a, _b);
|
537 | const aType = type(a);
|
538 | if (aType !== type(b)) return false;
|
539 |
|
540 | if (aType === 'Function') {
|
541 | return a.name === undefined ? false : a.name === b.name;
|
542 | }
|
543 |
|
544 | if (['NaN', 'Undefined', 'Null'].includes(aType)) return true;
|
545 |
|
546 | if (aType === 'Number') {
|
547 | if (Object.is(-0, a) !== Object.is(-0, b)) return false;
|
548 | return a.toString() === b.toString();
|
549 | }
|
550 |
|
551 | if (['String', 'Boolean'].includes(aType)) {
|
552 | return a.toString() === b.toString();
|
553 | }
|
554 |
|
555 | if (aType === 'Array') {
|
556 | const aClone = Array.from(a);
|
557 | const bClone = Array.from(b);
|
558 |
|
559 | if (aClone.toString() !== bClone.toString()) {
|
560 | return false;
|
561 | }
|
562 |
|
563 | let loopArrayFlag = true;
|
564 | aClone.forEach((aCloneInstance, aCloneIndex) => {
|
565 | if (loopArrayFlag) {
|
566 | if (aCloneInstance !== bClone[aCloneIndex] && !equals(aCloneInstance, bClone[aCloneIndex])) {
|
567 | loopArrayFlag = false;
|
568 | }
|
569 | }
|
570 | });
|
571 | return loopArrayFlag;
|
572 | }
|
573 |
|
574 | const aRegex = parseRegex(a);
|
575 | const bRegex = parseRegex(b);
|
576 |
|
577 | if (aRegex[0]) {
|
578 | return bRegex[0] ? aRegex[1] === bRegex[1] : false;
|
579 | } else if (bRegex[0]) return false;
|
580 |
|
581 | const aDate = parseDate(a);
|
582 | const bDate = parseDate(b);
|
583 |
|
584 | if (aDate[0]) {
|
585 | return bDate[0] ? aDate[1] === bDate[1] : false;
|
586 | } else if (bDate[0]) return false;
|
587 |
|
588 | const aError = parseError(a);
|
589 | const bError = parseError(b);
|
590 |
|
591 | if (aError[0]) {
|
592 | return bError[0] ? aError[0] === bError[0] && aError[1] === bError[1] : false;
|
593 | }
|
594 |
|
595 | if (aType === 'Object') {
|
596 | const aKeys = Object.keys(a);
|
597 |
|
598 | if (aKeys.length !== Object.keys(b).length) {
|
599 | return false;
|
600 | }
|
601 |
|
602 | let loopObjectFlag = true;
|
603 | aKeys.forEach(aKeyInstance => {
|
604 | if (loopObjectFlag) {
|
605 | const aValue = a[aKeyInstance];
|
606 | const bValue = b[aKeyInstance];
|
607 |
|
608 | if (aValue !== bValue && !equals(aValue, bValue)) {
|
609 | loopObjectFlag = false;
|
610 | }
|
611 | }
|
612 | });
|
613 | return loopObjectFlag;
|
614 | }
|
615 |
|
616 | return false;
|
617 | }
|
618 |
|
619 | function includesArray(valueToFind, input) {
|
620 | let index = -1;
|
621 |
|
622 | while (++index < input.length) {
|
623 | if (equals(input[index], valueToFind)) {
|
624 | return true;
|
625 | }
|
626 | }
|
627 |
|
628 | return false;
|
629 | }
|
630 | function includes(valueToFind, input) {
|
631 | if (arguments.length === 1) return _input => includes(valueToFind, _input);
|
632 |
|
633 | if (typeof input === 'string') {
|
634 | return input.includes(valueToFind);
|
635 | }
|
636 |
|
637 | if (!input) {
|
638 | throw new TypeError(`Cannot read property \'indexOf\' of ${input}`);
|
639 | }
|
640 |
|
641 | if (!_isArray(input)) return false;
|
642 | return includesArray(valueToFind, input);
|
643 | }
|
644 |
|
645 | function uniq(list) {
|
646 | let index = -1;
|
647 | const willReturn = [];
|
648 |
|
649 | while (++index < list.length) {
|
650 | const value = list[index];
|
651 |
|
652 | if (!includes(value, willReturn)) {
|
653 | willReturn.push(value);
|
654 | }
|
655 | }
|
656 |
|
657 | return willReturn;
|
658 | }
|
659 |
|
660 | function difference(a, b) {
|
661 | if (arguments.length === 1) return _b => difference(a, _b);
|
662 | return uniq(a).filter(aInstance => !includes(aInstance, b));
|
663 | }
|
664 |
|
665 | function dissoc(prop, obj) {
|
666 | if (arguments.length === 1) return _obj => dissoc(prop, _obj);
|
667 | if (obj === null || obj === undefined) return {};
|
668 | const willReturn = {};
|
669 |
|
670 | for (const p in obj) {
|
671 | willReturn[p] = obj[p];
|
672 | }
|
673 |
|
674 | delete willReturn[prop];
|
675 | return willReturn;
|
676 | }
|
677 |
|
678 | function divide(a, b) {
|
679 | if (arguments.length === 1) return _b => divide(a, _b);
|
680 | return a / b;
|
681 | }
|
682 |
|
683 | function drop(howManyToDrop, listOrString) {
|
684 | if (arguments.length === 1) return _list => drop(howManyToDrop, _list);
|
685 | return listOrString.slice(howManyToDrop > 0 ? howManyToDrop : 0);
|
686 | }
|
687 |
|
688 | function dropLast(howManyToDrop, listOrString) {
|
689 | if (arguments.length === 1) {
|
690 | return _listOrString => dropLast(howManyToDrop, _listOrString);
|
691 | }
|
692 |
|
693 | return howManyToDrop > 0 ? listOrString.slice(0, -howManyToDrop) : listOrString.slice();
|
694 | }
|
695 |
|
696 | function dropLastWhile(predicate, iterable) {
|
697 | if (arguments.length === 1) {
|
698 | return _iterable => dropLastWhile(predicate, _iterable);
|
699 | }
|
700 |
|
701 | if (iterable.length === 0) return iterable;
|
702 |
|
703 | const isArray = _isArray(iterable);
|
704 |
|
705 | if (typeof predicate !== 'function') {
|
706 | throw new Error(`'predicate' is from wrong type ${typeof predicate}`);
|
707 | }
|
708 |
|
709 | if (!isArray && typeof iterable !== 'string') {
|
710 | throw new Error(`'iterable' is from wrong type ${typeof iterable}`);
|
711 | }
|
712 |
|
713 | let found = false;
|
714 | const toReturn = [];
|
715 | let counter = iterable.length;
|
716 |
|
717 | while (counter > 0) {
|
718 | counter--;
|
719 |
|
720 | if (!found && predicate(iterable[counter]) === false) {
|
721 | found = true;
|
722 | toReturn.push(iterable[counter]);
|
723 | } else if (found) {
|
724 | toReturn.push(iterable[counter]);
|
725 | }
|
726 | }
|
727 |
|
728 | return isArray ? toReturn.reverse() : toReturn.reverse().join('');
|
729 | }
|
730 |
|
731 | function dropRepeats(list) {
|
732 | if (!_isArray(list)) {
|
733 | throw new Error(`${list} is not a list`);
|
734 | }
|
735 |
|
736 | const toReturn = [];
|
737 | list.reduce((prev, current) => {
|
738 | if (!equals(prev, current)) {
|
739 | toReturn.push(current);
|
740 | }
|
741 |
|
742 | return current;
|
743 | }, undefined);
|
744 | return toReturn;
|
745 | }
|
746 |
|
747 | function dropRepeatsWith(predicate, list) {
|
748 | if (arguments.length === 1) {
|
749 | return _iterable => dropRepeatsWith(predicate, _iterable);
|
750 | }
|
751 |
|
752 | if (!_isArray(list)) {
|
753 | throw new Error(`${list} is not a list`);
|
754 | }
|
755 |
|
756 | const toReturn = [];
|
757 | list.reduce((prev, current) => {
|
758 | if (prev === undefined) {
|
759 | toReturn.push(current);
|
760 | return current;
|
761 | }
|
762 |
|
763 | if (!predicate(prev, current)) {
|
764 | toReturn.push(current);
|
765 | }
|
766 |
|
767 | return current;
|
768 | }, undefined);
|
769 | return toReturn;
|
770 | }
|
771 |
|
772 | function dropWhile(predicate, iterable) {
|
773 | if (arguments.length === 1) {
|
774 | return _iterable => dropWhile(predicate, _iterable);
|
775 | }
|
776 |
|
777 | const isArray = _isArray(iterable);
|
778 |
|
779 | if (!isArray && typeof iterable !== 'string') {
|
780 | throw new Error('`iterable` is neither list nor a string');
|
781 | }
|
782 |
|
783 | let flag = false;
|
784 | const holder = [];
|
785 | let counter = -1;
|
786 |
|
787 | while (counter++ < iterable.length - 1) {
|
788 | if (flag) {
|
789 | holder.push(iterable[counter]);
|
790 | } else if (!predicate(iterable[counter])) {
|
791 | if (!flag) flag = true;
|
792 | holder.push(iterable[counter]);
|
793 | }
|
794 | }
|
795 |
|
796 | return isArray ? holder : holder.join('');
|
797 | }
|
798 |
|
799 | function either(firstPredicate, secondPredicate) {
|
800 | if (arguments.length === 1) {
|
801 | return _secondPredicate => either(firstPredicate, _secondPredicate);
|
802 | }
|
803 |
|
804 | return (...input) => Boolean(firstPredicate(...input) || secondPredicate(...input));
|
805 | }
|
806 |
|
807 | function endsWith(target, str) {
|
808 | if (arguments.length === 1) return _str => endsWith(target, _str);
|
809 | return str.endsWith(target);
|
810 | }
|
811 |
|
812 | function eqPropsFn(prop, obj1, obj2) {
|
813 | if (!obj1 || !obj2) {
|
814 | throw new Error('wrong object inputs are passed to R.eqProps');
|
815 | }
|
816 |
|
817 | return equals(obj1[prop], obj2[prop]);
|
818 | }
|
819 |
|
820 | const eqProps = curry(eqPropsFn);
|
821 |
|
822 | function evolveArray(rules, list) {
|
823 | return mapArray((x, i) => {
|
824 | if (type(rules[i]) === 'Function') {
|
825 | return rules[i](x);
|
826 | }
|
827 |
|
828 | return x;
|
829 | }, list, true);
|
830 | }
|
831 | function evolveObject(rules, iterable) {
|
832 | return mapObject((x, prop) => {
|
833 | if (type(x) === 'Object') {
|
834 | const typeRule = type(rules[prop]);
|
835 |
|
836 | if (typeRule === 'Function') {
|
837 | return rules[prop](x);
|
838 | }
|
839 |
|
840 | if (typeRule === 'Object') {
|
841 | return evolve(rules[prop], x);
|
842 | }
|
843 |
|
844 | return x;
|
845 | }
|
846 |
|
847 | if (type(rules[prop]) === 'Function') {
|
848 | return rules[prop](x);
|
849 | }
|
850 |
|
851 | return x;
|
852 | }, iterable);
|
853 | }
|
854 | function evolve(rules, iterable) {
|
855 | if (arguments.length === 1) {
|
856 | return _iterable => evolve(rules, _iterable);
|
857 | }
|
858 |
|
859 | const rulesType = type(rules);
|
860 | const iterableType = type(iterable);
|
861 |
|
862 | if (iterableType !== rulesType) {
|
863 | throw new Error('iterableType !== rulesType');
|
864 | }
|
865 |
|
866 | if (!['Object', 'Array'].includes(rulesType)) {
|
867 | throw new Error(`'iterable' and 'rules' are from wrong type ${rulesType}`);
|
868 | }
|
869 |
|
870 | if (iterableType === 'Object') {
|
871 | return evolveObject(rules, iterable);
|
872 | }
|
873 |
|
874 | return evolveArray(rules, iterable);
|
875 | }
|
876 |
|
877 | function filterObject(fn, obj) {
|
878 | const willReturn = {};
|
879 |
|
880 | for (const prop in obj) {
|
881 | if (fn(obj[prop], prop, obj)) {
|
882 | willReturn[prop] = obj[prop];
|
883 | }
|
884 | }
|
885 |
|
886 | return willReturn;
|
887 | }
|
888 | function filterArray(predicate, list, indexed = false) {
|
889 | let index = 0;
|
890 | const len = list.length;
|
891 | const willReturn = [];
|
892 |
|
893 | while (index < len) {
|
894 | const predicateResult = indexed ? predicate(list[index], index) : predicate(list[index]);
|
895 |
|
896 | if (predicateResult) {
|
897 | willReturn.push(list[index]);
|
898 | }
|
899 |
|
900 | index++;
|
901 | }
|
902 |
|
903 | return willReturn;
|
904 | }
|
905 | function filter(predicate, iterable) {
|
906 | if (arguments.length === 1) {
|
907 | return _iterable => filter(predicate, _iterable);
|
908 | }
|
909 |
|
910 | if (!iterable) return [];
|
911 | if (_isArray(iterable)) return filterArray(predicate, iterable);
|
912 | return filterObject(predicate, iterable);
|
913 | }
|
914 |
|
915 | function find(predicate, list) {
|
916 | if (arguments.length === 1) return _list => find(predicate, _list);
|
917 | let index = 0;
|
918 | const len = list.length;
|
919 |
|
920 | while (index < len) {
|
921 | const x = list[index];
|
922 |
|
923 | if (predicate(x)) {
|
924 | return x;
|
925 | }
|
926 |
|
927 | index++;
|
928 | }
|
929 | }
|
930 |
|
931 | function findIndex(predicate, list) {
|
932 | if (arguments.length === 1) return _list => findIndex(predicate, _list);
|
933 | const len = list.length;
|
934 | let index = -1;
|
935 |
|
936 | while (++index < len) {
|
937 | if (predicate(list[index])) {
|
938 | return index;
|
939 | }
|
940 | }
|
941 |
|
942 | return -1;
|
943 | }
|
944 |
|
945 | function findLast(predicate, list) {
|
946 | if (arguments.length === 1) return _list => findLast(predicate, _list);
|
947 | let index = list.length;
|
948 |
|
949 | while (--index >= 0) {
|
950 | if (predicate(list[index])) {
|
951 | return list[index];
|
952 | }
|
953 | }
|
954 |
|
955 | return undefined;
|
956 | }
|
957 |
|
958 | function findLastIndex(fn, list) {
|
959 | if (arguments.length === 1) return _list => findLastIndex(fn, _list);
|
960 | let index = list.length;
|
961 |
|
962 | while (--index >= 0) {
|
963 | if (fn(list[index])) {
|
964 | return index;
|
965 | }
|
966 | }
|
967 |
|
968 | return -1;
|
969 | }
|
970 |
|
971 | function flatten(list, input) {
|
972 | const willReturn = input === undefined ? [] : input;
|
973 |
|
974 | for (let i = 0; i < list.length; i++) {
|
975 | if (_isArray(list[i])) {
|
976 | flatten(list[i], willReturn);
|
977 | } else {
|
978 | willReturn.push(list[i]);
|
979 | }
|
980 | }
|
981 |
|
982 | return willReturn;
|
983 | }
|
984 |
|
985 | function flipFn(fn) {
|
986 | return (...input) => {
|
987 | if (input.length === 1) {
|
988 | return holder => fn(holder, input[0]);
|
989 | } else if (input.length === 2) {
|
990 | return fn(input[1], input[0]);
|
991 | } else if (input.length === 3) {
|
992 | return fn(input[1], input[0], input[2]);
|
993 | } else if (input.length === 4) {
|
994 | return fn(input[1], input[0], input[2], input[3]);
|
995 | }
|
996 |
|
997 | throw new Error('R.flip doesn\'t work with arity > 4');
|
998 | };
|
999 | }
|
1000 |
|
1001 | function flip(fn) {
|
1002 | return flipFn(fn);
|
1003 | }
|
1004 |
|
1005 | function forEach(fn, list) {
|
1006 | if (arguments.length === 1) return _list => forEach(fn, _list);
|
1007 |
|
1008 | if (list === undefined) {
|
1009 | return;
|
1010 | }
|
1011 |
|
1012 | if (_isArray(list)) {
|
1013 | let index = 0;
|
1014 | const len = list.length;
|
1015 |
|
1016 | while (index < len) {
|
1017 | fn(list[index]);
|
1018 | index++;
|
1019 | }
|
1020 | } else {
|
1021 | let index = 0;
|
1022 |
|
1023 | const keys = _keys(list);
|
1024 |
|
1025 | const len = keys.length;
|
1026 |
|
1027 | while (index < len) {
|
1028 | const key = keys[index];
|
1029 | fn(list[key], key, list);
|
1030 | index++;
|
1031 | }
|
1032 | }
|
1033 |
|
1034 | return list;
|
1035 | }
|
1036 |
|
1037 | function fromPairs(listOfPairs) {
|
1038 | const toReturn = {};
|
1039 | listOfPairs.forEach(([prop, value]) => toReturn[prop] = value);
|
1040 | return toReturn;
|
1041 | }
|
1042 |
|
1043 | function groupBy(groupFn, list) {
|
1044 | if (arguments.length === 1) return _list => groupBy(groupFn, _list);
|
1045 | const result = {};
|
1046 |
|
1047 | for (let i = 0; i < list.length; i++) {
|
1048 | const item = list[i];
|
1049 | const key = groupFn(item);
|
1050 |
|
1051 | if (!result[key]) {
|
1052 | result[key] = [];
|
1053 | }
|
1054 |
|
1055 | result[key].push(item);
|
1056 | }
|
1057 |
|
1058 | return result;
|
1059 | }
|
1060 |
|
1061 | function groupWith(compareFn, list) {
|
1062 | if (!_isArray(list)) throw new TypeError('list.reduce is not a function');
|
1063 | const clone = list.slice();
|
1064 | if (list.length === 1) return [clone];
|
1065 | const toReturn = [];
|
1066 | let holder = [];
|
1067 | clone.reduce((prev, current, i) => {
|
1068 | if (i === 0) return current;
|
1069 | const okCompare = compareFn(prev, current);
|
1070 | const holderIsEmpty = holder.length === 0;
|
1071 | const lastCall = i === list.length - 1;
|
1072 |
|
1073 | if (okCompare) {
|
1074 | if (holderIsEmpty) holder.push(prev);
|
1075 | holder.push(current);
|
1076 | if (lastCall) toReturn.push(holder);
|
1077 | return current;
|
1078 | }
|
1079 |
|
1080 | if (holderIsEmpty) {
|
1081 | toReturn.push([prev]);
|
1082 | if (lastCall) toReturn.push([current]);
|
1083 | return current;
|
1084 | }
|
1085 |
|
1086 | toReturn.push(holder);
|
1087 | if (lastCall) toReturn.push([current]);
|
1088 | holder = [];
|
1089 | return current;
|
1090 | }, undefined);
|
1091 | return toReturn;
|
1092 | }
|
1093 |
|
1094 | function has(prop, obj) {
|
1095 | if (arguments.length === 1) return _obj => has(prop, _obj);
|
1096 | if (!obj) return false;
|
1097 | return obj.hasOwnProperty(prop);
|
1098 | }
|
1099 |
|
1100 | function path(pathInput, obj) {
|
1101 | if (arguments.length === 1) return _obj => path(pathInput, _obj);
|
1102 |
|
1103 | if (obj === null || obj === undefined) {
|
1104 | return undefined;
|
1105 | }
|
1106 |
|
1107 | let willReturn = obj;
|
1108 | let counter = 0;
|
1109 | const pathArrValue = typeof pathInput === 'string' ? pathInput.split('.') : pathInput;
|
1110 |
|
1111 | while (counter < pathArrValue.length) {
|
1112 | if (willReturn === null || willReturn === undefined) {
|
1113 | return undefined;
|
1114 | }
|
1115 |
|
1116 | if (willReturn[pathArrValue[counter]] === null) return undefined;
|
1117 | willReturn = willReturn[pathArrValue[counter]];
|
1118 | counter++;
|
1119 | }
|
1120 |
|
1121 | return willReturn;
|
1122 | }
|
1123 |
|
1124 | function hasPath(maybePath, obj) {
|
1125 | if (arguments.length === 1) {
|
1126 | return objHolder => hasPath(maybePath, objHolder);
|
1127 | }
|
1128 |
|
1129 | return path(maybePath, obj) !== undefined;
|
1130 | }
|
1131 |
|
1132 | function head(listOrString) {
|
1133 | if (typeof listOrString === 'string') return listOrString[0] || '';
|
1134 | return listOrString[0];
|
1135 | }
|
1136 |
|
1137 | function _objectIs(a, b) {
|
1138 | if (a === b) {
|
1139 | return a !== 0 || 1 / a === 1 / b;
|
1140 | }
|
1141 |
|
1142 | return a !== a && b !== b;
|
1143 | }
|
1144 | var _objectIs$1 = Object.is || _objectIs;
|
1145 |
|
1146 | function identical(a, b) {
|
1147 | if (arguments.length === 1) return _b => identical(a, _b);
|
1148 | return _objectIs$1(a, b);
|
1149 | }
|
1150 |
|
1151 | function identity(input) {
|
1152 | return input;
|
1153 | }
|
1154 |
|
1155 | function ifElseFn(condition, onTrue, onFalse) {
|
1156 | return (...input) => {
|
1157 | const conditionResult = typeof condition === 'boolean' ? condition : condition(...input);
|
1158 |
|
1159 | if (conditionResult === true) {
|
1160 | return onTrue(...input);
|
1161 | }
|
1162 |
|
1163 | return onFalse(...input);
|
1164 | };
|
1165 | }
|
1166 |
|
1167 | const ifElse = curry(ifElseFn);
|
1168 |
|
1169 | const inc = x => x + 1;
|
1170 |
|
1171 | function indexByPath(pathInput, list) {
|
1172 | const toReturn = {};
|
1173 |
|
1174 | for (let i = 0; i < list.length; i++) {
|
1175 | const item = list[i];
|
1176 | toReturn[path(pathInput, item)] = item;
|
1177 | }
|
1178 |
|
1179 | return toReturn;
|
1180 | }
|
1181 |
|
1182 | function indexBy(condition, list) {
|
1183 | if (arguments.length === 1) {
|
1184 | return _list => indexBy(condition, _list);
|
1185 | }
|
1186 |
|
1187 | if (typeof condition === 'string') {
|
1188 | return indexByPath(condition, list);
|
1189 | }
|
1190 |
|
1191 | const toReturn = {};
|
1192 |
|
1193 | for (let i = 0; i < list.length; i++) {
|
1194 | const item = list[i];
|
1195 | toReturn[condition(item)] = item;
|
1196 | }
|
1197 |
|
1198 | return toReturn;
|
1199 | }
|
1200 |
|
1201 | function indexOf(valueToFind, list) {
|
1202 | if (arguments.length === 1) {
|
1203 | return _list => indexOf(valueToFind, _list);
|
1204 | }
|
1205 |
|
1206 | let index = -1;
|
1207 | const {
|
1208 | length
|
1209 | } = list;
|
1210 |
|
1211 | while (++index < length) {
|
1212 | if (list[index] === valueToFind) {
|
1213 | return index;
|
1214 | }
|
1215 | }
|
1216 |
|
1217 | return -1;
|
1218 | }
|
1219 |
|
1220 | function baseSlice(array, start, end) {
|
1221 | let index = -1;
|
1222 | let {
|
1223 | length
|
1224 | } = array;
|
1225 | end = end > length ? length : end;
|
1226 |
|
1227 | if (end < 0) {
|
1228 | end += length;
|
1229 | }
|
1230 |
|
1231 | length = start > end ? 0 : end - start >>> 0;
|
1232 | start >>>= 0;
|
1233 | const result = Array(length);
|
1234 |
|
1235 | while (++index < length) {
|
1236 | result[index] = array[index + start];
|
1237 | }
|
1238 |
|
1239 | return result;
|
1240 | }
|
1241 |
|
1242 | function init(listOrString) {
|
1243 | if (typeof listOrString === 'string') return listOrString.slice(0, -1);
|
1244 | return listOrString.length ? baseSlice(listOrString, 0, -1) : [];
|
1245 | }
|
1246 |
|
1247 | function intersection(listA, listB) {
|
1248 | if (arguments.length === 1) return _list => intersection(listA, _list);
|
1249 | return filter(x => includes(x, listA), listB);
|
1250 | }
|
1251 |
|
1252 | function intersperse(separator, list) {
|
1253 | if (arguments.length === 1) return _list => intersperse(separator, _list);
|
1254 | let index = -1;
|
1255 | const len = list.length;
|
1256 | const willReturn = [];
|
1257 |
|
1258 | while (++index < len) {
|
1259 | if (index === len - 1) {
|
1260 | willReturn.push(list[index]);
|
1261 | } else {
|
1262 | willReturn.push(list[index], separator);
|
1263 | }
|
1264 | }
|
1265 |
|
1266 | return willReturn;
|
1267 | }
|
1268 |
|
1269 | function is(targetPrototype, x) {
|
1270 | if (arguments.length === 1) return _x => is(targetPrototype, _x);
|
1271 | return x != null && x.constructor === targetPrototype || x instanceof targetPrototype;
|
1272 | }
|
1273 |
|
1274 | function isEmpty(input) {
|
1275 | const inputType = type(input);
|
1276 | if (['Undefined', 'NaN', 'Number', 'Null'].includes(inputType)) return false;
|
1277 | if (!input) return true;
|
1278 |
|
1279 | if (inputType === 'Object') {
|
1280 | return Object.keys(input).length === 0;
|
1281 | }
|
1282 |
|
1283 | if (inputType === 'Array') {
|
1284 | return input.length === 0;
|
1285 | }
|
1286 |
|
1287 | return false;
|
1288 | }
|
1289 |
|
1290 | function isNil(x) {
|
1291 | return x === undefined || x === null;
|
1292 | }
|
1293 |
|
1294 | function join(glue, list) {
|
1295 | if (arguments.length === 1) return _list => join(glue, _list);
|
1296 | return list.join(glue);
|
1297 | }
|
1298 |
|
1299 | function keys(x) {
|
1300 | return Object.keys(x);
|
1301 | }
|
1302 |
|
1303 | function last(listOrString) {
|
1304 | if (typeof listOrString === 'string') {
|
1305 | return listOrString[listOrString.length - 1] || '';
|
1306 | }
|
1307 |
|
1308 | return listOrString[listOrString.length - 1];
|
1309 | }
|
1310 |
|
1311 | function lastIndexOf(target, list) {
|
1312 | if (arguments.length === 1) return _list => lastIndexOf(target, _list);
|
1313 | let index = list.length;
|
1314 |
|
1315 | while (--index > 0) {
|
1316 | if (equals(list[index], target)) {
|
1317 | return index;
|
1318 | }
|
1319 | }
|
1320 |
|
1321 | return -1;
|
1322 | }
|
1323 |
|
1324 | function length(x) {
|
1325 | if (!x && x !== '' || x.length === undefined) {
|
1326 | return NaN;
|
1327 | }
|
1328 |
|
1329 | return x.length;
|
1330 | }
|
1331 |
|
1332 | function lens(getter, setter) {
|
1333 | return function (functor) {
|
1334 | return function (target) {
|
1335 | return functor(getter(target)).map(focus => setter(focus, target));
|
1336 | };
|
1337 | };
|
1338 | }
|
1339 |
|
1340 | function nth(index, list) {
|
1341 | if (arguments.length === 1) return _list => nth(index, _list);
|
1342 | const idx = index < 0 ? list.length + index : index;
|
1343 | return Object.prototype.toString.call(list) === '[object String]' ? list.charAt(idx) : list[idx];
|
1344 | }
|
1345 |
|
1346 | function updateFn(index, newValue, list) {
|
1347 | const arrClone = list.slice();
|
1348 | return arrClone.fill(newValue, index, index + 1);
|
1349 | }
|
1350 |
|
1351 | const update = curry(updateFn);
|
1352 |
|
1353 | function lensIndex(index) {
|
1354 | return lens(nth(index), update(index));
|
1355 | }
|
1356 |
|
1357 | function lensPath(key) {
|
1358 | return lens(path(key), assocPath(key));
|
1359 | }
|
1360 |
|
1361 | function prop(propToFind, obj) {
|
1362 | if (arguments.length === 1) return _obj => prop(propToFind, _obj);
|
1363 | if (!obj) return undefined;
|
1364 | return obj[propToFind];
|
1365 | }
|
1366 |
|
1367 | function lensProp(key) {
|
1368 | return lens(prop(key), assoc(key));
|
1369 | }
|
1370 |
|
1371 | function match(pattern, input) {
|
1372 | if (arguments.length === 1) return _input => match(pattern, _input);
|
1373 | const willReturn = input.match(pattern);
|
1374 | return willReturn === null ? [] : willReturn;
|
1375 | }
|
1376 |
|
1377 | function mathMod(x, y) {
|
1378 | if (arguments.length === 1) return _y => mathMod(x, _y);
|
1379 | if (!_isInteger$1(x) || !_isInteger$1(y) || y < 1) return NaN;
|
1380 | return (x % y + y) % y;
|
1381 | }
|
1382 |
|
1383 | function maxByFn(compareFn, x, y) {
|
1384 | return compareFn(y) > compareFn(x) ? y : x;
|
1385 | }
|
1386 | const maxBy = curry(maxByFn);
|
1387 |
|
1388 | function sum(list) {
|
1389 | return list.reduce((prev, current) => prev + current, 0);
|
1390 | }
|
1391 |
|
1392 | function mean(list) {
|
1393 | return sum(list) / list.length;
|
1394 | }
|
1395 |
|
1396 | function median(list) {
|
1397 | const len = list.length;
|
1398 | if (len === 0) return NaN;
|
1399 | const width = 2 - len % 2;
|
1400 | const idx = (len - width) / 2;
|
1401 | return mean(Array.prototype.slice.call(list, 0).sort((a, b) => {
|
1402 | if (a === b) return 0;
|
1403 | return a < b ? -1 : 1;
|
1404 | }).slice(idx, idx + width));
|
1405 | }
|
1406 |
|
1407 | function merge(target, newProps) {
|
1408 | if (arguments.length === 1) return _newProps => merge(target, _newProps);
|
1409 | return Object.assign({}, target || {}, newProps || {});
|
1410 | }
|
1411 |
|
1412 | function mergeAll(arr) {
|
1413 | let willReturn = {};
|
1414 | map(val => {
|
1415 | willReturn = merge(willReturn, val);
|
1416 | }, arr);
|
1417 | return willReturn;
|
1418 | }
|
1419 |
|
1420 | function mergeDeepRight(target, source) {
|
1421 | if (arguments.length === 1) {
|
1422 | return sourceHolder => mergeDeepRight(target, sourceHolder);
|
1423 | }
|
1424 |
|
1425 | const willReturn = JSON.parse(JSON.stringify(target));
|
1426 | Object.keys(source).forEach(key => {
|
1427 | if (type(source[key]) === 'Object') {
|
1428 | if (type(target[key]) === 'Object') {
|
1429 | willReturn[key] = mergeDeepRight(target[key], source[key]);
|
1430 | } else {
|
1431 | willReturn[key] = source[key];
|
1432 | }
|
1433 | } else {
|
1434 | willReturn[key] = source[key];
|
1435 | }
|
1436 | });
|
1437 | return willReturn;
|
1438 | }
|
1439 |
|
1440 | function mergeLeft(x, y) {
|
1441 | if (arguments.length === 1) return _y => mergeLeft(x, _y);
|
1442 | return merge(y, x);
|
1443 | }
|
1444 |
|
1445 | function min(x, y) {
|
1446 | if (arguments.length === 1) return _y => min(x, _y);
|
1447 | return y < x ? y : x;
|
1448 | }
|
1449 |
|
1450 | function minByFn(compareFn, x, y) {
|
1451 | return compareFn(y) < compareFn(x) ? y : x;
|
1452 | }
|
1453 | const minBy = curry(minByFn);
|
1454 |
|
1455 | function modulo(x, y) {
|
1456 | if (arguments.length === 1) return _y => modulo(x, _y);
|
1457 | return x % y;
|
1458 | }
|
1459 |
|
1460 | function moveFn(fromIndex, toIndex, list) {
|
1461 | if (fromIndex < 0 || toIndex < 0) {
|
1462 | throw new Error('Rambda.move does not support negative indexes');
|
1463 | }
|
1464 |
|
1465 | if (fromIndex > list.length - 1 || toIndex > list.length - 1) return list;
|
1466 | const clone = list.slice();
|
1467 | clone[fromIndex] = list[toIndex];
|
1468 | clone[toIndex] = list[fromIndex];
|
1469 | return clone;
|
1470 | }
|
1471 |
|
1472 | const move = curry(moveFn);
|
1473 |
|
1474 | function multiply(x, y) {
|
1475 | if (arguments.length === 1) return _y => multiply(x, _y);
|
1476 | return x * y;
|
1477 | }
|
1478 |
|
1479 | function negate(x) {
|
1480 | return -x;
|
1481 | }
|
1482 |
|
1483 | function none(predicate, list) {
|
1484 | if (arguments.length === 1) return _list => none(predicate, _list);
|
1485 |
|
1486 | for (let i = 0; i < list.length; i++) {
|
1487 | if (!predicate(list[i])) return true;
|
1488 | }
|
1489 |
|
1490 | return false;
|
1491 | }
|
1492 |
|
1493 | function not(input) {
|
1494 | return !input;
|
1495 | }
|
1496 |
|
1497 | function objOf(key, value) {
|
1498 | if (arguments.length === 1) {
|
1499 | return _value => objOf(key, _value);
|
1500 | }
|
1501 |
|
1502 | return {
|
1503 | [key]: value
|
1504 | };
|
1505 | }
|
1506 |
|
1507 | function of(value) {
|
1508 | return [value];
|
1509 | }
|
1510 |
|
1511 | function omit(propsToOmit, obj) {
|
1512 | if (arguments.length === 1) return _obj => omit(propsToOmit, _obj);
|
1513 |
|
1514 | if (obj === null || obj === undefined) {
|
1515 | return undefined;
|
1516 | }
|
1517 |
|
1518 | const propsToOmitValue = typeof propsToOmit === 'string' ? propsToOmit.split(',') : propsToOmit;
|
1519 | const willReturn = {};
|
1520 |
|
1521 | for (const key in obj) {
|
1522 | if (!propsToOmitValue.includes(key)) {
|
1523 | willReturn[key] = obj[key];
|
1524 | }
|
1525 | }
|
1526 |
|
1527 | return willReturn;
|
1528 | }
|
1529 |
|
1530 | function onceFn(fn, context) {
|
1531 | let result;
|
1532 | return function () {
|
1533 | if (fn) {
|
1534 | result = fn.apply(context || this, arguments);
|
1535 | fn = null;
|
1536 | }
|
1537 |
|
1538 | return result;
|
1539 | };
|
1540 | }
|
1541 |
|
1542 | function once(fn, context) {
|
1543 | if (arguments.length === 1) {
|
1544 | const wrap = onceFn(fn, context);
|
1545 | return curry(wrap);
|
1546 | }
|
1547 |
|
1548 | return onceFn(fn, context);
|
1549 | }
|
1550 |
|
1551 | function or(a, b) {
|
1552 | if (arguments.length === 1) return _b => or(a, _b);
|
1553 | return a || b;
|
1554 | }
|
1555 |
|
1556 | const Identity = x => ({
|
1557 | x,
|
1558 | map: fn => Identity(fn(x))
|
1559 | });
|
1560 |
|
1561 | function overFn(lens, fn, object) {
|
1562 | return lens(x => Identity(fn(x)))(object).x;
|
1563 | }
|
1564 |
|
1565 | const over = curry(overFn);
|
1566 |
|
1567 | function partial(fn, ...args) {
|
1568 | const len = fn.length;
|
1569 | return (...rest) => {
|
1570 | if (args.length + rest.length >= len) {
|
1571 | return fn(...args, ...rest);
|
1572 | }
|
1573 |
|
1574 | return partial(fn, ...[...args, ...rest]);
|
1575 | };
|
1576 | }
|
1577 |
|
1578 | function partitionObject(predicate, iterable) {
|
1579 | const yes = {};
|
1580 | const no = {};
|
1581 | Object.entries(iterable).forEach(([prop, value]) => {
|
1582 | if (predicate(value, prop)) {
|
1583 | yes[prop] = value;
|
1584 | } else {
|
1585 | no[prop] = value;
|
1586 | }
|
1587 | });
|
1588 | return [yes, no];
|
1589 | }
|
1590 | function partitionArray(predicate, list) {
|
1591 | const yes = [];
|
1592 | const no = [];
|
1593 | let counter = -1;
|
1594 |
|
1595 | while (counter++ < list.length - 1) {
|
1596 | if (predicate(list[counter])) {
|
1597 | yes.push(list[counter]);
|
1598 | } else {
|
1599 | no.push(list[counter]);
|
1600 | }
|
1601 | }
|
1602 |
|
1603 | return [yes, no];
|
1604 | }
|
1605 | function partition(predicate, iterable) {
|
1606 | if (arguments.length === 1) {
|
1607 | return listHolder => partition(predicate, listHolder);
|
1608 | }
|
1609 |
|
1610 | if (!_isArray(iterable)) return partitionObject(predicate, iterable);
|
1611 | return partitionArray(predicate, iterable);
|
1612 | }
|
1613 |
|
1614 | function pathEqFn(pathToSearch, target, input) {
|
1615 | return equals(path(pathToSearch, input), target);
|
1616 | }
|
1617 |
|
1618 | const pathEq = curry(pathEqFn);
|
1619 |
|
1620 | function pathOrFn(defaultValue, list, obj) {
|
1621 | return defaultTo(defaultValue, path(list, obj));
|
1622 | }
|
1623 |
|
1624 | const pathOr = curry(pathOrFn);
|
1625 |
|
1626 | function paths(pathsToSearch, obj) {
|
1627 | if (arguments.length === 1) {
|
1628 | return _obj => paths(pathsToSearch, _obj);
|
1629 | }
|
1630 |
|
1631 | return pathsToSearch.map(singlePath => path(singlePath, obj));
|
1632 | }
|
1633 |
|
1634 | function pick(propsToPick, input) {
|
1635 | if (arguments.length === 1) return _input => pick(propsToPick, _input);
|
1636 |
|
1637 | if (input === null || input === undefined) {
|
1638 | return undefined;
|
1639 | }
|
1640 |
|
1641 | const keys = typeof propsToPick === 'string' ? propsToPick.split(',') : propsToPick;
|
1642 | const willReturn = {};
|
1643 | let counter = 0;
|
1644 |
|
1645 | while (counter < keys.length) {
|
1646 | if (keys[counter] in input) {
|
1647 | willReturn[keys[counter]] = input[keys[counter]];
|
1648 | }
|
1649 |
|
1650 | counter++;
|
1651 | }
|
1652 |
|
1653 | return willReturn;
|
1654 | }
|
1655 |
|
1656 | function pickAll(propsToPick, obj) {
|
1657 | if (arguments.length === 1) return _obj => pickAll(propsToPick, _obj);
|
1658 |
|
1659 | if (obj === null || obj === undefined) {
|
1660 | return undefined;
|
1661 | }
|
1662 |
|
1663 | const keysValue = typeof propsToPick === 'string' ? propsToPick.split(',') : propsToPick;
|
1664 | const willReturn = {};
|
1665 | let counter = 0;
|
1666 |
|
1667 | while (counter < keysValue.length) {
|
1668 | if (keysValue[counter] in obj) {
|
1669 | willReturn[keysValue[counter]] = obj[keysValue[counter]];
|
1670 | } else {
|
1671 | willReturn[keysValue[counter]] = undefined;
|
1672 | }
|
1673 |
|
1674 | counter++;
|
1675 | }
|
1676 |
|
1677 | return willReturn;
|
1678 | }
|
1679 |
|
1680 | function pipe(...fns) {
|
1681 | if (fns.length === 0) throw new Error('pipe requires at least one argument');
|
1682 | return (...args) => {
|
1683 | const list = fns.slice();
|
1684 |
|
1685 | if (list.length > 0) {
|
1686 | const fn = list.shift();
|
1687 | let result = fn(...args);
|
1688 |
|
1689 | while (list.length > 0) {
|
1690 | result = list.shift()(result);
|
1691 | }
|
1692 |
|
1693 | return result;
|
1694 | }
|
1695 | };
|
1696 | }
|
1697 |
|
1698 | function pluck(property, list) {
|
1699 | if (arguments.length === 1) return _list => pluck(property, _list);
|
1700 | const willReturn = [];
|
1701 | map(x => {
|
1702 | if (x[property] !== undefined) {
|
1703 | willReturn.push(x[property]);
|
1704 | }
|
1705 | }, list);
|
1706 | return willReturn;
|
1707 | }
|
1708 |
|
1709 | function prepend(x, input) {
|
1710 | if (arguments.length === 1) return _input => prepend(x, _input);
|
1711 | if (typeof input === 'string') return [x].concat(input.split(''));
|
1712 | return [x].concat(input);
|
1713 | }
|
1714 |
|
1715 | const product = reduce(multiply, 1);
|
1716 |
|
1717 | function propEqFn(propToFind, valueToMatch, obj) {
|
1718 | if (!obj) return false;
|
1719 | return obj[propToFind] === valueToMatch;
|
1720 | }
|
1721 |
|
1722 | const propEq = curry(propEqFn);
|
1723 |
|
1724 | function propIsFn(targetPrototype, property, obj) {
|
1725 | return is(targetPrototype, obj[property]);
|
1726 | }
|
1727 |
|
1728 | const propIs = curry(propIsFn);
|
1729 |
|
1730 | function propOrFn(defaultValue, property, obj) {
|
1731 | if (!obj) return defaultValue;
|
1732 | return defaultTo(defaultValue, obj[property]);
|
1733 | }
|
1734 |
|
1735 | const propOr = curry(propOrFn);
|
1736 |
|
1737 | function props(propsToPick, obj) {
|
1738 | if (arguments.length === 1) {
|
1739 | return _obj => props(propsToPick, _obj);
|
1740 | }
|
1741 |
|
1742 | if (!_isArray(propsToPick)) {
|
1743 | throw new Error('propsToPick is not a list');
|
1744 | }
|
1745 |
|
1746 | return mapArray(prop => obj[prop], propsToPick);
|
1747 | }
|
1748 |
|
1749 | function range(start, end) {
|
1750 | if (arguments.length === 1) return _end => range(start, _end);
|
1751 |
|
1752 | if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
|
1753 | throw new TypeError('Both arguments to range must be numbers');
|
1754 | }
|
1755 |
|
1756 | if (end < start) return [];
|
1757 | const len = end - start;
|
1758 | const willReturn = Array(len);
|
1759 |
|
1760 | for (let i = 0; i < len; i++) {
|
1761 | willReturn[i] = start + i;
|
1762 | }
|
1763 |
|
1764 | return willReturn;
|
1765 | }
|
1766 |
|
1767 | function reject(predicate, list) {
|
1768 | if (arguments.length === 1) return _list => reject(predicate, _list);
|
1769 | return filter(x => !predicate(x), list);
|
1770 | }
|
1771 |
|
1772 | function repeat(x, timesToRepeat) {
|
1773 | if (arguments.length === 1) {
|
1774 | return _timesToRepeat => repeat(x, _timesToRepeat);
|
1775 | }
|
1776 |
|
1777 | return Array(timesToRepeat).fill(x);
|
1778 | }
|
1779 |
|
1780 | function replaceFn(pattern, replacer, str) {
|
1781 | return str.replace(pattern, replacer);
|
1782 | }
|
1783 |
|
1784 | const replace = curry(replaceFn);
|
1785 |
|
1786 | function reverse(listOrString) {
|
1787 | if (typeof listOrString === 'string') {
|
1788 | return listOrString.split('').reverse().join('');
|
1789 | }
|
1790 |
|
1791 | const clone = listOrString.slice();
|
1792 | return clone.reverse();
|
1793 | }
|
1794 |
|
1795 | function setFn(lens, replacer, x) {
|
1796 | return over(lens, always(replacer), x);
|
1797 | }
|
1798 |
|
1799 | const set = curry(setFn);
|
1800 |
|
1801 | function sliceFn(from, to, list) {
|
1802 | return list.slice(from, to);
|
1803 | }
|
1804 |
|
1805 | const slice = curry(sliceFn);
|
1806 |
|
1807 | function sort(sortFn, list) {
|
1808 | if (arguments.length === 1) return _list => sort(sortFn, _list);
|
1809 | const clone = list.slice();
|
1810 | return clone.sort(sortFn);
|
1811 | }
|
1812 |
|
1813 | function sortBy(sortFn, list) {
|
1814 | if (arguments.length === 1) return _list => sortBy(sortFn, _list);
|
1815 | const clone = list.slice();
|
1816 | return clone.sort((a, b) => {
|
1817 | const aSortResult = sortFn(a);
|
1818 | const bSortResult = sortFn(b);
|
1819 | if (aSortResult === bSortResult) return 0;
|
1820 | return aSortResult < bSortResult ? -1 : 1;
|
1821 | });
|
1822 | }
|
1823 |
|
1824 | function split(separator, str) {
|
1825 | if (arguments.length === 1) return _str => split(separator, _str);
|
1826 | return str.split(separator);
|
1827 | }
|
1828 |
|
1829 | function maybe(ifRule, whenIf, whenElse) {
|
1830 | const whenIfInput = ifRule && type(whenIf) === 'Function' ? whenIf() : whenIf;
|
1831 | const whenElseInput = !ifRule && type(whenElse) === 'Function' ? whenElse() : whenElse;
|
1832 | return ifRule ? whenIfInput : whenElseInput;
|
1833 | }
|
1834 |
|
1835 | function take(howMany, listOrString) {
|
1836 | if (arguments.length === 1) return _listOrString => take(howMany, _listOrString);
|
1837 | if (howMany < 0) return listOrString.slice();
|
1838 | if (typeof listOrString === 'string') return listOrString.slice(0, howMany);
|
1839 | return baseSlice(listOrString, 0, howMany);
|
1840 | }
|
1841 |
|
1842 | function splitAt(index, input) {
|
1843 | if (arguments.length === 1) {
|
1844 | return _list => splitAt(index, _list);
|
1845 | }
|
1846 |
|
1847 | if (!input) throw new TypeError(`Cannot read property 'slice' of ${input}`);
|
1848 | if (!_isArray(input) && typeof input !== 'string') return [[], []];
|
1849 | const correctIndex = maybe(index < 0, input.length + index < 0 ? 0 : input.length + index, index);
|
1850 | return [take(correctIndex, input), drop(correctIndex, input)];
|
1851 | }
|
1852 |
|
1853 | function splitEvery(sliceLength, listOrString) {
|
1854 | if (arguments.length === 1) {
|
1855 | return _listOrString => splitEvery(sliceLength, _listOrString);
|
1856 | }
|
1857 |
|
1858 | if (sliceLength < 1) {
|
1859 | throw new Error('First argument to splitEvery must be a positive integer');
|
1860 | }
|
1861 |
|
1862 | const willReturn = [];
|
1863 | let counter = 0;
|
1864 |
|
1865 | while (counter < listOrString.length) {
|
1866 | willReturn.push(listOrString.slice(counter, counter += sliceLength));
|
1867 | }
|
1868 |
|
1869 | return willReturn;
|
1870 | }
|
1871 |
|
1872 | function splitWhen(predicate, input) {
|
1873 | if (arguments.length === 1) {
|
1874 | return _input => splitWhen(predicate, _input);
|
1875 | }
|
1876 |
|
1877 | if (!input) throw new TypeError(`Cannot read property 'length' of ${input}`);
|
1878 | const preFound = [];
|
1879 | const postFound = [];
|
1880 | let found = false;
|
1881 | let counter = -1;
|
1882 |
|
1883 | while (counter++ < input.length - 1) {
|
1884 | if (found) {
|
1885 | postFound.push(input[counter]);
|
1886 | } else if (predicate(input[counter])) {
|
1887 | postFound.push(input[counter]);
|
1888 | found = true;
|
1889 | } else {
|
1890 | preFound.push(input[counter]);
|
1891 | }
|
1892 | }
|
1893 |
|
1894 | return [preFound, postFound];
|
1895 | }
|
1896 |
|
1897 | function startsWith(target, str) {
|
1898 | if (arguments.length === 1) return _str => startsWith(target, _str);
|
1899 | return str.startsWith(target);
|
1900 | }
|
1901 |
|
1902 | function subtract(a, b) {
|
1903 | if (arguments.length === 1) return _b => subtract(a, _b);
|
1904 | return a - b;
|
1905 | }
|
1906 |
|
1907 | function symmetricDifference(x, y) {
|
1908 | if (arguments.length === 1) {
|
1909 | return _y => symmetricDifference(x, _y);
|
1910 | }
|
1911 |
|
1912 | return concat(filter(value => !includes(value, y), x), filter(value => !includes(value, x), y));
|
1913 | }
|
1914 |
|
1915 | function tail(listOrString) {
|
1916 | return drop(1, listOrString);
|
1917 | }
|
1918 |
|
1919 | function takeLast(howMany, listOrString) {
|
1920 | if (arguments.length === 1) return _listOrString => takeLast(howMany, _listOrString);
|
1921 | const len = listOrString.length;
|
1922 | if (howMany < 0) return listOrString.slice();
|
1923 | let numValue = howMany > len ? len : howMany;
|
1924 | if (typeof listOrString === 'string') return listOrString.slice(len - numValue);
|
1925 | numValue = len - numValue;
|
1926 | return baseSlice(listOrString, numValue, len);
|
1927 | }
|
1928 |
|
1929 | function takeLastWhile(predicate, input) {
|
1930 | if (arguments.length === 1) {
|
1931 | return _input => takeLastWhile(predicate, _input);
|
1932 | }
|
1933 |
|
1934 | if (input.length === 0) return input;
|
1935 | let found = false;
|
1936 | const toReturn = [];
|
1937 | let counter = input.length;
|
1938 |
|
1939 | while (!found || counter === 0) {
|
1940 | counter--;
|
1941 |
|
1942 | if (predicate(input[counter]) === false) {
|
1943 | found = true;
|
1944 | } else if (!found) {
|
1945 | toReturn.push(input[counter]);
|
1946 | }
|
1947 | }
|
1948 |
|
1949 | return _isArray(input) ? toReturn.reverse() : toReturn.reverse().join('');
|
1950 | }
|
1951 |
|
1952 | function takeWhile(predicate, iterable) {
|
1953 | if (arguments.length === 1) {
|
1954 | return _iterable => takeWhile(predicate, _iterable);
|
1955 | }
|
1956 |
|
1957 | const isArray = _isArray(iterable);
|
1958 |
|
1959 | if (!isArray && typeof iterable !== 'string') {
|
1960 | throw new Error('`iterable` is neither list nor a string');
|
1961 | }
|
1962 |
|
1963 | let flag = true;
|
1964 | const holder = [];
|
1965 | let counter = -1;
|
1966 |
|
1967 | while (counter++ < iterable.length - 1) {
|
1968 | if (!predicate(iterable[counter])) {
|
1969 | if (flag) flag = false;
|
1970 | } else if (flag) {
|
1971 | holder.push(iterable[counter]);
|
1972 | }
|
1973 | }
|
1974 | return isArray ? holder : holder.join('');
|
1975 | }
|
1976 |
|
1977 | function tap(fn, x) {
|
1978 | if (arguments.length === 1) return _x => tap(fn, _x);
|
1979 | fn(x);
|
1980 | return x;
|
1981 | }
|
1982 |
|
1983 | function test(pattern, str) {
|
1984 | if (arguments.length === 1) return _str => test(pattern, _str);
|
1985 |
|
1986 | if (typeof pattern === 'string') {
|
1987 | throw new TypeError(`‘test’ requires a value of type RegExp as its first argument; received "${pattern}"`);
|
1988 | }
|
1989 |
|
1990 | return str.search(pattern) !== -1;
|
1991 | }
|
1992 |
|
1993 | function times(fn, howMany) {
|
1994 | if (arguments.length === 1) return _howMany => times(fn, _howMany);
|
1995 |
|
1996 | if (!Number.isInteger(howMany) || howMany < 0) {
|
1997 | throw new RangeError('n must be an integer');
|
1998 | }
|
1999 |
|
2000 | return map(fn, range(0, howMany));
|
2001 | }
|
2002 |
|
2003 | function toLower(str) {
|
2004 | return str.toLowerCase();
|
2005 | }
|
2006 |
|
2007 | function toPairs(obj) {
|
2008 | return Object.entries(obj);
|
2009 | }
|
2010 |
|
2011 | function toString(x) {
|
2012 | return x.toString();
|
2013 | }
|
2014 |
|
2015 | function toUpper(str) {
|
2016 | return str.toUpperCase();
|
2017 | }
|
2018 |
|
2019 | function transpose(array) {
|
2020 | return array.reduce((acc, el) => {
|
2021 | el.forEach((nestedEl, i) => _isArray(acc[i]) ? acc[i].push(nestedEl) : acc.push([nestedEl]));
|
2022 | return acc;
|
2023 | }, []);
|
2024 | }
|
2025 |
|
2026 | function trim(str) {
|
2027 | return str.trim();
|
2028 | }
|
2029 |
|
2030 | function isFunction(fn) {
|
2031 | return ['Async', 'Function'].includes(type(fn));
|
2032 | }
|
2033 |
|
2034 | function tryCatch(fn, fallback) {
|
2035 | if (!isFunction(fn)) {
|
2036 | throw new Error(`R.tryCatch | fn '${fn}'`);
|
2037 | }
|
2038 |
|
2039 | const passFallback = isFunction(fallback);
|
2040 | return (...inputs) => {
|
2041 | try {
|
2042 | return fn(...inputs);
|
2043 | } catch (e) {
|
2044 | return passFallback ? fallback(e, ...inputs) : fallback;
|
2045 | }
|
2046 | };
|
2047 | }
|
2048 |
|
2049 | function union(x, y) {
|
2050 | if (arguments.length === 1) return _y => union(x, _y);
|
2051 | const toReturn = x.slice();
|
2052 | y.forEach(yInstance => {
|
2053 | if (!includes(yInstance, x)) toReturn.push(yInstance);
|
2054 | });
|
2055 | return toReturn;
|
2056 | }
|
2057 |
|
2058 | function uniqWith(predicate, list) {
|
2059 | if (arguments.length === 1) return _list => uniqWith(predicate, _list);
|
2060 | let index = -1;
|
2061 | const willReturn = [];
|
2062 |
|
2063 | while (++index < list.length) {
|
2064 | const value = list[index];
|
2065 | const flag = any(x => predicate(value, x), willReturn);
|
2066 |
|
2067 | if (!flag) {
|
2068 | willReturn.push(value);
|
2069 | }
|
2070 | }
|
2071 |
|
2072 | return willReturn;
|
2073 | }
|
2074 |
|
2075 | function unless(predicate, whenFalse) {
|
2076 | if (arguments.length === 1) {
|
2077 | return _whenFalse => unless(predicate, _whenFalse);
|
2078 | }
|
2079 |
|
2080 | return input => predicate(input) ? input : whenFalse(input);
|
2081 | }
|
2082 |
|
2083 | function values(obj) {
|
2084 | if (type(obj) !== 'Object') return [];
|
2085 | return Object.values(obj);
|
2086 | }
|
2087 |
|
2088 | const Const = x => ({
|
2089 | x,
|
2090 | map: fn => Const(x)
|
2091 | });
|
2092 |
|
2093 | function view(lens, target) {
|
2094 | if (arguments.length === 1) return _target => view(lens, _target);
|
2095 | return lens(Const)(target).x;
|
2096 | }
|
2097 |
|
2098 | function whenFn(predicate, whenTrueFn, input) {
|
2099 | if (!predicate(input)) return input;
|
2100 | return whenTrueFn(input);
|
2101 | }
|
2102 |
|
2103 | const when = curry(whenFn);
|
2104 |
|
2105 | function where(conditions, input) {
|
2106 | if (input === undefined) {
|
2107 | return _input => where(conditions, _input);
|
2108 | }
|
2109 |
|
2110 | let flag = true;
|
2111 |
|
2112 | for (const prop in conditions) {
|
2113 | const result = conditions[prop](input[prop]);
|
2114 |
|
2115 | if (flag && result === false) {
|
2116 | flag = false;
|
2117 | }
|
2118 | }
|
2119 |
|
2120 | return flag;
|
2121 | }
|
2122 |
|
2123 | function whereEq(condition, input) {
|
2124 | if (arguments.length === 1) {
|
2125 | return _input => whereEq(condition, _input);
|
2126 | }
|
2127 |
|
2128 | const result = filter((conditionValue, conditionProp) => equals(conditionValue, input[conditionProp]), condition);
|
2129 | return Object.keys(result).length === Object.keys(condition).length;
|
2130 | }
|
2131 |
|
2132 | function without(matchAgainst, source) {
|
2133 | if (source === undefined) {
|
2134 | return _source => without(matchAgainst, _source);
|
2135 | }
|
2136 |
|
2137 | return reduce((prev, current) => includesArray(current, matchAgainst) ? prev : prev.concat(current), [], source);
|
2138 | }
|
2139 |
|
2140 | function xor(a, b) {
|
2141 | if (arguments.length === 1) return _b => xor(a, _b);
|
2142 | return Boolean(a) && !b || Boolean(b) && !a;
|
2143 | }
|
2144 |
|
2145 | function zip(left, right) {
|
2146 | if (arguments.length === 1) return _right => zip(left, _right);
|
2147 | const result = [];
|
2148 | const length = Math.min(left.length, right.length);
|
2149 |
|
2150 | for (let i = 0; i < length; i++) {
|
2151 | result[i] = [left[i], right[i]];
|
2152 | }
|
2153 |
|
2154 | return result;
|
2155 | }
|
2156 |
|
2157 | function zipObj(keys, values) {
|
2158 | if (arguments.length === 1) return yHolder => zipObj(keys, yHolder);
|
2159 | return take(values.length, keys).reduce((prev, xInstance, i) => {
|
2160 | prev[xInstance] = values[i];
|
2161 | return prev;
|
2162 | }, {});
|
2163 | }
|
2164 |
|
2165 | function zipWithFn(fn, x, y) {
|
2166 | return take(x.length > y.length ? y.length : x.length, x).map((xInstance, i) => fn(xInstance, y[i]));
|
2167 | }
|
2168 |
|
2169 | const zipWith = curry(zipWithFn);
|
2170 |
|
2171 | exports.F = F;
|
2172 | exports.T = T;
|
2173 | exports.add = add;
|
2174 | exports.adjust = adjust;
|
2175 | exports.all = all;
|
2176 | exports.allPass = allPass;
|
2177 | exports.always = always;
|
2178 | exports.and = and;
|
2179 | exports.any = any;
|
2180 | exports.anyPass = anyPass;
|
2181 | exports.append = append;
|
2182 | exports.applySpec = applySpec;
|
2183 | exports.assoc = assoc;
|
2184 | exports.assocPath = assocPath;
|
2185 | exports.both = both;
|
2186 | exports.chain = chain;
|
2187 | exports.clamp = clamp;
|
2188 | exports.clone = clone;
|
2189 | exports.complement = complement;
|
2190 | exports.compose = compose;
|
2191 | exports.concat = concat;
|
2192 | exports.cond = cond;
|
2193 | exports.converge = converge;
|
2194 | exports.curry = curry;
|
2195 | exports.curryN = curryN;
|
2196 | exports.dec = dec;
|
2197 | exports.defaultTo = defaultTo;
|
2198 | exports.difference = difference;
|
2199 | exports.dissoc = dissoc;
|
2200 | exports.divide = divide;
|
2201 | exports.drop = drop;
|
2202 | exports.dropLast = dropLast;
|
2203 | exports.dropLastWhile = dropLastWhile;
|
2204 | exports.dropRepeats = dropRepeats;
|
2205 | exports.dropRepeatsWith = dropRepeatsWith;
|
2206 | exports.dropWhile = dropWhile;
|
2207 | exports.either = either;
|
2208 | exports.endsWith = endsWith;
|
2209 | exports.eqProps = eqProps;
|
2210 | exports.equals = equals;
|
2211 | exports.evolve = evolve;
|
2212 | exports.evolveArray = evolveArray;
|
2213 | exports.evolveObject = evolveObject;
|
2214 | exports.filter = filter;
|
2215 | exports.filterArray = filterArray;
|
2216 | exports.filterObject = filterObject;
|
2217 | exports.find = find;
|
2218 | exports.findIndex = findIndex;
|
2219 | exports.findLast = findLast;
|
2220 | exports.findLastIndex = findLastIndex;
|
2221 | exports.flatten = flatten;
|
2222 | exports.flip = flip;
|
2223 | exports.forEach = forEach;
|
2224 | exports.fromPairs = fromPairs;
|
2225 | exports.groupBy = groupBy;
|
2226 | exports.groupWith = groupWith;
|
2227 | exports.has = has;
|
2228 | exports.hasPath = hasPath;
|
2229 | exports.head = head;
|
2230 | exports.identical = identical;
|
2231 | exports.identity = identity;
|
2232 | exports.ifElse = ifElse;
|
2233 | exports.inc = inc;
|
2234 | exports.includes = includes;
|
2235 | exports.includesArray = includesArray;
|
2236 | exports.indexBy = indexBy;
|
2237 | exports.indexOf = indexOf;
|
2238 | exports.init = init;
|
2239 | exports.intersection = intersection;
|
2240 | exports.intersperse = intersperse;
|
2241 | exports.is = is;
|
2242 | exports.isEmpty = isEmpty;
|
2243 | exports.isNil = isNil;
|
2244 | exports.join = join;
|
2245 | exports.keys = keys;
|
2246 | exports.last = last;
|
2247 | exports.lastIndexOf = lastIndexOf;
|
2248 | exports.length = length;
|
2249 | exports.lens = lens;
|
2250 | exports.lensIndex = lensIndex;
|
2251 | exports.lensPath = lensPath;
|
2252 | exports.lensProp = lensProp;
|
2253 | exports.map = map;
|
2254 | exports.mapArray = mapArray;
|
2255 | exports.mapObject = mapObject;
|
2256 | exports.match = match;
|
2257 | exports.mathMod = mathMod;
|
2258 | exports.max = max;
|
2259 | exports.maxBy = maxBy;
|
2260 | exports.maxByFn = maxByFn;
|
2261 | exports.mean = mean;
|
2262 | exports.median = median;
|
2263 | exports.merge = merge;
|
2264 | exports.mergeAll = mergeAll;
|
2265 | exports.mergeDeepRight = mergeDeepRight;
|
2266 | exports.mergeLeft = mergeLeft;
|
2267 | exports.min = min;
|
2268 | exports.minBy = minBy;
|
2269 | exports.minByFn = minByFn;
|
2270 | exports.modulo = modulo;
|
2271 | exports.move = move;
|
2272 | exports.multiply = multiply;
|
2273 | exports.negate = negate;
|
2274 | exports.none = none;
|
2275 | exports.not = not;
|
2276 | exports.nth = nth;
|
2277 | exports.objOf = objOf;
|
2278 | exports.of = of;
|
2279 | exports.omit = omit;
|
2280 | exports.once = once;
|
2281 | exports.or = or;
|
2282 | exports.over = over;
|
2283 | exports.partial = partial;
|
2284 | exports.partition = partition;
|
2285 | exports.partitionArray = partitionArray;
|
2286 | exports.partitionObject = partitionObject;
|
2287 | exports.path = path;
|
2288 | exports.pathEq = pathEq;
|
2289 | exports.pathOr = pathOr;
|
2290 | exports.paths = paths;
|
2291 | exports.pick = pick;
|
2292 | exports.pickAll = pickAll;
|
2293 | exports.pipe = pipe;
|
2294 | exports.pluck = pluck;
|
2295 | exports.prepend = prepend;
|
2296 | exports.product = product;
|
2297 | exports.prop = prop;
|
2298 | exports.propEq = propEq;
|
2299 | exports.propIs = propIs;
|
2300 | exports.propOr = propOr;
|
2301 | exports.props = props;
|
2302 | exports.range = range;
|
2303 | exports.reduce = reduce;
|
2304 | exports.reject = reject;
|
2305 | exports.repeat = repeat;
|
2306 | exports.replace = replace;
|
2307 | exports.reverse = reverse;
|
2308 | exports.set = set;
|
2309 | exports.slice = slice;
|
2310 | exports.sort = sort;
|
2311 | exports.sortBy = sortBy;
|
2312 | exports.split = split;
|
2313 | exports.splitAt = splitAt;
|
2314 | exports.splitEvery = splitEvery;
|
2315 | exports.splitWhen = splitWhen;
|
2316 | exports.startsWith = startsWith;
|
2317 | exports.subtract = subtract;
|
2318 | exports.sum = sum;
|
2319 | exports.symmetricDifference = symmetricDifference;
|
2320 | exports.tail = tail;
|
2321 | exports.take = take;
|
2322 | exports.takeLast = takeLast;
|
2323 | exports.takeLastWhile = takeLastWhile;
|
2324 | exports.takeWhile = takeWhile;
|
2325 | exports.tap = tap;
|
2326 | exports.test = test;
|
2327 | exports.times = times;
|
2328 | exports.toLower = toLower;
|
2329 | exports.toPairs = toPairs;
|
2330 | exports.toString = toString;
|
2331 | exports.toUpper = toUpper;
|
2332 | exports.transpose = transpose;
|
2333 | exports.trim = trim;
|
2334 | exports.tryCatch = tryCatch;
|
2335 | exports.type = type;
|
2336 | exports.union = union;
|
2337 | exports.uniq = uniq;
|
2338 | exports.uniqWith = uniqWith;
|
2339 | exports.unless = unless;
|
2340 | exports.update = update;
|
2341 | exports.values = values;
|
2342 | exports.view = view;
|
2343 | exports.when = when;
|
2344 | exports.where = where;
|
2345 | exports.whereEq = whereEq;
|
2346 | exports.without = without;
|
2347 | exports.xor = xor;
|
2348 | exports.zip = zip;
|
2349 | exports.zipObj = zipObj;
|
2350 | exports.zipWith = zipWith;
|
2351 |
|
\ | No newline at end of file |