json-schema-to-typescript
Advanced tools
Comparing version 2.1.2 to 2.2.0
@@ -7,3 +7,3 @@ // Generated by dts-bundle v0.5.0 | ||
export namespace JSONSchema { | ||
type SimpleTypes = "array" | "boolean" | "integer" | "null" | "number" | "object" | "string"; | ||
type SimpleTypes = 'array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string'; | ||
/** Core schema meta-schema */ | ||
@@ -10,0 +10,0 @@ type HttpJsonSchemaOrgDraft04Schema = { |
@@ -9,2 +9,6 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.jsonSchemaToTypescript = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var lodash_1 = require('lodash'); | ||
var multiLineCommentStart = '/** '; | ||
var multiLineCommentIndent = ' * '; | ||
var multiLineCommentEnd = ' */'; | ||
var newLineRegex = /\\n|\n/; | ||
var TsType; | ||
@@ -31,3 +35,8 @@ (function (TsType) { | ||
TsTypeBase.prototype.toBlockComment = function (settings) { | ||
return this.description && settings.declarationDescription ? "/** " + this.description + " */\n" : ''; | ||
return this.description && settings.declarationDescription ? | ||
"" + (this.description | ||
.split(newLineRegex) | ||
.map(function (line, lineNum) { return (lineNum > 0 ? multiLineCommentIndent : multiLineCommentStart) + line; }) | ||
.join('\n') + multiLineCommentEnd + '\n') : | ||
''; | ||
}; | ||
@@ -226,3 +235,4 @@ TsTypeBase.prototype._toDeclaration = function (decl, settings) { | ||
return declaration || !id ? "{\n " + this.props.map(function (_) { | ||
var decl = ' ' + _.name; | ||
var indentString = ' '; | ||
var decl = indentString + _.name; | ||
if (!_.required) | ||
@@ -233,4 +243,9 @@ decl += '?'; | ||
decl += ';'; | ||
//All descriptions will be inside jsdoc-style comments to support hinting in editors | ||
//(ie intellisense) | ||
if (settings.propertyDescription && _.type.description && !_.type.id) | ||
decl += ' // ' + _.type.description; | ||
decl = _.type.description | ||
.split(newLineRegex) | ||
.map(function (line, lineNum, lines) { return (lineNum > 0 ? multiLineCommentIndent : indentString + multiLineCommentStart) + line; }) | ||
.join('\n' + indentString) + multiLineCommentEnd + '\n' + decl; | ||
return decl; | ||
@@ -237,0 +252,0 @@ }).join('\n') + "\n}" : id; |
{ | ||
"name": "json-schema-to-typescript", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"description": "compile json schema to typescript typings", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
export namespace JSONSchema { | ||
export type SimpleTypes = "array" | "boolean" | "integer" | "null" | "number" | "object" | "string"; | ||
export type SimpleTypes = 'array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string'; | ||
/** Core schema meta-schema */ | ||
@@ -5,0 +5,0 @@ export type HttpJsonSchemaOrgDraft04Schema = { |
import { camelCase, upperFirst } from 'lodash' | ||
const multiLineCommentStart = '/** ' | ||
const multiLineCommentIndent = ' * ' | ||
const multiLineCommentEnd = ' */' | ||
const newLineRegex = /\\n|\n/ | ||
export namespace TsType { | ||
@@ -39,3 +44,9 @@ | ||
protected toBlockComment(settings: TsTypeSettings) { | ||
return this.description && settings.declarationDescription ? `/** ${this.description} */\n` : '' | ||
return this.description && settings.declarationDescription ? | ||
`${this.description | ||
.split(newLineRegex) | ||
.map((line, lineNum) => (lineNum > 0 ? multiLineCommentIndent : multiLineCommentStart) + line) | ||
.join('\n') + multiLineCommentEnd + '\n' | ||
}` : | ||
'' | ||
} | ||
@@ -185,3 +196,5 @@ protected _toDeclaration(decl: string, settings: TsTypeSettings): string { | ||
${this.props.map(_ => { | ||
let decl = ' ' + _.name | ||
const indentString = ' ' | ||
let decl = indentString + _.name | ||
if (!_.required) | ||
@@ -192,4 +205,11 @@ decl += '?' | ||
decl += ';' | ||
//All descriptions will be inside jsdoc-style comments to support hinting in editors | ||
//(ie intellisense) | ||
if (settings.propertyDescription && _.type.description && !_.type.id) | ||
decl += ' // ' + _.type.description | ||
decl = _.type.description | ||
.split(newLineRegex) | ||
.map((line, lineNum, lines) => (lineNum > 0 ? multiLineCommentIndent : indentString + multiLineCommentStart) + line) | ||
.join('\n' + indentString) + multiLineCommentEnd + '\n' + decl | ||
return decl | ||
@@ -196,0 +216,0 @@ }).join('\n')} |
@@ -37,3 +37,4 @@ export var schema = { | ||
lastName: string; | ||
age?: number; // Age in years | ||
/** Age in years */ | ||
age?: number; | ||
height?: number; | ||
@@ -40,0 +41,0 @@ favoriteFoods?: any[]; |
@@ -24,3 +24,4 @@ export var schema = { | ||
lastName: string; | ||
age?: number; // Age in years | ||
/** Age in years */ | ||
age?: number; | ||
}` |
@@ -22,3 +22,4 @@ export var schema = | ||
lastName: string; | ||
age?: number; // Age in years | ||
/** Age in years */ | ||
age?: number; | ||
height?: number; | ||
@@ -41,2 +42,2 @@ favoriteFoods?: any[]; | ||
} | ||
] | ||
] |
@@ -25,4 +25,5 @@ export var schema = { | ||
lastName: string; | ||
age?: number; // Age in years | ||
/** Age in years */ | ||
age?: number; | ||
[k: string]: any; | ||
}` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
88015
37
2415