@azizbecha/strkit
Version:
strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.
30 lines • 1.15 kB
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = toRadians;
/**
* Converts degrees to radians.
* Accepts both numbers and numeric strings.
* @param degrees - The angle in degrees (number or numeric string).
* @returns The angle in radians.
* @throws Error if the input is not a valid number.
* @example
* toRadians(180); // Output: 3.14159...
*/
function toRadians(degrees) {
const parsedDegrees = typeof degrees === 'string' ? parseFloat(degrees) : degrees;
if (isNaN(parsedDegrees)) {
throw new Error('Invalid input: degrees must be a number or a numeric string.');
}
return parsedDegrees * (Math.PI / 180);
}
});
//# sourceMappingURL=toRadians.js.map