json-to-jsdoc-converter
Advanced tools
Comparing version
import { Property } from "./internal"; | ||
interface ICustomTypeConstructorParams { | ||
path: string; | ||
props: Property[]; | ||
typesPrefix?: string; | ||
typesSuffix?: string; | ||
} | ||
export declare class CustomType { | ||
private readonly _typesPrefix; | ||
private readonly _typesSuffix; | ||
private readonly _path; | ||
private readonly _props; | ||
constructor({ path, props }: { | ||
path: string; | ||
props: Property[]; | ||
}); | ||
constructor({ path, props, typesPrefix, typesSuffix }: ICustomTypeConstructorParams); | ||
get path(): string; | ||
@@ -15,1 +20,2 @@ get parentPath(): string; | ||
} | ||
export {}; |
@@ -13,5 +13,7 @@ "use strict"; | ||
function CustomType(_a) { | ||
var path = _a.path, props = _a.props; | ||
var path = _a.path, props = _a.props, _b = _a.typesPrefix, typesPrefix = _b === void 0 ? "" : _b, _c = _a.typesSuffix, typesSuffix = _c === void 0 ? "" : _c; | ||
this._path = path; | ||
this._props = props; | ||
this._typesPrefix = typesPrefix; | ||
this._typesSuffix = !typesSuffix && !typesPrefix ? "Type" : typesSuffix; | ||
} | ||
@@ -43,5 +45,5 @@ Object.defineProperty(CustomType.prototype, "path", { | ||
get: function () { | ||
return this.paths | ||
return this._typesPrefix + this.paths | ||
.map(function (p) { return string_helper_1.StringHelper.capitalize(p); }) | ||
.join("") + "Type"; | ||
.join("") + this._typesSuffix; | ||
}, | ||
@@ -48,0 +50,0 @@ enumerable: true, |
@@ -0,4 +1,9 @@ | ||
interface IConvertConfig { | ||
typesPrefix?: string; | ||
typesSuffix?: string; | ||
} | ||
export declare class JsonToJsdocConverter { | ||
private _convertConfig; | ||
private _flat; | ||
convert(json: string): string; | ||
convert(json: string, convertConfig?: IConvertConfig): string; | ||
private _parseJsdoc; | ||
@@ -12,1 +17,2 @@ private _createJsDocForType; | ||
} | ||
export {}; |
@@ -10,2 +10,3 @@ "use strict"; | ||
function JsonToJsdocConverter() { | ||
this._convertConfig = {}; | ||
} | ||
@@ -15,3 +16,4 @@ JsonToJsdocConverter.prototype._flat = function (obj) { | ||
}; | ||
JsonToJsdocConverter.prototype.convert = function (json) { | ||
JsonToJsdocConverter.prototype.convert = function (json, convertConfig) { | ||
this._convertConfig = convertConfig || this._convertConfig; | ||
var obj = JSON.parse(json); | ||
@@ -67,2 +69,3 @@ var flattenedObj = this._flat(obj); | ||
JsonToJsdocConverter.prototype._createTypes = function (props) { | ||
var _this = this; | ||
var parentPaths = new Set(props.map(function (p) { return p.parentPath; })); | ||
@@ -72,3 +75,8 @@ var types = []; | ||
var _props = props.filter(function (p) { return p.parentPath === path; }); | ||
var _type = new internal_1.CustomType({ path: path, props: _props }); | ||
var _type = new internal_1.CustomType({ | ||
path: path, | ||
props: _props, | ||
typesPrefix: _this._convertConfig.typesPrefix, | ||
typesSuffix: _this._convertConfig.typesSuffix | ||
}); | ||
types.push(_type); | ||
@@ -75,0 +83,0 @@ }); |
{ | ||
"name": "json-to-jsdoc-converter", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/public/index.js", |
@@ -48,3 +48,3 @@ # json-to-jsdoc-converter | ||
const json = JSON.stringify(jsonMock1); | ||
const jsDoc = converter.convert(json); | ||
const jsDoc = converter.convert(json, { typesPrefix: "", typesSuffix: "Type" }); //you can set type name rules by passing optional config | ||
``` | ||
@@ -51,0 +51,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
23542
6.71%350
6.71%