import ts from 'typescript' ; import * as utils from '../utils' ; export function getModifiers ( node ) { const modifiers = utils . getValueOrUndefined ( node . modifiers ) ; return modifiers === undefined ? [ ] : modifiers ; } export function getFirstModifierByKind < Token extends ts . Modifier > ( node , kind ) { const modifier = getModifiers ( node ) . find ( ( mod ) : mod is Token => mod . kind === kind ) ; if ( modifier !== undefined ) { return modifier ; } return node . getChildren ( ) . find ( ( mod ) : mod is Token => mod . kind === kind ) ; } export function getAbstractKeyword ( node ) { return getFirstModifierByKind ( node , ts . SyntaxKind . AbstractKeyword ) ; } export function isAbstract ( node ) { return getAbstractKeyword ( node ) !== undefined ; } export function getConstKeyword ( node ) { return getFirstModifierByKind ( node , ts . SyntaxKind . ConstKeyword ) ; } export function isConst ( node ) { return getConstKeyword ( node ) !== undefined ; } export function getPublicKeyword ( node ) { return getFirstModifierByKind ( node , ts . SyntaxKind . PublicKeyword ) ; } export function isPublic ( node ) { return getPublicKeyword ( node ) !== undefined ; } export function getProtectedKeyword ( node ) { return getFirstModifierByKind ( node , ts . SyntaxKind . ProtectedKeyword ) ; } export function isProtected ( node ) { return getProtectedKeyword ( node ) !== undefined ; } export function getPrivateKeyword ( node ) { return getFirstModifierByKind ( node , ts . SyntaxKind . PrivateKeyword ) ; } export function isPrivate ( node ) { return getPrivateKeyword ( node ) !== undefined ; } export function getReadonlyKeyword ( node ) { return getFirstModifierByKind ( node , ts . SyntaxKind . ReadonlyKeyword ) ; } export function isReadonly ( node ) { return getReadonlyKeyword ( node ) !== undefined ; } export function getStaticKeyword ( node ) { return getFirstModifierByKind ( node , ts . SyntaxKind . StaticKeyword ) ; } export function isStatic ( node ) { return getStaticKeyword ( node ) !== undefined ; } export function getExportKeyword ( node ) { return getFirstModifierByKind ( node , ts . SyntaxKind . ExportKeyword ) ; } export function hasExportKeyword ( node ) { return getExportKeyword ( node ) !== undefined ; } export function getDefaultKeyword ( node ) { return getFirstModifierByKind ( node , ts . SyntaxKind . DefaultKeyword ) ; } export function hasDefaultKeyword ( node ) { return getDefaultKeyword ( node ) !== undefined ; } export function isNamedExport ( node ) { const parent = utils . getValueOrUndefined ( node . parent ) ; return parent !== undefined && ts . isSourceFile ( parent ) && hasExportKeyword ( node ) && ! hasDefaultKeyword ( node ) ; } export function isDefaultExport ( node ) { return hasExportKeyword ( node ) && hasDefaultKeyword ( node ) ; } export function getDeclareKeyword ( node ) { return getFirstModifierByKind ( node , ts . SyntaxKind . DeclareKeyword ) ; } export function hasDeclareKeyword ( node ) { return getDeclareKeyword ( node ) !== undefined ; }