-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb4eb56
commit d1c1322
Showing
27 changed files
with
847 additions
and
119 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true | ||
} | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
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,27 @@ | ||
import { freeze } from '../util/object-utils.js' | ||
import { OperationNode } from './operation-node.js' | ||
|
||
export type TopModifier = 'percent' | 'with ties' | 'percent with ties' | ||
|
||
export interface TopNode extends OperationNode { | ||
readonly kind: 'TopNode' | ||
readonly expression: number | bigint | ||
readonly modifiers?: TopModifier | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const TopNode = freeze({ | ||
is(node: OperationNode): node is TopNode { | ||
return node.kind === 'TopNode' | ||
}, | ||
|
||
create(expression: number | bigint, modifiers?: TopModifier): TopNode { | ||
return freeze({ | ||
kind: 'TopNode', | ||
expression, | ||
modifiers, | ||
}) | ||
}, | ||
}) |
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,25 @@ | ||
import { TopModifier, TopNode } from '../operation-node/top-node.js' | ||
import { isBigInt, isNumber, isUndefined } from '../util/object-utils.js' | ||
|
||
export function parseTop( | ||
expression: number | bigint, | ||
modifiers?: TopModifier, | ||
): TopNode { | ||
if (!isNumber(expression) && !isBigInt(expression)) { | ||
throw new Error(`Invalid top expression: ${expression}`) | ||
} | ||
|
||
if (!isUndefined(modifiers) && !isTopModifiers(modifiers)) { | ||
throw new Error(`Invalid top modifiers: ${modifiers}`) | ||
} | ||
|
||
return TopNode.create(expression, modifiers) | ||
} | ||
|
||
function isTopModifiers(modifiers: string): modifiers is TopModifier { | ||
return ( | ||
modifiers === 'percent' || | ||
modifiers === 'with ties' || | ||
modifiers === 'percent with ties' | ||
) | ||
} |
Oops, something went wrong.