npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

amd-doc

v0.2.2

Published

Documentation generator for AMD-based projects

Downloads

12

Readme

amd-doc

amd-doc is a JavaScript documentation generator for AMD-based projects. It post-processes the JSON output of jsdoc3, using RequireJS configuration and AMD conventions to infer more information.

Installation

npm install amd-doc

Usage

The main functionality of amd-doc is exposed through the compile function. It returns a Deferred object and accepts an opts argument which can contain these properties (example from deferreds.js):

var amddoc = require('amd-doc');

amddoc.compile({
	//globbing-supported String or Array of Strings with process-relative
	//files to process for documentation
	include: 'src/deferreds/**/*.js',

	//directory to output generated HTML (default = 'doc/out')
	out: 'doc/out',

	//directory to store jsdoc cache (default = 'doc/cache')
	cache: 'doc/cache',

	//directory to look for markdown mixins (default = 'doc/mixin')
	mixin: 'doc/mixin',

	//github URL where source is available. the file path and line number of
	//each documented variable will be added to this to make source links.
	repoview: 'https://github.com/zship/deferreds.js/blob/develop/',

	//Array of Type (see tasks/doc/Types.js) objects to transform into links
	//when used as parameter types, return types, or description namepaths
	types: (function() {
		var types = [];

		//make all built-in types link to their MDN pages
		['Number', 'String', 'Object', 'Function', 'Array', 'RegExp', 'Boolean'].forEach(function(val) {
			types.push({
				name: val,
				link: 'https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/' + val
			});
		});

		types.push({
			name: 'Any',
			link: 'https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects'
		});

		types.push({
			name: 'void',
			link: 'https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/undefined'
		});

		types.push({
			name: 'Element',
			link: 'https://developer.mozilla.org/en-US/docs/DOM/element'
		});

		types.push({
			name: 'jQuery',
			link: 'http://api.jquery.com/jQuery/'
		});

		types.push({
			name: 'require',
			link: 'http://requirejs.org/'
		});

		types.push({
			//any name matching this RegExp (with name.search()) will be given
			//the following link
			regexp: /amd-utils\/.*/,
			link: 'http://millermedeiros.github.com/amd-utils/'
		});

		return types;
	})(),

	//requirejs configuration object
	//more: https://github.com/jrburke/r.js/blob/master/build/example.build.js
	//amd-doc uses `basePath`, `paths`, and `packages` (all optional) to
	//transform file names to AMD module names.
	requirejs: {
		baseUrl: 'src/deferreds',
		optimize: 'none',
		packages: [
			{ name: 'amd-utils', location: '../lib/amd-utils' }
		],
	}
});

What it does

Inferred information

  • Class names
    • Convention: one class per file - names the class after the last part of the module name (e.g. 'joss/geometry/Rect' -> 'Rect')
    • When using @lends, any name may be specified and it will be replaced by the last part of the module name (i.e. /** @lends __.prototype */ will apply its properties to the only class defined in the file, regardless of the existence of a variable __)
  • Namespace names
    • Convention: one namespace per file - names the namespace after the last part of the module name
    • @namespace may be used by itself (with no name to assign to the namespace)
  • Dependencies
    • AMD dependencies of each file are included in the output

Other Additions

  • Cache jsdoc output
    • jsdoc3 is very comprehensive, but suffers from poor performance. amd-doc tries to compensate by maintaining a per-file cache, with freshness determined by hashing each source file's contents and comparing on each run.
  • Type system
    • Every declared class will, on declaration, have a Type object associated with it (see tasks/doc/Types.js). These Types contain both long names (full module names) and short names (last part of the module name) and are used to match against AMD dependencies, parameters, return types, and namepaths in descriptions.
    • External types like {String} and {Object} can be specified in the configuration object, to present links in the output. (e.g. {String} can become String, linking to MDN's String reference)
  • Mixing-in markdown documentation from external files
    • Markdown files can be specified in a directory structure mirroring your source, one per source file. Any h2s (##) in the file will be matched against variable names in your source, and content under the h2 will replace the description for that variable
  • Converting jsdoc namepaths or Type names to links within descriptions
    • Specify namepaths between braces {}, and if there is a matching documented variable, the namepath will be converted to a link.
    • {joss/geometry/Rect#moveTop} becomes Rect.moveTop
    • {Rect#moveTop} also becomes Rect.moveTop, if the short-name "Rect" is not declared more than once
    • {joss/geometry/Rect} becomes Rect. (it's a Type name, not a jsdoc namepath)
  • Multiple inheritance
  • Unstyled HTML output
    • Module definition for each module
    • Taglist for each module
      • taglists and module definitions are rendered from jade templates (see tasks/tpl)
    • Hierarchical menu linking to every module
  • Summary information
    • List of all declared and external Types, both long names and short names
    • List of ambiguous short names (e.g. joss/geometry/Rect and joss/display/Rect are unique modules, but the last part (the short-name) of both is Rect)
    • List of undeclared Types (used in parameters, return types, or description namepaths but never declared)
    • Percentage of documented variables with markdown descriptions
    • Percentage of documented variables with non-empty descriptions
    • (Guess) list of direct members of documented classes which have no jsdoc annotations, but probably should (because they're direct members)

amd-doc was created as the documentation generator for the joss framework.