Comparing version 0.19.0 to 0.20.0
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var isObject_1 = __importDefault(require("./isObject")); | ||
var types_1 = require("./types"); | ||
var Builder = (function () { | ||
@@ -206,4 +205,4 @@ function Builder(type, defaultValue) { | ||
this.checks.forEach(function (checker) { | ||
var _a; | ||
(_a = checker.callback).call.apply(_a, [_this, path, value].concat(checker.args)); | ||
var _a; | ||
}); | ||
@@ -239,3 +238,3 @@ } | ||
if (defaultValue === void 0) { defaultValue = false; } | ||
return new Builder(types_1.SupportedType.Boolean, defaultValue); | ||
return new Builder('boolean', defaultValue); | ||
} | ||
@@ -245,3 +244,3 @@ exports.bool = bool; | ||
if (defaultValue === void 0) { defaultValue = null; } | ||
return new Builder(types_1.SupportedType.Custom, defaultValue).custom(callback); | ||
return new Builder('custom', defaultValue).custom(callback); | ||
} | ||
@@ -251,4 +250,4 @@ exports.custom = custom; | ||
if (defaultValue === void 0) { defaultValue = null; } | ||
return new Builder(types_1.SupportedType.Function, defaultValue).nullable(); | ||
return new Builder('function', defaultValue).nullable(); | ||
} | ||
exports.func = func; |
import Builder from './Builder'; | ||
import { SupportedType } from './types'; | ||
export default class CollectionBuilder<T, TDefault> extends Builder<TDefault | null> { | ||
contents: Builder<T> | null; | ||
constructor(type: SupportedType.Array | SupportedType.Object, contents?: Builder<T> | null, defaultValue?: TDefault | null); | ||
constructor(type: 'array' | 'object', contents?: Builder<T> | null, defaultValue?: TDefault | null); | ||
checkContents(path: string, value: any, contents: Builder<T>): void; | ||
@@ -7,0 +6,0 @@ notEmpty(): this; |
@@ -14,6 +14,5 @@ "use strict"; | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Builder_1 = __importDefault(require("./Builder")); | ||
var types_1 = require("./types"); | ||
var CollectionBuilder = (function (_super) { | ||
@@ -78,3 +77,3 @@ __extends(CollectionBuilder, _super); | ||
if (defaultValue === void 0) { defaultValue = []; } | ||
return new CollectionBuilder(types_1.SupportedType.Array, contents, defaultValue); | ||
return new CollectionBuilder('array', contents, defaultValue); | ||
} | ||
@@ -85,4 +84,4 @@ exports.array = array; | ||
if (defaultValue === void 0) { defaultValue = {}; } | ||
return new CollectionBuilder(types_1.SupportedType.Object, contents, defaultValue); | ||
return new CollectionBuilder('object', contents, defaultValue); | ||
} | ||
exports.object = object; |
@@ -10,4 +10,4 @@ import optimal from './optimal'; | ||
export { array, bool, custom, date, func, instance, number, object, regex, shape, string, union }; | ||
export { Builder, CollectionBuilder, InstanceBuilder, NumberBuilder, ShapeBuilder, StringBuilder, UnionBuilder }; | ||
export { Builder, CollectionBuilder, InstanceBuilder, NumberBuilder, ShapeBuilder, StringBuilder, UnionBuilder, }; | ||
export * from './types'; | ||
export default optimal; |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var optimal_1 = __importDefault(require("./optimal")); | ||
var Builder_1 = __importDefault(require("./Builder")); | ||
var Builder_1 = __importStar(require("./Builder")); | ||
exports.Builder = Builder_1.default; | ||
@@ -15,7 +19,7 @@ exports.bool = Builder_1.bool; | ||
exports.func = Builder_1.func; | ||
var CollectionBuilder_1 = __importDefault(require("./CollectionBuilder")); | ||
var CollectionBuilder_1 = __importStar(require("./CollectionBuilder")); | ||
exports.CollectionBuilder = CollectionBuilder_1.default; | ||
exports.array = CollectionBuilder_1.array; | ||
exports.object = CollectionBuilder_1.object; | ||
var InstanceBuilder_1 = __importDefault(require("./InstanceBuilder")); | ||
var InstanceBuilder_1 = __importStar(require("./InstanceBuilder")); | ||
exports.InstanceBuilder = InstanceBuilder_1.default; | ||
@@ -25,15 +29,14 @@ exports.instance = InstanceBuilder_1.instance; | ||
exports.regex = InstanceBuilder_1.regex; | ||
var NumberBuilder_1 = __importDefault(require("./NumberBuilder")); | ||
var NumberBuilder_1 = __importStar(require("./NumberBuilder")); | ||
exports.NumberBuilder = NumberBuilder_1.default; | ||
exports.number = NumberBuilder_1.number; | ||
var ShapeBuilder_1 = __importDefault(require("./ShapeBuilder")); | ||
var ShapeBuilder_1 = __importStar(require("./ShapeBuilder")); | ||
exports.ShapeBuilder = ShapeBuilder_1.default; | ||
exports.shape = ShapeBuilder_1.shape; | ||
var StringBuilder_1 = __importDefault(require("./StringBuilder")); | ||
var StringBuilder_1 = __importStar(require("./StringBuilder")); | ||
exports.StringBuilder = StringBuilder_1.default; | ||
exports.string = StringBuilder_1.string; | ||
var UnionBuilder_1 = __importDefault(require("./UnionBuilder")); | ||
var UnionBuilder_1 = __importStar(require("./UnionBuilder")); | ||
exports.UnionBuilder = UnionBuilder_1.default; | ||
exports.union = UnionBuilder_1.union; | ||
__export(require("./types")); | ||
exports.default = optimal_1.default; |
@@ -14,7 +14,6 @@ "use strict"; | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Builder_1 = __importDefault(require("./Builder")); | ||
var isObject_1 = __importDefault(require("./isObject")); | ||
var types_1 = require("./types"); | ||
var InstanceBuilder = (function (_super) { | ||
@@ -24,3 +23,3 @@ __extends(InstanceBuilder, _super); | ||
if (refClass === void 0) { refClass = null; } | ||
var _this = _super.call(this, types_1.SupportedType.Instance, null) || this; | ||
var _this = _super.call(this, 'instance', null) || this; | ||
_this.refClass = null; | ||
@@ -27,0 +26,0 @@ _this.nullable(); |
@@ -14,6 +14,5 @@ "use strict"; | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Builder_1 = __importDefault(require("./Builder")); | ||
var types_1 = require("./types"); | ||
function isNumber(value) { | ||
@@ -26,3 +25,3 @@ return typeof value === 'number'; | ||
if (defaultValue === void 0) { defaultValue = 0; } | ||
return _super.call(this, types_1.SupportedType.Number, defaultValue) || this; | ||
return _super.call(this, 'number', defaultValue) || this; | ||
} | ||
@@ -29,0 +28,0 @@ NumberBuilder.prototype.between = function (min, max, inclusive) { |
@@ -12,3 +12,3 @@ "use strict"; | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -15,0 +15,0 @@ var Builder_1 = __importDefault(require("./Builder")); |
@@ -14,7 +14,6 @@ "use strict"; | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Builder_1 = __importDefault(require("./Builder")); | ||
var isObject_1 = __importDefault(require("./isObject")); | ||
var types_1 = require("./types"); | ||
var ShapeBuilder = (function (_super) { | ||
@@ -24,3 +23,3 @@ __extends(ShapeBuilder, _super); | ||
if (defaultValue === void 0) { defaultValue = {}; } | ||
var _this = _super.call(this, types_1.SupportedType.Shape, defaultValue) || this; | ||
var _this = _super.call(this, 'shape', defaultValue) || this; | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -27,0 +26,0 @@ _this.invariant(isObject_1.default(contents) && |
@@ -14,6 +14,5 @@ "use strict"; | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Builder_1 = __importDefault(require("./Builder")); | ||
var types_1 = require("./types"); | ||
function isString(value) { | ||
@@ -26,3 +25,3 @@ return typeof value === 'string' && value !== ''; | ||
if (defaultValue === void 0) { defaultValue = ''; } | ||
var _this = _super.call(this, types_1.SupportedType.String, defaultValue) || this; | ||
var _this = _super.call(this, 'string', defaultValue) || this; | ||
_this.allowEmpty = false; | ||
@@ -29,0 +28,0 @@ if (process.env.NODE_ENV !== 'production') { |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var isObject_1 = __importDefault(require("./isObject")); | ||
var types_1 = require("./types"); | ||
function typeOf(value) { | ||
if (Array.isArray(value)) { | ||
return value.every(function (item) { return typeof item === typeof value[0]; }) | ||
? types_1.SupportedType.Array | ||
: types_1.SupportedType.Union; | ||
return value.every(function (item) { return typeof item === typeof value[0]; }) ? 'array' : 'union'; | ||
} | ||
if (isObject_1.default(value)) { | ||
return value.constructor === Object ? types_1.SupportedType.Object : types_1.SupportedType.Instance; | ||
return value.constructor === Object ? 'object' : 'instance'; | ||
} | ||
switch (typeof value) { | ||
case 'boolean': | ||
return types_1.SupportedType.Boolean; | ||
case 'function': | ||
return types_1.SupportedType.Function; | ||
case 'number': | ||
return types_1.SupportedType.Number; | ||
case 'string': | ||
return types_1.SupportedType.String; | ||
return typeof value; | ||
default: | ||
return types_1.SupportedType.Unknown; | ||
return 'unknown'; | ||
} | ||
} | ||
exports.default = typeOf; |
@@ -14,14 +14,2 @@ import Builder from './Builder'; | ||
} | ||
export declare enum SupportedType { | ||
Array = "array", | ||
Boolean = "boolean", | ||
Custom = "custom", | ||
Function = "function", | ||
Instance = "instance", | ||
Number = "number", | ||
Object = "object", | ||
Shape = "shape", | ||
String = "string", | ||
Union = "union", | ||
Unknown = "unknown", | ||
} | ||
export declare type SupportedType = 'array' | 'boolean' | 'custom' | 'function' | 'instance' | 'number' | 'object' | 'shape' | 'string' | 'union' | 'unknown'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SupportedType; | ||
(function (SupportedType) { | ||
SupportedType["Array"] = "array"; | ||
SupportedType["Boolean"] = "boolean"; | ||
SupportedType["Custom"] = "custom"; | ||
SupportedType["Function"] = "function"; | ||
SupportedType["Instance"] = "instance"; | ||
SupportedType["Number"] = "number"; | ||
SupportedType["Object"] = "object"; | ||
SupportedType["Shape"] = "shape"; | ||
SupportedType["String"] = "string"; | ||
SupportedType["Union"] = "union"; | ||
SupportedType["Unknown"] = "unknown"; | ||
})(SupportedType = exports.SupportedType || (exports.SupportedType = {})); |
@@ -14,7 +14,6 @@ "use strict"; | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Builder_1 = __importDefault(require("./Builder")); | ||
var typeOf_1 = __importDefault(require("./typeOf")); | ||
var types_1 = require("./types"); | ||
var UnionBuilder = (function (_super) { | ||
@@ -24,3 +23,3 @@ __extends(UnionBuilder, _super); | ||
if (defaultValue === void 0) { defaultValue = null; } | ||
var _this = _super.call(this, types_1.SupportedType.Union, defaultValue) || this; | ||
var _this = _super.call(this, 'union', defaultValue) || this; | ||
_this.builders = []; | ||
@@ -27,0 +26,0 @@ if (process.env.NODE_ENV !== 'production') { |
{ | ||
"name": "optimal", | ||
"version": "0.19.0", | ||
"description": "A system for building and validating defined object structures", | ||
"version": "0.20.0", | ||
"description": "A system for building and validating defined object structures.", | ||
"main": "./lib/index.js", | ||
@@ -52,3 +52,3 @@ "types": "./lib/index.d.ts", | ||
"devDependencies": { | ||
"@milesj/build-tool-config": "^0.82.2" | ||
"@milesj/build-tool-config": "^0.100.1" | ||
}, | ||
@@ -55,0 +55,0 @@ "beemo": { |
@@ -9,13 +9,13 @@ # Optimal | ||
* Recursively builds and validates nested structures. | ||
* Supports common data types. | ||
* Autofills missing fields with default values. | ||
* Allows or restricts unknown fields. | ||
* Mark fields as nullable or required. | ||
* Handles complex operators like AND, OR, and XOR. | ||
- Recursively builds and validates nested structures. | ||
- Supports common data types. | ||
- Autofills missing fields with default values. | ||
- Allows or restricts unknown fields. | ||
- Mark fields as nullable or required. | ||
- Handles complex operators like AND, OR, and XOR. | ||
## Requirements | ||
* Node 6.5 (server) | ||
* IE 10+ (browser) | ||
- Node 6.5 (server) | ||
- IE 10+ (browser) | ||
@@ -32,19 +32,19 @@ ## Installation | ||
* [Optimal](#optimal) | ||
* [Blueprint](#blueprint) | ||
* [Customization](#customization) | ||
* [Predicates](#predicates) | ||
* [Array](#array) | ||
* [Bool](#bool) | ||
* [Custom](#custom) | ||
* [Date](#date) | ||
* [Function](#func) | ||
* [Instance](#instance) | ||
* [Number](#number) | ||
* [Object](#object) | ||
* [Regex](#regex) | ||
* [Shape](#shape) | ||
* [String](#string) | ||
* [Union](#union) | ||
- [Optimal](#optimal) | ||
- [Blueprint](#blueprint) | ||
- [Customization](#customization) | ||
- [Predicates](#predicates) | ||
- [Array](#array) | ||
- [Bool](#bool) | ||
- [Custom](#custom) | ||
- [Date](#date) | ||
- [Function](#func) | ||
- [Instance](#instance) | ||
- [Number](#number) | ||
- [Object](#object) | ||
- [Regex](#regex) | ||
- [Shape](#shape) | ||
- [String](#string) | ||
- [Union](#union) | ||
Will write eventually... |
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
363765
1011