rambda 7.0.3 → 7.1.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/CHANGELOG.md +18 -2
- package/README.md +3541 -2696
- package/dist/rambda.js +282 -76
- package/dist/rambda.mjs +268 -76
- package/dist/rambda.umd.js +1 -1
- package/immutable.d.ts +91 -10
- package/index.d.ts +91 -10
- package/package.json +119 -119
- package/src/F.js +1 -1
- package/src/T.js +1 -1
- package/src/_internals/_isInteger.js +1 -1
- package/src/_internals/_keys.js +0 -1
- package/src/_internals/_objectIs.js +2 -7
- package/src/_internals/baseSlice.js +8 -6
- package/src/_internals/cloneList.js +1 -3
- package/src/_internals/createPath.js +3 -0
- package/src/_internals/isFalsy.js +5 -5
- package/src/_internals/isObject.js +2 -2
- package/src/_internals/isTruthy.js +5 -5
- package/src/_internals/set.js +19 -13
- package/src/add.js +1 -1
- package/src/adjust.js +6 -4
- package/src/all.js +3 -3
- package/src/allPass.js +3 -3
- package/src/always.js +2 -2
- package/src/and.js +1 -1
- package/src/any.js +3 -3
- package/src/anyPass.js +3 -3
- package/src/append.js +2 -2
- package/src/apply.js +2 -2
- package/src/applySpec.js +59 -33
- package/src/assoc.js +7 -3
- package/src/assocPath.js +25 -21
- package/src/bind.js +3 -3
- package/src/both.js +1 -1
- package/src/chain.js +2 -2
- package/src/clamp.js +6 -6
- package/src/clone.js +10 -10
- package/src/complement.js +1 -1
- package/src/compose.js +5 -14
- package/src/concat.js +2 -2
- package/src/cond.js +3 -3
- package/src/converge.js +11 -11
- package/src/count.js +10 -0
- package/src/countBy.js +17 -0
- package/src/curry.js +2 -2
- package/src/curryN.js +81 -61
- package/src/defaultTo.js +3 -3
- package/src/difference.js +3 -3
- package/src/dissoc.js +4 -4
- package/src/divide.js +1 -1
- package/src/drop.js +1 -1
- package/src/dropLast.js +5 -5
- package/src/dropLastWhile.js +12 -12
- package/src/dropRepeats.js +6 -6
- package/src/dropRepeatsWith.js +7 -7
- package/src/dropWhile.js +9 -9
- package/src/either.js +2 -2
- package/src/endsWith.js +6 -5
- package/src/eqProps.js +6 -4
- package/src/equals.js +64 -65
- package/src/evolve.js +21 -23
- package/src/filter.js +21 -15
- package/src/find.js +4 -4
- package/src/findIndex.js +3 -3
- package/src/findLast.js +4 -4
- package/src/findLastIndex.js +3 -3
- package/src/flatten.js +6 -6
- package/src/flip.js +15 -11
- package/src/forEach.js +12 -10
- package/src/fromPairs.js +2 -2
- package/src/groupBy.js +6 -6
- package/src/groupWith.js +12 -10
- package/src/has.js +1 -1
- package/src/hasPath.js +3 -3
- package/src/head.js +3 -3
- package/src/identical.js +2 -2
- package/src/identity.js +1 -1
- package/src/ifElse.js +5 -3
- package/src/includes.js +6 -6
- package/src/indexBy.js +11 -11
- package/src/indexOf.js +3 -3
- package/src/init.js +7 -3
- package/src/intersection.js +3 -3
- package/src/intersperse.js +5 -5
- package/src/is.js +2 -2
- package/src/isEmpty.js +5 -5
- package/src/isNil.js +1 -1
- package/src/isPromise.js +3 -3
- package/src/join.js +1 -1
- package/src/juxt.js +3 -0
- package/src/keys.js +1 -1
- package/src/last.js +4 -4
- package/src/lastIndexOf.js +3 -3
- package/src/length.js +2 -2
- package/src/lens.js +3 -3
- package/src/lensIndex.js +4 -4
- package/src/lensPath.js +4 -4
- package/src/lensProp.js +4 -4
- package/src/map.js +15 -11
- package/src/match.js +1 -1
- package/src/mathMod.js +3 -3
- package/src/max.js +1 -1
- package/src/maxBy.js +4 -2
- package/src/maybe.js +4 -2
- package/src/mean.js +2 -2
- package/src/median.js +10 -12
- package/src/merge.js +1 -5
- package/src/mergeAll.js +4 -4
- package/src/mergeDeepRight.js +8 -8
- package/src/mergeLeft.js +3 -3
- package/src/mergeRight.js +7 -0
- package/src/mergeWith.js +29 -0
- package/src/min.js +1 -1
- package/src/minBy.js +4 -2
- package/src/modulo.js +1 -1
- package/src/move.js +8 -6
- package/src/multiply.js +1 -1
- package/src/negate.js +1 -1
- package/src/none.js +3 -3
- package/src/not.js +1 -1
- package/src/nth.js +6 -6
- package/src/objOf.js +3 -5
- package/src/of.js +2 -2
- package/src/omit.js +8 -8
- package/src/on.js +16 -0
- package/src/once.js +6 -6
- package/src/or.js +1 -1
- package/src/over.js +5 -3
- package/src/partial.js +3 -3
- package/src/partialObject.js +15 -0
- package/src/partition.js +18 -16
- package/src/path.js +9 -8
- package/src/pathEq.js +6 -4
- package/src/pathOr.js +6 -4
- package/src/paths.js +3 -3
- package/src/pick.js +8 -8
- package/src/pickAll.js +9 -9
- package/src/pipe.js +85 -13
- package/src/pluck.js +4 -4
- package/src/prepend.js +3 -3
- package/src/product.js +2 -2
- package/src/prop.js +2 -2
- package/src/propEq.js +5 -3
- package/src/propIs.js +6 -4
- package/src/propOr.js +6 -4
- package/src/propSatisfies.js +10 -0
- package/src/props.js +6 -6
- package/src/range.js +4 -4
- package/src/reduce.js +11 -7
- package/src/reject.js +2 -2
- package/src/repeat.js +2 -2
- package/src/replace.js +4 -2
- package/src/reverse.js +4 -3
- package/src/set.js +9 -5
- package/src/slice.js +4 -2
- package/src/sort.js +2 -2
- package/src/sortBy.js +2 -2
- package/src/split.js +1 -1
- package/src/splitAt.js +9 -9
- package/src/splitEvery.js +6 -8
- package/src/splitWhen.js +10 -10
- package/src/startsWith.js +6 -5
- package/src/subtract.js +1 -1
- package/src/sum.js +1 -1
- package/src/symmetricDifference.js +7 -9
- package/src/tail.js +2 -2
- package/src/take.js +5 -3
- package/src/takeLast.js +5 -3
- package/src/takeLastWhile.js +7 -7
- package/src/takeWhile.js +8 -8
- package/src/tap.js +1 -1
- package/src/test.js +3 -5
- package/src/times.js +4 -4
- package/src/toLower.js +1 -1
- package/src/toPairs.js +1 -1
- package/src/toString.js +1 -1
- package/src/toUpper.js +1 -1
- package/src/transpose.js +3 -4
- package/src/trim.js +1 -1
- package/src/tryCatch.js +7 -5
- package/src/type.js +5 -5
- package/src/unapply.js +2 -2
- package/src/union.js +3 -3
- package/src/uniq.js +3 -3
- package/src/uniqWith.js +12 -8
- package/src/unless.js +3 -3
- package/src/unwind.js +15 -0
- package/src/update.js +8 -4
- package/src/values.js +2 -2
- package/src/view.js +2 -2
- package/src/when.js +4 -2
- package/src/where.js +5 -5
- package/src/whereAny.js +12 -0
- package/src/whereEq.js +7 -9
- package/src/without.js +4 -4
- package/src/xor.js +2 -2
- package/src/zip.js +3 -3
- package/src/zipObj.js +6 -4
- package/src/zipWith.js +6 -6
- package/src/isFunction.js +0 -5
package/src/drop.js
CHANGED
package/src/dropLast.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export function dropLast(howManyToDrop, listOrString)
|
|
2
|
-
if (arguments.length === 1)
|
|
1
|
+
export function dropLast(howManyToDrop, listOrString){
|
|
2
|
+
if (arguments.length === 1){
|
|
3
3
|
return _listOrString => dropLast(howManyToDrop, _listOrString)
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
return howManyToDrop > 0
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
return howManyToDrop > 0 ?
|
|
7
|
+
listOrString.slice(0, -howManyToDrop) :
|
|
8
|
+
listOrString.slice()
|
|
9
9
|
}
|
package/src/dropLastWhile.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import {_isArray} from './_internals/_isArray'
|
|
1
|
+
import { _isArray } from './_internals/_isArray.js'
|
|
2
2
|
|
|
3
|
-
export function dropLastWhile(predicate, iterable)
|
|
4
|
-
if (arguments.length === 1)
|
|
3
|
+
export function dropLastWhile(predicate, iterable){
|
|
4
|
+
if (arguments.length === 1){
|
|
5
5
|
return _iterable => dropLastWhile(predicate, _iterable)
|
|
6
6
|
}
|
|
7
7
|
if (iterable.length === 0) return iterable
|
|
8
8
|
const isArray = _isArray(iterable)
|
|
9
9
|
|
|
10
|
-
if (typeof predicate !== 'function')
|
|
11
|
-
throw new Error(`'predicate' is from wrong type ${typeof predicate}`)
|
|
10
|
+
if (typeof predicate !== 'function'){
|
|
11
|
+
throw new Error(`'predicate' is from wrong type ${ typeof predicate }`)
|
|
12
12
|
}
|
|
13
|
-
if (!isArray && typeof iterable !== 'string')
|
|
14
|
-
throw new Error(`'iterable' is from wrong type ${typeof iterable}`)
|
|
13
|
+
if (!isArray && typeof iterable !== 'string'){
|
|
14
|
+
throw new Error(`'iterable' is from wrong type ${ typeof iterable }`)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
let found = false
|
|
18
18
|
const toReturn = []
|
|
19
19
|
let counter = iterable.length
|
|
20
20
|
|
|
21
|
-
while (counter > 0)
|
|
21
|
+
while (counter > 0){
|
|
22
22
|
counter--
|
|
23
|
-
if (!found && predicate(iterable[counter]) === false)
|
|
23
|
+
if (!found && predicate(iterable[ counter ]) === false){
|
|
24
24
|
found = true
|
|
25
|
-
toReturn.push(iterable[counter])
|
|
26
|
-
} else if (found)
|
|
27
|
-
toReturn.push(iterable[counter])
|
|
25
|
+
toReturn.push(iterable[ counter ])
|
|
26
|
+
} else if (found){
|
|
27
|
+
toReturn.push(iterable[ counter ])
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
package/src/dropRepeats.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {_isArray} from './_internals/_isArray'
|
|
2
|
-
import {equals} from './equals'
|
|
1
|
+
import { _isArray } from './_internals/_isArray.js'
|
|
2
|
+
import { equals } from './equals.js'
|
|
3
3
|
|
|
4
|
-
export function dropRepeats(list)
|
|
5
|
-
if (!_isArray(list))
|
|
6
|
-
throw new Error(`${list} is not a list`)
|
|
4
|
+
export function dropRepeats(list){
|
|
5
|
+
if (!_isArray(list)){
|
|
6
|
+
throw new Error(`${ list } is not a list`)
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
const toReturn = []
|
|
10
10
|
|
|
11
11
|
list.reduce((prev, current) => {
|
|
12
|
-
if (!equals(prev, current))
|
|
12
|
+
if (!equals(prev, current)){
|
|
13
13
|
toReturn.push(current)
|
|
14
14
|
}
|
|
15
15
|
|
package/src/dropRepeatsWith.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import {_isArray} from './_internals/_isArray'
|
|
1
|
+
import { _isArray } from './_internals/_isArray.js'
|
|
2
2
|
|
|
3
|
-
export function dropRepeatsWith(predicate, list)
|
|
4
|
-
if (arguments.length === 1)
|
|
3
|
+
export function dropRepeatsWith(predicate, list){
|
|
4
|
+
if (arguments.length === 1){
|
|
5
5
|
return _iterable => dropRepeatsWith(predicate, _iterable)
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
if (!_isArray(list))
|
|
9
|
-
throw new Error(`${list} is not a list`)
|
|
8
|
+
if (!_isArray(list)){
|
|
9
|
+
throw new Error(`${ list } is not a list`)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const toReturn = []
|
|
13
13
|
|
|
14
14
|
list.reduce((prev, current) => {
|
|
15
|
-
if (prev === undefined)
|
|
15
|
+
if (prev === undefined){
|
|
16
16
|
toReturn.push(current)
|
|
17
17
|
|
|
18
18
|
return current
|
|
19
19
|
}
|
|
20
|
-
if (!predicate(prev, current))
|
|
20
|
+
if (!predicate(prev, current)){
|
|
21
21
|
toReturn.push(current)
|
|
22
22
|
}
|
|
23
23
|
|
package/src/dropWhile.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {_isArray} from '../src/_internals/_isArray'
|
|
1
|
+
import { _isArray } from '../src/_internals/_isArray.js'
|
|
2
2
|
|
|
3
|
-
export function dropWhile(predicate, iterable)
|
|
4
|
-
if (arguments.length === 1)
|
|
3
|
+
export function dropWhile(predicate, iterable){
|
|
4
|
+
if (arguments.length === 1){
|
|
5
5
|
return _iterable => dropWhile(predicate, _iterable)
|
|
6
6
|
}
|
|
7
7
|
const isArray = _isArray(iterable)
|
|
8
|
-
if (!isArray && typeof iterable !== 'string')
|
|
8
|
+
if (!isArray && typeof iterable !== 'string'){
|
|
9
9
|
throw new Error('`iterable` is neither list nor a string')
|
|
10
10
|
}
|
|
11
11
|
let flag = false
|
|
12
12
|
const holder = []
|
|
13
13
|
let counter = -1
|
|
14
14
|
|
|
15
|
-
while (counter++ < iterable.length - 1)
|
|
16
|
-
if (flag)
|
|
17
|
-
holder.push(iterable[counter])
|
|
18
|
-
} else if (!predicate(iterable[counter]))
|
|
15
|
+
while (counter++ < iterable.length - 1){
|
|
16
|
+
if (flag){
|
|
17
|
+
holder.push(iterable[ counter ])
|
|
18
|
+
} else if (!predicate(iterable[ counter ])){
|
|
19
19
|
if (!flag) flag = true
|
|
20
20
|
|
|
21
|
-
holder.push(iterable[counter])
|
|
21
|
+
holder.push(iterable[ counter ])
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
package/src/either.js
CHANGED
package/src/endsWith.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { _isArray } from './_internals/_isArray.js'
|
|
2
|
+
import { equals } from './equals.js'
|
|
3
3
|
|
|
4
|
-
export function endsWith(target, iterable)
|
|
4
|
+
export function endsWith(target, iterable){
|
|
5
5
|
if (arguments.length === 1) return _iterable => endsWith(target, _iterable)
|
|
6
6
|
|
|
7
|
-
if (typeof iterable === 'string')
|
|
7
|
+
if (typeof iterable === 'string'){
|
|
8
8
|
return iterable.endsWith(target)
|
|
9
9
|
}
|
|
10
10
|
if (!_isArray(target)) return false
|
|
@@ -13,8 +13,9 @@ export function endsWith(target, iterable) {
|
|
|
13
13
|
let correct = true
|
|
14
14
|
const filtered = target.filter((x, index) => {
|
|
15
15
|
if (!correct) return false
|
|
16
|
-
const result = equals(x, iterable[index + diff])
|
|
16
|
+
const result = equals(x, iterable[ index + diff ])
|
|
17
17
|
if (!result) correct = false
|
|
18
|
+
|
|
18
19
|
return result
|
|
19
20
|
})
|
|
20
21
|
|
package/src/eqProps.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {curry} from './curry'
|
|
2
|
-
import {equals} from './equals'
|
|
3
|
-
import {prop} from './prop'
|
|
1
|
+
import { curry } from './curry.js'
|
|
2
|
+
import { equals } from './equals.js'
|
|
3
|
+
import { prop } from './prop.js'
|
|
4
4
|
|
|
5
|
-
function eqPropsFn(
|
|
5
|
+
function eqPropsFn(
|
|
6
|
+
property, objA, objB
|
|
7
|
+
){
|
|
6
8
|
return equals(prop(property, objA), prop(property, objB))
|
|
7
9
|
}
|
|
8
10
|
|
package/src/equals.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { _isArray } from './_internals/_isArray.js'
|
|
2
|
+
import { type } from './type.js'
|
|
3
3
|
|
|
4
|
-
export function _lastIndexOf(valueToFind, list)
|
|
5
|
-
if (!_isArray(list))
|
|
6
|
-
throw new Error(`Cannot read property 'indexOf' of ${list}`)
|
|
4
|
+
export function _lastIndexOf(valueToFind, list){
|
|
5
|
+
if (!_isArray(list)){
|
|
6
|
+
throw new Error(`Cannot read property 'indexOf' of ${ list }`)
|
|
7
7
|
}
|
|
8
8
|
const typeOfValue = type(valueToFind)
|
|
9
|
-
if (!['Object', 'Array', 'NaN', 'RegExp'].includes(typeOfValue))
|
|
9
|
+
if (![ 'Object', 'Array', 'NaN', 'RegExp' ].includes(typeOfValue))
|
|
10
10
|
return list.lastIndexOf(valueToFind)
|
|
11
11
|
|
|
12
|
-
const {length} = list
|
|
12
|
+
const { length } = list
|
|
13
13
|
let index = length
|
|
14
14
|
let foundIndex = -1
|
|
15
15
|
|
|
16
|
-
while (--index > -1 && foundIndex === -1)
|
|
17
|
-
if (equals(list[index], valueToFind))
|
|
16
|
+
while (--index > -1 && foundIndex === -1){
|
|
17
|
+
if (equals(list[ index ], valueToFind)){
|
|
18
18
|
foundIndex = index
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -22,20 +22,20 @@ export function _lastIndexOf(valueToFind, list) {
|
|
|
22
22
|
return foundIndex
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export function _indexOf(valueToFind, list)
|
|
26
|
-
if (!_isArray(list))
|
|
27
|
-
throw new Error(`Cannot read property 'indexOf' of ${list}`)
|
|
25
|
+
export function _indexOf(valueToFind, list){
|
|
26
|
+
if (!_isArray(list)){
|
|
27
|
+
throw new Error(`Cannot read property 'indexOf' of ${ list }`)
|
|
28
28
|
}
|
|
29
29
|
const typeOfValue = type(valueToFind)
|
|
30
|
-
if (!['Object', 'Array', 'NaN', 'RegExp'].includes(typeOfValue))
|
|
30
|
+
if (![ 'Object', 'Array', 'NaN', 'RegExp' ].includes(typeOfValue))
|
|
31
31
|
return list.indexOf(valueToFind)
|
|
32
32
|
|
|
33
33
|
let index = -1
|
|
34
34
|
let foundIndex = -1
|
|
35
|
-
const {length} = list
|
|
35
|
+
const { length } = list
|
|
36
36
|
|
|
37
|
-
while (++index < length && foundIndex === -1)
|
|
38
|
-
if (equals(list[index], valueToFind))
|
|
37
|
+
while (++index < length && foundIndex === -1){
|
|
38
|
+
if (equals(list[ index ], valueToFind)){
|
|
39
39
|
foundIndex = index
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -43,97 +43,96 @@ export function _indexOf(valueToFind, list) {
|
|
|
43
43
|
return foundIndex
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
function _arrayFromIterator(iter)
|
|
46
|
+
function _arrayFromIterator(iter){
|
|
47
47
|
const list = []
|
|
48
48
|
let next
|
|
49
|
-
while (!(next = iter.next()).done)
|
|
49
|
+
while (!(next = iter.next()).done){
|
|
50
50
|
list.push(next.value)
|
|
51
51
|
}
|
|
52
|
+
|
|
52
53
|
return list
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
function _equalsSets(a, b)
|
|
56
|
-
if (a.size !== b.size)
|
|
56
|
+
function _equalsSets(a, b){
|
|
57
|
+
if (a.size !== b.size){
|
|
57
58
|
return false
|
|
58
59
|
}
|
|
59
60
|
const aList = _arrayFromIterator(a.values())
|
|
60
61
|
const bList = _arrayFromIterator(b.values())
|
|
61
62
|
|
|
62
|
-
const filtered = aList.filter(
|
|
63
|
-
|
|
64
|
-
)
|
|
63
|
+
const filtered = aList.filter(aInstance => _indexOf(aInstance, bList) === -1)
|
|
64
|
+
|
|
65
65
|
return filtered.length === 0
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
function parseError(maybeError)
|
|
68
|
+
function parseError(maybeError){
|
|
69
69
|
const typeofError = maybeError.__proto__.toString()
|
|
70
|
-
if (!['Error', 'TypeError'].includes(typeofError)) return []
|
|
70
|
+
if (![ 'Error', 'TypeError' ].includes(typeofError)) return []
|
|
71
71
|
|
|
72
|
-
return [typeofError, maybeError.message]
|
|
72
|
+
return [ typeofError, maybeError.message ]
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
function parseDate(maybeDate)
|
|
76
|
-
if (!maybeDate.toDateString) return [false]
|
|
75
|
+
function parseDate(maybeDate){
|
|
76
|
+
if (!maybeDate.toDateString) return [ false ]
|
|
77
77
|
|
|
78
|
-
return [true, maybeDate.getTime()]
|
|
78
|
+
return [ true, maybeDate.getTime() ]
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
function parseRegex(maybeRegex)
|
|
82
|
-
if (maybeRegex.constructor !== RegExp) return [false]
|
|
81
|
+
function parseRegex(maybeRegex){
|
|
82
|
+
if (maybeRegex.constructor !== RegExp) return [ false ]
|
|
83
83
|
|
|
84
|
-
return [true, maybeRegex.toString()]
|
|
84
|
+
return [ true, maybeRegex.toString() ]
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
function equalsSets(a, b)
|
|
88
|
-
if (a.size !== b.size)
|
|
87
|
+
function equalsSets(a, b){
|
|
88
|
+
if (a.size !== b.size){
|
|
89
89
|
return false
|
|
90
90
|
}
|
|
91
91
|
const aList = _arrayFromIterator(a.values())
|
|
92
92
|
const bList = _arrayFromIterator(b.values())
|
|
93
93
|
|
|
94
|
-
const filtered = aList.filter(
|
|
95
|
-
|
|
96
|
-
)
|
|
94
|
+
const filtered = aList.filter(aInstance => _indexOf(aInstance, bList) === -1)
|
|
95
|
+
|
|
97
96
|
return filtered.length === 0
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
export function equals(a, b)
|
|
99
|
+
export function equals(a, b){
|
|
101
100
|
if (arguments.length === 1) return _b => equals(a, _b)
|
|
102
101
|
|
|
103
102
|
const aType = type(a)
|
|
104
103
|
|
|
105
104
|
if (aType !== type(b)) return false
|
|
106
|
-
if (aType === 'Function')
|
|
105
|
+
if (aType === 'Function'){
|
|
107
106
|
return a.name === undefined ? false : a.name === b.name
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
if (['NaN', 'Undefined', 'Null'].includes(aType)) return true
|
|
109
|
+
if ([ 'NaN', 'Undefined', 'Null' ].includes(aType)) return true
|
|
111
110
|
|
|
112
|
-
if (aType === 'Number')
|
|
111
|
+
if (aType === 'Number'){
|
|
113
112
|
if (Object.is(-0, a) !== Object.is(-0, b)) return false
|
|
114
113
|
|
|
115
114
|
return a.toString() === b.toString()
|
|
116
115
|
}
|
|
117
116
|
|
|
118
|
-
if (['String', 'Boolean'].includes(aType))
|
|
117
|
+
if ([ 'String', 'Boolean' ].includes(aType)){
|
|
119
118
|
return a.toString() === b.toString()
|
|
120
119
|
}
|
|
121
120
|
|
|
122
|
-
if (aType === 'Array')
|
|
121
|
+
if (aType === 'Array'){
|
|
123
122
|
const aClone = Array.from(a)
|
|
124
123
|
const bClone = Array.from(b)
|
|
125
124
|
|
|
126
|
-
if (aClone.toString() !== bClone.toString())
|
|
125
|
+
if (aClone.toString() !== bClone.toString()){
|
|
127
126
|
return false
|
|
128
127
|
}
|
|
129
128
|
|
|
130
129
|
let loopArrayFlag = true
|
|
131
130
|
aClone.forEach((aCloneInstance, aCloneIndex) => {
|
|
132
|
-
if (loopArrayFlag)
|
|
131
|
+
if (loopArrayFlag){
|
|
133
132
|
if (
|
|
134
|
-
aCloneInstance !== bClone[aCloneIndex] &&
|
|
135
|
-
!equals(aCloneInstance, bClone[aCloneIndex])
|
|
136
|
-
)
|
|
133
|
+
aCloneInstance !== bClone[ aCloneIndex ] &&
|
|
134
|
+
!equals(aCloneInstance, bClone[ aCloneIndex ])
|
|
135
|
+
){
|
|
137
136
|
loopArrayFlag = false
|
|
138
137
|
}
|
|
139
138
|
}
|
|
@@ -145,42 +144,42 @@ export function equals(a, b) {
|
|
|
145
144
|
const aRegex = parseRegex(a)
|
|
146
145
|
const bRegex = parseRegex(b)
|
|
147
146
|
|
|
148
|
-
if (aRegex[0])
|
|
149
|
-
return bRegex[0] ? aRegex[1] === bRegex[1] : false
|
|
150
|
-
} else if (bRegex[0]) return false
|
|
147
|
+
if (aRegex[ 0 ]){
|
|
148
|
+
return bRegex[ 0 ] ? aRegex[ 1 ] === bRegex[ 1 ] : false
|
|
149
|
+
} else if (bRegex[ 0 ]) return false
|
|
151
150
|
|
|
152
151
|
const aDate = parseDate(a)
|
|
153
152
|
const bDate = parseDate(b)
|
|
154
153
|
|
|
155
|
-
if (aDate[0])
|
|
156
|
-
return bDate[0] ? aDate[1] === bDate[1] : false
|
|
157
|
-
} else if (bDate[0]) return false
|
|
154
|
+
if (aDate[ 0 ]){
|
|
155
|
+
return bDate[ 0 ] ? aDate[ 1 ] === bDate[ 1 ] : false
|
|
156
|
+
} else if (bDate[ 0 ]) return false
|
|
158
157
|
|
|
159
158
|
const aError = parseError(a)
|
|
160
159
|
const bError = parseError(b)
|
|
161
160
|
|
|
162
|
-
if (aError[0])
|
|
163
|
-
return bError[0]
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
if (aError[ 0 ]){
|
|
162
|
+
return bError[ 0 ] ?
|
|
163
|
+
aError[ 0 ] === bError[ 0 ] && aError[ 1 ] === bError[ 1 ] :
|
|
164
|
+
false
|
|
166
165
|
}
|
|
167
|
-
if (aType === 'Set')
|
|
166
|
+
if (aType === 'Set'){
|
|
168
167
|
return _equalsSets(a, b)
|
|
169
168
|
}
|
|
170
|
-
if (aType === 'Object')
|
|
169
|
+
if (aType === 'Object'){
|
|
171
170
|
const aKeys = Object.keys(a)
|
|
172
171
|
|
|
173
|
-
if (aKeys.length !== Object.keys(b).length)
|
|
172
|
+
if (aKeys.length !== Object.keys(b).length){
|
|
174
173
|
return false
|
|
175
174
|
}
|
|
176
175
|
|
|
177
176
|
let loopObjectFlag = true
|
|
178
177
|
aKeys.forEach(aKeyInstance => {
|
|
179
|
-
if (loopObjectFlag)
|
|
180
|
-
const aValue = a[aKeyInstance]
|
|
181
|
-
const bValue = b[aKeyInstance]
|
|
178
|
+
if (loopObjectFlag){
|
|
179
|
+
const aValue = a[ aKeyInstance ]
|
|
180
|
+
const bValue = b[ aKeyInstance ]
|
|
182
181
|
|
|
183
|
-
if (aValue !== bValue && !equals(aValue, bValue))
|
|
182
|
+
if (aValue !== bValue && !equals(aValue, bValue)){
|
|
184
183
|
loopObjectFlag = false
|
|
185
184
|
}
|
|
186
185
|
}
|
package/src/evolve.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {_isArray} from './_internals/_isArray'
|
|
2
|
-
import {mapArray, mapObject} from './map'
|
|
3
|
-
import {type} from './type'
|
|
1
|
+
import { _isArray } from './_internals/_isArray.js'
|
|
2
|
+
import { mapArray, mapObject } from './map.js'
|
|
3
|
+
import { type } from './type.js'
|
|
4
4
|
|
|
5
|
-
export function evolveArray(rules, list)
|
|
5
|
+
export function evolveArray(rules, list){
|
|
6
6
|
return mapArray(
|
|
7
7
|
(x, i) => {
|
|
8
|
-
if (type(rules[i]) === 'Function')
|
|
9
|
-
return rules[i](x)
|
|
8
|
+
if (type(rules[ i ]) === 'Function'){
|
|
9
|
+
return rules[ i ](x)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
return x
|
|
@@ -16,45 +16,43 @@ export function evolveArray(rules, list) {
|
|
|
16
16
|
)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export function evolveObject(rules, iterable)
|
|
19
|
+
export function evolveObject(rules, iterable){
|
|
20
20
|
return mapObject((x, prop) => {
|
|
21
|
-
if (type(x) === 'Object')
|
|
22
|
-
const typeRule = type(rules[prop])
|
|
23
|
-
if (typeRule === 'Function')
|
|
24
|
-
return rules[prop](x)
|
|
21
|
+
if (type(x) === 'Object'){
|
|
22
|
+
const typeRule = type(rules[ prop ])
|
|
23
|
+
if (typeRule === 'Function'){
|
|
24
|
+
return rules[ prop ](x)
|
|
25
25
|
}
|
|
26
|
-
if (typeRule === 'Object')
|
|
27
|
-
return evolve(rules[prop], x)
|
|
26
|
+
if (typeRule === 'Object'){
|
|
27
|
+
return evolve(rules[ prop ], x)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
return x
|
|
31
31
|
}
|
|
32
|
-
if (type(rules[prop]) === 'Function')
|
|
33
|
-
return rules[prop](x)
|
|
32
|
+
if (type(rules[ prop ]) === 'Function'){
|
|
33
|
+
return rules[ prop ](x)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
return x
|
|
37
37
|
}, iterable)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export function evolve(rules, iterable)
|
|
41
|
-
if (arguments.length === 1)
|
|
40
|
+
export function evolve(rules, iterable){
|
|
41
|
+
if (arguments.length === 1){
|
|
42
42
|
return _iterable => evolve(rules, _iterable)
|
|
43
43
|
}
|
|
44
44
|
const rulesType = type(rules)
|
|
45
45
|
const iterableType = type(iterable)
|
|
46
46
|
|
|
47
|
-
if (iterableType !== rulesType)
|
|
47
|
+
if (iterableType !== rulesType){
|
|
48
48
|
throw new Error('iterableType !== rulesType')
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
if (!['Object', 'Array'].includes(rulesType))
|
|
52
|
-
throw new Error(
|
|
53
|
-
`'iterable' and 'rules' are from wrong type ${rulesType}`
|
|
54
|
-
)
|
|
51
|
+
if (![ 'Object', 'Array' ].includes(rulesType)){
|
|
52
|
+
throw new Error(`'iterable' and 'rules' are from wrong type ${ rulesType }`)
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
if (iterableType === 'Object')
|
|
55
|
+
if (iterableType === 'Object'){
|
|
58
56
|
return evolveObject(rules, iterable)
|
|
59
57
|
}
|
|
60
58
|
|
package/src/filter.js
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
|
-
import {_isArray} from './_internals/_isArray'
|
|
1
|
+
import { _isArray } from './_internals/_isArray.js'
|
|
2
2
|
|
|
3
|
-
export function filterObject(predicate, obj)
|
|
3
|
+
export function filterObject(predicate, obj){
|
|
4
4
|
const willReturn = {}
|
|
5
5
|
|
|
6
|
-
for (const prop in obj)
|
|
7
|
-
if (predicate(
|
|
8
|
-
|
|
6
|
+
for (const prop in obj){
|
|
7
|
+
if (predicate(
|
|
8
|
+
obj[ prop ], prop, obj
|
|
9
|
+
)){
|
|
10
|
+
willReturn[ prop ] = obj[ prop ]
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
return willReturn
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
export function filterArray(
|
|
17
|
+
export function filterArray(
|
|
18
|
+
predicate, list, indexed = false
|
|
19
|
+
){
|
|
16
20
|
let index = 0
|
|
17
21
|
const len = list.length
|
|
18
22
|
const willReturn = []
|
|
19
23
|
|
|
20
|
-
while (index < len)
|
|
21
|
-
const predicateResult = indexed
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (predicateResult)
|
|
25
|
-
willReturn.push(list[index])
|
|
24
|
+
while (index < len){
|
|
25
|
+
const predicateResult = indexed ?
|
|
26
|
+
predicate(list[ index ], index) :
|
|
27
|
+
predicate(list[ index ])
|
|
28
|
+
if (predicateResult){
|
|
29
|
+
willReturn.push(list[ index ])
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
index++
|
|
@@ -31,14 +35,16 @@ export function filterArray(predicate, list, indexed = false) {
|
|
|
31
35
|
return willReturn
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
export function filter(predicate, iterable)
|
|
38
|
+
export function filter(predicate, iterable){
|
|
35
39
|
if (arguments.length === 1)
|
|
36
40
|
return _iterable => filter(predicate, _iterable)
|
|
37
|
-
if (!iterable)
|
|
41
|
+
if (!iterable){
|
|
38
42
|
throw new Error('Incorrect iterable input')
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
if (_isArray(iterable)) return filterArray(
|
|
45
|
+
if (_isArray(iterable)) return filterArray(
|
|
46
|
+
predicate, iterable, false
|
|
47
|
+
)
|
|
42
48
|
|
|
43
49
|
return filterObject(predicate, iterable)
|
|
44
50
|
}
|
package/src/find.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export function find(predicate, list)
|
|
1
|
+
export function find(predicate, list){
|
|
2
2
|
if (arguments.length === 1) return _list => find(predicate, _list)
|
|
3
3
|
|
|
4
4
|
let index = 0
|
|
5
5
|
const len = list.length
|
|
6
6
|
|
|
7
|
-
while (index < len)
|
|
8
|
-
const x = list[index]
|
|
9
|
-
if (predicate(x))
|
|
7
|
+
while (index < len){
|
|
8
|
+
const x = list[ index ]
|
|
9
|
+
if (predicate(x)){
|
|
10
10
|
return x
|
|
11
11
|
}
|
|
12
12
|
|
package/src/findIndex.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export function findIndex(predicate, list)
|
|
1
|
+
export function findIndex(predicate, list){
|
|
2
2
|
if (arguments.length === 1) return _list => findIndex(predicate, _list)
|
|
3
3
|
|
|
4
4
|
const len = list.length
|
|
5
5
|
let index = -1
|
|
6
6
|
|
|
7
|
-
while (++index < len)
|
|
8
|
-
if (predicate(list[index]))
|
|
7
|
+
while (++index < len){
|
|
8
|
+
if (predicate(list[ index ])){
|
|
9
9
|
return index
|
|
10
10
|
}
|
|
11
11
|
}
|
package/src/findLast.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export function findLast(predicate, list)
|
|
1
|
+
export function findLast(predicate, list){
|
|
2
2
|
if (arguments.length === 1) return _list => findLast(predicate, _list)
|
|
3
3
|
|
|
4
4
|
let index = list.length
|
|
5
5
|
|
|
6
|
-
while (--index >= 0)
|
|
7
|
-
if (predicate(list[index]))
|
|
8
|
-
return list[index]
|
|
6
|
+
while (--index >= 0){
|
|
7
|
+
if (predicate(list[ index ])){
|
|
8
|
+
return list[ index ]
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
package/src/findLastIndex.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export function findLastIndex(fn, list)
|
|
1
|
+
export function findLastIndex(fn, list){
|
|
2
2
|
if (arguments.length === 1) return _list => findLastIndex(fn, _list)
|
|
3
3
|
|
|
4
4
|
let index = list.length
|
|
5
5
|
|
|
6
|
-
while (--index >= 0)
|
|
7
|
-
if (fn(list[index]))
|
|
6
|
+
while (--index >= 0){
|
|
7
|
+
if (fn(list[ index ])){
|
|
8
8
|
return index
|
|
9
9
|
}
|
|
10
10
|
}
|