Corpus Class

Defined in: packages/megadoc-corpus/lib/Corpus.js

The Corpus public API.

Constructor Documentation

Corpus()

Instance Method Documentation

    add(node: T.Namespace|T.Node)

    Add a namespace or a document to the corpus. The corpus will be populated with all offspring nodes (if applicable).

    Items added to the corpus will gain a UID and will be indexed.

    Parameters (1)

    node
    T.Namespace|T.Node

    Example

    corpus.add(b.namespace({
      id: 'JS',
      documents: [
        b.document({
          id: 'jQuery'
        })
      ]
    }))

    get(uid: String) -> T.Namespace|T.Node

    Retrieve a document AST node by its UID.

    Parameters (1)

    uid
    String

    Return Value

    T.Namespace|T.Node

    The document AST node, if found.

    resolve(anchor: Object) -> T.Node

    Resolve a link to a document.

    Parameters (3)

    anchor
    Object
    anchor.contextNode
    T.Node

    The contextNode we're resolving from. Defaults to the root corpus node.

    anchor.text
    String

    The term to use for looking up the document.

    Return Value

    T.Node

    dump()PRIVATE

    alias(uid: String, alias: String)

    Define an alias for a document.

    Parameters (2)

    uid
    String

    The UID of the node to alias.

    alias
    String

    The alias to use (should be fully-qualified.)

    toJSON() -> Object

    Serialize the Corpus to a flat JSON map with no circular dependencies.

    Return Value

    Object

    An object that can be safely serialized to disk.

    visit(visitor: Object, node: T.Namespace|T.Node)

    Install a Node visitor that will be called any time a node of the specified type is added to the corpus.

    Parameters (2)

    visitor
    Object

    A map of node types as keys and functions as values.

    node
    T.Namespace|T.Node

    Example

    corpus.visit({
      Document: function(node) {
        if (node.filePath.match(/foo.js/)) {
          node.meta.isFoo = true;
        }
      }
    });
    Unknown tag:
    {
      "type": "callback",
      "string": "",
      "typeInfo": {
        "name": null,
        "description": null,
        "isOptional": null,
        "defaultValue": null,
        "type": null
      },
      "line": 150
    }