Comparing version 2.0.0 to 2.0.1
# Changelog | ||
## [2.0.1] - 2020-02-26 | ||
### Fixed | ||
- Fix `optional()` to allow typescript to create optional keys | ||
## [2.0.0] - 2020-01-31 | ||
@@ -4,0 +11,0 @@ |
@@ -16,3 +16,6 @@ import { Validator } from './validate'; | ||
export declare function defaultTo<R>(validator: Validator<R>, _default: R | (() => R)): ObjectOptions<R>; | ||
export declare function optional<R>(validator: Validator<R>): ObjectOptions<R>; | ||
export declare function optional<R>(validator: Validator<R>): { | ||
validator: Validator<R>; | ||
optional: true; | ||
}; | ||
export {}; |
@@ -65,4 +65,9 @@ "use strict"; | ||
chai_1.expect(options).to.eql({ validator, optional: true }); | ||
const validate = object_1.object({ foo: options }); | ||
const result = validate({ foo: 'bar' }); | ||
chai_1.expect(result).to.eql({ foo: 'bar' }); | ||
const emptyResult = validate({}); | ||
chai_1.expect(emptyResult).to.eql({}); | ||
}); | ||
}); | ||
//# sourceMappingURL=object.test.js.map |
{ | ||
"name": "fefe", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Validate, sanitize and transform values with proper types.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -72,5 +72,10 @@ import { expect } from 'chai' | ||
const validator = string() | ||
const options: ObjectOptions<string> = optional(validator) | ||
const options = optional(validator) | ||
expect(options).to.eql({ validator, optional: true }) | ||
const validate = object({ foo: options }) | ||
const result: { foo?: string } = validate({ foo: 'bar' }) | ||
expect(result).to.eql({ foo: 'bar' }) | ||
const emptyResult: { foo?: string } = validate({}) | ||
expect(emptyResult).to.eql({}) | ||
}) | ||
}) |
@@ -78,3 +78,3 @@ import { FefeError } from './errors' | ||
export function optional<R> (validator: Validator<R>): ObjectOptions<R> { | ||
export function optional<R> (validator: Validator<R>): {validator: Validator<R>, optional: true} { | ||
return { | ||
@@ -81,0 +81,0 @@ validator, |
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
100074
1521