commit 9dd8723144cabe6fff2a0c454acae1301dbc9820 Author: Sven Slootweg Date: Tue May 26 02:28:33 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..eca865d --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# @validatem/is-string + +Documentation for this module has not been written yet. By the time it reaches 1.0.0, it will have full documentation. + +In the meantime, check out the `example.js` file in the repository for a usage demonstration. diff --git a/example.js b/example.js new file mode 100644 index 0000000..971f648 --- /dev/null +++ b/example.js @@ -0,0 +1,11 @@ +"use strict"; + +const { validateValue } = require("@validatem/core"); /* FIXME: Add to devDependencies */ +const isString = require("./"); + +console.log(validateValue("hello world", [ isString ])); // hello world + +console.log(validateValue(42, [ isString ])); /* + AggregrateValidationError: One or more validation errors occurred: + - At (root): Must be a string +*/ diff --git a/index.js b/index.js new file mode 100644 index 0000000..ac878e2 --- /dev/null +++ b/index.js @@ -0,0 +1,10 @@ +"use strict"; + +const ValidationError = require("@validatem/error"); +const isString = require("is-string"); + +module.exports = function (value) { + if (!isString(value)) { + throw new ValidationError("Must be a string"); + } +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..01f1a04 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "@validatem/is-string", + "description": "Validatem validator for ensuring that a value is a string", + "keywords": [ + "validatem", + "validator" + ], + "version": "0.1.0", + "main": "index.js", + "repository": "http://git.cryto.net/validatem/is-string.git", + "author": "Sven Slootweg ", + "license": "WTFPL OR CC0-1.0", + "dependencies": { + "@validatem/error": "^1.0.0", + "is-string": "^1.0.5" + } +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..4a6d680 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,20 @@ +# 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= + +is-string@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.5.tgz#40493ed198ef3ff477b8c7f92f644ec82a5cd3a6" + integrity sha512-buY6VNRjhQMiF1qWDouloZlQbRhDPCebwxSjxMjxgemYT46YMd2NR0/H+fBhEfWX4A/w9TBJ+ol+okqJKFE6vQ==