From 64208f26fa7260ec9b49715122d94324caeed548 Mon Sep 17 00:00:00 2001 From: "Adam A. Zerella" Date: Fri, 1 Mar 2019 16:10:22 +1100 Subject: [PATCH 1/2] Added file export type defs --- types/mumath/clamp.d.ts | 6 ++++++ types/mumath/closest.d.ts | 6 ++++++ types/mumath/index.d.ts | 1 - types/mumath/isMultiple.d.ts | 7 +++++++ types/mumath/len.d.ts | 6 ++++++ types/mumath/lerp.d.ts | 6 ++++++ types/mumath/mod.d.ts | 6 ++++++ types/mumath/mumath-tests.ts | 23 +++++++++++++++++++++++ types/mumath/order.d.ts | 6 ++++++ types/mumath/precision.d.ts | 6 ++++++ types/mumath/round.d.ts | 6 ++++++ types/mumath/scale.d.ts | 8 ++++++++ types/mumath/tsconfig.json | 11 +++++++++++ types/mumath/within.d.ts | 6 ++++++ 14 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 types/mumath/clamp.d.ts create mode 100644 types/mumath/closest.d.ts create mode 100644 types/mumath/isMultiple.d.ts create mode 100644 types/mumath/len.d.ts create mode 100644 types/mumath/lerp.d.ts create mode 100644 types/mumath/mod.d.ts create mode 100644 types/mumath/order.d.ts create mode 100644 types/mumath/precision.d.ts create mode 100644 types/mumath/round.d.ts create mode 100644 types/mumath/scale.d.ts create mode 100644 types/mumath/within.d.ts diff --git a/types/mumath/clamp.d.ts b/types/mumath/clamp.d.ts new file mode 100644 index 0000000000..fe08302e37 --- /dev/null +++ b/types/mumath/clamp.d.ts @@ -0,0 +1,6 @@ +/** + * Detects proper clamp min/max. + */ +declare function clamp(value: number, left: number, right: number): number; + +export default clamp; diff --git a/types/mumath/closest.d.ts b/types/mumath/closest.d.ts new file mode 100644 index 0000000000..f2db4ea1ec --- /dev/null +++ b/types/mumath/closest.d.ts @@ -0,0 +1,6 @@ +/** + * Get closest value out of a set. + */ +declare function closest(value: number, list: number[]): number; + +export default closest; diff --git a/types/mumath/index.d.ts b/types/mumath/index.d.ts index 8967bafa4f..3dcfccf565 100644 --- a/types/mumath/index.d.ts +++ b/types/mumath/index.d.ts @@ -2,7 +2,6 @@ // Project: https://github.com/dfcreative/mumath // Definitions by: Adam Zerella // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.3 /** * Detects proper clamp min/max. diff --git a/types/mumath/isMultiple.d.ts b/types/mumath/isMultiple.d.ts new file mode 100644 index 0000000000..255d0ece72 --- /dev/null +++ b/types/mumath/isMultiple.d.ts @@ -0,0 +1,7 @@ +/** + * Check if one number is multiple of other + * Same as a % b === 0, but with precision check. + */ +declare function isMultiple(a: number, b: number, eps?: number): boolean; + +export default isMultiple; diff --git a/types/mumath/len.d.ts b/types/mumath/len.d.ts new file mode 100644 index 0000000000..2392cff32f --- /dev/null +++ b/types/mumath/len.d.ts @@ -0,0 +1,6 @@ +/** + * Return quadratic length of a vector. + */ +declare function len(a: number, b: number): number; + +export default len; diff --git a/types/mumath/lerp.d.ts b/types/mumath/lerp.d.ts new file mode 100644 index 0000000000..3ab8639c0c --- /dev/null +++ b/types/mumath/lerp.d.ts @@ -0,0 +1,6 @@ +/** + * Return value interpolated between x and y. + */ +declare function lerp(x: number, y: number, ratio: number): number; + +export default lerp; diff --git a/types/mumath/mod.d.ts b/types/mumath/mod.d.ts new file mode 100644 index 0000000000..6517271e45 --- /dev/null +++ b/types/mumath/mod.d.ts @@ -0,0 +1,6 @@ +/** + * An enhanced mod-loop, like fmod — loops value within a frame. + */ +declare function mod(value: number, max: number, min?: number): number; + +export default mod; diff --git a/types/mumath/mumath-tests.ts b/types/mumath/mumath-tests.ts index c0fed04336..5a8fd6476f 100644 --- a/types/mumath/mumath-tests.ts +++ b/types/mumath/mumath-tests.ts @@ -1,25 +1,48 @@ import * as mumath from "mumath"; +import mumathClamp from "mumath/clamp"; +import mumathClosest from "mumath/closest"; +import mumathIsMultiple from "mumath/isMultiple"; +import mumathLen from "mumath/len"; +import mumathLerp from "mumath/lerp"; +import mumathMod from "mumath/mod"; +import mumathOrder from "mumath/order"; +import mumathPrecision from "mumath/precision"; +import mumathRound from "mumath/round"; +import mumathScale from "mumath/scale"; +import mumathWithin from "mumath/within"; + mumath.clamp(1, 2, 3); +mumathClamp(1, 2, 3); mumath.closest(5, [1, 7, 3, 6, 10]); +mumathClosest(5, [1, 7, 3, 6, 10]); mumath.isMultiple(5, 10, 1.000074); mumath.isMultiple(5, 10); +mumathIsMultiple(5, 10, 1.000074); mumath.len(15, 1.0); +mumathLen(15, 1.0); mumath.lerp(1, 2, 3); +mumathLerp(1, 2, 3); mumath.mod(1, 2, 3); mumath.mod(1, 2); +mumathMod(1, 2, 3); mumath.order(5); +mumathOrder(5); mumath.precision(5.0000001); +mumathPrecision(5.0000001); mumath.round(0.3, 0.5); +mumathRound(0.3, 0.5); mumath.scale(5.93, [1.0, 35, 10, 7.135]); +mumathScale(5.93, [1.0, 35, 10, 7.135]); mumath.within(5, 1, 10); +mumathWithin(5, 1, 10); diff --git a/types/mumath/order.d.ts b/types/mumath/order.d.ts new file mode 100644 index 0000000000..6da624f1d3 --- /dev/null +++ b/types/mumath/order.d.ts @@ -0,0 +1,6 @@ +/** + * Get order of magnitude for a number. + */ +declare function order(value: number): number; + +export default order; diff --git a/types/mumath/precision.d.ts b/types/mumath/precision.d.ts new file mode 100644 index 0000000000..ec94b3a4ed --- /dev/null +++ b/types/mumath/precision.d.ts @@ -0,0 +1,6 @@ +/** + * Get precision from float: + */ +declare function precision(value: number): number; + +export default precision; diff --git a/types/mumath/round.d.ts b/types/mumath/round.d.ts new file mode 100644 index 0000000000..09549f14f1 --- /dev/null +++ b/types/mumath/round.d.ts @@ -0,0 +1,6 @@ +/** + * Rounds value to optional step. + */ +declare function round(value: number, step?: number): number; + +export default round; diff --git a/types/mumath/scale.d.ts b/types/mumath/scale.d.ts new file mode 100644 index 0000000000..2d5487ea10 --- /dev/null +++ b/types/mumath/scale.d.ts @@ -0,0 +1,8 @@ +/** + * Get first scale out of a list of basic scales, aligned to the power. E. g. + * step(.37, [1, 2, 5]) → .5 step(456, [1, 2]) → 1000 + * Similar to closest, but takes all possible powers of scales. + */ +declare function scale(value: number, list: number[]): number; + +export default scale; diff --git a/types/mumath/tsconfig.json b/types/mumath/tsconfig.json index 67aa9c2b29..e96b912780 100644 --- a/types/mumath/tsconfig.json +++ b/types/mumath/tsconfig.json @@ -20,6 +20,17 @@ }, "files": [ "index.d.ts", + "clamp.d.ts", + "closest.d.ts", + "isMultiple.d.ts", + "len.d.ts", + "lerp.d.ts", + "mod.d.ts", + "order.d.ts", + "precision.d.ts", + "round.d.ts", + "scale.d.ts", + "within.d.ts", "mumath-tests.ts" ] } diff --git a/types/mumath/within.d.ts b/types/mumath/within.d.ts new file mode 100644 index 0000000000..47558c73d0 --- /dev/null +++ b/types/mumath/within.d.ts @@ -0,0 +1,6 @@ +/** + * Whether element is between left & right, including. + */ +declare function within(value: number, left: number, right: number): number; + +export default within; From 5887c8669381c6c8d8ead32c72d23d147a1b8a10 Mon Sep 17 00:00:00 2001 From: "Adam A. Zerella" Date: Tue, 5 Mar 2019 14:19:18 +1100 Subject: [PATCH 2/2] Updated function default export to function --- types/mumath/clamp.d.ts | 2 +- types/mumath/closest.d.ts | 2 +- types/mumath/index.d.ts | 68 +++++++----------------------------- types/mumath/isMultiple.d.ts | 2 +- types/mumath/len.d.ts | 2 +- types/mumath/lerp.d.ts | 2 +- types/mumath/mod.d.ts | 2 +- types/mumath/mumath-tests.ts | 24 ++++++------- types/mumath/order.d.ts | 2 +- types/mumath/precision.d.ts | 2 +- types/mumath/round.d.ts | 2 +- types/mumath/scale.d.ts | 2 +- types/mumath/within.d.ts | 2 +- 13 files changed, 35 insertions(+), 79 deletions(-) diff --git a/types/mumath/clamp.d.ts b/types/mumath/clamp.d.ts index fe08302e37..9d674a9620 100644 --- a/types/mumath/clamp.d.ts +++ b/types/mumath/clamp.d.ts @@ -3,4 +3,4 @@ */ declare function clamp(value: number, left: number, right: number): number; -export default clamp; +export = clamp; diff --git a/types/mumath/closest.d.ts b/types/mumath/closest.d.ts index f2db4ea1ec..762bcb6548 100644 --- a/types/mumath/closest.d.ts +++ b/types/mumath/closest.d.ts @@ -3,4 +3,4 @@ */ declare function closest(value: number, list: number[]): number; -export default closest; +export = closest; diff --git a/types/mumath/index.d.ts b/types/mumath/index.d.ts index 3dcfccf565..ee0f0ff6c6 100644 --- a/types/mumath/index.d.ts +++ b/types/mumath/index.d.ts @@ -3,60 +3,16 @@ // Definitions by: Adam Zerella // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/** - * Detects proper clamp min/max. - */ -export function clamp(value: number, left: number, right: number): number; +import clamp = require('./clamp'); +import closest = require('./closest'); +import isMultiple = require('./isMultiple'); +import len = require('./len'); +import lerp = require('./lerp'); +import mod = require('./mod'); +import order = require('./order'); +import precision = require('./precision'); +import round = require('./round'); +import scale = require('./scale'); +import within = require('./within'); -/** - * Get closest value out of a set. - */ -export function closest(value: number, list: number[]): number; - -/** - * Check if one number is multiple of other - * Same as a % b === 0, but with precision check. - */ -export function isMultiple(a: number, b: number, eps?: number): boolean; - -/** - * Return quadratic length of a vector. - */ -export function len(a: number, b: number): number; - -/** - * Return value interpolated between x and y. - */ -export function lerp(x: number, y: number, ratio: number): number; - -/** - * An enhanced mod-loop, like fmod — loops value within a frame. - */ -export function mod(value: number, max: number, min?: number): number; - -/** - * Get order of magnitude for a number. - */ -export function order(value: number): number; - -/** - * Get precision from float: - */ -export function precision(value: number): number; - -/** - * Rounds value to optional step. - */ -export function round(value: number, step?: number): number; - -/** - * Get first scale out of a list of basic scales, aligned to the power. E. g. - * step(.37, [1, 2, 5]) → .5 step(456, [1, 2]) → 1000 - * Similar to closest, but takes all possible powers of scales. - */ -export function scale(value: number, list: number[]): number; - -/** - * Whether element is between left & right, including. - */ -export function within(value: number, left: number, right: number): number; +export { clamp, closest, isMultiple, len, lerp, mod, order, precision, round, scale, within }; diff --git a/types/mumath/isMultiple.d.ts b/types/mumath/isMultiple.d.ts index 255d0ece72..31c7a09b08 100644 --- a/types/mumath/isMultiple.d.ts +++ b/types/mumath/isMultiple.d.ts @@ -4,4 +4,4 @@ */ declare function isMultiple(a: number, b: number, eps?: number): boolean; -export default isMultiple; +export = isMultiple; diff --git a/types/mumath/len.d.ts b/types/mumath/len.d.ts index 2392cff32f..b2fae8a8e5 100644 --- a/types/mumath/len.d.ts +++ b/types/mumath/len.d.ts @@ -3,4 +3,4 @@ */ declare function len(a: number, b: number): number; -export default len; +export = len; diff --git a/types/mumath/lerp.d.ts b/types/mumath/lerp.d.ts index 3ab8639c0c..5e09370be2 100644 --- a/types/mumath/lerp.d.ts +++ b/types/mumath/lerp.d.ts @@ -3,4 +3,4 @@ */ declare function lerp(x: number, y: number, ratio: number): number; -export default lerp; +export = lerp; diff --git a/types/mumath/mod.d.ts b/types/mumath/mod.d.ts index 6517271e45..ac1784fe06 100644 --- a/types/mumath/mod.d.ts +++ b/types/mumath/mod.d.ts @@ -3,4 +3,4 @@ */ declare function mod(value: number, max: number, min?: number): number; -export default mod; +export = mod; diff --git a/types/mumath/mumath-tests.ts b/types/mumath/mumath-tests.ts index 5a8fd6476f..a5b339b2fe 100644 --- a/types/mumath/mumath-tests.ts +++ b/types/mumath/mumath-tests.ts @@ -1,16 +1,16 @@ -import * as mumath from "mumath"; +import mumath = require("mumath"); -import mumathClamp from "mumath/clamp"; -import mumathClosest from "mumath/closest"; -import mumathIsMultiple from "mumath/isMultiple"; -import mumathLen from "mumath/len"; -import mumathLerp from "mumath/lerp"; -import mumathMod from "mumath/mod"; -import mumathOrder from "mumath/order"; -import mumathPrecision from "mumath/precision"; -import mumathRound from "mumath/round"; -import mumathScale from "mumath/scale"; -import mumathWithin from "mumath/within"; +import mumathClamp = require("mumath/clamp"); +import mumathClosest = require("mumath/closest"); +import mumathIsMultiple = require("mumath/isMultiple"); +import mumathLen = require("mumath/len"); +import mumathLerp = require("mumath/lerp"); +import mumathMod = require("mumath/mod"); +import mumathOrder = require("mumath/order"); +import mumathPrecision = require("mumath/precision"); +import mumathRound = require("mumath/round"); +import mumathScale = require("mumath/scale"); +import mumathWithin = require("mumath/within"); mumath.clamp(1, 2, 3); mumathClamp(1, 2, 3); diff --git a/types/mumath/order.d.ts b/types/mumath/order.d.ts index 6da624f1d3..8ce4c396fa 100644 --- a/types/mumath/order.d.ts +++ b/types/mumath/order.d.ts @@ -3,4 +3,4 @@ */ declare function order(value: number): number; -export default order; +export = order; diff --git a/types/mumath/precision.d.ts b/types/mumath/precision.d.ts index ec94b3a4ed..1b1a7290cc 100644 --- a/types/mumath/precision.d.ts +++ b/types/mumath/precision.d.ts @@ -3,4 +3,4 @@ */ declare function precision(value: number): number; -export default precision; +export = precision; diff --git a/types/mumath/round.d.ts b/types/mumath/round.d.ts index 09549f14f1..8966dc6068 100644 --- a/types/mumath/round.d.ts +++ b/types/mumath/round.d.ts @@ -3,4 +3,4 @@ */ declare function round(value: number, step?: number): number; -export default round; +export = round; diff --git a/types/mumath/scale.d.ts b/types/mumath/scale.d.ts index 2d5487ea10..2cb97bcb4f 100644 --- a/types/mumath/scale.d.ts +++ b/types/mumath/scale.d.ts @@ -5,4 +5,4 @@ */ declare function scale(value: number, list: number[]): number; -export default scale; +export = scale; diff --git a/types/mumath/within.d.ts b/types/mumath/within.d.ts index 47558c73d0..f1d7e56cbd 100644 --- a/types/mumath/within.d.ts +++ b/types/mumath/within.d.ts @@ -3,4 +3,4 @@ */ declare function within(value: number, left: number, right: number): number; -export default within; +export = within;