Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
catharsis
Advanced tools
Readme
A JavaScript parser for Google Closure Compiler type expressions.
Catharsis is designed to be:
var catharsis = require('catharsis');
var type;
var jsdocType;
var parsedType;
var parsedJsdocType;
// normal parsing
try {
type = '!Object';
parsedType = catharsis.parse(type);
console.log('%j', parsedType); // {"type":"NameExpression,"name":"Object","nullable":false}
}
catch(e) {
console.error('unable to parse %s: %s', type, e);
}
// lenient parsing
try {
jsdocType = 'number|string'; // should be (number|string)
parsedJsdocType = catharsis.parse(jsdocType, {lenient: true});
}
catch (e) {
console.error('you will not see this error, thanks to lenient mode!');
}
console.log(catharsis.stringify(parsedType)); // !Object
console.log(catharsis.stringify(parsedJsdocType)); // number|string
console.log(catharsis.stringify(parsedJsdocType, // (number|string)
{useCache: false}));
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.
When called without options, Catharsis attempts to parse type expressions in the same way as
Closure Compiler. When the lenient
option is enabled, Catharsis can also parse several kinds of
type expressions that are used in JSDoc:
function
is treated as a function type with no parameters.Array.<string>
and
Array<string>
will be parsed in the same way.[]
to a name expression (for example, string[]
) to interpret it as a type
application with the expression Array
(for example, Array.<string>
).(number|string)
and
number|string
will be parsed in the same way.#
, ~
, :
, and /
.type
: A string containing a Closure Compiler type expression.options
: Options for parsing the type expression.
options.lenient
: Specifies whether to enable lenient mode. Defaults to false
.options.useCache
: Specifies whether to use the cache of parsed types. Defaults to true
.An object containing the parse results. See the test/specs/
directory for examples of the parse
results for different type expressions.
The object also includes two non-enumerable properties:
lenient
: A boolean indicating whether the type expression was parsed in lenient mode.typeExpression
: A string containing the type expression that was parsed.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.options
: Options for stringifying the parse results.
options.htmlSafe
: Specifies whether to return an HTML-safe string that replaces left angle
brackets (<
) with the corresponding entity (<
). Note: Characters in name expressions
are not escaped.options.useCache
: Specifies whether to use the cache of stringified parse results. If the
cache is enabled, and the parsed type expression includes a typeExpression
property, the
typeExpression
property will be returned as-is. Defaults to true
.options.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.
:
and /
.[]
(for example, string[]
)
will be interpreted as a type application with the expression Array
(for example,
Array.<string>
).parse()
and stringify()
methods now honor all of the specified options.lenient
: A boolean indicating whether the type expression was parsed in lenient mode.typeExpression
: A string containing the original type expression.stringify()
method now honors the useCache
option. If a parsed type includes a
typeExpression
property, and useCache
is not set to false
, the stringified type will be
identical to the original type expression.integer
, are now
parsed correctly.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.
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
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).