├── tests ├── data │ ├── access │ │ ├── spec.yml │ │ └── sample.ts │ ├── variables │ │ ├── spec.yml │ │ └── sample.ts │ ├── weird-names │ │ ├── spec.yml │ │ └── sample.ts │ ├── exception │ │ ├── sample.ts │ │ └── spec.yml │ ├── module │ │ ├── spec.yml │ │ └── sample.ts │ ├── single-exports │ │ ├── sample.ts │ │ └── spec.yml │ ├── default-exports │ │ ├── sample.ts │ │ └── spec.yml │ ├── enumerations │ │ ├── sample.ts │ │ └── spec.yml │ ├── generics │ │ ├── sample.ts │ │ └── spec.yml │ ├── functions │ │ ├── sample.ts │ │ └── spec.yml │ └── classes │ │ ├── sample.ts │ │ └── spec.yml ├── helper.ts └── converter.test.ts ├── src ├── common │ ├── regex.ts │ ├── flags.ts │ └── constants.ts ├── interfaces │ ├── UidMapping.ts │ ├── ReferenceMapping.ts │ ├── TocItem.ts │ ├── RepoConfig.ts │ ├── TypeDocModel.ts │ └── YamlModel.ts ├── converters │ ├── empty.ts │ ├── enum.ts │ ├── module.ts │ ├── context.ts │ ├── method.ts │ ├── converter.ts │ ├── property.ts │ ├── accessor.ts │ ├── type.ts │ └── base.ts ├── packageGenerator.ts ├── moduleGenerator.ts ├── parser.ts ├── tocGenerator.ts ├── helpers │ └── linkConvertHelper.ts ├── idResolver.ts ├── main.ts └── postTransformer.ts ├── jest.config.js ├── tsconfig.json ├── .github └── workflows │ └── node.js.yml ├── README.md ├── .gitignore ├── .npmignore ├── package.json ├── .vscode └── launch.json ├── tslint.json └── LICENSE /tests/data/access/spec.yml: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /tests/data/variables/spec.yml: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /tests/data/weird-names/spec.yml: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /src/common/regex.ts: -------------------------------------------------------------------------------- 1 | export const uidRegex = /@uid:(.+?)!@/g; 2 | -------------------------------------------------------------------------------- /src/interfaces/UidMapping.ts: -------------------------------------------------------------------------------- 1 | export interface UidMapping { 2 | [typedocId: number]: string; 3 | } 4 | -------------------------------------------------------------------------------- /src/common/flags.ts: -------------------------------------------------------------------------------- 1 | export let flags = { 2 | hasModule: false, 3 | enableAlphabetOrder: true 4 | }; 5 | -------------------------------------------------------------------------------- /src/interfaces/ReferenceMapping.ts: -------------------------------------------------------------------------------- 1 | export interface ReferenceMapping { 2 | [referenceName: string]: string; 3 | } 4 | -------------------------------------------------------------------------------- /src/interfaces/TocItem.ts: -------------------------------------------------------------------------------- 1 | export interface TocItem { 2 | uid?: string; 3 | name: string; 4 | items?: Array; 5 | } 6 | -------------------------------------------------------------------------------- /src/interfaces/RepoConfig.ts: -------------------------------------------------------------------------------- 1 | export interface RepoConfig { 2 | repo: string; 3 | branch: string; 4 | basePath: string; 5 | } 6 | -------------------------------------------------------------------------------- /tests/data/exception/sample.ts: -------------------------------------------------------------------------------- 1 | export class Foo { 2 | /** 3 | * @throws Exception description. 4 | */ 5 | public bar() { 6 | } 7 | } -------------------------------------------------------------------------------- /tests/data/weird-names/sample.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Object with characters that must be escaped. 3 | */ 4 | export const foo = { 5 | '': '', 6 | '=': '=' 7 | }; -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | transform: { '^.+\\.ts?$': 'ts-jest' }, 3 | testEnvironment: 'node', 4 | testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$', 5 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'] 6 | }; -------------------------------------------------------------------------------- /src/common/constants.ts: -------------------------------------------------------------------------------- 1 | export const constructorName = 'constructor'; 2 | export const yamlHeader = '### YamlMime:UniversalReference'; 3 | export const setOfTopLevelItems = new Set(['class', 'interface', 'module', 'type alias']); 4 | export const langs = ['typeScript']; -------------------------------------------------------------------------------- /tests/data/variables/sample.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A const variable 3 | */ 4 | export const constVariable = 'const'; 5 | 6 | /** 7 | * A let variable 8 | */ 9 | export let letVariable = 'let'; 10 | 11 | /** 12 | * A var variable 13 | */ 14 | export var varVariable= 'var'; -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": [ 3 | "src/**/*" 4 | ], 5 | "exclude": [ 6 | "node_modules" 7 | ], 8 | "compilerOptions": { 9 | "noImplicitAny": true, 10 | "sourceMap": true, 11 | "outDir": "dist", 12 | "target": "es5", 13 | "lib": ["es6"], 14 | "allowJs": true 15 | } 16 | } -------------------------------------------------------------------------------- /src/converters/empty.ts: -------------------------------------------------------------------------------- 1 | import { YamlModel } from '../interfaces/YamlModel'; 2 | import { Node } from '../interfaces/TypeDocModel'; 3 | import { AbstractConverter } from './base'; 4 | import { Context } from './context'; 5 | 6 | export class EmptyConverter extends AbstractConverter { 7 | protected generate(node: Node, context: Context): Array { 8 | return []; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/data/exception/spec.yml: -------------------------------------------------------------------------------- 1 | - uid: type2docfx.Foo 2 | name: Foo 3 | fullName: Foo 4 | children: 5 | - uid: type2docfx.Foo.bar 6 | name: bar() 7 | children: [] 8 | type: method 9 | langs: 10 | - typeScript 11 | summary: '' 12 | syntax: 13 | content: function bar() 14 | parameters: [] 15 | package: type2docfx 16 | langs: 17 | - typeScript 18 | type: class 19 | summary: '' 20 | package: type2docfx -------------------------------------------------------------------------------- /tests/helper.ts: -------------------------------------------------------------------------------- 1 | import { Application, ProjectReflection } from 'typedoc'; 2 | import * as path from 'path'; 3 | 4 | export function generate(file: string): ProjectReflection { 5 | const app = new Application({ 6 | mode: 'Modules', 7 | logger: 'none', 8 | target: 'ES5', 9 | module: 'CommonJS', 10 | includeDeclarations: true, 11 | ignoreCompilerErrors: true, 12 | excludeExternals: true 13 | }); 14 | 15 | file = path.resolve(file); 16 | return app.convert(app.expandInputFiles([file])); 17 | } -------------------------------------------------------------------------------- /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | name: Publish NPM Package 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | 8 | jobs: 9 | publish-npm: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v2 14 | - uses: actions/setup-node@v1 15 | with: 16 | node-version: 12 17 | registry-url: https://registry.npmjs.org/ 18 | - run: npm install 19 | - run: npm run build --if-present 20 | - run: npm run test 21 | - run: npm publish --access public 22 | env: 23 | NODE_AUTH_TOKEN: ${{secrets.npm_token}} 24 | 25 | 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Type2DocFx 2 | > A tool to convert json format output from TypeDoc to universal reference model for DocFx to consume. 3 | 4 | ## Installation 5 | Type2DocFx runs on Node.js and is available as an NPM package. 6 | 7 | ``` 8 | $ npm install type2docfx --save-dev 9 | ``` 10 | 11 | ## Usage 12 | ``` 13 | Usage: type2docfx [options] 14 | 15 | A tool to convert the json format api file generated by TypeDoc to yaml format output files for docfx. 16 | 17 | 18 | Options: 19 | 20 | -V, --version output the version number 21 | --hasModule Add the option if the source repository contains module 22 | --disableAlphabetOrder Add the option if you want to disable the alphabet order in output yaml 23 | -h, --help output usage information 24 | ``` 25 | 26 | ## License 27 | 28 | Licensed under the Apache License 2.0. 29 | -------------------------------------------------------------------------------- /src/converters/enum.ts: -------------------------------------------------------------------------------- 1 | import { YamlModel } from '../interfaces/YamlModel'; 2 | import { Node } from '../interfaces/TypeDocModel'; 3 | import { AbstractConverter } from './base'; 4 | import { Context } from './context'; 5 | import { langs } from '../common/constants'; 6 | 7 | export class EnumConverter extends AbstractConverter { 8 | protected generate(node: Node, context: Context): Array { 9 | const uid = context.ParentUid + '.' + node.name; 10 | const model: YamlModel = { 11 | uid: uid, 12 | name: node.name, 13 | children: [], 14 | langs: langs, 15 | summary: node.comment ? this.findDescriptionInComment(node.comment) : '', 16 | type: 'field' 17 | }; 18 | 19 | if (node.defaultValue) { 20 | model.numericValue = parseInt(node.defaultValue, 10); 21 | } 22 | 23 | console.log(` - ${node.kindString}: ${uid}`); 24 | return [model]; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/data/module/spec.yml: -------------------------------------------------------------------------------- 1 | - uid: type2docfx.MyModule 2 | name: MyModule 3 | langs: 4 | - typeScript 5 | fullName: MyModule 6 | children: 7 | - uid: type2docfx.MyModule.MySubmodule 8 | name: MySubmodule 9 | langs: 10 | - typeScript 11 | fullName: MySubmodule 12 | children: [] 13 | type: module 14 | summary: This is a submodule with the preferred comment. 15 | package: type2docfx 16 | - uid: type2docfx.print 17 | name: print(string) 18 | children: [] 19 | type: function 20 | langs: 21 | - typeScript 22 | summary: An object literal function. 23 | syntax: 24 | content: 'function print(value: string)' 25 | parameters: 26 | - id: value 27 | type: 28 | - typeName: string 29 | typeId: ! '' 30 | description: '' 31 | optional: false 32 | package: type2docfx 33 | type: module 34 | summary: This is a module. 35 | package: type2docfx -------------------------------------------------------------------------------- /src/converters/module.ts: -------------------------------------------------------------------------------- 1 | import { YamlModel } from '../interfaces/YamlModel'; 2 | import { Node } from '../interfaces/TypeDocModel'; 3 | import { AbstractConverter } from './base'; 4 | import { Context } from './context'; 5 | import { langs } from '../common/constants'; 6 | 7 | export class ModuleConverter extends AbstractConverter { 8 | protected generate(node: Node, context: Context): Array { 9 | node.name = node.name.replace(/"/g, ''); 10 | node.name = node.name.replace(/\//g, '.'); 11 | 12 | const uid = context.ParentUid + `.${node.name}`; 13 | const model: YamlModel = { 14 | uid: uid, 15 | name: node.name, 16 | langs: langs, 17 | fullName: node.name + this.getGenericType(node.typeParameter), 18 | children: [], 19 | type: node.kindString.toLowerCase(), 20 | summary: node.comment ? this.findDescriptionInComment(node.comment) : '' 21 | }; 22 | 23 | console.log(`${node.kindString}: ${uid}`); 24 | 25 | return [model]; 26 | } 27 | } -------------------------------------------------------------------------------- /src/packageGenerator.ts: -------------------------------------------------------------------------------- 1 | import { YamlModel, Root } from './interfaces/YamlModel'; 2 | 3 | export function generatePackage(elements: YamlModel[]): Root { 4 | let root: Root = { 5 | items: [], 6 | references: [] 7 | }; 8 | let packageModel: YamlModel = null; 9 | if (elements && elements.length) { 10 | packageModel = { 11 | uid: null, 12 | name: null, 13 | summary: '', 14 | children: [], 15 | type: 'package', 16 | langs: [ 'typeScript' ] 17 | }; 18 | 19 | elements.forEach(element => { 20 | root.references.push({ 21 | uid: element.uid, 22 | name: element.name 23 | }); 24 | (packageModel.children as string[]).push(element.uid); 25 | if (!packageModel.uid && element.package) { 26 | packageModel.uid = element.package; 27 | packageModel.name = element.package; 28 | } 29 | }); 30 | } 31 | root.items.push(packageModel); 32 | return root; 33 | } 34 | -------------------------------------------------------------------------------- /src/moduleGenerator.ts: -------------------------------------------------------------------------------- 1 | import { YamlModel, Root } from './interfaces/YamlModel'; 2 | import { TocItem } from './interfaces/TocItem'; 3 | 4 | export function generateModules(tocRoots: TocItem[]): Root[] { 5 | let result: Root[] = []; 6 | 7 | tocRoots.forEach(tocRoot => { 8 | let root: Root = { 9 | items: [], 10 | references: [] 11 | }; 12 | let moduleModel: YamlModel = { 13 | uid: tocRoot.uid, 14 | name: tocRoot.name, 15 | summary: '', 16 | langs: [ 'typeScript' ], 17 | type: 'module', 18 | children: [] 19 | }; 20 | 21 | if (tocRoot.items && tocRoot.items.length) { 22 | tocRoot.items.forEach(item => { 23 | (moduleModel.children as string[]).push(item.uid); 24 | root.references.push({ 25 | uid: item.uid, 26 | name: item.name 27 | }); 28 | }); 29 | 30 | root.items.push(moduleModel); 31 | result.push(root); 32 | } 33 | }); 34 | 35 | return result; 36 | } 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | dist/ 61 | -------------------------------------------------------------------------------- /tests/data/single-exports/sample.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This class is not exported. 3 | */ 4 | class NotExportedClass 5 | { 6 | /** 7 | * Property of not exported class. 8 | */ 9 | public notExportedProperty:string; 10 | 11 | 12 | /** 13 | * This is the constructor of the not exported class. 14 | */ 15 | constructor() { } 16 | 17 | 18 | /** 19 | * Method of not exported class. 20 | */ 21 | public getNotExportedProperty():string { 22 | return this.notExportedProperty; 23 | } 24 | } 25 | 26 | 27 | /** 28 | * This class is exported by being assigned to ´export´. 29 | * 30 | * ~~~ 31 | * export = SingleExportedClass; 32 | * ~~~ 33 | */ 34 | class SingleExportedClass 35 | { 36 | /** 37 | * Property of exported class. 38 | */ 39 | public exportedProperty:string; 40 | 41 | 42 | /** 43 | * This is the constructor of the exported class. 44 | */ 45 | constructor() { } 46 | 47 | 48 | /** 49 | * Method of exported class. 50 | */ 51 | public getExportedProperty():string { 52 | return this.exportedProperty; 53 | } 54 | } 55 | 56 | 57 | /** 58 | * The export statement. 59 | */ 60 | export = SingleExportedClass; -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # vscode folder 61 | .vscode 62 | tests/data 63 | tests/out 64 | src 65 | 66 | appveyor.yml 67 | gulpfile.js 68 | tslint.json 69 | 70 | .github/ 71 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "type2docfx", 3 | "version": "0.10.5", 4 | "description": "A tool to convert json format output from TypeDoc to universal reference model for DocFx to consume.", 5 | "main": "./dist/main.js", 6 | "bin": "./dist/main.js", 7 | "scripts": { 8 | "build": "tsc", 9 | "test": "jest", 10 | "coverage": "jest --coverage" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/wuhanyumsft/type2docfx.git" 15 | }, 16 | "keywords": [ 17 | "typescript", 18 | "docfx", 19 | "documentation" 20 | ], 21 | "author": "Simon Wu (siw)", 22 | "license": "Apache-2.0", 23 | "bugs": { 24 | "url": "https://github.com/wuhanyumsft/type2docfx/issues" 25 | }, 26 | "homepage": "https://github.com/wuhanyumsft/type2docfx#readme", 27 | "devDependencies": { 28 | "@types/commander": "^2.12.2", 29 | "@types/fs-extra": "^4.0.9", 30 | "@types/jest": "^24.0.23", 31 | "@types/js-yaml": "^3.12.1", 32 | "@types/lodash": "^4.14.149", 33 | "jest": "^24.9.0", 34 | "ts-jest": "^24.2.0", 35 | "tslint": "^5.20.1", 36 | "typedoc": "^0.15.3", 37 | "typescript": "^3.7.3" 38 | }, 39 | "dependencies": { 40 | "commander": "^5.0.0", 41 | "fs-extra": "^9.0.0", 42 | "js-yaml": "^3.13.1", 43 | "lodash": "^4.17.5" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/converters/context.ts: -------------------------------------------------------------------------------- 1 | import { RepoConfig } from "../interfaces/RepoConfig"; 2 | 3 | export class Context { 4 | private parentUid: string; 5 | private parentKind: string; 6 | private repo: RepoConfig; 7 | private packageName: string; 8 | private references: Map 9 | 10 | constructor( 11 | repo: RepoConfig, 12 | parentUid: string, 13 | parentKind: string, 14 | packageName: string, 15 | references: Map) { 16 | this.repo = repo; 17 | this.packageName = packageName; 18 | this.parentUid = parentUid; 19 | this.parentKind = parentKind; 20 | this.references = references; 21 | } 22 | 23 | public get PackageName() { 24 | return this.packageName; 25 | } 26 | 27 | public get References() { 28 | return this.references; 29 | } 30 | 31 | public get Repo(): RepoConfig { 32 | return this.repo; 33 | } 34 | 35 | public get ParentUid(): string { 36 | if (this.parentUid === '') { 37 | return this.PackageName; 38 | } 39 | 40 | return this.parentUid; 41 | } 42 | 43 | public set ParentUid(uid: string) { 44 | this.parentUid = uid; 45 | } 46 | 47 | public get ParentKind(): string { 48 | return this.parentKind; 49 | } 50 | } -------------------------------------------------------------------------------- /tests/converter.test.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs'; 2 | import * as path from 'path'; 3 | import * as helper from "./helper"; 4 | import * as yaml from 'js-yaml'; 5 | import { Node } from '../src/interfaces/TypeDocModel'; 6 | import { Context } from '../src/converters/context'; 7 | import { Parser } from '../src/parser'; 8 | 9 | describe('converter', () => { 10 | const testData = 'tests/data'; 11 | for (const dir of fs.readdirSync(testData)) { 12 | const dirPath = path.join(testData, dir); 13 | if (!fs.lstatSync(dirPath).isDirectory()) { 14 | return; 15 | } 16 | 17 | describe(dir, () => { 18 | it('match specs', () => { 19 | const sample = path.join(dirPath, 'sample.ts'); 20 | const spec = path.join(dirPath, 'spec.yml'); 21 | const data = helper.generate(sample); 22 | 23 | const node = data as any as Node; 24 | const context = new Context(null, '', '', node.name, new Map()); 25 | const models = new Parser().traverse(node, {}, context); 26 | 27 | const actual = yaml.dump(models, { noRefs: true }).trim(); 28 | const expected = fs.readFileSync(spec, "utf8").replace(/\r\n/g, '\n').trim(); 29 | 30 | expect(actual).toEqual(expected); 31 | }) 32 | }); 33 | } 34 | }); -------------------------------------------------------------------------------- /tests/data/default-exports/sample.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This class is exported under a different name. The exported name is 3 | * "ExportedClassName" 4 | * 5 | * ```JavaScript 6 | * export {NotExportedClassName as ExportedClassName}; 7 | * ``` 8 | */ 9 | class NotExportedClassName 10 | { 11 | /** 12 | * Property of NotExportedClassName class. 13 | */ 14 | public notExportedProperty:string; 15 | 16 | 17 | /** 18 | * This is the constructor of the NotExportedClassName class. 19 | */ 20 | constructor() { } 21 | 22 | 23 | /** 24 | * Method of NotExportedClassName class. 25 | */ 26 | public getNotExportedProperty():string { 27 | return this.notExportedProperty; 28 | } 29 | } 30 | 31 | 32 | /** 33 | * This class is exported via es6 export syntax. 34 | * 35 | * ``` 36 | * export default class DefaultExportedClass 37 | * ``` 38 | */ 39 | export default class DefaultExportedClass 40 | { 41 | /** 42 | * Property of default exported class. 43 | */ 44 | public exportedProperty:string; 45 | 46 | 47 | /** 48 | * This is the constructor of the default exported class. 49 | */ 50 | constructor() { } 51 | 52 | 53 | /** 54 | * Method of default exported class. 55 | */ 56 | public getExportedProperty():string { 57 | return this.exportedProperty; 58 | } 59 | } 60 | 61 | // Rename class on export 62 | export {NotExportedClassName as ExportedClassName}; -------------------------------------------------------------------------------- /tests/data/access/sample.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A variable that is made private via comment. 3 | * @private 4 | */ 5 | export var fakePrivateVariable = 'test'; 6 | 7 | /** 8 | * A variable that is made protected via comment. 9 | * @protected 10 | */ 11 | export var fakeProtectedVariable = 'test'; 12 | 13 | /** 14 | * A function that is made private via comment. 15 | * @private 16 | */ 17 | export function fakePrivateFunction() {} 18 | 19 | /** 20 | * A function that is made protected via comment. 21 | * @protected 22 | */ 23 | export function fakeProtectedFunction() {} 24 | 25 | /** 26 | * A class that is documented as being private. 27 | * @private 28 | */ 29 | export class PrivateClass 30 | { 31 | /** 32 | * A variable that is made private via comment. 33 | * @private 34 | */ 35 | fakePrivateVariable:string; 36 | 37 | /** 38 | * A variable that is made protected via comment. 39 | * @protected 40 | */ 41 | fakeProtectedVariable:string; 42 | 43 | /** 44 | * A function that is made private via comment. 45 | * @private 46 | */ 47 | fakePrivateFunction() {} 48 | 49 | /** 50 | * A function that is made protected via comment. 51 | * @protected 52 | */ 53 | fakeProtectedFunction() {} 54 | } 55 | 56 | /** 57 | * A module that is documented as being private. 58 | * @private 59 | */ 60 | export module PrivateModule 61 | { 62 | export function functionInsidePrivateModule() {} 63 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Program", 11 | "skipFiles": [ 12 | "/**" 13 | ], 14 | "program": "${workspaceFolder}/dist/main.js", 15 | "args": [ 16 | "../docfx-seed-typescript/tmp.json", 17 | "_temp" 18 | ], 19 | "outFiles": [ 20 | "${workspaceFolder}/**/*.js" 21 | ] 22 | }, 23 | { 24 | "type": "node", 25 | "request": "launch", 26 | "name": "Jest Current File", 27 | "program": "${workspaceFolder}/node_modules/.bin/jest", 28 | "args": [ 29 | "--runTestsByPath", 30 | "${relativeFile}", 31 | "--config", 32 | "${workspaceFolder}/jest.config.js" 33 | ], 34 | "console": "integratedTerminal", 35 | "internalConsoleOptions": "neverOpen", 36 | "windows": { 37 | "program": "${workspaceFolder}/node_modules/jest/bin/jest" 38 | } 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /src/converters/method.ts: -------------------------------------------------------------------------------- 1 | import { YamlModel } from '../interfaces/YamlModel'; 2 | import { Node } from '../interfaces/TypeDocModel'; 3 | import { AbstractConverter } from './base'; 4 | import * as _ from 'lodash'; 5 | import { Context } from './context'; 6 | import { convertLinkToGfm } from '../helpers/linkConvertHelper'; 7 | import { langs } from '../common/constants'; 8 | 9 | export class MethodConverter extends AbstractConverter { 10 | protected generate(node: Node, context: Context): Array { 11 | if (!node.signatures) { 12 | return; 13 | } 14 | 15 | const models = new Array(); 16 | for (let index = 0; index < node.signatures.length; index++) { 17 | let uid = context.ParentUid + '.' + node.name; 18 | if (index > 0) { 19 | uid += `_${index}`; 20 | } 21 | 22 | console.log(` - ${node.kindString}: ${uid}`); 23 | const model: YamlModel = { 24 | uid: uid, 25 | name: node.name, 26 | children: [], 27 | type: '', 28 | langs: langs, 29 | summary: '', 30 | syntax: { 31 | content: '' 32 | } 33 | }; 34 | 35 | this.extractInformationFromSignature(model, node, index); 36 | model.name = this.composeMethodNameFromSignature(model); 37 | model.summary = convertLinkToGfm(model.summary); 38 | 39 | models.push(model); 40 | } 41 | 42 | 43 | return models; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/data/enumerations/sample.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This is a simple Enumeration. 3 | */ 4 | export enum Directions 5 | { 6 | /** 7 | * A simple enum member. 8 | */ 9 | Top, 10 | 11 | /** 12 | * A simple enum member. 13 | */ 14 | Right, 15 | 16 | /** 17 | * A simple enum member. 18 | */ 19 | Bottom, 20 | 21 | /** 22 | * A simple enum member. 23 | */ 24 | Left, 25 | 26 | /** 27 | * A composite enum member. 28 | */ 29 | TopLeft = Top | Left, 30 | 31 | /** 32 | * A composite enum member. 33 | */ 34 | TopRight = Top | Right 35 | } 36 | 37 | 38 | /** 39 | * This is a enumeration extended by a module. 40 | * 41 | * You should see both the enum members and the module members. 42 | */ 43 | export enum Size 44 | { 45 | /** 46 | * A simple enum member. 47 | */ 48 | Small, 49 | 50 | /** 51 | * A simple enum member. 52 | */ 53 | Medium, 54 | 55 | /** 56 | * A simple enum member. 57 | */ 58 | Large 59 | } 60 | 61 | 62 | /** 63 | * This comment is ignored, as the enumeration is already defined. 64 | */ 65 | export module Size 66 | { 67 | /** 68 | * A variable that is attached to an enumeration. 69 | */ 70 | var defaultSize:Size = Size.Medium; 71 | 72 | 73 | /** 74 | * A function that is attached to an enumeration. 75 | * 76 | * @param value The value that should be tested. 77 | * @returns TRUE when the given value equals Size.Small. 78 | */ 79 | function isSmall(value:Size):boolean { 80 | return value == Size.Small; 81 | } 82 | } -------------------------------------------------------------------------------- /src/converters/converter.ts: -------------------------------------------------------------------------------- 1 | import { YamlModel } from '../interfaces/YamlModel'; 2 | import { Node } from '../interfaces/TypeDocModel'; 3 | import { ModuleConverter } from './module'; 4 | import { AbstractConverter } from './base'; 5 | import { EnumConverter } from './enum'; 6 | import { PropertyConverter } from './property'; 7 | import { AccessorConverter } from './accessor'; 8 | import { MethodConverter } from './method'; 9 | import { TypeConverter } from './type'; 10 | import { Context } from './context'; 11 | import { EmptyConverter } from './empty'; 12 | 13 | export class Converter { 14 | public convert(node: Node, context: Context): Array { 15 | const converter = this.createConverter(node, context.References); 16 | return converter.convert(node, context); 17 | } 18 | 19 | private createConverter(node: Node, references: Map): AbstractConverter { 20 | switch (node.kindString) { 21 | case 'Module': 22 | return new ModuleConverter(references); 23 | case 'Enumeration member': 24 | return new EnumConverter(references); 25 | case 'Property': 26 | return new PropertyConverter(references); 27 | case 'Accessor': 28 | return new AccessorConverter(references); 29 | case 'Method': 30 | case 'Function': 31 | case 'Constructor': 32 | return new MethodConverter(references); 33 | case 'Class': 34 | case 'Interface': 35 | case 'Enumeration': 36 | case 'Type alias': 37 | return new TypeConverter(references); 38 | default: 39 | return new EmptyConverter(references); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /src/converters/property.ts: -------------------------------------------------------------------------------- 1 | import { YamlModel } from '../interfaces/YamlModel'; 2 | import { Node } from '../interfaces/TypeDocModel'; 3 | import { AbstractConverter } from './base'; 4 | import { typeToString } from '../idResolver'; 5 | import * as _ from 'lodash'; 6 | import { Context } from './context'; 7 | import { langs } from '../common/constants'; 8 | 9 | export class PropertyConverter extends AbstractConverter { 10 | protected generate(node: Node, context: Context): Array { 11 | const uid = context.ParentUid + '.' + node.name; 12 | console.log(` - ${node.kindString}: ${uid}`); 13 | let isPublic = node.flags && node.flags.isPublic ? 'public ' : ''; 14 | let isStatic = node.flags && node.flags.isStatic ? 'static ' : ''; 15 | let isOptional = node.flags && node.flags.isOptional ? '?' : ''; 16 | let defaultValue = node.defaultValue ? ` = ${_.trim(node.defaultValue)}` : ''; 17 | const model: YamlModel = { 18 | uid: uid, 19 | name: node.name, 20 | fullName: node.name, 21 | children: [], 22 | langs: langs, 23 | type: node.kindString.toLowerCase(), 24 | summary: node.comment ? this.findDescriptionInComment(node.comment) : '', 25 | optional: node.flags && node.flags.isOptional, 26 | syntax: { 27 | content: `${isPublic}${isStatic}${node.name}${isOptional}: ${typeToString(this.extractType(node.type)[0], node.kindString)}${defaultValue}`, 28 | return: { 29 | type: this.extractType(node.type), 30 | description: this.extractReturnComment(node.comment) 31 | } 32 | } 33 | }; 34 | 35 | return [model]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/data/module/sample.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * ... 3 | */ 4 | 5 | /** 6 | * This is a module. 7 | */ 8 | export module MyModule 9 | { 10 | /** 11 | * This is an object literal. 12 | */ 13 | export var object = { 14 | /** 15 | * An object literal value. 16 | */ 17 | name: 'Test', 18 | 19 | /** 20 | * An object literal function. 21 | */ 22 | print: function(value:string) { } 23 | }; 24 | 25 | 26 | /** 27 | * This is a submodule. 28 | */ 29 | export module MySubmodule 30 | { 31 | var a:string; 32 | } 33 | 34 | 35 | export var exportedModuleVariable = 'foo'; 36 | 37 | var moduleVariable = [100, 200]; 38 | 39 | var moduleVariable2:number[]; 40 | } 41 | 42 | /** 43 | * This is a submodule with the preferred comment. 44 | * @preferred 45 | */ 46 | export module MyModule.MySubmodule 47 | { 48 | var b:string; 49 | } 50 | 51 | /** 52 | * An exported global variable. 53 | */ 54 | export var exportedGlobalVariable = 'foo'; 55 | 56 | /** 57 | * A non-exported global variable. 58 | */ 59 | var globalVariable = 'foo'; 60 | 61 | /** 62 | * An object literal. 63 | */ 64 | var objectLiteral = { 65 | valueZ: 'foo', 66 | valueY: function() { return 'foo'; }, 67 | valueX: { 68 | valueZ: 'foo', 69 | valueY: (z:string) => { return {a:'test', b:z}; }, 70 | valueA: [100, 200, 300] 71 | }, 72 | valueA: 100, 73 | valueB: true 74 | }; 75 | 76 | var typeLiteral:{ 77 | ():string; 78 | valueZ:string; 79 | valueY:{():string;}; 80 | valueX:{ 81 | valueZ:string; 82 | valueY:{(z:string):{a:string; b:string}; }; 83 | valueA:number[]; 84 | }; 85 | valueA?:number; 86 | valueB?:boolean; 87 | }; 88 | -------------------------------------------------------------------------------- /tests/data/single-exports/spec.yml: -------------------------------------------------------------------------------- 1 | - uid: type2docfx.SingleExportedClass 2 | name: SingleExportedClass 3 | fullName: SingleExportedClass 4 | children: 5 | - uid: type2docfx.SingleExportedClass.constructor 6 | name: SingleExportedClass() 7 | children: [] 8 | type: constructor 9 | langs: 10 | - typeScript 11 | summary: This is the constructor of the exported class. 12 | syntax: 13 | content: new SingleExportedClass() 14 | parameters: [] 15 | package: type2docfx 16 | - uid: type2docfx.SingleExportedClass.exportedProperty 17 | name: exportedProperty 18 | fullName: exportedProperty 19 | children: [] 20 | langs: 21 | - typeScript 22 | type: property 23 | summary: Property of exported class. 24 | optional: false 25 | syntax: 26 | content: 'public exportedProperty: string' 27 | return: 28 | type: 29 | - typeName: string 30 | typeId: ! '' 31 | description: '' 32 | package: type2docfx 33 | - uid: type2docfx.SingleExportedClass.getExportedProperty 34 | name: getExportedProperty() 35 | children: [] 36 | type: method 37 | langs: 38 | - typeScript 39 | summary: Method of exported class. 40 | syntax: 41 | content: function getExportedProperty() 42 | parameters: [] 43 | return: 44 | type: 45 | - typeName: string 46 | typeId: ! '' 47 | description: '' 48 | package: type2docfx 49 | langs: 50 | - typeScript 51 | type: class 52 | summary: | 53 | This class is exported by being assigned to ´export´. 54 | ~~~ 55 | export = SingleExportedClass; 56 | ~~~ 57 | package: type2docfx -------------------------------------------------------------------------------- /src/interfaces/TypeDocModel.ts: -------------------------------------------------------------------------------- 1 | export interface Node { 2 | id: number; 3 | name: string; 4 | kind: number; 5 | kindString: string; 6 | children: Node[]; 7 | flags: Flags; 8 | comment: Comment; 9 | signatures: Signature[]; 10 | type: ParameterType; 11 | defaultValue: string; 12 | parameters: Parameter[]; 13 | indexSignature: Node[]; 14 | extendedTypes: ParameterType[]; 15 | inheritedFrom: ParameterType; 16 | sources: Source[]; 17 | typeParameter: ParameterType[]; 18 | getSignature: Node[] | Node; 19 | setSignature: Node[] | Node; 20 | } 21 | 22 | interface Source { 23 | fileName: string; 24 | line: number; 25 | } 26 | 27 | interface Flags { 28 | isExported: boolean; 29 | isPrivate: boolean; 30 | isProtected: boolean; 31 | isStatic: boolean; 32 | isOptional: boolean; 33 | isPublic: boolean; 34 | } 35 | 36 | export interface Comment { 37 | text?: string; 38 | shortText?: string; 39 | returns?: string; 40 | tags?: Tag[]; 41 | } 42 | 43 | export interface Tag { 44 | tag: string; 45 | text: string; 46 | param: string; 47 | } 48 | 49 | export interface Signature { 50 | comment: Comment; 51 | parameters: Parameter[]; 52 | type?: ParameterType; 53 | typeParameter: ParameterType[]; 54 | } 55 | 56 | export interface Parameter { 57 | name: string; 58 | type: ParameterType; 59 | comment: Comment; 60 | flags: ParameterFlag; 61 | } 62 | 63 | export interface ParameterType { 64 | type: string; 65 | types: ParameterType[]; 66 | name: string; 67 | value: string; 68 | id: number; 69 | typeArguments: ParameterType[]; 70 | declaration: Node; 71 | elementType: ParameterType; 72 | elements: ParameterType[]; 73 | } 74 | 75 | interface ParameterFlag { 76 | isOptional: boolean; 77 | } 78 | -------------------------------------------------------------------------------- /tests/data/generics/sample.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A generic function 3 | * 4 | * @typeparam T The generic type parameter. 5 | * @param value A generic parameter. 6 | * @returns A generic return value. 7 | */ 8 | function testFunction(value:T):T { 9 | return value; 10 | } 11 | 12 | /** 13 | * A generic interface. 14 | * 15 | * @param T The generic type parameter. 16 | */ 17 | interface A 18 | { 19 | /** 20 | * A generic member function. 21 | * 22 | * @return A generic return value. 23 | */ 24 | getT():T; 25 | } 26 | 27 | 28 | /** 29 | * A generic interface with two type parameters. 30 | * 31 | * @param The first generic type parameter. 32 | * @param The second generic type parameter. 33 | */ 34 | interface B 35 | { 36 | /** 37 | * A generic member function. 38 | * 39 | * @param value A generic parameter. 40 | */ 41 | setT(value:T):void; 42 | 43 | /** 44 | * A generic member function. 45 | * 46 | * @return A generic return value. 47 | */ 48 | getC():C; 49 | } 50 | 51 | 52 | /** 53 | * A generic interface extending two other generic interfaces 54 | * and setting one of the type parameters. 55 | * 56 | * @typeparam T The leftover generic type parameter. 57 | */ 58 | interface AB extends A, B {} 59 | 60 | 61 | /** 62 | * An interface extending a generic interface and setting its type parameter. 63 | */ 64 | export interface ABString extends AB {} 65 | 66 | 67 | /** 68 | * An interface extending a generic interface and setting its type parameter. 69 | */ 70 | interface ABNumber extends AB {} 71 | 72 | 73 | /** 74 | * A function returning a generic array with type parameters. 75 | * 76 | * @return The return value with type arguments. 77 | */ 78 | function getGenericArray():Array { 79 | return ['']; 80 | } -------------------------------------------------------------------------------- /src/converters/accessor.ts: -------------------------------------------------------------------------------- 1 | import { YamlModel } from '../interfaces/YamlModel'; 2 | import { Node } from '../interfaces/TypeDocModel'; 3 | import { AbstractConverter } from './base'; 4 | import { typeToString } from '../idResolver'; 5 | import { Context } from './context'; 6 | 7 | export class AccessorConverter extends AbstractConverter { 8 | protected generate(node: Node, context: Context): Array { 9 | const uid = context.ParentUid + '.' + node.name; 10 | console.log(` - ${node.kindString}: ${uid}`); 11 | let signatureType; 12 | if (node.getSignature) { 13 | if (Array.isArray(node.getSignature)) { 14 | signatureType = node.getSignature[0].type; 15 | } else { 16 | signatureType = node.getSignature.type; 17 | } 18 | } else if (node.setSignature) { 19 | if (Array.isArray(node.setSignature)) { 20 | signatureType = node.setSignature[0].type; 21 | } else { 22 | signatureType = node.setSignature.type; 23 | } 24 | } 25 | 26 | const model: YamlModel = { 27 | uid: uid, 28 | name: node.name, 29 | fullName: node.name, 30 | children: [], 31 | langs: ['typeScript'], 32 | type: 'property', 33 | summary: node.comment ? this.findDescriptionInComment(node.comment) : '', 34 | syntax: { 35 | content: `${node.flags && node.flags.isStatic ? 'static ' : ''}${typeToString(this.extractType(signatureType)[0])} ${node.name}`, 36 | return: { 37 | type: this.extractType(signatureType), 38 | description: this.extractReturnComment(node.comment) 39 | } 40 | } 41 | }; 42 | 43 | return [model]; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/data/default-exports/spec.yml: -------------------------------------------------------------------------------- 1 | - uid: type2docfx.DefaultExportedClass 2 | name: DefaultExportedClass 3 | fullName: DefaultExportedClass 4 | children: 5 | - uid: type2docfx.DefaultExportedClass.constructor 6 | name: DefaultExportedClass() 7 | children: [] 8 | type: constructor 9 | langs: 10 | - typeScript 11 | summary: This is the constructor of the default exported class. 12 | syntax: 13 | content: new DefaultExportedClass() 14 | parameters: [] 15 | package: type2docfx 16 | - uid: type2docfx.DefaultExportedClass.exportedProperty 17 | name: exportedProperty 18 | fullName: exportedProperty 19 | children: [] 20 | langs: 21 | - typeScript 22 | type: property 23 | summary: Property of default exported class. 24 | optional: false 25 | syntax: 26 | content: 'public exportedProperty: string' 27 | return: 28 | type: 29 | - typeName: string 30 | typeId: ! '' 31 | description: '' 32 | package: type2docfx 33 | - uid: type2docfx.DefaultExportedClass.getExportedProperty 34 | name: getExportedProperty() 35 | children: [] 36 | type: method 37 | langs: 38 | - typeScript 39 | summary: Method of default exported class. 40 | syntax: 41 | content: function getExportedProperty() 42 | parameters: [] 43 | return: 44 | type: 45 | - typeName: string 46 | typeId: ! '' 47 | description: '' 48 | package: type2docfx 49 | langs: 50 | - typeScript 51 | type: class 52 | summary: | 53 | This class is exported via es6 export syntax. 54 | ``` 55 | export default class DefaultExportedClass 56 | ``` 57 | package: type2docfx -------------------------------------------------------------------------------- /tests/data/generics/spec.yml: -------------------------------------------------------------------------------- 1 | - uid: type2docfx.ABString 2 | name: ABString 3 | fullName: ABString 4 | children: 5 | - uid: type2docfx.ABString.getC 6 | name: getC() 7 | children: [] 8 | type: method 9 | langs: 10 | - typeScript 11 | summary: A generic member function. 12 | syntax: 13 | content: function getC() 14 | parameters: [] 15 | return: 16 | type: 17 | - typeName: boolean 18 | typeId: ! '' 19 | description: A generic return value. 20 | package: type2docfx 21 | - uid: type2docfx.ABString.getT 22 | name: getT() 23 | children: [] 24 | type: method 25 | langs: 26 | - typeScript 27 | summary: A generic member function. 28 | syntax: 29 | content: function getT() 30 | parameters: [] 31 | return: 32 | type: 33 | - typeName: string 34 | typeId: ! '' 35 | description: A generic return value. 36 | package: type2docfx 37 | - uid: type2docfx.ABString.setT 38 | name: setT(string) 39 | children: [] 40 | type: method 41 | langs: 42 | - typeScript 43 | summary: A generic member function. 44 | syntax: 45 | content: 'function setT(value: string)' 46 | parameters: 47 | - id: value 48 | type: 49 | - typeName: string 50 | typeId: ! '' 51 | description: | 52 | A generic parameter. 53 | optional: false 54 | package: type2docfx 55 | langs: 56 | - typeScript 57 | type: interface 58 | summary: An interface extending a generic interface and setting its type parameter. 59 | extends: 60 | name: 61 | genericType: 62 | outter: 63 | typeName: AB 64 | typeId: ! '' 65 | inner: 66 | - typeName: string 67 | typeId: ! '' 68 | package: type2docfx -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "align": false, 4 | "ban": [], 5 | "class-name": true, 6 | "comment-format": [ true, "check-space" ], 7 | "curly": true, 8 | "eofline": true, 9 | "forin": false, 10 | "indent": [ true, "spaces" ], 11 | "interface-name": [ true, "never-prefix" ], 12 | "jsdoc-format": true, 13 | "label-position": true, 14 | "max-line-length": 120, 15 | "member-access": false, 16 | "member-ordering": false, 17 | "no-any": false, 18 | "no-arg": true, 19 | "no-bitwise": false, 20 | "no-consecutive-blank-lines": true, 21 | "no-console": false, 22 | "no-construct": false, 23 | "no-debugger": true, 24 | "no-duplicate-variable": true, 25 | "no-empty": false, 26 | "no-eval": true, 27 | "no-inferrable-types": [ true, "ignore-params" ], 28 | "no-shadowed-variable": false, 29 | "no-string-literal": false, 30 | "no-switch-case-fall-through": false, 31 | "no-trailing-whitespace": true, 32 | "no-unused-expression": false, 33 | "no-use-before-declare": false, 34 | "no-var-keyword": true, 35 | "no-var-requires": false, 36 | "object-literal-sort-keys": false, 37 | "one-line": [ true, "check-open-brace", "check-whitespace", "check-else", "check-catch" ], 38 | "quotemark": [ true, "single", "avoid-escape" ], 39 | "radix": true, 40 | "semicolon": [ true, "always" ], 41 | "trailing-comma": [ true, { 42 | "multiline": "never", 43 | "singleline": "never" 44 | } ], 45 | "triple-equals": [ true, "allow-null-check" ], 46 | "typedef": false, 47 | "typedef-whitespace": [ true, { 48 | "call-signature": "nospace", 49 | "index-signature": "nospace", 50 | "parameter": "nospace", 51 | "property-declaration": "nospace", 52 | "variable-declaration": "nospace" 53 | }, { 54 | "call-signature": "onespace", 55 | "index-signature": "onespace", 56 | "parameter": "onespace", 57 | "property-declaration": "onespace", 58 | "variable-declaration": "onespace" 59 | } ], 60 | "variable-name": [ true, "check-format", "allow-leading-underscore", "ban-keywords" ], 61 | "whitespace": [ true, "check-branch", "check-decl", "check-operator", "check-module", "check-separator", "check-type", "check-typecast" ] 62 | } 63 | } -------------------------------------------------------------------------------- /src/interfaces/YamlModel.ts: -------------------------------------------------------------------------------- 1 | export interface YamlModel { 2 | uid: string; 3 | name: string; 4 | children: Array | Array; 5 | langs: Array; 6 | type: string; 7 | summary?: string; 8 | syntax?: Syntax; 9 | fullName?: string; 10 | exceptions?: Array; 11 | numericValue?: number; 12 | package?: string; 13 | module?: string; 14 | source?: Source; 15 | extends?: NameWithUrl; 16 | deprecated?: Deprecated; 17 | isPreview?: boolean; 18 | remarks?: string; 19 | optional?: boolean; 20 | } 21 | 22 | export type Types = Type[] | string[]; 23 | 24 | interface NameWithUrl { 25 | name: Type | string; 26 | href?: string; 27 | } 28 | interface Deprecated { 29 | content: string; 30 | } 31 | 32 | interface Source { 33 | path: string; 34 | startLine: number; 35 | remote: Remote; 36 | } 37 | 38 | interface Remote { 39 | path: string; 40 | branch: string; 41 | repo: string; 42 | } 43 | 44 | export interface Reference { 45 | uid?: string; 46 | name?: string; 47 | fullName?: string; 48 | 'spec.typeScript'?: Reference[]; 49 | } 50 | 51 | export interface Syntax { 52 | parameters?: Array; 53 | content?: string; 54 | return?: Return; 55 | } 56 | 57 | interface Return { 58 | type: Types; 59 | description: string; 60 | } 61 | 62 | export interface YamlParameter { 63 | id: string; 64 | type: Types; 65 | description: string; 66 | optional?: boolean; 67 | } 68 | 69 | export interface Root { 70 | items: Array; 71 | references?: Array; 72 | } 73 | 74 | export interface Type { 75 | typeName?: string; 76 | typeId?: number; 77 | reflectedType?: ReflectedType; 78 | genericType?: GenericType; 79 | intersectionType?: IntersectionType; 80 | unionType?: UnionType; 81 | arrayType?: Type | string; 82 | } 83 | 84 | export interface UnionType { 85 | types: Type[] | string[]; 86 | } 87 | 88 | export interface IntersectionType { 89 | types: Type[] | string[]; 90 | } 91 | 92 | export interface GenericType { 93 | outter: Type | string; 94 | inner: Type[] | string[]; 95 | } 96 | 97 | export interface ReflectedType { 98 | key: Type | string; 99 | value: Type | string; 100 | } 101 | 102 | export interface Exception { 103 | type: string; 104 | description: string; 105 | } 106 | -------------------------------------------------------------------------------- /src/parser.ts: -------------------------------------------------------------------------------- 1 | import { YamlModel } from './interfaces/YamlModel'; 2 | import { Node } from './interfaces/TypeDocModel'; 3 | import { UidMapping } from './interfaces/UidMapping'; 4 | import * as _ from 'lodash'; 5 | import { Converter } from './converters/converter'; 6 | import { Context } from './converters/context'; 7 | 8 | export class Parser { 9 | public traverse(node: Node, uidMapping: UidMapping, context: Context): YamlModel[] { 10 | let collection = new Array(); 11 | 12 | if (this.needIgnore(node)) { 13 | return collection; 14 | } 15 | 16 | let models = new Converter().convert(node, context); 17 | for (const model of models) { 18 | uidMapping[node.id] = model.uid; 19 | collection.push(model); 20 | } 21 | 22 | if (!node.children || node.children === []) { 23 | return collection; 24 | } 25 | 26 | for (const child of node.children) { 27 | const uid = models.length > 0 ? models[0].uid : context.PackageName; 28 | const newContext = new Context( 29 | context.Repo, 30 | uid, 31 | node.kindString, 32 | context.PackageName, 33 | context.References); 34 | if (models.length > 0) { 35 | models[0].children = [].concat(models[0].children, this.traverse(child, uidMapping, newContext)); 36 | } else { 37 | collection = [].concat(collection, this.traverse(child, uidMapping, newContext)); 38 | } 39 | } 40 | 41 | return collection; 42 | } 43 | 44 | private needIgnore(node: Node): boolean { 45 | if (node.name && node.name[0] === '_') { 46 | return true; 47 | } 48 | 49 | if (node.flags.isPrivate || node.flags.isProtected) { 50 | return true; 51 | } 52 | 53 | if (this.isInternal(node)) { 54 | return true; 55 | } 56 | 57 | if (!node.flags.isExported 58 | && node.sources 59 | && !node.sources[0].fileName.toLowerCase().endsWith('.d.ts')) { 60 | return true; 61 | } 62 | 63 | return false; 64 | } 65 | 66 | private isInternal(node: Node): boolean { 67 | if (node && node.comment && node.comment.tags) { 68 | node.comment.tags.forEach(tag => { 69 | if (tag.tag === 'internal') { 70 | return true; 71 | } 72 | }); 73 | } 74 | 75 | return false; 76 | } 77 | } -------------------------------------------------------------------------------- /src/tocGenerator.ts: -------------------------------------------------------------------------------- 1 | import { YamlModel } from './interfaces/YamlModel'; 2 | import { setOfTopLevelItems } from './common/constants'; 3 | import { TocItem } from './interfaces/TocItem'; 4 | import { flags } from './common/flags'; 5 | 6 | function generateItems(element: YamlModel): TocItem { 7 | let result: TocItem; 8 | let itemsDetails: TocItem[] = []; 9 | result = { 10 | uid: element.uid, 11 | name: element.name.split('(')[0], 12 | items: itemsDetails 13 | }; 14 | if (!element.children || element.children.length === 0) { 15 | if (setOfTopLevelItems.has(element.type)) { 16 | return result; 17 | } 18 | return null; 19 | } 20 | let children = element.children as YamlModel[]; 21 | if (children.length > 1) { 22 | if (flags.enableAlphabetOrder) { 23 | children = children.sort(sortTOC); 24 | } 25 | } 26 | children.forEach(child => { 27 | let items = generateItems(child); 28 | if (items) { 29 | itemsDetails.push(items); 30 | } 31 | }); 32 | return result; 33 | } 34 | 35 | export function generateTOC(elements: YamlModel[], packageUid: string): TocItem[] { 36 | let itemsDetails: TocItem[] = []; 37 | if (elements) { 38 | if (elements.length > 1) { 39 | if (flags.enableAlphabetOrder) { 40 | elements = elements.sort(sortTOC); 41 | } 42 | } 43 | elements.forEach(element => { 44 | let items = generateItems(element); 45 | if (items) { 46 | itemsDetails.push(items); 47 | } 48 | }); 49 | 50 | } 51 | 52 | if (itemsDetails.length === 0) { 53 | itemsDetails = null; 54 | } else { 55 | changeTocToOverview(itemsDetails, packageUid); 56 | } 57 | 58 | return [{ 59 | name: packageUid, 60 | items: itemsDetails 61 | }]; 62 | } 63 | 64 | function changeTocToOverview(items: TocItem[], uid: string) { 65 | items.splice(0, 0, { 66 | name: "Overview", 67 | uid: uid 68 | }); 69 | for (let item of items) { 70 | if (item.items && item.items.length > 0) { 71 | const uid = item.uid 72 | delete item.uid 73 | changeTocToOverview(item.items, uid) 74 | } 75 | } 76 | } 77 | 78 | function sortTOC(a: YamlModel, b: YamlModel) { 79 | let nameA = a.name.toUpperCase(); 80 | let nameB = b.name.toUpperCase(); 81 | if (nameA < nameB) { 82 | return -1; 83 | } 84 | if (nameA > nameB) { 85 | return 1; 86 | } 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /src/helpers/linkConvertHelper.ts: -------------------------------------------------------------------------------- 1 | var dfmRegex = [ 2 | /\[(?:([^\]]+))\]{(@link|@link|@linkcode|@linkplain) +(?:module:)?([^}| ]+)}/g, 3 | /\{(@link|@linkcode|@linkplain) +(?:module:)?([^}| ]+)(?:(?:\|| +)([^}]+))?\}/g 4 | ]; 5 | 6 | export function getTextAndLink(text: string) { 7 | var matches = dfmRegex[0].exec(text); 8 | if (matches[1] && matches[3]) { 9 | return [matches[1], matches[3]]; 10 | } 11 | matches = dfmRegex[1].exec(text); 12 | if (matches[3] && matches[2]) { 13 | return [matches[3], matches[2]]; 14 | } 15 | return []; 16 | } 17 | 18 | export function convertLinkToGfm(text: string, uidPrefix: string = null) { 19 | if (!text) return ''; 20 | var dfmLinkRules = [ 21 | { 22 | // [link text]{@link namepathOrURL} 23 | regexp: dfmRegex[0], 24 | callback: function (match: any, p1: any, p2: any, p3: any) { 25 | return generateDfmLink(p2, p3, p1); 26 | } 27 | }, 28 | { 29 | // {@link namepathOrURL} 30 | // {@link namepathOrURL|link text} 31 | // {@link namepathOrURL link text (after the first space)} 32 | regexp: dfmRegex[1], 33 | callback: function (match: any, p1: any, p2: any, p3: any) { 34 | return generateDfmLink(p1, p2, p3); 35 | } 36 | } 37 | ]; 38 | 39 | var result = text; 40 | dfmLinkRules.forEach(function (r) { 41 | result = result.replace(r.regexp, r.callback); 42 | }); 43 | return result; 44 | 45 | function generateDfmLink(tag: string, target: string, text: string) { 46 | var result = ''; 47 | if (!text) { 48 | // if link text is undefined, it must link to namepath(uid) 49 | result = ''; 50 | if (tag === '@linkcode') { 51 | return '' + result + ''; 52 | } 53 | } else { 54 | result = text; 55 | if (tag === '@linkcode') { 56 | result = '' + result + ''; 57 | } 58 | result = '[' + result + ']('; 59 | // http://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url#answer-3809435 60 | if (!/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/.test(target)) { 61 | // if target isn't a url, it must be a namepath(uid) 62 | result += 'xref:'; 63 | target = convertNamepathToUid(target); 64 | } 65 | result += target + ')'; 66 | } 67 | return result; 68 | 69 | function convertNamepathToUid(namepath: string) { 70 | var uid = encodeURIComponent(namepath); 71 | if (uidPrefix) { 72 | uid = uidPrefix + uid; 73 | } 74 | return uid; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/converters/type.ts: -------------------------------------------------------------------------------- 1 | import { YamlModel } from '../interfaces/YamlModel'; 2 | import { Node } from '../interfaces/TypeDocModel'; 3 | import { AbstractConverter } from './base'; 4 | import * as _ from 'lodash'; 5 | import { Context } from './context'; 6 | import { langs } from '../common/constants'; 7 | 8 | export class TypeConverter extends AbstractConverter { 9 | protected generate(node: Node, context: Context): Array { 10 | // to add this to handle duplicate class and module under the same hirachy 11 | if (node.kindString === 'Class' || node.kindString === 'Interface' || node.kindString === 'Type alias') { 12 | if (context.ParentKind === 'Class' || context.ParentKind === 'Interface') { 13 | const currentUid = context.ParentUid + `.${node.name}`; 14 | let mapping: string[] = []; 15 | if (this.references.has(context.ParentUid)) { 16 | mapping = this.references.get(context.ParentUid); 17 | } 18 | mapping.push(currentUid); 19 | this.references.set(context.ParentUid, mapping); 20 | } 21 | } 22 | 23 | const uid = context.ParentUid + `.${node.name}`; 24 | console.log(`${node.kindString}: ${uid}`); 25 | const model: YamlModel = { 26 | uid: uid, 27 | name: node.name, 28 | fullName: node.name + this.getGenericType(node.typeParameter), 29 | children: [], 30 | langs: langs, 31 | type: node.kindString.toLowerCase(), 32 | summary: node.comment ? this.findDescriptionInComment(node.comment) : '' 33 | }; 34 | if (model.type === 'enumeration') { 35 | model.type = 'enum'; 36 | } 37 | 38 | if (model.type === 'type alias') { 39 | let typeArgumentsContent = this.parseTypeArgumentsForTypeAlias(node); 40 | if (typeArgumentsContent) { 41 | model.syntax = { content: 'type ' + model.name + typeArgumentsContent + ' = ' + this.parseTypeDeclarationForTypeAlias(node.type) }; 42 | } else { 43 | model.syntax = { content: 'type ' + model.name + ' = ' + this.parseTypeDeclarationForTypeAlias(node.type) }; 44 | } 45 | } 46 | 47 | if (node.extendedTypes && node.extendedTypes.length) { 48 | model.extends = { 49 | name: this.extractType(node.extendedTypes[0])[0] 50 | }; 51 | } 52 | 53 | if (context.Repo && node.sources && node.sources.length) { 54 | model.source = { 55 | path: node.sources[0].fileName, 56 | // shift one line up as systematic off for TypeDoc 57 | startLine: node.sources[0].line, 58 | remote: { 59 | path: `${context.Repo.basePath}\\${node.sources[0].fileName}`, 60 | repo: context.Repo.repo, 61 | branch: context.Repo.branch 62 | } 63 | }; 64 | } 65 | 66 | return [model]; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/data/enumerations/spec.yml: -------------------------------------------------------------------------------- 1 | - uid: type2docfx.Directions 2 | name: Directions 3 | fullName: Directions 4 | children: 5 | - uid: type2docfx.Directions.Bottom 6 | name: Bottom 7 | children: [] 8 | langs: 9 | - typeScript 10 | summary: A simple enum member. 11 | type: field 12 | package: type2docfx 13 | - uid: type2docfx.Directions.Left 14 | name: Left 15 | children: [] 16 | langs: 17 | - typeScript 18 | summary: A simple enum member. 19 | type: field 20 | package: type2docfx 21 | - uid: type2docfx.Directions.Right 22 | name: Right 23 | children: [] 24 | langs: 25 | - typeScript 26 | summary: A simple enum member. 27 | type: field 28 | package: type2docfx 29 | - uid: type2docfx.Directions.Top 30 | name: Top 31 | children: [] 32 | langs: 33 | - typeScript 34 | summary: A simple enum member. 35 | type: field 36 | package: type2docfx 37 | - uid: type2docfx.Directions.TopLeft 38 | name: TopLeft 39 | children: [] 40 | langs: 41 | - typeScript 42 | summary: A composite enum member. 43 | type: field 44 | numericValue: .nan 45 | package: type2docfx 46 | - uid: type2docfx.Directions.TopRight 47 | name: TopRight 48 | children: [] 49 | langs: 50 | - typeScript 51 | summary: A composite enum member. 52 | type: field 53 | numericValue: .nan 54 | package: type2docfx 55 | langs: 56 | - typeScript 57 | type: enum 58 | summary: This is a simple Enumeration. 59 | package: type2docfx 60 | - uid: type2docfx.Size 61 | name: Size 62 | fullName: Size 63 | children: 64 | - uid: type2docfx.Size.Large 65 | name: Large 66 | children: [] 67 | langs: 68 | - typeScript 69 | summary: A simple enum member. 70 | type: field 71 | package: type2docfx 72 | - uid: type2docfx.Size.Medium 73 | name: Medium 74 | children: [] 75 | langs: 76 | - typeScript 77 | summary: A simple enum member. 78 | type: field 79 | package: type2docfx 80 | - uid: type2docfx.Size.Small 81 | name: Small 82 | children: [] 83 | langs: 84 | - typeScript 85 | summary: A simple enum member. 86 | type: field 87 | package: type2docfx 88 | - uid: type2docfx.Size.isSmall 89 | name: isSmall(Size) 90 | children: [] 91 | type: function 92 | langs: 93 | - typeScript 94 | summary: A function that is attached to an enumeration. 95 | syntax: 96 | content: 'function isSmall(value: Size)' 97 | parameters: 98 | - id: value 99 | type: 100 | - typeName: Size 101 | typeId: ! '' 102 | description: The value that should be tested. 103 | optional: false 104 | return: 105 | type: 106 | - typeName: boolean 107 | typeId: ! '' 108 | description: TRUE when the given value equals Size.Small. 109 | package: type2docfx 110 | langs: 111 | - typeScript 112 | type: enum 113 | summary: | 114 | This is a enumeration extended by a module. 115 | This comment is ignored, as the enumeration is already defined. 116 | You should see both the enum members and the module members. 117 | package: type2docfx -------------------------------------------------------------------------------- /src/idResolver.ts: -------------------------------------------------------------------------------- 1 | import { YamlModel, Type, Types } from './interfaces/YamlModel'; 2 | import { UidMapping } from './interfaces/UidMapping'; 3 | import { ReferenceMapping } from './interfaces/ReferenceMapping'; 4 | import { uidRegex } from './common/regex'; 5 | import { setOfTopLevelItems } from './common/constants'; 6 | 7 | export function resolveIds(element: YamlModel, uidMapping: UidMapping, referenceMapping: ReferenceMapping): void { 8 | if (element.syntax) { 9 | if (element.syntax.parameters) { 10 | for (const p of element.syntax.parameters) { 11 | p.type = restoreReferences(p.type, uidMapping, referenceMapping); 12 | } 13 | } 14 | 15 | if (element.syntax.return) { 16 | element.syntax.return.type = restoreReferences(element.syntax.return.type, uidMapping, referenceMapping); 17 | } 18 | } 19 | 20 | if (element.extends) { 21 | element.extends.name = restoreReferences([element.extends.name as Type], uidMapping, referenceMapping)[0]; 22 | } 23 | 24 | for (const child of element.children as YamlModel[]) { 25 | resolveIds(child, uidMapping, referenceMapping); 26 | if (setOfTopLevelItems.has(child.type)) { 27 | referenceMapping[child.uid] = `@uid:${child.uid}!@`; 28 | } 29 | } 30 | } 31 | 32 | function restoreReferences(types: Types, uidMapping: UidMapping, referenceMapping: ReferenceMapping): string[] { 33 | let restoredTypes = restoreTypes(types, uidMapping); 34 | return restoredTypes.map(restoreType => { 35 | if (restoreType) { 36 | let hasUid = false; 37 | let restoreTypeTrim = restoreType.replace(uidRegex, (match, uid) => { 38 | if (uid) { 39 | hasUid = true; 40 | return uid; 41 | } 42 | return match; 43 | }); 44 | if (hasUid && referenceMapping[restoreTypeTrim] !== null) { 45 | referenceMapping[restoreTypeTrim] = restoreType; 46 | } 47 | return restoreTypeTrim; 48 | } 49 | return restoreType; 50 | }); 51 | } 52 | 53 | function restoreTypes(types: Types, uidMapping: UidMapping): string[] { 54 | if (types) { 55 | return (types as any[]).map(t => restoreType(t, uidMapping)); 56 | } 57 | return null; 58 | } 59 | 60 | function restoreType(type: Type | string, uidMapping: UidMapping): string { 61 | if (typeof (type) === 'string') { 62 | return type; 63 | } 64 | 65 | if (type.reflectedType) { 66 | type.reflectedType.key = restoreType(type.reflectedType.key, uidMapping); 67 | type.reflectedType.value = restoreType(type.reflectedType.value, uidMapping); 68 | } else if (type.genericType) { 69 | type.genericType.inner = (type.genericType.inner as Type[]).map(t => restoreType(t, uidMapping)); 70 | type.genericType.outter = restoreType(type.genericType.outter, uidMapping); 71 | } if (type.unionType) { 72 | type.unionType.types = (type.unionType.types as Type[]).map(t => restoreType(t, uidMapping)); 73 | } else if (type.intersectionType) { 74 | type.intersectionType.types = (type.intersectionType.types as Type[]).map(t => restoreType(t, uidMapping)); 75 | } else if (type.arrayType) { 76 | type.arrayType = restoreType(type.arrayType, uidMapping); 77 | } else { 78 | if (type.typeId && uidMapping[type.typeId]) { 79 | type.typeName = `@uid:${uidMapping[type.typeId]}!@`; 80 | } 81 | } 82 | 83 | return typeToString(type); 84 | } 85 | 86 | export function typeToString(type: Type | string, kind?: string): string { 87 | if (!type) { 88 | return 'function'; 89 | } 90 | 91 | if (typeof (type) === 'string') { 92 | if (type[0] === '@') { 93 | return type; 94 | } else if (kind && kind !== 'Property') { 95 | let t = type.split('.'); 96 | return t[t.length - 1]; 97 | } else { 98 | return type; 99 | } 100 | } 101 | 102 | if (type.reflectedType) { 103 | return `[key: ${typeToString(type.reflectedType.key)}]: ${typeToString(type.reflectedType.value)}`; 104 | } else if (type.genericType) { 105 | return `${typeToString(type.genericType.outter)}<${((type.genericType.inner as Type[]).map(t => typeToString(t)).join(', '))}>`; 106 | } else if (type.unionType) { 107 | return (type.unionType.types as Type[]).map(t => typeToString(t)).join(' | '); 108 | } else if (type.intersectionType) { 109 | return (type.intersectionType.types as Type[]).map(t => typeToString(t)).join(' & '); 110 | } else if (type.arrayType) { 111 | return `${typeToString(type.arrayType)}[]`; 112 | } else { 113 | return typeToString(type.typeName); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /tests/data/functions/sample.ts: -------------------------------------------------------------------------------- 1 | import classes = require('../classes/sample'); 2 | 3 | /** 4 | * This is an internal function. 5 | */ 6 | function internalFunction():void { } 7 | 8 | 9 | /** 10 | * This is a simple exported function. 11 | */ 12 | export function exportedFunction():void { } 13 | 14 | 15 | /** 16 | * This is a function with multiple arguments and a return value. 17 | * @param paramZ This is a string parameter. 18 | * @param paramG This is a parameter flagged with any. 19 | * This sentence is placed in the next line. 20 | * 21 | * @param paramA 22 | * This is a **parameter** pointing to an interface. 23 | * 24 | * ~~~ 25 | * var value:BaseClass = new BaseClass('test'); 26 | * functionWithArguments('arg', 0, value); 27 | * ~~~ 28 | * 29 | */ 30 | var variableFunction = function(paramZ:string, paramG:any, paramA:classes.INameInterface):number { 31 | return 0; 32 | }; 33 | 34 | 35 | /** 36 | * This is a function with multiple arguments and a return value. 37 | * @param paramZ This is a string parameter. 38 | * @param paramG This is a parameter flagged with any. 39 | * This sentence is placed in the next line. 40 | * 41 | * @param paramA 42 | * This is a **parameter** pointing to an interface. 43 | * 44 | * ~~~ 45 | * var value:BaseClass = new BaseClass('test'); 46 | * functionWithArguments('arg', 0, value); 47 | * ~~~ 48 | * 49 | */ 50 | export function functionWithArguments(paramZ:string, paramG:any, paramA:classes.INameInterface):number { 51 | return 0; 52 | } 53 | 54 | 55 | /** 56 | * This is a function with a parameter that is optional. 57 | * 58 | * @param requiredParam A normal parameter. 59 | * @param optionalParam An optional parameter. 60 | */ 61 | export function functionWithOptionalValue(requiredParam:string, optionalParam?:string) { } 62 | 63 | 64 | /** 65 | * This is a function with a parameter that has a default value. 66 | * 67 | * @param value An optional return value. 68 | * @returns The input value or the default value. 69 | */ 70 | export function functionWithDefaults( 71 | valueA:string = 'defaultValue', 72 | valueB:number = 100, 73 | valueC:number = Number.NaN, 74 | valueD:boolean = true, 75 | valueE:boolean = false 76 | ):string { 77 | return valueA; 78 | } 79 | 80 | 81 | /** 82 | * This is a function with rest parameter. 83 | * 84 | * @param rest Multiple strings. 85 | * @returns The combined string. 86 | */ 87 | function functionWithRest(...rest:string[]):string { 88 | return rest.join(', '); 89 | } 90 | 91 | 92 | /** 93 | * This is the first signature of a function with multiple signatures. 94 | * 95 | * @param value The name value. 96 | */ 97 | export function multipleSignatures(value:string):string; 98 | 99 | /** 100 | * This is the second signature of a function with multiple signatures. 101 | * 102 | * @param value An object containing the name value. 103 | * @param value.name A value of the object. 104 | */ 105 | export function multipleSignatures(value:{name:string}):string; 106 | 107 | /** 108 | * This is the actual implementation, this comment will not be visible 109 | * in the generated documentation. 110 | */ 111 | export function multipleSignatures():string { 112 | if (arguments.length > 0) { 113 | if (typeof arguments[0] == 'object') { 114 | return arguments[0].name; 115 | } else { 116 | return arguments[0]; 117 | } 118 | } 119 | 120 | return ''; 121 | } 122 | 123 | 124 | /** 125 | * This is a generic function. 126 | * 127 | * @param T The type parameter. 128 | * @param value The typed value. 129 | * @return Returns the typed value. 130 | */ 131 | export function genericFunction(value:T):T { 132 | return value; 133 | } 134 | 135 | 136 | /** 137 | * This is a function that is extended by a module. 138 | * 139 | * @param arg An argument. 140 | */ 141 | export function moduleFunction(arg:string):string { return ''; } 142 | 143 | 144 | /** 145 | * This is the module extending the function moduleFunction(). 146 | */ 147 | export module moduleFunction 148 | { 149 | /** 150 | * This variable is appended to a function. 151 | */ 152 | var functionVariable:string; 153 | 154 | 155 | /** 156 | * This function is appended to another function. 157 | */ 158 | function append() { 159 | 160 | } 161 | 162 | /** 163 | * This function is appended to another function. 164 | */ 165 | function prepend() { 166 | 167 | } 168 | } 169 | 170 | 171 | /** 172 | * A function that returns an object. 173 | * Also no type information is given, the object should be correctly reflected. 174 | */ 175 | export function createSomething() { 176 | return { 177 | foo: 'bar', 178 | doSomething: (a:number) => a + 1, 179 | doAnotherThing: () => {} 180 | }; 181 | } 182 | 183 | 184 | /** 185 | * See {@linkcode INameInterface} and [INameInterface's name property]{@link INameInterface.name}. 186 | * Also, check out {@link https://www.google.com|Google} and 187 | * {@link https://github.com GitHub}. 188 | * 189 | * Taken from http://usejsdoc.org/tags-inline-link.html. 190 | */ 191 | export function functionWithDocLink():void { } -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import * as fs from 'fs-extra'; 4 | import * as serializer from 'js-yaml'; 5 | import * as program from 'commander'; 6 | import { Parser } from './parser'; 7 | import { postTransform, insertClassReferenceForModule, insertInnerClassReference } from './postTransformer'; 8 | import { generateTOC } from './tocGenerator'; 9 | import { generatePackage } from './packageGenerator'; 10 | import { resolveIds } from './idResolver'; 11 | import { YamlModel } from './interfaces/YamlModel'; 12 | import { UidMapping } from './interfaces/UidMapping'; 13 | import { RepoConfig } from './interfaces/RepoConfig'; 14 | import { yamlHeader } from './common/constants'; 15 | import { flags } from './common/flags'; 16 | import { ReferenceMapping } from './interfaces/ReferenceMapping'; 17 | import { Context } from './converters/context'; 18 | import { Node } from './interfaces/TypeDocModel'; 19 | 20 | let pjson = require('../package.json'); 21 | 22 | let path: string; 23 | let outputPath: string; 24 | let repoConfigPath: string; 25 | program 26 | .version(`v${pjson.version}`) 27 | .description('A tool to convert the json format api file generated by TypeDoc to yaml format output files for docfx.') 28 | .option('--hasModule', 'Add the option if the source repository contains module.') 29 | .option('--disableAlphabetOrder', 'Add the option if you want to disable the alphabet order in output yaml.') 30 | .option('--basePath [value]', 'Current base path to the repository.') 31 | .option('--sourceUrl [value]', 'Define the source repository address.') 32 | .option('--sourceBranch [value]', 'Define the branch of source repository.') 33 | .arguments(' [repoConfigureFile]') 34 | .action(function (input: string, output: string, repoConfig: string) { 35 | path = input; 36 | outputPath = output; 37 | repoConfigPath = repoConfig; 38 | }) 39 | .parse(process.argv); 40 | 41 | if (!path || !outputPath) { 42 | console.log('Error: The input file path and output folder path is not specified!'); 43 | program.help(); 44 | } 45 | 46 | let repoConfig: RepoConfig; 47 | if (repoConfigPath && program.basePath) { 48 | if (fs.existsSync(repoConfigPath)) { 49 | let temp = JSON.parse(fs.readFileSync(repoConfigPath).toString()); 50 | repoConfig = { 51 | repo: temp.repo, 52 | branch: temp.branch, 53 | basePath: program.basePath 54 | }; 55 | } else { 56 | console.log(`Error: repository config file path {${repoConfigPath}} doesn't exit!`); 57 | program.help(); 58 | } 59 | } 60 | 61 | if (!repoConfig && program.sourceUrl && program.sourceBranch && program.basePath) { 62 | repoConfig = { 63 | repo: program.sourceUrl, 64 | branch: program.sourceBranch, 65 | basePath: program.basePath 66 | }; 67 | } 68 | 69 | if (program.disableAlphabetOrder) { 70 | flags.enableAlphabetOrder = false; 71 | } 72 | 73 | let json = null; 74 | if (fs.existsSync(path)) { 75 | let dataStr = fs.readFileSync(path).toString(); 76 | json = JSON.parse(dataStr) as Node; 77 | } else { 78 | console.error(`API doc file ${path} doesn\'t exist.`); 79 | program.help(); 80 | } 81 | 82 | const uidMapping: UidMapping = {}; 83 | const innerClassReferenceMapping = new Map(); 84 | 85 | let collection: YamlModel[] = []; 86 | if (json) { 87 | const context = new Context(repoConfig, '', '', json.name, new Map()); 88 | collection = new Parser().traverse(json, uidMapping, context); 89 | } 90 | 91 | if (!collection || collection.length === 0) { 92 | console.log("Warning: nothing genereatd."); 93 | } 94 | 95 | const referenceMappings: ReferenceMapping[] = []; 96 | for (const rootElement of collection) { 97 | let referenceMapping = {}; 98 | resolveIds(rootElement, uidMapping, referenceMapping); 99 | referenceMappings.push(referenceMapping); 100 | } 101 | 102 | const rootElementsForTOC = JSON.parse(JSON.stringify(collection)); 103 | const flattenElements = collection.map((rootElement, index) => { 104 | if (rootElement.uid.indexOf('constructor') >= 0) { 105 | return []; 106 | } 107 | 108 | return postTransform(rootElement, referenceMappings[index]); 109 | }).reduce(function (a, b) { 110 | return a.concat(b); 111 | }, []); 112 | 113 | insertClassReferenceForModule(flattenElements); 114 | console.log('Yaml dump start.'); 115 | fs.ensureDirSync(outputPath); 116 | 117 | for (let transfomredClass of flattenElements) { 118 | // to add this to handle duplicate class and module under the same hierachy 119 | insertInnerClassReference(innerClassReferenceMapping, transfomredClass); 120 | transfomredClass = JSON.parse(JSON.stringify(transfomredClass)); 121 | let filename = transfomredClass.items[0].uid.replace(`${transfomredClass.items[0].package}.`, ''); 122 | filename = filename.split('(')[0]; 123 | filename = filename.replace(/\//g, '.'); 124 | console.log(`Dump ${outputPath}/${filename}.yml`); 125 | fs.writeFileSync(`${outputPath}/${filename}.yml`, `${yamlHeader}\n${serializer.safeDump(transfomredClass)}`); 126 | } 127 | 128 | console.log('Yaml dump end.'); 129 | 130 | const yamlModels: YamlModel[] = []; 131 | flattenElements.forEach(element => { 132 | yamlModels.push(element.items[0]); 133 | }); 134 | 135 | const packageIndex = generatePackage(yamlModels); 136 | fs.writeFileSync(`${outputPath}/index.yml`, `${yamlHeader}\n${serializer.safeDump(packageIndex)}`); 137 | console.log('Package index generated.'); 138 | 139 | const toc = generateTOC(rootElementsForTOC, flattenElements[0].items[0].package); 140 | fs.writeFileSync(`${outputPath}/toc.yml`, serializer.safeDump(toc)); 141 | console.log('Toc generated.'); 142 | -------------------------------------------------------------------------------- /src/postTransformer.ts: -------------------------------------------------------------------------------- 1 | import { YamlModel, Root, Reference } from './interfaces/YamlModel'; 2 | import { constructorName, setOfTopLevelItems } from './common/constants'; 3 | import { uidRegex } from './common/regex'; 4 | import { flags } from './common/flags'; 5 | import { ReferenceMapping } from './interfaces/ReferenceMapping'; 6 | 7 | export function groupOrphanFunctions(elements: YamlModel[]): { [key: string]: YamlModel[] } { 8 | if (elements && elements.length) { 9 | let mapping: { [key: string]: YamlModel[] } = {}; 10 | for (let i = 0; i < elements.length; i++) { 11 | if (elements[i].type === 'function') { 12 | let key = elements[i].module ? elements[i].module : 'ParentToPackage'; 13 | if (!mapping[key]) { 14 | mapping[key] = []; 15 | } 16 | mapping[key].push(elements[i]); 17 | elements.splice(i, 1); 18 | i--; 19 | } 20 | } 21 | return mapping; 22 | } 23 | } 24 | 25 | export function insertFunctionToIndex(index: Root, functions: YamlModel[]) { 26 | if (index && functions) { 27 | index.items[0].children = (index.items[0].children as string[]).concat(functions.map(f => f.uid)); 28 | index.items = index.items.concat(functions); 29 | } 30 | } 31 | 32 | export function postTransform(element: YamlModel, references: ReferenceMapping): Root[] { 33 | let roots = flattening(element); 34 | for (const root of roots) { 35 | insertReferences(root, references); 36 | } 37 | 38 | return roots; 39 | } 40 | 41 | function insertReferences(root: Root, references: ReferenceMapping): void { 42 | if (!references || Object.keys(references).length === 0) { 43 | return; 44 | } 45 | 46 | root.references = []; 47 | for (let key in references) { 48 | let names = key.split('.'); 49 | let reference: Reference = { 50 | uid: key, 51 | name: names[names.length - 1], 52 | 'spec.typeScript': [] 53 | }; 54 | 55 | let match; 56 | let lastIndex = 0; 57 | while ((match = uidRegex.exec(references[key])) !== null) { 58 | if (lastIndex < match.index) { 59 | reference['spec.typeScript'].push(getReference(references[key].substring(lastIndex, match.index))); 60 | } 61 | lastIndex = match.index + match[0].length; 62 | reference['spec.typeScript'].push(getReference(getItemName(match[1]), match[1])); 63 | } 64 | 65 | if (lastIndex < references[key].length) { 66 | reference['spec.typeScript'].push(getReference(references[key].substring(lastIndex))); 67 | } 68 | 69 | root.references.push(reference); 70 | } 71 | } 72 | 73 | // to add this function due to classes under modules need to be cross reference 74 | export function insertClassReferenceForModule(flattenElements: Root[]) { 75 | for (const element of flattenElements) { 76 | if (element.items[0].type !== 'module') { 77 | continue; 78 | } 79 | 80 | if (!element.references) { 81 | element.references = [] 82 | continue; 83 | } 84 | 85 | let children = element.items[0].children as string[]; 86 | for (const child of children) { 87 | let find = false; 88 | for (const ref of element.references) { 89 | if (ref.uid === child) { 90 | find = true; 91 | break; 92 | } 93 | } 94 | 95 | if (!find) { 96 | const names = child.split('.'); 97 | const reference: Reference = { 98 | uid: child, 99 | name: names[names.length - 1] 100 | }; 101 | element.references.push(reference); 102 | } 103 | } 104 | } 105 | } 106 | 107 | export function insertInnerClassReference(innerClassReferenceMapping: Map, transfomredClass: Root) { 108 | if ((transfomredClass.items[0].type === 'class' || transfomredClass.items[0].type === 'interface') && innerClassReferenceMapping.has(transfomredClass.items[0].uid)) { 109 | const reference = transfomredClass.references || []; 110 | const referencedClass = innerClassReferenceMapping.get(transfomredClass.items[0].uid); 111 | referencedClass.forEach(function (item) { 112 | const names = item.split('.'); 113 | const ref: Reference = { 114 | uid: item, 115 | name: names[names.length - 1] 116 | }; 117 | reference.push(ref); 118 | }); 119 | } 120 | } 121 | 122 | function getReference(name: string, uid?: string): Reference { 123 | let reference: Reference = { 124 | name: name, 125 | fullName: name 126 | }; 127 | 128 | if (uid) { 129 | reference.uid = uid; 130 | } 131 | 132 | return reference; 133 | } 134 | 135 | function getItemName(uid: string): string { 136 | let tmp = uid.split('.'); 137 | return tmp[tmp.length - 1]; 138 | } 139 | 140 | function flattening(element: YamlModel): Root[] { 141 | if (!element) { 142 | return []; 143 | } 144 | 145 | let result: Root[] = []; 146 | result.push({ 147 | items: [element] 148 | }); 149 | 150 | if (element.children) { 151 | const childrenUid: string[] = []; 152 | let children = element.children as YamlModel[]; 153 | if (flags.enableAlphabetOrder) { 154 | children = children.sort(sortYamlModel); 155 | } 156 | 157 | for (const child of children) { 158 | if (child.children && child.children.length > 0) { 159 | result = result.concat(flattening(child)); 160 | } else if (setOfTopLevelItems.has(child.type)) { 161 | let resultWithoutChild: Root[] = []; 162 | resultWithoutChild.push({ 163 | items: [child] 164 | }); 165 | result = result.concat(resultWithoutChild); 166 | } else { 167 | result[0].items.push(child); 168 | } 169 | if (child.type !== 'module') { 170 | childrenUid.push(child.uid); 171 | } 172 | } 173 | 174 | element.children = childrenUid; 175 | return result; 176 | } 177 | } 178 | 179 | function sortYamlModel(a: YamlModel, b: YamlModel): number { 180 | if (a.numericValue !== undefined && b.numericValue !== undefined) { 181 | return a.numericValue - b.numericValue; 182 | } 183 | 184 | // sort classes alphabetically, contructor first 185 | if (b.name === constructorName) { 186 | return 1; 187 | } 188 | if (a.name === constructorName) { 189 | return -1; 190 | } 191 | 192 | let nameA = a.name.toUpperCase(); 193 | let nameB = b.name.toUpperCase(); 194 | if (nameA < nameB) { 195 | return -1; 196 | } 197 | if (nameA > nameB) { 198 | return 1; 199 | } 200 | 201 | return 0; 202 | } 203 | -------------------------------------------------------------------------------- /tests/data/functions/spec.yml: -------------------------------------------------------------------------------- 1 | - uid: type2docfx.moduleFunction 2 | name: moduleFunction 3 | langs: 4 | - typeScript 5 | fullName: moduleFunction 6 | children: [] 7 | type: module 8 | summary: This is the module extending the function moduleFunction(). 9 | package: type2docfx 10 | - uid: type2docfx.createSomething 11 | name: createSomething() 12 | children: [] 13 | type: function 14 | langs: 15 | - typeScript 16 | summary: |- 17 | A function that returns an object. 18 | Also no type information is given, the object should be correctly reflected. 19 | syntax: 20 | content: function createSomething() 21 | parameters: [] 22 | return: 23 | type: 24 | - typeName: Object 25 | description: '' 26 | package: type2docfx 27 | - uid: type2docfx.exportedFunction 28 | name: exportedFunction() 29 | children: [] 30 | type: function 31 | langs: 32 | - typeScript 33 | summary: This is a simple exported function. 34 | syntax: 35 | content: function exportedFunction() 36 | parameters: [] 37 | package: type2docfx 38 | - uid: type2docfx.functionWithArguments 39 | name: 'functionWithArguments(string, any, INameInterface)' 40 | children: [] 41 | type: function 42 | langs: 43 | - typeScript 44 | summary: This is a function with multiple arguments and a return value. 45 | syntax: 46 | content: >- 47 | function functionWithArguments(paramZ: string, paramG: any, paramA: 48 | INameInterface) 49 | parameters: 50 | - id: paramZ 51 | type: 52 | - typeName: string 53 | typeId: ! '' 54 | description: This is a string parameter. 55 | optional: false 56 | - id: paramG 57 | type: 58 | - typeName: any 59 | typeId: ! '' 60 | description: | 61 | This is a parameter flagged with any. 62 | This sentence is placed in the next line. 63 | optional: false 64 | - id: paramA 65 | type: 66 | - typeName: INameInterface 67 | typeId: ! '' 68 | description: |+ 69 | 70 | This is a **parameter** pointing to an interface. 71 | 72 | ~~~ 73 | var value:BaseClass = new BaseClass('test'); 74 | functionWithArguments('arg', 0, value); 75 | ~~~ 76 | 77 | optional: false 78 | return: 79 | type: 80 | - typeName: number 81 | typeId: ! '' 82 | description: '' 83 | package: type2docfx 84 | - uid: type2docfx.functionWithDefaults 85 | name: 'functionWithDefaults(string, number, number, boolean, boolean)' 86 | children: [] 87 | type: function 88 | langs: 89 | - typeScript 90 | summary: This is a function with a parameter that has a default value. 91 | syntax: 92 | content: >- 93 | function functionWithDefaults(valueA: string, valueB: number, valueC: 94 | number, valueD: boolean, valueE: boolean) 95 | parameters: 96 | - id: valueA 97 | type: 98 | - typeName: string 99 | typeId: ! '' 100 | description: '' 101 | optional: false 102 | - id: valueB 103 | type: 104 | - typeName: number 105 | typeId: ! '' 106 | description: '' 107 | optional: false 108 | - id: valueC 109 | type: 110 | - typeName: number 111 | typeId: ! '' 112 | description: '' 113 | optional: false 114 | - id: valueD 115 | type: 116 | - typeName: boolean 117 | typeId: ! '' 118 | description: '' 119 | optional: false 120 | - id: valueE 121 | type: 122 | - typeName: boolean 123 | typeId: ! '' 124 | description: '' 125 | optional: false 126 | return: 127 | type: 128 | - typeName: string 129 | typeId: ! '' 130 | description: The input value or the default value. 131 | package: type2docfx 132 | - uid: type2docfx.functionWithDocLink 133 | name: functionWithDocLink() 134 | children: [] 135 | type: function 136 | langs: 137 | - typeScript 138 | summary: > 139 | See and [INameInterface's name 140 | property](xref:INameInterface.name). 141 | 142 | Also, check out [Google](https://www.google.com) and 143 | 144 | [GitHub](https://github.com). 145 | 146 | Taken from http://usejsdoc.org/tags-inline-link.html. 147 | syntax: 148 | content: function functionWithDocLink() 149 | parameters: [] 150 | package: type2docfx 151 | - uid: type2docfx.functionWithOptionalValue 152 | name: 'functionWithOptionalValue(string, string)' 153 | children: [] 154 | type: function 155 | langs: 156 | - typeScript 157 | summary: This is a function with a parameter that is optional. 158 | syntax: 159 | content: >- 160 | function functionWithOptionalValue(requiredParam: string, optionalParam?: 161 | string) 162 | parameters: 163 | - id: requiredParam 164 | type: 165 | - typeName: string 166 | typeId: ! '' 167 | description: A normal parameter. 168 | optional: false 169 | - id: optionalParam 170 | type: 171 | - typeName: string 172 | typeId: ! '' 173 | description: | 174 | An optional parameter. 175 | optional: true 176 | package: type2docfx 177 | - uid: type2docfx.genericFunction 178 | name: genericFunction(T) 179 | children: [] 180 | type: function 181 | langs: 182 | - typeScript 183 | summary: This is a generic function. 184 | syntax: 185 | content: 'function genericFunction(value: T)' 186 | parameters: 187 | - id: value 188 | type: 189 | - typeName: T 190 | typeId: ! '' 191 | description: The typed value. 192 | optional: false 193 | return: 194 | type: 195 | - typeName: T 196 | typeId: ! '' 197 | description: Returns the typed value. 198 | package: type2docfx 199 | - uid: type2docfx.multipleSignatures 200 | name: multipleSignatures(string) 201 | children: [] 202 | type: function 203 | langs: 204 | - typeScript 205 | summary: This is the first signature of a function with multiple signatures. 206 | syntax: 207 | content: 'function multipleSignatures(value: string)' 208 | parameters: 209 | - id: value 210 | type: 211 | - typeName: string 212 | typeId: ! '' 213 | description: | 214 | The name value. 215 | optional: false 216 | return: 217 | type: 218 | - typeName: string 219 | typeId: ! '' 220 | description: '' 221 | package: type2docfx 222 | - uid: type2docfx.multipleSignatures_1 223 | name: multipleSignatures(Object) 224 | children: [] 225 | type: function 226 | langs: 227 | - typeScript 228 | summary: This is the second signature of a function with multiple signatures. 229 | syntax: 230 | content: 'function multipleSignatures(value: Object)' 231 | parameters: 232 | - id: value 233 | type: 234 | - typeName: Object 235 | description: An object containing the name value. 236 | optional: false 237 | return: 238 | type: 239 | - typeName: string 240 | typeId: ! '' 241 | description: '' 242 | package: type2docfx -------------------------------------------------------------------------------- /tests/data/classes/sample.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This is a simple interface. 3 | */ 4 | export interface INameInterface 5 | { 6 | /** 7 | * This is a interface member of INameInterface. 8 | * 9 | * It should be inherited by all subinterfaces. 10 | */ 11 | name:string; 12 | 13 | /** 14 | * This is a interface function of INameInterface. 15 | * 16 | * It should be inherited by all subinterfaces. 17 | */ 18 | getName():string; 19 | } 20 | 21 | 22 | /** 23 | * This is a simple interface. 24 | */ 25 | export interface IPrintInterface 26 | { 27 | /** 28 | * This is a interface function of IPrintInterface 29 | * 30 | * It should be inherited by all subinterfaces. 31 | */ 32 | print(value:string):void; 33 | } 34 | 35 | 36 | /** 37 | * This is a interface inheriting from two other interfaces. 38 | */ 39 | export interface IPrintNameInterface extends INameInterface, IPrintInterface 40 | { 41 | /** 42 | * This is a interface function of IPrintNameInterface 43 | */ 44 | printName():void; 45 | } 46 | 47 | 48 | /** 49 | * This is a simple base class. 50 | * 51 | * [[include:class-example.md]] 52 | */ 53 | export abstract class BaseClass implements INameInterface 54 | { 55 | /** 56 | * This is a simple public member. 57 | */ 58 | public name:string; 59 | 60 | /** 61 | * This is a simple protected member. 62 | */ 63 | protected kind:number; 64 | 65 | /** 66 | * This is a static member. 67 | * 68 | * Static members should not be inherited. 69 | */ 70 | static instance:BaseClass; 71 | static instances:BaseClass[]; 72 | 73 | /** 74 | * This is an instance member of an internal class. 75 | */ 76 | private internalClass:InternalClass; 77 | 78 | 79 | constructor(name:string); 80 | constructor(source:BaseClass); 81 | constructor() { 82 | if (arguments.length > 0) { 83 | if (typeof arguments[0] == 'string') { 84 | this.name = arguments[0]; 85 | } else if (arguments[0] instanceof BaseClass) { 86 | this.name = arguments[0].name; 87 | } 88 | } 89 | 90 | this.checkName(); 91 | } 92 | 93 | public abstract abstractMethod(): void; 94 | 95 | /** 96 | * This is a simple member function. 97 | * 98 | * It should be inherited by all subclasses. This class has a static 99 | * member with the same name, both should be documented. 100 | * 101 | * @returns Return the name. 102 | */ 103 | public getName():string { 104 | return this.name; 105 | } 106 | 107 | 108 | /** 109 | * This is a simple static member function. 110 | * 111 | * Static functions should not be inherited. This class has a 112 | * member with the same name, both should be documented. 113 | * 114 | * @returns Return the name. 115 | */ 116 | static getName():string { 117 | return 'A name'; 118 | } 119 | 120 | 121 | /** 122 | * This is a simple member function. 123 | * 124 | * It should be inherited by all subclasses. 125 | * 126 | * @param name The new name. 127 | */ 128 | public setName(name:string) { 129 | this.name = name; 130 | this.checkName(); 131 | } 132 | 133 | 134 | /** 135 | * This is a simple fat arrow function. 136 | * 137 | * @param param1 The first parameter needed by this function. 138 | * @param param2 The second parameter needed by this function. 139 | * @see https://github.com/sebastian-lenz/typedoc/issues/37 140 | */ 141 | public arrowFunction = (param2: string, param1: number): void => { 142 | }; 143 | 144 | 145 | /** 146 | * This is a private function. 147 | */ 148 | private checkName() { 149 | return true; 150 | } 151 | 152 | 153 | /** 154 | * This is a static function. 155 | * 156 | * Static functions should not be inherited. 157 | * 158 | * @returns An instance of BaseClass. 159 | */ 160 | static getInstance():BaseClass { 161 | return BaseClass.instance; 162 | } 163 | 164 | 165 | /** 166 | * @see https://github.com/sebastian-lenz/typedoc/issues/42 167 | */ 168 | public static caTest(originalValues:BaseClass, newRecord: any, fieldNames:string[], mandatoryFields:string[]): string { 169 | var returnval = ""; 170 | var updates: string[] = []; 171 | var allFields: string[] = fieldNames; 172 | for (var j = 0; j < allFields.length; j++) { 173 | var field = allFields[j]; 174 | var oldValue = originalValues[field]; 175 | var newValue = newRecord[field]; 176 | } 177 | return returnval; 178 | } 179 | } 180 | 181 | /** 182 | * This is an internal class, it is not exported. 183 | */ 184 | class InternalClass 185 | { 186 | constructor(options:{name:string}) { 187 | 188 | } 189 | } 190 | 191 | /** 192 | * This is a class that extends another class. 193 | * 194 | * This class has no own constructor, so its constructor should be inherited 195 | * from BaseClass. 196 | */ 197 | export class SubClassA extends BaseClass implements IPrintNameInterface 198 | { 199 | public name:string; 200 | 201 | /** 202 | * This is a simple interface function. 203 | */ 204 | public print(value:string):void { } 205 | 206 | /** 207 | * @inheritdoc 208 | */ 209 | public printName():void { 210 | this.print(this.getName()); 211 | } 212 | 213 | /** 214 | * Returns the name. See [[BaseClass.name]]. 215 | * 216 | * @returns The return value. 217 | */ 218 | public get nameProperty():string { 219 | return this.name; 220 | } 221 | 222 | /** 223 | * Sets the name. See [[BaseClass.name]]. 224 | * 225 | * @param value The new name. 226 | * @returns The return value. 227 | */ 228 | public set nameProperty(value:string) { 229 | this.name = value; 230 | } 231 | 232 | /** 233 | * Returns the name. See [[BaseClass.name]]. 234 | * 235 | * @returns The return value. 236 | */ 237 | public get readOnlyNameProperty():string { 238 | return this.name; 239 | } 240 | 241 | /** 242 | * Sets the name. See [[BaseClass.name]]. 243 | * 244 | * @param value The new name. 245 | * @returns The return value. 246 | */ 247 | public set writeOnlyNameProperty(value:string) { 248 | this.name = value; 249 | } 250 | 251 | public abstractMethod(): void { 252 | 253 | } 254 | } 255 | 256 | /** 257 | * This is a class that extends another class. 258 | * 259 | * The constructor of the original class should be overwritten. 260 | */ 261 | export class SubClassB extends BaseClass 262 | { 263 | public name: string; 264 | 265 | constructor(name:string) { 266 | super(name); 267 | } 268 | 269 | abstractMethod(): void { 270 | 271 | } 272 | 273 | doSomething(value:[string, SubClassA, SubClassB]) { 274 | } 275 | } 276 | 277 | /** 278 | * This is a generic class. 279 | * 280 | * @param T This a type parameter. 281 | */ 282 | export class GenericClass 283 | { 284 | public value:T; 285 | 286 | /** 287 | * Constructor short text. 288 | * 289 | * @param p1 Constructor param 290 | * @param p2 Private string property 291 | * @param p3 Public number property 292 | * @param p4 Public implicit any property 293 | * @param p5 Readonly property 294 | */ 295 | constructor(p1, protected p2:T, public p3:number, private p4:number, readonly p5: string) { 296 | } 297 | 298 | /** 299 | * @param value [[getValue]] is the counterpart. 300 | */ 301 | public setValue(value:T) { 302 | this.value = value; 303 | } 304 | 305 | public getValue():T { 306 | return this.value; 307 | } 308 | } 309 | 310 | /** 311 | * This a non generic class derived from a [[GenericClass|generic class]]. 312 | */ 313 | export class NonGenericClass extends GenericClass { 314 | 315 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /src/converters/base.ts: -------------------------------------------------------------------------------- 1 | import { YamlModel, YamlParameter, Type } from '../interfaces/YamlModel'; 2 | import { Node, Parameter, Comment, ParameterType } from '../interfaces/TypeDocModel'; 3 | import { typeToString } from '../idResolver'; 4 | import { convertLinkToGfm, getTextAndLink } from '../helpers/linkConvertHelper'; 5 | import { Context } from './context'; 6 | 7 | export abstract class AbstractConverter { 8 | protected references: Map; 9 | 10 | public constructor(references: Map) { 11 | this.references = references; 12 | } 13 | 14 | public convert(node: Node, context: Context): Array { 15 | var models = this.generate(node, context) || []; 16 | for (const model of models) { 17 | model.summary = convertLinkToGfm(model.summary); 18 | model.package = context.PackageName; 19 | 20 | this.setSource(model, node, context); 21 | 22 | if (node.comment || node.signatures && node.signatures.length && node.signatures[0].comment) { 23 | this.setCustomModuleName(model, node.comment); 24 | 25 | const comment = node.comment ? node.comment : node.signatures[0].comment; 26 | this.setDeprecated(model, comment); 27 | this.setIsPreview(model, comment); 28 | this.setRemarks(model, comment); 29 | this.setInherits(model, comment); 30 | } 31 | } 32 | 33 | return models; 34 | } 35 | 36 | protected abstract generate(node: Node, context: Context): Array; 37 | 38 | private setSource(model: YamlModel, node: Node, context: Context) { 39 | if (context.Repo && node.sources && node.sources.length) { 40 | model.source = { 41 | path: node.sources[0].fileName, 42 | // shift one line up as systematic off for TypeDoc 43 | startLine: node.sources[0].line, 44 | remote: { 45 | path: `${context.Repo.basePath}\\${node.sources[0].fileName}`, 46 | repo: context.Repo.repo, 47 | branch: context.Repo.branch 48 | } 49 | }; 50 | } 51 | } 52 | 53 | private setDeprecated(model: YamlModel, comment: Comment) { 54 | const deprecated = this.extractTextFromComment('deprecated', comment); 55 | if (deprecated != null) { 56 | model.deprecated = { 57 | content: convertLinkToGfm(deprecated) 58 | }; 59 | } 60 | } 61 | 62 | private setIsPreview(model: YamlModel, comment: Comment) { 63 | const isPreview = this.extractTextFromComment('beta', comment); 64 | if (isPreview != null) { 65 | model.isPreview = true; 66 | } 67 | } 68 | 69 | private setRemarks(model: YamlModel, comment: Comment) { 70 | const remarks = this.extractTextFromComment('remarks', comment); 71 | if (remarks != null) { 72 | model.remarks = convertLinkToGfm(remarks); 73 | } 74 | } 75 | 76 | private setCustomModuleName(model: YamlModel, comment: Comment) { 77 | const customModuleName = this.extractTextFromComment('module', comment); 78 | if (customModuleName) { 79 | model.module = customModuleName; 80 | } 81 | } 82 | 83 | private setInherits(model: YamlModel, comment: Comment) { 84 | const inherits = this.extractTextFromComment('inherits', comment); 85 | if (inherits != null) { 86 | const tokens = getTextAndLink(inherits); 87 | if (tokens.length === 2) { 88 | model.extends = { 89 | name: tokens[0], 90 | href: tokens[1] 91 | }; 92 | } 93 | } 94 | } 95 | 96 | private extractTextFromComment(infoName: string, comment: Comment): string { 97 | if (comment && comment.tags) { 98 | for (const tag of comment.tags) { 99 | if (tag.tag === infoName) { 100 | return tag.text.trim(); 101 | } 102 | } 103 | } 104 | 105 | return null; 106 | } 107 | 108 | protected getGenericType(typeParameters: ParameterType[]): string { 109 | if (typeParameters && typeParameters.length) { 110 | return `<${typeParameters[0].name}>`; 111 | } 112 | return ''; 113 | } 114 | 115 | protected findDescriptionInComment(comment: Comment): string { 116 | if (!comment) { 117 | return ''; 118 | } 119 | 120 | if (comment.tags) { 121 | let text: string = null; 122 | comment.tags.forEach(tag => { 123 | if (tag.tag === 'classdesc' 124 | || tag.tag === 'description' 125 | || tag.tag === 'exemptedapi' 126 | || tag.tag === 'property') { 127 | text = tag.text.trim(); 128 | return; 129 | } 130 | }); 131 | if (text) { 132 | return text.trim(); 133 | } 134 | } 135 | 136 | if (comment.shortText && comment.text) { 137 | return `${comment.shortText}\n${comment.text}`; 138 | } 139 | 140 | if (comment.text) { 141 | return comment.text.trim(); 142 | } 143 | 144 | if (comment.shortText) { 145 | return comment.shortText.trim(); 146 | } 147 | 148 | return ''; 149 | } 150 | 151 | protected extractType(type: ParameterType): Type[] { 152 | let result: Type[] = []; 153 | if (type === undefined) { 154 | return result; 155 | } 156 | if (type.type === 'union' && type.types && type.types.length) { 157 | if (this.hasCommonPrefix(type.types)) { 158 | result.push({ 159 | typeName: type.types[0].name.split('.')[0] 160 | }); 161 | } else { 162 | result.push({ 163 | unionType: { 164 | types: type.types.map(t => this.extractType(t)[0]) 165 | } 166 | }); 167 | } 168 | } else if (type.type === 'array') { 169 | let newType = this.extractType(type.elementType); 170 | result.push({ 171 | arrayType: newType[0] 172 | }); 173 | } else if (type.type === 'intersection' && type.types.length) { 174 | result.push({ 175 | intersectionType: { 176 | types: type.types.map(t => this.extractType(t)[0]) 177 | } 178 | }); 179 | } else if (type.type === 'reflection' && type.declaration) { 180 | if (type.declaration.indexSignature) { 181 | let signatures = type.declaration.indexSignature; 182 | signatures.forEach(signature => { 183 | result.push({ 184 | reflectedType: { 185 | key: { 186 | typeName: signature.parameters[0].type.name, 187 | typeId: signature.parameters[0].type.id 188 | }, 189 | value: { 190 | typeName: signature.type.name, 191 | typeId: signature.type.id 192 | } 193 | } 194 | }); 195 | }); 196 | } else if (type.declaration.signatures && type.declaration.signatures.length) { 197 | result.push({ 198 | typeName: `${this.generateCallFunction('', this.fillParameters(type.declaration.signatures[0].parameters))} => ${typeToString(this.extractType(type.declaration.signatures[0].type)[0])}` 199 | }); 200 | } else { 201 | result.push({ 202 | typeName: 'Object' 203 | }); 204 | } 205 | } else if (type.typeArguments && type.typeArguments.length) { 206 | result.push({ 207 | genericType: { 208 | outter: { 209 | typeName: type.name, 210 | typeId: type.id 211 | }, 212 | inner: type.typeArguments.map(t => this.extractType(t)[0]) 213 | } 214 | }); 215 | } else if (type.name) { 216 | result.push({ 217 | typeName: type.name, 218 | typeId: type.id 219 | }); 220 | } else if (type.value) { 221 | result.push({ 222 | typeName: `"${type.value}"` 223 | }); 224 | } else { 225 | result.push({ 226 | typeName: 'Object' 227 | }); 228 | } 229 | 230 | return result; 231 | } 232 | 233 | protected hasCommonPrefix(types: ParameterType[]): boolean { 234 | if (types && types.length > 1 && types[0].name) { 235 | if (types[0].name.indexOf('.') < 0) { 236 | return false; 237 | } 238 | let prefix = types[0].name.split('.')[0]; 239 | types.forEach(t => { 240 | if (!t.name || t.name.split('.')[0] !== prefix) { 241 | return false; 242 | } 243 | }); 244 | return true; 245 | } 246 | return false; 247 | } 248 | 249 | protected generateCallFunction(prefix: string, parameters: YamlParameter[], typeParameters?: ParameterType[]): string { 250 | if (parameters) { 251 | return `${prefix}${this.getGenericType(typeParameters)}(${parameters.map(p => `${p.id}${p.optional ? '?' : ''}: ${(typeToString(p.type[0]))}`).join(', ')})`; 252 | } 253 | return ''; 254 | } 255 | 256 | protected fillParameters(parameters: Parameter[]): YamlParameter[] { 257 | if (parameters) { 258 | return parameters.map(p => { 259 | let description = ''; 260 | if (p.comment) { 261 | description = (p.comment.shortText && p.comment.shortText !== '') ? p.comment.shortText : p.comment.text; 262 | } 263 | return { 264 | id: p.name, 265 | type: this.extractType(p.type), 266 | description: convertLinkToGfm(description), 267 | optional: p.flags && p.flags.isOptional 268 | }; 269 | }); 270 | } 271 | return []; 272 | } 273 | 274 | protected extractReturnComment(comment: Comment): string { 275 | if (comment == null || comment.returns == null) { 276 | return ''; 277 | } 278 | 279 | return comment.returns.trim(); 280 | } 281 | 282 | protected extractInformationFromSignature(method: YamlModel, node: Node, signatureIndex: number) { 283 | if (node.signatures[signatureIndex].comment) { 284 | method.summary = this.findDescriptionInComment(node.signatures[signatureIndex].comment); 285 | } 286 | method.syntax.parameters = this.fillParameters(node.signatures[signatureIndex].parameters); 287 | 288 | if (node.signatures[signatureIndex].type && node.kindString !== 'Constructor' && node.signatures[signatureIndex].type.name !== 'void') { 289 | method.syntax.return = { 290 | type: this.extractType(node.signatures[signatureIndex].type), 291 | description: this.extractReturnComment(node.signatures[signatureIndex].comment) 292 | }; 293 | } 294 | // comment the exception handling for now as template doesn't support it, so CI will not be blocked. 295 | /* 296 | let exceptions; 297 | if (node.signatures[signatureIndex].comment && node.signatures[signatureIndex].comment.tags) { 298 | exceptions = node.signatures[signatureIndex].comment.tags.filter(tag => tag.tag === 'throws'); 299 | } 300 | 301 | if (exceptions && exceptions.length) { 302 | method.exceptions = exceptions.map(e => extractException(e)); 303 | } 304 | */ 305 | if (node.kindString === 'Method' || node.kindString === 'Function') { 306 | const typeParameter = node.signatures[signatureIndex].typeParameter 307 | method.name = `${node.name}${this.getGenericType(typeParameter)}`; 308 | const functionBody = this.generateCallFunction(method.name, method.syntax.parameters, typeParameter); 309 | method.syntax.content = `${node.flags && node.flags.isStatic ? 'static ' : ''}function ${functionBody}`; 310 | method.type = node.kindString.toLowerCase(); 311 | } else { 312 | method.name = method.uid.split('.').reverse()[1]; 313 | const functionBody = this.generateCallFunction(method.name, method.syntax.parameters); 314 | method.syntax.content = `new ${functionBody}`; 315 | method.type = 'constructor'; 316 | } 317 | } 318 | 319 | protected composeMethodNameFromSignature(method: YamlModel): string { 320 | const parameterType = method.syntax.parameters.map(p => { 321 | return typeToString(p.type[0]); 322 | }).join(', '); 323 | return method.name + '(' + parameterType + ')'; 324 | } 325 | 326 | protected parseTypeArgumentsForTypeAlias(node: Node | ParameterType): string { 327 | let typeParameter; 328 | if ((node).typeParameter) { 329 | typeParameter = (node).typeParameter; 330 | } else if ((node).typeArguments) { 331 | typeParameter = (node).typeArguments; 332 | } 333 | if (typeParameter && typeParameter.length) { 334 | let typeArgumentsList = typeParameter.map(item => { 335 | return item.name; 336 | }).join(','); 337 | typeArgumentsList = '<' + typeArgumentsList + '>'; 338 | return typeArgumentsList; 339 | } 340 | return ''; 341 | } 342 | 343 | protected parseTypeDeclarationForTypeAlias(typeInfo: ParameterType): string { 344 | switch (typeInfo.type) { 345 | case 'union': 346 | return this.parseUnionType(typeInfo); 347 | case 'tuple': 348 | return this.parseTupleType(typeInfo); 349 | case 'reflection': 350 | if (typeInfo.declaration) { 351 | if (typeInfo.declaration.signatures && typeInfo.declaration.signatures.length) { 352 | return this.parseFunctionType(typeInfo); 353 | } 354 | if (typeInfo.declaration.children) { 355 | return this.parseUserDefinedType(typeInfo); 356 | } 357 | return 'Object'; 358 | } 359 | break; 360 | case 'intersection': 361 | return this.parseIntersection(typeInfo); 362 | default: 363 | let content = 'Object'; 364 | if (typeInfo.name) { 365 | content = typeInfo.name; 366 | } else if (typeInfo.value) { 367 | content = typeInfo.value; 368 | } 369 | if (typeInfo.typeArguments && typeInfo.typeArguments.length) { 370 | content += this.parseTypeArgumentsForTypeAlias(typeInfo); 371 | } 372 | return content; 373 | } 374 | } 375 | 376 | protected parseUnionType(typeInfo: ParameterType): string { 377 | let content = ''; 378 | if (typeInfo.types && typeInfo.types.length) { 379 | content = this.parseCommonTypeInfo(typeInfo, 'union', ' | '); 380 | } 381 | return content; 382 | } 383 | 384 | protected parseTupleType(typeInfo: ParameterType): string { 385 | let content = ''; 386 | if (typeInfo.elements && typeInfo.elements.length) { 387 | content = this.parseCommonTypeInfo(typeInfo, 'tuple', ', '); 388 | } 389 | content = '[ ' + content + ' ]'; 390 | return content; 391 | } 392 | 393 | protected parseIntersection(typeInfo: ParameterType): string { 394 | if (typeInfo.types && typeInfo.types.length) { 395 | return this.parseCommonTypeInfo(typeInfo, 'intersection', ' & '); 396 | } 397 | return ''; 398 | } 399 | 400 | protected parseCommonTypeInfo(typeInfo: ParameterType, type: string, seperator: string): string { 401 | let typeDeclaration; 402 | if (type === 'tuple') { 403 | typeDeclaration = typeInfo.elements; 404 | } else { 405 | typeDeclaration = typeInfo.types; 406 | } 407 | let content = typeDeclaration.map(item => { 408 | if (item.name) { 409 | // for generic 410 | if (item.typeArguments && item.typeArguments.length) { 411 | return item.name + '<' + item.typeArguments[0].name + '>'; 412 | } else { 413 | return item.name; 414 | } 415 | } else if (item.value) { 416 | return `"${item.value}"`; 417 | } else if (item.type === 'array' && item.elementType) { 418 | return `${item.elementType.name}[]`; 419 | } 420 | else { 421 | return this.parseUserDefinedType(item); 422 | } 423 | }).join(seperator); 424 | return content; 425 | } 426 | 427 | protected parseFunctionType(typeInfo: ParameterType): string { 428 | let typeResult = this.extractType(typeInfo); 429 | let content = ''; 430 | if (typeResult.length) { 431 | content = typeResult[0].typeName; 432 | } 433 | return content; 434 | } 435 | 436 | protected parseUserDefinedType(typeInfo: ParameterType): string { 437 | if (!typeInfo.declaration || !typeInfo.declaration.children) { 438 | return ''; 439 | } 440 | let content = typeInfo.declaration.children.map(child => { 441 | let type = ''; 442 | if (child.kindString === 'Variable') { 443 | if (child.type.name) { 444 | let typeName = ''; 445 | if (child.type.typeArguments && child.type.typeArguments.length) { 446 | typeName = child.type.name + '<' + child.type.typeArguments[0].name + '>'; 447 | } else { 448 | typeName = child.type.name; 449 | } 450 | type = `${child.name}: ${typeName}`; 451 | } else if (child.type.value) { 452 | type = `${child.name}: ${child.type.value}`; 453 | } else { 454 | type = `${child.name}: Object`; 455 | } 456 | } else if (child.kindString === 'Function') { 457 | type = `${this.generateCallFunction(child.name, this.fillParameters(child.signatures[0].parameters))} => ${typeToString(this.extractType(child.signatures[0].type)[0])}`; 458 | } 459 | return type; 460 | 461 | }).join(', '); 462 | content = '{ ' + content + ' }'; 463 | return content; 464 | } 465 | 466 | } -------------------------------------------------------------------------------- /tests/data/classes/spec.yml: -------------------------------------------------------------------------------- 1 | - uid: type2docfx.BaseClass 2 | name: BaseClass 3 | fullName: BaseClass 4 | children: 5 | - uid: type2docfx.BaseClass.constructor 6 | name: BaseClass(string) 7 | children: [] 8 | type: constructor 9 | langs: 10 | - typeScript 11 | summary: '' 12 | syntax: 13 | content: 'new BaseClass(name: string)' 14 | parameters: 15 | - id: name 16 | type: 17 | - typeName: string 18 | typeId: ! '' 19 | description: '' 20 | optional: false 21 | package: type2docfx 22 | - uid: type2docfx.BaseClass.constructor_1 23 | name: BaseClass(BaseClass) 24 | children: [] 25 | type: constructor 26 | langs: 27 | - typeScript 28 | summary: '' 29 | syntax: 30 | content: 'new BaseClass(source: BaseClass)' 31 | parameters: 32 | - id: source 33 | type: 34 | - typeName: BaseClass 35 | typeId: ! '' 36 | description: '' 37 | optional: false 38 | package: type2docfx 39 | - uid: type2docfx.BaseClass.name 40 | name: name 41 | fullName: name 42 | children: [] 43 | langs: 44 | - typeScript 45 | type: property 46 | summary: This is a simple public member. 47 | optional: false 48 | syntax: 49 | content: 'public name: string' 50 | return: 51 | type: 52 | - typeName: string 53 | typeId: ! '' 54 | description: '' 55 | package: type2docfx 56 | - uid: type2docfx.BaseClass.instance 57 | name: instance 58 | fullName: instance 59 | children: [] 60 | langs: 61 | - typeScript 62 | type: property 63 | summary: | 64 | This is a static member. 65 | Static members should not be inherited. 66 | optional: false 67 | syntax: 68 | content: 'static instance: BaseClass' 69 | return: 70 | type: 71 | - typeName: BaseClass 72 | typeId: ! '' 73 | description: '' 74 | package: type2docfx 75 | - uid: type2docfx.BaseClass.instances 76 | name: instances 77 | fullName: instances 78 | children: [] 79 | langs: 80 | - typeScript 81 | type: property 82 | summary: '' 83 | optional: false 84 | syntax: 85 | content: 'static instances: BaseClass[]' 86 | return: 87 | type: 88 | - arrayType: 89 | typeName: BaseClass 90 | typeId: ! '' 91 | description: '' 92 | package: type2docfx 93 | - uid: type2docfx.BaseClass.abstractMethod 94 | name: abstractMethod() 95 | children: [] 96 | type: method 97 | langs: 98 | - typeScript 99 | summary: '' 100 | syntax: 101 | content: function abstractMethod() 102 | parameters: [] 103 | package: type2docfx 104 | - uid: type2docfx.BaseClass.arrowFunction 105 | name: 'arrowFunction(string, number)' 106 | children: [] 107 | type: method 108 | langs: 109 | - typeScript 110 | summary: This is a simple fat arrow function. 111 | syntax: 112 | content: 'function arrowFunction(param2: string, param1: number)' 113 | parameters: 114 | - id: param2 115 | type: 116 | - typeName: string 117 | typeId: ! '' 118 | description: The second parameter needed by this function. 119 | optional: false 120 | - id: param1 121 | type: 122 | - typeName: number 123 | typeId: ! '' 124 | description: The first parameter needed by this function. 125 | optional: false 126 | package: type2docfx 127 | - uid: type2docfx.BaseClass.getName 128 | name: getName() 129 | children: [] 130 | type: method 131 | langs: 132 | - typeScript 133 | summary: | 134 | This is a simple member function. 135 | It should be inherited by all subclasses. This class has a static 136 | member with the same name, both should be documented. 137 | syntax: 138 | content: function getName() 139 | parameters: [] 140 | return: 141 | type: 142 | - typeName: string 143 | typeId: ! '' 144 | description: Return the name. 145 | package: type2docfx 146 | - uid: type2docfx.BaseClass.setName 147 | name: setName(string) 148 | children: [] 149 | type: method 150 | langs: 151 | - typeScript 152 | summary: | 153 | This is a simple member function. 154 | It should be inherited by all subclasses. 155 | syntax: 156 | content: 'function setName(name: string)' 157 | parameters: 158 | - id: name 159 | type: 160 | - typeName: string 161 | typeId: ! '' 162 | description: | 163 | The new name. 164 | optional: false 165 | package: type2docfx 166 | - uid: type2docfx.BaseClass.caTest 167 | name: 'caTest(BaseClass, any, string[], string[])' 168 | children: [] 169 | type: method 170 | langs: 171 | - typeScript 172 | summary: '' 173 | syntax: 174 | content: >- 175 | static function caTest(originalValues: BaseClass, newRecord: any, 176 | fieldNames: string[], mandatoryFields: string[]) 177 | parameters: 178 | - id: originalValues 179 | type: 180 | - typeName: BaseClass 181 | typeId: ! '' 182 | description: '' 183 | optional: false 184 | - id: newRecord 185 | type: 186 | - typeName: any 187 | typeId: ! '' 188 | description: '' 189 | optional: false 190 | - id: fieldNames 191 | type: 192 | - arrayType: 193 | typeName: string 194 | typeId: ! '' 195 | description: '' 196 | optional: false 197 | - id: mandatoryFields 198 | type: 199 | - arrayType: 200 | typeName: string 201 | typeId: ! '' 202 | description: '' 203 | optional: false 204 | return: 205 | type: 206 | - typeName: string 207 | typeId: ! '' 208 | description: '' 209 | package: type2docfx 210 | - uid: type2docfx.BaseClass.getInstance 211 | name: getInstance() 212 | children: [] 213 | type: method 214 | langs: 215 | - typeScript 216 | summary: | 217 | This is a static function. 218 | Static functions should not be inherited. 219 | syntax: 220 | content: static function getInstance() 221 | parameters: [] 222 | return: 223 | type: 224 | - typeName: BaseClass 225 | typeId: ! '' 226 | description: An instance of BaseClass. 227 | package: type2docfx 228 | - uid: type2docfx.BaseClass.getName 229 | name: getName() 230 | children: [] 231 | type: method 232 | langs: 233 | - typeScript 234 | summary: | 235 | This is a simple static member function. 236 | Static functions should not be inherited. This class has a 237 | member with the same name, both should be documented. 238 | syntax: 239 | content: static function getName() 240 | parameters: [] 241 | return: 242 | type: 243 | - typeName: string 244 | typeId: ! '' 245 | description: Return the name. 246 | package: type2docfx 247 | langs: 248 | - typeScript 249 | type: class 250 | summary: | 251 | This is a simple base class. 252 | [[include:class-example.md]] 253 | package: type2docfx 254 | - uid: type2docfx.GenericClass 255 | name: GenericClass 256 | fullName: GenericClass 257 | children: 258 | - uid: type2docfx.GenericClass.constructor 259 | name: 'GenericClass(any, T, number, number, string)' 260 | children: [] 261 | type: constructor 262 | langs: 263 | - typeScript 264 | summary: Constructor short text. 265 | syntax: 266 | content: 'new GenericClass(p1: any, p2: T, p3: number, p4: number, p5: string)' 267 | parameters: 268 | - id: p1 269 | type: 270 | - typeName: any 271 | typeId: ! '' 272 | description: Constructor param 273 | optional: false 274 | - id: p2 275 | type: 276 | - typeName: T 277 | typeId: ! '' 278 | description: Private string property 279 | optional: false 280 | - id: p3 281 | type: 282 | - typeName: number 283 | typeId: ! '' 284 | description: Public number property 285 | optional: false 286 | - id: p4 287 | type: 288 | - typeName: number 289 | typeId: ! '' 290 | description: Public implicit any property 291 | optional: false 292 | - id: p5 293 | type: 294 | - typeName: string 295 | typeId: ! '' 296 | description: | 297 | Readonly property 298 | optional: false 299 | package: type2docfx 300 | - uid: type2docfx.GenericClass.p3 301 | name: p3 302 | fullName: p3 303 | children: [] 304 | langs: 305 | - typeScript 306 | type: property 307 | summary: Public number property 308 | optional: false 309 | syntax: 310 | content: 'public p3: number' 311 | return: 312 | type: 313 | - typeName: number 314 | typeId: ! '' 315 | description: '' 316 | package: type2docfx 317 | - uid: type2docfx.GenericClass.p5 318 | name: p5 319 | fullName: p5 320 | children: [] 321 | langs: 322 | - typeScript 323 | type: property 324 | summary: Readonly property 325 | optional: false 326 | syntax: 327 | content: 'p5: string' 328 | return: 329 | type: 330 | - typeName: string 331 | typeId: ! '' 332 | description: '' 333 | package: type2docfx 334 | - uid: type2docfx.GenericClass.value 335 | name: value 336 | fullName: value 337 | children: [] 338 | langs: 339 | - typeScript 340 | type: property 341 | summary: '' 342 | optional: false 343 | syntax: 344 | content: 'public value: T' 345 | return: 346 | type: 347 | - typeName: T 348 | typeId: ! '' 349 | description: '' 350 | package: type2docfx 351 | - uid: type2docfx.GenericClass.getValue 352 | name: getValue() 353 | children: [] 354 | type: method 355 | langs: 356 | - typeScript 357 | summary: '' 358 | syntax: 359 | content: function getValue() 360 | parameters: [] 361 | return: 362 | type: 363 | - typeName: T 364 | typeId: ! '' 365 | description: '' 366 | package: type2docfx 367 | - uid: type2docfx.GenericClass.setValue 368 | name: setValue(T) 369 | children: [] 370 | type: method 371 | langs: 372 | - typeScript 373 | summary: '' 374 | syntax: 375 | content: 'function setValue(value: T)' 376 | parameters: 377 | - id: value 378 | type: 379 | - typeName: T 380 | typeId: ! '' 381 | description: | 382 | [[getValue]] is the counterpart. 383 | optional: false 384 | package: type2docfx 385 | langs: 386 | - typeScript 387 | type: class 388 | summary: This is a generic class. 389 | package: type2docfx 390 | - uid: type2docfx.NonGenericClass 391 | name: NonGenericClass 392 | fullName: NonGenericClass 393 | children: 394 | - uid: type2docfx.NonGenericClass.constructor 395 | name: 'NonGenericClass(any, SubClassB, number, number, string)' 396 | children: [] 397 | type: constructor 398 | langs: 399 | - typeScript 400 | summary: Constructor short text. 401 | syntax: 402 | content: >- 403 | new NonGenericClass(p1: any, p2: SubClassB, p3: number, p4: number, 404 | p5: string) 405 | parameters: 406 | - id: p1 407 | type: 408 | - typeName: any 409 | typeId: ! '' 410 | description: Constructor param 411 | optional: false 412 | - id: p2 413 | type: 414 | - typeName: SubClassB 415 | typeId: ! '' 416 | description: Private string property 417 | optional: false 418 | - id: p3 419 | type: 420 | - typeName: number 421 | typeId: ! '' 422 | description: Public number property 423 | optional: false 424 | - id: p4 425 | type: 426 | - typeName: number 427 | typeId: ! '' 428 | description: Public implicit any property 429 | optional: false 430 | - id: p5 431 | type: 432 | - typeName: string 433 | typeId: ! '' 434 | description: | 435 | Readonly property 436 | optional: false 437 | package: type2docfx 438 | - uid: type2docfx.NonGenericClass.p3 439 | name: p3 440 | fullName: p3 441 | children: [] 442 | langs: 443 | - typeScript 444 | type: property 445 | summary: Public number property 446 | optional: false 447 | syntax: 448 | content: 'public p3: number' 449 | return: 450 | type: 451 | - typeName: number 452 | typeId: ! '' 453 | description: '' 454 | package: type2docfx 455 | - uid: type2docfx.NonGenericClass.p5 456 | name: p5 457 | fullName: p5 458 | children: [] 459 | langs: 460 | - typeScript 461 | type: property 462 | summary: Readonly property 463 | optional: false 464 | syntax: 465 | content: 'p5: string' 466 | return: 467 | type: 468 | - typeName: string 469 | typeId: ! '' 470 | description: '' 471 | package: type2docfx 472 | - uid: type2docfx.NonGenericClass.value 473 | name: value 474 | fullName: value 475 | children: [] 476 | langs: 477 | - typeScript 478 | type: property 479 | summary: '' 480 | optional: false 481 | syntax: 482 | content: 'public value: SubClassB' 483 | return: 484 | type: 485 | - typeName: SubClassB 486 | typeId: ! '' 487 | description: '' 488 | package: type2docfx 489 | - uid: type2docfx.NonGenericClass.getValue 490 | name: getValue() 491 | children: [] 492 | type: method 493 | langs: 494 | - typeScript 495 | summary: '' 496 | syntax: 497 | content: function getValue() 498 | parameters: [] 499 | return: 500 | type: 501 | - typeName: SubClassB 502 | typeId: ! '' 503 | description: '' 504 | package: type2docfx 505 | - uid: type2docfx.NonGenericClass.setValue 506 | name: setValue(SubClassB) 507 | children: [] 508 | type: method 509 | langs: 510 | - typeScript 511 | summary: '' 512 | syntax: 513 | content: 'function setValue(value: SubClassB)' 514 | parameters: 515 | - id: value 516 | type: 517 | - typeName: SubClassB 518 | typeId: ! '' 519 | description: | 520 | [[getValue]] is the counterpart. 521 | optional: false 522 | package: type2docfx 523 | langs: 524 | - typeScript 525 | type: class 526 | summary: 'This a non generic class derived from a [[GenericClass|generic class]].' 527 | extends: 528 | name: 529 | genericType: 530 | outter: 531 | typeName: GenericClass 532 | typeId: ! '' 533 | inner: 534 | - typeName: SubClassB 535 | typeId: ! '' 536 | package: type2docfx 537 | - uid: type2docfx.SubClassA 538 | name: SubClassA 539 | fullName: SubClassA 540 | children: 541 | - uid: type2docfx.SubClassA.constructor 542 | name: SubClassA(string) 543 | children: [] 544 | type: constructor 545 | langs: 546 | - typeScript 547 | summary: '' 548 | syntax: 549 | content: 'new SubClassA(name: string)' 550 | parameters: 551 | - id: name 552 | type: 553 | - typeName: string 554 | typeId: ! '' 555 | description: '' 556 | optional: false 557 | package: type2docfx 558 | - uid: type2docfx.SubClassA.constructor_1 559 | name: SubClassA(BaseClass) 560 | children: [] 561 | type: constructor 562 | langs: 563 | - typeScript 564 | summary: '' 565 | syntax: 566 | content: 'new SubClassA(source: BaseClass)' 567 | parameters: 568 | - id: source 569 | type: 570 | - typeName: BaseClass 571 | typeId: ! '' 572 | description: '' 573 | optional: false 574 | package: type2docfx 575 | - uid: type2docfx.SubClassA.name 576 | name: name 577 | fullName: name 578 | children: [] 579 | langs: 580 | - typeScript 581 | type: property 582 | summary: '' 583 | optional: false 584 | syntax: 585 | content: 'public name: string' 586 | return: 587 | type: 588 | - typeName: string 589 | typeId: ! '' 590 | description: '' 591 | package: type2docfx 592 | - uid: type2docfx.SubClassA.instance 593 | name: instance 594 | fullName: instance 595 | children: [] 596 | langs: 597 | - typeScript 598 | type: property 599 | summary: | 600 | This is a static member. 601 | Static members should not be inherited. 602 | optional: false 603 | syntax: 604 | content: 'static instance: BaseClass' 605 | return: 606 | type: 607 | - typeName: BaseClass 608 | typeId: ! '' 609 | description: '' 610 | package: type2docfx 611 | - uid: type2docfx.SubClassA.instances 612 | name: instances 613 | fullName: instances 614 | children: [] 615 | langs: 616 | - typeScript 617 | type: property 618 | summary: '' 619 | optional: false 620 | syntax: 621 | content: 'static instances: BaseClass[]' 622 | return: 623 | type: 624 | - arrayType: 625 | typeName: BaseClass 626 | typeId: ! '' 627 | description: '' 628 | package: type2docfx 629 | - uid: type2docfx.SubClassA.nameProperty 630 | name: nameProperty 631 | fullName: nameProperty 632 | children: [] 633 | langs: 634 | - typeScript 635 | type: property 636 | summary: |- 637 | Returns the name. See [[BaseClass.name]]. 638 | Sets the name. See [[BaseClass.name]]. 639 | syntax: 640 | content: string nameProperty 641 | return: 642 | type: 643 | - typeName: string 644 | typeId: ! '' 645 | description: The return value. 646 | package: type2docfx 647 | - uid: type2docfx.SubClassA.readOnlyNameProperty 648 | name: readOnlyNameProperty 649 | fullName: readOnlyNameProperty 650 | children: [] 651 | langs: 652 | - typeScript 653 | type: property 654 | summary: 'Returns the name. See [[BaseClass.name]].' 655 | syntax: 656 | content: string readOnlyNameProperty 657 | return: 658 | type: 659 | - typeName: string 660 | typeId: ! '' 661 | description: The return value. 662 | package: type2docfx 663 | - uid: type2docfx.SubClassA.writeOnlyNameProperty 664 | name: writeOnlyNameProperty 665 | fullName: writeOnlyNameProperty 666 | children: [] 667 | langs: 668 | - typeScript 669 | type: property 670 | summary: 'Sets the name. See [[BaseClass.name]].' 671 | syntax: 672 | content: void writeOnlyNameProperty 673 | return: 674 | type: 675 | - typeName: void 676 | typeId: ! '' 677 | description: The return value. 678 | package: type2docfx 679 | - uid: type2docfx.SubClassA.abstractMethod 680 | name: abstractMethod() 681 | children: [] 682 | type: method 683 | langs: 684 | - typeScript 685 | summary: '' 686 | syntax: 687 | content: function abstractMethod() 688 | parameters: [] 689 | package: type2docfx 690 | - uid: type2docfx.SubClassA.arrowFunction 691 | name: 'arrowFunction(string, number)' 692 | children: [] 693 | type: method 694 | langs: 695 | - typeScript 696 | summary: This is a simple fat arrow function. 697 | syntax: 698 | content: 'function arrowFunction(param2: string, param1: number)' 699 | parameters: 700 | - id: param2 701 | type: 702 | - typeName: string 703 | typeId: ! '' 704 | description: The second parameter needed by this function. 705 | optional: false 706 | - id: param1 707 | type: 708 | - typeName: number 709 | typeId: ! '' 710 | description: The first parameter needed by this function. 711 | optional: false 712 | package: type2docfx 713 | - uid: type2docfx.SubClassA.getName 714 | name: getName() 715 | children: [] 716 | type: method 717 | langs: 718 | - typeScript 719 | summary: | 720 | This is a simple member function. 721 | It should be inherited by all subclasses. This class has a static 722 | member with the same name, both should be documented. 723 | syntax: 724 | content: function getName() 725 | parameters: [] 726 | return: 727 | type: 728 | - typeName: string 729 | typeId: ! '' 730 | description: Return the name. 731 | package: type2docfx 732 | - uid: type2docfx.SubClassA.print 733 | name: print(string) 734 | children: [] 735 | type: method 736 | langs: 737 | - typeScript 738 | summary: This is a simple interface function. 739 | syntax: 740 | content: 'function print(value: string)' 741 | parameters: 742 | - id: value 743 | type: 744 | - typeName: string 745 | typeId: ! '' 746 | description: '' 747 | optional: false 748 | package: type2docfx 749 | - uid: type2docfx.SubClassA.printName 750 | name: printName() 751 | children: [] 752 | type: method 753 | langs: 754 | - typeScript 755 | summary: This is a interface function of IPrintNameInterface 756 | syntax: 757 | content: function printName() 758 | parameters: [] 759 | package: type2docfx 760 | - uid: type2docfx.SubClassA.setName 761 | name: setName(string) 762 | children: [] 763 | type: method 764 | langs: 765 | - typeScript 766 | summary: | 767 | This is a simple member function. 768 | It should be inherited by all subclasses. 769 | syntax: 770 | content: 'function setName(name: string)' 771 | parameters: 772 | - id: name 773 | type: 774 | - typeName: string 775 | typeId: ! '' 776 | description: | 777 | The new name. 778 | optional: false 779 | package: type2docfx 780 | - uid: type2docfx.SubClassA.caTest 781 | name: 'caTest(BaseClass, any, string[], string[])' 782 | children: [] 783 | type: method 784 | langs: 785 | - typeScript 786 | summary: '' 787 | syntax: 788 | content: >- 789 | static function caTest(originalValues: BaseClass, newRecord: any, 790 | fieldNames: string[], mandatoryFields: string[]) 791 | parameters: 792 | - id: originalValues 793 | type: 794 | - typeName: BaseClass 795 | typeId: ! '' 796 | description: '' 797 | optional: false 798 | - id: newRecord 799 | type: 800 | - typeName: any 801 | typeId: ! '' 802 | description: '' 803 | optional: false 804 | - id: fieldNames 805 | type: 806 | - arrayType: 807 | typeName: string 808 | typeId: ! '' 809 | description: '' 810 | optional: false 811 | - id: mandatoryFields 812 | type: 813 | - arrayType: 814 | typeName: string 815 | typeId: ! '' 816 | description: '' 817 | optional: false 818 | return: 819 | type: 820 | - typeName: string 821 | typeId: ! '' 822 | description: '' 823 | package: type2docfx 824 | - uid: type2docfx.SubClassA.getInstance 825 | name: getInstance() 826 | children: [] 827 | type: method 828 | langs: 829 | - typeScript 830 | summary: | 831 | This is a static function. 832 | Static functions should not be inherited. 833 | syntax: 834 | content: static function getInstance() 835 | parameters: [] 836 | return: 837 | type: 838 | - typeName: BaseClass 839 | typeId: ! '' 840 | description: An instance of BaseClass. 841 | package: type2docfx 842 | - uid: type2docfx.SubClassA.getName 843 | name: getName() 844 | children: [] 845 | type: method 846 | langs: 847 | - typeScript 848 | summary: | 849 | This is a simple static member function. 850 | Static functions should not be inherited. This class has a 851 | member with the same name, both should be documented. 852 | syntax: 853 | content: static function getName() 854 | parameters: [] 855 | return: 856 | type: 857 | - typeName: string 858 | typeId: ! '' 859 | description: Return the name. 860 | package: type2docfx 861 | langs: 862 | - typeScript 863 | type: class 864 | summary: | 865 | This is a class that extends another class. 866 | This class has no own constructor, so its constructor should be inherited 867 | from BaseClass. 868 | extends: 869 | name: 870 | typeName: BaseClass 871 | typeId: ! '' 872 | package: type2docfx 873 | - uid: type2docfx.SubClassB 874 | name: SubClassB 875 | fullName: SubClassB 876 | children: 877 | - uid: type2docfx.SubClassB.constructor 878 | name: SubClassB(string) 879 | children: [] 880 | type: constructor 881 | langs: 882 | - typeScript 883 | summary: '' 884 | syntax: 885 | content: 'new SubClassB(name: string)' 886 | parameters: 887 | - id: name 888 | type: 889 | - typeName: string 890 | typeId: ! '' 891 | description: '' 892 | optional: false 893 | package: type2docfx 894 | - uid: type2docfx.SubClassB.name 895 | name: name 896 | fullName: name 897 | children: [] 898 | langs: 899 | - typeScript 900 | type: property 901 | summary: '' 902 | optional: false 903 | syntax: 904 | content: 'public name: string' 905 | return: 906 | type: 907 | - typeName: string 908 | typeId: ! '' 909 | description: '' 910 | package: type2docfx 911 | - uid: type2docfx.SubClassB.instance 912 | name: instance 913 | fullName: instance 914 | children: [] 915 | langs: 916 | - typeScript 917 | type: property 918 | summary: | 919 | This is a static member. 920 | Static members should not be inherited. 921 | optional: false 922 | syntax: 923 | content: 'static instance: BaseClass' 924 | return: 925 | type: 926 | - typeName: BaseClass 927 | typeId: ! '' 928 | description: '' 929 | package: type2docfx 930 | - uid: type2docfx.SubClassB.instances 931 | name: instances 932 | fullName: instances 933 | children: [] 934 | langs: 935 | - typeScript 936 | type: property 937 | summary: '' 938 | optional: false 939 | syntax: 940 | content: 'static instances: BaseClass[]' 941 | return: 942 | type: 943 | - arrayType: 944 | typeName: BaseClass 945 | typeId: ! '' 946 | description: '' 947 | package: type2docfx 948 | - uid: type2docfx.SubClassB.abstractMethod 949 | name: abstractMethod() 950 | children: [] 951 | type: method 952 | langs: 953 | - typeScript 954 | summary: '' 955 | syntax: 956 | content: function abstractMethod() 957 | parameters: [] 958 | package: type2docfx 959 | - uid: type2docfx.SubClassB.arrowFunction 960 | name: 'arrowFunction(string, number)' 961 | children: [] 962 | type: method 963 | langs: 964 | - typeScript 965 | summary: This is a simple fat arrow function. 966 | syntax: 967 | content: 'function arrowFunction(param2: string, param1: number)' 968 | parameters: 969 | - id: param2 970 | type: 971 | - typeName: string 972 | typeId: ! '' 973 | description: The second parameter needed by this function. 974 | optional: false 975 | - id: param1 976 | type: 977 | - typeName: number 978 | typeId: ! '' 979 | description: The first parameter needed by this function. 980 | optional: false 981 | package: type2docfx 982 | - uid: type2docfx.SubClassB.doSomething 983 | name: doSomething(Object) 984 | children: [] 985 | type: method 986 | langs: 987 | - typeScript 988 | summary: '' 989 | syntax: 990 | content: 'function doSomething(value: Object)' 991 | parameters: 992 | - id: value 993 | type: 994 | - typeName: Object 995 | description: '' 996 | optional: false 997 | package: type2docfx 998 | - uid: type2docfx.SubClassB.getName 999 | name: getName() 1000 | children: [] 1001 | type: method 1002 | langs: 1003 | - typeScript 1004 | summary: | 1005 | This is a simple member function. 1006 | It should be inherited by all subclasses. This class has a static 1007 | member with the same name, both should be documented. 1008 | syntax: 1009 | content: function getName() 1010 | parameters: [] 1011 | return: 1012 | type: 1013 | - typeName: string 1014 | typeId: ! '' 1015 | description: Return the name. 1016 | package: type2docfx 1017 | - uid: type2docfx.SubClassB.setName 1018 | name: setName(string) 1019 | children: [] 1020 | type: method 1021 | langs: 1022 | - typeScript 1023 | summary: | 1024 | This is a simple member function. 1025 | It should be inherited by all subclasses. 1026 | syntax: 1027 | content: 'function setName(name: string)' 1028 | parameters: 1029 | - id: name 1030 | type: 1031 | - typeName: string 1032 | typeId: ! '' 1033 | description: | 1034 | The new name. 1035 | optional: false 1036 | package: type2docfx 1037 | - uid: type2docfx.SubClassB.caTest 1038 | name: 'caTest(BaseClass, any, string[], string[])' 1039 | children: [] 1040 | type: method 1041 | langs: 1042 | - typeScript 1043 | summary: '' 1044 | syntax: 1045 | content: >- 1046 | static function caTest(originalValues: BaseClass, newRecord: any, 1047 | fieldNames: string[], mandatoryFields: string[]) 1048 | parameters: 1049 | - id: originalValues 1050 | type: 1051 | - typeName: BaseClass 1052 | typeId: ! '' 1053 | description: '' 1054 | optional: false 1055 | - id: newRecord 1056 | type: 1057 | - typeName: any 1058 | typeId: ! '' 1059 | description: '' 1060 | optional: false 1061 | - id: fieldNames 1062 | type: 1063 | - arrayType: 1064 | typeName: string 1065 | typeId: ! '' 1066 | description: '' 1067 | optional: false 1068 | - id: mandatoryFields 1069 | type: 1070 | - arrayType: 1071 | typeName: string 1072 | typeId: ! '' 1073 | description: '' 1074 | optional: false 1075 | return: 1076 | type: 1077 | - typeName: string 1078 | typeId: ! '' 1079 | description: '' 1080 | package: type2docfx 1081 | - uid: type2docfx.SubClassB.getInstance 1082 | name: getInstance() 1083 | children: [] 1084 | type: method 1085 | langs: 1086 | - typeScript 1087 | summary: | 1088 | This is a static function. 1089 | Static functions should not be inherited. 1090 | syntax: 1091 | content: static function getInstance() 1092 | parameters: [] 1093 | return: 1094 | type: 1095 | - typeName: BaseClass 1096 | typeId: ! '' 1097 | description: An instance of BaseClass. 1098 | package: type2docfx 1099 | - uid: type2docfx.SubClassB.getName 1100 | name: getName() 1101 | children: [] 1102 | type: method 1103 | langs: 1104 | - typeScript 1105 | summary: | 1106 | This is a simple static member function. 1107 | Static functions should not be inherited. This class has a 1108 | member with the same name, both should be documented. 1109 | syntax: 1110 | content: static function getName() 1111 | parameters: [] 1112 | return: 1113 | type: 1114 | - typeName: string 1115 | typeId: ! '' 1116 | description: Return the name. 1117 | package: type2docfx 1118 | langs: 1119 | - typeScript 1120 | type: class 1121 | summary: | 1122 | This is a class that extends another class. 1123 | The constructor of the original class should be overwritten. 1124 | extends: 1125 | name: 1126 | typeName: BaseClass 1127 | typeId: ! '' 1128 | package: type2docfx 1129 | - uid: type2docfx.INameInterface 1130 | name: INameInterface 1131 | fullName: INameInterface 1132 | children: 1133 | - uid: type2docfx.INameInterface.name 1134 | name: name 1135 | fullName: name 1136 | children: [] 1137 | langs: 1138 | - typeScript 1139 | type: property 1140 | summary: | 1141 | This is a interface member of INameInterface. 1142 | It should be inherited by all subinterfaces. 1143 | optional: false 1144 | syntax: 1145 | content: 'name: string' 1146 | return: 1147 | type: 1148 | - typeName: string 1149 | typeId: ! '' 1150 | description: '' 1151 | package: type2docfx 1152 | - uid: type2docfx.INameInterface.getName 1153 | name: getName() 1154 | children: [] 1155 | type: method 1156 | langs: 1157 | - typeScript 1158 | summary: | 1159 | This is a interface function of INameInterface. 1160 | It should be inherited by all subinterfaces. 1161 | syntax: 1162 | content: function getName() 1163 | parameters: [] 1164 | return: 1165 | type: 1166 | - typeName: string 1167 | typeId: ! '' 1168 | description: '' 1169 | package: type2docfx 1170 | langs: 1171 | - typeScript 1172 | type: interface 1173 | summary: This is a simple interface. 1174 | package: type2docfx 1175 | - uid: type2docfx.IPrintInterface 1176 | name: IPrintInterface 1177 | fullName: IPrintInterface 1178 | children: 1179 | - uid: type2docfx.IPrintInterface.print 1180 | name: print(string) 1181 | children: [] 1182 | type: method 1183 | langs: 1184 | - typeScript 1185 | summary: | 1186 | This is a interface function of IPrintInterface 1187 | It should be inherited by all subinterfaces. 1188 | syntax: 1189 | content: 'function print(value: string)' 1190 | parameters: 1191 | - id: value 1192 | type: 1193 | - typeName: string 1194 | typeId: ! '' 1195 | description: '' 1196 | optional: false 1197 | package: type2docfx 1198 | langs: 1199 | - typeScript 1200 | type: interface 1201 | summary: This is a simple interface. 1202 | package: type2docfx 1203 | - uid: type2docfx.IPrintNameInterface 1204 | name: IPrintNameInterface 1205 | fullName: IPrintNameInterface 1206 | children: 1207 | - uid: type2docfx.IPrintNameInterface.name 1208 | name: name 1209 | fullName: name 1210 | children: [] 1211 | langs: 1212 | - typeScript 1213 | type: property 1214 | summary: | 1215 | This is a interface member of INameInterface. 1216 | It should be inherited by all subinterfaces. 1217 | optional: false 1218 | syntax: 1219 | content: 'name: string' 1220 | return: 1221 | type: 1222 | - typeName: string 1223 | typeId: ! '' 1224 | description: '' 1225 | package: type2docfx 1226 | - uid: type2docfx.IPrintNameInterface.getName 1227 | name: getName() 1228 | children: [] 1229 | type: method 1230 | langs: 1231 | - typeScript 1232 | summary: | 1233 | This is a interface function of INameInterface. 1234 | It should be inherited by all subinterfaces. 1235 | syntax: 1236 | content: function getName() 1237 | parameters: [] 1238 | return: 1239 | type: 1240 | - typeName: string 1241 | typeId: ! '' 1242 | description: '' 1243 | package: type2docfx 1244 | - uid: type2docfx.IPrintNameInterface.print 1245 | name: print(string) 1246 | children: [] 1247 | type: method 1248 | langs: 1249 | - typeScript 1250 | summary: | 1251 | This is a interface function of IPrintInterface 1252 | It should be inherited by all subinterfaces. 1253 | syntax: 1254 | content: 'function print(value: string)' 1255 | parameters: 1256 | - id: value 1257 | type: 1258 | - typeName: string 1259 | typeId: ! '' 1260 | description: '' 1261 | optional: false 1262 | package: type2docfx 1263 | - uid: type2docfx.IPrintNameInterface.printName 1264 | name: printName() 1265 | children: [] 1266 | type: method 1267 | langs: 1268 | - typeScript 1269 | summary: This is a interface function of IPrintNameInterface 1270 | syntax: 1271 | content: function printName() 1272 | parameters: [] 1273 | package: type2docfx 1274 | langs: 1275 | - typeScript 1276 | type: interface 1277 | summary: This is a interface inheriting from two other interfaces. 1278 | extends: 1279 | name: 1280 | typeName: INameInterface 1281 | typeId: ! '' 1282 | package: type2docfx --------------------------------------------------------------------------------