admin管理员组

文章数量:1026989

I can't find a way to print space when documenting properties default values in JSDOC. Example: /** * @prop {string} str='String with space' - The string. */

This will be documented as:

Name    Type      Default       Description
str     string    'String       with space' - The string

Any suggestion how to do the proper one?

I can't find a way to print space when documenting properties default values in JSDOC. Example: /** * @prop {string} str='String with space' - The string. */

This will be documented as:

Name    Type      Default       Description
str     string    'String       with space' - The string

Any suggestion how to do the proper one?

Share Improve this question asked Feb 11, 2016 at 8:32 Ardit MetiArdit Meti 5815 silver badges22 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

At least since jsdoc 3.3.0 you can do it this way.

/**
 * @prop {string} [str=String with space] - The string.
 */

I don't quite have the solution, but today I was facing the same issue and found a work-around. :) The problem is that the current jsdoc parser (and regex) only handles this correctly if we use the optional brackets. And on this case, we want a default not being optional.

Inside publish.js of your template add this. I use the " - " as separator, so make this work, use " - " on your descriptions and this will post-process the parser correctly.

data().each(function(doclet) {
    if (doclet.properties) {
        doclet.properties = doclet.properties.map(function(property) {
            var separator = " - ",
                separatorLength = separator.length;

            var defaultvalue = property.defaultvalue;
            var description = property.description;

            if( property.defaultvalue !== 'undefined' && !property.optional && description.indexOf(separator) > 0) {
                var index = description.indexOf(separator);
                defaultvalue += " " + description.substr(separatorLength, index-separatorLength);
                description = "<p>" + description.substr(index + separatorLength, description.length);
            }

            return {
                defaultvalue: defaultvalue,
                description: description,
                type: property.type,
                name: property.name
            }  
        });                  
    }
});

I can't find a way to print space when documenting properties default values in JSDOC. Example: /** * @prop {string} str='String with space' - The string. */

This will be documented as:

Name    Type      Default       Description
str     string    'String       with space' - The string

Any suggestion how to do the proper one?

I can't find a way to print space when documenting properties default values in JSDOC. Example: /** * @prop {string} str='String with space' - The string. */

This will be documented as:

Name    Type      Default       Description
str     string    'String       with space' - The string

Any suggestion how to do the proper one?

Share Improve this question asked Feb 11, 2016 at 8:32 Ardit MetiArdit Meti 5815 silver badges22 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

At least since jsdoc 3.3.0 you can do it this way.

/**
 * @prop {string} [str=String with space] - The string.
 */

I don't quite have the solution, but today I was facing the same issue and found a work-around. :) The problem is that the current jsdoc parser (and regex) only handles this correctly if we use the optional brackets. And on this case, we want a default not being optional.

Inside publish.js of your template add this. I use the " - " as separator, so make this work, use " - " on your descriptions and this will post-process the parser correctly.

data().each(function(doclet) {
    if (doclet.properties) {
        doclet.properties = doclet.properties.map(function(property) {
            var separator = " - ",
                separatorLength = separator.length;

            var defaultvalue = property.defaultvalue;
            var description = property.description;

            if( property.defaultvalue !== 'undefined' && !property.optional && description.indexOf(separator) > 0) {
                var index = description.indexOf(separator);
                defaultvalue += " " + description.substr(separatorLength, index-separatorLength);
                description = "<p>" + description.substr(index + separatorLength, description.length);
            }

            return {
                defaultvalue: defaultvalue,
                description: description,
                type: property.type,
                name: property.name
            }  
        });                  
    }
});

本文标签: javascriptHow to write space in default values of properties in jsdocStack Overflow