json-schema-to-flow-type
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -110,3 +110,3 @@ 'use strict'; | ||
if (_lodash2.default.isArray(schema.type)) { | ||
return f.union(_lodash2.default.map(schema.type, type => convertSchema(_extends({}, schema, { | ||
return f.union(_lodash2.default.map([].concat(schema.type || []), type => convertSchema(_extends({}, schema, { | ||
type | ||
@@ -132,3 +132,3 @@ })))); | ||
switch (_lodash2.default.toLower(schema.type)) { | ||
switch (_lodash2.default.toLower(String(schema.type))) { | ||
case 'string': | ||
@@ -135,0 +135,0 @@ return f.flowType('string'); |
@@ -35,3 +35,3 @@ 'use strict'; | ||
const processObjectSchema = (flowSchema, processor) => { | ||
const fields = _lodash2.default.reduce(flowSchema.$properties, (nextFields, fieldFlowSchema, field) => _extends({}, nextFields, { | ||
const fields = _lodash2.default.reduce(flowSchema.$properties || {}, (nextFields, fieldFlowSchema, field) => _extends({}, nextFields, { | ||
[`${ field }${ _lodash2.default.includes(flowSchema.$required, field) ? '' : '?' }`]: processor(fieldFlowSchema) | ||
@@ -38,0 +38,0 @@ }), {}); |
{ | ||
"name": "json-schema-to-flow-type", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"ava": { | ||
@@ -17,4 +17,3 @@ "files": [ | ||
"build": "rm -rf lib && babel src --ignore __**__ -d lib", | ||
"flow-typed": "flow-typed install", | ||
"postinstall": "npm run flow-typed", | ||
"postinstall": "flow-typed update", | ||
"prepublish": "npm test && npm run build" | ||
@@ -37,3 +36,8 @@ }, | ||
], | ||
"license": "WTFPL" | ||
} | ||
"license": "WTFPL", | ||
"repository": { | ||
"url": "git@github.com:morlay/json-schema-to-flow-type.git", | ||
"type": "git" | ||
}, | ||
"author": "Morlay <morlay@qq.com>" | ||
} |
@@ -1,13 +0,10 @@ | ||
# Convert JSON Schema to Flow Type Definitions; | ||
# Convert JSON Schema to Flow Type Definitions | ||
[![Build Status](https://img.shields.io/travis/morlay/json-schema-to-flow-type.svg?style=flat-square)](https://travis-ci.org/morlay/json-schema-to-flow-type) | ||
[![NPM](https://img.shields.io/npm/v/json-schema-to-flow-type.svg?style=flat-square)](https://npmjs.org/package/json-schema-to-flow-type) | ||
[![Dependencies](https://img.shields.io/david/morlay/json-schema-to-flow-type.svg?style=flat-square)](https://david-dm.org/morlay/json-schema-to-flow-type) | ||
[![License](https://img.shields.io/npm/l/json-schema-to-flow-type.svg?style=flat-square)](https://npmjs.org/package/json-schema-to-flow-type) | ||
[![npm][json-schema-to-flow-type-badge]][json-schema-to-flow-type] | ||
[![dependences][json-schema-to-flow-type-deps-badge]][json-schema-to-flow-type-deps] | ||
[json-schema-to-flow-type]: https://www.npmjs.com/package/@morlay/json-schema-to-flow-type | ||
[json-schema-to-flow-type-badge]: https://img.shields.io/npm/v/@morlay/json-schema-to-flow-type.svg | ||
[json-schema-to-flow-type-deps]: https://david-dm.org/morlay/dep-packages?path=packages/json-schema-to-flow-type | ||
[json-schema-to-flow-type-deps-badge]: https://david-dm.org/morlay/dep-packages.svg?path=packages/json-schema-to-flow-type | ||
## APIs | ||
@@ -14,0 +11,0 @@ |
@@ -5,3 +5,6 @@ // @flow | ||
import type { Schema } from './schema.js.flow'; | ||
import type { | ||
Schema, | ||
SimpleTypes, | ||
} from './schema.js.flow'; | ||
@@ -147,6 +150,11 @@ type FlowType = 'Object' | 'Array' | 'string' | 'number' | 'boolean' | 'null' | 'any' | 'void'; | ||
if (_.isArray(schema.type)) { | ||
return f.union(_.map(schema.type, (type) => convertSchema({ | ||
...schema, | ||
type, | ||
}))); | ||
return f.union( | ||
_.map( | ||
[].concat(schema.type || []), | ||
(type: SimpleTypes) => convertSchema({ | ||
...schema, | ||
type, | ||
}), | ||
) | ||
); | ||
} | ||
@@ -177,3 +185,3 @@ | ||
switch (_.toLower(schema.type)) { | ||
switch (_.toLower(String(schema.type))) { | ||
case 'string': | ||
@@ -180,0 +188,0 @@ return f.flowType('string'); |
@@ -42,3 +42,3 @@ // @flow | ||
const fields = _.reduce( | ||
flowSchema.$properties, | ||
flowSchema.$properties || {}, | ||
(nextFields: Object, fieldFlowSchema: FlowSchema, field: string) => ({ | ||
@@ -45,0 +45,0 @@ ...nextFields, |
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
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
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
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
80816
2544
2
1
0
39