Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typedoc-plugin-typescript-declaration

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typedoc-plugin-typescript-declaration - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

215

dist/index.js

@@ -5,7 +5,7 @@ 'use strict';

var declaration = require('typedoc/dist/lib/utils/options/declaration');
var models = require('typedoc/dist/lib/models');
var converter = require('typedoc/dist/lib/converter');
var components = require('typedoc/dist/lib/output/components');
var components$1 = require('typedoc/dist/lib/converter/components');
var models = require('typedoc/dist/lib/models');
var declaration = require('typedoc/dist/lib/utils/options/declaration');
var CommentPlugin = require('typedoc/dist/lib/converter/plugins/CommentPlugin');

@@ -19,2 +19,133 @@ var path = require('path');

/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function propertySorter(selector) {
return (a, b) => {
const valA = selector(a);
const valB = selector(b);
if (valA > valB) {
return 1;
}
if (valA < valB) {
return -1;
}
return 0;
};
}
class KeyOfCommentResolver {
resolveKeys(project, reflection, override = false) {
var _a, _b;
const node = reflection;
const type = node.type;
const reference = this.getDeclaration(project, type.target);
let keys = this.getKeys(reference)
.sort(propertySorter(r => r.id))
.map(r => { var _a, _b; return ((_a = type.target) === null || _a === void 0 ? void 0 : _a.type) === 'reference' ? `[[${(_b = type.target) === null || _b === void 0 ? void 0 : _b.name}.${r.name}|\`${r.name}\`]]` : `\`${r.name}\``; })
.join(', ');
if (!node.comment) {
node.comment = new models.Comment();
}
if (!node.comment.tags) {
node.comment.tags = [];
}
let tag = (_b = (_a = node.comment) === null || _a === void 0 ? void 0 : _a.tags) === null || _b === void 0 ? void 0 : _b.find(t => t.tagName === 'keys');
if (tag) {
if (override) {
tag.text = keys;
}
}
else {
tag = new models.CommentTag('keys', undefined, keys);
node.comment.tags.push(tag);
}
}
shouldResolveKeys(project, reflection) {
var _a, _b, _c;
const node = reflection;
if (node.kind === models.ReflectionKind.TypeAlias) {
const type = node.type;
if (((_a = type) === null || _a === void 0 ? void 0 : _a.type) === 'typeOperator' && ((_b = type) === null || _b === void 0 ? void 0 : _b.operator) === 'keyof' && ((_c = type) === null || _c === void 0 ? void 0 : _c.target)) {
const reference = this.getDeclaration(project, type.target);
if (this.getKeys(reference)) {
return true;
}
}
}
return false;
}
getDeclaration(project, type) {
let reference;
if (type.type === 'reference') {
const targetType = type;
reference = project.findReflectionByName(targetType.name);
}
else if (type.type === 'reflection') {
const reflectionType = type;
reference = reflectionType.declaration;
}
return reference;
}
getKeys(reflection) {
var _a, _b, _c, _d;
return ((_a = reflection) === null || _a === void 0 ? void 0 : _a.children) || ((_d = (_c = (_b = reflection) === null || _b === void 0 ? void 0 : _b.type) === null || _c === void 0 ? void 0 : _c.declaration) === null || _d === void 0 ? void 0 : _d.children)
|| [];
}
static instance() {
if (!KeyOfCommentResolver._instance) {
KeyOfCommentResolver._instance = new KeyOfCommentResolver();
}
return KeyOfCommentResolver._instance;
}
}
var AddKeysTagOption;
(function (AddKeysTagOption) {
AddKeysTagOption[AddKeysTagOption["off"] = 0] = "off";
AddKeysTagOption[AddKeysTagOption["notexists"] = 1] = "notexists";
AddKeysTagOption[AddKeysTagOption["force"] = 2] = "force";
})(AddKeysTagOption || (AddKeysTagOption = {}));
const addKeysOptionMapping = {
off: AddKeysTagOption.off,
notexists: AddKeysTagOption.notexists,
force: AddKeysTagOption.force,
};
let KeyOfCommentConverter = class KeyOfCommentConverter extends components$1.ConverterComponent {
initialize() {
this.listenTo(this.owner, {
[converter.Converter.EVENT_RESOLVE_BEGIN]: this.onBeginResolve,
});
}
onBeginResolve(context) {
const resolver = KeyOfCommentResolver.instance();
const override = this.application.options.getValue('keyofComments') === AddKeysTagOption.force;
Object.values(context.project.reflections)
.filter(item => resolver.shouldResolveKeys(context.project, item))
.forEach(item => resolver.resolveKeys(context.project, item, override));
}
};
KeyOfCommentConverter = __decorate([
components.Component({ name: 'keyof-comment' })
], KeyOfCommentConverter);
function join(delimiter, ...values) {

@@ -296,16 +427,2 @@ return values.filter(v => v !== null && v !== undefined && v !== '')

function propertySorter(selector) {
return (a, b) => {
const valA = selector(a);
const valB = selector(b);
if (valA > valB) {
return 1;
}
if (valA < valB) {
return -1;
}
return 0;
};
}
class ContainerRenderer extends ReflectionRenderer {

@@ -342,3 +459,3 @@ constructor(type) {

}
renderBody(declarationNode, indentBy = 1) {
renderBody(declarationNode, indentBy = 1, delimiter = ';') {
let sorter;

@@ -361,3 +478,3 @@ const isGroupType = !!['module', 'project'].find(type => type === this._type);

.sort(sorter)
.map(node => ReflectionFormatter.instance().render(node, ';'))
.map(node => ReflectionFormatter.instance().render(node, delimiter))
.filter(s => s)

@@ -539,3 +656,6 @@ .join(insertBlankLine ? '\n\n' : '\n');

class TypeAliasRenderer extends ReflectionRenderer {
class TypeAliasRenderer extends ContainerRenderer {
constructor() {
super('type_alias');
}
render(node, terminationCharacter) {

@@ -559,7 +679,6 @@ var _a;

lines.push(join(' ', ...declarationParts, '{'));
const indent = this._indentor.getIndent(1);
const members = type.declaration.children
.sort(propertySorter(node => node.id))
.map(node => ReflectionFormatter.instance().render(node, ';'));
lines.push(...members.map(block => block.split(/\r?\n(?=.)/gm).map(l => `${indent}${l}`).join('\n')));
const body = this.renderBody(type.declaration);
if (body) {
lines.push(body);
}
lines.push('}');

@@ -574,4 +693,8 @@ }

class TypeLiteralRenderer extends ReflectionRenderer {
class TypeLiteralRenderer extends ContainerRenderer {
constructor() {
super('type_literal');
}
render(node) {
var _a;
const lines = [];

@@ -583,3 +706,11 @@ if (node.comment) {

if (member.children) {
lines.push(join(' ', '{', member.children.map(c => ReflectionFormatter.instance().render(c)).join(', '), '}'));
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.kind) === models.ReflectionKind.TypeAlias) {
const body = this.renderBody(member, 1, ',');
if (body) {
lines.push('{', body, '}');
}
}
else {
lines.push(join(' ', '{', member.children.map(c => ReflectionFormatter.instance().render(c)).join(', '), '}'));
}
}

@@ -669,24 +800,2 @@ if (member.signatures) {

/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
const VersionExpression = /^(\d)+(\.(\d+))?(\.(\d+))?(\.(\d+))?(-([\w][\w.-]*))?$/;

@@ -921,2 +1030,9 @@ class Version {

app.options.addDeclaration({
name: 'keyofComments',
type: declaration.ParameterType.Map,
help: 'Expands the values of the keyof operator and adds a tag, default is force which overrides existing values',
defaultValue: AddKeysTagOption.force,
map: addKeysOptionMapping,
});
app.options.addDeclaration({
name: 'maxVersion',

@@ -934,2 +1050,5 @@ type: declaration.ParameterType.String,

}
if (app.options.getValue('keyofComments') !== AddKeysTagOption.off) {
app.converter.addComponent('keyof-comment', new KeyOfCommentConverter(app.converter));
}
ReflectionFormatter.sortOption = app.options.getValue('sortOption');

@@ -936,0 +1055,0 @@ app.renderer.addComponent('typescript-declaration-renderer', new TypeScriptDeclarationRenderer(app.renderer));

{
"name": "typedoc-plugin-typescript-declaration",
"version": "0.1.5",
"version": "0.1.6",
"description": "Typedoc plugin to render to typescript declaration file",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc