
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@hiya620/ts-parser
Advanced tools
ts-parser解析typescript代码,
const { AST } = require('ts-parser')
const ast = new AST({filePath: path.join(__dirname, 'demo.ts')})
console.log(ast.config)
ast.config :
imports - 解析import声明生成的数据interfaces - 解析interface声明生成的数据enums - 解析enum声明生成的数据types - 解析type声明生成的数据例如
import { Base, Time } from './base'
import Props from './props'
import Main, { Props as BaseProps } from './type'
import './style.scss'
生成结果:
interface ImportDeclaration {
from: string
defaultSpecifier?: string
specifiers?: Array<{
imported: string
local: string
}>
}
例如
export enum Enabled {
DISABLED = 0,
ENABLED = 1
}
生成结果:
export interface TSEnumDeclaration {
/** 枚举名 */
name: string
/** 枚举成员 */
members: Array<{
label: string
value: string | number | boolean
}>
}
例如
export interface Time {
createTime?: string // 创建时间
updateTime?: string // 更新时间
}
export interface Category extends Base, Time {
id?: string // 类目id
categoryName?: string | number // 类目名称
categoryCode?: string // 类目名称的短码
}
生成结果:
interface FieldType {
simpleType?: string // 简单类型:string, number, boolean
referenceType?: {
name?: string
body?: TSInterfaceDeclaration['body']
} // 引用类型:interface, enum, type等
literalType?: string // 文本值类型:1 | 2
unionType?: Array<FieldType> // 联合类型,例如 string|number
}
interface TSInterfaceDeclaration {
/** 接口名 */
name: string
body: {
[key: string]: {
key: string
optional?: boolean // 是否必须
isArray?: boolean // 是否数组
} & FieldType
}
params?: Array<{
argName: string
defaultValue?: string
}> // 参数,例如 interface Base<T = any> {}
extends?: Array<string>
}
解析支持的写法:
extends,例如 interface Person extends Base {}<T = any>,例如 interface Person<T = any> { }id?: '123456'id?: stringid?: number | stringinterface/enum/type等类型,category?: Categoryperson?: { id: string; name: string }ids?: string[] 或 ids?: Array<string>例如
export type Size = 'sm' | 'md' | 'lg'
export type NumberType = number
export type SimpleType = number | boolean | string | null | undefined
export type Info = Base & Time
export type Person = { id: string; name: string }
export type Persons = Person[]
生成结果:
interface TSTypeAliasDeclaration extends FieldType {
name: string
isArray?: boolean
}
FAQs
> TODO: description
We found that @hiya620/ts-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.