How to use catharsis - 10 common examples

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 melonjs / melonJS / tasks / jsdoc / lib / jsdoc / tag / type.js View on Github external
types.push('*');
            break;
        case TYPES.FunctionType:
            types.push('function');
            break;
        case TYPES.NameExpression:
            types.push(parsedType.name);
            break;
        case TYPES.NullLiteral:
            types.push('null');
            break;
        case TYPES.RecordType:
            types.push('Object');
            break;
        case TYPES.TypeApplication:
            types.push( catharsis.stringify(parsedType) );
            break;
        case TYPES.TypeUnion:
            parsedType.elements.forEach(function(element) {
                types = types.concat( getTypeStrings(element) );
            });
            break;
        case TYPES.UndefinedLiteral:
            types.push('undefined');
            break;
        case TYPES.UnknownLiteral:
            types.push('?');
            break;
        default:
            // this shouldn't happen
            throw new Error( util.format('unrecognized type %s in parsed type: %j', parsedType.type,
                parsedType) );
github WASdev / lib.rtcomm.clientjs / build_resources / lib / jsdoc-master / lib / jsdoc / tag / type.js View on Github external
case TYPES.RecordType:
            types.push('Object');
            break;
        case TYPES.TypeApplication:
            // if this is the outermost type, we strip the modifiers; otherwise, we keep them
            if (isOutermostType) {
                applications = parsedType.applications.map(function(application) {
                    return catharsis.stringify(application);
                }).join(', ');
                typeString = util.format( '%s.<%s>', getTypeStrings(parsedType.expression),
                    applications );

                types.push(typeString);
            }
            else {
                types.push( catharsis.stringify(parsedType) );
            }
            break;
        case TYPES.TypeUnion:
            parsedType.elements.forEach(function(element) {
                types = types.concat( getTypeStrings(element) );
            });
            break;
        case TYPES.UndefinedLiteral:
            types.push('undefined');
            break;
        case TYPES.UnknownLiteral:
            types.push('?');
            break;
        default:
            // this shouldn't happen
            throw new Error( util.format('unrecognized type %s in parsed type: %j', parsedType.type,
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 wingedfox / dgeni-alive / src / services / getTypeName.js View on Github external
function TypeName (typeStr) {
        var type;
        var typeName = typeStr;
        try {
            if ('Function' == typeName) {
                typeName = '{' + typeName + '}';
            }
            type = catharsis.parse(typeName);
            if (type.type === catharsis.Types.TypeApplication && (type.expression.name === 'Array' || type.expression.name === 'Object')) {
                typeName = type.applications[0].name;
            } else if (type.type === catharsis.Types.FunctionType) {
                typeName = 'Function';
                type = null;
            } else {
                typeName = typeStr;
                type = null;
            }
        } catch (e) {
//            log.error('getTypeName: Parse of "%s" failed with reason: %s', typeStr, e.message);
            typeName = typeStr;
        }

        var doc = aliasMap.getDocs(typeName);
        var res = '';

        if (doc.length === 1) {
            doc = doc[0];
github wingedfox / dgeni-alive / src / services / getTypeLink.js View on Github external
function TypeLink (typeStr) {
        var type;
        var typeName = typeStr;
        try {
            if ('Function' == typeName) {
                typeName = '{' + typeName + '}';
            }
            type = catharsis.parse(typeName);
            if (type.type === catharsis.Types.TypeApplication && (type.expression.name === 'Array' || type.expression.name === 'Object')) {
                typeName = type.applications[0].name;
            } else if (type.type === catharsis.Types.FunctionType) {
                typeName = 'Function';
                type = null;
            } else {
                typeName = typeStr;
                type = null;
            }
        } catch (e) {
//            log.error('getTypeName: Parse of "%s" failed with reason: %s', typeStr, e.message);
            typeName = typeStr;
        }

        var doc = aliasMap.getDocs(typeName);
        var res = '';
github hegemonic / jsdoc-baseline / lib / helpers / expression / index.js View on Github external
let description;

            if (typeof format !== 'string') {
                format = 'simple';
            } else if (!['extended', 'simple'].includes(format)) {
                throw new Exception('The {{describeType}} helper accepts the options "simple" ' +
                    'and "extended".');
            } else if (format === 'extended' && typeof property !== 'string') {
                property = 'description';
            }

            if (typeof parsedType === 'object') {
                description = catharsis.describe(parsedType, catharsisOptions);
            } else {
                // We don't know the type
                description = catharsis.describe(catharsis.parse('?'), catharsisOptions);
            }

            if (format === 'extended') {
                return new SafeString(_.get(description.extended, property));
            } else {
                return new SafeString(description.simple);
            }
        },
github hegemonic / jsdoc-baseline / lib / helpers.js View on Github external
Helpers.prototype.describeType = function describeType(parsedType, options) {
    var catharsisOptions = {
        // TODO: add codeTag and/or codeClass based on config
        // TODO: use the correct locale
        links: templateHelper.longnameToUrl
    };
    var description;

    options = _.defaults(options || {}, {
        format: 'simple'
    });

    description = catharsis.describe(parsedType, catharsisOptions);

    switch(options.format) {
        case 'extended':
            return description.extended;
        default: {
            return description.simple;
        }
    }
};
github hegemonic / jsdoc-baseline / lib / helpers / expression / index.js View on Github external
describeType(parsedType, format, property) {
            const catharsisOptions = getCatharsisOptions(template);
            let description;

            if (typeof format !== 'string') {
                format = 'simple';
            } else if (!['extended', 'simple'].includes(format)) {
                throw new Exception('The {{describeType}} helper accepts the options "simple" ' +
                    'and "extended".');
            } else if (format === 'extended' && typeof property !== 'string') {
                property = 'description';
            }

            if (typeof parsedType === 'object') {
                description = catharsis.describe(parsedType, catharsisOptions);
            } else {
                // We don't know the type
                description = catharsis.describe(catharsis.parse('?'), catharsisOptions);
            }

            if (format === 'extended') {
                return new SafeString(_.get(description.extended, property));
            } else {
                return new SafeString(description.simple);
            }
        },
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();
            });

catharsis

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

MIT
Latest version published 4 years ago

Package Health Score

76 / 100
Full package analysis

Similar packages