extra-utils 5.9.0 → 5.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -75,7 +75,18 @@ function isntBigInt<T>(val: T): val is Exclude<T, bigint>
75
75
 
76
76
  function clamp(
77
77
  val: number
78
- , [min, max]: [min: number, max: number]
78
+ , [min, max]: readonly [min: number, max: number]
79
+ ): number
80
+
81
+ function remap(
82
+ value: number
83
+ , [oldMin, oldMax]: readonly [oldMin: number, oldMax: number]
84
+ , [newMin, newMax]: readonly [newMin: number, newMax: number]
85
+ ): number
86
+
87
+ function lerp(
88
+ alpha: number
89
+ , [from, to]: readonly [from: number, to: number]
79
90
  ): number
80
91
  ```
81
92
 
@@ -1 +1 @@
1
- export declare function clamp(val: number, [min, max]: [min: number, max: number]): number;
1
+ export declare function clamp(val: number, [min, max]: readonly [min: number, max: number]): number;
@@ -1 +1 @@
1
- {"version":3,"file":"clamp.js","sourceRoot":"","sources":["../../src/number/clamp.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CACnB,GAAW,EACX,CAAC,GAAG,EAAE,GAAG,CAA6B;IAEtC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;AAC1C,CAAC"}
1
+ {"version":3,"file":"clamp.js","sourceRoot":"","sources":["../../src/number/clamp.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CACnB,GAAW,EACX,CAAC,GAAG,EAAE,GAAG,CAAsC;IAE/C,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;AAC1C,CAAC"}
@@ -4,3 +4,5 @@ export * from './is-infinity.js';
4
4
  export * from './is-nan.js';
5
5
  export * from './is-number.js';
6
6
  export * from './clamp.js';
7
+ export * from './remap.js';
8
+ export * from './lerp.js';
@@ -4,4 +4,6 @@ export * from './is-infinity.js';
4
4
  export * from './is-nan.js';
5
5
  export * from './is-number.js';
6
6
  export * from './clamp.js';
7
+ export * from './remap.js';
8
+ export * from './lerp.js';
7
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/number/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/number/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA"}
@@ -0,0 +1 @@
1
+ export declare function lerp(alpha: number, [from, to]: readonly [from: number, to: number]): number;
@@ -0,0 +1,4 @@
1
+ export function lerp(alpha, [from, to]) {
2
+ return from + (to - from) * alpha;
3
+ }
4
+ //# sourceMappingURL=lerp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lerp.js","sourceRoot":"","sources":["../../src/number/lerp.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,IAAI,CAClB,KAAa,EACb,CAAC,IAAI,EAAE,EAAE,CAAsC;IAE/C,OAAO,IAAI,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,KAAK,CAAA;AACnC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function remap(value: number, [oldMin, oldMax]: readonly [oldMin: number, oldMax: number], [newMin, newMax]: readonly [newMin: number, newMax: number]): number;
@@ -0,0 +1,6 @@
1
+ export function remap(value, [oldMin, oldMax], [newMin, newMax]) {
2
+ return (value - oldMin) / (oldMax - oldMin)
3
+ * (newMax - newMin)
4
+ + newMin;
5
+ }
6
+ //# sourceMappingURL=remap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remap.js","sourceRoot":"","sources":["../../src/number/remap.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CACnB,KAAa,EACb,CAAC,MAAM,EAAE,MAAM,CAA4C,EAC3D,CAAC,MAAM,EAAE,MAAM,CAA4C;IAE3D,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;UACpC,CAAC,MAAM,GAAG,MAAM,CAAC;UACjB,MAAM,CAAA;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "extra-utils",
3
- "version": "5.9.0",
3
+ "version": "5.11.0",
4
4
  "description": "Utilities for JavaScript and Typescript",
5
5
  "files": [
6
6
  "src",
@@ -1,6 +1,6 @@
1
1
  export function clamp(
2
2
  val: number
3
- , [min, max]: [min: number, max: number]
3
+ , [min, max]: readonly [min: number, max: number]
4
4
  ): number {
5
5
  return Math.max(min, Math.min(val, max))
6
6
  }
@@ -4,3 +4,5 @@ export * from './is-infinity.js'
4
4
  export * from './is-nan.js'
5
5
  export * from './is-number.js'
6
6
  export * from './clamp.js'
7
+ export * from './remap.js'
8
+ export * from './lerp.js'
@@ -0,0 +1,6 @@
1
+ export function lerp(
2
+ alpha: number
3
+ , [from, to]: readonly [from: number, to: number]
4
+ ): number {
5
+ return from + (to - from) * alpha
6
+ }
@@ -0,0 +1,9 @@
1
+ export function remap(
2
+ value: number
3
+ , [oldMin, oldMax]: readonly [oldMin: number, oldMax: number]
4
+ , [newMin, newMax]: readonly [newMin: number, newMax: number]
5
+ ): number {
6
+ return (value - oldMin) / (oldMax - oldMin)
7
+ * (newMax - newMin)
8
+ + newMin
9
+ }