Skip to content

Instantly share code, notes, and snippets.

@thenamankumar
Last active July 22, 2020 16:18
Show Gist options
  • Save thenamankumar/a266faab167f29320438204515864a71 to your computer and use it in GitHub Desktop.
Save thenamankumar/a266faab167f29320438204515864a71 to your computer and use it in GitHub Desktop.
const Rules: RulesType = require('./rules.json');
export type RuleName = string;
interface BaseRule {
butNot?: RuleDefinition;
optional?: boolean;
}
export interface OfValueRule extends BaseRule {
ofValue: string;
}
export interface OfPatternRule extends BaseRule {
ofPattern: string;
}
export interface PunctuatorRule extends BaseRule {
punctuator: string;
}
export interface KeywordRule extends BaseRule {
keyword: string;
}
export interface OneOfRule extends BaseRule {
oneOf: string[];
}
export interface OfTypeRule extends BaseRule {
ofType: RuleDefinition;
}
export interface OneOfTypeRule extends BaseRule {
oneOfType: [RuleDefinition];
}
export interface ListOfTypeRule extends BaseRule {
listOfType: RuleDefinition;
}
export type RuleDefinition =
| RuleName
| OfValueRule
| OfPatternRule
| PunctuatorRule
| KeywordRule
| OneOfRule
| OfTypeRule
| OneOfTypeRule
| ListOfTypeRule
| [RuleDefinition];
export interface RulesType {
[ruleDefinitionName: RuleName]: RuleDefinition;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment