https://github.com/charto/readts
TypeScript exported definitions parser
https://github.com/charto/readts
Last synced: 2 months ago
JSON representation
TypeScript exported definitions parser
- Host: GitHub
- URL: https://github.com/charto/readts
- Owner: charto
- License: mit
- Created: 2016-03-19T00:34:12.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-09-14T17:19:27.000Z (over 7 years ago)
- Last Synced: 2025-08-09T14:52:57.608Z (5 months ago)
- Language: TypeScript
- Size: 40 KB
- Stars: 19
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
readts
======
[](http://travis-ci.org/charto/readts)
[](https://www.npmjs.com/package/readts)
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](https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API).
Usage
-----
```typescript
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`](#api-ModuleSpec) objects, each with exported classes and interfaces ([`ClassSpec`](#api-ClassSpec)),
functions ([`FunctionSpec`](#api-FunctionSpec)) and variables ([`IdentifierSpec`](#api-IdentifierSpec)).
Types of variables and function parameters are parsed to [`TypeSpec`](#api-TypeSpec) objects,
pointing to correct [`ClassSpec`](#api-ClassSpec) objects if applicable.
This allows cross-linking types to their definitions in generated documentation.
See [charto/docts](https://github.com/charto/docts) for a documentation generator using this parser.
API
===
Docs generated using [`docts`](https://github.com/charto/docts)
>
>
> ### Class [`ClassSpec`](#api-ClassSpec)
> Class or interface and its members.
> Source code: [`<>`](http://github.com/charto/readts/blob/62754ee/src/ClassSpec.ts#L11-L74)
>
> Methods:
> > **new( )** ⇒ [ClassSpec](#api-ClassSpec) [`<>`](http://github.com/charto/readts/blob/62754ee/src/ClassSpec.ts#L14-L21)
> > ▪ spec SymbolSpec
>
> Properties:
> > **.name** string
> > Class name.
> > **.pos** [SourcePos](#api-SourcePos)
> > **.construct** [FunctionSpec](#api-FunctionSpec)
> > Constructor function.
> > **.index** [IndexSpec](#api-IndexSpec)
> > Index signature.
> > **.methodList** [FunctionSpec](#api-FunctionSpec)[]
> > Public methods.
> > **.propertyList** [IdentifierSpec](#api-IdentifierSpec)[]
> > Public properties.
> > **.extendList** [ClassSpec](#api-ClassSpec)[]
> > Class extends
> > **.exports** [ModuleSpec](#api-ModuleSpec)
> > Class exports
> > **.doc** string
> > JSDoc comment.
>
>
> ### Class [`EnumSpec`](#api-EnumSpec)
> Enum and its members.
> Source code: [`<>`](http://github.com/charto/readts/blob/ce93baf/src/EnumSpec.ts#L11-L37)
>
> Methods:
> > **new( )** ⇒ [EnumSpec](#api-EnumSpec) [`<>`](http://github.com/charto/readts/blob/ce93baf/src/EnumSpec.ts#L14-L20)
> > ▪ spec SymbolSpec
> > **.addMember( )** ⇒ void [`<>`](http://github.com/charto/readts/blob/ce93baf/src/EnumSpec.ts#L22-L26)
> > ▪ spec [IdentifierSpec](#api-IdentifierSpec)
>
> Properties:
> > **.name** string
> > Class name.
> > **.pos** [SourcePos](#api-SourcePos)
> > **.memberList** [IdentifierSpec](#api-IdentifierSpec)[]
> > Public properties.
> > **.doc** string
> > JSDoc comment.
>
>
> ### Interface [`FormatHooks`](#api-FormatHooks)
> Hooks to change how parts of type definitions are converted to strings.
> Source code: [`<>`](http://github.com/charto/readts/blob/ce93baf/src/TypeSpec.ts#L11-L20)
>
> Properties:
> > **.unknown**? FormatHook
> > **.ref**? FormatHook
> > **.array**? FormatHook
> > **.union**? FormatHook
> > **.intersection**? FormatHook
> > **.generic**? FormatHook
>
>
> ### Class [`FunctionSpec`](#api-FunctionSpec)
> Function or method with any number of overloaded signatures.
> Source code: [`<>`](http://github.com/charto/readts/blob/c857e04/src/FunctionSpec.ts#L11-L30)
>
> Methods:
> > **new( )** ⇒ [FunctionSpec](#api-FunctionSpec) [`<>`](http://github.com/charto/readts/blob/c857e04/src/FunctionSpec.ts#L14-L18)
> > ▪ spec SymbolSpec
>
> Properties:
> > **.name** string
> > Function name.
> > **.signatureList** [SignatureSpec](#api-SignatureSpec)[]
> > List of signatures, one for each overload.
>
>
> ### Class [`IdentifierSpec`](#api-IdentifierSpec)
> Property, function / method parameter or variable.
> Source code: [`<>`](http://github.com/charto/readts/blob/ce93baf/src/IdentifierSpec.ts#L11-L34)
>
> Properties:
> > **.name** string
> > Identifier name.
> > **.pos** [SourcePos](#api-SourcePos)
> > **.type** [TypeSpec](#api-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`](#api-IndexSpec)
> Index signature.
> Source code: [`<>`](http://github.com/charto/readts/blob/62754ee/src/IndexSpec.ts#L9-L21)
>
> Properties:
> > **.signature** [TypeSpec](#api-TypeSpec)
> > Singature type.
> > **.value** [TypeSpec](#api-TypeSpec)
> > Value type
>
>
> ### Class [`ModuleSpec`](#api-ModuleSpec)
> Module or source file.
> Source code: [`<>`](http://github.com/charto/readts/blob/ce93baf/src/ModuleSpec.ts#L11-L58)
>
> Methods:
> > **.isEmpty( )** ⇒ boolean [`<>`](http://github.com/charto/readts/blob/ce93baf/src/ModuleSpec.ts#L38-L46)
> > Test if nothing is exported.
>
> Properties:
> > **.enumList** [EnumSpec](#api-EnumSpec)[]
> > Definitions of exported enums.
> > **.classList** [ClassSpec](#api-ClassSpec)[]
> > Definitions of exported classes.
> > **.interfaceList** [ClassSpec](#api-ClassSpec)[]
> > Definitions of exported interfaces.
> > **.functionList** [FunctionSpec](#api-FunctionSpec)[]
> > Definitions of exported functions.
> > **.variableList** [IdentifierSpec](#api-IdentifierSpec)[]
> > Definitions of exported variables.
>
>
> ### Class [`Parser`](#api-Parser)
> Main parser class with public methods, also holding its internal state.
> Source code: [`<>`](http://github.com/charto/readts/blob/f0d51fd/src/Parser.ts#L36-L402)
>
> Methods:
> > **.parseConfig( )** ⇒ ParsedCommandLine [`<>`](http://github.com/charto/readts/blob/f0d51fd/src/Parser.ts#L39-L44)
> > Parse a tsconfig.json file using TypeScript services API.
> > ▪ tsconfigPath string
> > **.parse( )** ⇒ [ModuleSpec](#api-ModuleSpec)[] [`<>`](http://github.com/charto/readts/blob/f0d51fd/src/Parser.ts#L48-L75)
> > Parse a TypeScript project using TypeScript services API and configuration.
> > ▪ config ParsedCommandLine
> > ▫ nameFilter? (pathName: string) => boolean
> > ▫ extension? string
>
>
> ### Interface [`RefSpec`](#api-RefSpec)
> Source code: [`<>`](http://github.com/charto/readts/blob/f0d51fd/src/Parser.ts#L25-L32)
>
> Properties:
> > **.name**? string
> > **.symbol**? Symbol
> > **.class**? [ClassSpec](#api-ClassSpec)
> > **.enum**? [EnumSpec](#api-EnumSpec)
>
>
> ### Class [`SignatureSpec`](#api-SignatureSpec)
> Function or method signature defining input and output types.
> Source code: [`<>`](http://github.com/charto/readts/blob/c857e04/src/SignatureSpec.ts#L11-L33)
>
> Methods:
> > **new( )** ⇒ [SignatureSpec](#api-SignatureSpec) [`<>`](http://github.com/charto/readts/blob/c857e04/src/SignatureSpec.ts#L14-L18)
> > ▪ pos [SourcePos](#api-SourcePos)
> > ▪ returnType [TypeSpec](#api-TypeSpec)
> > ▪ doc string
>
> Properties:
> > **.pos** [SourcePos](#api-SourcePos)
> > **.paramList** [IdentifierSpec](#api-IdentifierSpec)[]
> > List of parameters.
> > **.returnType** [TypeSpec](#api-TypeSpec)
> > Return type definition.
> > **.doc** string
> > JSDoc comment.
>
>
> ### Interface [`SourcePos`](#api-SourcePos)
> Source code: [`<>`](http://github.com/charto/readts/blob/f0d51fd/src/Parser.ts#L8-L12)
>
> Properties:
> > **.sourcePath** string
> > **.firstLine** number
> > **.lastLine** number
>
>
> ### Class [`TypeSpec`](#api-TypeSpec)
> Type definition.
> Source code: [`<>`](http://github.com/charto/readts/blob/ce93baf/src/TypeSpec.ts#L24-L163)
>
> Methods:
> > **.format( )** ⇒ string [`<>`](http://github.com/charto/readts/blob/ce93baf/src/TypeSpec.ts#L106-L147)
> > Convert to string, with optional hooks replacing default formatting code.
> > ▫ hooks? [FormatHooks](#api-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](#api-RefSpec)
> > Definition of what the type points to, if available.
> > **.unionOf** [TypeSpec](#api-TypeSpec)[]
> > If the type is a union, list of the possible types.
> > **.intersectionOf** [TypeSpec](#api-TypeSpec)[]
> > If the type is an intersection, list of the possible types.
> > **.arrayOf** [TypeSpec](#api-TypeSpec)
> > If the type is an array, its element type.
> > **.argumentList** [TypeSpec](#api-TypeSpec)[]
> > Arguments of a generic type.
License
=======
[The MIT License](https://raw.githubusercontent.com/charto/readts/master/LICENSE)
Copyright (c) 2016 BusFaster Ltd