jsft-schema
Advanced tools
Comparing version 0.1.0 to 0.1.1
144
lib/types.js
@@ -17,2 +17,5 @@ 'use strict'; | ||
exports.dataArray = dataArray; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
/* | ||
@@ -22,57 +25,116 @@ Helper methods to make schema objects simpler to read and contain less boilerplate | ||
function mergeOptions() { | ||
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var typeOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () { | ||
return {}; | ||
}; | ||
if (typeof params[0] === 'string' && typeof params[1] === 'string') { | ||
return _extends({ | ||
title: params[0], | ||
description: params[1] | ||
}, typeOptions.apply(undefined, _toConsumableArray(params.slice(2)))); | ||
} else if (typeof params[0] === 'string') { | ||
return _extends({ | ||
title: params[0] | ||
}, typeOptions.apply(undefined, _toConsumableArray(params.slice(1)))); | ||
} else { | ||
return typeOptions.apply(undefined, _toConsumableArray(params)); | ||
} | ||
} | ||
function string() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
for (var _len = arguments.length, params = Array(_len), _key = 0; _key < _len; _key++) { | ||
params[_key] = arguments[_key]; | ||
} | ||
return _extends({ | ||
type: 'string' | ||
}, options); | ||
return mergeOptions(params, function () { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return _extends({ | ||
type: 'string' | ||
}, options); | ||
}); | ||
} | ||
function number() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
for (var _len2 = arguments.length, params = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
params[_key2] = arguments[_key2]; | ||
} | ||
return _extends({ | ||
type: 'number' | ||
}, options); | ||
return mergeOptions(params, function () { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return _extends({ | ||
type: 'number' | ||
}, options); | ||
}); | ||
} | ||
function integer() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
for (var _len3 = arguments.length, params = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
params[_key3] = arguments[_key3]; | ||
} | ||
return _extends({ | ||
type: 'integer' | ||
}, options); | ||
return mergeOptions(params, function () { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return _extends({ | ||
type: 'integer' | ||
}, options); | ||
}); | ||
} | ||
function boolean() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
for (var _len4 = arguments.length, params = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
params[_key4] = arguments[_key4]; | ||
} | ||
return _extends({ | ||
type: 'boolean' | ||
}, options); | ||
return mergeOptions(params, function () { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return _extends({ | ||
type: 'boolean' | ||
}, options); | ||
}); | ||
} | ||
function array(items) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
function array() { | ||
for (var _len5 = arguments.length, params = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { | ||
params[_key5] = arguments[_key5]; | ||
} | ||
return _extends({ | ||
type: 'array', | ||
items: items | ||
}, options); | ||
return mergeOptions(params, function () { | ||
var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return _extends({ | ||
type: 'array', | ||
items: items | ||
}, options); | ||
}); | ||
} | ||
function object() { | ||
var properties = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
for (var _len6 = arguments.length, params = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) { | ||
params[_key6] = arguments[_key6]; | ||
} | ||
return _extends({ | ||
type: 'object', | ||
properties: properties | ||
}, options); | ||
return mergeOptions(params, function () { | ||
var properties = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return _extends({ | ||
type: 'object', | ||
properties: properties | ||
}, options); | ||
}); | ||
} | ||
function enumValues(values) { | ||
return { | ||
enum: values | ||
}; | ||
function enumValues() { | ||
for (var _len7 = arguments.length, params = Array(_len7), _key7 = 0; _key7 < _len7; _key7++) { | ||
params[_key7] = arguments[_key7]; | ||
} | ||
return mergeOptions(params, function () { | ||
var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return _extends({ | ||
enum: values | ||
}, options); | ||
}); | ||
} | ||
@@ -82,8 +144,16 @@ | ||
function dataArray(items) { | ||
return object({ | ||
data: array(items) | ||
}, { | ||
required: ['data'] | ||
function dataArray() { | ||
for (var _len8 = arguments.length, params = Array(_len8), _key8 = 0; _key8 < _len8; _key8++) { | ||
params[_key8] = arguments[_key8]; | ||
} | ||
return mergeOptions(params, function () { | ||
var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return object({ | ||
data: array(items) | ||
}, _extends({}, options, { | ||
required: ['data'] | ||
})); | ||
}); | ||
} |
{ | ||
"name": "jsft-schema", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Functional tools for creating object definitions using json-schema.", | ||
@@ -11,3 +11,3 @@ "main": "lib/index.js", | ||
"test": "npm run test:eslint", | ||
"test:mocha": "NODE_PATH=. mocha -S --compilers js:babel-register --timeout 8000 \"src/**/_tests/test.*\"", | ||
"test:mocha": "NODE_PATH=. mocha -S --compilers js:babel-register --timeout 8000 \"src/**/_tests/*.test.js\"", | ||
"test:eslint": "NODE_PATH=. eslint .", | ||
@@ -14,0 +14,0 @@ "compile": "babel src --out-dir lib", |
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
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
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
20607
5
460
1