Installations
npm install dox
Score
98.8
Supply Chain
100
Quality
79.8
Maintenance
100
Vulnerability
99.6
License
Releases
Contributors
Developer
visionmedia
Developer Guide
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
No
Node Version
16.16.0
NPM Version
8.18.0
Statistics
2,156 Stars
509 Commits
194 Forks
39 Watching
2 Branches
38 Contributors
Updated on 28 Nov 2024
Bundle Size
274.39 kB
Minified
63.92 kB
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
4,312,068
Last day
-36.7%
3,596
Compared to previous day
Last week
32.5%
109,411
Compared to previous week
Last month
413.7%
241,518
Compared to previous month
Last year
13.7%
610,890
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Dox
Dox is a JavaScript documentation generator written with node. Dox no longer generates an opinionated structure or style for your docs, it simply gives you a JSON representation, allowing you to use markdown and JSDoc-style tags.
Installation
Install from npm:
1npm install -g dox
Usage Examples
dox(1)
operates over stdio:
1$ dox < utils.js 2...JSON...
to inspect the generated data you can use the --debug
flag, which is easier to read than the JSON output:
1dox --debug < utils.js
1/** 2 * Escape the given `html`. 3 * 4 * @example 5 * utils.escape('<script></script>') 6 * // => '<script></script>' 7 * 8 * @param {String} html string to be escaped 9 * @return {String} escaped html 10 * @api public 11 */ 12 13exports.escape = function(html){ 14 return String(html) 15 .replace(/&(?!\w+;)/g, '&') 16 .replace(/</g, '<') 17 .replace(/>/g, '>'); 18};
output:
1[ 2 { 3 "tags": [ 4 { 5 "type": "param", 6 "string": "{String} html", 7 "name": "html", 8 "description": "", 9 "types": [ 10 "String" 11 ], 12 "typesDescription": "<code>String</code>", 13 "optional": false, 14 "nullable": false, 15 "nonNullable": false, 16 "variable": false, 17 "html": "<p>{String} html</p>" 18 }, 19 { 20 "type": "return", 21 "string": "{String}", 22 "types": [ 23 "String" 24 ], 25 "typesDescription": "<code>String</code>", 26 "optional": false, 27 "nullable": false, 28 "nonNullable": false, 29 "variable": false, 30 "description": "", 31 "html": "<p>{String}</p>" 32 }, 33 { 34 "type": "api", 35 "string": "private", 36 "visibility": "private", 37 "html": "<p>private</p>" 38 } 39 ], 40 "description": { 41 "full": "<p>Escape the given <code>html</code>.</p>", 42 "summary": "<p>Escape the given <code>html</code>.</p>", 43 "body": "" 44 }, 45 "isPrivate": true, 46 "isConstructor": false, 47 "isClass": false, 48 "isEvent": false, 49 "ignore": false, 50 "line": 2, 51 "codeStart": 10, 52 "code": "exports.escape = function(html){\n return String(html)\n .replace(/&(?!\\w+;)/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>');\n};", 53 "ctx": { 54 "type": "method", 55 "receiver": "exports", 56 "name": "escape", 57 "string": "exports.escape()" 58 } 59 } 60]
This output can then be passed to a template for rendering. Look below at the "Properties" section for details.
Usage
1 2Usage: dox [options] 3 4 Options: 5 6 -h, --help output usage information 7 -V, --version output the version number 8 -r, --raw output "raw" comments, leaving the markdown intact 9 -a, --api output markdown readme documentation 10 -s, --skipPrefixes [prefixes] skip comments prefixed with these prefixes, separated by commas 11 -d, --debug output parsed comments for debugging 12 -S, --skipSingleStar set to false to ignore `/* ... */` comments 13 14 Examples: 15 16 # stdin 17 $ dox > myfile.json 18 19 # operates over stdio 20 $ dox < myfile.js > myfile.json 21
Programmatic Usage
1var dox = require('dox'), 2 code = "..."; 3 4var obj = dox.parseComments(code); 5 6// [{ tags:[ ... ], description, ... }, { ... }, ...]
Properties
A "comment" is comprised of the following detailed properties:
- tags
- description
- isPrivate
- isEvent
- isConstructor
- line
- ignore
- code
- ctx
Description
A dox description is comprised of three parts, the "full" description, the "summary", and the "body". The following example has only a "summary", as it consists of a single paragraph only, therefore the "full" property has only this value as well.
1/** 2 * Output the given `str` to _stdout_. 3 */ 4 5exports.write = function(str) { 6 process.stdout.write(str); 7};
yields:
1[ 2 { 3 "description": { 4 "full": "<p>Output the given <code>str</code> to <em>stdout</em>.</p>", 5 "summary": "<p>Output the given <code>str</code> to <em>stdout</em>.</p>", 6 "body": "" 7 }, 8 // ... other tags 9 } 10]
Large descriptions might look something like the following, where the "summary" is still the first paragraph, the remaining description becomes the "body". Keep in mind this is markdown, so you can indent code, use lists, links, etc. Dox also augments markdown, allowing "Some Title:\n" to form a header.
1/** 2 * Output the given `str` to _stdout_ 3 * or the stream specified by `options`. 4 * 5 * Options: 6 * 7 * - `stream` defaulting to _stdout_ 8 * 9 * Examples: 10 * 11 * mymodule.write('foo') 12 * mymodule.write('foo', { stream: process.stderr }) 13 * 14 */ 15 16exports.write = function(str, options) { 17 options = options || {}; 18 (options.stream || process.stdout).write(str); 19};
yields:
1[ 2 { 3 "description": { 4 "full": "<p>Output the given <code>str</code> to <em>stdout</em><br />\nor the stream specified by <code>options</code>.</p>\n<p>Options:</p>\n<ul>\n<li><code>stream</code> defaulting to <em>stdout</em></li>\n</ul>\n<p>Examples:</p>\n<pre><code>mymodule.write('foo')\nmymodule.write('foo', { stream: process.stderr })\n</code></pre>", 5 "summary": "<p>Output the given <code>str</code> to <em>stdout</em><br />\nor the stream specified by <code>options</code>.</p>", 6 "body": "<p>Options:</p>\n<ul>\n<li><code>stream</code> defaulting to <em>stdout</em></li>\n</ul>\n<p>Examples:</p>\n<pre><code>mymodule.write('foo')\nmymodule.write('foo', { stream: process.stderr })\n</code></pre>" 7 }, 8 // ... other tags 9 } 10]
Tags
Dox also supports JSdoc-style tags. Currently only @api is special-cased, providing the comment.isPrivate
boolean so you may omit "private" utilities etc.
1/** 2 * Output the given `str` to _stdout_ 3 * or the stream specified by `options`. 4 * 5 * @param {String} str 6 * @param {{stream: Writable}} options 7 * @return {Object} exports for chaining 8 */ 9 10exports.write = function(str, options) { 11 options = options || {}; 12 (options.stream || process.stdout).write(str); 13 return this; 14};
yields:
1[ 2 { 3 "tags": [ 4 { 5 "type": "param", 6 "string": "{String} str", 7 "name": "str", 8 "description": "", 9 "types": [ 10 "String" 11 ], 12 "typesDescription": "<code>String</code>", 13 "optional": false, 14 "nullable": false, 15 "nonNullable": false, 16 "variable": false, 17 "html": "<p>{String} str</p>" 18 }, 19 { 20 "type": "param", 21 "string": "{{stream: Writable}} options", 22 "name": "options", 23 "description": "", 24 "types": [ 25 { 26 "stream": [ 27 "Writable" 28 ] 29 } 30 ], 31 "typesDescription": "{stream: <code>Writable</code>}", 32 "optional": false, 33 "nullable": false, 34 "nonNullable": false, 35 "variable": false, 36 "html": "<p>{{stream: Writable}} options</p>" 37 }, 38 { 39 "type": "return", 40 "string": "{Object} exports for chaining", 41 "types": [ 42 "Object" 43 ], 44 "typesDescription": "<code>Object</code>", 45 "optional": false, 46 "nullable": false, 47 "nonNullable": false, 48 "variable": false, 49 "description": "<p>exports for chaining</p>" 50 } 51 ], 52 // ... other tags 53 } 54]
Complex jsdoc tags
dox supports all jsdoc type strings specified in the jsdoc documentation. You can
specify complex object types including optional flag =
, nullable ?
, non-nullable !
and variable arguments ...
.
Additionally you can use typesDescription
which contains formatted HTML for displaying complex types.
1/** 2 * Generates a person information string based on input. 3 * 4 * @param {string | {name: string, age: number | date}} name Name or person object 5 * @param {{separator: string} =} options An options object 6 * @return {string} The constructed information string 7 */ 8 9exports.generatePersonInfo = function(name, options) { 10 var str = ''; 11 var separator = options && options.separator ? options.separator : ' '; 12 13 if(typeof name === 'object') { 14 str = [name.name, '(', name.age, ')'].join(separator); 15 } else { 16 str = name; 17 } 18};
yields:
1[ 2 { 3 "tags": [ 4 { 5 "type": "param", 6 "string": "{string | {name: string, age: number | date}} name Name or person object", 7 "name": "name", 8 "description": "<p>Name or person object</p>", 9 "types": [ 10 "string", 11 { 12 "name": [ 13 "string" 14 ], 15 "age": [ 16 "number", 17 "date" 18 ] 19 } 20 ], 21 "typesDescription": "<code>string</code> | {name: <code>string</code>, age: <code>number</code> | <code>date</code>}", 22 "optional": false, 23 "nullable": false, 24 "nonNullable": false, 25 "variable": false 26 }, 27 { 28 "type": "param", 29 "string": "{{separator: string} =} options An options object", 30 "name": "options", 31 "description": "<p>An options object</p>", 32 "types": [ 33 { 34 "separator": [ 35 "string" 36 ] 37 } 38 ], 39 "typesDescription": "{separator: <code>string</code>|<code>undefined</code>}", 40 "optional": true, 41 "nullable": false, 42 "nonNullable": false, 43 "variable": false 44 }, 45 { 46 "type": "return", 47 "string": "{string} The constructed information string", 48 "types": [ 49 "string" 50 ], 51 "typesDescription": "<code>string</code>", 52 "optional": false, 53 "nullable": false, 54 "nonNullable": false, 55 "variable": false, 56 "description": "<p>The constructed information string</p>" 57 } 58 ], 59 // ... other tags 60 } 61]
Code
The .code
property is the code following the comment block, in our previous examples:
1exports.write = function(str, options) { 2 options = options || {}; 3 (options.stream || process.stdout).write(str); 4 return this; 5};
Ctx
The .ctx
object indicates the context of the code block, is it a method, a function, a variable etc. Below are some examples:
1/** */ 2exports.generate = function(str, options) {};
yields:
1[ 2 { 3 // ... other tags 4 "ctx": { 5 "type": "method", 6 "receiver": "exports", 7 "name": "generate", 8 "string": "exports.generate()" 9 } 10 } 11]
1/** */ 2var foo = 'bar';
yields:
1[ 2 { 3 // ... other tags 4 "ctx": { 5 "type": "declaration", 6 "name": "foo", 7 "value": "'bar'", 8 "string": "foo" 9 } 10 } 11]
1/** */ 2function User() {}
yields:
1[ 2 { 3 // ... other tags 4 "ctx": { 5 "type": "function", 6 "name": "User", 7 "string": "User()" 8 } 9 } 10]
Extending Context Matching
Context matching in dox is done by performing pattern matching against the code following a
comment block. dox.contextPatternMatchers
is an array of all pattern matching functions,
which dox will iterate over until one of them returns a result. If none return a result,
then the comment block does not receive a ctx
value.
This array is exposed to allow for extension of unsupported context patterns by adding more functions. Each function is passed the code following the comment block and (if detected) the parent context if the block.
1dox.contextPatternMatchers.push(function (str, parentContext) { 2 // return a context object if found 3 // return false otherwise 4});
Ignore
Comments and their associated bodies of code may be flagged with "!" to be considered worth ignoring, these are typically things like file comments containing copyright etc, however you of course can output them in your templates if you want.
1/** 2 * Not ignored. 3 */
vs
1/*! 2 * Ignored. 3 */
You may use -S
, --skipSingleStar
or {skipSingleStar: true}
to ignore /* ... */
comments.
Running tests
Install dev dependencies and execute make test
:
1npm install -d 2make test
License
(The MIT License)
Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
1 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
Reason
Found 2/7 approved changesets -- score normalized to 2
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.workflow.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/tj/dox/test.workflow.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.workflow.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/tj/dox/test.workflow.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/test.workflow.yml:32
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 2 npmCommand dependencies pinned
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/test.workflow.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 25 are checked with a SAST tool
Score
3.3
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More