🚧
Still under progress. Soon will be finished.
Description
A utility object that has a few type predicate functions available to make life easier when traversing the reflected nodes.
Value
const is = {
// IMPORTS
ImportNode: (node: unknown): node is ImportNode => {
if (node == null || typeof node !== 'object') {
return false;
}
return 'getNodeType' in node &&
typeof node.getNodeType === 'function' &&
node.getNodeType() === RootNodeType.Import;
},
DefaultImportNode: (node: unknown): node is DefaultImportNode => {
return is.ImportNode(node) && node.getKind() === ImportKind.Default;
},
NamedImportNode: (node: unknown): node is NamedImportNode => {
return is.ImportNode(node) && node.getKind() === ImportKind.Named;
},
NamespaceImportNode: (node: unknown): node is NamespaceImportNode => {
return is.ImportNode(node) && node.getKind() === ImportKind.Namespace;
},
SideEffectImportNode: (node: unknown): node is SideEffectImportNode => {
return is.ImportNode(node) && node.getKind() === ImportKind.SideEffect;
},
// DECLARATIONS
DeclarationNode: (node: unknown): node is DeclarationNode => {
if (node == null || typeof node !== 'object') {
return false;
}
return 'getNodeType' in node &&
typeof node.getNodeType === 'function' &&
node.getNodeType() === RootNodeType.Declaration;
},
EnumNode: (node: unknown): node is EnumNode => {
return is.DeclarationNode(node) && node.getKind() === DeclarationKind.Enum;
},
VariableNode: (node: unknown): node is VariableNode => {
return is.DeclarationNode(node) && node.getKind() === DeclarationKind.Variable;
},
TypeAliasNode: (node: unknown): node is TypeAliasNode => {
return is.DeclarationNode(node) && node.getKind() === DeclarationKind.TypeAlias;
},
FunctionNode: (node: unknown): node is FunctionNode => {
return is.DeclarationNode(node) && node.getKind() === DeclarationKind.Function;
},
ClassNode: (node: unknown): node is ClassNode => {
return is.DeclarationNode(node) && node.getKind() === DeclarationKind.Class;
},
InterfaceNode: (node: unknown): node is InterfaceNode => {
return is.DeclarationNode(node) && node.getKind() === DeclarationKind.Interface;
},
// TYPES
TypeNode: (node: unknown): node is ReflectedTypeNode => {
if (node == null || typeof node !== 'object') {
return false;
}
return 'getKind' in node && typeof node.getKind === 'function';
},
ArrayTypeNode: (node: unknown): node is ArrayTypeNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Array;
},
ConditionalTypeNode: (node: unknown): node is ConditionalTypeNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Conditional;
},
FunctionTypeNode: (node: unknown): node is FunctionTypeNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Function;
},
IndexedAccessTypeNode: (node: unknown): node is IndexedAccessTypeNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.IndexAccess;
},
InferTypeNode: (node: unknown): node is InferTypeNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Infer;
},
IntersectionTypeNode: (node: unknown): node is IntersectionTypeNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Intersection;
},
TypeLiteralTypeNode: (node: unknown): node is TypeLiteralNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.TypeLiteral;
},
MappedTypeNode: (node: unknown): node is MappedTypeNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Mapped;
},
NamedTupleMemberNode: (node: unknown): node is NamedTupleMemberNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.NamedTupleMember;
},
OptionalTypeNode: (node: unknown): node is OptionalTypeNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Optional;
},
IntrinsicTypeNode: (node: unknown): node is IntrinsicTypeNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Intrinsic;
},
RestTypeNode: (node: unknown): node is RestTypeNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Rest;
},
TemplateLiteralTypeNode: (node: unknown): node is TemplateLiteralTypeNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.TemplateLiteral;
},
TupleTypeNode: (node: unknown): node is TupleTypeNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Tuple;
},
TypeLiteralNode: (node: unknown): node is TypeLiteralNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Literal;
},
TypeOperatorNode: (node: unknown): node is TypeOperatorNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Operator;
},
TypePredicateNode: (node: unknown): node is TypePredicateNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Predicate;
},
TypeQueryNode: (node: unknown): node is TypeQueryNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Query;
},
TypeReferenceNode: (node: unknown): node is TypeReferenceNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Reference;
},
UnionTypeNode: (node: unknown): node is UnionTypeNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Union;
},
UnknownTypeNode: (node: unknown): node is UnknownTypeNode => {
return is.TypeNode(node) && node.getKind() === TypeKind.Unknown;
},
// EXPORTS
ExportNode: (node: unknown): node is ExportNode => {
if (node == null || typeof node !== 'object') {
return false;
}
return 'getNodeType' in node &&
typeof node.getNodeType === 'function' &&
node.getNodeType() === RootNodeType.Export;
},
DefaultExportNode: (node: unknown): node is ExportAssignmentNode | ExportDeclarationNode => {
return is.ExportNode(node) && node.getKind() === ExportKind.Default;
},
NamedExportNode: (node: unknown): node is NamedExportNode | ExportDeclarationNode => {
return is.ExportNode(node) && node.getKind() === ExportKind.Named;
},
EqualExportNode: (node: unknown): node is ExportAssignmentNode => {
return is.ExportNode(node) && node.getKind() === ExportKind.Equals;
},
NamespaceExportNode: (node: unknown): node is NamespaceExportNode => {
return is.ExportNode(node) && node.getKind() === ExportKind.Namespace;
},
ReExportNode: (node: unknown): node is ReExportNode => {
return is.ExportNode(node) && node.getKind() === ExportKind.Star;
},
}