• 前端-常用函数记录-持续更新


    // 获取当前路径下?问号后边的值
    GetQueryString = function (name) { const reg = new RegExp (`(^|&)${name}=([^&]*)(&|$)`); const href = window.location.href; const index = href.indexOf('?'); const r = href.substr(index + 1).match (reg); if (r != null) return unescape (r[2]); return null; };
    调用示例:
      获取
    “https://www.google.com/search?q=baidu” 这个路径 “q” 后面的 “baibu
      templateId('q');
      "baidu"
    // 全局唯一ID函数 uuid
    GetUuid = function () {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace (/[xy]/g, c => { let r = (Math.random () * 16) | 0; let v = c == 'x' ? r : (r & 0x3) | 0x8; return v.toString (16); }); }
    调用示例:
      GetUUid();
      "327aaf38-c195-4000-b5c4-d36bf9b2894e"
    // 对象数组去重
    arrayUnique = function (songs) { const result = {}; const finalResult = []; for (let i = songs.length - 1; i >= 0; i--) { result[songs[i].name] = songs[i]; } Object.keys(result).map((item) => finalResult.push(result[item])); return finalResult; }

    // 拉取某个文件夹下面的所有文件
    loadAllFile = function ('filePath','fileExp') {     const filesMD = require.context(filePath, true,fileExp); return filesMD.keys(); }
  • 相关阅读:
    C#中virtual 方法和abstract方法的区别
    解决zabbix的cannot allocate shared memory of size错误
    批量改名的shell脚本
    /bin/bash和/bin/sh的区别
    搭建redmine全攻略——与apache整合(CentOS 5.8 64位)
    内网监控利器——Nagios
    Maven
    TypeScript
    ShardingSphere
    Spring框架源码分析
  • 原文地址:https://www.cnblogs.com/ChineseLiao/p/12979806.html
Copyright © 2020-2023  润新知