Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

optimal

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

optimal - npm Package Compare versions

Comparing version 4.0.0-2 to 4.0.0

1

CHANGELOG.md

@@ -20,2 +20,3 @@ # 4.0.0

- Add support for default values via factory functions.
- Add `Predicate#default()` to return the default value.
- Add `Predicate#validate()` to run stand-alone validation with a predicate.

@@ -22,0 +23,0 @@ - **[array,object,string]** Add `sizeOf()` method.

58

esm/index.js

@@ -146,2 +146,9 @@ function _defineProperty(obj, key, value) {

_proto.default = function _default() {
var _ref2, _this$schema2;
var value = this.defaultValueFactory ? this.defaultValueFactory((_ref2 = (_this$schema2 = this.schema) === null || _this$schema2 === void 0 ? void 0 : _this$schema2.struct) !== null && _ref2 !== void 0 ? _ref2 : {}) : this.defaultValue;
return this.cast(value);
};
_proto.deprecate = function deprecate(message) {

@@ -166,5 +173,5 @@ if ("production" !== process.env.NODE_ENV) {

var _ref2 = this.schema || {},
filePath = _ref2.filePath,
schemaName = _ref2.schemaName;
var _ref3 = this.schema || {},
filePath = _ref3.filePath,
schemaName = _ref3.schemaName;

@@ -225,3 +232,3 @@ var error = this.errorMessage || message;

if ("production" !== process.env.NODE_ENV) {
var defaultValue = this.getDefaultValue();
var defaultValue = this.default();
this.invariant(typeof defaultValue === this.type, "Only requires a default " + this.type + " value.");

@@ -246,6 +253,6 @@ this.addCheck(function (path, value) {

this.addCheck(function (path) {
var _ref3, _this4$schema;
var _ref4, _this4$schema;
var orKeys = [_this4.key(path)].concat(keys);
var struct = (_ref3 = (_this4$schema = _this4.schema) === null || _this4$schema === void 0 ? void 0 : _this4$schema.struct) !== null && _ref3 !== void 0 ? _ref3 : {};
var struct = (_ref4 = (_this4$schema = _this4.schema) === null || _this4$schema === void 0 ? void 0 : _this4$schema.struct) !== null && _ref4 !== void 0 ? _ref4 : {};
var defs = orKeys.filter(function (key) {

@@ -273,3 +280,3 @@ return typeof struct[key] !== 'undefined' && struct[key] !== null;

this.schema = schema;
this.defaultValue = this.getDefaultValue();
this.defaultValue = this.default();
var value = initialValue;

@@ -339,6 +346,6 @@

this.addCheck(function (path) {
var _ref4, _this6$schema;
var _ref5, _this6$schema;
var xorKeys = [_this6.key(path)].concat(keys);
var struct = (_ref4 = (_this6$schema = _this6.schema) === null || _this6$schema === void 0 ? void 0 : _this6$schema.struct) !== null && _ref4 !== void 0 ? _ref4 : {};
var struct = (_ref5 = (_this6$schema = _this6.schema) === null || _this6$schema === void 0 ? void 0 : _this6$schema.struct) !== null && _ref5 !== void 0 ? _ref5 : {};
var defs = xorKeys.filter(function (key) {

@@ -384,14 +391,4 @@ return typeof struct[key] !== 'undefined' && struct[key] !== null;

_proto.getDefaultValue = function getDefaultValue() {
if (this.defaultValueFactory) {
var _ref5, _this$schema2;
return this.defaultValueFactory((_ref5 = (_this$schema2 = this.schema) === null || _this$schema2 === void 0 ? void 0 : _this$schema2.struct) !== null && _ref5 !== void 0 ? _ref5 : {});
}
return this.defaultValue;
};
_proto.isOptionalDefault = function isOptionalDefault(value) {
return !this.isRequired && value === this.getDefaultValue();
return !this.isRequired && value === this.default();
};

@@ -1062,2 +1059,13 @@

_proto.default = function _default() {
var _this2 = this;
var struct = {};
Object.keys(this.contents).forEach(function (baseKey) {
var key = baseKey;
struct[key] = _this2.contents[key].default();
});
return struct;
};
_proto.exact = function exact() {

@@ -1069,3 +1077,3 @@ this.isExact = true;

_proto.run = function run(value, path, schema) {
var _this2 = this;
var _this3 = this;

@@ -1081,3 +1089,3 @@ if ("production" !== process.env.NODE_ENV && value) {

var key = baseKey;
var content = _this2.contents[key];
var content = _this3.contents[key];
struct[key] = content.run(value === null || value === void 0 ? void 0 : value[key], path + "." + key, schema);

@@ -1258,2 +1266,8 @@ delete unknownFields[key];

_proto.default = function _default() {
return this.contents.map(function (content) {
return content.default();
});
};
_proto.run = function run(value, path) {

@@ -1260,0 +1274,0 @@ var _this2 = this;

@@ -150,2 +150,9 @@ 'use strict';

_proto.default = function _default() {
var _ref2, _this$schema2;
var value = this.defaultValueFactory ? this.defaultValueFactory((_ref2 = (_this$schema2 = this.schema) === null || _this$schema2 === void 0 ? void 0 : _this$schema2.struct) !== null && _ref2 !== void 0 ? _ref2 : {}) : this.defaultValue;
return this.cast(value);
};
_proto.deprecate = function deprecate(message) {

@@ -170,5 +177,5 @@ if ("production" !== process.env.NODE_ENV) {

var _ref2 = this.schema || {},
filePath = _ref2.filePath,
schemaName = _ref2.schemaName;
var _ref3 = this.schema || {},
filePath = _ref3.filePath,
schemaName = _ref3.schemaName;

@@ -229,3 +236,3 @@ var error = this.errorMessage || message;

if ("production" !== process.env.NODE_ENV) {
var defaultValue = this.getDefaultValue();
var defaultValue = this.default();
this.invariant(typeof defaultValue === this.type, "Only requires a default " + this.type + " value.");

@@ -250,6 +257,6 @@ this.addCheck(function (path, value) {

this.addCheck(function (path) {
var _ref3, _this4$schema;
var _ref4, _this4$schema;
var orKeys = [_this4.key(path)].concat(keys);
var struct = (_ref3 = (_this4$schema = _this4.schema) === null || _this4$schema === void 0 ? void 0 : _this4$schema.struct) !== null && _ref3 !== void 0 ? _ref3 : {};
var struct = (_ref4 = (_this4$schema = _this4.schema) === null || _this4$schema === void 0 ? void 0 : _this4$schema.struct) !== null && _ref4 !== void 0 ? _ref4 : {};
var defs = orKeys.filter(function (key) {

@@ -277,3 +284,3 @@ return typeof struct[key] !== 'undefined' && struct[key] !== null;

this.schema = schema;
this.defaultValue = this.getDefaultValue();
this.defaultValue = this.default();
var value = initialValue;

@@ -343,6 +350,6 @@

this.addCheck(function (path) {
var _ref4, _this6$schema;
var _ref5, _this6$schema;
var xorKeys = [_this6.key(path)].concat(keys);
var struct = (_ref4 = (_this6$schema = _this6.schema) === null || _this6$schema === void 0 ? void 0 : _this6$schema.struct) !== null && _ref4 !== void 0 ? _ref4 : {};
var struct = (_ref5 = (_this6$schema = _this6.schema) === null || _this6$schema === void 0 ? void 0 : _this6$schema.struct) !== null && _ref5 !== void 0 ? _ref5 : {};
var defs = xorKeys.filter(function (key) {

@@ -388,14 +395,4 @@ return typeof struct[key] !== 'undefined' && struct[key] !== null;

_proto.getDefaultValue = function getDefaultValue() {
if (this.defaultValueFactory) {
var _ref5, _this$schema2;
return this.defaultValueFactory((_ref5 = (_this$schema2 = this.schema) === null || _this$schema2 === void 0 ? void 0 : _this$schema2.struct) !== null && _ref5 !== void 0 ? _ref5 : {});
}
return this.defaultValue;
};
_proto.isOptionalDefault = function isOptionalDefault(value) {
return !this.isRequired && value === this.getDefaultValue();
return !this.isRequired && value === this.default();
};

@@ -1066,2 +1063,13 @@

_proto.default = function _default() {
var _this2 = this;
var struct = {};
Object.keys(this.contents).forEach(function (baseKey) {
var key = baseKey;
struct[key] = _this2.contents[key].default();
});
return struct;
};
_proto.exact = function exact() {

@@ -1073,3 +1081,3 @@ this.isExact = true;

_proto.run = function run(value, path, schema) {
var _this2 = this;
var _this3 = this;

@@ -1085,3 +1093,3 @@ if ("production" !== process.env.NODE_ENV && value) {

var key = baseKey;
var content = _this2.contents[key];
var content = _this3.contents[key];
struct[key] = content.run(value === null || value === void 0 ? void 0 : value[key], path + "." + key, schema);

@@ -1262,2 +1270,8 @@ delete unknownFields[key];

_proto.default = function _default() {
return this.contents.map(function (content) {
return content.default();
});
};
_proto.run = function run(value, path) {

@@ -1264,0 +1278,0 @@ var _this2 = this;

@@ -32,2 +32,6 @@ import Schema from './Schema';

/**
* Return the default value for the current instance.
*/
default(): T;
/**
* Set a message to log when this field is present.

@@ -96,6 +100,2 @@ */

/**
* Return the possible default value.
*/
protected getDefaultValue(): T | undefined;
/**
* Return true if the value matches the default value and the predicate is optional.

@@ -102,0 +102,0 @@ */

@@ -8,2 +8,3 @@ import Predicate from '../Predicate';

constructor(contents: Blueprint<T>);
default(): T;
exact(): this;

@@ -10,0 +11,0 @@ run(value: T | undefined, path: string, schema: Schema<{}>): T;

@@ -6,2 +6,3 @@ import Predicate from '../Predicate';

constructor(contents: InferTupleContents<T>);
default(): T;
run(value: T | undefined, path: string): T | null;

@@ -8,0 +9,0 @@ /**

{
"name": "optimal",
"version": "4.0.0-2",
"version": "4.0.0",
"description": "A system for building and validating defined object structures.",

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

"@milesj/build-tools": "^0.62.0",
"@types/node": "^13.1.2",
"@types/node": "^13.1.4",
"conventional-changelog-beemo": "^1.6.0",
"rollup": "^1.27.14",
"rollup": "^1.28.0",
"rollup-plugin-babel": "^4.3.3",

@@ -53,0 +53,0 @@ "rollup-plugin-node-resolve": "^5.2.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