ramda-adjunct 2.32.0 → 2.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/.nvmrc +1 -0
  2. package/CHANGELOG.md +10 -0
  3. package/README.md +3 -3
  4. package/dist/RA.node.js +232 -129
  5. package/dist/RA.node.min.js +1 -1
  6. package/dist/RA.web.js +232 -129
  7. package/dist/RA.web.min.js +1 -1
  8. package/dist/RA.web.standalone.js +232 -129
  9. package/dist/RA.web.standalone.min.js +1 -1
  10. package/es/catchP.js +24 -0
  11. package/es/dispatch.js +1 -1
  12. package/es/fantasy-land/Identity.js +61 -74
  13. package/es/fantasy-land/mapping.js +20 -23
  14. package/es/fantasy-land/traits.js +1 -1
  15. package/es/flattenDepth.js +1 -1
  16. package/es/index.js +3 -1
  17. package/es/internal/ap.js +1 -1
  18. package/es/internal/ponyfills/Array.from.js +1 -1
  19. package/es/internal/ponyfills/Promise.allSettled.js +1 -1
  20. package/es/internal/ponyfills/Promise.any.js +1 -1
  21. package/es/isSentinelValue.js +26 -0
  22. package/es/lastP.js +1 -1
  23. package/es/reduceP.js +1 -1
  24. package/es/reduceRightP.js +1 -1
  25. package/es/sortByProps.js +1 -1
  26. package/lib/anyP.js +2 -2
  27. package/lib/catchP.js +30 -0
  28. package/lib/dispatch.js +1 -1
  29. package/lib/fantasy-land/Identity.js +65 -75
  30. package/lib/fantasy-land/mapping.js +41 -25
  31. package/lib/fantasy-land/traits.js +18 -12
  32. package/lib/flattenDepth.js +1 -1
  33. package/lib/index.js +11 -3
  34. package/lib/internal/ap.js +9 -3
  35. package/lib/internal/ponyfills/Array.from.js +1 -1
  36. package/lib/internal/ponyfills/Promise.allSettled.js +1 -1
  37. package/lib/internal/ponyfills/Promise.any.js +1 -1
  38. package/lib/isSentinelValue.js +35 -0
  39. package/lib/lastP.js +1 -1
  40. package/lib/reduceP.js +1 -1
  41. package/lib/reduceRightP.js +1 -1
  42. package/lib/sortByProps.js +1 -1
  43. package/package.json +24 -25
  44. package/src/catchP.js +25 -0
  45. package/src/fantasy-land/Identity.js +24 -27
  46. package/src/fantasy-land/mapping.js +20 -24
  47. package/src/fantasy-land/traits.js +1 -1
  48. package/src/index.js +2 -0
  49. package/src/internal/ap.js +1 -1
  50. package/src/internal/ponyfills/Promise.allSettled.js +4 -3
  51. package/src/isSentinelValue.js +26 -0
  52. package/types/index.d.ts +14 -0
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "cookbook",
15
15
  "functional"
16
16
  ],
17
- "version": "2.32.0",
17
+ "version": "2.33.0",
18
18
  "homepage": "https://github.com/char0n/ramda-adjunct",
19
19
  "license": "BSD-3-Clause",
20
20
  "repository": {
@@ -78,7 +78,6 @@
78
78
  "build:es": "better-npm-run build:es",
79
79
  "build:commonjs": "better-npm-run build:commonjs",
80
80
  "build:umd": "better-npm-run build:umd",
81
- "prepublishOnly": "better-npm-run prepublishOnly",
82
81
  "clean": "better-npm-run clean"
83
82
  },
84
83
  "betterScripts": {
@@ -139,47 +138,47 @@
139
138
  "ramda": ">= 0.19.0 <= 0.27.1"
140
139
  },
