import React from 'react' import moment from 'moment' // import regex_parse from './parseCommon.js'; exports.formatTime = (timestamp) => { return moment.unix(timestamp).format("YYYY-MM-DD HH:mm:ss") } // 获取 YAPI LOGO 的 SVG // 参数 length 为 svg 的直径。 exports.logoSVG = (length) => ( Icon Created with Sketch. ); // 防抖函数,减少高频触发的函数执行的频率 // 请在 constructor 里使用: // import { debounce } from '$/common'; // this.func = debounce(this.func, 400); exports.debounce = (func, wait) => { let timeout; return function () { clearTimeout(timeout); timeout = setTimeout(func, wait); }; }; // 从 Javascript 对象中选取随机属性 exports.pickRandomProperty = (obj) => { let result; let count = 0; for (let prop in obj) if (Math.random() < 1 / ++count) result = prop; return result; } exports.getImgPath = (path, type) => { let rate = window.devicePixelRatio >= 2 ? 2 : 1; return `${path}@${rate}x.${type}`; } function trim(str) { if (!str) { return str; } str = str + ''; return str.replace(/(^\s*)|(\s*$)/g, ''); } exports.trim = trim; exports.handlePath = (path) => { path = trim(path); if (!path) return path; if (path === '/') return ''; path = path[0] !== '/' ? '/' + path : path; path = path[path.length - 1] === '/' ? path.substr(0, path.length - 1) : path; return path; }