Package Exports
- jsdoctypeparser
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jsdoctypeparser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Jsdoc strict type parser
This module is Jsdoc type expression parser.
This parser provide:
- Parse strict
- Build DOM
- Convert a type name to a link by using
toHtml()
This parser can parse:
- JsDoc type expressions
foo.bar
,String[]
- Closure Compiler type expressions
Array.<string>
,function(this: Objext, arg1, arg2): ret
- Nested type expressions
Array.<Array.<string>>
,function(function(Function))
Parsing
var Parser = require('jsdoctypeparser').Parser;
var parser = new Parser();
var result = parser.parse('Array.<string|number, ?Object=>|string|undefined');
The result
is:
{
optional: true,
types: [
{
parameterTypeUnions: [
{
types: [
{ name: 'string' },
{ name: 'number' }
]
},
{
nullable: true
optional: true
types: [
{ name: 'Object' }
]
}
]
}, {
{ name: 'string' }
}
]
}
DOM Specification
Type name
TypeName = {
name: string
};
Type Union
TypeUnion = {
optional: boolean,
nullable: boolean,
variable: boolean,
nonNullable: boolean,
all: boolean,
unknown: boolean,
types: Array.<TypeName|GenericType|FunctionType|RecordType>
};
Generic type
GenericType = {
genericTypeName: string,
parameterTypeUnions: Array.<TypeUnion>
};
Function type
FunctionType = {
parameterTypeUnions: Array.<TypeUnion>,
returnTypeUnion: TypeUnion|null,
isConstructor: boolean,
contextTypeUnion: TypeUnion|null
};
Record type
RecordType = {
entries: Array.<RecordEntry>
};
RecordEntry = {
name: string,
typeUnion: TypeUnion
};
Publishing
var Parser = require('jsdoctypeparser).Parser;
var parser = new Parser();
var result = parser.parse('Array.<MyClass>=');
result.toString()
⇒'Array.<MyClass>|undefined'
result.toHtml()
⇒'Array.<<a href="MyClass.html">MyClass</a>>|undefined'
Customize type name URI
You can change a file URL by set TypeBulder.TypeName.getUrlByTypeName(typeName)
.
var Builder = require('jsdoctypeparser').Builder;
Bulder.TypeName.getUrlByTypeName = function(typeName) {
// do something.
return typeName;
};
License
This script licensed under the MIT. See: http://orgachem.mit-license.org