Socket
Socket
Sign inDemoInstall

json-schema-migrate

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-migrate - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

77

lib/index.js

@@ -99,34 +99,57 @@ 'use strict';

}
if (dataSchema.id) dataSchema.$id = use('id');
var $s = dataSchema.$schema;
if ($s) {
dataSchema.$schema = $s == metaSchema4.id || $s == metaSchemaV5.id
? 'http://json-schema.org/draft-06/schema#'
: $s == hyperSchema.id
? 'http://json-schema.org/draft-06/hyper-schema#'
: $s;
var dsCopy = copy(dataSchema);
var key;
for (key in dataSchema) delete dataSchema[key];
for (var i=0; i<keys.length; i++) {
key = keys[i];
switch (key) {
case 'id':
dataSchema.$id = dsCopy.id;
break;
case '$schema':
var $s = dsCopy.$schema;
dataSchema.$schema = $s == metaSchema4.id || $s == metaSchemaV5.id
? 'http://json-schema.org/draft-06/schema#'
: $s == hyperSchema.id
? 'http://json-schema.org/draft-06/hyper-schema#'
: $s;
break;
case 'constant':
dataSchema.const = dsCopy.constant;
break;
case 'enum':
if (Array.isArray(dsCopy.enum)
&& dsCopy.enum.length == 1
&& dsCopy.constant === undefined) {
dataSchema.const = dsCopy.enum[0];
} else {
dataSchema.enum = dsCopy.enum;
}
break;
case 'exclusiveMaximum':
migrateExclusive('maximum');
break;
case 'exclusiveMinimum':
migrateExclusive('minimum');
break;
case 'maximum':
if (dsCopy.exclusiveMaximum !== true)
dataSchema.maximum = dsCopy.maximum;
break;
case 'minimum':
if (dsCopy.exclusiveMinimum !== true)
dataSchema.minimum = dsCopy.minimum;
break;
default:
dataSchema[key] = dsCopy[key];
}
}
migrateExclusiveM('aximum');
migrateExclusiveM('inimum');
if (dataSchema.constant !== undefined)
dataSchema.const = use('constant');
else if (Array.isArray(dataSchema.enum) && dataSchema.enum.length == 1)
dataSchema.const = use('enum')[0];
function migrateExclusiveM(limit) {
var key = 'exclusiveM' + limit;
if (dataSchema[key] === true)
dataSchema[key] = use('m' + limit);
else if (dataSchema[key] === false)
delete dataSchema[key];
else if (dataSchema[key] !== undefined)
function migrateExclusive(limit) {
if (dsCopy[key] === true)
dataSchema[key] = dsCopy[limit];
else if (dsCopy[key] !== false && dsCopy[key] !== undefined)
console.warn(key + ' is not boolean');
}
function use(keyword) {
var value = dataSchema[keyword];
delete dataSchema[keyword];
return value;
}
}

@@ -133,0 +156,0 @@ });

{
"name": "json-schema-migrate",
"version": "0.1.0",
"version": "0.1.1",
"description": "Migrate JSON-Schema to draft-06",

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

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