How to use the catharsis.parse function in catharsis

To help you get started, we’ve selected a few catharsis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BladeRunnerJS / brjs / brjs-sdk / sdk / jsdoc-toolkit-resources / jsdoc-toolkit / lib / jsdoc / tag / type.js View on Github external
function parseTypeExpression(tagInfo) {
    var errorMessage;
    var parsedType;

    // don't try to parse empty type expressions
    if (!tagInfo.typeExpression) {
        return tagInfo;
    }

    try {
        parsedType = catharsis.parse(tagInfo.typeExpression, {jsdoc: true});
    }
    catch (e) {
        // always re-throw so the caller has a chance to report which file was bad
        throw new Error( util.format('Invalid type expression "%s": %s', tagInfo.typeExpression,
            e.message) );
    }

    tagInfo.type = tagInfo.type.concat( getTypeStrings(parsedType, true) );
    tagInfo.parsedType = parsedType;

    // Catharsis and JSDoc use the same names for 'optional' and 'nullable'...
    ['optional', 'nullable'].forEach(function(key) {
        if (parsedType[key] !== null && parsedType[key] !== undefined) {
            tagInfo[key] = parsedType[key];
        }
    });
github jsdoc / jsdoc / packages / jsdoc / lib / jsdoc / tag / type.js View on Github external
function parseTypeExpression(tagInfo) {
    let parsedType;

    // don't try to parse empty type expressions
    if (!tagInfo.typeExpression) {
        return tagInfo;
    }

    try {
        parsedType = catharsis.parse(tagInfo.typeExpression, {jsdoc: true});
    }
    catch (e) {
        // always re-throw so the caller has a chance to report which file was bad
        throw new Error(`Invalid type expression "${tagInfo.typeExpression}": ${e.message}`);
    }

    tagInfo.type = tagInfo.type.concat( getTypeStrings(parsedType, true) );
    tagInfo.parsedType = parsedType;

    // Catharsis and JSDoc use the same names for 'optional' and 'nullable'...
    ['optional', 'nullable'].forEach(key => {
        if (parsedType[key] !== null && parsedType[key] !== undefined) {
            tagInfo[key] = parsedType[key];
        }
    });
github hegemonic / jsdoc-baseline / test / specs / lib / helpers / expression / index.js View on Github external
describe('describeType', () => {
            const catharsis = require('catharsis');

            const parsedType = catharsis.parse('!string');

            it('should use "unknown type" if no type is provided', () => {
                const description = instance.describeType(undefined);

                expect(description).toBeInstanceOf(SafeString);
                expect(description.toString()).toBe('unknown');
            });

            it('should throw if the requested format is not available', () => {
                function shouldThrow() {
                    return instance.describeType(parsedType, 'marshmallow');
                }

                expect(shouldThrow).toThrow();
            });
github melonjs / melonJS / tasks / jsdoc / lib / jsdoc / util / templateHelper.js View on Github external
function parseType(longname) {
    var catharsis = require('catharsis');
    var err;

    try {
        return catharsis.parse(longname, {jsdoc: true});
    }
    catch (e) {
        err = new Error('unable to parse ' + longname + ': ' + e.message);
        require('jsdoc/util/error').handle(err);
        return longname;
    }
}
github jsdoc / jsdoc / packages / jsdoc / lib / jsdoc / util / templateHelper.js View on Github external
function parseType(longname) {
    let err;

    try {
        return catharsis.parse(longname, {jsdoc: true});
    }
    catch (e) {
        err = new Error(`unable to parse ${longname}: ${e.message}`);
        logger.error(err);

        return longname;
    }
}
github iTowns / itowns / docs / templateHelper.js View on Github external
function parseType(longname) {
    var err;

    longname = longname.replace('<', '<');

    try {
        return catharsis.parse(longname, { jsdoc: true });
    } catch (e) {
        err = new Error(`unable to parse ${longname}: ${e.message}`);
        logger.error(err);

        return longname;
    }
}
github BladeRunnerJS / brjs / brjs-sdk / build-resources / includes / sdk / jsdoc-toolkit-resources / jsdoc-toolkit / lib / jsdoc / util / templateHelper.js View on Github external
function parseType(longname) {
    var catharsis = require('catharsis');
    var err;

    try {
        return catharsis.parse(longname, {jsdoc: true});
    }
    catch (e) {
        err = new Error('unable to parse ' + longname + ': ' + e.message);
        require('jsdoc/util/logger').error(err);
        return longname;
    }
}
github BladeRunnerJS / brjs / brjs-sdk / sdk / jsdoc-toolkit-resources / jsdoc-toolkit / lib / jsdoc / util / templateHelper.js View on Github external
function parseType(longname) {
    var err;

    try {
        return catharsis.parse(longname, {jsdoc: true});
    }
    catch (e) {
        err = new Error('unable to parse ' + longname + ': ' + e.message);
        require('jsdoc/util/logger').error(err);
        return longname;
    }
}

catharsis

A JavaScript parser for Google Closure Compiler and JSDoc type expressions.

MIT
Latest version published 4 years ago

Package Health Score

70 / 100
Full package analysis

Similar packages