UNPKG

5.72 kBMarkdownView Raw
1# Specification
2
3## 1. Design
4
5### 1.1 UID Specification
6Based on the [namepath] in JSDoc, to avoid UID conflict between packages, the format of UID is designed to include [package name](https://docs.npmjs.com/files/package.json#name) as:
7```
8{packageName}.namepath
9```
10For global members that hasn't parent class, the format of UID is designed as:
11```
12{packageName}._global.namepath
13```
14As jsdoc's `@link` supports namepath, so this tool need to convert namepath to DocFX's uid. It needs:
151. prepend package name as design above.
162. encodeURIComponent the namepath. As `#` often appears in namepath, but it also means url anchor in DocFX's cross reference syntax. It should be encoded into `%23`.
17
18### 1.2 New DocumentProcessor for DocFX
19JavaScript has some language features hard to fit DocFX's PageViewModel, like [optional parameter](221-an-optional-parameter-using-jsdoc-syntax), [multiple types parameter](231-allows-one-type-or-another-type-type-union), so some new properties are needed and some existing properties' type need to be changed.
20* plugin package: https://www.nuget.org/packages/Microsoft.DocAsCode.Build.JavaScriptReference/
21* plugin source: https://github.com/dotnet/docfx/tree/dev/plugins/Microsoft.DocAsCode.Build.JavaScriptReference
22
23## 2. JavaScript Language Features
24### 2.1 Parameters with properties
25See http://usejsdoc.org/tags-param.html#parameters-with-properties
26
27#### 2.1.1 Documenting a parameter's properties
28
29* Example:
30
31 ```js
32 /**
33 * Assign the project to an employee.
34 * @param {Object} employee - The employee who is responsible for the project.
35 * @param {string} employee.name - The name of the employee.
36 * @param {string} employee.department - The employee's department.
37 */
38 Project.prototype.assign = function(employee) {
39 // ...
40 };
41 ```
42* Need template support:
43 * [JavaScriptReference.common.js](../docfx_template/JavaScriptReference.common.js): `function groupParameters(parameters)`
44 * [parameters.tmpl.partial](../docfx_template/partials/parameters.tmpl.partial)
45
46#### 2.1.2 Documenting properties of values in an array (🛠**TO BE IMPLEMENTED**)
47
48* Example:
49
50 ```js
51 /**
52 * Assign the project to a list of employees.
53 * @param {Object[]} employees - The employees who are responsible for the project.
54 * @param {string} employees[].name - The name of an employee.
55 * @param {string} employees[].department - The employee's department.
56 */
57 Project.prototype.assign = function(employees) {
58 // ...
59 };
60 ```
61
62### 2.2 Optional parameters and default values
63See http://usejsdoc.org/tags-param.html#optional-parameters-and-default-values
64#### 2.2.1 An optional parameter (using JSDoc syntax) (🛠**TO BE IMPLEMENTED**)
65
66* Example:
67
68 ```js
69 /**
70 * @param {string} [somebody] - Somebody's name.
71 */
72 function sayHello(somebody) {
73 if (!somebody) {
74 somebody = 'John Doe';
75 }
76 alert('Hello ' + somebody);
77 }
78 ```
79
80#### 2.2.2 An optional parameter and default value (🛠**TO BE IMPLEMENTED**)
81
82* Example:
83
84 ```js
85 /**
86 * @param {string} [somebody=John Doe] - Somebody's name.
87 */
88 function sayHello(somebody) {
89 if (!somebody) {
90 somebody = 'John Doe';
91 }
92 alert('Hello ' + somebody);
93 }
94 ```
95
96### 2.3 Multiple types and repeatable parameters
97See http://usejsdoc.org/tags-param.html#multiple-types-and-repeatable-parameters
98#### 2.3.1 Allows one type OR another type (type union)
99
100* Example:
101
102 ```js
103 /**
104 * @param {(string|string[])} [somebody=John Doe] - Somebody's name, or an array of names.
105 */
106 function sayHello(somebody) {
107 if (!somebody) {
108 somebody = 'John Doe';
109 } else if (Array.isArray(somebody)) {
110 somebody = somebody.join(', ');
111 }
112 alert('Hello ' + somebody);
113 }
114 ```
115* Need template support:
116 * [JavaScriptReference.common.js](../docfx_template/JavaScriptReference.common.js): `function joinType(parameter)`
117
118#### 2.3.2 Allows any type (🛠**TO BE IMPLEMENTED**)
119
120* Example:
121
122 ```js
123 /**
124 * @param {*} somebody - Whatever you want.
125 */
126 function sayHello(somebody) {
127 console.log('Hello ' + JSON.stringify(somebody));
128 }
129 ```
130
131#### 2.3.3 Allows a parameter to be repeated (🛠**TO BE IMPLEMENTED**)
132
133* Example:
134
135 ```js
136 /**
137 * Returns the sum of all numbers passed to the function.
138 * @param {...number} num - A positive or negative number.
139 */
140 function sum(num) {
141 var i = 0, n = arguments.length, t = 0;
142 for (; i < n; i++) {
143 t += arguments[i];
144 }
145 return t;
146 }
147 ```
148
149## 3. Other Features in JSDoc
150
151### 3.1 `{@link}`
152See http://usejsdoc.org/tags-inline-link.html
153JSDoc uses `{@link}` inline tag to link to an internal item or an external URL, which is link a combination of [cross reference](http://dotnet.github.io/docfx/spec/docfx_flavored_markdown.html#cross-reference) in DFM and [link](https://help.github.com/articles/basic-writing-and-formatting-syntax/#links) in GFM.
154To make it compatible with DocFX, `{@link}` syntax will be transformed to DFM syntax when generating YAML files.
155
156### 3.2 `{@tutorial}` (:no_good_man:**NOT SUPPORTED FOR NOW**)
157See http://usejsdoc.org/about-tutorials.html
158JSDoc uses `{@tutorial}` inline/block tag to link to an internal markdown or HTML file, with the filename without extension as identifier. This is not supported as it has the assumption that file under different directionaries can't have the same filename. Using [Markdown Links](https://help.github.com/articles/basic-writing-and-formatting-syntax/#links) is recommended.
159
\No newline at end of file