-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* renamed "create" method to "compile" * declared "create" as alias for "compile" method * added "clamp" as alias for "limit" method
- Loading branch information
1 parent
15fb8fe
commit 364987b
Showing
13 changed files
with
75 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { compile, create, wrap, limit, clamp } from '../src' | ||
|
||
describe('alias', () => { | ||
|
||
test('should export compile alias', () => { | ||
expect(create).toBe(compile) | ||
expect(wrap).toBe(compile) | ||
}) | ||
|
||
test('should export limit alias', () => { | ||
expect(clamp).toBe(limit) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import map from './map' | ||
import { MapNumberFunction } from './types' | ||
|
||
function ceil(num: number, inMin: number, inMax: number, outMin: number, outMax: number): number { | ||
return Math.ceil( | ||
map(num, inMin, inMax, outMin, outMax), | ||
) | ||
} | ||
|
||
export default ceil | ||
export default ceil as MapNumberFunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { CompiledMapNumberFunction, MapNumberFunction } from './types' | ||
|
||
function compile(func: MapNumberFunction, inMin: number, inMax: number, outMin: number, outMax: number): CompiledMapNumberFunction { | ||
return (num: number): number => func(num, inMin, inMax, outMin, outMax) | ||
} | ||
|
||
export default compile |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import map from './map' | ||
import { MapNumberFunction } from './types' | ||
|
||
function floor(num: number, inMin: number, inMax: number, outMin: number, outMax: number): number { | ||
return Math.floor( | ||
map(num, inMin, inMax, outMin, outMax), | ||
) | ||
} | ||
|
||
export default floor | ||
export default floor as MapNumberFunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,15 @@ | ||
import map from './map' | ||
import { max, min } from './math' | ||
import { MapNumberFunction } from './types' | ||
|
||
function limit(num: number, inMin: number, inMax: number, outMin: number, outMax: number): number { | ||
return max( | ||
min(outMin, outMax), | ||
min( | ||
outMin, | ||
outMax, | ||
), | ||
min( | ||
max( | ||
outMin, | ||
outMax, | ||
), | ||
max(outMin, outMax), | ||
map(num, inMin, inMax, outMin, outMax), | ||
), | ||
) | ||
} | ||
|
||
export default limit | ||
export default limit as MapNumberFunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { MapNumberFunction } from './types' | ||
|
||
function map(num: number, inMin: number, inMax: number, outMin: number, outMax: number): number { | ||
return (num - inMin) * (outMax - outMin) / (inMax - inMin) + outMin | ||
} | ||
|
||
export default map | ||
export default map as MapNumberFunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import map from './map' | ||
import { MapNumberFunction } from './types' | ||
|
||
function round(num: number, inMin: number, inMax: number, outMin: number, outMax: number): number { | ||
return Math.round( | ||
map(num, inMin, inMax, outMin, outMax), | ||
) | ||
} | ||
|
||
export default round | ||
export default round as MapNumberFunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export type MapNumberFunction = (num: number, inMin: number, inMax: number, outMin: number, outMax: number) => number; | ||
export type CompiledMapNumberFunction = (num: number) => number; |