rambda 7.2.1 → 7.4.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 (62) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +1431 -3264
  3. package/dist/rambda.js +83 -422
  4. package/dist/rambda.mjs +89 -433
  5. package/dist/rambda.umd.js +1 -1
  6. package/immutable.d.ts +290 -229
  7. package/index.d.ts +290 -229
  8. package/package.json +38 -33
  9. package/rambda.js +187 -0
  10. package/src/_internals/constants.js +1 -0
  11. package/src/_internals/isArray.js +1 -0
  12. package/src/_internals/isFalsy.js +2 -2
  13. package/src/_internals/isInteger.js +5 -0
  14. package/src/_internals/isIterable.js +5 -0
  15. package/src/_internals/isObject.js +1 -1
  16. package/src/_internals/isTruthy.js +2 -2
  17. package/src/_internals/keys.js +1 -0
  18. package/src/_internals/{_objectIs.js → objectIs.js} +2 -2
  19. package/src/applySpec.js +3 -3
  20. package/src/assocPath.js +7 -7
  21. package/src/clone.js +2 -2
  22. package/src/count.js +2 -2
  23. package/src/dropLastWhile.js +2 -2
  24. package/src/dropRepeats.js +2 -2
  25. package/src/dropRepeatsWith.js +2 -2
  26. package/src/dropWhile.js +2 -2
  27. package/src/endsWith.js +2 -2
  28. package/src/equals.js +3 -15
  29. package/src/evolve.js +1 -1
  30. package/src/filter.js +2 -2
  31. package/src/flatten.js +2 -2
  32. package/src/forEach.js +6 -6
  33. package/src/groupWith.js +2 -2
  34. package/src/identical.js +2 -2
  35. package/src/includes.js +2 -2
  36. package/src/isPromise.js +1 -1
  37. package/src/length.js +2 -2
  38. package/src/map.js +8 -7
  39. package/src/mathMod.js +2 -2
  40. package/src/merge.js +1 -1
  41. package/src/mergeDeepRight.js +2 -1
  42. package/src/mergeRight.js +2 -1
  43. package/src/modify.js +23 -0
  44. package/src/modifyPath.js +2 -2
  45. package/src/nop.js +1 -0
  46. package/src/partialObject.js +1 -11
  47. package/src/partition.js +2 -2
  48. package/src/props.js +2 -2
  49. package/src/reduce.js +2 -3
  50. package/src/splitAt.js +2 -2
  51. package/src/startsWith.js +2 -2
  52. package/src/takeLastWhile.js +2 -2
  53. package/src/takeWhile.js +2 -2
  54. package/src/test.js +1 -1
  55. package/src/times.js +2 -1
  56. package/src/transpose.js +2 -2
  57. package/src/unwind.js +4 -3
  58. package/src/update.js +1 -1
  59. package/src/where.js +1 -0
  60. package/src/_internals/_isArray.js +0 -1
  61. package/src/_internals/_isInteger.js +0 -5
  62. package/src/_internals/_keys.js +0 -1
package/src/groupWith.js CHANGED
@@ -1,8 +1,8 @@
1
- import { _isArray } from './_internals/_isArray.js'
2
1
  import { cloneList } from './_internals/cloneList.js'
2
+ import { isArray } from './_internals/isArray.js'
3
3
 
4
4
  export function groupWith(compareFn, list){
5
- if (!_isArray(list)) throw new TypeError('list.reduce is not a function')
5
+ if (!isArray(list)) throw new TypeError('list.reduce is not a function')
6
6
 
7
7
  const clone = cloneList(list)
8
8
 
package/src/identical.js CHANGED
@@ -1,7 +1,7 @@
1
- import _objectIs from './_internals/_objectIs.js'
1
+ import { objectIs } from './_internals/objectIs.js'
2
2
 
3
3
  export function identical(a, b){
4
4
  if (arguments.length === 1) return _b => identical(a, _b)
5
5
 
6
- return _objectIs(a, b)
6
+ return objectIs(a, b)
7
7
  }
package/src/includes.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _isArray } from './_internals/_isArray.js'
1
+ import { isArray } from './_internals/isArray.js'
2
2
  import { _indexOf } from './equals.js'
3
3
 
4
4
  export function includes(valueToFind, iterable){
@@ -10,7 +10,7 @@ export function includes(valueToFind, iterable){
10
10
  if (!iterable){
11
11
  throw new TypeError(`Cannot read property \'indexOf\' of ${ iterable }`)
12
12
  }
13
- if (!_isArray(iterable)) return false
13
+ if (!isArray(iterable)) return false
14
14
 
15
15
  return _indexOf(valueToFind, iterable) > -1
16
16
  }
package/src/isPromise.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type } from './type.js'
2
2
 
