-
Notifications
You must be signed in to change notification settings - Fork 15
/
eq.js
62 lines (59 loc) · 1.84 KB
/
eq.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const ComparisonOperator = require('./_internal/ComparisonOperator')
const equals = require('./_internal/equals')
/**
* @name eq
*
* @synopsis
* ```coffeescript [specscript]
* eq(leftValue Promise|any, rightValue Promise|any) -> boolean
*
* eq(leftValue Promise|any, right function)(...args) -> Promise|boolean
* eq(...args, leftValue Promise|any, right function) -> Promise|boolean
*
* eq(left function, rightValue Promise|any)(...args) -> Promise|boolean
* eq(...args, left function, rightValue Promise|any) -> Promise|boolean
*
* eq(left function, right function)(...args) -> Promise|boolean
* eq(...args, left function, right function) -> Promise|boolean
* ```
*
* @description
* Test for [equality (`==`)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality) between two values.
*
* ```javascript [playground]
* const areNamesEqual = eq('Ted', 'George')
*
* console.log(areNamesEqual) // false
* ```
*
* If either of the two values are resolver functions, `eq` returns a function that resolves the values to compare from its arguments.
*
* ```javascript [playground]
* const personIsGeorge = eq(get('name'), 'George')
*
* const person = { name: 'George', likes: 'bananas' }
*
* if (personIsGeorge(person)) {
* console.log('The person is george')
* }
* ```
*
* `eq` supports a lazy API for composability.
*
* ```javascript [playground]
* pipe({ name: 'George' }, [
* eq('George', get('name')),
* console.log, // true
* ])
* ```
*
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
*
* ```javascript [playground]
* eq(Promise.resolve({ a: 1, b: 1 }), get('a'), get('b')).then(console.log) // true
* ```
*
* @execution concurrent
*/
const eq = ComparisonOperator(equals)
module.exports = eq