From 34ca4f3efafc7cad5569c22ecb71c5be7d301eea Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 11 Jan 2017 00:11:42 -0800 Subject: [PATCH] Consolidate relational modules. --- .internal/baseGt.js | 14 -------------- .internal/baseLt.js | 14 -------------- .internal/createRelationalOperation.js | 20 -------------------- gt.js | 11 ++++++++--- gte.js | 10 ++++++++-- lt.js | 11 ++++++++--- lte.js | 10 ++++++++-- 7 files changed, 32 insertions(+), 58 deletions(-) delete mode 100644 .internal/baseGt.js delete mode 100644 .internal/baseLt.js delete mode 100644 .internal/createRelationalOperation.js diff --git a/.internal/baseGt.js b/.internal/baseGt.js deleted file mode 100644 index 040061d7b..000000000 --- a/.internal/baseGt.js +++ /dev/null @@ -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; diff --git a/.internal/baseLt.js b/.internal/baseLt.js deleted file mode 100644 index f66a47f21..000000000 --- a/.internal/baseLt.js +++ /dev/null @@ -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; diff --git a/.internal/createRelationalOperation.js b/.internal/createRelationalOperation.js deleted file mode 100644 index 5bee50b23..000000000 --- a/.internal/createRelationalOperation.js +++ /dev/null @@ -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; diff --git a/gt.js b/gt.js index 4a16edf2a..70ac8da87 100644 --- a/gt.js +++ b/gt.js @@ -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; diff --git a/gte.js b/gte.js index af16f906e..cb936c8b6 100644 --- a/gte.js +++ b/gte.js @@ -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; diff --git a/lt.js b/lt.js index bade80646..9c1801773 100644 --- a/lt.js +++ b/lt.js @@ -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; diff --git a/lte.js b/lte.js index 3032f975d..114cafadd 100644 --- a/lte.js +++ b/lte.js @@ -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;