Webpack搭建项目:
验证帐号是否合法:
验证帐号是否合法:/^[a-zA-z]\w{3,15}$/ 手机号码:/^1\d{10}$/ 电话号码:/^0\d{2,3}-?\d{7,8}$/ 邮箱:/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/ 密码的正则表达式 6-16位数字和字母的组合 ^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$时间格式 eg:20200707213455
function formatterDateTime() { var date=new Date() var month=date.getMonth() + 1 var datetime = date.getFullYear() + ""// "年" + (month >= 10 ? month : "0"+ month) + ""// "月" + (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + "" + (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + "" + (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) + "" + (date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()); return datetime; }wx小程序POST请求封装
function Post(url, params) { // var token = wx.getStorageSync('token') ? wx.getStorageSync('token') : []; return new Promise(function (resolve, reject) { wx.request({ url: 'https://route.showapi.com' + url, data: { "showapi_timestamp": formatterDateTime(), "showapi_appid": '206877', "showapi_sign": '8fb905d853284f7bb88e383e4ba94197', }, dataType: 'json', method: 'post', header: { 'content-Type': 'application/x-www-form-urlencoded', // 'token': wx.getStorageSync('token') }, success: res => { resolve(res.data); }, fail: res => { reject(res.data) } }) }); }console自定义封装 前面带时间
['log', 'info', 'warn', 'error'].forEach(function(method) { console[method] = console[method].bind( console, new Date().toISOString() ); }); console.log("出错了!");判断变量是否为对象的函数
function isObject(value) { return value === Object(value); } isObject([]) // true isObject(true)封装判断所有的数据类型
var type = function (o){ var s = Object.prototype.toString.call(o); return s.match(/\[object (.*?)\]/)[1].toLowerCase(); }; type({}); // "object" type([]); // "array" type(5); // "number" type(null); // "null" type(); // "undefined" type(/abcd/); // "regex" type(new Date()); // "date"专门判断某种类型数据的
var type = function (o){ var s = Object.prototype.toString.call(o); return s.match(/\[object (.*?)\]/)[1].toLowerCase(); }; ['Null', 'Undefined', 'Object', 'Array', 'String', 'Number', 'Boolean', 'Function', 'RegExp' ].forEach(function (t) { type['is' + t] = function (o) { return type(o) === t.toLowerCase(); }; }); type.isObject({}) // true type.isNumber(NaN) // true type.isRegExp(/abc/) // true