@ephykal/operations-utils
Version:
> TODO: description
235 lines • 4.75 kB
JavaScript
// src/operations-utils.ts
var Operations = () => {
function add({ a, b = 1 }) {
return a + b;
}
function subtract({ a, b = 1 }) {
return a - b;
}
function multiply({ a, b = 1 }) {
return a * b;
}
function divide({ a, b = 1 }) {
if (b === 0) {
throw new Error("Division by zero is not allowed");
}
return a / b;
}
function modulus({ a, b = 1 }) {
if (b === 0) {
throw new Error("Division by zero is not allowed");
}
return a % b;
}
function exponentiation({ a, b = 1 }) {
if (b < 0) {
throw new Error("Exponentiation with negative exponent is not allowed");
}
return a ** b;
}
function power({ a, b = 1 }) {
return Math.pow(a, b);
}
function squareRoot({ a }) {
if (a < 0) {
throw new Error("Square root of negative number is not allowed");
}
return Math.sqrt(a);
}
function absoluteValue({ a }) {
return Math.abs(a);
}
function cubeRoot({ a }) {
if (a < 0) throw new Error("Cube root of negative number is not allowed");
return Math.cbrt(a);
}
function round({ a }) {
return Math.round(a);
}
function floor({ a }) {
return Math.floor(a);
}
function ceil({ a }) {
return Math.ceil(a);
}
function truncate({ a }) {
return Math.trunc(a);
}
function sin({ a }) {
return Math.sin(a);
}
function cos({ a }) {
return Math.cos(a);
}
function tan({ a }) {
return Math.tan(a);
}
function asin({ a }) {
if (a < -1 || a > 1) {
throw new Error("Input for asin must be in the range [-1, 1]");
}
return Math.asin(a);
}
function acos({ a }) {
if (a < -1 || a > 1) {
throw new Error("Input for acos must be in the range [-1, 1]");
}
return Math.acos(a);
}
function atan({ a }) {
return Math.atan(a);
}
function atan2({ a, b = 1 }) {
return Math.atan2(a, b);
}
function log({ a, b = 1 }) {
if (a <= 0 || b <= 0) {
throw new Error("Logarithm base and value must be greater than zero");
}
return Math.log(a) / Math.log(b);
}
function log10({ a }) {
if (a <= 0) {
throw new Error("Logarithm base 10 must be greater than zero");
}
return Math.log10(a);
}
function log2({ a }) {
if (a <= 0) {
throw new Error("Logarithm base 2 must be greater than zero");
}
return Math.log2(a);
}
function exp({ a }) {
return Math.exp(a);
}
function factorial({ a }) {
if (a < 0) {
throw new Error("Factorial is not defined for negative numbers");
}
if (a === 0 || a === 1) {
return 1;
}
let result = 1;
for (let i = 2; i <= a; i++) {
result *= i;
}
return result;
}
function min({ a, b = 1 }) {
return Math.min(a, b);
}
function max({ a, b = 1 }) {
return Math.max(a, b);
}
function random({ a, b = 1 }) {
if (a >= b) {
throw new Error("Invalid range for random number generation");
}
return Math.random() * (b - a) + a;
}
function clamp({ a, b = 1 }) {
if (a > b) {
throw new Error("Invalid range for clamping");
}
return Math.max(a, Math.min(b, a));
}
function isEven({ a }) {
return a % 2 === 0;
}
function isOdd({ a }) {
return a % 2 !== 0;
}
function isPrime({ a }) {
if (a <= 1) return false;
for (let i = 2; i <= Math.sqrt(a); i++) {
if (a % i === 0) return false;
}
return true;
}
function pi({ a }) {
return Math.PI;
}
function euler({ a }) {
return Math.E;
}
function ln10({ a }) {
return Math.LN10;
}
function ln2({ a }) {
return Math.LN2;
}
function log10e({ a }) {
return Math.LOG10E;
}
function log2e({ a }) {
return Math.LOG2E;
}
function sqrt1({ a }) {
if (a < 0) {
throw new Error("Square root of negative number is not allowed");
}
return Math.SQRT1_2;
}
function sqrt2({ a }) {
if (a < 0) {
throw new Error("Square root of negative number is not allowed");
}
return Math.SQRT2;
}
function toDegrees({ a }) {
return a * 180 / Math.PI;
}
function toRadians({ a }) {
return a * Math.PI / 180;
}
return {
add,
subtract,
multiply,
divide,
modulus,
exponentiation,
power,
squareRoot,
absoluteValue,
cubeRoot,
round,
floor,
ceil,
truncate,
sin,
cos,
tan,
asin,
acos,
atan,
atan2,
log,
log10,
log2,
exp,
factorial,
min,
max,
random,
clamp,
isEven,
isOdd,
isPrime,
pi,
euler,
ln10,
ln2,
log10e,
log2e,
sqrt1,
sqrt2,
toDegrees,
toRadians
};
};
export {
Operations
};
//# sourceMappingURL=index.mjs.map