Comparing version 0.15.0 to 0.16.0
@@ -7,19 +7,19 @@ declare module 'optimal/lib/isObject' { | ||
import Builder from 'optimal/lib/Builder'; | ||
export type SupportedType = 'array' | 'boolean' | 'function' | 'instance' | 'number' | 'object' | 'shape' | 'string' | 'union' | 'custom'; | ||
export type Checker = (path: string, value: any, ...args: any[]) => void; | ||
export type CustomCallback = (value: any, options: object) => void; | ||
export interface Blueprint { | ||
[field: string]: Builder<any> | Blueprint; | ||
} | ||
export interface Config { | ||
export type Checker = (path: string, value: any, ...args: any[]) => void; | ||
export type CustomCallback = (value: any, options: OptionsBag) => void; | ||
export interface OptionsBag { | ||
[key: string]: any; | ||
} | ||
export interface OptionsConfig { | ||
name?: string; | ||
unknown?: boolean; | ||
} | ||
export interface Options { | ||
[key: string]: any; | ||
} | ||
export type SupportedType = 'array' | 'boolean' | 'function' | 'instance' | 'number' | 'object' | 'shape' | 'string' | 'union' | 'custom'; | ||
} | ||
declare module 'optimal/lib/Builder' { | ||
import { SupportedType, Checker, Config, CustomCallback, Options } from 'optimal/lib/types'; | ||
import { SupportedType, Checker, CustomCallback, OptionsBag, OptionsConfig } from 'optimal/lib/types'; | ||
export interface Check { | ||
@@ -31,4 +31,4 @@ args: any[]; | ||
checks: Check[]; | ||
currentConfig: Config; | ||
currentOptions: Options; | ||
currentConfig: OptionsConfig; | ||
currentOptions: OptionsBag; | ||
defaultValue: T; | ||
@@ -57,3 +57,3 @@ deprecatedMessage: string; | ||
required(state?: boolean): this; | ||
runChecks(path: string, initialValue: any, options: Object, config?: Config): any; | ||
runChecks(path: string, initialValue: any, options: OptionsBag, config?: OptionsConfig): any; | ||
typeAlias(): string; | ||
@@ -86,2 +86,14 @@ xor(...keys: string[]): this; | ||
} | ||
declare module 'optimal/lib/typeOf' { | ||
import { SupportedType } from 'optimal/lib/types'; | ||
export default function typeOf(value: any): SupportedType; | ||
} | ||
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/InstanceBuilder' { | ||
@@ -120,5 +132,3 @@ import Builder from 'optimal/lib/Builder'; | ||
import Builder from 'optimal/lib/Builder'; | ||
export interface ShapeBlueprint { | ||
[key: string]: Builder<any>; | ||
} | ||
import { Blueprint } from 'optimal/lib/types'; | ||
export interface Shape { | ||
@@ -128,6 +138,6 @@ [key: string]: any; | ||
export default class ShapeBuilder extends Builder<Shape | null> { | ||
constructor(contents: ShapeBlueprint, defaultValue?: Shape | null); | ||
checkContents(path: string, object: any, contents: ShapeBlueprint): void; | ||
constructor(contents: Blueprint, defaultValue?: Shape | null); | ||
checkContents(path: string, object: any, contents: Blueprint): void; | ||
} | ||
export function shape(contents: ShapeBlueprint, defaultValue?: Shape | null): ShapeBuilder; | ||
export function shape(contents: Blueprint, defaultValue?: Shape | null): ShapeBuilder; | ||
@@ -152,7 +162,2 @@ } | ||
} | ||
declare module 'optimal/lib/typeOf' { | ||
import { SupportedType } from 'optimal/lib/types'; | ||
export default function typeOf(value: any): SupportedType; | ||
} | ||
declare module 'optimal/lib/UnionBuilder' { | ||
@@ -169,18 +174,17 @@ import Builder from 'optimal/lib/Builder'; | ||
} | ||
declare module 'optimal/lib/Options' { | ||
import { Blueprint, Config, Options } from 'optimal/lib/types'; | ||
export default function parseOptions(options: Options, blueprint: Blueprint, config?: Config): Options; | ||
} | ||
declare module 'optimal/lib/index' { | ||
import { bool, custom, func } from 'optimal/lib/Builder'; | ||
import { array, object } from 'optimal/lib/CollectionBuilder'; | ||
import { instance, date, regex } from 'optimal/lib/InstanceBuilder'; | ||
import { number } from 'optimal/lib/NumberBuilder'; | ||
import { shape } from 'optimal/lib/ShapeBuilder'; | ||
import { string } from 'optimal/lib/StringBuilder'; | ||
import { union } from 'optimal/lib/UnionBuilder'; | ||
declare module 'optimal' { | ||
import Options from 'optimal/lib/Options'; | ||
import Builder, { bool, custom, func } from 'optimal/lib/Builder'; | ||
import CollectionBuilder, { array, object } from 'optimal/lib/CollectionBuilder'; | ||
import InstanceBuilder, { instance, date, regex } from 'optimal/lib/InstanceBuilder'; | ||
import NumberBuilder, { number } from 'optimal/lib/NumberBuilder'; | ||
import ShapeBuilder, { shape } from 'optimal/lib/ShapeBuilder'; | ||
import StringBuilder, { string } from 'optimal/lib/StringBuilder'; | ||
import UnionBuilder, { union } from 'optimal/lib/UnionBuilder'; | ||
import { Blueprint, Checker, CustomCallback, OptionsBag, OptionsConfig, SupportedType } from 'optimal/lib/types'; | ||
export { array, bool, custom, date, func, instance, number, object, regex, shape, string, union }; | ||
export { default } from 'optimal/lib/Options'; | ||
export { Builder, CollectionBuilder, InstanceBuilder, NumberBuilder, ShapeBuilder, StringBuilder, UnionBuilder }; | ||
export { Blueprint, Checker, CustomCallback, OptionsBag, OptionsConfig, SupportedType }; | ||
export default Options; | ||
} |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Builder_1 = require("./Builder"); | ||
var Options_1 = __importDefault(require("./Options")); | ||
var Builder_1 = __importDefault(require("./Builder")); | ||
exports.Builder = Builder_1.default; | ||
exports.bool = Builder_1.bool; | ||
exports.custom = Builder_1.custom; | ||
exports.func = Builder_1.func; | ||
var CollectionBuilder_1 = require("./CollectionBuilder"); | ||
var CollectionBuilder_1 = __importDefault(require("./CollectionBuilder")); | ||
exports.CollectionBuilder = CollectionBuilder_1.default; | ||
exports.array = CollectionBuilder_1.array; | ||
exports.object = CollectionBuilder_1.object; | ||
var InstanceBuilder_1 = require("./InstanceBuilder"); | ||
var InstanceBuilder_1 = __importDefault(require("./InstanceBuilder")); | ||
exports.InstanceBuilder = InstanceBuilder_1.default; | ||
exports.instance = InstanceBuilder_1.instance; | ||
exports.date = InstanceBuilder_1.date; | ||
exports.regex = InstanceBuilder_1.regex; | ||
var NumberBuilder_1 = require("./NumberBuilder"); | ||
var NumberBuilder_1 = __importDefault(require("./NumberBuilder")); | ||
exports.NumberBuilder = NumberBuilder_1.default; | ||
exports.number = NumberBuilder_1.number; | ||
var ShapeBuilder_1 = require("./ShapeBuilder"); | ||
var ShapeBuilder_1 = __importDefault(require("./ShapeBuilder")); | ||
exports.ShapeBuilder = ShapeBuilder_1.default; | ||
exports.shape = ShapeBuilder_1.shape; | ||
var StringBuilder_1 = require("./StringBuilder"); | ||
var StringBuilder_1 = __importDefault(require("./StringBuilder")); | ||
exports.StringBuilder = StringBuilder_1.default; | ||
exports.string = StringBuilder_1.string; | ||
var UnionBuilder_1 = require("./UnionBuilder"); | ||
var UnionBuilder_1 = __importDefault(require("./UnionBuilder")); | ||
exports.UnionBuilder = UnionBuilder_1.default; | ||
exports.union = UnionBuilder_1.union; | ||
var Options_1 = require("./Options"); | ||
exports.default = Options_1.default; |
@@ -47,17 +47,24 @@ "use strict"; | ||
} | ||
function parseOptions(options, blueprint, config) { | ||
if (config === void 0) { config = {}; } | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (!isObject_1.default(options)) { | ||
throw new TypeError("Options require a plain object, found " + typeOf_1.default(options) + "."); | ||
var Options = (function () { | ||
function Options(options, blueprint, config) { | ||
if (config === void 0) { config = {}; } | ||
var _this = this; | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (!isObject_1.default(options)) { | ||
throw new TypeError("Options require a plain object, found " + typeOf_1.default(options) + "."); | ||
} | ||
else if (!isObject_1.default(config)) { | ||
throw new TypeError('Option configuration must be a plain object.'); | ||
} | ||
else if (!isObject_1.default(blueprint)) { | ||
throw new TypeError('An options blueprint is required.'); | ||
} | ||
} | ||
else if (!isObject_1.default(config)) { | ||
throw new TypeError('Option configuration must be a plain object.'); | ||
} | ||
else if (!isObject_1.default(blueprint)) { | ||
throw new TypeError('An options blueprint is required.'); | ||
} | ||
var builtOptions = buildAndCheckOptions(options, blueprint, config); | ||
Object.keys(builtOptions).forEach(function (key) { | ||
_this[key] = builtOptions[key]; | ||
}); | ||
} | ||
return buildAndCheckOptions(options, blueprint, config); | ||
} | ||
exports.default = parseOptions; | ||
return Options; | ||
}()); | ||
exports.default = Options; |
@@ -36,3 +36,3 @@ "use strict"; | ||
var builder = contents[key]; | ||
if (builder.isRequired || typeof object[key] !== 'undefined') { | ||
if (builder instanceof Builder_1.default && (builder.isRequired || typeof object[key] !== 'undefined')) { | ||
builder.runChecks(path + "." + key, object[key], object, _this.currentConfig); | ||
@@ -39,0 +39,0 @@ } |
{ | ||
"name": "optimal", | ||
"version": "0.15.0", | ||
"version": "0.16.0", | ||
"description": "Options object builder and validator.", | ||
@@ -9,3 +9,3 @@ "main": "./lib/index.js", | ||
"build": "beemo typescript", | ||
"build:dts": "beemo run-script generate-dts --name optimal/lib", | ||
"build:dts": "beemo run-script generate-dts", | ||
"coverage": "yarn run jest --coverage", | ||
@@ -49,3 +49,3 @@ "eslint": "beemo eslint", | ||
"devDependencies": { | ||
"@milesj/build-tool-config": "^0.75.1" | ||
"@milesj/build-tool-config": "^0.76.0" | ||
}, | ||
@@ -52,0 +52,0 @@ "beemo": { |
Sorry, the diff of this file is not supported yet
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
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
336274
1002
0