Ground-up rewrite that migrates to a more composable API. Under the hood, classes were refactored into functions to reduce file size and overhead.
The biggest change is that predicates are now known as schemas. For the purpose of this release, the changelog will use the new verbiage, but may affect previous APIs.
- Dropped Node.js v10 support. Minimum requirement v12.17.
- Updated to ECMAScript modules, and now publishes
.mjs
for Node.js, and ESM.js
for browsers. - Updated
optimal()
to no longer accept the object to validate and build as the 1st argument. Instead avalidate()
function is returned, in which that object should be passed to. Because of this change, TypeScript types are more powerful and accurate. - Updated the API to be immutable, so each chained method will return a new schema instance.
- Updated
array()
to no longer accept a schema as an argument, usearray().of()
instead. - Updated
func()
to not be nullable by default. Instead usesundefined
. - Updated
instance()
to no longer accept a schema as an argument, useinstance().of()
instead. - Updated
object()
to no longer accept a schema as an argument, useobject().of()
instead. - Updated
union()
to no longer accept a list of schemas as an argument, useunion().of()
instead. - Renamed
.nonNullable()
method to.notNullable()
. - Removed
.key()
method. - Removed
.message()
method. - Removed the
predicate()
schema (useschema()
instead). - Removed the state boolean argument from
.required()
(use.notRequired()
). - Removed internal
__DEV__
checks. Validations will now run in production!
- Chained methods are now immutable, returning new schema instances.
- Errors are now collected and displayed as one, instead of failing on the first error.
- Added
.notRequired()
method. - Added
date()
andschema()
schemas. - Added
object().keysOf()
criteria method. - Added
createSchema()
function for creating custom schemas. - Added
createPredicate()
function for creating boolean return checkers. - Added custom messages to all schema methods through a
message
option. - Added lazy default value initializer callbacks to all schemas.
- A
ValidationError
is now thrown instead of anError
. - Migrated to Packemon for package building.
- Improved the handling of
null
andundefined
values. - Increased code coverage, especially around edge cases.
- Renamed predicates to schemas.
- Renamed validation checks to criteria.
- Improved error messages by including the currently invalid value.
- Fixed an issue where arrays and tuples were used at the same time in a union.
- Updated union error messages to be more readable.
- Updated tuple type aliases to use "tuple".
- Fixed some object comparison checks that would fail cross-realm.
- Reworked default values to handle undefined and null by default, and in a much better fashion.
- [shape] Reset schema state after validating children.
- [array,object,string] Updated empty checks to take nullable into account.
- [func] Removed the generic constraint as it is too restrictive.
- Added
Schema#currentPath
,currentValue
,initialStruct
,parentPath
, andparentStruct
properties. Should make custom tree checks much easier. - Added
Predicate#doRun
, so that sub-classes can hook into the run process.
- [shape,tuple] Fixed an issue where common predicate checks were not always running.
- [tuple] Fixed some array type check failures.
- [tuple] Fixed tuples failing to validate when in a
union
.
- Updated Node.js requirement to v10.
- Values are now type cast once all checks and validations have ran. This may cause unexpected results in production, but is not exactly breaking.
- Updated
custom()
callbacks to receive aSchema
as the 2nd argument instead of a struct object. - Removed and inlined all
check*
methods as we don't want them publicly chainable. - Renamed
Builder
toPredicate
for all classes. - Renamed
Builder#runChecks()
method toPredicate#run()
and reworked the arguments. - Renamed
builder()
topredicate()
. - [ts] Added visibility modifiers to many internal properties and methods.
- Add new
Schema
class for handling the building and validation of structs. - Add new
tuple()
predicate . - Add support for default values via factory functions.
- Add
Predicate#default()
to return the default value. - Add
Predicate#validate()
to run stand-alone validation with a predicate. - [array,object,string] Add
sizeOf()
method. - [number] Add
float()
,int()
,negative()
, andpositive()
methods. - [string] Add
lowerCase()
andupperCase()
methods.
- Updated
object()
andObjectOf
to support mapped types through a keys generic.
- Package is now built with Rollup to reduce filesize.
- Add
never()
for all predicates. - [bool] Add
onlyFalse()
andonlyTrue()
methods. - [string] Add
camelCase()
,kebabCase()
,pascalCase()
, andsnakeCase()
methods.
- Update
CustomCallback
with a struct generic.
- Update to latest.
- Refined types and replaced
any
withunknown
.
- Fixed some build issues.
- Added a
prefix
option tooptimal
, which customizes the initial object path prefix for errors. - Builder methods can now return a value to mutate the value being checked.
- Shapes within arrays, objects, or unions are now returned with the full object.
- Updated
ShapeBuilder
to calloptimal
internally, as the APIs are very similar. - Removed
@babel/runtime-corejs3
as it wasn't saving much space.
- Updated
StringBuilder#contains
andStringBuilder#match
to only check when the passed value is not the default value or the field is required.
- Added
ShapeBuilder#exact
, which throws on unknown fields and requires an exact shape. - Updated
UnionBuilder
to support builders of the same type in parallel. For example, can now use 2 instances ofobject()
. - Updated
UnionBuilder
to support object and shapes in parallel. - TS: Updated
instance()
to allow abstract classes.
- Added a
builder()
predicate, which checks that a property value is aBuilder
instance. - Added a
blueprint()
predicate, which checks that a property is an object ofBuilder
s.
- Updated to
@babel/runtime-corejs3
, which uses Babel v7.4 and CoreJS v3. - TS: Updated
optimal
to return the shape wrapped inRequired
. - TS: Updated
Blueprint
to remove optional properties (acts likeRequired
). - TS: Updated
Builder#custom
to infer the value argument based on the builder type. - TS: Replaced some usage of
any
withunknown
.
- Fixed some inheritance issues for instance of checks in loose mode.
- Removed docblocks from source files to reduce bundle size.
- TypeScript minimum version requirement is now 3.0.
- TypeScript has been rewritten to infer builder types and structures as best it can. This may cause
unexpected inferrence for
optimal()
usage and may require explicit generic types to be passed. - Nested blueprints must now use
shape()
instead of a plain object. - Collections have split into
ArrayBuilder
andObjectBuilder
.array()
andobject()
are still the same. Builder#nullable
no longer accepts an argument and instead enables nulls.custom()
- Default value is now required at all times.
- TS: Type will be inferred by the default value. Can be explicitly typed using generics.
shape()
- Default value has been removed (since it's inferred by nested blueprint structure).
string()
- String logic has been reversed, as they are now empty by default, instead of not empty. To
enable the old logic, use the
notEmpty()
method. - The
empty()
method has been removed.
- String logic has been reversed, as they are now empty by default, instead of not empty. To
enable the old logic, use the
union()
- Default value is now required at all times.
- TS: Type is
any
as unions are not inferrable. Can be explicitly typed using generics.
- Added documentation.
- Added a
file
option tooptimal()
to include in error messages. - Added a
predicates
export from the index, which is an object of all builder factory functions.- TS: Also added a
Predicates
type representing this shape.
- TS: Also added a
- Added a
loose
option toinstance()
, so cross-realm instance checks work (compares constructor name). - Added
Builder#notNullable
to disable null values. - Added
StringBuilder#notEmpty
to require strings to not be empty.
- TS: Removed
Struct
type.
- Added and ES
module
target.
- Fixed an issue with built files.
- Updated
shape()
to return an object with inherited or default values, instead of an empty object.
- Fixed an issue with built declaration files.
- Switched to Babel 7 as the transpiler. Bumped IE requirement to v11, and Node requirement to v8.9.
- Initial release.