141
140
  "devDependencies": {
142
- "@babel/cli": "7.13.14",
143
- "@babel/core": "7.13.15",
144
- "@babel/plugin-transform-modules-commonjs": "7.13.8",
145
- "@babel/preset-env": "7.12.11",
146
- "@babel/register": "7.13.14",
147
- "@commitlint/cli": "=12.1.1",
148
- "@commitlint/config-conventional": "=12.1.1",
141
+ "@babel/cli": "7.14.3",
142
+ "@babel/core": "=7.14.3",
143
+ "@babel/plugin-transform-modules-commonjs": "7.14.0",
144
+ "@babel/preset-env": "=7.14.2",
145
+ "@babel/register": "7.13.16",
146
+ "@commitlint/cli": "=12.1.4",
147
+ "@commitlint/config-conventional": "=12.1.4",
149
148
  "assert": "=2.0.0",
150
149
  "babel-loader": "8.2.2",
151
150
  "babel-plugin-annotate-pure-calls": "0.4.0",
152
151
  "babel-plugin-istanbul": "6.0.0",
153
152
  "better-npm-run": "0.1.1",
154
153
  "chai": "4.3.4",
155
- "codecov": "3.8.1",
154
+ "codecov": "3.8.2",
156
155
  "conventional-changelog-cli": "2.1.1",
157
- "core-js": "=3.10.1",
156
+ "core-js": "=3.12.1",
158
157
  "docdash": "git+https://github.com/char0n/docdash.git#534b44382138a55dd8d93642c979e51e46471185",
159
158
  "dtslint": "=4.0.9",
160
- "eslint": "7.23.0",
159
+ "eslint": "7.26.0",
161
160
  "eslint-config-airbnb-base": "14.2.1",
162
- "eslint-config-prettier": "=8.1.0",
163
- "eslint-plugin-import": "2.22.1",
161
+ "eslint-config-prettier": "=8.3.0",
162
+ "eslint-plugin-import": "2.23.2",
164
163
  "eslint-plugin-mocha": "8.1.0",
165
- "eslint-plugin-prettier": "3.3.1",
164
+ "eslint-plugin-prettier": "3.4.0",
166
165
  "eslint-plugin-ramda": "2.5.1",
167
- "fantasy-land": "4.1.0",
166
+ "fantasy-land": "5.0.0",
168
167
  "fantasy-laws": "=1.2.0",
169
168
  "folktale": "=2.3.2",
170
- "glob": "7.1.6",
169
+ "glob": "7.1.7",
171
170
  "husky": "6.0.0",
172
171
  "istanbul": "=0.4.5",
173
- "jsdoc": "3.6.6",
172
+ "jsdoc": "=3.6.7",
174
173
  "jsverify": "0.8.4",
175
174
  "license-cli": "1.1.6",
176
- "lint-staged": "10.5.4",
177
- "mocha": "=8.3.2",
175
+ "lint-staged": "11.0.0",
176
+ "mocha": "=8.4.0",
178
177
  "mocha-junit-reporter": "2.0.0",
179
178
  "mocha-multi-reporters": "1.5.1",
180
179
  "monet": "0.9.2",
181
180
  "nyc": "15.1.0",
182
- "prettier": "=2.2.1",
181
+ "prettier": "=2.3.0",
183
182
  "process": "=0.11.10",
184
183
  "ramda": "0.27.1",
185
184
  "ramda-fantasy": "=0.8.0",
@@ -187,12 +186,12 @@
187
186
  "rimraf": "3.0.2",
188
187
  "sanctuary-show": "2.0.0",
189
188
  "sinon": "10.0.1",
190
- "terser-webpack-plugin": "5.1.1",
191
- "testem": "=3.4.0",
189
+ "terser-webpack-plugin": "5.1.2",
190
+ "testem": "=3.4.1",
192
191
  "tslint": "=6.1.3",
193
192
  "typescript": "=4.2.4",
194
- "webpack": "=5.31.0",
195
- "webpack-cli": "4.6.0"
193
+ "webpack": "=5.37.1",
194
+ "webpack-cli": "4.7.0"
196
195
  },
197
196
  "browserslist": "> 0.25%, ie 10, ie 11, not op_mini all",
198
197
  "tonicExampleFilename": "tonicExample.js",
package/src/catchP.js ADDED
@@ -0,0 +1,25 @@
1
+ import { invoker } from 'ramda';
2
+
3
+ /**
4
+ * Composable shortcut for `Promise.catch`.
5
+ * The catchP function returns a Promise. It takes two arguments: a callback function for the failure of the Promise
6
+ * and the promise instance itself.
7
+ *
8
+ * @func catchP
9
+ * @memberOf RA
10
+ * @since {@link https://char0n.github.io/ramda-adjunct/2.29.0|v2.29.0}
11
+ * @category Function
12
+ * @sig (a -> Promise b | b) -> Promise b
13
+ * @param {Function} onRejected A Function called if the Promise is rejected. This function has one argument, the rejection reason.
14
+ * @param {Promise} promise Any Promise
15
+ * @return {Promise} Returns a Promise with dealt rejected cases
16
+ * @see {@link RA.thenP|thenP}, {@link RA.resolveP|resolveP}, {@link RA.rejectP|rejectP}, {@link RA.allP|allP}
17
+ *
18
+ * @example
19
+ *
20
+ * RA.catchP(() => 'b', Promise.resolve('a')); //=> Promise('a')
21
+ * RA.catchP(() => 'b', Promise.reject('a')); //=> Promise('b')
22
+ */
23
+ const catchP = invoker(1, 'catch');
24
+
25
+ export default catchP;
@@ -1,6 +1,6 @@
1
1
  import { empty as emptyR } from 'ramda';
