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 0.16.0 to 0.17.0

lib/optimal.js

32

index.d.ts

@@ -11,7 +11,7 @@ declare module 'optimal/lib/isObject' {

export type Checker = (path: string, value: any, ...args: any[]) => void;
export type CustomCallback = (value: any, options: OptionsBag) => void;
export interface OptionsBag {
export type CustomCallback = (value: any, options: Options) => void;
export interface Options {
[key: string]: any;
}
export interface OptionsConfig {
export interface OptimalOptions extends Options {
name?: string;

@@ -24,3 +24,3 @@ unknown?: boolean;

declare module 'optimal/lib/Builder' {
import { SupportedType, Checker, CustomCallback, OptionsBag, OptionsConfig } from 'optimal/lib/types';
import { SupportedType, Checker, CustomCallback, Options, OptimalOptions } from 'optimal/lib/types';
export interface Check {

@@ -32,4 +32,3 @@ args: any[];

checks: Check[];
currentConfig: OptionsConfig;
currentOptions: OptionsBag;
currentOptions: Options;
defaultValue: T;

@@ -40,2 +39,3 @@ deprecatedMessage: string;

isRequired: boolean;
optimalOptions: OptimalOptions;
type: SupportedType;

@@ -59,3 +59,3 @@ constructor(type: SupportedType, defaultValue: T);

required(state?: boolean): this;
runChecks(path: string, initialValue: any, options: OptionsBag, config?: OptionsConfig): any;
runChecks(path: string, initialValue: any, options: Options, optimalOptions?: OptimalOptions): any;
typeAlias(): string;

@@ -93,7 +93,5 @@ xor(...keys: string[]): this;

}
declare module 'optimal/lib/Options' {
import { Blueprint, OptionsBag, OptionsConfig } from 'optimal/lib/types';
export default class Options implements OptionsBag {
constructor(options: OptionsBag, blueprint: Blueprint, config?: OptionsConfig);
}
declare module 'optimal/lib/optimal' {
import { Blueprint, Options, OptimalOptions } from 'optimal/lib/types';
export default function optimal<T extends Options>(stagedOptions: Options, blueprint: Blueprint, options?: OptimalOptions): T;

@@ -109,3 +107,3 @@ }

}
export function instance<T>(refClass?: T | null): InstanceBuilder<T>;
export function instance<T extends Function>(refClass?: T | null): InstanceBuilder<T>;
export function regex(): InstanceBuilder<Function>;

@@ -175,3 +173,3 @@ export function date(): InstanceBuilder<Function>;

declare module 'optimal' {
import Options from 'optimal/lib/Options';
import optimal from 'optimal/lib/optimal';
import Builder, { bool, custom, func } from 'optimal/lib/Builder';

@@ -184,8 +182,8 @@ import CollectionBuilder, { array, object } from 'optimal/lib/CollectionBuilder';

import UnionBuilder, { union } from 'optimal/lib/UnionBuilder';
import { Blueprint, Checker, CustomCallback, OptionsBag, OptionsConfig, SupportedType } from 'optimal/lib/types';
import { Blueprint, Checker, CustomCallback, Options, OptimalOptions, SupportedType } from 'optimal/lib/types';
export { array, bool, custom, date, func, instance, number, object, regex, shape, string, union };
export { Builder, CollectionBuilder, InstanceBuilder, NumberBuilder, ShapeBuilder, StringBuilder, UnionBuilder };
export { Blueprint, Checker, CustomCallback, OptionsBag, OptionsConfig, SupportedType };
export default Options;
export { Blueprint, Checker, CustomCallback, Options, OptimalOptions, SupportedType };
export default optimal;
}

@@ -10,3 +10,2 @@ "use strict";

this.checks = [];
this.currentConfig = {};
this.currentOptions = {};

@@ -17,2 +16,3 @@ this.deprecatedMessage = '';

this.isRequired = false;
this.optimalOptions = {};
if (process.env.NODE_ENV !== 'production') {

@@ -108,3 +108,3 @@ this.invariant(typeof defaultValue !== 'undefined', "A default value for type \"" + type + "\" is required.");

}
var name = this.currentConfig.name;
var name = this.optimalOptions.name;
var prefix = '';

@@ -179,7 +179,7 @@ if (path) {

};
Builder.prototype.runChecks = function (path, initialValue, options, config) {
Builder.prototype.runChecks = function (path, initialValue, options, optimalOptions) {
var _this = this;
if (config === void 0) { config = {}; }
this.currentConfig = config;
if (optimalOptions === void 0) { optimalOptions = {}; }
this.currentOptions = options;
this.optimalOptions = optimalOptions;
var value = initialValue;

@@ -186,0 +186,0 @@ if (typeof value === 'undefined') {

@@ -42,3 +42,3 @@ "use strict";

value.forEach(function (item, i) {
contents.runChecks(path + "[" + i + "]", item, _this.currentOptions, _this.currentConfig);
contents.runChecks(path + "[" + i + "]", item, _this.currentOptions, _this.optimalOptions);
});

@@ -48,3 +48,3 @@ }

Object.keys(value).forEach(function (key) {
contents.runChecks(path + "." + key, value[key], _this.currentOptions, _this.currentConfig);
contents.runChecks(path + "." + key, value[key], _this.currentOptions, _this.optimalOptions);
});

@@ -51,0 +51,0 @@ }

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var Options_1 = __importDefault(require("./Options"));
var optimal_1 = __importDefault(require("./optimal"));
var Builder_1 = __importDefault(require("./Builder"));

@@ -34,2 +34,2 @@ exports.Builder = Builder_1.default;

exports.union = UnionBuilder_1.union;
exports.default = Options_1.default;
exports.default = optimal_1.default;

@@ -36,4 +36,5 @@ "use strict";

var builder = contents[key];
if (builder instanceof Builder_1.default && (builder.isRequired || typeof object[key] !== 'undefined')) {
builder.runChecks(path + "." + key, object[key], object, _this.currentConfig);
if (builder instanceof Builder_1.default &&
(builder.isRequired || typeof object[key] !== 'undefined')) {
builder.runChecks(path + "." + key, object[key], object, _this.optimalOptions);
}

@@ -40,0 +41,0 @@ });

@@ -60,3 +60,3 @@ "use strict";

checked_1 = true;
builder.runChecks(path, value, _this.currentOptions, _this.currentConfig);
builder.runChecks(path, value, _this.currentOptions, _this.optimalOptions);
}

@@ -63,0 +63,0 @@ });

{
"name": "optimal",
"version": "0.16.0",
"version": "0.17.0",
"description": "Options object builder and validator.",

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

"devDependencies": {
"@milesj/build-tool-config": "^0.76.0"
"@milesj/build-tool-config": "^0.76.1"
},

@@ -51,0 +51,0 @@ "beemo": {

Sorry, the diff of this file is not supported yet

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