{"name":"jsdoctypeparser","description":"Strict JsDoc type expression parser","version":"0.0.1","author":{"name":"Orga Chem","email":"orga.chem.job@gmail.com"},"keywords":["jsdoc","parser"],"repository":{"type":"git","url":"git://github.com/OrgaChem/jsdoc-strict-type-parser.git"},"bugs":{"mail":"orga.chem.job@gmail.com","url":"https://github.com/OrgaChem/jsdoc-strict-type-parser/issues"},"directories":{"test":"test"},"main":"lib/index.js","scripts":{"test":"node test/run.js"},"licenses":[{"type":"MIT","url":"http://orgachem.mit-license.org/"}],"gitHead":"a50d4c5cfa3eca783d762f9b533521681bea9f10","dependencies":{},"devDependencies":{"nodeunit":"~0.8.0","benchmark":"~1.0.0"},"license":"MIT","_id":"jsdoctypeparser@0.0.1","dist":{"shasum":"c688bc1a6890636c607617a430bd83a88b2d35f6","tarball":"http://registry-npm.ywwl.com/jsdoctypeparser/download/jsdoctypeparser-0.0.1.tgz","integrity":"sha512-r2Al6F+g0NnhAXwuuO5mMVBPxM9b5kMnqk9gVp3oZsTzpEVO0tlBO2SOqqxItEx3/ZV9qcy7W5HKvq0VBbJjIA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCpW2KIhwMCC2E2VnlDtJxJiSENENfQPqJmQ2EUw8WBjAIhAN/OVXfEyAWwimTGh9g1HaXXrmHTGZk1S/YuX8R/vdee"}],"size":16418,"noattachment":false,"key":"/jsdoctypeparser/-/jsdoctypeparser-0.0.1.tgz"},"_from":".","_npmVersion":"1.2.11","_npmUser":{"name":"orgachem","email":"orga.chem.job@gmail.com"},"maintainers":[{"name":"orgachem","email":"orga.chem.job@gmail.com"}],"readme":"# jsdoctypeparser\n\n[![Build Status](https://travis-ci.org/jsdoctypeparser/jsdoctypeparser.svg?branch=master)](https://travis-ci.org/jsdoctypeparser/jsdoctypeparser)\n[![NPM version](https://badge.fury.io/js/jsdoctypeparser.svg)](http://badge.fury.io/js/jsdoctypeparser)\n\nThe parser can parse:\n\n* [JSDoc type expressions](https://jsdoc.app/tags-type.html)\n  * `foo.bar`, `String[]`\n* [Closure Compiler type expressions](https://developers.google.com/closure/compiler/docs/js-for-compiler)\n  * `Array<string>`, `function(arg1, arg2): ret`\n* [some Typescript types](https://github.com/Microsoft/TypeScript)\n  * `(x: number) => string`, `typeof x`, `import(\"./some-module\")`\n* Complex type expressions\n  * `Array<Array<string>>`, `function(function(Function))`\n\n## Live demo\n\nThe [live demo](https://jsdoctypeparser.github.io) is available.\n\n## Usage (Programmatic)\n\n### Parsing\n\n```javascript\nconst {parse} = require('jsdoctypeparser');\n\nconst ast = parse('Array<MyClass>');\n```\n\nThe `ast` becomes:\n\n```json\n{\n  \"type\": \"GENERIC\",\n  \"subject\": {\n    \"type\": \"NAME\",\n    \"name\": \"Array\"\n  },\n  \"objects\": [\n    {\n      \"type\": \"NAME\",\n      \"name\": \"MyClass\"\n    }\n  ],\n  \"meta\": {\n    \"syntax\": \"ANGLE_BRACKET\"\n  }\n}\n```\n\nSee the [AST specifications](https://github.com/Kuniwak/jsdoctypeparser/blob/update-readme/README.md#ast-specifications).\n\n### Publishing\n\nWe can stringify the AST nodes by using `publish`.\n\n```javascript\nconst {publish} = require('jsdoctypeparser');\n\nconst ast = {\n  type: 'GENERIC',\n  subject: {\n    type: 'NAME',\n    name: 'Array'\n  },\n  objects: [\n    {\n      type: 'NAME',\n      name: 'MyClass'\n    }\n  ]\n};\n\nconst string = publish(ast);\n```\n\nThe `string` becomes:\n\n```json\n\"Array<MyClass>\"\n```\n\n#### Custom publishing\n\nWe can change the stringification strategy by using the 2nd parameter of `publish(node, publisher)`.\nThe `publisher` MUST have handlers for all node types (see `lib/NodeType.js`).\n\nAnd we can override default behavior by using `createDefaultPublisher`.\n\n```javascript\nconst {publish, createDefaultPublisher} = require('jsdoctypeparser');\n\nconst ast = {\n  type: 'NAME',\n  name: 'MyClass',\n};\n\nconst customPublisher = createDefaultPublisher();\ncustomPublisher.NAME = (node, pub) =>\n  `<a href=\"./types/${node.name}.html\">${node.name}</a>`;\n\nconst string = publish(ast, customPublisher);\n```\n\nThe `string` becomes:\n\n```html\n<a href=\"./types/MyClass.html\">MyClass</a>\n```\n\n### Traversing\n\nWe can traverse the AST by using `traverse`.\nThis function takes 3 parameters (a node and an onEnter handler, an onLeave handler).\nThe handlers take a visiting node.\n\n```javascript\nconst {parse, traverse} = require('jsdoctypeparser');\nconst ast = parse('Array<{ key1: function(), key2: A.B.C }>');\n\nfunction onEnter(node, parentName, parentNode) {\n  console.log('enter', node.type, parentName, parentNode.type);\n}\n\nfunction onLeave(node, parentName, parentNode) {\n  console.log('leave', node.type, parentName, parentNode.type);\n}\n\ntraverse(ast, onEnter, onLeave);\n```\n\nThe output will be:\n\n```\nenter GENERIC null null\nenter NAME subject GENERIC\nleave NAME subject GENERIC\nenter RECORD objects GENERIC\nenter RECORD_ENTRY entries RECORD\nenter FUNCTION value RECORD_ENTRY\nleave FUNCTION value RECORD_ENTRY\nleave RECORD_ENTRY entries RECORD\nenter RECORD_ENTRY entries RECORD\nenter MEMBER value RECORD_ENTRY\nenter MEMBER owner MEMBER\nenter NAME owner MEMBER\nleave NAME owner MEMBER\nleave MEMBER owner MEMBER\nleave MEMBER value RECORD_ENTRY\nleave RECORD_ENTRY entries RECORD\nleave RECORD objects GENERIC\nleave GENERIC null null\n```\n\n## AST Specifications\n\n### `NAME`\n\nExample:\n\n```javascript\n/**\n * @type {name}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"NAME\",\n  \"name\": string\n}\n```\n\n### `MEMBER`\n\nExample:\n\n```javascript\n/**\n * @type {owner.name}\n * @type {superOwner.owner.name}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"MEMBER\",\n  \"name\": string,\n  \"quoteStyle\": \"none\",\n  \"owner\": node,\n  \"hasEventPrefix\": boolean\n}\n```\n\n### `INNER_MEMBER`\n\nExample:\n\n```javascript\n/**\n * @type {owner~name}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"INNER_MEMBER\",\n  \"name\": string,\n  \"quoteStyle\": \"none\",\n  \"owner\": node,\n  \"hasEventPrefix\": boolean\n}\n```\n\n### `INSTANCE_MEMBER`\n\nExample:\n\n```javascript\n/**\n * @type {owner#name}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"INSTANCE_MEMBER\",\n  \"name\": string,\n  \"quoteStyle\": \"none\",\n  \"owner\": node,\n  \"hasEventPrefix\": boolean\n}\n```\n\n### `UNION`\n\nExample:\n\n```javascript\n/**\n * @type {left|right}\n * @type {(left|right)}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"UNION\",\n  \"left\": node,\n  \"right\": node\n}\n```\n\n### `INTERSECTION`\n\nExample:\n\n```javascript\n/**\n * @type {left&right}\n * @type {(left&right)}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"INTERSECTION\",\n  \"left\": node,\n  \"right\": node\n}\n```\n\n### `RECORD`\n\nExample:\n\n```javascript\n/**\n * @type {{}}\n * @type {{ key: value }}\n * @type {{ key: value, anyKey }}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"RECORD\",\n  \"entries\": [\n    recordEntryNode,\n    recordEntryNode,\n    ...\n  ]\n}\n```\n\n### `RECORD_ENTRY`\n\nStructure:\n\n```javascript\n{\n  \"type\": \"RECORD_ENTRY\",\n  \"key\": string,\n  \"value\": node (or null)\n}\n```\n\n### `GENERIC`\n\nExample:\n\n```javascript\n/**\n * @type {Subject<Object, Object>}\n * @type {Object[]}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"GENERIC\",\n  \"subject\": node,\n  \"objects\": [\n    node,\n    node,\n    ...\n  ],\n  \"meta\": {\n    \"syntax\": (\"ANGLE_BRACKET\" or \"ANGLE_BRACKET_WITH_DOT\" or \"SQUARE_BRACKET\")\n  }\n}\n```\n\n### `FUNCTION`\n\nExample:\n\n```javascript\n/**\n * @type {function()}\n * @type {function(param, param): return}\n * @type {function(this: Context)}\n * @type {function(new: Class)}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"FUNCTION\",\n  \"params\": [\n    node,\n    node,\n    ...\n  ],\n  \"returns\": node (or null),\n  \"new\": node (or null),\n  \"this\": node (or null)\n}\n```\n\n### `OPTIONAL`\n\nExample:\n\n```javascript\n/**\n * @type {Optional=}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"OPTIONAL\",\n  \"value\": node,\n  \"meta\": {\n    \"syntax\": (\"PREFIX_EQUALS_SIGN\" or \"SUFFIX_EQUALS_SIGN\")\n  }\n}\n```\n\n### `NULLABLE`\n\nExample:\n\n```javascript\n/**\n * @type {?Nullable}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"NULLABLE\",\n  \"value\": node,\n  \"meta\": {\n    \"syntax\": (\"PREFIX_QUESTION_MARK\" or \"SUFFIX_QUESTION_MARK\")\n  }\n}\n```\n\n### `NOT_NULLABLE`\n\nExample:\n\n```javascript\n/**\n * @type {!NotNullable}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"NOT_NULLABLE\",\n  \"value\": node,\n  \"meta\": {\n    \"syntax\": (\"PREFIX_BANG\" or \"SUFFIX_BANG\")\n  }\n}\n```\n\n### `VARIADIC`\n\nExample:\n\n```javascript\n/**\n * @type {...Variadic}\n * @type {Variadic...}\n * @type {...}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"VARIADIC\",\n  \"value\": node (or null),\n  \"meta\": {\n    \"syntax\": (\"PREFIX_DOTS\" or \"SUFFIX_DOTS\" or \"ONLY_DOTS\")\n  }\n}\n```\n\n### `MODULE`\n\nExample:\n\n```javascript\n/**\n * @type {module:path/to/file.Module}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"MODULE\",\n  \"value\": node\n}\n```\n\n### `FILE_PATH`\n\nExample:\n\n```javascript\n/**\n * @type {module:path/to/file.Module}\n *               ^^^^^^^^^^^^\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"FILE_PATH\",\n  \"path\": string\n}\n```\n\n### `EXTERNAL`\n\nExample:\n\n```javascript\n/**\n * @type {external:External}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"EXTERNAL\",\n  \"value\": node\n}\n```\n\n### `STRING_VALUE`\n\nExample:\n\n```javascript\n/**\n * @type {\"abc\"}\n * @type {\"can\\\"escape\"}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"STRING_VALUE\",\n  \"quoteStyle\": \"double\",\n  \"string\": string\n}\n```\n\n### `NUMBER_VALUE`\n\nExample:\n\n```javascript\n/**\n * @type {123}\n * @type {0b11}\n * @type {0o77}\n * @type {0xff}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"NUMBER_VALUE\",\n  \"number\": string\n}\n```\n\n### `ANY`\n\nExample:\n\n```javascript\n/**\n * @type {*}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"ANY\"\n}\n```\n\n### `UNKNOWN`\n\nExample:\n\n```javascript\n/**\n * @type {?}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"UNKNOWN\"\n}\n```\n\n### `PARENTHESIS`\n\nExample:\n\n```javascript\n/**\n * @type {(Foo)}\n */\n```\n\nStructure:\n\n```javascript\n{\n  \"type\": \"PARENTHESIS\",\n  \"value\": node\n}\n```\n\n### Others\n\nWe can use a parenthesis to change operator orders.\n\n```javascript\n/**\n * @type {(module:path/to/file.js).foo}\n */\n```\n\n## Usage (CLI)\n\nTo parse a type into a JSON structure, you may pass a string argument\ncontaining the structure to parse (with the JSON results equivalent to the\nparsing example above):\n\n```\njsdoctypeparser 'Array<MyClass>'\n```\n\nNote: There is no need to prefix the path to the `jsdoctypeparser` binary,\ne.g., with `./node_modules/.bin/` when you are running within one of the\n`package.json` `scripts` or if you have installed the package globally.\n\n## License\n\n[This script is licensed under the MIT](./LICENSE-MIT.txt).\n","publish_time":1365339761862,"_cnpm_publish_time":1365339761862,"dist-tags":{"latest":"9.0.0"}}