npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hiya620/ts-parser

v1.0.2

Published

> TODO: description

Downloads

30

Readme

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声明

例如

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
  }>
}

解析enum声明

例如

export enum Enabled {
  DISABLED = 0,
  ENABLED = 1
}

生成结果:

export interface TSEnumDeclaration {
  /** 枚举名 */
  name: string
  /** 枚举成员 */
  members: Array<{
    label: string
    value: string | number | boolean
  }>
}

解析interface声明

例如

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?: string
  • 成员类型为联合类型,id?: number | string
  • 成员类型为interface/enum/type等类型,category?: Category
  • 成员类型为person?: { id: string; name: string }
  • 成员类型为数组,ids?: string[]ids?: Array<string>

解析type声明

例如

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
}