前端常用链接地址、常用逻辑代码

1.掘金:

Webpack搭建项目:

1.正则表达式:

验证帐号是否合法:

验证帐号是否合法:/^[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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值