mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 18:07:49 +00:00
Consolidate relational modules.
This commit is contained in:
@@ -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;
|
|
||||||
@@ -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;
|
|
||||||
@@ -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
11
gt.js
@@ -1,5 +1,4 @@
|
|||||||
import baseGt from './.internal/baseGt.js';
|
import toNumber from './toNumber.js';
|
||||||
import createRelationalOperation from './.internal/createRelationalOperation.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is greater than `other`.
|
* Checks if `value` is greater than `other`.
|
||||||
@@ -22,6 +21,12 @@ import createRelationalOperation from './.internal/createRelationalOperation.js'
|
|||||||
* gt(1, 3);
|
* gt(1, 3);
|
||||||
* // => false
|
* // => 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;
|
export default gt;
|
||||||
|
|||||||
10
gte.js
10
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`.
|
* Checks if `value` is greater than or equal to `other`.
|
||||||
@@ -21,6 +21,12 @@ import createRelationalOperation from './.internal/createRelationalOperation.js'
|
|||||||
* gte(1, 3);
|
* gte(1, 3);
|
||||||
* // => false
|
* // => 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;
|
export default gte;
|
||||||
|
|||||||
11
lt.js
11
lt.js
@@ -1,5 +1,4 @@
|
|||||||
import baseLt from './.internal/baseLt.js';
|
import toNumber from './toNumber.js';
|
||||||
import createRelationalOperation from './.internal/createRelationalOperation.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is less than `other`.
|
* Checks if `value` is less than `other`.
|
||||||
@@ -22,6 +21,12 @@ import createRelationalOperation from './.internal/createRelationalOperation.js'
|
|||||||
* lt(3, 1);
|
* lt(3, 1);
|
||||||
* // => false
|
* // => 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;
|
export default lt;
|
||||||
|
|||||||
10
lte.js
10
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`.
|
* Checks if `value` is less than or equal to `other`.
|
||||||
@@ -21,6 +21,12 @@ import createRelationalOperation from './.internal/createRelationalOperation.js'
|
|||||||
* lte(3, 1);
|
* lte(3, 1);
|
||||||
* // => false
|
* // => 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;
|
export default lte;
|
||||||
|
|||||||
Reference in New Issue
Block a user