Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
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:
var catharsis = require('catharsis');
var type = '!Object';
var parsedType;
var expr;
try {
parsedType = catharsis.parse('!Object');
console.log('%j', parsedType); // {"type":"NameExpression,"name":"Object","nullable":false}
}
catch(e) {
console.error('unable to parse %s: %s', type, e);
}
expr = catharsis.stringify(parsedType);
console.log(expr); // !Object
See the test/specs/
directory for more examples of Catharsis' parse results.
Parse the Closure Compiler type type
, and return the parse results. Throws an error if the type
cannot be parsed.
type
: A string containing a Closure Compiler type expression.opts
: Options for parsing the type expression.
opts.useCache
: Specifies whether to use the cache of parsed types. Defaults to true
.An object containing the parse results.
Stringify the parsed Closure Compiler type expression parsedType
, and return the type expression.
If validation is enabled, throws an error if the stringified type expression cannot be parsed.
parsedType
: An object containing a parsed Closure Compiler type expression.opts
: Options for stringifying the parse results.
opts.useCache
: Specifies whether to use the cache of stringified parse results. Defaults to
true
.opts.validate
: Specifies whether to validate the stringified parse results by attempting to
parse them as a type expression. Defaults to false
.A string containing the type expression.
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.
parse()
and stringify()
methods are now synchronous, and the parseSync()
and
stringifySync()
methods have been removed. Note: This change is not backwards-compatible
with previous versions.reservedWord: true
property.new
or this
properties unless the properties are defined
in the type expression. In addition, the new
and this
properties can now use any type
expression.*
), are now parsed and stringified
correctly.null
and undefined
literals with additional properties, such as repeatable
, are now
stringified correctly.stringify()
and stringifySync()
methods, which convert a parsed type to a type
expression.opts
argument to parse()
and parseSync()
methods. Note: The
change to parse()
is not backwards-compatible with previous versions.FAQs
A JavaScript parser for Google Closure Compiler and JSDoc type expressions.
The npm package catharsis receives a total of 345,114 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.