Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aspnet-validation

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aspnet-validation - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

types/index.d.ts

33

dist/aspnet-validation.js

@@ -377,2 +377,6 @@ (function webpackUniversalModuleDefinition(root, factory) {

/**
* A key-value collection of UID to Element for quick lookup.
*/
this.elementByUID = {};
/**
* A key-value collection of input UIDs for a <form> UID.

@@ -447,7 +451,7 @@ */

var e = validationMessageElements[i];
var id = e.getAttribute('data-valmsg-for');
if (!this.messageFor[id]) {
this.messageFor[id] = [];
var name_1 = e.getAttribute('data-valmsg-for');
if (!this.messageFor[name_1]) {
this.messageFor[name_1] = [];
}
this.messageFor[id].push(e);
this.messageFor[name_1].push(e);
}

@@ -521,2 +525,3 @@ };

});
this.elementByUID[uid] = node;
return uid;

@@ -574,2 +579,18 @@ };

form.addEventListener('submit', cb);
form.addEventListener('reset', function (e) {
var uids = _this.formInputs[formUID];
for (var _i = 0, uids_1 = uids; _i < uids_1.length; _i++) {
var uid = uids_1[_i];
var input = _this.elementByUID[uid];
input.classList.remove('input-validation-error');
var spans = _this.messageFor[input.name];
if (spans) {
for (var i = 0; i < spans.length; i++) {
spans[i].innerHTML = '';
}
}
delete _this.summary[uid];
}
_this.renderSummary();
});
this.elementEvents[formUID] = cb;

@@ -667,3 +688,3 @@ };

