Skip to content

Commit

Permalink
feat: implement eq and ne
Browse files Browse the repository at this point in the history
  • Loading branch information
customcommander committed Jul 15, 2021
1 parent 85635d3 commit 12693df
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/logic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @license MIT
* @copyright (c) 2021 Julien Gonzalez <hello@spinjs.com>
*/

const {curry} = require('./functions');

/**
* @namespace
* @alias ROOT
*/
module.exports = {
/**
* True if `a` and `b` are equal. Use `Object.is`.
*
* @example
* ```javascript
* const eq42 = eq(42);
*
* eq42(42);
* //=> true
*
* eq42('42');
* //=> false
*
* eq(NaN, NaN);
* //=> true;
* ```
*
* @public
* @param {?} a
* @param {?} b
* @return {boolean}
* @see ne
*/
eq: curry((a, b) => Object.is(a, b) == true),

/**
* True if `a` and `b` are not equal. Use `Object.is`.
*
* @example
* ```javascript
* ne(null, undefined);
* //=> true
*
* ne(NaN, NaN);
* //=> false
* ```
*
* @public
* @param {?} a
* @param {?} b
* @return {boolean}
* @see eq
*/
ne: curry((a, b) => Object.is(a, b) == false)
};
22 changes: 22 additions & 0 deletions test/logic.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const test = require('tape');
const {eq, ne} = require('../');

test('eq returns true if both parameters are equal', t => {
const run = (a, b) => t.same(eq(a)(b), Object.is(a, b));
run(1, '1');
run(0, false);
run(+0, -0);
run(NaN, NaN);
run(null, undefined);
t.end();
});

test('ne returns true if both parameters are not equal', t => {
const run = (a, b) => t.same(ne(a)(b), Object.is(a, b) == false);
run(1, '1');
run(0, false);
run(+0, -0);
run(NaN, NaN);
run(null, undefined);
t.end();
});

0 comments on commit 12693df

Please sign in to comment.