diff --git a/types/ecma-proposal-math-extensions/ecma-proposal-math-extensions-tests.ts b/types/ecma-proposal-math-extensions/ecma-proposal-math-extensions-tests.ts new file mode 100644 index 0000000000..3dc5a9d61a --- /dev/null +++ b/types/ecma-proposal-math-extensions/ecma-proposal-math-extensions-tests.ts @@ -0,0 +1,7 @@ +import "ecma-proposal-math-extensions"; + +Math.scale(42, 21, 64, 0, 100); +Math.fscale(0.42, 0.21, 0.64, 0.0, 1.0); +Math.clamp(42, 0, 100); +Math.radians(180) === 180 * Math.DEG_PER_RAD; +Math.degrees(Math.PI) === Math.PI * Math.RAD_PER_DEG; diff --git a/types/ecma-proposal-math-extensions/index.d.ts b/types/ecma-proposal-math-extensions/index.d.ts new file mode 100644 index 0000000000..6412e63dd6 --- /dev/null +++ b/types/ecma-proposal-math-extensions/index.d.ts @@ -0,0 +1,52 @@ +// Type definitions for ecma-proposal-math-extensions 0.0 +// Project: https://github.com/rwaldron/proposal-math-extensions#readme +// Definitions by: Konstantin Simon Maria Möllers +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.0 + +interface Math { + /** This is the number of how many degrees are one radian. */ + readonly DEG_PER_RAD: number; + /** This is the number of how many radians are one degree. */ + readonly RAD_PER_DEG: number; + /** + * Scales a value between `inLow` and `inHigh` to the range of `outLow` to `outHigh`. + * @param x The numeric value in the input range to scale. + * @param inLow The lower bound of the input range. + * @param inHigh The upper bound of the input range. + * @param outLow The lower bound of the output range. + * @param outHigh The upper bound of the output range. + * @return The input value scaled to the output range. + */ + scale(x: number, inLow: number, inHigh: number, outLow: number, outHigh: number): number; + /** + * Scales a floating point value between `inLow` and `inHigh` to the range of `outLow` to `outHigh`. + * @param x The numeric value in the input range to scale. + * @param inLow The lower bound of the input range. + * @param inHigh The upper bound of the input range. + * @param outLow The lower bound of the output range. + * @param outHigh The upper bound of the output range. + * @return The input value scaled to the output range. + */ + fscale(x: number, inLow: number, inHigh: number, outLow: number, outHigh: number): number; + /** + * Clamps an incoming value `x` to a range between `lower` and `upper`. + * @param x The value to clamp. + * @param lower The lower bound of the range to clamp `x` to. + * @param upper The upper bound of the range to clamp `x` to. + * @return The input value clamped to the given range. + */ + clamp(x: number, lower: number, upper: number): number; + /** + * Converts an angle given in degrees to an angle given in radians. + * @param degrees The input angle in degrees. + * @return The output angle in radians. + */ + radians(degrees: number): number; + /** + * Converts an angle given in radians to an angle given in degrees. + * @param radians The input angle in radians. + * @return The output angle in degrees. + */ + degrees(radians: number): number; +} diff --git a/types/ecma-proposal-math-extensions/tsconfig.json b/types/ecma-proposal-math-extensions/tsconfig.json new file mode 100644 index 0000000000..52115765eb --- /dev/null +++ b/types/ecma-proposal-math-extensions/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "target": "es2017", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ecma-proposal-math-extensions-tests.ts" + ] +} diff --git a/types/ecma-proposal-math-extensions/tslint.json b/types/ecma-proposal-math-extensions/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/ecma-proposal-math-extensions/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }