Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit d7c459fd06d3bd8e2688f164dd51528f38c9c833 0 parents
Cameron Bytheway camshaft authored
Showing with 108 additions and 0 deletions.
  1. +2 −0  .gitignore
  2. +40 −0 README.md
  3. +40 −0 index.js
  4. +26 −0 package.json
2  .gitignore
@@ -0,0 +1,2 @@
+node_modules
+npm-debug.log
40 README.md
@@ -0,0 +1,40 @@
+# architect-validator
+
+[validator](https://github.com/chriso/node-validator) plugin for
+[architect](https://github.com/c9/architect)
+
+## Config Format
+
+```json
+{
+ "packagePath": "./node_modules/architect-validator",
+ "sanitize": true
+}
+```
+
+## Usage
+
+Validate that ssssshtuff
+
+```js
+module.exports = function (options, imports, register) {
+
+ var validator = imports.validator;
+
+ var obj = {
+ email: "this isn't an email",
+ name: "My name can be whatever"
+ }
+
+ validator(obj, function(key, value){
+ // throw an exception or return false
+ if (key == 'email') {
+ return isEmail(value);
+ }
+ }, function(errors){
+ // Errors come back as a list of kv's
+ // errors == [{key: 'email', "My name can be whatever"}]
+ });
+
+};
+```
40 index.js
@@ -0,0 +1,40 @@
+
+module.exports = function(options, imports, register) {
+
+ var _ = require('underscore');
+ var sanitizer = require('validator').sanitize;
+
+ options = _.defaults(options, {sanitize: true});
+
+ var validate = function(data, reduce, done, sanitize) {
+
+ if (_.isUndefined(sanitize)) {
+ sanitize = options.sanitize;
+ }
+
+ var errors =
+ _.chain(data)
+ .map(function(value, key) {
+ if(sanitize) {
+ value = sanitizer(value).xss();
+ }
+ return {key: key, value: value};
+ })
+ .reduce(function(memo, input) {
+ try {
+ var result = reduce(input.key, input.value);
+ if (result == false) memo.push(input);
+ }
+ catch(e) {
+ if (!memo) memo=[];
+ memo.push(input);
+ }
+ return memo;
+ }, false)
+ .value();
+
+ done(errors);
+ }
+
+ register(null, {validator: validate});
+}
26 package.json
@@ -0,0 +1,26 @@
+{
+ "name": "architect-validator",
+ "description": "Validator for Architect",
+ "version": "0.0.1",
+ "main": "index.js",
+ "author": {
+ "name": "Nujii Labs",
+ "email": "developer@nujii.com"
+ },
+ "contributors": [
+ { "name": "Cameron Bytheway", "email": "cameron@nujii.com" }
+ ],
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/nujii/architect-validator.git"
+ },
+ "license": "MIT",
+ "dependencies": {
+ "validator": "~0.4.11",
+ "underscore": "~1.3.3"
+ },
+ "plugin": {
+ "provides": ["validator"],
+ "consumes": []
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.