mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 10:01:39 -05:00
26 lines
577 B
TypeScript
26 lines
577 B
TypeScript
import { Type } from "./Type"
|
|
|
|
export class NumberType implements Type {
|
|
public static instance = new NumberType()
|
|
public kind = "number"
|
|
|
|
public toConstructor() {
|
|
return "NumberType.instance"
|
|
}
|
|
|
|
public toString() {
|
|
return this.kind
|
|
}
|
|
|
|
public convert(argument) {
|
|
let n = parseInt(argument, 10)
|
|
if (!Number.isNaN(n)) {
|
|
return n
|
|
}
|
|
n = parseFloat(argument)
|
|
if (!Number.isNaN(n)) {
|
|
return n
|
|
}
|
|
throw new Error(`Can't convert to number: ${argument}`)
|
|
}
|
|
}
|