| function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
| import Builder from './Builder'; | ||
| var BooleanBuilder = function (_Builder) { | ||
| _inheritsLoose(BooleanBuilder, _Builder); | ||
| function BooleanBuilder(defaultValue) { | ||
| return _Builder.call(this, 'boolean', defaultValue || false) || this; | ||
| } | ||
| var _proto = BooleanBuilder.prototype; | ||
| _proto.onlyFalse = function onlyFalse() { | ||
| this.defaultValue = false; | ||
| this.addCheck(this.checkOnlyFalse); | ||
| return this; | ||
| }; | ||
| _proto.checkOnlyFalse = function checkOnlyFalse(path, value) { | ||
| if ("production" !== process.env.NODE_ENV) { | ||
| this.invariant(value === false, 'May only be `false`.', path); | ||
| } | ||
| }; | ||
| _proto.onlyTrue = function onlyTrue() { | ||
| this.defaultValue = true; | ||
| this.addCheck(this.checkOnlyTrue); | ||
| return this; | ||
| }; | ||
| _proto.checkOnlyTrue = function checkOnlyTrue(path, value) { | ||
| if ("production" !== process.env.NODE_ENV) { | ||
| this.invariant(value === true, 'May only be `true`.', path); | ||
| } | ||
| }; | ||
| return BooleanBuilder; | ||
| }(Builder); | ||
| export { BooleanBuilder as default }; | ||
| export function bool(defaultValue) { | ||
| if (defaultValue === void 0) { | ||
| defaultValue = false; | ||
| } | ||
| return new BooleanBuilder(defaultValue); | ||
| } |
| import Builder from './Builder'; | ||
| export default class BooleanBuilder<T extends boolean = boolean> extends Builder<T> { | ||
| constructor(defaultValue?: T); | ||
| onlyFalse(): BooleanBuilder<false>; | ||
| checkOnlyFalse(path: string, value: T): void; | ||
| onlyTrue(): BooleanBuilder<true>; | ||
| checkOnlyTrue(path: string, value: T): void; | ||
| } | ||
| export declare function bool(defaultValue?: boolean): BooleanBuilder<boolean>; |
| "use strict"; | ||
| exports.__esModule = true; | ||
| exports.bool = bool; | ||
| exports.default = void 0; | ||
| var _Builder2 = _interopRequireDefault(require("./Builder")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
| var BooleanBuilder = function (_Builder) { | ||
| _inheritsLoose(BooleanBuilder, _Builder); | ||
| function BooleanBuilder(defaultValue) { | ||
| return _Builder.call(this, 'boolean', defaultValue || false) || this; | ||
| } | ||
| var _proto = BooleanBuilder.prototype; | ||
| _proto.onlyFalse = function onlyFalse() { | ||
| this.defaultValue = false; | ||
| this.addCheck(this.checkOnlyFalse); | ||
| return this; | ||
| }; | ||
| _proto.checkOnlyFalse = function checkOnlyFalse(path, value) { | ||
| if ("production" !== process.env.NODE_ENV) { | ||
| this.invariant(value === false, 'May only be `false`.', path); | ||
| } | ||
| }; | ||
| _proto.onlyTrue = function onlyTrue() { | ||
| this.defaultValue = true; | ||
| this.addCheck(this.checkOnlyTrue); | ||
| return this; | ||
| }; | ||
| _proto.checkOnlyTrue = function checkOnlyTrue(path, value) { | ||
| if ("production" !== process.env.NODE_ENV) { | ||
| this.invariant(value === true, 'May only be `true`.', path); | ||
| } | ||
| }; | ||
| return BooleanBuilder; | ||
| }(_Builder2.default); | ||
| exports.default = BooleanBuilder; | ||
| function bool(defaultValue) { | ||
| if (defaultValue === void 0) { | ||
| defaultValue = false; | ||
| } | ||
| return new BooleanBuilder(defaultValue); | ||
| } |
+17
-1
@@ -1,5 +0,21 @@ | ||
| ## 3.3.0 | ||
| ## 3.4.0 - 2019-12-28 | ||
| #### 🚀 Updates | ||
| - Add `never()` for all builders. | ||
| - **[bool]** Add `onlyFalse()` and `onlyTrue()` methods. | ||
| - **[string]** Add `camelCase()`, `kebabCase()`, `pascalCase()`, and `snakeCase()` methods. | ||
| #### ⚙️ Types | ||
| - Update `CustomCallback` with a struct generic. | ||
| #### 📦 Dependencies | ||
| - Update to latest. | ||
| ## 3.3.0 - 2019-12-02 | ||
| #### ⚙️ Types | ||
| - Refined types and replaced `any` with `unknown`. | ||
@@ -6,0 +22,0 @@ |
+21
-9
@@ -17,2 +17,4 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
| _defineProperty(this, "isNever", false); | ||
| _defineProperty(this, "isNullable", false); | ||
@@ -189,2 +191,11 @@ | ||
| _proto.never = function never() { | ||
| if ("production" !== process.env.NODE_ENV) { | ||
| this.defaultValue = undefined; | ||
| this.isNever = true; | ||
| } | ||
| return this; | ||
| }; | ||
| _proto.notNullable = function notNullable() { | ||
@@ -272,5 +283,13 @@ if ("production" !== process.env.NODE_ENV) { | ||
| } | ||
| } else if (this.deprecatedMessage) { | ||
| } else { | ||
| if (this.deprecatedMessage) { | ||
| if ("production" !== process.env.NODE_ENV) { | ||
| console.info("Field \"" + path + "\" is deprecated. " + this.deprecatedMessage); | ||
| } | ||
| } | ||
| if ("production" !== process.env.NODE_ENV) { | ||
| console.info("Field \"" + path + "\" is deprecated. " + this.deprecatedMessage); | ||
| if (this.isNever) { | ||
| this.invariant(false, 'Field should never be used.', path); | ||
| } | ||
| } | ||
@@ -335,9 +354,2 @@ } | ||
| export { Builder as default }; | ||
| export function bool(defaultValue) { | ||
| if (defaultValue === void 0) { | ||
| defaultValue = false; | ||
| } | ||
| return new Builder('boolean', defaultValue); | ||
| } | ||
| export function custom(callback, defaultValue) { | ||
@@ -344,0 +356,0 @@ return new Builder('custom', defaultValue).custom(callback); |
+3
-2
@@ -6,4 +6,5 @@ /** | ||
| import optimal from './optimal'; | ||
| import Builder, { bool, custom, func } from './Builder'; | ||
| import Builder, { custom, func } from './Builder'; | ||
| import ArrayBuilder, { array } from './ArrayBuilder'; | ||
| import BooleanBuilder, { bool } from './BooleanBuilder'; | ||
| import InstanceBuilder, { builder, instance, date, regex } from './InstanceBuilder'; | ||
@@ -32,4 +33,4 @@ import NumberBuilder, { number } from './NumberBuilder'; | ||
| export { array, blueprint, bool, builder, custom, date, func, instance, number, object, regex, shape, string, union }; | ||
| export { Builder, ArrayBuilder, InstanceBuilder, NumberBuilder, ObjectBuilder, ShapeBuilder, StringBuilder, UnionBuilder }; | ||
| export { Builder, ArrayBuilder, BooleanBuilder, InstanceBuilder, NumberBuilder, ObjectBuilder, ShapeBuilder, StringBuilder, UnionBuilder }; | ||
| export * from './types'; | ||
| export default optimal; |
+24
-4
@@ -18,2 +18,6 @@ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
| _proto.camelCase = function camelCase() { | ||
| return this.match(/^[a-z][0-9A-Za-z]+$/, 'String must be in camel case.'); | ||
| }; | ||
| _proto.contains = function contains(token, index) { | ||
@@ -45,3 +49,11 @@ if (index === void 0) { | ||
| _proto.match = function match(pattern) { | ||
| _proto.kebabCase = function kebabCase() { | ||
| return this.match(/^[a-z][\x2D0-9a-z]+$/, 'String must be in kebab case.'); | ||
| }; | ||
| _proto.match = function match(pattern, message) { | ||
| if (message === void 0) { | ||
| message = ''; | ||
| } | ||
| if ("production" !== process.env.NODE_ENV) { | ||
@@ -51,6 +63,6 @@ this.invariant(pattern instanceof RegExp, 'Match requires a regular expression to match against.'); | ||
| return this.addCheck(this.checkMatch, pattern); | ||
| return this.addCheck(this.checkMatch, pattern, message); | ||
| }; | ||
| _proto.checkMatch = function checkMatch(path, value, pattern) { | ||
| _proto.checkMatch = function checkMatch(path, value, pattern, message) { | ||
| if ("production" !== process.env.NODE_ENV) { | ||
@@ -61,3 +73,3 @@ if (this.isOptionalDefault(value)) { | ||
| this.invariant(!!value.match(pattern), "String does not match pattern \"" + pattern.source + "\".", path); | ||
| this.invariant(!!value.match(pattern), (message || 'String does not match.') + " (pattern \"" + pattern.source + "\")", path); | ||
| } | ||
@@ -93,2 +105,10 @@ }; | ||
| _proto.pascalCase = function pascalCase() { | ||
| return this.match(/^[A-Z][0-9A-Za-z]+$/, 'String must be in pascal case.'); | ||
| }; | ||
| _proto.snakeCase = function snakeCase() { | ||
| return this.match(/^[a-z][0-9_a-z]+$/, 'String must be in snake case.'); | ||
| }; | ||
| return StringBuilder; | ||
@@ -95,0 +115,0 @@ }(Builder); |
+7
-3
@@ -15,2 +15,3 @@ import { SupportedType, CheckerCallback, CustomCallback, OptimalOptions, FuncOf } from './types'; | ||
| errorMessage: string; | ||
| isNever: boolean; | ||
| isNullable: boolean; | ||
@@ -41,3 +42,3 @@ isRequired: boolean; | ||
| */ | ||
| custom(callback: CustomCallback<T>): this; | ||
| custom<S = object>(callback: CustomCallback<T, S>): this; | ||
| /** | ||
@@ -68,2 +69,6 @@ * Validate the value using a custom callback. | ||
| /** | ||
| * Field should never be used. | ||
| */ | ||
| never(): Builder<never>; | ||
| /** | ||
| * Disallow null values. | ||
@@ -113,4 +118,3 @@ */ | ||
| } | ||
| export declare function bool(defaultValue?: boolean): Builder<boolean>; | ||
| export declare function custom<T>(callback: CustomCallback<T>, defaultValue: T): Builder<T>; | ||
| export declare function custom<T, S = object>(callback: CustomCallback<T, S>, defaultValue: T): Builder<T>; | ||
| export declare function func<T = FuncOf>(defaultValue?: T | null): Builder<T | null>; |
+21
-11
| "use strict"; | ||
| exports.__esModule = true; | ||
| exports.bool = bool; | ||
| exports.custom = custom; | ||
@@ -27,2 +26,4 @@ exports.func = func; | ||
| _defineProperty(this, "isNever", false); | ||
| _defineProperty(this, "isNullable", false); | ||
@@ -199,2 +200,11 @@ | ||
| _proto.never = function never() { | ||
| if ("production" !== process.env.NODE_ENV) { | ||
| this.defaultValue = undefined; | ||
| this.isNever = true; | ||
| } | ||
| return this; | ||
| }; | ||
| _proto.notNullable = function notNullable() { | ||
@@ -282,5 +292,13 @@ if ("production" !== process.env.NODE_ENV) { | ||
| } | ||
| } else if (this.deprecatedMessage) { | ||
| } else { | ||
| if (this.deprecatedMessage) { | ||
| if ("production" !== process.env.NODE_ENV) { | ||
| console.info("Field \"" + path + "\" is deprecated. " + this.deprecatedMessage); | ||
| } | ||
| } | ||
| if ("production" !== process.env.NODE_ENV) { | ||
| console.info("Field \"" + path + "\" is deprecated. " + this.deprecatedMessage); | ||
| if (this.isNever) { | ||
| this.invariant(false, 'Field should never be used.', path); | ||
| } | ||
| } | ||
@@ -346,10 +364,2 @@ } | ||
| function bool(defaultValue) { | ||
| if (defaultValue === void 0) { | ||
| defaultValue = false; | ||
| } | ||
| return new Builder('boolean', defaultValue); | ||
| } | ||
| function custom(callback, defaultValue) { | ||
@@ -356,0 +366,0 @@ return new Builder('custom', defaultValue).custom(callback); |
+3
-2
@@ -6,4 +6,5 @@ /** | ||
| import optimal from './optimal'; | ||
| import Builder, { bool, custom, func } from './Builder'; | ||
| import Builder, { custom, func } from './Builder'; | ||
| import ArrayBuilder, { array } from './ArrayBuilder'; | ||
| import BooleanBuilder, { bool } from './BooleanBuilder'; | ||
| import InstanceBuilder, { builder, instance, date, regex } from './InstanceBuilder'; | ||
@@ -32,5 +33,5 @@ import NumberBuilder, { number } from './NumberBuilder'; | ||
| export { array, blueprint, bool, builder, custom, date, func, instance, number, object, regex, shape, string, union, }; | ||
| export { Builder, ArrayBuilder, InstanceBuilder, NumberBuilder, ObjectBuilder, ShapeBuilder, StringBuilder, UnionBuilder, }; | ||
| export { Builder, ArrayBuilder, BooleanBuilder, InstanceBuilder, NumberBuilder, ObjectBuilder, ShapeBuilder, StringBuilder, UnionBuilder, }; | ||
| export declare type Predicates = typeof predicates; | ||
| export * from './types'; | ||
| export default optimal; |
+8
-3
@@ -7,3 +7,2 @@ "use strict"; | ||
| Builder: true, | ||
| bool: true, | ||
| custom: true, | ||
@@ -13,2 +12,4 @@ func: true, | ||
| array: true, | ||
| BooleanBuilder: true, | ||
| bool: true, | ||
| InstanceBuilder: true, | ||
@@ -38,3 +39,2 @@ builder: true, | ||
| exports.Builder = _Builder.default; | ||
| exports.bool = _Builder.bool; | ||
| exports.custom = _Builder.custom; | ||
@@ -48,2 +48,7 @@ exports.func = _Builder.func; | ||
| var _BooleanBuilder = _interopRequireWildcard(require("./BooleanBuilder")); | ||
| exports.BooleanBuilder = _BooleanBuilder.default; | ||
| exports.bool = _BooleanBuilder.bool; | ||
| var _InstanceBuilder = _interopRequireWildcard(require("./InstanceBuilder")); | ||
@@ -104,3 +109,3 @@ | ||
| blueprint: _ObjectBuilder.blueprint, | ||
| bool: _Builder.bool, | ||
| bool: _BooleanBuilder.bool, | ||
| builder: _InstanceBuilder.builder, | ||
@@ -107,0 +112,0 @@ custom: _Builder.custom, |
| import Builder from './Builder'; | ||
| export default class StringBuilder<T extends string = string> extends Builder<T> { | ||
| constructor(defaultValue?: T); | ||
| camelCase(): this; | ||
| contains(token: string, index?: number): this; | ||
| checkContains(path: string, value: T, token: string, index?: number): void; | ||
| match(pattern: RegExp): this; | ||
| checkMatch(path: string, value: T, pattern: RegExp): void; | ||
| kebabCase(): this; | ||
| match(pattern: RegExp, message?: string): this; | ||
| checkMatch(path: string, value: T, pattern: RegExp, message?: string): void; | ||
| notEmpty(): this; | ||
@@ -12,3 +14,5 @@ checkNotEmpty(path: string, value: T): void; | ||
| checkOneOf(path: string, value: T, list: T[]): void; | ||
| pascalCase(): this; | ||
| snakeCase(): this; | ||
| } | ||
| export declare function string<T extends string = string>(defaultValue?: string): StringBuilder<T>; |
+24
-4
@@ -26,2 +26,6 @@ "use strict"; | ||
| _proto.camelCase = function camelCase() { | ||
| return this.match(/^[a-z][0-9A-Za-z]+$/, 'String must be in camel case.'); | ||
| }; | ||
| _proto.contains = function contains(token, index) { | ||
@@ -53,3 +57,11 @@ if (index === void 0) { | ||
| _proto.match = function match(pattern) { | ||
| _proto.kebabCase = function kebabCase() { | ||
| return this.match(/^[a-z][\x2D0-9a-z]+$/, 'String must be in kebab case.'); | ||
| }; | ||
| _proto.match = function match(pattern, message) { | ||
| if (message === void 0) { | ||
| message = ''; | ||
| } | ||
| if ("production" !== process.env.NODE_ENV) { | ||
@@ -59,6 +71,6 @@ this.invariant(pattern instanceof RegExp, 'Match requires a regular expression to match against.'); | ||
| return this.addCheck(this.checkMatch, pattern); | ||
| return this.addCheck(this.checkMatch, pattern, message); | ||
| }; | ||
| _proto.checkMatch = function checkMatch(path, value, pattern) { | ||
| _proto.checkMatch = function checkMatch(path, value, pattern, message) { | ||
| if ("production" !== process.env.NODE_ENV) { | ||
@@ -69,3 +81,3 @@ if (this.isOptionalDefault(value)) { | ||
| this.invariant(!!value.match(pattern), "String does not match pattern \"" + pattern.source + "\".", path); | ||
| this.invariant(!!value.match(pattern), (message || 'String does not match.') + " (pattern \"" + pattern.source + "\")", path); | ||
| } | ||
@@ -101,2 +113,10 @@ }; | ||
| _proto.pascalCase = function pascalCase() { | ||
| return this.match(/^[A-Z][0-9A-Za-z]+$/, 'String must be in pascal case.'); | ||
| }; | ||
| _proto.snakeCase = function snakeCase() { | ||
| return this.match(/^[a-z][0-9_a-z]+$/, 'String must be in snake case.'); | ||
| }; | ||
| return StringBuilder; | ||
@@ -103,0 +123,0 @@ }(_Builder2.default); |
+1
-1
@@ -11,3 +11,3 @@ import Builder from './Builder'; | ||
| export declare type CheckerCallback = (path: string, value: any, ...args: any[]) => unknown; | ||
| export declare type CustomCallback<T> = (value: T, struct: object) => void; | ||
| export declare type CustomCallback<T, S = object> = (value: T, struct: S) => void; | ||
| export interface OptimalOptions { | ||
@@ -14,0 +14,0 @@ file?: string; |
+3
-3
| { | ||
| "name": "optimal", | ||
| "version": "3.3.0", | ||
| "version": "3.4.0", | ||
| "description": "A system for building and validating defined object structures.", | ||
@@ -47,4 +47,4 @@ "main": "./lib/index.js", | ||
| "devDependencies": { | ||
| "@milesj/build-tools": "^0.60.5", | ||
| "@types/node": "^12.12.14", | ||
| "@milesj/build-tools": "^0.61.4", | ||
| "@types/node": "^13.1.1", | ||
| "conventional-changelog-beemo": "^1.6.0" | ||
@@ -51,0 +51,0 @@ }, |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
100684
6.26%52
6.12%2260
6.91%114
7.55%