rambda 9.4.2 → 10.0.0-beta.1
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 +177 -1
- package/README.md +6799 -11799
- package/dist/rambda.cjs +1795 -0
- package/dist/rambda.js +1162 -2234
- package/dist/rambda.umd.js +1801 -1
- package/immutable.d.ts +1154 -1403
- package/index.d.ts +1154 -1403
- package/package.json +102 -94
- package/rambda.js +24 -137
- package/src/_internals/baseSlice.js +5 -7
- package/src/_internals/createPath.js +4 -6
- package/src/_internals/includes.js +8 -4
- package/src/_internals/set.js +11 -11
- package/src/addProp.js +3 -0
- package/src/all.js +8 -6
- package/src/allPass.js +4 -4
- package/src/any.js +10 -10
- package/src/anyPass.js +4 -4
- package/src/append.js +6 -8
- package/src/ascend.js +8 -15
- package/src/checkObjectWithSpec.js +16 -0
- package/src/compact.js +12 -0
- package/src/complement.js +1 -1
- package/src/concat.js +2 -4
- package/src/count.js +7 -6
- package/src/countBy.js +13 -14
- package/src/createObjectFromKeys.js +10 -0
- package/src/defaultTo.js +4 -6
- package/src/descend.js +6 -13
- package/src/drop.js +4 -2
- package/src/dropLast.js +2 -8
- package/src/dropLastWhile.js +17 -26
- package/src/dropWhile.js +14 -22
- package/src/eqBy.js +3 -8
- package/src/eqProps.js +3 -9
- package/src/equals.js +99 -58
- package/src/evolve.js +3 -57
- package/src/excludes.js +5 -0
- package/src/filter.js +13 -43
- package/src/filterObject.js +13 -0
- package/src/find.js +10 -10
- package/src/findIndex.js +10 -10
- package/src/findLast.js +9 -9
- package/src/findLastIndex.js +9 -9
- package/src/findNth.js +16 -0
- package/src/flatMap.js +3 -0
- package/src/flatten.js +5 -5
- package/src/groupBy.js +14 -11
- package/src/head.js +5 -3
- package/src/includes.js +13 -11
- package/src/indexOf.js +2 -6
- package/src/init.js +6 -8
- package/src/innerJoin.js +11 -19
- package/src/interpolate.js +29 -0
- package/src/intersection.js +2 -4
- package/src/intersperse.js +13 -13
- package/src/join.js +2 -4
- package/src/last.js +4 -4
- package/src/lastIndexOf.js +2 -6
- package/src/map.js +9 -49
- package/src/mapAsync.js +11 -0
- package/src/mapKeys.js +11 -0
- package/src/mapObject.js +18 -0
- package/src/mapObjectAsync.js +10 -0
- package/src/mapParallelAsync.js +3 -0
- package/src/match.js +5 -5
- package/src/maxBy.js +2 -8
- package/src/merge.js +4 -1
- package/src/mergeTypes.js +3 -0
- package/src/minBy.js +2 -8
- package/src/modifyProp.js +20 -0
- package/src/none.js +8 -6
- package/src/objOf.js +2 -6
- package/src/objectIncludes.js +12 -0
- package/src/omit.js +26 -11
- package/src/partition.js +15 -42
- package/src/partitionObject.js +15 -0
- package/src/path.js +14 -15
- package/src/permutations.js +40 -0
- package/src/pick.js +15 -15
- package/src/pipe.js +70 -13
- package/src/pipeAsync.js +11 -0
- package/src/pluck.js +12 -14
- package/src/prepend.js +2 -6
- package/src/prop.js +2 -10
- package/src/propEq.js +8 -10
- package/src/propOr.js +7 -8
- package/src/propSatisfies.js +2 -9
- package/src/range.js +34 -11
- package/src/reduce.js +15 -30
- package/src/reject.js +2 -4
- package/src/rejectObject.js +13 -0
- package/src/replace.js +2 -8
- package/src/replaceItemAtIndex.js +15 -0
- package/src/shuffle.js +13 -0
- package/src/sort.js +2 -4
- package/src/sortBy.js +12 -10
- package/src/sortObject.js +15 -0
- package/src/sortWith.js +12 -16
- package/src/split.js +2 -4
- package/src/splitEvery.js +11 -13
- package/src/symmetricDifference.js +5 -8
- package/src/tail.js +2 -2
- package/src/take.js +11 -9
- package/src/takeLast.js +14 -14
- package/src/takeLastWhile.js +15 -16
- package/src/takeWhile.js +12 -21
- package/src/tap.js +5 -5
- package/src/test.js +2 -8
- package/src/tryCatch.js +5 -14
- package/src/type.js +6 -5
- package/src/union.js +10 -8
- package/src/uniq.js +2 -2
- package/src/uniqBy.js +5 -6
- package/src/uniqWith.js +15 -19
- package/src/unless.js +7 -9
- package/src/unwind.js +6 -14
- package/src/update.js +8 -11
- package/src/when.js +7 -9
- package/src/zip.js +8 -8
- package/src/zipWith.js +5 -7
- package/src/F.js +0 -3
- package/src/T.js +0 -3
- package/src/_internals/_arity.js +0 -64
- package/src/_internals/compare.js +0 -3
- package/src/_internals/constants.js +0 -1
- package/src/_internals/createPathInput.js +0 -7
- package/src/_internals/isFalsy.js +0 -13
- package/src/_internals/isInteger.js +0 -10
- package/src/_internals/isIterable.js +0 -5
- package/src/_internals/isObject.js +0 -5
- package/src/_internals/isTruthy.js +0 -13
- package/src/_internals/objectIs.js +0 -9
- package/src/_internals/utils.js +0 -21
- package/src/add.js +0 -5
- package/src/addIndex.js +0 -23
- package/src/addIndexRight.js +0 -9
- package/src/adjust.js +0 -16
- package/src/always.js +0 -3
- package/src/and.js +0 -5
- package/src/ap.js +0 -7
- package/src/aperture.js +0 -15
- package/src/apply.js +0 -7
- package/src/applySpec.js +0 -132
- package/src/applyTo.js +0 -7
- package/src/assoc.js +0 -11
- package/src/assocPath.js +0 -46
- package/src/binary.js +0 -5
- package/src/bind.js +0 -9
- package/src/both.js +0 -5
- package/src/call.js +0 -1
- package/src/chain.js +0 -7
- package/src/clamp.js +0 -15
- package/src/clone.js +0 -18
- package/src/collectBy.js +0 -27
- package/src/comparator.js +0 -5
- package/src/compose.js +0 -9
- package/src/composeWith.js +0 -33
- package/src/cond.js +0 -14
- package/src/converge.js +0 -18
- package/src/curry.js +0 -7
- package/src/curryN.js +0 -40
- package/src/dec.js +0 -1
- package/src/difference.js +0 -8
- package/src/differenceWith.js +0 -20
- package/src/dissoc.js +0 -13
- package/src/dissocPath.js +0 -47
- package/src/divide.js +0 -5
- package/src/dropRepeats.js +0 -20
- package/src/dropRepeatsBy.js +0 -21
- package/src/dropRepeatsWith.js +0 -28
- package/src/either.js +0 -8
- package/src/empty.js +0 -15
- package/src/endsWith.js +0 -23
- package/src/flip.js +0 -23
- package/src/forEach.js +0 -19
- package/src/forEachObjIndexed.js +0 -24
- package/src/fromPairs.js +0 -6
- package/src/groupWith.js +0 -46
- package/src/gt.js +0 -6
- package/src/gte.js +0 -6
- package/src/has.js +0 -7
- package/src/hasIn.js +0 -9
- package/src/hasPath.js +0 -9
- package/src/identical.js +0 -7
- package/src/identity.js +0 -3
- package/src/ifElse.js +0 -17
- package/src/inc.js +0 -1
- package/src/indexBy.js +0 -29
- package/src/insert.js +0 -11
- package/src/insertAll.js +0 -7
- package/src/is.js +0 -8
- package/src/isEmpty.js +0 -18
- package/src/isNil.js +0 -3
- package/src/isNotEmpty.js +0 -5
- package/src/isNotNil.js +0 -3
- package/src/isPromise.js +0 -5
- package/src/juxt.js +0 -3
- package/src/keys.js +0 -3
- package/src/length.js +0 -8
- package/src/lens.js +0 -7
- package/src/lensIndex.js +0 -7
- package/src/lensPath.js +0 -7
- package/src/lensProp.js +0 -7
- package/src/lt.js +0 -6
- package/src/lte.js +0 -6
- package/src/mathMod.js +0 -8
- package/src/max.js +0 -5
- package/src/maybe.js +0 -13
- package/src/mean.js +0 -5
- package/src/median.js +0 -17
- package/src/mergeAll.js +0 -11
- package/src/mergeDeepLeft.js +0 -5
- package/src/mergeDeepRight.js +0 -24
- package/src/mergeLeft.js +0 -7
- package/src/mergeRight.js +0 -8
- package/src/mergeWith.js +0 -25
- package/src/min.js +0 -5
- package/src/modify.js +0 -23
- package/src/modifyPath.js +0 -33
- package/src/modulo.js +0 -5
- package/src/move.js +0 -19
- package/src/multiply.js +0 -5
- package/src/negate.js +0 -3
- package/src/not.js +0 -3
- package/src/nth.js +0 -9
- package/src/of.js +0 -3
- package/src/on.js +0 -16
- package/src/once.js +0 -24
- package/src/or.js +0 -5
- package/src/over.js +0 -14
- package/src/partial.js +0 -17
- package/src/partialObject.js +0 -5
- package/src/pathEq.js +0 -11
- package/src/pathOr.js +0 -11
- package/src/pathSatisfies.js +0 -9
- package/src/paths.js +0 -9
- package/src/pickAll.js +0 -23
- package/src/pickBy.js +0 -11
- package/src/product.js +0 -4
- package/src/propIs.js +0 -10
- package/src/props.js +0 -13
- package/src/reduceBy.js +0 -29
- package/src/removeIndex.js +0 -7
- package/src/repeat.js +0 -7
- package/src/reverse.js +0 -9
- package/src/set.js +0 -9
- package/src/slice.js +0 -9
- package/src/splitAt.js +0 -21
- package/src/splitWhen.js +0 -25
- package/src/startsWith.js +0 -23
- package/src/subtract.js +0 -5
- package/src/sum.js +0 -3
- package/src/swap.js +0 -42
- package/src/times.js +0 -12
- package/src/toLower.js +0 -3
- package/src/toPairs.js +0 -3
- package/src/toString.js +0 -3
- package/src/toUpper.js +0 -3
- package/src/transpose.js +0 -10
- package/src/trim.js +0 -3
- package/src/unapply.js +0 -5
- package/src/unnest.js +0 -9
- package/src/values.js +0 -6
- package/src/view.js +0 -10
- package/src/where.js +0 -15
- package/src/whereAny.js +0 -12
- package/src/whereEq.js +0 -14
- package/src/without.js +0 -15
- package/src/xor.js +0 -5
- package/src/zipObj.js +0 -13
package/src/append.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { cloneList } from './_internals/cloneList.js'
|
|
2
2
|
|
|
3
|
-
export function append(x
|
|
4
|
-
|
|
3
|
+
export function append(x) {
|
|
4
|
+
return list => {
|
|
5
|
+
const clone = cloneList(list)
|
|
6
|
+
clone.push(x)
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const clone = cloneList(input)
|
|
9
|
-
clone.push(x)
|
|
10
|
-
|
|
11
|
-
return clone
|
|
8
|
+
return clone
|
|
9
|
+
}
|
|
12
10
|
}
|
package/src/ascend.js
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
export function createCompareFunction(
|
|
2
|
-
a
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export function createCompareFunction(a, b, winner, loser) {
|
|
2
|
+
if (a === b) {
|
|
3
|
+
return 0
|
|
4
|
+
}
|
|
5
5
|
|
|
6
6
|
return a < b ? winner : loser
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export function ascend(
|
|
10
|
-
|
|
11
|
-
){
|
|
12
|
-
if (arguments.length === 1){
|
|
13
|
-
return (_a, _b) => ascend(
|
|
14
|
-
getFunction, _a, _b
|
|
15
|
-
)
|
|
16
|
-
}
|
|
9
|
+
export function ascend(getFunction) {
|
|
10
|
+
return (a, b) => {
|
|
17
11
|
const aValue = getFunction(a)
|
|
18
12
|
const bValue = getFunction(b)
|
|
19
13
|
|
|
20
|
-
return createCompareFunction(
|
|
21
|
-
|
|
22
|
-
)
|
|
14
|
+
return createCompareFunction(aValue, bValue, -1, 1)
|
|
15
|
+
}
|
|
23
16
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function checkObjectWithSpec(conditions) {
|
|
2
|
+
return input => {
|
|
3
|
+
let shouldProceed = true
|
|
4
|
+
for (const prop in conditions) {
|
|
5
|
+
if (!shouldProceed) {
|
|
6
|
+
continue
|
|
7
|
+
}
|
|
8
|
+
const result = conditions[prop](input[prop])
|
|
9
|
+
if (shouldProceed && result === false) {
|
|
10
|
+
shouldProceed = false
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return shouldProceed
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/compact.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isArray } from './_internals/isArray.js'
|
|
2
|
+
import { reject } from './reject.js'
|
|
3
|
+
import { rejectObject } from './rejectObject.js'
|
|
4
|
+
|
|
5
|
+
const isNullOrUndefined = x => x === null || x === undefined
|
|
6
|
+
|
|
7
|
+
export function compact(input){
|
|
8
|
+
if(isArray(input)){
|
|
9
|
+
return reject(isNullOrUndefined)(input)
|
|
10
|
+
}
|
|
11
|
+
return rejectObject(isNullOrUndefined)(input)
|
|
12
|
+
}
|
package/src/complement.js
CHANGED
package/src/concat.js
CHANGED
package/src/count.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { isArray } from './_internals/isArray.js'
|
|
2
2
|
|
|
3
|
-
export function count(predicate
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export function count(predicate) {
|
|
4
|
+
return list => {
|
|
5
|
+
if (!isArray(list)) {
|
|
6
|
+
return 0
|
|
7
|
+
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
return list.filter(x => predicate(x)).length
|
|
10
|
+
}
|
|
10
11
|
}
|
package/src/countBy.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
export function countBy(fn
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
const willReturn = {}
|
|
1
|
+
export function countBy(fn) {
|
|
2
|
+
return list => {
|
|
3
|
+
const willReturn = {}
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
list.forEach(item => {
|
|
6
|
+
const key = fn(item)
|
|
7
|
+
if (!willReturn[key]) {
|
|
8
|
+
willReturn[key] = 1
|
|
9
|
+
} else {
|
|
10
|
+
willReturn[key]++
|
|
11
|
+
}
|
|
12
|
+
})
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
return willReturn
|
|
15
|
+
}
|
|
17
16
|
}
|
package/src/defaultTo.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
function isFalsy(input){
|
|
2
|
-
return (
|
|
3
|
-
input === undefined || input === null || Number.isNaN(input) === true
|
|
4
|
-
)
|
|
1
|
+
function isFalsy(input) {
|
|
2
|
+
return input === undefined || input === null || Number.isNaN(input) === true
|
|
5
3
|
}
|
|
6
4
|
|
|
7
|
-
export function defaultTo(defaultArgument, input){
|
|
8
|
-
if (arguments.length === 1){
|
|
5
|
+
export function defaultTo(defaultArgument, input) {
|
|
6
|
+
if (arguments.length === 1) {
|
|
9
7
|
return _input => defaultTo(defaultArgument, _input)
|
|
10
8
|
}
|
|
11
9
|
|
package/src/descend.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import { createCompareFunction } from './ascend.js'
|
|
2
2
|
|
|
3
|
-
export function descend(
|
|
4
|
-
|
|
5
|
-
)
|
|
6
|
-
|
|
7
|
-
return (_a, _b) => descend(
|
|
8
|
-
getFunction, _a, _b
|
|
9
|
-
)
|
|
10
|
-
}
|
|
11
|
-
const aValue = getFunction(a)
|
|
12
|
-
const bValue = getFunction(b)
|
|
3
|
+
export function descend(getFunction) {
|
|
4
|
+
return (a, b) => {
|
|
5
|
+
const aValue = getFunction(a)
|
|
6
|
+
const bValue = getFunction(b)
|
|
13
7
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
)
|
|
8
|
+
return createCompareFunction(aValue, bValue, 1, -1)
|
|
9
|
+
}
|
|
17
10
|
}
|
package/src/drop.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export function drop(howManyToDrop, listOrString){
|
|
2
|
-
if (arguments.length === 1)
|
|
1
|
+
export function drop(howManyToDrop, listOrString) {
|
|
2
|
+
if (arguments.length === 1) {
|
|
3
|
+
return _list => drop(howManyToDrop, _list)
|
|
4
|
+
}
|
|
3
5
|
|
|
4
6
|
return listOrString.slice(howManyToDrop > 0 ? howManyToDrop : 0)
|
|
5
7
|
}
|
package/src/dropLast.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
export function dropLast(
|
|
2
|
-
|
|
3
|
-
return _listOrString => dropLast(howManyToDrop, _listOrString)
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
return howManyToDrop > 0 ?
|
|
7
|
-
listOrString.slice(0, -howManyToDrop) :
|
|
8
|
-
listOrString.slice()
|
|
1
|
+
export function dropLast(numberItems) {
|
|
2
|
+
return list => (numberItems > 0 ? list.slice(0, -numberItems) : list.slice())
|
|
9
3
|
}
|
package/src/dropLastWhile.js
CHANGED
|
@@ -1,33 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
if (iterable.length === 0) return iterable
|
|
8
|
-
const isArray = isArrayMethod(iterable)
|
|
1
|
+
export function dropLastWhile(predicate) {
|
|
2
|
+
return list => {
|
|
3
|
+
if (list.length === 0) {
|
|
4
|
+
return list
|
|
5
|
+
}
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
if (!isArray && typeof iterable !== 'string'){
|
|
14
|
-
throw new Error(`'iterable' is from wrong type ${ typeof iterable }`)
|
|
15
|
-
}
|
|
7
|
+
const toReturn = []
|
|
8
|
+
let counter = list.length
|
|
16
9
|
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
while (counter) {
|
|
11
|
+
const item = list[--counter]
|
|
12
|
+
if (!predicate(item, counter)) {
|
|
13
|
+
toReturn.push(item)
|
|
14
|
+
break
|
|
15
|
+
}
|
|
16
|
+
}
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (!predicate(item)){
|
|
23
|
-
toReturn.push(item)
|
|
24
|
-
break
|
|
18
|
+
while (counter) {
|
|
19
|
+
toReturn.push(list[--counter])
|
|
25
20
|
}
|
|
26
|
-
}
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
toReturn.push(iterable[ --counter ])
|
|
22
|
+
return toReturn.reverse()
|
|
30
23
|
}
|
|
31
|
-
|
|
32
|
-
return isArray ? toReturn.reverse() : toReturn.reverse().join('')
|
|
33
24
|
}
|
package/src/dropWhile.js
CHANGED
|
@@ -1,28 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
export function dropWhile(predicate) {
|
|
2
|
+
return iterable => {
|
|
3
|
+
const toReturn = []
|
|
4
|
+
let counter = 0
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const toReturn = []
|
|
13
|
-
let counter = 0
|
|
6
|
+
while (counter < iterable.length) {
|
|
7
|
+
const item = iterable[counter++]
|
|
8
|
+
if (!predicate(item, counter)) {
|
|
9
|
+
toReturn.push(item)
|
|
10
|
+
break
|
|
11
|
+
}
|
|
12
|
+
}
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (!predicate(item)){
|
|
18
|
-
toReturn.push(item)
|
|
19
|
-
break
|
|
14
|
+
while (counter < iterable.length) {
|
|
15
|
+
toReturn.push(iterable[counter++])
|
|
20
16
|
}
|
|
21
|
-
}
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
toReturn.push(iterable[ counter++ ])
|
|
18
|
+
return toReturn
|
|
25
19
|
}
|
|
26
|
-
|
|
27
|
-
return isArray ? toReturn : toReturn.join('')
|
|
28
20
|
}
|
package/src/eqBy.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { equals } from './equals.js'
|
|
1
|
+
import { equalsFn } from './equals.js'
|
|
3
2
|
|
|
4
|
-
export function
|
|
5
|
-
fn
|
|
6
|
-
){
|
|
7
|
-
return equals(fn(a), fn(b))
|
|
3
|
+
export function eqBy(fn, a) {
|
|
4
|
+
return b => equalsFn(fn(a), fn(b))
|
|
8
5
|
}
|
|
9
|
-
|
|
10
|
-
export const eqBy = curry(eqByFn)
|
package/src/eqProps.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { equals } from './equals.js'
|
|
3
|
-
import { prop } from './prop.js'
|
|
1
|
+
import { equalsFn } from './equals.js'
|
|
4
2
|
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
){
|
|
8
|
-
return equals(prop(property, objA), prop(property, objB))
|
|
3
|
+
export function eqProps(property, objA) {
|
|
4
|
+
return objB => equalsFn( objA[property], objB[property] )
|
|
9
5
|
}
|
|
10
|
-
|
|
11
|
-
export const eqProps = curry(eqPropsFn)
|
package/src/equals.js
CHANGED
|
@@ -1,56 +1,66 @@
|
|
|
1
1
|
import { isArray } from './_internals/isArray.js'
|
|
2
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 ${
|
|
4
|
+
export function _lastIndexOf(valueToFind, list) {
|
|
5
|
+
if (!isArray(list)) {
|
|
6
|
+
throw new Error(`Cannot read property 'indexOf' of ${list}`)
|
|
7
|
+
}
|
|
7
8
|
|
|
8
9
|
const typeOfValue = type(valueToFind)
|
|
9
|
-
if (![
|
|
10
|
+
if (!['Array', 'NaN', 'Object', 'RegExp'].includes(typeOfValue)) {
|
|
10
11
|
return list.lastIndexOf(valueToFind)
|
|
12
|
+
}
|
|
11
13
|
|
|
12
14
|
const { length } = list
|
|
13
15
|
let index = length
|
|
14
16
|
let foundIndex = -1
|
|
15
17
|
|
|
16
|
-
while (--index > -1 && foundIndex === -1)
|
|
17
|
-
if (
|
|
18
|
+
while (--index > -1 && foundIndex === -1) {
|
|
19
|
+
if (equalsFn(list[index], valueToFind)) {
|
|
18
20
|
foundIndex = index
|
|
21
|
+
}
|
|
22
|
+
}
|
|
19
23
|
|
|
20
24
|
return foundIndex
|
|
21
25
|
}
|
|
22
26
|
|
|
23
|
-
export function _indexOf(valueToFind, list){
|
|
24
|
-
if (!isArray(list))
|
|
25
|
-
throw new Error(`Cannot read property 'indexOf' of ${
|
|
27
|
+
export function _indexOf(valueToFind, list) {
|
|
28
|
+
if (!isArray(list)) {
|
|
29
|
+
throw new Error(`Cannot read property 'indexOf' of ${list}`)
|
|
30
|
+
}
|
|
26
31
|
|
|
27
32
|
const typeOfValue = type(valueToFind)
|
|
28
|
-
if (![
|
|
33
|
+
if (!['Array', 'NaN', 'Object', 'RegExp'].includes(typeOfValue)) {
|
|
29
34
|
return list.indexOf(valueToFind)
|
|
35
|
+
}
|
|
30
36
|
|
|
31
37
|
let index = -1
|
|
32
38
|
let foundIndex = -1
|
|
33
39
|
const { length } = list
|
|
34
40
|
|
|
35
|
-
while (++index < length && foundIndex === -1)
|
|
36
|
-
if (
|
|
41
|
+
while (++index < length && foundIndex === -1) {
|
|
42
|
+
if (equalsFn(list[index], valueToFind)) {
|
|
37
43
|
foundIndex = index
|
|
44
|
+
}
|
|
45
|
+
}
|
|
38
46
|
|
|
39
47
|
return foundIndex
|
|
40
48
|
}
|
|
41
49
|
|
|
42
|
-
function _arrayFromIterator(iter){
|
|
50
|
+
function _arrayFromIterator(iter) {
|
|
43
51
|
const list = []
|
|
44
52
|
let next
|
|
45
|
-
while (!(next = iter.next()).done)
|
|
53
|
+
while (!(next = iter.next()).done) {
|
|
46
54
|
list.push(next.value)
|
|
55
|
+
}
|
|
47
56
|
|
|
48
57
|
return list
|
|
49
58
|
}
|
|
50
59
|
|
|
51
|
-
function _compareSets(a, b){
|
|
52
|
-
if (a.size !== b.size)
|
|
60
|
+
function _compareSets(a, b) {
|
|
61
|
+
if (a.size !== b.size) {
|
|
53
62
|
return false
|
|
63
|
+
}
|
|
54
64
|
|
|
55
65
|
const aList = _arrayFromIterator(a.values())
|
|
56
66
|
const bList = _arrayFromIterator(b.values())
|
|
@@ -60,63 +70,81 @@ function _compareSets(a, b){
|
|
|
60
70
|
return filtered.length === 0
|
|
61
71
|
}
|
|
62
72
|
|
|
63
|
-
function compareErrors(a, b){
|
|
64
|
-
if (a.message !== b.message)
|
|
65
|
-
|
|
73
|
+
function compareErrors(a, b) {
|
|
74
|
+
if (a.message !== b.message) {
|
|
75
|
+
return false
|
|
76
|
+
}
|
|
77
|
+
if (a.toString !== b.toString) {
|
|
78
|
+
return false
|
|
79
|
+
}
|
|
66
80
|
|
|
67
81
|
return a.toString() === b.toString()
|
|
68
82
|
}
|
|
69
83
|
|
|
70
|
-
function parseDate(maybeDate){
|
|
71
|
-
if (!maybeDate.toDateString)
|
|
84
|
+
function parseDate(maybeDate) {
|
|
85
|
+
if (!maybeDate.toDateString) {
|
|
86
|
+
return [false]
|
|
87
|
+
}
|
|
72
88
|
|
|
73
|
-
return [
|
|
89
|
+
return [true, maybeDate.getTime()]
|
|
74
90
|
}
|
|
75
91
|
|
|
76
|
-
function parseRegex(maybeRegex){
|
|
77
|
-
if (maybeRegex.constructor !== RegExp)
|
|
92
|
+
function parseRegex(maybeRegex) {
|
|
93
|
+
if (maybeRegex.constructor !== RegExp) {
|
|
94
|
+
return [false]
|
|
95
|
+
}
|
|
78
96
|
|
|
79
|
-
return [
|
|
97
|
+
return [true, maybeRegex.toString()]
|
|
80
98
|
}
|
|
81
99
|
|
|
82
|
-
export function
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
|
|
100
|
+
export function equalsFn(a, b) {
|
|
101
|
+
if (Object.is(a, b)) {
|
|
102
|
+
return true
|
|
103
|
+
}
|
|
86
104
|
|
|
87
105
|
const aType = type(a)
|
|
88
106
|
|
|
89
|
-
if (aType !== type(b))
|
|
90
|
-
|
|
107
|
+
if (aType !== type(b)) {
|
|
108
|
+
return false
|
|
109
|
+
}
|
|
110
|
+
if (aType === 'Function') {
|
|
91
111
|
return a.name === undefined ? false : a.name === b.name
|
|
112
|
+
}
|
|
92
113
|
|
|
93
|
-
if ([
|
|
114
|
+
if (['NaN', 'Null', 'Undefined'].includes(aType)) {
|
|
115
|
+
return true
|
|
116
|
+
}
|
|
94
117
|
|
|
95
|
-
if ([
|
|
96
|
-
if (Object.is(-0, a) !== Object.is(-0, b))
|
|
118
|
+
if (['BigInt', 'Number'].includes(aType)) {
|
|
119
|
+
if (Object.is(-0, a) !== Object.is(-0, b)) {
|
|
120
|
+
return false
|
|
121
|
+
}
|
|
97
122
|
|
|
98
123
|
return a.toString() === b.toString()
|
|
99
124
|
}
|
|
100
125
|
|
|
101
|
-
if ([
|
|
126
|
+
if (['Boolean', 'String'].includes(aType)) {
|
|
102
127
|
return a.toString() === b.toString()
|
|
128
|
+
}
|
|
103
129
|
|
|
104
|
-
if (aType === 'Array'){
|
|
130
|
+
if (aType === 'Array') {
|
|
105
131
|
const aClone = Array.from(a)
|
|
106
132
|
const bClone = Array.from(b)
|
|
107
133
|
|
|
108
|
-
if (aClone.toString() !== bClone.toString())
|
|
134
|
+
if (aClone.toString() !== bClone.toString()) {
|
|
109
135
|
return false
|
|
136
|
+
}
|
|
110
137
|
|
|
111
138
|
let loopArrayFlag = true
|
|
112
139
|
aClone.forEach((aCloneInstance, aCloneIndex) => {
|
|
113
|
-
if (loopArrayFlag)
|
|
140
|
+
if (loopArrayFlag) {
|
|
114
141
|
if (
|
|
115
|
-
aCloneInstance !== bClone[
|
|
116
|
-
!
|
|
117
|
-
)
|
|
142
|
+
aCloneInstance !== bClone[aCloneIndex] &&
|
|
143
|
+
!equalsFn(aCloneInstance, bClone[aCloneIndex])
|
|
144
|
+
) {
|
|
118
145
|
loopArrayFlag = false
|
|
119
|
-
|
|
146
|
+
}
|
|
147
|
+
}
|
|
120
148
|
})
|
|
121
149
|
|
|
122
150
|
return loopArrayFlag
|
|
@@ -125,41 +153,51 @@ export function equals(a, b){
|
|
|
125
153
|
const aRegex = parseRegex(a)
|
|
126
154
|
const bRegex = parseRegex(b)
|
|
127
155
|
|
|
128
|
-
if (aRegex[
|
|
129
|
-
return bRegex[
|
|
130
|
-
|
|
156
|
+
if (aRegex[0]) {
|
|
157
|
+
return bRegex[0] ? aRegex[1] === bRegex[1] : false
|
|
158
|
+
}
|
|
159
|
+
if (bRegex[0]) {
|
|
160
|
+
return false
|
|
161
|
+
}
|
|
131
162
|
|
|
132
163
|
const aDate = parseDate(a)
|
|
133
164
|
const bDate = parseDate(b)
|
|
134
165
|
|
|
135
|
-
if (aDate[
|
|
136
|
-
return bDate[
|
|
137
|
-
|
|
166
|
+
if (aDate[0]) {
|
|
167
|
+
return bDate[0] ? aDate[1] === bDate[1] : false
|
|
168
|
+
}
|
|
169
|
+
if (bDate[0]) {
|
|
170
|
+
return false
|
|
171
|
+
}
|
|
138
172
|
|
|
139
|
-
if (a instanceof Error){
|
|
140
|
-
if (!(b instanceof Error))
|
|
173
|
+
if (a instanceof Error) {
|
|
174
|
+
if (!(b instanceof Error)) {
|
|
175
|
+
return false
|
|
176
|
+
}
|
|
141
177
|
|
|
142
178
|
return compareErrors(a, b)
|
|
143
179
|
}
|
|
144
180
|
|
|
145
|
-
if (aType === 'Set')
|
|
181
|
+
if (aType === 'Set') {
|
|
146
182
|
return _compareSets(a, b)
|
|
183
|
+
}
|
|
147
184
|
|
|
148
|
-
if (aType === 'Object'){
|
|
185
|
+
if (aType === 'Object') {
|
|
149
186
|
const aKeys = Object.keys(a)
|
|
150
187
|
|
|
151
|
-
if (aKeys.length !== Object.keys(b).length)
|
|
188
|
+
if (aKeys.length !== Object.keys(b).length) {
|
|
152
189
|
return false
|
|
190
|
+
}
|
|
153
191
|
|
|
154
192
|
let loopObjectFlag = true
|
|
155
193
|
aKeys.forEach(aKeyInstance => {
|
|
156
|
-
if (loopObjectFlag){
|
|
157
|
-
const aValue = a[
|
|
158
|
-
const bValue = b[
|
|
194
|
+
if (loopObjectFlag) {
|
|
195
|
+
const aValue = a[aKeyInstance]
|
|
196
|
+
const bValue = b[aKeyInstance]
|
|
159
197
|
|
|
160
|
-
if (aValue !== bValue && !
|
|
198
|
+
if (aValue !== bValue && !equalsFn(aValue, bValue)) {
|
|
161
199
|
loopObjectFlag = false
|
|
162
|
-
|
|
200
|
+
}
|
|
163
201
|
}
|
|
164
202
|
})
|
|
165
203
|
|
|
@@ -168,3 +206,6 @@ export function equals(a, b){
|
|
|
168
206
|
|
|
169
207
|
return false
|
|
170
208
|
}
|
|
209
|
+
export function equals(a) {
|
|
210
|
+
return b => equalsFn(a, b)
|
|
211
|
+
}
|