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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@snipcart/readts

v3.0.0-develop6

Published

TypeScript exported definitions parser

Downloads

3

Readme

readts

build status npm version

This is a TypeScript exported class, function, type and documentation parser. It outputs everything needed to automatically generate documentation and better understand a project's public API. Information is extracted using TypeScript's Compiler API.

Usage

import * as readts from 'readts';

var parser = new readts.Parser();

// Read configuration used in the project we want to analyze.
var config = parser.parseConfig('tsconfig.json');

// Modify configuration as needed, for example to avoid writing compiler output to disk.
config.options.noEmit = true;

// Parse the project.
var tree = parser.parse(config);

The output is a list of ModuleSpec objects, each with exported classes and interfaces (ClassSpec), functions (FunctionSpec) and variables (IdentifierSpec). Types of variables and function parameters are parsed to TypeSpec objects, pointing to correct ClassSpec objects if applicable. This allows cross-linking types to their definitions in generated documentation.

See charto/docts for a documentation generator using this parser.

API

Docs generated using docts

Class ClassSpec

Class or interface and its members.
Source code: <>

Methods:

new( ) ClassSpec <>
 ▪ spec SymbolSpec

Properties:

.name string
Class name.
.pos SourcePos

.construct FunctionSpec
Constructor function.
.index IndexSpec
Index signature.
.methodList FunctionSpec[]
Public methods.
.propertyList IdentifierSpec[]
Public properties.
.extendList ClassSpec[]
Class extends
.exports ModuleSpec
Class exports
.doc string
JSDoc comment.

Class EnumSpec

Enum and its members.
Source code: <>

Methods:

new( ) EnumSpec <>
 ▪ spec SymbolSpec
.addMember( ) void <>
 ▪ spec IdentifierSpec

Properties:

.name string
Class name.
.pos SourcePos

.memberList IdentifierSpec[]
Public properties.
.doc string
JSDoc comment.

Interface FormatHooks

Hooks to change how parts of type definitions are converted to strings.
Source code: <>

Properties:

.unknown? FormatHook
.ref? FormatHook
.array? FormatHook
.union? FormatHook
.intersection? FormatHook
.generic? FormatHook

Class FunctionSpec

Function or method with any number of overloaded signatures.
Source code: <>

Methods:

new( ) FunctionSpec <>
 ▪ spec SymbolSpec

Properties:

.name string
Function name.
.signatureList SignatureSpec[]
List of signatures, one for each overload.

Class IdentifierSpec

Property, function / method parameter or variable.
Source code: <>

Properties:

.name string
Identifier name.
.pos SourcePos
.type TypeSpec
Type definition.
.value? any
Literal type value
.optional boolean
Interface members and function / method parameters may be optional.
.doc string
JSDoc comment.

Class IndexSpec

Index signature.
Source code: <>

Properties:

.signature TypeSpec
Singature type.
.value TypeSpec
Value type

Class ModuleSpec

Module or source file.
Source code: <>

Methods:

.isEmpty( ) boolean <>
Test if nothing is exported.

Properties:

.enumList EnumSpec[]
Definitions of exported enums.
.classList ClassSpec[]
Definitions of exported classes.
.interfaceList ClassSpec[]
Definitions of exported interfaces.
.functionList FunctionSpec[]
Definitions of exported functions.
.variableList IdentifierSpec[]
Definitions of exported variables.

Class Parser

Main parser class with public methods, also holding its internal state.
Source code: <>

Methods:

.parseConfig( ) ParsedCommandLine <>
Parse a tsconfig.json file using TypeScript services API.
 ▪ tsconfigPath string
.parse( ) ModuleSpec[] <>
Parse a TypeScript project using TypeScript services API and configuration.
 ▪ config ParsedCommandLine
 ▫ nameFilter? (pathName: string) => boolean
 ▫ extension? string

Interface RefSpec

Source code: <>

Properties:

.name? string
.symbol? Symbol
.class? ClassSpec
.enum? EnumSpec

Class SignatureSpec

Function or method signature defining input and output types.
Source code: <>

Methods:

new( ) SignatureSpec <>
 ▪ pos SourcePos
 ▪ returnType TypeSpec
 ▪ doc string

Properties:

.pos SourcePos
.paramList IdentifierSpec[]
List of parameters.
.returnType TypeSpec
Return type definition.
.doc string
JSDoc comment.

Interface SourcePos

Source code: <>

Properties:

.sourcePath string
.firstLine number
.lastLine number

Class TypeSpec

Type definition.
Source code: <>

Methods:

.format( ) string <>
Convert to string, with optional hooks replacing default formatting code.
 ▫ hooks? FormatHooks
 ▫ needParens? boolean

Properties:

.name string
Name of the type, only present if not composed of other type or class etc.
.value? string | number
Value of the type, only present if literal type
.ref RefSpec
Definition of what the type points to, if available.
.unionOf TypeSpec[]
If the type is a union, list of the possible types.
.intersectionOf TypeSpec[]
If the type is an intersection, list of the possible types.
.arrayOf TypeSpec
If the type is an array, its element type.
.argumentList TypeSpec[]
Arguments of a generic type.

License

The MIT License

Copyright (c) 2016- readts authors.