mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 01:17:50 +00:00
wip: migrate to bun
This commit is contained in:
35
src/.internal/createMathOperation.ts
Normal file
35
src/.internal/createMathOperation.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import baseToNumber from './baseToNumber.js'
|
||||
import baseToString from './baseToString.js'
|
||||
|
||||
/**
|
||||
* Creates a function that performs a mathematical operation on two values.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} operator The function to perform the operation.
|
||||
* @param {number} [defaultValue] The value used for `undefined` arguments.
|
||||
* @returns {Function} Returns the new mathematical operation function.
|
||||
*/
|
||||
function createMathOperation(operator, defaultValue) {
|
||||
return (value, other) => {
|
||||
if (value === undefined && other === undefined) {
|
||||
return defaultValue
|
||||
}
|
||||
if (value !== undefined && other === undefined) {
|
||||
return value
|
||||
}
|
||||
if (other !== undefined && value === undefined) {
|
||||
return other
|
||||
}
|
||||
if (typeof value === 'string' || typeof other === 'string') {
|
||||
value = baseToString(value)
|
||||
other = baseToString(other)
|
||||
}
|
||||
else {
|
||||
value = baseToNumber(value)
|
||||
other = baseToNumber(other)
|
||||
}
|
||||
return operator(value, other)
|
||||
}
|
||||
}
|
||||
|
||||
export default createMathOperation
|
||||
Reference in New Issue
Block a user