tsutils-etc
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -0,3 +1,10 @@ | ||
<a name="1.1.0"></a> | ||
## [1.1.0](https://github.com/cartant/tsutils-etc/compare/v1.0.1...v1.1.0) (2019-03-09) | ||
## Features | ||
* Added support for fully-qualified names to `couldBeType` and `isType`. ([f34effa](https://github.com/cartant/rxjs-tslint-rules/commit/f34effa)) | ||
<a name="1.0.1"></a> | ||
## [1.10.1](https://github.com/cartant/tsutils-etc/compare/v1.0.0...v1.0.1) (2019-02-23) | ||
## [1.0.1](https://github.com/cartant/tsutils-etc/compare/v1.0.0...v1.0.1) (2019-02-23) | ||
@@ -4,0 +11,0 @@ ## Fixes |
@@ -10,11 +10,11 @@ import * as ts from "typescript"; | ||
} | ||
export function couldBeType(type, name) { | ||
export function couldBeType(type, name, qualified) { | ||
if (isReferenceType(type)) { | ||
type = type.target; | ||
} | ||
if (isType(type, name)) { | ||
if (isType(type, name, qualified)) { | ||
return true; | ||
} | ||
if (isIntersectionType(type) || isUnionType(type)) { | ||
return type.types.some((t) => couldBeType(t, name)); | ||
return type.types.some((t) => couldBeType(t, name, qualified)); | ||
} | ||
@@ -25,3 +25,3 @@ const baseTypes = type.getBaseTypes(); | ||
} | ||
return baseTypes.some((t) => couldBeType(t, name)); | ||
return baseTypes.some((t) => couldBeType(t, name, qualified)); | ||
} | ||
@@ -80,6 +80,9 @@ export function findDeclaration(node, typeChecker) { | ||
} | ||
export function isType(type, name) { | ||
export function isType(type, name, qualified) { | ||
if (!type.symbol) { | ||
return false; | ||
} | ||
if (qualified && !qualified.name.test(qualified.typeChecker.getFullyQualifiedName(type.symbol))) { | ||
return false; | ||
} | ||
return (typeof name === "string") ? | ||
@@ -86,0 +89,0 @@ (type.symbol.name === name) : |
@@ -10,11 +10,11 @@ import * as ts from "typescript"; | ||
} | ||
export function couldBeType(type, name) { | ||
export function couldBeType(type, name, qualified) { | ||
if (isReferenceType(type)) { | ||
type = type.target; | ||
} | ||
if (isType(type, name)) { | ||
if (isType(type, name, qualified)) { | ||
return true; | ||
} | ||
if (isIntersectionType(type) || isUnionType(type)) { | ||
return type.types.some(function (t) { return couldBeType(t, name); }); | ||
return type.types.some(function (t) { return couldBeType(t, name, qualified); }); | ||
} | ||
@@ -25,3 +25,3 @@ var baseTypes = type.getBaseTypes(); | ||
} | ||
return baseTypes.some(function (t) { return couldBeType(t, name); }); | ||
return baseTypes.some(function (t) { return couldBeType(t, name, qualified); }); | ||
} | ||
@@ -80,6 +80,9 @@ export function findDeclaration(node, typeChecker) { | ||
} | ||
export function isType(type, name) { | ||
export function isType(type, name, qualified) { | ||
if (!type.symbol) { | ||
return false; | ||
} | ||
if (qualified && !qualified.name.test(qualified.typeChecker.getFullyQualifiedName(type.symbol))) { | ||
return false; | ||
} | ||
return (typeof name === "string") ? | ||
@@ -86,0 +89,0 @@ (type.symbol.name === name) : |
@@ -33,3 +33,3 @@ { | ||
"types": "./index.d.ts", | ||
"version": "1.0.1" | ||
"version": "1.1.0" | ||
} |
import * as ts from "typescript"; | ||
export declare function couldBeFunction(type: ts.Type): boolean; | ||
export declare function couldBeType(type: ts.Type, name: string | RegExp): boolean; | ||
export declare function couldBeType(type: ts.Type, name: string | RegExp, qualified?: { | ||
name: RegExp; | ||
typeChecker: ts.TypeChecker; | ||
}): boolean; | ||
export declare function findDeclaration(node: ts.Node, typeChecker: ts.TypeChecker): ts.Declaration | undefined; | ||
@@ -11,5 +14,8 @@ export declare function isAny(type: ts.Type): boolean; | ||
export declare function isThis(node: ts.Node): boolean; | ||
export declare function isType(type: ts.Type, name: string | RegExp): boolean; | ||
export declare function isType(type: ts.Type, name: string | RegExp, qualified?: { | ||
name: RegExp; | ||
typeChecker: ts.TypeChecker; | ||
}): boolean; | ||
export declare function isUnionType(type: ts.Type): type is ts.UnionType; | ||
export declare function isWithinCallExpressionExpression(node: ts.Node): boolean; | ||
export declare function isWithinParameterDeclaration(node: ts.Node): boolean; |
13
utils.js
@@ -13,11 +13,11 @@ "use strict"; | ||
exports.couldBeFunction = couldBeFunction; | ||
function couldBeType(type, name) { | ||
function couldBeType(type, name, qualified) { | ||
if (isReferenceType(type)) { | ||
type = type.target; | ||
} | ||
if (isType(type, name)) { | ||
if (isType(type, name, qualified)) { | ||
return true; | ||
} | ||
if (isIntersectionType(type) || isUnionType(type)) { | ||
return type.types.some(function (t) { return couldBeType(t, name); }); | ||
return type.types.some(function (t) { return couldBeType(t, name, qualified); }); | ||
} | ||
@@ -28,3 +28,3 @@ var baseTypes = type.getBaseTypes(); | ||
} | ||
return baseTypes.some(function (t) { return couldBeType(t, name); }); | ||
return baseTypes.some(function (t) { return couldBeType(t, name, qualified); }); | ||
} | ||
@@ -91,6 +91,9 @@ exports.couldBeType = couldBeType; | ||
exports.isThis = isThis; | ||
function isType(type, name) { | ||
function isType(type, name, qualified) { | ||
if (!type.symbol) { | ||
return false; | ||
} | ||
if (qualified && !qualified.name.test(qualified.typeChecker.getFullyQualifiedName(type.symbol))) { | ||
return false; | ||
} | ||
return (typeof name === "string") ? | ||
@@ -97,0 +100,0 @@ (type.symbol.name === name) : |
16070
365