Socket
Socket
Sign inDemoInstall

json-schema-to-typescript

Package Overview
Dependencies
Maintainers
1
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-to-typescript - npm Package Compare versions

Comparing version 2.3.1 to 2.4.0

6

dist/index.js

@@ -58,2 +58,8 @@ "use strict";

Compiler.prototype.getRuleType = function (rule) {
// normalize rule
// TODO: move this somewhere else
// TODO: avoid mutating rule
if (rule.type && Array.isArray(rule.type) && rule.type.length === 1) {
rule.type = rule.type[0];
}
if (rule.type === 'array' && rule.items) {

@@ -60,0 +66,0 @@ return RuleType.TypedArray;

3

dist/TsTypes.js

@@ -190,3 +190,4 @@ "use strict";

Array.prototype._type = function (settings) {
return (this.type || new Any()).toSafeType(settings) + "[]";
var type = (this.type || new Any()).toSafeType(settings);
return (type.indexOf('|') > -1 || type.indexOf('&') > -1 ? "(" + type + ")" : type) + "[]"; // hacky
};

@@ -193,0 +194,0 @@ return Array;

{
"name": "json-schema-to-typescript",
"version": "2.3.1",
"version": "2.4.0",
"description": "compile json schema to typescript typings",

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

@@ -65,2 +65,10 @@ import { EnumJSONSchema, JSONSchema, NamedEnumJSONSchema } from './JSONSchema'

private getRuleType(rule: JSONSchema): RuleType {
// normalize rule
// TODO: move this somewhere else
// TODO: avoid mutating rule
if (rule.type && Array.isArray(rule.type) && rule.type.length === 1) {
rule.type = rule.type[0]
}
if (rule.type === 'array' && rule.items) {

@@ -67,0 +75,0 @@ return RuleType.TypedArray

@@ -160,3 +160,4 @@ import { camelCase, upperFirst } from 'lodash'

_type(settings: TsTypeSettings) {
return `${(this.type || new Any()).toSafeType(settings)}[]`
const type = (this.type || new Any()).toSafeType(settings)
return `${type.indexOf('|') > -1 || type.indexOf('&') > -1 ? `(${type})` : type}[]` // hacky
}

@@ -163,0 +164,0 @@ }

@@ -10,2 +10,14 @@ export var schema = {

"type": "array"
},
"bar": {
"items": {
"type": "string"
},
"type": ["array"]
},
"baz": {
"items": {
"type": ["string", "number"]
},
"type": ["array"]
}

@@ -17,3 +29,5 @@ }

foo?: string[];
bar?: string[];
baz?: (string | number)[];
[k: string]: any;
}`

@@ -38,2 +38,5 @@ export var schema = {

"tsEnumNames": ["Four","Five","Six"]
},
"impliedHeterogeneousEnum": {
"enum": [-20.1, null, "foo", false]
}

@@ -71,4 +74,5 @@ },

impliedNamedIntegerEnum: ImpliedNamedIntegerEnum;
impliedHeterogeneousEnum?: -20.1 | null | "foo" | false;
}`
}
})
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