es-toolkit
Version:
A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
23 lines (20 loc) • 573 B
JavaScript
import { toNumber } from '../util/toNumber.mjs';
import { toString } from '../util/toString.mjs';
function multiply(value, other) {
if (value === undefined && other === undefined) {
return 1;
}
if (value === undefined || other === undefined) {
return value ?? other;
}
if (typeof value === 'string' || typeof other === 'string') {
value = toString(value);
other = toString(other);
}
else {
value = toNumber(value);
other = toNumber(other);
}
return value * other;
}
export { multiply };