Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
The catharsis npm package is a JavaScript library for parsing and stringifying JSDoc type expressions. It allows developers to convert JSDoc type expressions into JavaScript objects and vice versa, making it easier to work with type annotations in code documentation.
Parsing JSDoc Type Expressions
This feature allows you to parse JSDoc type expressions into JavaScript objects. The example code parses the JSDoc type expression 'Array.<string>' and converts it into a JavaScript object.
const catharsis = require('catharsis');
const parsedType = catharsis.parse('Array.<string>');
console.log(parsedType);
Stringifying JSDoc Type Expressions
This feature allows you to convert JavaScript objects back into JSDoc type expressions. The example code takes a JavaScript object representing a type and converts it into a JSDoc type expression string.
const catharsis = require('catharsis');
const typeObj = { type: 'NameExpression', name: 'string' };
const typeString = catharsis.stringify(typeObj);
console.log(typeString);
Doctrine is a popular library for parsing JSDoc comments, including type expressions. It provides more comprehensive support for JSDoc comments, including tags and descriptions, making it a more feature-rich alternative to catharsis.
jsdoctypeparser is another library for parsing JSDoc type expressions. It focuses specifically on type expressions, similar to catharsis, but offers a different API and may have different performance characteristics.
A JavaScript parser for Google Closure Compiler type expressions.
Catharsis is designed to be:
Asynchronous interface:
var catharsis = require('catharsis');
var type = '!Object';
catharsis.parse(type, function(error, parsed) {
if (error) {
console.error('unable to parse %s: %s', type, error);
} else {
console.log('%j', parsed); // {"typeName":"Object","nullable":false}
}
});
Synchronous interface:
var catharsis = require('catharsis');
var type = '!Object';
var parsed;
try {
parsed = catharsis.parseSync('!Object'); // {"typeName":"Object","nullable":false}
}
catch(e) {
console.error('unable to parse %s: %s', type, e);
}
See the test/specs/
directory for more examples of Catharsis' parse results.
With npm:
npm install catharsis
Or without:
git clone git://github.com/hegemonic/catharsis.git
Take a look at the issue tracker to see what's in store for Catharsis.
Bug reports, feature requests, and pull requests are always welcome! If you're working on a large pull request, please contact me in advance so I can help things go smoothly.
Note: The parse tree's format should not be considered final until Catharsis reaches version 1.0. I'll do my best to provide release notes for any changes.
FAQs
A JavaScript parser for Google Closure Compiler and JSDoc type expressions.
The npm package catharsis receives a total of 1,593,815 weekly downloads. As such, catharsis popularity was classified as popular.
We found that catharsis demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.