UNPKG

@ephykal/operations-utils

Version:
1 lines 13.2 kB
{"version":3,"sources":["../src/operations-utils.ts"],"sourcesContent":["import { OperationsUtilsProps } from \"./index\";\n\nexport const Operations = (): {\n add: (props: OperationsUtilsProps) => number;\n subtract: (props: OperationsUtilsProps) => number;\n multiply: (props: OperationsUtilsProps) => number;\n divide: (props: OperationsUtilsProps) => number;\n modulus: (props: OperationsUtilsProps) => number;\n exponentiation: (props: OperationsUtilsProps) => number;\n power: (props: OperationsUtilsProps) => number;\n squareRoot: (props: OperationsUtilsProps) => number;\n absoluteValue: (props: OperationsUtilsProps) => number;\n cubeRoot: (props: OperationsUtilsProps) => number;\n round: (props: OperationsUtilsProps) => number;\n floor: (props: OperationsUtilsProps) => number;\n ceil: (props: OperationsUtilsProps) => number;\n truncate: (props: OperationsUtilsProps) => number;\n sin: (props: OperationsUtilsProps) => number;\n cos: (props: OperationsUtilsProps) => number;\n tan: (props: OperationsUtilsProps) => number;\n asin: (props: OperationsUtilsProps) => number;\n acos: (props: OperationsUtilsProps) => number;\n atan: (props: OperationsUtilsProps) => number;\n atan2: (props: OperationsUtilsProps) => number;\n log: (props: OperationsUtilsProps) => number;\n log10: (props: OperationsUtilsProps) => number;\n log2: (props: OperationsUtilsProps) => number;\n exp: (props: OperationsUtilsProps) => number;\n factorial: (props: OperationsUtilsProps) => number;\n min: (props: OperationsUtilsProps) => number;\n max: (props: OperationsUtilsProps) => number;\n random: (props: OperationsUtilsProps) => number;\n clamp: (props: OperationsUtilsProps) => number;\n isEven: (props: OperationsUtilsProps) => boolean;\n isOdd: (props: OperationsUtilsProps) => boolean;\n isPrime: (props: OperationsUtilsProps) => boolean;\n pi: (props: OperationsUtilsProps) => number;\n euler: (props: OperationsUtilsProps) => number;\n ln10: (props: OperationsUtilsProps) => number;\n ln2: (props: OperationsUtilsProps) => number;\n log10e: (props: OperationsUtilsProps) => number;\n log2e: (props: OperationsUtilsProps) => number;\n sqrt1: (props: OperationsUtilsProps) => number;\n sqrt2: (props: OperationsUtilsProps) => number;\n toDegrees: (props: OperationsUtilsProps) => number;\n toRadians: (props: OperationsUtilsProps) => number;\n} => {\n function add({ a, b = 1 }: OperationsUtilsProps): number {\n return a + b;\n }\n\n function subtract({ a, b = 1 }: OperationsUtilsProps): number {\n return a - b;\n }\n\n function multiply({ a, b = 1 }: OperationsUtilsProps): number {\n return a * b;\n }\n\n function divide({ a, b = 1 }: OperationsUtilsProps): number {\n if (b === 0) {\n throw new Error(\"Division by zero is not allowed\");\n }\n return a / b;\n }\n function modulus({ a, b = 1 }: OperationsUtilsProps): number {\n if (b === 0) {\n throw new Error(\"Division by zero is not allowed\");\n }\n return a % b;\n }\n function exponentiation({ a, b = 1 }: OperationsUtilsProps): number {\n if (b < 0) {\n throw new Error(\"Exponentiation with negative exponent is not allowed\");\n }\n return a ** b;\n }\n function power({ a, b = 1 }: OperationsUtilsProps): number {\n return Math.pow(a, b);\n }\n function squareRoot({ a }: OperationsUtilsProps): number {\n if (a < 0) {\n throw new Error(\"Square root of negative number is not allowed\");\n }\n return Math.sqrt(a);\n }\n function absoluteValue({ a }: OperationsUtilsProps): number {\n return Math.abs(a);\n }\n\n function cubeRoot({ a }: OperationsUtilsProps): number {\n if (a < 0) throw new Error(\"Cube root of negative number is not allowed\");\n\n return Math.cbrt(a);\n }\n\n function round({ a }: OperationsUtilsProps): number {\n return Math.round(a);\n }\n\n function floor({ a }: OperationsUtilsProps): number {\n return Math.floor(a);\n }\n function ceil({ a }: OperationsUtilsProps): number {\n return Math.ceil(a);\n }\n function truncate({ a }: OperationsUtilsProps): number {\n return Math.trunc(a);\n }\n\n function sin({ a }: OperationsUtilsProps): number {\n return Math.sin(a);\n }\n function cos({ a }: OperationsUtilsProps): number {\n return Math.cos(a);\n }\n function tan({ a }: OperationsUtilsProps): number {\n return Math.tan(a);\n }\n function asin({ a }: OperationsUtilsProps): number {\n if (a < -1 || a > 1) {\n throw new Error(\"Input for asin must be in the range [-1, 1]\");\n }\n return Math.asin(a);\n }\n function acos({ a }: OperationsUtilsProps): number {\n if (a < -1 || a > 1) {\n throw new Error(\"Input for acos must be in the range [-1, 1]\");\n }\n return Math.acos(a);\n }\n function atan({ a }: OperationsUtilsProps): number {\n return Math.atan(a);\n }\n function atan2({ a, b = 1 }: OperationsUtilsProps): number {\n return Math.atan2(a, b);\n }\n function log({ a, b = 1 }: OperationsUtilsProps): number {\n if (a <= 0 || b <= 0) {\n throw new Error(\"Logarithm base and value must be greater than zero\");\n }\n return Math.log(a) / Math.log(b);\n }\n function log10({ a }: OperationsUtilsProps): number {\n if (a <= 0) {\n throw new Error(\"Logarithm base 10 must be greater than zero\");\n }\n return Math.log10(a);\n }\n function log2({ a }: OperationsUtilsProps): number {\n if (a <= 0) {\n throw new Error(\"Logarithm base 2 must be greater than zero\");\n }\n return Math.log2(a);\n }\n function exp({ a }: OperationsUtilsProps): number {\n return Math.exp(a);\n }\n function factorial({ a }: OperationsUtilsProps): number {\n if (a < 0) {\n throw new Error(\"Factorial is not defined for negative numbers\");\n }\n if (a === 0 || a === 1) {\n return 1;\n }\n let result = 1;\n for (let i = 2; i <= a; i++) {\n result *= i;\n }\n return result;\n }\n\n function min({ a, b = 1 }: OperationsUtilsProps): number {\n return Math.min(a, b);\n }\n\n function max({ a, b = 1 }: OperationsUtilsProps): number {\n return Math.max(a, b);\n }\n\n function random({ a, b = 1 }: OperationsUtilsProps): number {\n if (a >= b) {\n throw new Error(\"Invalid range for random number generation\");\n }\n return Math.random() * (b - a) + a;\n }\n function clamp({ a, b = 1 }: OperationsUtilsProps): number {\n if (a > b) {\n throw new Error(\"Invalid range for clamping\");\n }\n return Math.max(a, Math.min(b, a));\n }\n function isEven({ a }: OperationsUtilsProps): boolean {\n return a % 2 === 0;\n }\n function isOdd({ a }: OperationsUtilsProps): boolean {\n return a % 2 !== 0;\n }\n function isPrime({ a }: OperationsUtilsProps): boolean {\n if (a <= 1) return false;\n for (let i = 2; i <= Math.sqrt(a); i++) {\n if (a % i === 0) return false;\n }\n return true;\n }\n function pi({ a }: OperationsUtilsProps): number {\n return Math.PI;\n }\n function euler({ a }: OperationsUtilsProps): number {\n return Math.E;\n }\n function ln10({ a }: OperationsUtilsProps): number {\n return Math.LN10;\n }\n function ln2({ a }: OperationsUtilsProps) {\n return Math.LN2;\n }\n function log10e({ a }: OperationsUtilsProps): number {\n return Math.LOG10E;\n }\n function log2e({ a }: OperationsUtilsProps): number {\n return Math.LOG2E;\n }\n\n function sqrt1({ a }: OperationsUtilsProps): number {\n if (a < 0) {\n throw new Error(\"Square root of negative number is not allowed\");\n }\n return Math.SQRT1_2;\n }\n function sqrt2({ a }: OperationsUtilsProps): number {\n if (a < 0) {\n throw new Error(\"Square root of negative number is not allowed\");\n }\n return Math.SQRT2;\n }\n function toDegrees({ a }: OperationsUtilsProps): number {\n return (a * 180) / Math.PI;\n }\n function toRadians({ a }: OperationsUtilsProps): number {\n return (a * Math.PI) / 180;\n }\n\n return {\n add,\n subtract,\n multiply,\n divide,\n modulus,\n exponentiation,\n power,\n squareRoot,\n absoluteValue,\n cubeRoot,\n round,\n floor,\n ceil,\n truncate,\n sin,\n cos,\n tan,\n asin,\n acos,\n atan,\n atan2,\n log,\n log10,\n log2,\n exp,\n factorial,\n min,\n max,\n random,\n clamp,\n isEven,\n isOdd,\n isPrime,\n pi,\n euler,\n ln10,\n ln2,\n log10e,\n log2e,\n sqrt1,\n sqrt2,\n toDegrees,\n toRadians,\n };\n};\n"],"mappings":";AAEO,IAAM,aAAa,MA4CrB;AACH,WAAS,IAAI,EAAE,GAAG,IAAI,EAAE,GAAiC;AACvD,WAAO,IAAI;AAAA,EACb;AAEA,WAAS,SAAS,EAAE,GAAG,IAAI,EAAE,GAAiC;AAC5D,WAAO,IAAI;AAAA,EACb;AAEA,WAAS,SAAS,EAAE,GAAG,IAAI,EAAE,GAAiC;AAC5D,WAAO,IAAI;AAAA,EACb;AAEA,WAAS,OAAO,EAAE,GAAG,IAAI,EAAE,GAAiC;AAC1D,QAAI,MAAM,GAAG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