Code coverage report for master/lib/jsdoc/tag/dictionary.js

Statements: 100% (53 / 53)      Branches: 90% (18 / 20)      Functions: 100% (11 / 11)      Lines: 100% (53 / 53)      Ignored: none     

All files » master/lib/jsdoc/tag/ » dictionary.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123      1   1   1     1 1709 1709   1709   1709       1709 3948         1 1 1             1 32 32     32       1 65   65 65     65       1 1709 1709   1709 65     1709       1 422       1 26       1 11751   11751 11666     85       1 1017 994 994 79       938       1 20873   20873 436     20437       1     1 1     1     1  
/** @module jsdoc/tag/dictionary */
'use strict';
 
var definitions = require('jsdoc/tag/dictionary/definitions');
 
var hasOwnProp = Object.prototype.hasOwnProperty;
 
var dictionary;
 
/** @private */
function TagDefinition(dict, title, etc) {
    var self = this;
    etc = etc || {};
 
    this.title = dict.normalise(title);
 
    Object.defineProperty(this, '_dictionary', {
        value: dict
    });
 
    Object.keys(etc).forEach(function(p) {
        self[p] = etc[p];
    });
}
 
/** @private */
TagDefinition.prototype.synonym = function(synonymName) {
    this._dictionary.defineSynonym(this.title, synonymName);
    return this; // chainable
};
 
/**
 * @class
 * @alias module:jsdoc/tag/dictionary.Dictionary
 */
function Dictionary() {
    this._tags = {};
    this._tagSynonyms = {};
    // The longnames for `Package` objects include a `package` namespace. There's no `package` tag,
    // though, so we declare the namespace here.
    this._namespaces = ['package'];
}
 
/** @function */
Dictionary.prototype._defineNamespace = function defineNamespace(title) {
    title = this.normalise(title || '');
 
    Eif (title && this._namespaces.indexOf(title) === -1) {
        this._namespaces.push(title);
    }
 
    return this;
};
 
/** @function */
Dictionary.prototype.defineTag = function defineTag(title, opts) {
    var tagDef = new TagDefinition(this, title, opts);
    this._tags[tagDef.title] = tagDef;
 
    if (opts && opts.isNamespace) {
        this._defineNamespace(tagDef.title);
    }
 
    return this._tags[tagDef.title];
};
 
/** @function */
Dictionary.prototype.defineSynonym = function defineSynonym(title, synonym) {
    this._tagSynonyms[synonym.toLowerCase()] = this.normalise(title);
};
 
/** @function */
Dictionary.prototype.getNamespaces = function getNamespaces() {
    return this._namespaces.slice(0);
};
 
/** @function */
Dictionary.prototype.lookUp = function lookUp(title) {
    title = this.normalise(title);
 
    if ( hasOwnProp.call(this._tags, title) ) {
       return this._tags[title];
    }
 
    return false;
};
 
/** @function */
Dictionary.prototype.isNamespace = function isNamespace(kind) {
    if (kind) {
        kind = this.normalise(kind);
        if (this._namespaces.indexOf(kind) !== -1) {
            return true;
        }
    }
 
    return false;
};
 
/** @function */
Dictionary.prototype.normalise = function normalise(title) {
    var canonicalName = title.toLowerCase();
 
    if ( hasOwnProp.call(this._tagSynonyms, canonicalName) ) {
        return this._tagSynonyms[canonicalName];
    }
 
    return canonicalName;
};
 
/** @function */
Dictionary.prototype.normalize = Dictionary.prototype.normalise;
 
// initialize the default dictionary
dictionary = new Dictionary();
definitions.defineTags(dictionary);
 
// make the constructor available for unit-testing purposes
dictionary.Dictionary = Dictionary;
 
/** @type {module:jsdoc/tag/dictionary.Dictionary} */
module.exports = dictionary;