Socket
Socket
Sign inDemoInstall

catharsis

Package Overview
Dependencies
1
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.8.11 to 0.9.0

51

catharsis.js

@@ -6,3 +6,3 @@ /**

* @author Jeff Williams <jeffrey.l.williams@gmail.com>
* @license MIT License <http://opensource.org/licenses/mit-license.php/>
* @license MIT
*/

@@ -15,13 +15,13 @@

const typeExpressionCache = {
normal: {},
jsdoc: {}
normal: new Map(),
jsdoc: new Map()
};
const parsedTypeCache = {
normal: {},
htmlSafe: {}
normal: new Map(),
htmlSafe: new Map()
};
const descriptionCache = {
normal: {}
normal: new Map()
};

@@ -85,6 +85,6 @@

const cache = getTypeExpressionCache(options);
let parsedType;
let parsedType = cache ? cache.get(expr) : null;
if (cache && Object.prototype.hasOwnProperty.call(cache, expr)) {
return cache[expr];
if (parsedType) {
return parsedType;
} else {

@@ -95,3 +95,3 @@ parsedType = parse(expr, options);

if (cache) {
cache[expr] = parsedType;
cache.set(expr, parsedType);
}

@@ -105,3 +105,3 @@

const cache = getParsedTypeCache(options);
let json;
let stringified;

@@ -111,6 +111,9 @@ if (canReturnOriginalExpression(parsedType, options)) {

} else if (cache) {
json = JSON.stringify(parsedType);
cache[json] = cache[json] || stringify(parsedType, options);
stringified = cache.get(parsedType);
if (!stringified) {
stringified = stringify(parsedType, options);
cache.set(parsedType, stringified);
}
return cache[json];
return stringified;
} else {

@@ -123,15 +126,15 @@ return stringify(parsedType, options);

const cache = getDescriptionCache(options);
let json;
let result;
let description = cache ? cache.get(parsedType) : null;
if (cache) {
json = JSON.stringify(parsedType);
cache[json] = cache[json] || describe(parsedType, options);
return cache[json];
if (description) {
return description;
} else {
result = describe(parsedType, options);
result = prepareFrozenObject(result, null, options);
description = describe(parsedType, options);
description = prepareFrozenObject(description, null, options);
return result;
if (cache) {
cache.set(parsedType, description);
}
return description;
}

@@ -138,0 +141,0 @@ }

@@ -478,16 +478,34 @@ const _ = require('lodash');

_getHrefForString(nameString) {
let href = '';
const links = this._options.links;
if (!links) {
return href;
}
// accept a map or an object
if (links instanceof Map) {
href = links.get(nameString);
} else if ({}.hasOwnProperty.call(links, nameString)) {
href = links[nameString];
}
return href;
}
_addLinks(nameString) {
let linkClass = '';
const options = this._options;
const href = this._getHrefForString(nameString);
let link = nameString;
let linkClass = this._options.linkClass || '';
if (options.links && Object.prototype.hasOwnProperty.call(options.links, nameString)) {
if (options.linkClass) {
linkClass = ` class="${options.linkClass}"`;
if (href) {
if (linkClass) {
linkClass = ` class="${linkClass}"`;
}
nameString = `<a href="${options.links[nameString]}"${linkClass}>${nameString}</a>`;
link = `<a href="${href}"${linkClass}>${nameString}</a>`;
}
return nameString;
return link;
}

@@ -494,0 +512,0 @@

@@ -207,17 +207,15 @@ /* eslint-disable class-methods-use-this */

_addLinks(nameString) {
let openTag;
const href = this._getHrefForString(nameString);
let link = nameString;
let linkClass = this._options.linkClass || '';
let linkClass = '';
const options = this._options;
if (options.links && Object.prototype.hasOwnProperty.call(options.links, nameString)) {
if (options.linkClass) {
linkClass = ` class="${options.linkClass}"`;
if (href) {
if (linkClass) {
linkClass = ` class="${linkClass}"`;
}
openTag = `<a href="${options.links[nameString]}"${linkClass}>`;
nameString = `${openTag + nameString}</a>`;
link = `<a href="${href}"${linkClass}>${nameString}</a>`;
}
return nameString;
return link;
}

@@ -234,2 +232,20 @@

_getHrefForString(nameString) {
let href = '';
const links = this._options.links;
if (!links) {
return href;
}
// accept a map or an object
if (links instanceof Map) {
href = links.get(nameString);
} else if ({}.hasOwnProperty.call(links, nameString)) {
href = links[nameString];
}
return href;
}
_signature(type) {

@@ -236,0 +252,0 @@ let param;

{
"version": "0.8.11",
"version": "0.9.0",
"name": "catharsis",

@@ -13,7 +13,7 @@ "description": "A JavaScript parser for Google Closure Compiler and JSDoc type expressions.",

"dependencies": {
"lodash": "^4.17.14"
"lodash": "^4.17.15"
},
"devDependencies": {
"ajv": "^6.10.2",
"mocha": "^6.1.4",
"ajv": "^6.12.2",
"mocha": "^8.0.1",
"pegjs": "^0.10.0",

@@ -24,3 +24,3 @@ "should": "^13.2.3",

"engines": {
"node": ">= 8"
"node": ">= 10"
},

@@ -27,0 +27,0 @@ "scripts": {

# Catharsis
[![Build Status][travis-img]][travis-url]
[travis-img]: https://travis-ci.com/hegemonic/catharsis.svg?branch=master
[travis-url]: https://travis-ci.com/hegemonic/catharsis
A JavaScript parser for

@@ -9,6 +14,5 @@ [Google Closure Compiler](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#type-expressions)

+ **Accurate**. Catharsis is based on a [PEG.js](http://pegjs.majda.cz/) grammar
that's designed to handle any valid type expression. It uses a
[Mocha](http://visionmedia.github.com/mocha/) test suite to verify the parser's
accuracy.
+ **Accurate**. Catharsis is based on a [PEG.js](https://pegjs.org/) grammar
that's designed to handle any valid type expression. It uses a thorough test
suite to verify the parser's accuracy.
+ **Fast**. Parse results are cached, so the parser is invoked only when

@@ -24,7 +28,7 @@ necessary.

```js
var catharsis = require('catharsis');
const catharsis = require('catharsis');
// Closure Compiler parsing
var type = '!Object';
var parsedType;
const type = '!Object';
let parsedType;
try {

@@ -37,4 +41,4 @@ parsedType = catharsis.parse(type); // {"type":"NameExpression,"name":"Object","nullable":false}

// JSDoc-style type expressions enabled
var jsdocType = 'string[]'; // Closure Compiler expects Array.<string>
var parsedJsdocType;
const jsdocType = 'string[]'; // Closure Compiler expects Array.<string>
let parsedJsdocType;
try {

@@ -96,4 +100,4 @@ parsedJsdocType = catharsis.parse(jsdocType, {jsdoc: true});

An object containing the parse results. See the
[`test/specs` directory](test/specs) for examples of the parse results for
different type expressions.
[`test/specs` directory](https://github.com/hegemonic/catharsis/tree/master/test/specs)
for examples of the parse results for different type expressions.

@@ -121,8 +125,8 @@ The object also includes two non-enumerable properties:

`options.links` is provided. By default, no CSS class is added.
+ `options.links`: An object whose keys are name expressions and whose
values are URIs. If a name expression matches a key in `options.links`, the
name expression is wrapped in an HTML `<a>` tag that links to the URI. If
`options.linkClass` is specified, the `<a>` tag includes a `class`
attribute. **Note**: When using this option, parsed types are always
restringified, and the resulting string is not cached.
+ `options.links`: An object or map whose keys are name expressions and
whose values are URIs. If a name expression matches a key in
`options.links`, the name expression will be wrapped in an HTML `<a>` tag
that links to the URI. If you also specify `options.linkClass`, the `<a>`
tag includes a `class` attribute. **Note**: When using this option, parsed
types are always restringified, and the resulting string is not cached.
+ `options.restringify`: Forces Catharsis to restringify the parsed type. If

@@ -197,8 +201,8 @@ this option is not specified, and the parsed type object includes a

`options.links` is provided. By default, no CSS class is added.
+ `options.links`: An object whose keys are name expressions and whose
values are URIs. If a name expression matches a key in `options.links`, the
name expression will be wrapped in an HTML `<a>` tag that links to the URI.
If you also specify `options.linkClass`, the `<a>` tag includes a `class`
attribute. **Note**: When you use this option, the description is not
cached.
+ `options.links`: An object or map whose keys are name expressions and
whose values are URIs. If a name expression matches a key in
`options.links`, the name expression will be wrapped in an HTML `<a>` tag
that links to the URI. If you also specify `options.linkClass`, the `<a>`
tag includes a `class` attribute. **Note**: When you use this option, the
description is not cached.
+ `options.resources`: An object that specifies how to describe type

@@ -242,2 +246,6 @@ expressions for a given language. The object's property names should use the

+ 0.9.0 (June 2020):
+ For the `describe()` and `stringify()` methods, the `options.links`
parameter now accepts either a map or an object.
+ Catharsis now requires Node.js 10 or later.
+ 0.8.11 (July 2019): Updated dependencies.

@@ -363,4 +371,4 @@ + 0.8.10 (May 2019): Updated dependencies.

identical, to the format used by the
[doctrine](https://github.com/Constellation/doctrine) parser. **Note**: This
change is not backwards-compatible with previous versions.
[doctrine](https://github.com/eslint/doctrine) parser. **Note**: This change
is not backwards-compatible with previous versions.
+ Name expressions that contain a reserved word now include a

@@ -367,0 +375,0 @@ `reservedWord: true` property.

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc