Initial commit; v1.0.0

master
Sven Slootweg 5 years ago
commit 696492df7f

1
.gitignore vendored

@ -0,0 +1 @@
node_modules

@ -0,0 +1,33 @@
# @validatem/error
This package contains the `ValidationError` type for [`validatem`](https://www.npmjs.com/package/@validatem/core).
__A VERY IMPORTANT NOTE:__ You should *always* use the caret notation (eg. `^1.0.0`) when depending on this package. NPM and Yarn will do this by default when you `npm install @validatem/error` or `yarn add @validatem/error`, but some people turn this off - don't do that here, or things might break!
## Why is this a separate package?
Because it makes forwards compatibility easier. Even if [`@validatem/core`](https://www.npmjs.com/package/@validatem/core) ever needs a breaking release, chances are that the error format remains unchanged. Making the error type separately versionable, means that in that scenario validators should stay compatible with both the old *and* the new version of the core, without validator authors needing to update anything.
## License, donations, and other boilerplate
Licensed under either the [WTFPL](http://www.wtfpl.net/txt/copying/) or [CC0](https://creativecommons.org/publicdomain/zero/1.0/), at your choice. In practice, that means it's more or less public domain, and you can do whatever you want with it. Giving credit is *not* required, but still very much appreciated! I'd love to [hear from you](mailto:admin@cryto.net) if `validatem` was useful to you.
Creating and maintaining open-source modules is a lot of work. A donation is also not required, but much appreciated! You can donate [here](http://cryto.net/~joepie91/donate.html).
## API
### new ValidationError(message, [properties])
The constructor for `validatem`'s `ValidationError` type. This is invoked like any other `Error` constructor, but you may optionally pass extra metadata that should be stored on the error.
__Unless you are implementing a parser and using virtual properties, you probably do not need to specify the `path` property.__ Combinators like `arrayOf` will insert their path segments after-the-fact by themselves, your validator does not need to do this.
* __message:__ A description of the validation problem. This should be formatted in such a way that it describes the *requirement*, and *not* how it failed; for example, it should say "Must be a string" rather than "Is not a string".
* __properties:__ *Optional.* An object of properties to attach to the new error object.
* __path:__ An array of 'path segment' strings that describes the location of the validation error.
## Changelog
### v1.0.0 (April 20, 2020)
Initial release.

@ -0,0 +1,12 @@
"use strict";
const createError = require("create-error");
module.exports = createError("ValidationError", {
path: [],
// NOTE: The below are for potential future compatibility logic.
___validatem_isValidationError: true,
___validatem_errorVersion: 1
});
module.exports.__modulePath = __dirname;

@ -0,0 +1,11 @@
{
"name": "@validatem/error",
"version": "1.0.0",
"main": "index.js",
"repository": "http://git.cryto.net/validatem/error.git",
"author": "Sven Slootweg <admin@cryto.net>",
"license": "WTFPL OR CC0-1.0",
"dependencies": {
"create-error": "^0.3.1"
}
}

@ -0,0 +1,8 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
create-error@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/create-error/-/create-error-0.3.1.tgz#69810245a629e654432bf04377360003a5351a23"
integrity sha1-aYECRaYp5lRDK/BDdzYAA6U1GiM=
Loading…
Cancel
Save