3
3
  export function isPromise(x){
4
- return [ 'Async', 'Promise' ].includes(type(x))
4
+ return 'Promise' === type(x)
5
5
  }
package/src/length.js CHANGED
@@ -1,7 +1,7 @@
1
- import { _isArray } from './_internals/_isArray.js'
1
+ import { isArray } from './_internals/isArray.js'
2
2
 
3
3
  export function length(x){
4
- if (_isArray(x)) return x.length
4
+ if (isArray(x)) return x.length
5
5
  if (typeof x === 'string') return x.length
6
6
 
7
7
  return NaN
package/src/map.js CHANGED
@@ -1,5 +1,6 @@
1
- import { _isArray } from './_internals/_isArray.js'
2
- import { _keys } from './_internals/_keys.js'
1
+ import { INCORRECT_ITERABLE_INPUT } from './_internals/constants.js'
2
+ import { isArray } from './_internals/isArray.js'
3
+ import { keys } from './_internals/keys.js'
3
4
 
4
5
  export function mapArray(
5
6
  fn, list, isIndexed = false
@@ -21,12 +22,12 @@ export function mapObject(fn, obj){
21
22
  return _obj => mapObject(fn, _obj)
22
23
  }
23
24
  let index = 0
24
- const keys = _keys(obj)
25
- const len = keys.length
25
+ const objKeys = keys(obj)
26
+ const len = objKeys.length
26
27
  const willReturn = {}
27
28
 
28
29
  while (index < len){
29
- const key = keys[ index ]
30
+ const key = objKeys[ index ]
30
31
  willReturn[ key ] = fn(
31
32
  obj[ key ], key, obj
32
33
  )
@@ -41,10 +42,10 @@ export const mapObjIndexed = mapObject
41
42
  export function map(fn, iterable){
42
43
  if (arguments.length === 1) return _iterable => map(fn, _iterable)
43
44
  if (!iterable){
44
- throw new Error('Incorrect iterable input')
45
+ throw new Error(INCORRECT_ITERABLE_INPUT)
45
46
  }
46
47
 
47
- if (_isArray(iterable)) return mapArray(fn, iterable)
48
+ if (isArray(iterable)) return mapArray(fn, iterable)
48
49
 
49
50
  return mapObject(fn, iterable)
50
51
  }
package/src/mathMod.js CHANGED
@@ -1,8 +1,8 @@
1
- import _isInteger from './_internals/_isInteger.js'
1
+ import { isInteger } from './_internals/isInteger.js'
2
2
 
3
3
  export function mathMod(x, y){
4
4
  if (arguments.length === 1) return _y => mathMod(x, _y)
5
- if (!_isInteger(x) || !_isInteger(y) || y < 1) return NaN
5
+ if (!isInteger(x) || !isInteger(y) || y < 1) return NaN
6
6
 
7
7
  return (x % y + y) % y
8
8
  }
package/src/merge.js CHANGED
@@ -1 +1 @@
1
- export {mergeRight as merge} from './mergeRight.js'
1
+ export { mergeRight as merge } from './mergeRight.js'
@@ -1,3 +1,4 @@
1
+ import { clone } from './clone.js'
1
2
  import { type } from './type.js'
2
3
 
3
4
  export function mergeDeepRight(target, source){
@@ -5,7 +6,7 @@ export function mergeDeepRight(target, source){
5
6
  return sourceHolder => mergeDeepRight(target, sourceHolder)
6
7
  }
7
8
 
8
- const willReturn = JSON.parse(JSON.stringify(target))
9
+ const willReturn = clone(target)
9
10
 
10
11
  Object.keys(source).forEach(key => {
11
12
  if (type(source[ key ]) === 'Object'){
package/src/mergeRight.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export function mergeRight(target, newProps){
2
- if (arguments.length === 1) return _newProps => mergeRight(target, _newProps)
2
+ if (arguments.length === 1)
3
+ return _newProps => mergeRight(target, _newProps)
3
4
 
4
5
  return Object.assign(
5
6
  {}, target || {}, newProps || {}
package/src/modify.js ADDED
@@ -0,0 +1,23 @@
1
+ import { isArray } from './_internals/isArray.js'
2
+ import { isIterable } from './_internals/isIterable.js'
3
+ import { curry } from './curry.js'
4
+ import { updateFn } from './update.js'
5
+
6
+ function modifyFn(
7
+ property, fn, iterable
8
+ ){
9
+ if (!isIterable(iterable)) return iterable
10
+ if (iterable[ property ] === undefined) return iterable
11
+ if (isArray(iterable)){
12
+ return updateFn(
13
+ property, fn(iterable[ property ]), iterable
14
+ )
15
+ }
16
+
17
+ return {
18
+ ...iterable,
19
+ [ property ] : fn(iterable[ property ]),
20
+ }
21
+ }
22
+
23
+ export const modify = curry(modifyFn)
package/src/modifyPath.js CHANGED
@@ -1,5 +1,5 @@
1
- import { _isArray } from './_internals/_isArray.js'
2
1
  import { createPath } from './_internals/createPath.js'
2
+ import { isArray } from './_internals/isArray.js'
3
3
  import { assoc } from './assoc.js'
4
4
  import { curry } from './curry.js'
5
5
  import { path as pathModule } from './path.js'
@@ -11,7 +11,7 @@ export function modifyPathFn(
11
11
  if (path.length === 1){
12
12
  return {
13
13
  ...object,
14
- [ path[0] ] : fn(object[ path[0] ]),
14
+ [ path[ 0 ] ] : fn(object[ path[ 0 ] ]),
15
15
  }
16
16
  }
17
17
  if (pathModule(path, object) === undefined) return object
package/src/nop.js ADDED
@@ -0,0 +1 @@
1
+ export function nop(){}
@@ -1,15 +1,5 @@
1
1
  import { mergeDeepRight } from './mergeDeepRight.js'
2
- import { type } from './type.js'
3
2
 
4
3
  export function partialObject(fn, input){
5
- return rest => {
6
- if (type(fn) === 'Async'){
7
- return new Promise((resolve, reject) => {
8
- fn(mergeDeepRight(rest, input)).then(resolve)
9
- .catch(reject)
10
- })
11
- }
12
-
13
- return fn(mergeDeepRight(rest, input))
14
- }
4
+ return nextInput => fn(mergeDeepRight(nextInput, input))
15
5
  }
package/src/partition.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _isArray } from './_internals/_isArray.js'
1
+ import { isArray } from './_internals/isArray.js'
2
2
 
3
3
  export function partitionObject(predicate, iterable){
4
4
  const yes = {}
@@ -38,7 +38,7 @@ export function partition(predicate, iterable){
38
38
  if (arguments.length === 1){
39
39
  return listHolder => partition(predicate, listHolder)
40
40
  }
41
- if (!_isArray(iterable)) return partitionObject(predicate, iterable)
41
+ if (!isArray(iterable)) return partitionObject(predicate, iterable)
42
42
 
43
43
  return partitionArray(predicate, iterable)
44
44
  }
package/src/props.js CHANGED
@@ -1,11 +1,11 @@
1
- import { _isArray } from './_internals/_isArray.js'
1
+ import { isArray } from './_internals/isArray.js'
2
2
  import { mapArray } from './map.js'
3
3
 
4
4
  export function props(propsToPick, obj){
5
5
  if (arguments.length === 1){
6
6
  return _obj => props(propsToPick, _obj)
7
7
  }
8
- if (!_isArray(propsToPick)){
8
+ if (!isArray(propsToPick)){
9
9
  throw new Error('propsToPick is not a list')
10
10
  }
11
11
 
package/src/reduce.js CHANGED
@@ -1,5 +1,4 @@
1
- import { _isArray } from './_internals/_isArray.js'
2
- import { _keys } from './_internals/_keys.js'
1
+ import { isArray } from './_internals/isArray.js'
3
2
  import { curry } from './curry.js'
4
3
 
5
4
  class ReduceStopper{
@@ -11,7 +10,7 @@ class ReduceStopper{
11
10
  export function reduceFn(
12
11
  reducer, acc, list
13
12
  ){
14
- if (!_isArray(list)){
13
+ if (!isArray(list)){
15
14
  throw new TypeError('reduce: list must be array or iterable')
16
15
  }
17
16
  let index = 0
package/src/splitAt.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _isArray } from './_internals/_isArray.js'
1
+ import { isArray } from './_internals/isArray.js'
2
2
  import { drop } from './drop.js'
3
3
  import { maybe } from './maybe.js'
4
4
  import { take } from './take.js'
@@ -9,7 +9,7 @@ export function splitAt(index, input){
9
9
  }
10
10
  if (!input) throw new TypeError(`Cannot read property 'slice' of ${ input }`)
11
11
 
12
- if (!_isArray(input) && typeof input !== 'string') return [ [], [] ]
12
+ if (!isArray(input) && typeof input !== 'string') return [ [], [] ]
13
13
 
14
14
  const correctIndex = maybe(
15
15
  index < 0,
package/src/startsWith.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _isArray } from './_internals/_isArray.js'
1
+ import { isArray } from './_internals/isArray.js'
2
2
  import { equals } from './equals.js'
3
3
 
4
4
  export function startsWith(target, iterable){
@@ -8,7 +8,7 @@ export function startsWith(target, iterable){
8
8
  if (typeof iterable === 'string'){
9
9
  return iterable.startsWith(target)
10
10
  }
11
- if (!_isArray(target)) return false
11
+ if (!isArray(target)) return false
12
12
 
13
13
  let correct = true
14
14
  const filtered = target.filter((x, index) => {
@@ -1,4 +1,4 @@
1
- import { _isArray } from './_internals/_isArray.js'
1
+ import { isArray } from './_internals/isArray.js'
2
2
 
3
3
  export function takeLastWhile(predicate, input){
4
4
  if (arguments.length === 1){
@@ -18,5 +18,5 @@ export function takeLastWhile(predicate, input){
18
18
  }
19
19
  }
20
20
 
21
- return _isArray(input) ? toReturn.reverse() : toReturn.reverse().join('')
21
+ return isArray(input) ? toReturn.reverse() : toReturn.reverse().join('')
22
22
  }
package/src/takeWhile.js CHANGED
@@ -1,10 +1,10 @@
1
- import { _isArray } from '../src/_internals/_isArray.js'
1
+ import { isArray as isArrayModule } from './_internals/isArray.js'
2
2
 
3
3
  export function takeWhile(predicate, iterable){
4
4
  if (arguments.length === 1){
5
5
  return _iterable => takeWhile(predicate, _iterable)
6
6
  }
7
- const isArray = _isArray(iterable)
7
+ const isArray = isArrayModule(iterable)
8
8
  if (!isArray && typeof iterable !== 'string'){
9
9
  throw new Error('`iterable` is neither list nor a string')
10
10
  }
package/src/test.js CHANGED
@@ -2,7 +2,7 @@ export function test(pattern, str){
2
2
  if (arguments.length === 1) return _str => test(pattern, _str)
3
3
 
4
4
  if (typeof pattern === 'string'){
5
- throw new TypeError(`‘test requires a value of type RegExp as its first argument; received "${ pattern }"`)
5
+ throw new TypeError(`R.test requires a value of type RegExp as its first argument; received "${ pattern }"`)
6
6
  }
7
7
 
8
8
  return str.search(pattern) !== -1
package/src/times.js CHANGED
@@ -1,9 +1,10 @@
1
+ import { isInteger } from './_internals/isInteger.js'
1
2
  import { map } from './map.js'
2
3
  import { range } from './range.js'
3
4
 
4
5
  export function times(fn, howMany){
5
6
  if (arguments.length === 1) return _howMany => times(fn, _howMany)
6
- if (!Number.isInteger(howMany) || howMany < 0){
7
+ if (!isInteger(howMany) || howMany < 0){
7
8
  throw new RangeError('n must be an integer')
8
9
  }
9
10
 
package/src/transpose.js CHANGED
@@ -1,9 +1,9 @@
1
- import { _isArray } from './_internals/_isArray.js'
1
+ import { isArray } from './_internals/isArray.js'
2
2
 
3
3
  export function transpose(array){
4
4
  return array.reduce((acc, el) => {
5
5
  el.forEach((nestedEl, i) =>
6
- _isArray(acc[ i ]) ? acc[ i ].push(nestedEl) : acc.push([ nestedEl ]))
6
+ isArray(acc[ i ]) ? acc[ i ].push(nestedEl) : acc.push([ nestedEl ]))
7
7
 
8
8
  return acc
9
9
  }, [])
package/src/unwind.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _isArray } from './_internals/_isArray.js'
1
+ import { isArray } from './_internals/isArray.js'
2
2
  import { mapArray } from './map.js'
3
3
 
4
4
  export function unwind(property, obj){
@@ -6,10 +6,11 @@ export function unwind(property, obj){
6
6
  return _obj => unwind(property, _obj)
7
7
  }
8
8
 
9
- if (!_isArray(obj[ property ])) return [ obj ]
9
+ if (!isArray(obj[ property ])) return [ obj ]
10
10
 
11
11
  return mapArray(x => ({
12
12
  ...obj,
13
13
  [ property ] : x,
14
- }), obj[ property ])
14
+ }),
15
+ obj[ property ])
15
16
  }
package/src/update.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { cloneList } from './_internals/cloneList.js'
2
2
  import { curry } from './curry.js'
3
3
 
4
- function updateFn(
4
+ export function updateFn(
5
5
  index, newValue, list
6
6
  ){
7
7
  const clone = cloneList(list)
package/src/where.js CHANGED
@@ -4,6 +4,7 @@ export function where(conditions, input){
4
4
  }
5
5
  let flag = true
6
6
  for (const prop in conditions){
7
+ if (!flag) continue
7
8
  const result = conditions[ prop ](input[ prop ])
8
9
  if (flag && result === false){
9
10
  flag = false
@@ -1 +0,0 @@
1
- export const _isArray = Array.isArray
@@ -1,5 +0,0 @@
1
- export function _isInteger(n){
2
- return n << 0 === n
3
- }
4
-
5
- export default Number.isInteger || _isInteger
@@ -1 +0,0 @@
1
- export const _keys = Object.keys