Changelog
3.0.0
Release date: 2020-12-26
@babel/runtime
and lodash
: These are no longer bundled, in order to reduce duplication when bundling RTV.js into an app, since they are very common dependencies.process.env.NODE_ENV
being defined during bundling as either "development"
or "production"
. This is a fairly standard global definition, so it shouldn't really cause any trouble, and had previously been required for the CJS build anyway../dist/rtv.js
) with process.env.NODE_ENV === "development"
checks where appropriate for dev-only behavior (e.g. deprecation warnings). It is targeted for consumption by app bundlers such as Webpack or Rollup.@babel/runtime
and lodash
, which are now declared as peer dependencies of this package, rather than pre-bundling them and adding unnecessary bloat when the consuming project is already using Babel and/or Lodash../dist/rtv.esm.js
and also requires defining the process.env.NODE_ENV
global.browser
property because Webpack will prioritize that type of bundle by default, and this is not how this package should be consumed by another bundler who is also preparing a package to run in the browser. Doing so would lead to unnecessary duplication of code between Babel Runtime Helpers and Lodash functions, as well as prevent any level of tree shaking.RtvError.cause
, replaced with RtvError.mismatch
.RtvError.failure
, replaced with RtvError.rootCause
.rtv.t
, being replaced by rtv.types
.rtv.q
, being replaced by rtv.qualifiers
.rtv.e
, being replaced by rtv.enabled
(and then also removed; see below).rtv.enabled
convenience accessor. Use rtv.config.enabled
instead, or define your own environment variable, e.g. DEV_ENV && rtv.verify(...)
import rtv from 'rtvjs'; -> import * as rtv from 'rtvjs';
. Default exports are generally a bad idea, especially when converting from ESM to CJS. The elimination of the default export should make bundling RTV.js much easier, regardless of your target format (CJS, ESM, UMD, ...).ARRAY
form's ts
argument (which provides the typeset to use when verifying an array's elements) has been renamed to $
to be consistent with the $
property used in the fully-qualified form of the OBJECT
, ANY_OBJECT
, PLAIN_OBJECT
, and CLASS_OBJECt
types. In the end, whether with an ARRAY
or one of the 4 object types, it's still a typeset, so there was no reason to confuse things by using different property names. $
is unique and will be used for the same purpose should new features require nested typesets on other types.keys
and values
properties have been renamed to $keys
and $values
, respectively, because they represent typesets, and this brings the property names inline with the distinctive $
used for typeset arguments on ARRAY
and object types.rtv.check() / rtv.verify()
option, exactShapes: boolean
(default: false
), and new Shape Object Argument, exact: boolean
(default: false
):
exactShapes: true
, any shape encountered will require its related object value to have exactly the same own-properties that it has.exact: boolean
flag in the Shape Object Arguments.OBJECT
, ANY_OBJECT
, PLAIN_OBJECT
, CLASS_OBJECT
.deep
, which applies to HASH_MAP
only: When true
, if a value in the map does not match the $values
typeset, it's expected to be a nested HASH_MAP
whose keys and values match the parent map's structure (i.e. the same arguments used on the parent map are used to verify the value of its key).rtv.config.enabled
to a value that is not strictly a boolean
will no longer cause an RtvError
exception; instead, the value will simply be cast as a boolean
.RtvError.typeset
and RtvError.mismatch
typesets, resulting from a failed type validation with the OBJECT
, ANY_OBJECT
, or PLAIN_OBJECT
types, would not contain type arguments when they were specified as part of the original typeset. Difficult to explain, but just know that things are working better, even in obscure cases.Changelog
2.4.0
Release date: 2020-07-09
.hasOwnProperty()
directly on objects. Instead, uses Object.prototype.hasOwnProperty.call(obj, 'property')
.parent
and parentKey
properties to Type Validator Context to provide more flexibility to reactive validations (see example in README).Changelog
2.3.1
Release date: 2020-06-09
engines
back to oldest supported Node LTS (>=10.21.0
) and the version of NPM it ships with (>=6.14.4
).Changelog
2.3.0
Release date: 2020-05-25
Changelog
2.2.0
Release date: 2020-02-17
sideEffects:false
bundler hint/flag to package.json
: This will help bundlers like Webpack, which support the hint/flag, to know that this package does not have any side effects, and can confidently be removed during tree shaking if there are no code paths that refer to the library (e.g. if you only use RTV in your development build). See Webpack docs for more information.context
, which is a type validator context. This context provides additional information about the verification, such as the original value being verified (which differs from the first parameter, value
, as that is the value currently being verified, closest to the custom validator itself, e.g. the value of element in an array, as opposed to the array itself).RtvError
constructor function (and RtvSuccess
also, to balance things out) is now provided as rtv.RtvError
so that an Error
object can be tested using the instanceof
operator.TRUTHY
. Think of this qualifier as, "if truthy, the value is required to be of the specified type." Therefore, falsy values like null
, NaN
, or false
are permitted even if they aren't of the expected type(s), which makes it possible to verify only when a value is truthy, something that was not previously possible even with the OPTIONAL
qualifier."<validator>"
instead of "<function>"
(hopefully that's more helpful when reading the typeset, typically in an RtvError
's string representation)."Verification failed due to custom validator"
to "Verification failed by the custom validator"
, which hopefully better indicates that the verification failed because the custom validator chose to fail it, not because of the presence of a custom validator (as if it shouldn't have been there).RtvError.cause
, replaced with RtvError.mismatch
.RtvError.failure
, replaced with RtvError.rootCause
.rtv.t
, rtv.q
, and rtv.e
deprecated properties. rtv.enabled
(the newer one) no longer appears twice, once deprecated, once not.RtvError#failure
property (the property was undefined
in most cases, even if the validator threw an error).Changelog
2.1.0
Release date: 2019-10-05
rtv
object (e.g. rtv.STRING
).RtvError
's message and string serialization no longer includes the typeset
to reduce log bloat/noise (they could be very long), but the typeset
is still available as a property of the object.rtv.t
, being replaced by rtv.types
.rtv.q
, being replaced by rtv.qualifiers
.rtv.e
, being replaced by rtv.enabled
.impl
, it's no longer wrapped in an "outer" exception, resulting in a cleaner error message (e.g. what was once, "Cannot check value: Cannot check value: Invalid typeset..." for an invalid typeset nested 2 levels deep is now just, "Invalid typeset...").Changelog
2.0.0
Release date: 2019-09-10
./dist/cjs/...
./dist/umd/...
Changelog
1.1.0
Release date: 2019-02-02