2
2
 
3
- import fl from './mapping';
3
+ import * as fl from './mapping';
4
4
  import {
5
5
  applyTrait,
6
6
  functorTrait,
@@ -10,9 +10,6 @@ import {
10
10
  ordTrait,
11
11
  } from './traits';
12
12
 
13
- // we do this here for jsdocs generate properly
14
- const { of, ap, map, equals, concat, chain, lte, empty, contramap } = fl;
15
-
16
13
  /**
17
14
  * The simplest {@link https://github.com/fantasyland/fantasy-land|fantasy-land}
18
15
  * compatible monad which attaches no information to values.
@@ -48,7 +45,7 @@ class Identity {
48
45
  *
49
46
  * const a = Identity.of(1); //=> Identity(1)
50
47
  */
51
- static [of](value) {
48
+ static [fl.of](value) {
52
49
  return new Identity(value);
53
50
  }
54
51
 
@@ -98,12 +95,12 @@ class Identity {
98
95
  *
99
96
  * a.ap(b); //=> Identity(2)
100
97
  */
101
- [ap](applyWithFn) {
102
- return applyTrait[ap].call(this, applyWithFn);
98
+ [fl.ap](applyWithFn) {
99
+ return applyTrait[fl.ap].call(this, applyWithFn);
103
100
  }
104
101
 
105
102
  ap(applyWithFn) {
106
- return this[ap](applyWithFn);
103
+ return this[fl.ap](applyWithFn);
107
104
  }
108
105
 
109
106
  /**
@@ -117,12 +114,12 @@ class Identity {
117
114
  * const a = Identity.of(1);
118
115
  * a.map(a => a + 1); //=> Identity(2)
119
116
  */
120
- [map](fn) {
121
- return functorTrait[map].call(this, fn);
117
+ [fl.map](fn) {
118
+ return functorTrait[fl.map].call(this, fn);
122
119
  }
123
120
 
124
121
  map(fn) {
125
- return this[map](fn);
122
+ return this[fl.map](fn);
126
123
  }
127
124
 
128
125
  /**
@@ -140,12 +137,12 @@ class Identity {
140
137
  * a.equals(b); //=> true
141
138
  * a.equals(c); //=> false
142
139
  */
143
- [equals](setoid) {
144
- return setoidTrait[equals].call(this, setoid);
140
+ [fl.equals](setoid) {
141
+ return setoidTrait[fl.equals].call(this, setoid);
145
142
  }
146
143
 
147
144
  equals(setoid) {
148
- return this[equals](setoid);
145
+ return this[fl.equals](setoid);
149
146
  }
150
147
 
151
148
  /**
@@ -168,12 +165,12 @@ class Identity {
168
165
  * const f = Identity.of(['f']);
169
166
  * e.concat(f); //=> ['e', 'f']
170
167
  */
171
- [concat](semigroup) {
172
- return semigroupTrait[concat].call(this, semigroup);
168
+ [fl.concat](semigroup) {
169
+ return semigroupTrait[fl.concat].call(this, semigroup);
173
170
  }
174
171
 
175
172
  concat(semigroup) {
176
- return this[concat](semigroup);
173
+ return this[fl.concat](semigroup);
177
174
  }
178
175
 
179
176
  /**
@@ -189,12 +186,12 @@ class Identity {
189
186
  *
190
187
  * a.chain(fn).chain(fn); //=> Identity(3)
191
188
  */
192
- [chain](fn) {
193
- return chainTrait[chain].call(this, fn);
189
+ [fl.chain](fn) {
190
+ return chainTrait[fl.chain].call(this, fn);
194
191
  }
195
192
 
196
193
  chain(fn) {
197
- return this[chain](fn);
194
+ return this[fl.chain](fn);
198
195
  }
199
196
 
200
197
  /**
@@ -213,12 +210,12 @@ class Identity {
213
210
  * a.lte(c); //=> true
214
211
  * c.lte(a); //=> false
215
212
  */
216
- [lte](ord) {
217
- return ordTrait[lte].call(this, ord);
213
+ [fl.lte](ord) {
214
+ return ordTrait[fl.lte].call(this, ord);
218
215
  }
219
216
 
220
217
  lte(ord) {
221
- return this[lte](ord);
218
+ return this[fl.lte](ord);
222
219
  }
223
220
 
224
221
  /**
@@ -237,12 +234,12 @@ class Identity {
237
234
  * a.concat(i); //=> Identity('string');
238
235
  * i.concat(a); //=> Identity('string');
239
236
  */
240
- [empty]() {
237
+ [fl.empty]() {
241
238
  return this.constructor.of(emptyR(this.value));
242
239
  }
243
240
 
244
241
  empty() {
245
- return this[empty]();
242
+ return this[fl.empty]();
246
243
  }
247
244
 
248
245
  /**
@@ -261,12 +258,12 @@ class Identity {
261
258
  * Identity.of(identity).contramap(divide2).contramap(add1).get()(3); //=> 2
262
259
  * Identity.of(identity).contramap(a => divide2(add1(a))).get()(3); //=> 2
263
260
  */
264
- [contramap](fn) {
261
+ [fl.contramap](fn) {
265
262
  return this.constructor.of((value) => this.value(fn(value)));
266
263
  }
267
264
 
268
265
  contramap(fn) {
269
- return this[contramap](fn);
266
+ return this[fl.contramap](fn);
270
267
  }
271
268
  }
272
269
 
@@ -1,24 +1,20 @@
1
- const mapping = Object.freeze({
2
- equals: 'fantasy-land/equals',
3
- lte: 'fantasy-land/lte',
4
- compose: 'fantasy-land/compose',
5
- id: 'fantasy-land/id',
6
- concat: 'fantasy-land/concat',
7
- empty: 'fantasy-land/empty',
8
- map: 'fantasy-land/map',
9
- contramap: 'fantasy-land/contramap',
10
- ap: 'fantasy-land/ap',
11
- of: 'fantasy-land/of',
12
- alt: 'fantasy-land/alt',
13
- zero: 'fantasy-land/zero',
14
- reduce: 'fantasy-land/reduce',
15
- traverse: 'fantasy-land/traverse',
16
- chain: 'fantasy-land/chain',
17
- chainRec: 'fantasy-land/chainRec',
18
- extend: 'fantasy-land/extend',
19
- extract: 'fantasy-land/extract',
20
- bimap: 'fantasy-land/bimap',
21
- promap: 'fantasy-land/promap',
22
- });
23
-
24
- export default mapping;
1
+ export const equals = 'fantasy-land/equals';
2
+ export const lte = 'fantasy-land/lte';
3
+ export const compose = 'fantasy-land/compose';
4
+ export const id = 'fantasy-land/id';
5
+ export const concat = 'fantasy-land/concat';
6
+ export const empty = 'fantasy-land/empty';
7
+ export const map = 'fantasy-land/map';
8
+ export const contramap = 'fantasy-land/contramap';
9
+ export const ap = 'fantasy-land/ap';
10
+ export const of = 'fantasy-land/of';
11
+ export const alt = 'fantasy-land/alt';
12
+ export const zero = 'fantasy-land/zero';
13
+ export const reduce = 'fantasy-land/reduce';
14
+ export const traverse = 'fantasy-land/traverse';
15
+ export const chain = 'fantasy-land/chain';
16
+ export const chainRec = 'fantasy-land/chainRec';
17
+ export const extend = 'fantasy-land/extend';
18
+ export const extract = 'fantasy-land/extract';
19
+ export const bimap = 'fantasy-land/bimap';
20
+ export const promap = 'fantasy-land/promap';
@@ -4,7 +4,7 @@ import isString from '../isString';
4
4
  import isNumber from '../isNumber';
5
5
  import isFunction from '../isFunction';
6
6
  import { isSameType } from './util';
7
- import fl from './mapping';
7
+ import * as fl from './mapping';
8
8
 
9
9
  export const functorTrait = {
10
10
  [fl.map](fn) {
package/src/index.js CHANGED
@@ -91,6 +91,7 @@ export { default as isError } from './isError';
91
91
  export { default as isNaturalNumber } from './isNaturalNumber';
92
92
  export { default as isPrimitive } from './isPrimitive';
93
93
  export { default as isNotPrimitive } from './isNotPrimitive';
94
+ export { default as isSentinelValue } from './isSentinelValue';
94
95
  // Function
95
96
  export { default as stubUndefined } from './stubUndefined';
96
97
  export { default as stubNull } from './stubNull';
@@ -107,6 +108,7 @@ export { default as weaveLazy } from './weaveLazy';
107
108
  export { default as curryRightN } from './curryRightN';
108
109
  export { default as curryRight } from './curryRight';
109
110
  export { default as allP } from './allP';
111
+ export { default as catchP } from './catchP';
110
112
  export { default as noneP } from './noneP';
111
113
  export { default as resolveP } from './resolveP';
112
114
  export { default as rejectP } from './rejectP';
@@ -1,7 +1,7 @@
1
1
  import { ap as apR, curryN, pathSatisfies, both, either } from 'ramda';
2
2
 
3
3
  import isFunction from '../isFunction';
4
- import fl from '../fantasy-land/mapping';
4
+ import * as fl from '../fantasy-land/mapping';
5
5
 
6
6
  const isFunctor = either(
7
7
  pathSatisfies(isFunction, ['map']),
@@ -7,9 +7,10 @@ const onFulfill = (value) => ({ status: 'fulfilled', value });
7
7
  const onReject = (reason) => ({ status: 'rejected', reason });
8
8
 
9
9
  const allSettledPonyfill = (iterable) => {
10
- const array = map((p) => resolveP(p).then(onFulfill).catch(onReject), [
11
- ...iterable,
12
- ]);
10
+ const array = map(
11
+ (p) => resolveP(p).then(onFulfill).catch(onReject),
12
+ [...iterable]
13
+ );
13
14
 
14
15
  return allP(array);
15
16
  };
@@ -0,0 +1,26 @@
1
+ import { curryN } from 'ramda';
2
+
3
+ import isInteger32 from './isInteger32';
4
+
5
+ /**
6
+ * Checks whether the passed value is {@link https://github.com/getify/You-Dont-Know-JS/blob/9959fc904d584bbf0b02cf41c192f74ff4238581/types-grammar/ch4.md#the-curious-case-of-the-|a sentinel value}.
7
+ *
8
+ * @func isSentinelValue
9
+ * @memberOf RA
10
+ * @since {@link https://char0n.github.io/ramda-adjunct/2.33.0|v2.33.0}
11
+ * @category Type
12
+ * @sig * -> Boolean
13
+ * @param {*} val The value to test
14
+ * @return {boolean}
15
+ * @example
16
+ *
17
+ * RA.isSentinelValue(-1); //=> true
18
+ *
19
+ * RA.isSentinelValue('-1'); //=> false
20
+ * RA.isSentinelValue(1); //=> false
21
+ * RA.isSentinelValue([-1]); //=> false
22
+ */
23
+ // eslint-disable-next-line no-bitwise
24
+ const isSentinelValue = curryN(1, (val) => isInteger32(val) && ~val === 0);
25
+
26
+ export default isSentinelValue;
package/types/index.d.ts CHANGED
@@ -455,6 +455,12 @@ declare namespace RamdaAdjunct {
455
455
  */
456
456
  isSparseArray(val: any): boolean;
457
457
 
458
+ /**
459
+ * Checks whether the passed value is
460
+ * {@link https://github.com/getify/You-Dont-Know-JS/blob/9959fc904d584bbf0b02cf41c192f74ff4238581/types-grammar/ch4.md#the-curious-case-of-the-|a sentinel value}.
461
+ */
462
+ isSentinelValue(val: any): boolean;
463
+
458
464
  /**
459
465
  * A function that returns `undefined`.
460
466
  */
@@ -996,6 +1002,14 @@ declare namespace RamdaAdjunct {
996
1002
  reject<T>(options: { timeout: number, value: T }): Promise<T>
997
1003
  };
998
1004
 
1005
+ /**
1006
+ * Composable shortcut for `Promise.catch`.
1007
+ * The catchP function returns a Promise. It takes two arguments: a callback function for the rejections of the Promise
1008
+ * and the promise instance itself.
1009
+ */
1010
+ catchP<A, B = unknown>(onRejected: (error: any) => B | Promise<B>, promise: Promise<A>): Promise<A | B>;
1011
+ catchP<A, B = unknown>(onRejected: (error: any) => B | Promise<B>): (promise: Promise<A>) => Promise<A | B>;
1012
+
999
1013
  /**
1000
1014
  * Composable shortcut for `Promise.then`.
1001
1015
  * The thenP function returns a Promise. It takes two arguments: a callback function for the success of the Promise