mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
add stripNamespace and stripVariation methods (#858)
This commit is contained in:
parent
60b239fd33
commit
e471a1f55e
@ -197,6 +197,11 @@ exports.applyNamespace = function(longname, ns) {
|
|||||||
return longname;
|
return longname;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: docs
|
||||||
|
exports.stripNamespace = function(longname) {
|
||||||
|
return longname.replace(/^[a-zA-Z]+:/, '');
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: docs
|
// TODO: docs
|
||||||
function atomize(longname, sliceChars, forcedMemberof) {
|
function atomize(longname, sliceChars, forcedMemberof) {
|
||||||
var i;
|
var i;
|
||||||
@ -290,9 +295,14 @@ exports.combine = function(parts) {
|
|||||||
(parts.variation || '');
|
(parts.variation || '');
|
||||||
};
|
};
|
||||||
|
|
||||||
function stripVariation(name) {
|
// TODO: docs
|
||||||
return name.replace(/\([^)]\)$/, '');
|
exports.stripVariation = function(name) {
|
||||||
}
|
var parts = exports.shorten(name);
|
||||||
|
|
||||||
|
parts.variation = '';
|
||||||
|
|
||||||
|
return exports.combine(parts);
|
||||||
|
};
|
||||||
|
|
||||||
function splitLongname(longname, options) {
|
function splitLongname(longname, options) {
|
||||||
var chunks = [];
|
var chunks = [];
|
||||||
@ -307,7 +317,7 @@ function splitLongname(longname, options) {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
if (!options.includeVariation) {
|
if (!options.includeVariation) {
|
||||||
previousName = stripVariation(previousName);
|
previousName = exports.stripVariation(previousName);
|
||||||
}
|
}
|
||||||
currentNameInfo = nameInfo[previousName] = atomize(previousName, splitters);
|
currentNameInfo = nameInfo[previousName] = atomize(previousName, splitters);
|
||||||
previousName = currentNameInfo.memberof;
|
previousName = currentNameInfo.memberof;
|
||||||
|
|||||||
@ -21,6 +21,10 @@ describe('jsdoc/name', function() {
|
|||||||
expect(typeof jsdoc.name.applyNamespace).toBe('function');
|
expect(typeof jsdoc.name.applyNamespace).toBe('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should export a "stripNamespace" function', function() {
|
||||||
|
expect(typeof jsdoc.name.stripNamespace).toBe('function');
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: add tests for other exported constants
|
// TODO: add tests for other exported constants
|
||||||
it('should export a SCOPE enum', function() {
|
it('should export a SCOPE enum', function() {
|
||||||
expect(jsdoc.name.SCOPE).toBeDefined();
|
expect(jsdoc.name.SCOPE).toBeDefined();
|
||||||
@ -37,6 +41,10 @@ describe('jsdoc/name', function() {
|
|||||||
expect(typeof jsdoc.name.combine).toBe('function');
|
expect(typeof jsdoc.name.combine).toBe('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should export a "stripVariation" function', function() {
|
||||||
|
expect(typeof jsdoc.name.stripVariation).toBe('function');
|
||||||
|
});
|
||||||
|
|
||||||
it('should export a "longnamesToTree" function', function() {
|
it('should export a "longnamesToTree" function', function() {
|
||||||
expect(jsdoc.name.longnamesToTree).toBeDefined();
|
expect(jsdoc.name.longnamesToTree).toBeDefined();
|
||||||
expect(typeof jsdoc.name.longnamesToTree).toBe('function');
|
expect(typeof jsdoc.name.longnamesToTree).toBe('function');
|
||||||
@ -233,10 +241,49 @@ describe('jsdoc/name', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('stripNamespace', function() {
|
||||||
|
it('should not change longnames without a leading namespace', function() {
|
||||||
|
var startName = 'Foo#bar';
|
||||||
|
var endName = jsdoc.name.stripNamespace(startName);
|
||||||
|
|
||||||
|
expect(endName).toBe(startName);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not change longnames with an embedded namespace', function() {
|
||||||
|
var startName = 'foo/bar.baz~event:qux';
|
||||||
|
var endName = jsdoc.name.stripNamespace(startName);
|
||||||
|
|
||||||
|
expect(endName).toBe(startName);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove the leading namespace, if present', function() {
|
||||||
|
var startName = 'module:foo/bar/baz';
|
||||||
|
var endName = jsdoc.name.stripNamespace(startName);
|
||||||
|
|
||||||
|
expect(endName).toBe('foo/bar/baz');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
xdescribe('combine', function() {
|
xdescribe('combine', function() {
|
||||||
// TODO: tests
|
// TODO: tests
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('stripVariation', function() {
|
||||||
|
it('should not change longnames without a variation', function() {
|
||||||
|
var startName = 'Foo#bar';
|
||||||
|
var endName = jsdoc.name.stripVariation(startName);
|
||||||
|
|
||||||
|
expect(endName).toBe(startName);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove the variation, if present', function() {
|
||||||
|
var startName = 'Foo#bar(qux)';
|
||||||
|
var endName = jsdoc.name.stripVariation(startName);
|
||||||
|
|
||||||
|
expect(endName).toBe('Foo#bar');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
xdescribe('longnamesToTree', function() {
|
xdescribe('longnamesToTree', function() {
|
||||||
// TODO: tests
|
// TODO: tests
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user