Socket
Socket
Sign inDemoInstall

json-schema-to-flow-type

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-to-flow-type - npm Package Compare versions

Comparing version 0.0.0 to 0.0.1

8

lib/index.js

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

const unionTypes = types => _lodash2.default.join(types, ' | ');
const unionTypes = types => _lodash2.default.join(_lodash2.default.uniq(types), ' | ');
const intersectionTypes = types => _lodash2.default.join(types, ' & ');
const intersectionTypes = types => _lodash2.default.join(_lodash2.default.uniq(types), ' & ');

@@ -34,5 +34,5 @@ const fieldsToFlowObjectDef = fields => {

if (schema.additionalProperties) {
if (schema.additionalProperties || schema.patternProperties) {
return fieldsToFlowObjectDef(_extends({}, fields, {
'[key: any]': typeof schema.additionalProperties === 'object' ? processor(schema.additionalProperties) : 'any'
'[key: any]': unionTypes((schema.additionalProperties ? [typeof schema.additionalProperties === 'object' ? processor(schema.additionalProperties) : 'any'] : []).concat(_lodash2.default.map(schema.patternProperties, processor)))
}));

@@ -39,0 +39,0 @@ }

{
"name": "json-schema-to-flow-type",
"version": "0.0.0",
"version": "0.0.1",
"ava": {

@@ -5,0 +5,0 @@ "files": [

# Convert JSON Schema to Flow Type Definitions;
[![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

@@ -4,0 +14,0 @@

@@ -131,2 +131,17 @@ // @flow

test('should convert Object with patternProperties', (t: AssertContext) => {
const result = convertSchema({
type: 'object',
patternProperties: {
'^x-': {
type: 'string',
},
},
}, { type: 'SomeClass' });
t.is(result, 'type SomeClass = { [key: any]: string };');
});
test('should convert Object with nested', (t: AssertContext) => {

@@ -133,0 +148,0 @@ const result = convertSchema({

@@ -15,5 +15,5 @@ // @flow

const unionTypes = (types: Array<string>): string => _.join(types, ' | ');
const unionTypes = (types: Array<string>): string => _.join(_.uniq(types), ' | ');
const intersectionTypes = (types: Array<string>): string => _.join(types, ' & ');
const intersectionTypes = (types: Array<string>): string => _.join(_.uniq(types), ' & ');

@@ -46,10 +46,14 @@ const fieldsToFlowObjectDef = (

if (schema.additionalProperties) {
if (schema.additionalProperties || schema.patternProperties) {
return fieldsToFlowObjectDef({
...fields,
'[key: any]': (
(typeof schema.additionalProperties === 'object')
? processor(schema.additionalProperties)
: 'any'
),
'[key: any]': unionTypes((
schema.additionalProperties ? [
(typeof schema.additionalProperties === 'object')
? processor(schema.additionalProperties)
: 'any',
] : []
).concat(
_.map(schema.patternProperties, processor),
)),
});

@@ -56,0 +60,0 @@ }

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