Skip to content

Commit

Permalink
Split src into multiple directories
Browse files Browse the repository at this point in the history
  • Loading branch information
ajafff committed May 19, 2017
1 parent 8729269 commit 578fe2d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/index.ts → index.ts
@@ -1,2 +1,2 @@
export * from './typeguard';
export * from './utils';
export * from './util';
4 changes: 1 addition & 3 deletions package.json
Expand Up @@ -2,11 +2,9 @@
"name": "tsutils",
"version": "1.9.1",
"description": "utilities for working with typescript's AST",
"main": "src/index.js",
"types": "src/index.d.ts",
"scripts": {
"compile": "tsc -p .",
"lint": "tslint 'src/**/*.ts'",
"lint": "tslint -p .",
"prepublish": "npm run compile"
},
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions typeguard/index.ts
@@ -0,0 +1,2 @@
export * from './node';
export * from './type';
58 changes: 0 additions & 58 deletions src/typeguard.ts → typeguard/node.ts
Expand Up @@ -568,61 +568,3 @@ export function isWhileStatement(node: ts.Node): node is ts.WhileStatement {
export function isWithStatement(node: ts.Node): node is ts.WithStatement {
return node.kind === ts.SyntaxKind.WithStatement;
}

// types

export function isEnumType(type: ts.Type): type is ts.EnumType {
return (type.flags & ts.TypeFlags.Enum) !== 0;
}

export function isGenericType(type: ts.Type): type is ts.GenericType {
return (type.flags & ts.TypeFlags.Object) !== 0 &&
((<ts.ObjectType>type).objectFlags & ts.ObjectFlags.ClassOrInterface) !== 0 &&
((<ts.ObjectType>type).objectFlags & ts.ObjectFlags.Reference) !== 0;
}

export function isIndexedAccessType(type: ts.Type): type is ts.IndexedAccessType {
return (type.flags & ts.TypeFlags.IndexedAccess) !== 0;
}

export function isIndexedAccessype(type: ts.Type): type is ts.IndexType {
return (type.flags & ts.TypeFlags.Index) !== 0;
}

export function isInterfaceType(type: ts.Type): type is ts.InterfaceType {
return (type.flags & ts.TypeFlags.Object) !== 0 &&
((<ts.ObjectType>type).objectFlags & ts.ObjectFlags.ClassOrInterface) !== 0;
}

export function isIntersectionType(type: ts.Type): type is ts.IntersectionType {
return (type.flags & ts.TypeFlags.Intersection) !== 0;
}

export function isLiteralType(type: ts.Type): type is ts.LiteralType {
return (type.flags & ts.TypeFlags.Literal) !== 0;
}

export function isObjectType(type: ts.Type): type is ts.ObjectType {
return (type.flags & ts.TypeFlags.Object) !== 0;
}

export function isTypeParameter(type: ts.Type): type is ts.TypeParameter {
return (type.flags & ts.TypeFlags.TypeParameter) !== 0;
}

export function isTypeReference(type: ts.Type): type is ts.TypeReference {
return (type.flags & ts.TypeFlags.Object) !== 0 &&
((<ts.ObjectType>type).objectFlags & ts.ObjectFlags.Reference) !== 0;
}

export function isTypeVariable(type: ts.Type): type is ts.TypeVariable {
return (type.flags & ts.TypeFlags.TypeVariable) !== 0;
}

export function isUnionOrIntersectionType(type: ts.Type): type is ts.UnionOrIntersectionType {
return (type.flags & ts.TypeFlags.UnionOrIntersection) !== 0;
}

export function isUnionType(type: ts.Type): type is ts.UnionType {
return (type.flags & ts.TypeFlags.Union) !== 0;
}
57 changes: 57 additions & 0 deletions typeguard/type.ts
@@ -0,0 +1,57 @@
import * as ts from 'typescript';

export function isEnumType(type: ts.Type): type is ts.EnumType {
return (type.flags & ts.TypeFlags.Enum) !== 0;
}

export function isGenericType(type: ts.Type): type is ts.GenericType {
return (type.flags & ts.TypeFlags.Object) !== 0 &&
((<ts.ObjectType>type).objectFlags & ts.ObjectFlags.ClassOrInterface) !== 0 &&
((<ts.ObjectType>type).objectFlags & ts.ObjectFlags.Reference) !== 0;
}

export function isIndexedAccessType(type: ts.Type): type is ts.IndexedAccessType {
return (type.flags & ts.TypeFlags.IndexedAccess) !== 0;
}

export function isIndexedAccessype(type: ts.Type): type is ts.IndexType {
return (type.flags & ts.TypeFlags.Index) !== 0;
}

export function isInterfaceType(type: ts.Type): type is ts.InterfaceType {
return (type.flags & ts.TypeFlags.Object) !== 0 &&
((<ts.ObjectType>type).objectFlags & ts.ObjectFlags.ClassOrInterface) !== 0;
}

export function isIntersectionType(type: ts.Type): type is ts.IntersectionType {
return (type.flags & ts.TypeFlags.Intersection) !== 0;
}

export function isLiteralType(type: ts.Type): type is ts.LiteralType {
return (type.flags & ts.TypeFlags.Literal) !== 0;
}

export function isObjectType(type: ts.Type): type is ts.ObjectType {
return (type.flags & ts.TypeFlags.Object) !== 0;
}

export function isTypeParameter(type: ts.Type): type is ts.TypeParameter {
return (type.flags & ts.TypeFlags.TypeParameter) !== 0;
}

export function isTypeReference(type: ts.Type): type is ts.TypeReference {
return (type.flags & ts.TypeFlags.Object) !== 0 &&
((<ts.ObjectType>type).objectFlags & ts.ObjectFlags.Reference) !== 0;
}

export function isTypeVariable(type: ts.Type): type is ts.TypeVariable {
return (type.flags & ts.TypeFlags.TypeVariable) !== 0;
}

export function isUnionOrIntersectionType(type: ts.Type): type is ts.UnionOrIntersectionType {
return (type.flags & ts.TypeFlags.UnionOrIntersection) !== 0;
}

export function isUnionType(type: ts.Type): type is ts.UnionType {
return (type.flags & ts.TypeFlags.Union) !== 0;
}
2 changes: 1 addition & 1 deletion src/utils.ts → util/index.ts
@@ -1,5 +1,5 @@
import * as ts from 'typescript';
import { isBlockLike, isIfStatement, isLiteralExpression, isSwitchStatement } from './typeguard';
import { isBlockLike, isIfStatement, isLiteralExpression, isSwitchStatement } from '../typeguard/node';

export function getChildOfKind(node: ts.Node, kind: ts.SyntaxKind, sourceFile?: ts.SourceFile) {
for (const child of node.getChildren(sourceFile))
Expand Down

0 comments on commit 578fe2d

Please sign in to comment.