Consolidate relational modules.

This commit is contained in:
John-David Dalton
2017-01-11 00:11:42 -08:00
parent 11052f4d87
commit 34ca4f3efa
7 changed files with 32 additions and 58 deletions

View File

@@ -1,14 +0,0 @@
/**
* The base implementation of `gt` which doesn't coerce arguments.
*
* @private
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if `value` is greater than `other`,
* else `false`.
*/
function baseGt(value, other) {
return value > other;
}
export default baseGt;

View File

@@ -1,14 +0,0 @@
/**
* The base implementation of `lt` which doesn't coerce arguments.
*
* @private
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if `value` is less than `other`,
* else `false`.
*/
function baseLt(value, other) {
return value < other;
}
export default baseLt;

View File

@@ -1,20 +0,0 @@
import toNumber from './toNumber.js';
/**
* Creates a function that performs a relational operation on two values.
*
* @private
* @param {Function} operator The function to perform the operation.
* @returns {Function} Returns the new relational operation function.
*/
function createRelationalOperation(operator) {
return (value, other) => {
if (!(typeof value == 'string' && typeof other == 'string')) {
value = toNumber(value);
other = toNumber(other);
}
return operator(value, other);
};
}
export default createRelationalOperation;

11
gt.js
View File

@@ -1,5 +1,4 @@
import baseGt from './.internal/baseGt.js';
import createRelationalOperation from './.internal/createRelationalOperation.js';
import toNumber from './toNumber.js';
/**
* Checks if `value` is greater than `other`.
@@ -22,6 +21,12 @@ import createRelationalOperation from './.internal/createRelationalOperation.js'
* gt(1, 3);
* // => false
*/
const gt = createRelationalOperation(baseGt);
function gt(value, other) {
if (!(typeof value == 'string' && typeof other == 'string')) {
value = toNumber(value);
other = toNumber(other);
}
return value > other;
}
export default gt;

10
gte.js
View File

@@ -1,4 +1,4 @@
import createRelationalOperation from './.internal/createRelationalOperation.js';
import toNumber from './toNumber.js';
/**
* Checks if `value` is greater than or equal to `other`.
@@ -21,6 +21,12 @@ import createRelationalOperation from './.internal/createRelationalOperation.js'
* gte(1, 3);
* // => false
*/
const gte = createRelationalOperation((value, other) => value >= other);
function gte(value, other) {
if (!(typeof value == 'string' && typeof other == 'string')) {
value = toNumber(value);
other = toNumber(other);
}
return value >= other;
}
export default gte;

11
lt.js
View File

@@ -1,5 +1,4 @@
import baseLt from './.internal/baseLt.js';
import createRelationalOperation from './.internal/createRelationalOperation.js';
import toNumber from './toNumber.js';
/**
* Checks if `value` is less than `other`.
@@ -22,6 +21,12 @@ import createRelationalOperation from './.internal/createRelationalOperation.js'
* lt(3, 1);
* // => false
*/
const lt = createRelationalOperation(baseLt);
function lt(value, other) {
if (!(typeof value == 'string' && typeof other == 'string')) {
value = toNumber(value);
other = toNumber(other);
}
return value < other;
}
export default lt;

10
lte.js
View File

@@ -1,4 +1,4 @@
import createRelationalOperation from './.internal/createRelationalOperation.js';
import toNumber from './toNumber.js';
/**
* Checks if `value` is less than or equal to `other`.
@@ -21,6 +21,12 @@ import createRelationalOperation from './.internal/createRelationalOperation.js'
* lte(3, 1);
* // => false
*/
const lte = createRelationalOperation((value, other) => value <= other);
function lte(value, other) {
if (!(typeof value == 'string' && typeof other == 'string')) {
value = toNumber(value);
other = toNumber(other);
}
return value <= other;
}
export default lte;