thuan-client
Advanced tools
Comparing version 2.0.1 to 2.0.2
111
index.js
@@ -1,7 +0,104 @@ | ||
var fs = require('fs'); | ||
var list = fs.readdirSync(__dirname+'/dist'); | ||
var name = ''; | ||
for(var i=0, n=list.length; i<n; i++){ | ||
name = list[i].replace('.js', ''); | ||
module.exports[name] = require(__dirname+'/dist/'+name); | ||
} | ||
function empty (s) { | ||
return !(s||s.length||Object.keys(s).length); | ||
}; | ||
module.exports.empty = empty; | ||
module.exports.confirm = function (o, cb) { | ||
var div = document.getElementById('modal'); | ||
var html = '<div id="modal_first"></div>'; | ||
html += '<div id="modal_last">'; | ||
html += '<form action="javascript:void(0);" method="GET">'; | ||
if(o.header) html += '<header>'+o.header+'</header>'; | ||
if(o.content) html += '<section>'+o.content+'</section>'; | ||
html += '<footer class="clearfix">'; | ||
html += '<span></span>'; | ||
if(o.btn) { | ||
for(var i in o.btn){ | ||
if('string'==typeof o.btn[i]) html += '<button type="submit" name="modal_btn" value="'+i+'" class="btn btn-default">' + o.btn[i] + '</button>'; | ||
else html += '<button type="submit" name="modal_btn" value="'+i+'" class="btn '+(o.btn[i].class||'')+'">' + o.btn[i].text + '</button>'; | ||
} | ||
}; | ||
html += '</footer></form></div>'; | ||
div.innerHTML = html; html=false; | ||
var modal_last = document.getElementById('modal_last'); | ||
modal_last.style.left = (window.innerWidth-modal_last.clientWidth-20)/2 + 'px'; | ||
div.onclick = function (e) { | ||
if(e.target.name=='modal_btn'){ | ||
if(o.remove===false) cb(e.target.value, div); | ||
else{cb(e.target.value);this.innerHTML=''} | ||
} | ||
}; | ||
return false; | ||
}; | ||
module.exports.cookie = { | ||
set: function (o) { | ||
for(var i in o){ document.cookie = i + '=' + o[i] + ';' + this.str }; | ||
return true; | ||
}, | ||
init: function (o) { | ||
if(o){ | ||
this.str = ''; | ||
for(var i in o){ this.str += i+'='+o[i]+';' }; | ||
}else{ | ||
var it = document.cookie, array = []; | ||
if(!it) return false; | ||
it = it.split('; '); | ||
for(var i=0, n=it.length; i<n; i++){ | ||
array = it[i].split('='); | ||
this[array[0]] = array[1]; | ||
}; | ||
it = null; array = []; | ||
}; | ||
return this; | ||
}, | ||
remove: function (name) { | ||
if(name) document.cookie = name+'=;'+this.str; | ||
return true; | ||
} | ||
}; | ||
module.exports.is = { | ||
name: function (a) { | ||
if(empty(a)) return false; | ||
var n = a.trim(), s; | ||
if(n.length<2||n.length>71) return false; | ||
if(/[~`!@#\$%\^&\*\(\)_\+\-=\{\}\[\]\\:\";\'<>\?\,\.\/\|\d]+/g.test(n)) return false; | ||
s = n.match(/\s/g); | ||
if(s!=null){if(s.length>1) return false} | ||
s = n.match(/[QWERTYUIOPASDFGHJKLZXCVBNMƯỨỮỬỰAĂÂÁÀẢÃẠĂẮẰẶẴẲẤẦẨẪẬĐÊẾỀỂỄỆÍÌỈĨỊÝỲỶỸỴ]/g); | ||
if(s!=null){if(s.length>2) return false} | ||
return true; | ||
}, | ||
phone: function (a) { | ||
if(empty(a)) return false; | ||
return (/^[0-9]{9,15}$/g.test(a)&&a[0]==0); | ||
}, | ||
code: function (a) { | ||
if(empty(a)) return false; | ||
return /^[0-9]{10}$/g.test(a); | ||
}, | ||
pass: function (a) { | ||
if(empty(a)) return false; | ||
return /(.){8,100}/g.test(a); | ||
}, | ||
email: function (a) { | ||
if(empty(a)) return false; | ||
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/g; | ||
return filter.test(a); | ||
}, | ||
username: function (a) { | ||
if(empty(a)) return false; | ||
return /^[a-zA-Z0-9\.]{1,50}$/gi.test(a); | ||
}, | ||
url: function (a) { | ||
if(empty(a)) return false; | ||
var urlRegex = /(http|https|ftp)\:\/\/([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(\/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*/g; | ||
var url = urlRegex.exec(a); | ||
if (url && url.length) { return url[0]; } else { return false; } | ||
}, | ||
image: function (a) { | ||
if(empty(a)) return false; | ||
var p = a.split('/'), ext = ['jpeg', 'png', 'gif', 'bmp', 'jpg']; | ||
return (p[0]=='image' && ext.indexOf(p[1]) > -1) ? p[1] : false; | ||
} | ||
}; |
@@ -5,4 +5,4 @@ { | ||
"description": "Code use client for my project", | ||
"version": "2.0.1", | ||
"main": "index.js", | ||
"version": "2.0.2", | ||
"main": "./dist/index.js", | ||
"scripts": { | ||
@@ -9,0 +9,0 @@ "test": "echo \"Error: no test specified\" && exit 1" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
12933
203
2
1
0
8