Browse Source

Initial commit

master
Sven Slootweg 1 year ago
commit
e74b675b3a
  1. 1
      .gitignore
  2. 22
      example.js
  3. 15
      index.js
  4. 15
      package.json
  5. 27
      yarn.lock

1
.gitignore

@ -0,0 +1 @@
node_modules

22
example.js

@ -0,0 +1,22 @@
"use strict";
const validationResult = require("./");
const ValidationError = require("@validatem/error");
const { validateValue } = require("@validatem/core"); /* FIXME: Add to devDeps */
function nonsenseValidator(value) {
return validationResult({
errors: [
new ValidationError("Some nonsense"),
new ValidationError("Some more nonsense"),
],
newValue: value * 2 /* This will currently get lost into the void, because there are validation errors - a future version of Validatem may expose this "partial result", though */
});
}
let result = validateValue(21, nonsenseValidator);
/*
AggregrateValidationError: One or more validation errors occurred:
- At (root): Some nonsense
- At (root): Some more nonsense
*/

15
index.js

@ -0,0 +1,15 @@
"use strict";
const defaultValue = require("default-value");
module.exports = function validationResult({ errors, newValue }) {
return {
errors: defaultValue(errors, []),
newValue: newValue,
___validatem_isSpecial: true,
___validatem_isValidationResult: true,
___validatem_validationResultVersion: 1,
};
};
module.exports.__modulePath = __dirname;

15
package.json

@ -0,0 +1,15 @@
{
"name": "@validatem/validation-result",
"description": "Utility for creating a 'validation result', ie. an object that represents zero or more errors and an optional result value",
"version": "0.1.0",
"main": "index.js",
"repository": "http://git.cryto.net/validatem/validation-result.git",
"author": "Sven Slootweg <admin@cryto.net>",
"license": "WTFPL OR CC0-1.0",
"dependencies": {
"default-value": "^1.0.0"
},
"devDependencies": {
"@validatem/error": "^1.0.0"
}
}

27
yarn.lock

@ -0,0 +1,27 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@validatem/error@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@validatem/error/-/error-1.0.0.tgz#a975904aa4c3e7618d89088a393567a5e1778340"
integrity sha512-7M3tV4DhCuimuCRdC2L/topBByDjhzspzeQGNU0S4/mdn2aDNtESYE43K/2Kh/utCAhqXh2gyw89WYxy//t3fQ==
dependencies:
create-error "^0.3.1"
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=
default-value@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/default-value/-/default-value-1.0.0.tgz#8c6f52a5a1193fe78fdc9f86eb71d16c9757c83a"
integrity sha1-jG9SpaEZP+eP3J+G63HRbJdXyDo=
dependencies:
es6-promise-try "0.0.1"
es6-promise-try@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/es6-promise-try/-/es6-promise-try-0.0.1.tgz#10f140dad27459cef949973e5d21a087f7274b20"
integrity sha1-EPFA2tJ0Wc75SZc+XSGgh/cnSyA=
Loading…
Cancel
Save