-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Upgrade to TypeScript 3.5 * Refactor exponent handling and fix tests * Update docs
- Loading branch information
Showing
29 changed files
with
305 additions
and
216 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { genFileHeader, getExponents, ICommonSpec } from "./common"; | ||
|
||
export function genExponentType(spec: ICommonSpec): string { | ||
const exponents = getExponents(spec).join(" | "); | ||
const exponents = getExponents(spec) | ||
.map(exponent => exponent.type) | ||
.join(" | "); | ||
return [...genFileHeader(false), `export type Exponent = ${exponents};`, ""].join("\n"); | ||
} |
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
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
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
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,20 @@ | ||
import { Exponent } from "./generated/exponent"; | ||
|
||
export function getExponentValue(value: Exponent): number { | ||
return parseInt(value, 10); | ||
} | ||
|
||
export const negateExponent = (value: Exponent) => toExponent(-getExponentValue(value)); | ||
export const addExponents = wrapBinaryExponentFn((left, right) => left + right); | ||
export const multiplyExponents = wrapBinaryExponentFn((left, right) => left * right); | ||
export const divideExponents = wrapBinaryExponentFn((left, right) => left / right); | ||
|
||
type BinaryExponentFn = (left: Exponent, right: Exponent) => Exponent; | ||
|
||
function wrapBinaryExponentFn(fn: (left: number, right: number) => number): BinaryExponentFn { | ||
return (left, right) => toExponent(fn(getExponentValue(left), getExponentValue(right))); | ||
} | ||
|
||
function toExponent(value: number): Exponent { | ||
return `${value}` as Exponent; | ||
} |
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
Oops, something went wrong.