commit 437b798064e1960e4844fffa3762ff3eb674b97c Author: Sven Slootweg Date: Wed May 27 01:55:40 2020 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/README.md b/README.md new file mode 100644 index 0000000..ea08bc1 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# @validatem/with-context + +Documentation for this module has not been fully written yet. By the time it reaches 1.0.0, it will have full documentation. + +In the meantime, check out the [`@validatem/allow-extra-properties` module](https://git.cryto.net/validatem/allow-extra-properties) for a usage demonstration. diff --git a/index.js b/index.js new file mode 100644 index 0000000..f4f6681 --- /dev/null +++ b/index.js @@ -0,0 +1,11 @@ +"use strict"; + +const combinator = require("@validatem/combinator"); + +module.exports = function withContext(rules, context) { + return combinator((item, applyValidators, parentContext) => { + let mergedContext = Object.assign({}, parentContext, context); + + return applyValidators(item, rules, mergedContext); + }); +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..3b15ca4 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "@validatem/with-context", + "description": "Validatem combinator for applying context (custom configuration) to a validator", + "keywords": [ + "validatem", + "validator", + "combinator" + ], + "version": "0.1.0", + "main": "index.js", + "repository": "http://git.cryto.net/validatem/with-context.git", + "author": "Sven Slootweg ", + "license": "WTFPL OR CC0-1.0", + "dependencies": { + "@validatem/combinator": "^0.1.1" + } +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..e97beb5 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,8 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@validatem/combinator@^0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@validatem/combinator/-/combinator-0.1.1.tgz#202f31243f8d57cf87f1b449405b134e2fa40c5a" + integrity sha512-crzAYCmKUcb1DC5sSpdof4gWHX81VRmm+REWflhFuRlKH6JHRV5RcBCxEjlDfRrxW2yF6s9i0rQAOyVVE+GGAg==