ramda-adjunct 2.30.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.
- package/.nvmrc +1 -0
- package/CHANGELOG.md +44 -0
- package/README.md +6 -6
- package/dist/RA.node.js +7544 -7169
- package/dist/RA.node.min.js +1 -1
- package/dist/RA.web.js +7544 -7169
- package/dist/RA.web.min.js +1 -1
- package/dist/RA.web.standalone.js +20077 -18989
- package/dist/RA.web.standalone.min.js +1 -1
- package/es/catchP.js +24 -0
- package/es/dispatch.js +1 -1
- package/es/fantasy-land/Identity.js +61 -74
- package/es/fantasy-land/mapping.js +20 -23
- package/es/fantasy-land/traits.js +1 -1
- package/es/filterIndexed.js +27 -0
- package/es/findOr.js +28 -0
- package/es/flattenDepth.js +1 -1
- package/es/index.js +14 -3
- package/es/internal/ap.js +1 -1
- package/es/internal/ponyfills/Array.from.js +1 -1
- package/es/internal/ponyfills/Promise.allSettled.js +1 -1
- package/es/internal/ponyfills/Promise.any.js +2 -2
- package/es/invoke.js +20 -0
- package/es/isInteger32.js +28 -0
- package/es/isNotPrimitive.js +22 -0
- package/es/isPrimitive.js +31 -0
- package/es/isPrototypeOf.js +34 -0
- package/es/isSentinelValue.js +26 -0
- package/es/lastP.js +1 -1
- package/es/pathOrLazy.js +1 -1
- package/es/reduceP.js +1 -1
- package/es/reduceRightP.js +1 -1
- package/es/sortByProps.js +1 -1
- package/lib/anyP.js +2 -2
- package/lib/catchP.js +30 -0
- package/lib/dispatch.js +1 -1
- package/lib/fantasy-land/Identity.js +65 -75
- package/lib/fantasy-land/mapping.js +41 -25
- package/lib/fantasy-land/traits.js +18 -12
- package/lib/filterIndexed.js +33 -0
- package/lib/findOr.js +34 -0
- package/lib/flattenDepth.js +1 -1
- package/lib/index.js +40 -3
- package/lib/internal/ap.js +9 -3
- package/lib/internal/ponyfills/Array.from.js +1 -1
- package/lib/internal/ponyfills/Promise.allSettled.js +1 -1
- package/lib/internal/ponyfills/Promise.any.js +2 -2
- package/lib/invoke.js +29 -0
- package/lib/isInteger32.js +37 -0
- package/lib/isNotPrimitive.js +31 -0
- package/lib/isPrimitive.js +47 -0
- package/lib/isPrototypeOf.js +43 -0
- package/lib/isSentinelValue.js +35 -0
- package/lib/lastP.js +1 -1
- package/lib/pathOrLazy.js +1 -1
- package/lib/reduceP.js +1 -1
- package/lib/reduceRightP.js +1 -1
- package/lib/sortByProps.js +1 -1
- package/package.json +34 -32
- package/src/catchP.js +25 -0
- package/src/fantasy-land/Identity.js +24 -27
- package/src/fantasy-land/mapping.js +20 -24
- package/src/fantasy-land/traits.js +1 -1
- package/src/filterIndexed.js +28 -0
- package/src/findOr.js +30 -0
- package/src/fnull.js +4 -4
- package/src/index.js +10 -0
- package/src/internal/ap.js +1 -1
- package/src/internal/makeFlat.js +2 -3
- package/src/internal/ponyfills/Promise.allSettled.js +4 -3
- package/src/invoke.js +22 -0
- package/src/isInteger32.js +28 -0
- package/src/isNotPrimitive.js +25 -0
- package/src/isPrimitive.js +45 -0
- package/src/isPrototypeOf.js +36 -0
- package/src/isSentinelValue.js +26 -0
- package/src/isSymbol.js +4 -4
- package/src/pathOrLazy.js +4 -4
- package/src/replaceAll.js +0 -1
- package/types/index.d.ts +85 -1
- package/.mocharc.js +0 -9
|
@@ -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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { addIndex, filter } from 'ramda';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* {@link http://ramdajs.com/docs/#filter|R.filter} function that more closely resembles `Array.prototype.filter`.
|
|
5
|
+
* It takes two new parameters to its callback function: the current index, and the entire list.
|
|
6
|
+
*
|
|
7
|
+
* `filterIndexed` implementation is simple: `
|
|
8
|
+
* const filterIndexed = R.addIndex(R.filter);
|
|
9
|
+
* `
|
|
10
|
+
*
|
|
11
|
+
* @func filterIndexed
|
|
12
|
+
* @memberOf RA
|
|
13
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/2.31.0|v2.31.0}
|
|
14
|
+
* @category List
|
|
15
|
+
* @typedef Idx = Number
|
|
16
|
+
* @sig Filterable f => ((a, Idx, f a) -> Boolean) -> f a -> f a
|
|
17
|
+
* @param {Function} pred The predicate function
|
|
18
|
+
* @param {Array} list The collection to filter
|
|
19
|
+
* @return {Array} Filterable
|
|
20
|
+
* @see {@link http://ramdajs.com/docs/#addIndex|R.addIndex}, {@link http://ramdajs.com/docs/#filter|R.filter}
|
|
21
|
+
* @example
|
|
22
|
+
*
|
|
23
|
+
* const isValueGtIndex = (val, idx) => val > idx;
|
|
24
|
+
* RA.filterIndexed(isValueGtIndex, [5, 4, 3, 2, 1, 0]); //=> [5, 4, 3]
|
|
25
|
+
*/
|
|
26
|
+
const filterIndexed = addIndex(filter);
|
|
27
|
+
|
|
28
|
+
export default filterIndexed;
|
package/src/findOr.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { pipe, curry, find, defaultTo } from 'ramda';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the first element of the list which matches the predicate.
|
|
5
|
+
* Returns default value if no element matches or matched element is `null`, `undefined` or `NaN`.
|
|
6
|
+
* Dispatches to the find method of the second argument, if present.
|
|
7
|
+
* Acts as a transducer if a transformer is given in list position.
|
|
8
|
+
*
|
|
9
|
+
* @func findOr
|
|
10
|
+
* @memberOf RA
|
|
11
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/2.32.0|v2.32.0}
|
|
12
|
+
* @category List
|
|
13
|
+
* @sig a -> (b -> Boolean) -> [b] -> b | a
|
|
14
|
+
* @param {*} defaultValue The default value
|
|
15
|
+
* @param {Function} fn The predicate function used to determine if the element is the desired one.
|
|
16
|
+
* @param {Array} list The array to consider.
|
|
17
|
+
* @return {*} The element found, or the default value.
|
|
18
|
+
* @see {@link http://ramdajs.com/docs/#defaultTo|R.defaultTo}, {@link http://ramdajs.com/docs/#find|R.find}
|
|
19
|
+
* @example
|
|
20
|
+
*
|
|
21
|
+
* RA.findOr(1, isUndefined, [1, 2, undefined]); // => 1
|
|
22
|
+
* RA.findOr(1, val => val === 2, [1, 2, undefined]); // => 2
|
|
23
|
+
* RA.findOr(1, val => val === 3, [1, 2, undefined]); // => 1
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const findOr = curry((defaultVal, fn, list) =>
|
|
27
|
+
pipe(find(fn), defaultTo(defaultVal))(list)
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export default findOr;
|
package/src/fnull.js
CHANGED
|
@@ -24,15 +24,15 @@ import mapIndexed from './mapIndexed';
|
|
|
24
24
|
* addDefaults(undefined, undefined); // => 9
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
-
const fnull = curry((fn, defaults) =>
|
|
28
|
-
|
|
27
|
+
const fnull = curry((fn, defaults) =>
|
|
28
|
+
curryN(fn.length, (...args) => {
|
|
29
29
|
const argsWithDefaults = mapIndexed(
|
|
30
30
|
(val, idx) => defaultWhen(isNil, defaults[idx], val),
|
|
31
31
|
args
|
|
32
32
|
);
|
|
33
33
|
|
|
34
34
|
return apply(fn, argsWithDefaults);
|
|
35
|
-
})
|
|
36
|
-
|
|
35
|
+
})
|
|
36
|
+
);
|
|
37
37
|
|
|
38
38
|
export default fnull;
|
package/src/index.js
CHANGED
|
@@ -61,6 +61,8 @@ export { default as isNotNaN } from './isNotNaN';
|
|
|
61
61
|
export { default as isFinite } from './isFinite';
|
|
62
62
|
export { default as isNotFinite } from './isNotFinite';
|
|
63
63
|
export { default as isInteger } from './isInteger';
|
|
64
|
+
export { default as isInteger32 } from './isInteger32';
|
|
65
|
+
export { default as isInt32 } from './isInteger32'; // alias of isInteger32
|
|
64
66
|
export { default as isNotInteger } from './isNotInteger';
|
|
65
67
|
export { default as isBigInt } from './isBigInt';
|
|
66
68
|
export { default as isFloat } from './isFloat';
|
|
@@ -87,6 +89,9 @@ export { default as isSafeInteger } from './isSafeInteger';
|
|
|
87
89
|
export { default as isIndexed } from './isIndexed';
|
|
88
90
|
export { default as isError } from './isError';
|
|
89
91
|
export { default as isNaturalNumber } from './isNaturalNumber';
|
|
92
|
+
export { default as isPrimitive } from './isPrimitive';
|
|
93
|
+
export { default as isNotPrimitive } from './isNotPrimitive';
|
|
94
|
+
export { default as isSentinelValue } from './isSentinelValue';
|
|
90
95
|
// Function
|
|
91
96
|
export { default as stubUndefined } from './stubUndefined';
|
|
92
97
|
export { default as stubNull } from './stubNull';
|
|
@@ -103,6 +108,7 @@ export { default as weaveLazy } from './weaveLazy';
|
|
|
103
108
|
export { default as curryRightN } from './curryRightN';
|
|
104
109
|
export { default as curryRight } from './curryRight';
|
|
105
110
|
export { default as allP } from './allP';
|
|
111
|
+
export { default as catchP } from './catchP';
|
|
106
112
|
export { default as noneP } from './noneP';
|
|
107
113
|
export { default as resolveP } from './resolveP';
|
|
108
114
|
export { default as rejectP } from './rejectP';
|
|
@@ -123,6 +129,7 @@ export { default as fnull } from './fnull';
|
|
|
123
129
|
// List
|
|
124
130
|
export { default as mapIndexed } from './mapIndexed';
|
|
125
131
|
export { default as reduceIndexed } from './reduceIndexed';
|
|
132
|
+
export { default as filterIndexed } from './filterIndexed';
|
|
126
133
|
export { default as pickIndexes } from './pickIndexes';
|
|
127
134
|
export { default as list } from './list';
|
|
128
135
|
export { default as ensureArray } from './ensureArray';
|
|
@@ -156,7 +163,9 @@ export { default as notAllUnique } from './notAllUnique';
|
|
|
156
163
|
export { default as sortByProps } from './sortByProps';
|
|
157
164
|
export { default as skipTake } from './skipTake';
|
|
158
165
|
export { default as rangeStep } from './rangeStep';
|
|
166
|
+
export { default as findOr } from './findOr';
|
|
159
167
|
// Object
|
|
168
|
+
export { default as invoke } from './invoke';
|
|
160
169
|
export { default as invokeArgs } from './invokeArgs';
|
|
161
170
|
export { default as paths } from './paths';
|
|
162
171
|
export { default as renameKeys } from './renameKeys';
|
|
@@ -179,6 +188,7 @@ export { default as flattenProp } from './flattenProp';
|
|
|
179
188
|
export { default as flattenPath } from './flattenPath';
|
|
180
189
|
export { default as unzipObjWith } from './unzipObjWith';
|
|
181
190
|
export { default as zipObjWith } from './zipObjWith';
|
|
191
|
+
export { default as isPrototypeOf } from './isPrototypeOf';
|
|
182
192
|
// Relation
|
|
183
193
|
export { default as lensEq } from './lensEq';
|
|
184
194
|
export { default as lensNotEq } from './lensNotEq';
|
package/src/internal/ap.js
CHANGED
|
@@ -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']),
|
package/src/internal/makeFlat.js
CHANGED
|
@@ -14,8 +14,8 @@ import isArrayLike from '../isArrayLike';
|
|
|
14
14
|
* @sig Bool -> List -> List
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
|
-
const makeFlat = (recursive) =>
|
|
18
|
-
|
|
17
|
+
const makeFlat = (recursive) =>
|
|
18
|
+
function flatt(list) {
|
|
19
19
|
let value;
|
|
20
20
|
let jlen;
|
|
21
21
|
let j;
|
|
@@ -38,6 +38,5 @@ const makeFlat = (recursive) => {
|
|
|
38
38
|
}
|
|
39
39
|
return result;
|
|
40
40
|
};
|
|
41
|
-
};
|
|
42
41
|
|
|
43
42
|
export default makeFlat;
|
|
@@ -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(
|
|
11
|
-
|
|
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
|
};
|
package/src/invoke.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { __ } from 'ramda';
|
|
2
|
+
|
|
3
|
+
import invokeArgs from './invokeArgs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Invokes the method at path of object.
|
|
7
|
+
*
|
|
8
|
+
* @func invoke
|
|
9
|
+
* @memberOf RA
|
|
10
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/2.31.0|v2.31.0}
|
|
11
|
+
* @category Object
|
|
12
|
+
* @sig Array -> Object -> *
|
|
13
|
+
* @param {Array.<string|number>} path The path of the method to invoke
|
|
14
|
+
* @param {Object} obj The object to query
|
|
15
|
+
* @return {*}
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* RA.invoke(['random'], Math); //=> 0.5113253820009047
|
|
19
|
+
*/
|
|
20
|
+
const invoke = invokeArgs(__, [], __);
|
|
21
|
+
|
|
22
|
+
export default invoke;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { curryN } from 'ramda';
|
|
2
|
+
|
|
3
|
+
import toInteger32 from './toInteger32';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks whether the passed value is a signed 32 bit integer.
|
|
7
|
+
*
|
|
8
|
+
* @func isInteger32
|
|
9
|
+
* @aliases isInt32
|
|
10
|
+
* @memberOf RA
|
|
11
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/2.32.0|v2.32.0}
|
|
12
|
+
* @category Type
|
|
13
|
+
* @sig * -> Boolean
|
|
14
|
+
* @param {*} val The value to test
|
|
15
|
+
* @return {boolean}
|
|
16
|
+
* @see {@link RA.toInteger32|toInteger32}
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* RA.isInteger32(0); //=> true
|
|
20
|
+
* RA.isInteger32((-2) ** 31); //=> true
|
|
21
|
+
*
|
|
22
|
+
* RA.isInteger32(Infinity); //=> false
|
|
23
|
+
* RA.isInteger32(NaN); //=> false
|
|
24
|
+
* RA.isInteger32(2 ** 31); //=> false
|
|
25
|
+
*/
|
|
26
|
+
const isInteger32 = curryN(1, (val) => toInteger32(val) === val);
|
|
27
|
+
|
|
28
|
+
export default isInteger32;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { complement, curryN } from 'ramda';
|
|
2
|
+
|
|
3
|
+
import isPrimitive from './isPrimitive';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks if value is not a primitive data type. There are 6 primitive data types: `string`, `number`, `bigint`, `boolean`, `undefined`, `symbol` and a special case of `null`.
|
|
7
|
+
*
|
|
8
|
+
* @func isNotPrimitive
|
|
9
|
+
* @category Type
|
|
10
|
+
* @sig * -> Boolean
|
|
11
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/2.32.0|v2.32.0}
|
|
12
|
+
* @param {*} val The value to test
|
|
13
|
+
* @return {boolean}
|
|
14
|
+
* @see {@link RA.isPrimitive|isPrimitive}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#primitive_values|MDN Primitive values}, {@link https://developer.mozilla.org/en-US/docs/Glossary/Primitive|MDN Primitive}
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* RA.isNotPrimitive(new String("string")); //=> true
|
|
18
|
+
* RA.isNotPrimitive(new Number(1)); //=> true
|
|
19
|
+
* RA.isNotPrimitive("string"); //=> false
|
|
20
|
+
* RA.isNotPrimitive(1); //=> false
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const isNotPrimitive = curryN(1, complement(isPrimitive));
|
|
24
|
+
|
|
25
|
+
export default isNotPrimitive;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { both, anyPass } from 'ramda';
|
|
2
|
+
|
|
3
|
+
import isNotObj from './isNotObj';
|
|
4
|
+
import isString from './isString';
|
|
5
|
+
import isNumber from './isNumber';
|
|
6
|
+
import isBigInt from './isBigInt';
|
|
7
|
+
import isBoolean from './isBoolean';
|
|
8
|
+
import isUndefined from './isUndefined';
|
|
9
|
+
import isNull from './isNull';
|
|
10
|
+
import isSymbol from './isSymbol';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Checks if value is a primitive data type. There are 6 primitive data types: `string`, `number`, `bigint`, `boolean`, `undefined`, `symbol` and a special case of `null`.
|
|
14
|
+
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Primitive_values
|
|
15
|
+
* for definition of what sub-types comprise a primitive.
|
|
16
|
+
*
|
|
17
|
+
* @func isPrimitive
|
|
18
|
+
* @category Type
|
|
19
|
+
* @sig * -> Boolean
|
|
20
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/2.32.0|v2.32.0}
|
|
21
|
+
* @param {*} val The value to test
|
|
22
|
+
* @return {boolean}
|
|
23
|
+
* @see {@link RA.isNotPrimitive|isNotPrimitive}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#primitive_values|MDN Primitive values}, {@link https://developer.mozilla.org/en-US/docs/Glossary/Primitive|MDN Primitive}
|
|
24
|
+
* @example
|
|
25
|
+
*
|
|
26
|
+
* RA.isPrimitive("string"); //=> true
|
|
27
|
+
* RA.isPrimitive(1); //=> true
|
|
28
|
+
* RA.isPrimitive(new String("string")); //=> false
|
|
29
|
+
* RA.isPrimitive(new Number(1)); //=> false
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const isPrimitive = both(
|
|
33
|
+
isNotObj,
|
|
34
|
+
anyPass([
|
|
35
|
+
isString,
|
|
36
|
+
isNumber,
|
|
37
|
+
isBigInt,
|
|
38
|
+
isBoolean,
|
|
39
|
+
isUndefined,
|
|
40
|
+
isNull,
|
|
41
|
+
isSymbol,
|
|
42
|
+
])
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export default isPrimitive;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { curry } from 'ramda';
|
|
2
|
+
|
|
3
|
+
import invokeArgs from './invokeArgs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks if an object exists in another object's prototype chain.
|
|
7
|
+
*
|
|
8
|
+
* @func isPrototypeOf
|
|
9
|
+
* @category Object
|
|
10
|
+
* @memberOf RA
|
|
11
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/2.31.0|v2.31.0}
|
|
12
|
+
* @sig * -> Boolean
|
|
13
|
+
* @param {Object} type The prototype that we're searching for
|
|
14
|
+
* @param {Object} object The object whose prototype chain will be searched
|
|
15
|
+
* @return {boolean}
|
|
16
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf|Object.prorotype.isPrototypeOf}
|
|
17
|
+
* @example
|
|
18
|
+
* function Foo() {}
|
|
19
|
+
* function Bar() {}
|
|
20
|
+
* function Baz() {}
|
|
21
|
+
*
|
|
22
|
+
* Bar.prototype = Object.create(Foo.prototype);
|
|
23
|
+
* Baz.prototype = Object.create(Bar.prototype);
|
|
24
|
+
*
|
|
25
|
+
* const baz = new Baz();
|
|
26
|
+
*
|
|
27
|
+
* RA.isPrototypeOf(Baz, baz); // => true
|
|
28
|
+
* RA.isPrototypeOf(Bar, baz); // => true
|
|
29
|
+
* RA.isPrototypeOf(Foo, baz); // => true
|
|
30
|
+
* RA.isPrototypeOf(Object, baz); // => true
|
|
31
|
+
*/
|
|
32
|
+
const isPrototypeOf = curry((type, object) =>
|
|
33
|
+
Boolean(invokeArgs(['prototype', 'isPrototypeOf'], [object], type))
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export default isPrototypeOf;
|
|
@@ -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/src/isSymbol.js
CHANGED
|
@@ -19,11 +19,11 @@ import { type, curryN } from 'ramda';
|
|
|
19
19
|
* RA.isSymbol(undefined); //=> false
|
|
20
20
|
* RA.isSymbol(null); //=> false
|
|
21
21
|
*/
|
|
22
|
-
const isSymbol = curryN(
|
|
23
|
-
|
|
22
|
+
const isSymbol = curryN(
|
|
23
|
+
1,
|
|
24
|
+
(val) =>
|
|
24
25
|
typeof val === 'symbol' ||
|
|
25
26
|
(typeof val === 'object' && type(val) === 'Symbol')
|
|
26
|
-
|
|
27
|
-
});
|
|
27
|
+
);
|
|
28
28
|
|
|
29
29
|
export default isSymbol;
|
package/src/pathOrLazy.js
CHANGED
|
@@ -19,12 +19,12 @@ import { curryN, identical, partial, pathOr, unary, when } from 'ramda';
|
|
|
19
19
|
* RA.pathOrLazy(() => 'N/A', ['a', 'b'], {a: {b: 2}}); //=> 2
|
|
20
20
|
* RA.pathOrLazy(() => 'N/A', ['a', 'b'], {c: {b: 2}}); //=> "N/A"
|
|
21
21
|
*/
|
|
22
|
-
const pathOrLazy = curryN(3,
|
|
23
|
-
|
|
22
|
+
const pathOrLazy = curryN(3, (defaultFn, path, obj) =>
|
|
23
|
+
when(
|
|
24
24
|
identical(defaultFn),
|
|
25
25
|
partial(unary(defaultFn), [obj]),
|
|
26
26
|
pathOr(defaultFn, path, obj)
|
|
27
|
-
)
|
|
28
|
-
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
29
|
|
|
30
30
|
export default pathOrLazy;
|
package/src/replaceAll.js
CHANGED
|
@@ -28,7 +28,6 @@ export const replaceAllInvoker = invoker(2, 'replaceAll');
|
|
|
28
28
|
* RA.replaceAll(/x/g, 'v', 'xxx'); //=> 'vvv'
|
|
29
29
|
* RA.replaceAll(/x/, 'v', 'xxx'); //=> TypeError
|
|
30
30
|
*/
|
|
31
|
-
|
|
32
31
|
const replaceAll = isFunction(String.prototype.replaceAll)
|
|
33
32
|
? replaceAllInvoker
|
|
34
33
|
: replaceAllPonyfill;
|