ValidationService.prototype.addError = function (input, message) {
var spans = this.messageFor[input.id];
var spans = this.messageFor[input.name];
if (spans) {

@@ -686,3 +707,3 @@ for (var i = 0; i < spans.length; i++) {

ValidationService.prototype.removeError = function (input) {
var spans = this.messageFor[input.id];
var spans = this.messageFor[input.name];
if (spans) {

@@ -689,0 +710,0 @@ for (var i = 0; i < spans.length; i++) {

2

dist/aspnet-validation.min.js

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.aspnetValidation=e():t.aspnetValidation=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),r.d(e,"MvcValidationProviders",function(){return a}),r.d(e,"ValidationService",function(){return o});var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))(function(i,a){function o(t){try{u(n.next(t))}catch(t){a(t)}}function s(t){try{u(n.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new r(function(e){e(t.value)}).then(o,s)}u((n=n.apply(t,e||[])).next())})},i=this&&this.__generator||function(t,e){function r(t){return function(e){return n([t,e])}}function n(r){if(i)throw new TypeError("Generator is already executing.");for(;u;)try{if(i=1,a&&(o=a[2&r[0]?"return":r[0]?"throw":"next"])&&!(o=o.call(a,r[1])).done)return o;switch(a=0,o&&(r=[0,o.value]),r[0]){case 0:case 1:o=r;break;case 4:return u.label++,{value:r[1],done:!1};case 5:u.label++,a=r[1],r=[0];continue;case 7:r=u.ops.pop(),u.trys.pop();continue;default:if(o=u.trys,!(o=o.length>0&&o[o.length-1])&&(6===r[0]||2===r[0])){u=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]<o[3])){u.label=r[1];break}if(6===r[0]&&u.label<o[1]){u.label=o[1],o=r;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(r);break}o[2]&&u.ops.pop(),u.trys.pop();continue}r=e.call(t,u)}catch(t){r=[6,t],a=0}finally{i=o=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}var i,a,o,s,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:r(0),throw:r(1),return:r(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s},a=function(){function t(){this.required=function(t,e,r){return Boolean(t)},this.stringLength=function(t,e,r){if(!t)return!0;if(r.min){var n=parseInt(r.min);if(t.length<n)return!1}if(r.max){var i=parseInt(r.max);if(t.length>i)return!1}return!0},this.compare=function(t,e,r){if(!r.other)return!0;var n=document.getElementById(r.other.substr(2));return!n||n.value===t},this.range=function(t,e,r){if(!t)return!0;var n=parseFloat(t);if(isNaN(n))return!1;if(r.min){if(n<parseFloat(r.min))return!1}if(r.max){if(n>parseFloat(r.max))return!1}return!0},this.regex=function(t,e,r){return!t||!r.pattern||new RegExp(r.pattern).test(t)},this.email=function(t,e,r){return!t||/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*(\.\w{2,})+$/.test(t)},this.creditcard=function(t,e,r){if(!t)return!0;if(/[^0-9 \-]+/.test(t))return!1;var n,i,a=0,o=0,s=!1;if(t=t.replace(/\D/g,""),t.length<13||t.length>19)return!1;for(n=t.length-1;n>=0;n--)i=t.charAt(n),o=parseInt(i,10),s&&(o*=2)>9&&(o-=9),a+=o,s=!s;return a%10==0},this.url=function(t,e,r){return!t||new RegExp("^(?:(?:https?|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))\\.?)(?::\\d{2,5})?(?:[/?#]\\S*)?$","i").test(t)},this.phone=function(t,e,r){return!t||!/[\+\-\s][\-\s]/g.test(t)&&/^\+?[0-9\-\s]+$/.test(t)},this.remote=function(t,e,r){return!t||new Promise(function(n,i){for(var a=r.url+"?"+e.name+"="+encodeURIComponent(t),o=r.additionalfields.split(","),s=0;s<o.length;s++){var u=o[s].substr(2);if(u!==e.name){var d=document.getElementById(u);d&&d.value&&(a=a+"&"+d.name+"="+encodeURIComponent(d.value))}}var f=new XMLHttpRequest;f.open("get",a),f.onload=function(t){if(f.status>=200&&f.status<300){var e=JSON.parse(f.responseText);n(e)}else i({status:f.status,statusText:f.statusText,data:f.responseText})},f.onerror=function(t){i({status:f.status,statusText:f.statusText,data:f.responseText})},f.send()})}}return t}(),o=function(){function t(){this.providers={},this.messageFor={},this.elementUIDs=[],this.formInputs={},this.validators={},this.elementEvents={},this.summary={},this.debounce=300}return t.prototype.addProvider=function(t,e){this.providers[t]||(this.providers[t]=e)},t.prototype.addMvcProviders=function(){var t=new a;this.addProvider("required",t.required),this.addProvider("length",t.stringLength),this.addProvider("maxlength",t.stringLength),this.addProvider("minlength",t.stringLength),this.addProvider("equalto",t.compare),this.addProvider("range",t.range),this.addProvider("regex",t.regex),this.addProvider("creditcard",t.creditcard),this.addProvider("email",t.email),this.addProvider("url",t.url),this.addProvider("phone",t.phone),this.addProvider("remote",t.remote)},t.prototype.scanMessages=function(){for(var t=document.querySelectorAll("[data-valmsg-for]"),e=0;e<t.length;e++){var r=t[e],n=r.getAttribute("data-valmsg-for");this.messageFor[n]||(this.messageFor[n]=[]),this.messageFor[n].push(r)}},t.prototype.parseDirectives=function(t){for(var e={},r={},n="data-val-".length,i=0;i<t.length;i++){var a=t[i];if(0===a.name.indexOf("data-val-")){var o=a.name.substr(n);r[o]=a.value}}for(var o in r)!function(t){if(-1===t.indexOf("-")){for(var n=Object.keys(r).filter(function(e){return e!==t&&0===e.indexOf(t)}),i={error:r[t],params:{}},a=(t+"-").length,o=0;o<n.length;o++){var s=r[n[o]],u=n[o].substr(a);i.params[u]=s}e[t]=i}}(o);return e},t.prototype.guid4=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})},t.prototype.getElementUID=function(t){var e=this.elementUIDs.filter(function(e){return e.node===t})[0];if(e)return e.uid;var r=this.guid4();return this.elementUIDs.push({node:t,uid:r}),r},t.prototype.getFormValidationTask=function(t){var e=this.formInputs[t];if(!e||0===e.length)return null;for(var r=[],n=0;n<e.length;n++){var i=e[n];r.push(this.validators[i])}var a=r.map(function(t){return t()});return Promise.all(a).then(function(t){return t.every(function(t){return t})})},t.prototype.trackFormInput=function(t,e){var r=this,n=this.getElementUID(t);if(this.formInputs[n]||(this.formInputs[n]=[]),-1===this.formInputs[n].indexOf(e)&&this.formInputs[n].push(e),!this.elementEvents[n]){var i=function(e){var i=r.getFormValidationTask(n);i&&(e.preventDefault(),i.then(function(e){e&&t.submit()}).catch(function(t){console.log(t)}))};t.addEventListener("submit",i),this.elementEvents[n]=i}},t.prototype.addInput=function(t){var e=this,r=this.getElementUID(t),n=this.parseDirectives(t.attributes),i=this.createValidator(t,n);if(this.validators[r]=i,this.trackFormInput(t.form,r),!this.elementEvents[r]){var a,o=function(t){var n=e.validators[r];clearTimeout(a),a=setTimeout(n,e.debounce)};"select"===t.tagName.toLowerCase()?t.addEventListener("change",o):t.addEventListener("input",o),this.elementEvents[r]=o}},t.prototype.scanInputs=function(){for(var t=document.querySelectorAll('[data-val="true"]'),e=0;e<t.length;e++){var r=t[e];this.addInput(r)}},t.prototype.createSummaryDOM=function(){if(!Object.keys(this.summary).length)return null;var t=document.createElement("ul");for(var e in this.summary){var r=document.createElement("li");r.innerHTML=this.summary[e],t.appendChild(r)}return t},t.prototype.renderSummary=function(){var t=document.querySelectorAll('[data-valmsg-summary="true"]');if(t.length){var e=JSON.stringify(this.summary,Object.keys(this.summary).sort());if(e!==this.renderedSummaryJSON){this.renderedSummaryJSON=e;for(var r=this.createSummaryDOM(),n=0;n<t.length;n++){var i=t[n];i.innerHTML="",r?(i.className="validation-summary-error",i.appendChild(r.cloneNode(!0))):i.className="validation-summary-valid"}}}},t.prototype.addError=function(t,e){var r=this.messageFor[t.id];if(r)for(var n=0;n<r.length;n++)r[n].innerHTML=e,r[n].className="field-validation-error";t.classList.remove("input-validation-valid"),t.classList.add("input-validation-error");var i=this.getElementUID(t);this.summary[i]=e,this.renderSummary()},t.prototype.removeError=function(t){var e=this.messageFor[t.id];if(e)for(var r=0;r<e.length;r++)e[r].innerHTML="",e[r].className="field-validation-valid";t.classList.remove("input-validation-error"),t.classList.add("input-validation-valid");var n=this.getElementUID(t);delete this.summary[n],this.renderSummary()},t.prototype.createValidator=function(t,e){var r=this;return function(){return n(r,void 0,void 0,function(){var r,n,a,o,s,u,d,f,l,c;return i(this,function(i){switch(i.label){case 0:r=[];for(n in e)r.push(n);a=0,i.label=1;case 1:return a<r.length?(o=r[a],s=e[o],(u=this.providers[o])?(d=u(t.value,t,s.params),f=!1,l=s.error,"boolean"!=typeof d?[3,2]:(f=d,[3,5])):(console.log("aspnet-validation provider not implemented: "+o),[3,6])):[3,7];case 2:return"string"!=typeof d?[3,3]:(f=!1,l=d,[3,5]);case 3:return[4,d];case 4:c=i.sent(),"boolean"==typeof c?f=c:(f=!1,l=c),i.label=5;case 5:if(!f)return this.addError(t,l),[2,!1];i.label=6;case 6:return a++,[3,1];case 7:return this.removeError(t),[2,!0]}})})}},t.prototype.bootstrap=function(){var t=this;this.addMvcProviders(),document.addEventListener("DOMContentLoaded",function(e){t.scanMessages(),t.scanInputs()})},t}()}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.aspnetValidation=t():e.aspnetValidation=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var a=r[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,t),a.l=!0,a.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=0)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),r.d(t,"MvcValidationProviders",function(){return i}),r.d(t,"ValidationService",function(){return o});var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(a,i){function o(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){e.done?a(e.value):new r(function(t){t(e.value)}).then(o,s)}u((n=n.apply(e,t||[])).next())})},a=this&&this.__generator||function(e,t){function r(e){return function(t){return n([e,t])}}function n(r){if(a)throw new TypeError("Generator is already executing.");for(;u;)try{if(a=1,i&&(o=i[2&r[0]?"return":r[0]?"throw":"next"])&&!(o=o.call(i,r[1])).done)return o;switch(i=0,o&&(r=[0,o.value]),r[0]){case 0:case 1:o=r;break;case 4:return u.label++,{value:r[1],done:!1};case 5:u.label++,i=r[1],r=[0];continue;case 7:r=u.ops.pop(),u.trys.pop();continue;default:if(o=u.trys,!(o=o.length>0&&o[o.length-1])&&(6===r[0]||2===r[0])){u=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]<o[3])){u.label=r[1];break}if(6===r[0]&&u.label<o[1]){u.label=o[1],o=r;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(r);break}o[2]&&u.ops.pop(),u.trys.pop();continue}r=t.call(e,u)}catch(e){r=[6,e],i=0}finally{a=o=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}var a,i,o,s,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:r(0),throw:r(1),return:r(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s},i=function(){function e(){this.required=function(e,t,r){return Boolean(e)},this.stringLength=function(e,t,r){if(!e)return!0;if(r.min){var n=parseInt(r.min);if(e.length<n)return!1}if(r.max){var a=parseInt(r.max);if(e.length>a)return!1}return!0},this.compare=function(e,t,r){if(!r.other)return!0;var n=document.getElementById(r.other.substr(2));return!n||n.value===e},this.range=function(e,t,r){if(!e)return!0;var n=parseFloat(e);if(isNaN(n))return!1;if(r.min){if(n<parseFloat(r.min))return!1}if(r.max){if(n>parseFloat(r.max))return!1}return!0},this.regex=function(e,t,r){return!e||!r.pattern||new RegExp(r.pattern).test(e)},this.email=function(e,t,r){return!e||/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*(\.\w{2,})+$/.test(e)},this.creditcard=function(e,t,r){if(!e)return!0;if(/[^0-9 \-]+/.test(e))return!1;var n,a,i=0,o=0,s=!1;if(e=e.replace(/\D/g,""),e.length<13||e.length>19)return!1;for(n=e.length-1;n>=0;n--)a=e.charAt(n),o=parseInt(a,10),s&&(o*=2)>9&&(o-=9),i+=o,s=!s;return i%10==0},this.url=function(e,t,r){return!e||new RegExp("^(?:(?:https?|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))\\.?)(?::\\d{2,5})?(?:[/?#]\\S*)?$","i").test(e)},this.phone=function(e,t,r){return!e||!/[\+\-\s][\-\s]/g.test(e)&&/^\+?[0-9\-\s]+$/.test(e)},this.remote=function(e,t,r){return!e||new Promise(function(n,a){for(var i=r.url+"?"+t.name+"="+encodeURIComponent(e),o=r.additionalfields.split(","),s=0;s<o.length;s++){var u=o[s].substr(2);if(u!==t.name){var d=document.getElementById(u);d&&d.value&&(i=i+"&"+d.name+"="+encodeURIComponent(d.value))}}var f=new XMLHttpRequest;f.open("get",i),f.onload=function(e){if(f.status>=200&&f.status<300){var t=JSON.parse(f.responseText);n(t)}else a({status:f.status,statusText:f.statusText,data:f.responseText})},f.onerror=function(e){a({status:f.status,statusText:f.statusText,data:f.responseText})},f.send()})}}return e}(),o=function(){function e(){this.providers={},this.messageFor={},this.elementUIDs=[],this.elementByUID={},this.formInputs={},this.validators={},this.elementEvents={},this.summary={},this.debounce=300}return e.prototype.addProvider=function(e,t){this.providers[e]||(this.providers[e]=t)},e.prototype.addMvcProviders=function(){var e=new i;this.addProvider("required",e.required),this.addProvider("length",e.stringLength),this.addProvider("maxlength",e.stringLength),this.addProvider("minlength",e.stringLength),this.addProvider("equalto",e.compare),this.addProvider("range",e.range),this.addProvider("regex",e.regex),this.addProvider("creditcard",e.creditcard),this.addProvider("email",e.email),this.addProvider("url",e.url),this.addProvider("phone",e.phone),this.addProvider("remote",e.remote)},e.prototype.scanMessages=function(){for(var e=document.querySelectorAll("[data-valmsg-for]"),t=0;t<e.length;t++){var r=e[t],n=r.getAttribute("data-valmsg-for");this.messageFor[n]||(this.messageFor[n]=[]),this.messageFor[n].push(r)}},e.prototype.parseDirectives=function(e){for(var t={},r={},n="data-val-".length,a=0;a<e.length;a++){var i=e[a];if(0===i.name.indexOf("data-val-")){var o=i.name.substr(n);r[o]=i.value}}for(var o in r)!function(e){if(-1===e.indexOf("-")){for(var n=Object.keys(r).filter(function(t){return t!==e&&0===t.indexOf(e)}),a={error:r[e],params:{}},i=(e+"-").length,o=0;o<n.length;o++){var s=r[n[o]],u=n[o].substr(i);a.params[u]=s}t[e]=a}}(o);return t},e.prototype.guid4=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)})},e.prototype.getElementUID=function(e){var t=this.elementUIDs.filter(function(t){return t.node===e})[0];if(t)return t.uid;var r=this.guid4();return this.elementUIDs.push({node:e,uid:r}),this.elementByUID[r]=e,r},e.prototype.getFormValidationTask=function(e){var t=this.formInputs[e];if(!t||0===t.length)return null;for(var r=[],n=0;n<t.length;n++){var a=t[n];r.push(this.validators[a])}var i=r.map(function(e){return e()});return Promise.all(i).then(function(e){return e.every(function(e){return e})})},e.prototype.trackFormInput=function(e,t){var r=this,n=this.getElementUID(e);if(this.formInputs[n]||(this.formInputs[n]=[]),-1===this.formInputs[n].indexOf(t)&&this.formInputs[n].push(t),!this.elementEvents[n]){var a=function(t){var a=r.getFormValidationTask(n);a&&(t.preventDefault(),a.then(function(t){t&&e.submit()}).catch(function(e){console.log(e)}))};e.addEventListener("submit",a),e.addEventListener("reset",function(e){for(var t=r.formInputs[n],a=0,i=t;a<i.length;a++){var o=i[a],s=r.elementByUID[o];s.classList.remove("input-validation-error");var u=r.messageFor[s.name];if(u)for(var d=0;d<u.length;d++)u[d].innerHTML="";delete r.summary[o]}r.renderSummary()}),this.elementEvents[n]=a}},e.prototype.addInput=function(e){var t=this,r=this.getElementUID(e),n=this.parseDirectives(e.attributes),a=this.createValidator(e,n);if(this.validators[r]=a,this.trackFormInput(e.form,r),!this.elementEvents[r]){var i,o=function(e){var n=t.validators[r];clearTimeout(i),i=setTimeout(n,t.debounce)};"select"===e.tagName.toLowerCase()?e.addEventListener("change",o):e.addEventListener("input",o),this.elementEvents[r]=o}},e.prototype.scanInputs=function(){for(var e=document.querySelectorAll('[data-val="true"]'),t=0;t<e.length;t++){var r=e[t];this.addInput(r)}},e.prototype.createSummaryDOM=function(){if(!Object.keys(this.summary).length)return null;var e=document.createElement("ul");for(var t in this.summary){var r=document.createElement("li");r.innerHTML=this.summary[t],e.appendChild(r)}return e},e.prototype.renderSummary=function(){var e=document.querySelectorAll('[data-valmsg-summary="true"]');if(e.length){var t=JSON.stringify(this.summary,Object.keys(this.summary).sort());if(t!==this.renderedSummaryJSON){this.renderedSummaryJSON=t;for(var r=this.createSummaryDOM(),n=0;n<e.length;n++){var a=e[n];a.innerHTML="",r?(a.className="validation-summary-error",a.appendChild(r.cloneNode(!0))):a.className="validation-summary-valid"}}}},e.prototype.addError=function(e,t){var r=this.messageFor[e.name];if(r)for(var n=0;n<r.length;n++)r[n].innerHTML=t,r[n].className="field-validation-error";e.classList.remove("input-validation-valid"),e.classList.add("input-validation-error");var a=this.getElementUID(e);this.summary[a]=t,this.renderSummary()},e.prototype.removeError=function(e){var t=this.messageFor[e.name];if(t)for(var r=0;r<t.length;r++)t[r].innerHTML="",t[r].className="field-validation-valid";e.classList.remove("input-validation-error"),e.classList.add("input-validation-valid");var n=this.getElementUID(e);delete this.summary[n],this.renderSummary()},e.prototype.createValidator=function(e,t){var r=this;return function(){return n(r,void 0,void 0,function(){var r,n,i,o,s,u,d,f,l,c;return a(this,function(a){switch(a.label){case 0:r=[];for(n in t)r.push(n);i=0,a.label=1;case 1:return i<r.length?(o=r[i],s=t[o],(u=this.providers[o])?(d=u(e.value,e,s.params),f=!1,l=s.error,"boolean"!=typeof d?[3,2]:(f=d,[3,5])):(console.log("aspnet-validation provider not implemented: "+o),[3,6])):[3,7];case 2:return"string"!=typeof d?[3,3]:(f=!1,l=d,[3,5]);case 3:return[4,d];case 4:c=a.sent(),"boolean"==typeof c?f=c:(f=!1,l=c),a.label=5;case 5:if(!f)return this.addError(e,l),[2,!1];a.label=6;case 6:return i++,[3,1];case 7:return this.removeError(e),[2,!0]}})})}},e.prototype.bootstrap=function(){var e=this;this.addMvcProviders(),document.addEventListener("DOMContentLoaded",function(t){e.scanMessages(),e.scanInputs()})},e}()}])});
//# sourceMappingURL=aspnet-validation.min.js.map
{
"name": "aspnet-validation",
"version": "0.0.2",
"version": "0.0.3",
"description": "Enables ASP.NET Core MVC client-side validation, without JQuery!",
"main": "./dist/aspnet-validation.js",
"types": "./typings/index.d.ts",
"types": "./types/index.d.ts",
"repository": "https://github.com/ryanelian/aspnet-validation",

@@ -18,3 +18,3 @@ "bugs": {

"devDependencies": {
"ts-loader": "^3.0.2",
"ts-loader": "^3.0.3",
"typescript": "^2.5.3",

@@ -21,0 +21,0 @@ "webpack": "^3.8.1"

@@ -350,2 +350,7 @@ /**

/**
* A key-value collection of UID to Element for quick lookup.
*/
private elementByUID: { [uid: string]: Element } = {};
/**
* A key-value collection of input UIDs for a <form> UID.

@@ -433,9 +438,9 @@ */

let e = validationMessageElements[i];
let id = e.getAttribute('data-valmsg-for');
let name = e.getAttribute('data-valmsg-for');
if (!this.messageFor[id]) {
this.messageFor[id] = [];
if (!this.messageFor[name]) {
this.messageFor[name] = [];
}
this.messageFor[id].push(e);
this.messageFor[name].push(e);
}

@@ -519,2 +524,3 @@ }

});
this.elementByUID[uid] = node;
return uid;

@@ -580,2 +586,20 @@ }

form.addEventListener('submit', cb);
form.addEventListener('reset', e => {
let uids = this.formInputs[formUID];
for (let uid of uids) {
let input = this.elementByUID[uid] as HTMLInputElement;
input.classList.remove('input-validation-error');
let spans = this.messageFor[input.name];
if (spans) {
for (let i = 0; i < spans.length; i++) {
spans[i].innerHTML = '';
}
}
delete this.summary[uid];
}
this.renderSummary();
});
this.elementEvents[formUID] = cb;

@@ -686,3 +710,3 @@ }

addError(input: HTMLInputElement, message: string) {
let spans = this.messageFor[input.id];
let spans = this.messageFor[input.name];
if (spans) {

@@ -708,3 +732,3 @@ for (let i = 0; i < spans.length; i++) {

removeError(input: HTMLInputElement) {
let spans = this.messageFor[input.id];
let spans = this.messageFor[input.name];
if (spans) {

@@ -711,0 +735,0 @@ for (let i = 0; i < spans.length; i++) {

let tsconfigOverride = {
declaration: true,
declarationDir: 'typings',
declarationDir: 'types',
sourceMap: false,

@@ -5,0 +5,0 @@ noEmit: false

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc