Skip to content

Commit

Permalink
remove if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Picalines committed Sep 5, 2023
1 parent 6c8bea4 commit 042df71
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/command/argument/readers/Number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@ import { parsedRegexReader } from "./Regex.js";
import { argumentReaderTerms as readerTerms } from "./terms/Terms.js";

export const numberReader = (type: 'int' | 'float', range?: [min: number, max: number]): ArgumentReader<number> => {
const parseNumber = type == 'int' ? parseInt : parseFloat;
range ??= [-Infinity, Infinity];

let inRange: (n: number) => boolean;
if (range) {
inRange = n => n >= range![0] && n <= range![1];
}
else {
inRange = () => true;
range = [-Infinity, Infinity];
}
const parseNumber = type == 'int' ? parseInt : parseFloat;
const inRange = (n: number) => n >= range![0] && n <= range![1];

return parsedRegexReader(/[+-]?\d+(\.\d*)?/, (numberInput, context) => {
const number = parseNumber(numberInput);
Expand Down

0 comments on commit 042df71

Please sign in to comment.