whitelister
Advanced tools
Comparing version 0.1.0-beta to 0.1.0-beta2
@@ -91,7 +91,32 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
function _extendableBuiltin(cls) { | ||
function ExtendableBuiltin() { | ||
var instance = Reflect.construct(cls, Array.from(arguments)); | ||
Object.setPrototypeOf(instance, Object.getPrototypeOf(this)); | ||
return instance; | ||
} | ||
ExtendableBuiltin.prototype = Object.create(cls.prototype, { | ||
constructor: { | ||
value: cls, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (Object.setPrototypeOf) { | ||
Object.setPrototypeOf(ExtendableBuiltin, cls); | ||
} else { | ||
ExtendableBuiltin.__proto__ = cls; | ||
} | ||
return ExtendableBuiltin; | ||
} | ||
var _require = __webpack_require__(1), | ||
isFunc = _require.isFunc; | ||
module.exports.BaseError = function (_Error) { | ||
_inherits(_class, _Error); | ||
module.exports.BaseError = function (_extendableBuiltin2) { | ||
_inherits(_class, _extendableBuiltin2); | ||
@@ -120,3 +145,3 @@ function _class() { | ||
return _class; | ||
}(Error); | ||
}(_extendableBuiltin(Error)); | ||
@@ -123,0 +148,0 @@ module.exports.ArgumentError = function (_module$exports$BaseE) { |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.whitelister=t():e.whitelister=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=2)}([function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var s=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=r(1),u=a.isFunc;e.exports.BaseError=function(e){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";n(this,t);var r=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return r.name="BaseError",r.message=e,r}return o(t,e),s(t,[{key:"toJSON",value:function(){return{message:this.message}}}]),t}(Error),e.exports.ArgumentError=function(e){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";n(this,t);var o=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));o.name="ArgumentError";var s=r.length>0?" "+r:"";return o.message=""+e+s,o}return o(t,e),t}(e.exports.BaseError),e.exports.FieldError=function(e){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"is invalid";n(this,t);var o=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return o.name="FieldError",o.field=e,o.message=r,o}return o(t,e),s(t,[{key:"toString",value:function(){return this.field+" "+this.message}},{key:"toJSON",value:function(){return{field:this.field,message:this.message}}}]),t}(e.exports.BaseError),e.exports.WhitelistError=function(t){function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];n(this,r);var o=i(this,(r.__proto__||Object.getPrototypeOf(r)).call(this));return o.name="WhitelistError",o.errors=[],o.message="",t.forEach(function(t){t instanceof e.exports.WhitelistError?(t.errors.forEach(function(e){o.errors.push(e)}),o.addToMessage(t.message)):u(t.toJSON)?(o.errors.push(t.toJSON()),o.addToMessage(t.toString())):(o.errors.push({message:t.toString()}),o.addToMessage(t.message||t.toString()))}),o}return o(r,t),s(r,[{key:"addToMessage",value:function(e){this.message.length>0?this.message=this.message+", "+e:this.message=e}},{key:"toJSON",value:function(){return{message:this.message,errors:this.errors}}}]),r}(e.exports.BaseError)},function(e,t,r){"use strict";var n=function(){function e(e,t){var r=[],n=!0,i=!1,o=void 0;try{for(var s,a=e[Symbol.iterator]();!(n=(s=a.next()).done)&&(r.push(s.value),!t||r.length!==t);n=!0);}catch(e){i=!0,o=e}finally{try{!n&&a.return&&a.return()}finally{if(i)throw o}}return r}return function(t,r){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),i=Object.prototype.toString,o=Object.prototype.hasOwnProperty,s=function(e){return void 0!==e},a=function(e){return"[object Function]"===i.call(e)},u=function(e){return"[object String]"===i.call(e)},f=function(e){return"[object Object]"===i.call(e)},l=function(e){return!s(e)||null===e},c=function(e,t){var r=e.length<t.length?[e,t]:[t,e],i=n(r,2),o=i[0],s=i[1];return o.some(function(e){return s.includes(e)})};e.exports={has:o,includesOneOf:c,isDefined:s,isFunc:a,isNil:l,isObject:f,isString:u}},function(e,t,r){"use strict";e.exports=r(3),e.exports.errors=r(0)},function(e,t,r){"use strict";var n=r(0),i=n.ArgumentError,o=n.FieldError,s=n.WhitelistError,a=r(1),u=a.has,f=a.includesOneOf,l=a.isDefined,c=a.isFunc,h=a.isNil,m=a.isObject,p=a.isString,g={config:{nestedNames:!0},setConfig:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};l(e.nestedNames)&&(g.config.nestedNames=e.nestedNames)}};g.byRules=function(e,t,r,n){function a(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";if(!u.call(g,e))throw new i(n+"."+e,"is invalid");var o=g[e],s=void 0;try{s=o(t,r,n)}catch(e){f.push(e),s=r}return s}if(!m(e)&&!p(e)&&!c(e))throw new i("rules","is not an object or string");var f=[],d=function(e){if(f.length>0)throw new s(f);return e};if(p(e))return a(e,{},t,r);if(c(e)){if(!e(t))throw new o(""+(r||"value"),"is invalid");return t}if(u.call(e,"type")&&!n){var w=u.call(e,"preTransform")&&c(e.preTransform)?e.preTransform(t):t,y=void 0;try{y=a(e.type,e,w,r)}catch(e){f.push(e)}return d(y)}var v={};return Object.keys(e).forEach(function(n){var s=e[n]||{},m=g.config.nestedNames&&r?r+"["+n+"]":n,d=void 0;try{if(p(s)&&u.call(t,n))d=t[n],v[n]=a(s,{},d,m);else if(c(s)){if(d=t[n],!s(d))throw new o(m,"is invalid");v[n]=d}else if(u.call(t,n)&&l(t[n]))if(null!==(d=t[n])||!s.allowNull&&"null"!==s.type){if(h(d)&&s.required)throw new o(m,"is required");if(!u.call(g,s.type)&&!c(s.filterWith))throw new i(m+".type","is invalid");if(u.call(s,"preTransform")&&c(s.preTransform)&&(d=s.preTransform(d,m)),c(s.filterWith)){if(!s.filterWith(d,m))throw new o(m,"is invalid")}else d=g[s.type](s,d,m);if(Array.isArray(s.acceptedValues)&&!function(e){return e.some(function(e){return"function"==typeof e?e(d):e===d})}(s.acceptedValues))throw new o(m,"must be one of "+s.acceptedValues.join(", "));v[n]=u.call(s,"postTransform")&&c(s.postTransform)?s.postTransform(d,m):d}else v[n]=d;else if(l(s.default))v[n]=s.default;else if(s.required)throw new o(m,"is required")}catch(e){f.push(e)}}),d(v)},g.array=function(e,t,r){var n=p(t)?t.split(",").map(function(e){return e.trim()}):t;if(l(n)&&!Array.isArray(n))throw new o(r,"is not an array");if(l(e.minLength)&&(!l(n)||n.length<e.minLength))throw new o(r,"has too few elements (min "+e.minLength+" elements)");if(l(e.maxLength)&&l(n)&&n.length>e.maxLength)throw new o(r,"has too many elements (max "+e.maxLength+" elements)");var i=e.attributes;return l(i)?n.map(function(e,t){return g.byRules(i,e,r+"["+t+"]")}):n},g.boolean=function(e,t,r){var n=t;if(["true","1","t"].includes((""+n).toLowerCase()))n=!0;else if(["false","0","f"].includes((""+n).toLowerCase()))n=!1;else if(l(n))throw new o(r,"is not true or false");return n},g.email=function(e,t,r){if(!/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t))throw new o(r,"is not a valid email address");return t},g.null=function(e,t,r){if(null!==t)throw new o(r,"must be null");return t},g.integer=function(e,t,r){var n=t;if(Number.isInteger(n)||(n=parseInt(n,10)),isNaN(n))throw new o(r,"is not an integer");if(l(e.max)&&n>e.max)throw new o(r,"is too large (max "+e.max+")");if(l(e.min)&&n<e.min)throw new o(r,"is too small (min "+e.min+")");return n},g.float=function(e,t,r){var n=parseFloat(t,10);if(isNaN(n))throw new o(r,"is not a float");if(l(e.max)&&n>e.max)throw new o(r,"is too large (max "+e.max+")");if(l(e.min)&&n<e.min)throw new o(r,"is too small (min "+e.min+")");return n},g.object=function(e,t,r){if((h(t)||Object.keys(t).length<1)&&e.required)throw new o(r,"is required");if(!m(t))throw new o(r,"is not an object");if(Array.isArray(e.requireOneOf)&&!f(e.requireOneOf,Object.keys(t))){var n=e.requireOneOf.join(", ");throw new o(r,"must include one of "+n)}if(u.call(e,"attributes")){var i=g.config.nestedNames?r:"";return g.byRules(e.attributes,t,i,!0)}return t},g.string=function(e,t,r){var n=void 0;if(l(t)){if(!p(t))throw new o(r,"is not a string");if(n=t.toString(),e.minLength&&n.trim().length<e.minLength)throw new o(r,"is too short (min "+e.minLength+" characters)");if(e.maxLength&&n.trim().length>e.maxLength)throw new o(r,"is too long (max "+e.maxLength+" characters)");return n}if(e.required&&!l(n))throw new o(r,"is not a string");return n},e.exports=function(e,t){return new Promise(function(r,n){var i=void 0,o=void 0;try{o=g.byRules(e,t)}catch(e){i=e}i?n(i):r(o)})},e.exports.sync=function(e,t){return g.byRules(e,t)},e.exports.setConfig=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};g.setConfig(e)}}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.whitelister=t():e.whitelister=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=2)}([function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var s=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=r(1),u=a.isFunc;e.exports.BaseError=function(e){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";n(this,t);var r=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return r.name="BaseError",r.message=e,r}return i(t,e),s(t,[{key:"toJSON",value:function(){return{message:this.message}}}]),t}(function(e){function t(){var t=Reflect.construct(e,Array.from(arguments));return Object.setPrototypeOf(t,Object.getPrototypeOf(this)),t}return t.prototype=Object.create(e.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e,t}(Error)),e.exports.ArgumentError=function(e){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";n(this,t);var i=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));i.name="ArgumentError";var s=r.length>0?" "+r:"";return i.message=""+e+s,i}return i(t,e),t}(e.exports.BaseError),e.exports.FieldError=function(e){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"is invalid";n(this,t);var i=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return i.name="FieldError",i.field=e,i.message=r,i}return i(t,e),s(t,[{key:"toString",value:function(){return this.field+" "+this.message}},{key:"toJSON",value:function(){return{field:this.field,message:this.message}}}]),t}(e.exports.BaseError),e.exports.WhitelistError=function(t){function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];n(this,r);var i=o(this,(r.__proto__||Object.getPrototypeOf(r)).call(this));return i.name="WhitelistError",i.errors=[],i.message="",t.forEach(function(t){t instanceof e.exports.WhitelistError?(t.errors.forEach(function(e){i.errors.push(e)}),i.addToMessage(t.message)):u(t.toJSON)?(i.errors.push(t.toJSON()),i.addToMessage(t.toString())):(i.errors.push({message:t.toString()}),i.addToMessage(t.message||t.toString()))}),i}return i(r,t),s(r,[{key:"addToMessage",value:function(e){this.message.length>0?this.message=this.message+", "+e:this.message=e}},{key:"toJSON",value:function(){return{message:this.message,errors:this.errors}}}]),r}(e.exports.BaseError)},function(e,t,r){"use strict";var n=function(){function e(e,t){var r=[],n=!0,o=!1,i=void 0;try{for(var s,a=e[Symbol.iterator]();!(n=(s=a.next()).done)&&(r.push(s.value),!t||r.length!==t);n=!0);}catch(e){o=!0,i=e}finally{try{!n&&a.return&&a.return()}finally{if(o)throw i}}return r}return function(t,r){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),o=Object.prototype.toString,i=Object.prototype.hasOwnProperty,s=function(e){return void 0!==e},a=function(e){return"[object Function]"===o.call(e)},u=function(e){return"[object String]"===o.call(e)},f=function(e){return"[object Object]"===o.call(e)},c=function(e){return!s(e)||null===e},l=function(e,t){var r=e.length<t.length?[e,t]:[t,e],o=n(r,2),i=o[0],s=o[1];return i.some(function(e){return s.includes(e)})};e.exports={has:i,includesOneOf:l,isDefined:s,isFunc:a,isNil:c,isObject:f,isString:u}},function(e,t,r){"use strict";e.exports=r(3),e.exports.errors=r(0)},function(e,t,r){"use strict";var n=r(0),o=n.ArgumentError,i=n.FieldError,s=n.WhitelistError,a=r(1),u=a.has,f=a.includesOneOf,c=a.isDefined,l=a.isFunc,h=a.isNil,m=a.isObject,p=a.isString,g={config:{nestedNames:!0},setConfig:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};c(e.nestedNames)&&(g.config.nestedNames=e.nestedNames)}};g.byRules=function(e,t,r,n){function a(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";if(!u.call(g,e))throw new o(n+"."+e,"is invalid");var i=g[e],s=void 0;try{s=i(t,r,n)}catch(e){f.push(e),s=r}return s}if(!m(e)&&!p(e)&&!l(e))throw new o("rules","is not an object or string");var f=[],d=function(e){if(f.length>0)throw new s(f);return e};if(p(e))return a(e,{},t,r);if(l(e)){if(!e(t))throw new i(""+(r||"value"),"is invalid");return t}if(u.call(e,"type")&&!n){var w=u.call(e,"preTransform")&&l(e.preTransform)?e.preTransform(t):t,y=void 0;try{y=a(e.type,e,w,r)}catch(e){f.push(e)}return d(y)}var v={};return Object.keys(e).forEach(function(n){var s=e[n]||{},m=g.config.nestedNames&&r?r+"["+n+"]":n,d=void 0;try{if(p(s)&&u.call(t,n))d=t[n],v[n]=a(s,{},d,m);else if(l(s)){if(d=t[n],!s(d))throw new i(m,"is invalid");v[n]=d}else if(u.call(t,n)&&c(t[n]))if(null!==(d=t[n])||!s.allowNull&&"null"!==s.type){if(h(d)&&s.required)throw new i(m,"is required");if(!u.call(g,s.type)&&!l(s.filterWith))throw new o(m+".type","is invalid");if(u.call(s,"preTransform")&&l(s.preTransform)&&(d=s.preTransform(d,m)),l(s.filterWith)){if(!s.filterWith(d,m))throw new i(m,"is invalid")}else d=g[s.type](s,d,m);if(Array.isArray(s.acceptedValues)&&!function(e){return e.some(function(e){return"function"==typeof e?e(d):e===d})}(s.acceptedValues))throw new i(m,"must be one of "+s.acceptedValues.join(", "));v[n]=u.call(s,"postTransform")&&l(s.postTransform)?s.postTransform(d,m):d}else v[n]=d;else if(c(s.default))v[n]=s.default;else if(s.required)throw new i(m,"is required")}catch(e){f.push(e)}}),d(v)},g.array=function(e,t,r){var n=p(t)?t.split(",").map(function(e){return e.trim()}):t;if(c(n)&&!Array.isArray(n))throw new i(r,"is not an array");if(c(e.minLength)&&(!c(n)||n.length<e.minLength))throw new i(r,"has too few elements (min "+e.minLength+" elements)");if(c(e.maxLength)&&c(n)&&n.length>e.maxLength)throw new i(r,"has too many elements (max "+e.maxLength+" elements)");var o=e.attributes;return c(o)?n.map(function(e,t){return g.byRules(o,e,r+"["+t+"]")}):n},g.boolean=function(e,t,r){var n=t;if(["true","1","t"].includes((""+n).toLowerCase()))n=!0;else if(["false","0","f"].includes((""+n).toLowerCase()))n=!1;else if(c(n))throw new i(r,"is not true or false");return n},g.email=function(e,t,r){if(!/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t))throw new i(r,"is not a valid email address");return t},g.null=function(e,t,r){if(null!==t)throw new i(r,"must be null");return t},g.integer=function(e,t,r){var n=t;if(Number.isInteger(n)||(n=parseInt(n,10)),isNaN(n))throw new i(r,"is not an integer");if(c(e.max)&&n>e.max)throw new i(r,"is too large (max "+e.max+")");if(c(e.min)&&n<e.min)throw new i(r,"is too small (min "+e.min+")");return n},g.float=function(e,t,r){var n=parseFloat(t,10);if(isNaN(n))throw new i(r,"is not a float");if(c(e.max)&&n>e.max)throw new i(r,"is too large (max "+e.max+")");if(c(e.min)&&n<e.min)throw new i(r,"is too small (min "+e.min+")");return n},g.object=function(e,t,r){if((h(t)||Object.keys(t).length<1)&&e.required)throw new i(r,"is required");if(!m(t))throw new i(r,"is not an object");if(Array.isArray(e.requireOneOf)&&!f(e.requireOneOf,Object.keys(t))){var n=e.requireOneOf.join(", ");throw new i(r,"must include one of "+n)}if(u.call(e,"attributes")){var o=g.config.nestedNames?r:"";return g.byRules(e.attributes,t,o,!0)}return t},g.string=function(e,t,r){var n=void 0;if(c(t)){if(!p(t))throw new i(r,"is not a string");if(n=t.toString(),e.minLength&&n.trim().length<e.minLength)throw new i(r,"is too short (min "+e.minLength+" characters)");if(e.maxLength&&n.trim().length>e.maxLength)throw new i(r,"is too long (max "+e.maxLength+" characters)");return n}if(e.required&&!c(n))throw new i(r,"is not a string");return n},e.exports=function(e,t){return new Promise(function(r,n){var o=void 0,i=void 0;try{i=g.byRules(e,t)}catch(e){o=e}o?n(o):r(i)})},e.exports.sync=function(e,t){return g.byRules(e,t)},e.exports.setConfig=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};g.setConfig(e)}}])}); |
{ | ||
"name": "whitelister", | ||
"version": "0.1.0-beta", | ||
"version": "0.1.0-beta2", | ||
"description": "Simple, basic filtering and validation tool for Node.js.", | ||
@@ -51,2 +51,3 @@ "main": "./whitelister.js", | ||
"babel-loader": "^7.1.2", | ||
"babel-plugin-transform-builtin-extend": "^1.1.2", | ||
"babel-preset-env": "^1.6.1", | ||
@@ -53,0 +54,0 @@ "chai": "^3.5.0", |
# Whitelister | ||
Simple, **dependency-free** filtering and validation tool for Node.js. | ||
Simple, **dependency-free** filtering and validation tool for Node.js and the browser. | ||
@@ -9,7 +9,12 @@ [![Build Status](https://travis-ci.org/SpireTeam/whitelister.svg?branch=master)](https://travis-ci.org/SpireTeam/whitelister) | ||
#### Node.js | ||
Using yarn: | ||
`yarn add whitelister@latest` | ||
Using npm: | ||
`npm i --save whitelister` | ||
`npm i --save whitelister@latest` | ||
In Node.js | ||
```js | ||
@@ -30,2 +35,22 @@ const whitelister = require('whitelister'); | ||
#### Browser | ||
```html | ||
<script src="https://unpkg.com/whitelister@latest/dist/whitelister.js" /> | ||
# or the minified version | ||
<script src="https://unpkg.com/whitelister@latest/dist/whitelister.min.js" /> | ||
<script> | ||
var rules = { | ||
q: 'string', | ||
page: { type: 'integer', min: 1, default: 1 }, | ||
per_page: { type: 'integer', min: 1, max: 100, default: 20 }, | ||
}; | ||
var params = { q: 'hello' }; | ||
var result = whitelister.sync(rules, params); | ||
</script> | ||
``` | ||
## Documentation | ||
@@ -32,0 +57,0 @@ |
44596
851
71
16