Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | 3x 3x 3x 4x 1x 1x 8x 6x 6x 6x 42x 8x 3x 3x 3x 3x 3x 21x 3x 1x 1x 1x 1x 6x 1x 2x 2x 2x 1x 1x 1x 1x 6x 5x 5x 3x 3x 2x 2x 4x 4x 4x 3x 3x 3x 5x 5x 4x 4x 3x 1x 5x 5x 3x 2x 4x 4x 2x 2x 4x 5x | /* eslint-disable no-prototype-builtins, guard-for-in */
import isDeepEqual from 'ray-visutil/lib/deepEqual';
import tools$2 from 'ray-visutil/lib/tools';
const encodeLen = 8;
const defaultRE = /\{((?:.|\n)+?)\}/g;
const tools = {
...tools$2,
/**
* 判断两个值是否相同 (深度比较)
* @param {*} valA
* @param {*} valB
* @returns {Boolean}
*/
isEqual(valA, valB) {
return isDeepEqual(valA, valB);
},
/**
* 检测是否可用 dom
*/
canUseDom: typeof window !== 'undefined',
/**
* 混淆url 只截取部分
* @param {String} url
*/
uglifyUrl(url = '') {
url = url.replace(/\/|\\|(.(png|jpg|gif|mtl|obj))/gi, '');
return url.substr(url.length - 6);
},
/** 判断移动设备 */
isMobileDevice() {
if (!window.navigator) {
return true;
}
const ua = navigator.userAgent.toLowerCase();
return ua.indexOf('mobile') !== -1 || ua.indexOf('android') !== -1;
},
/**
* 解码URL中的特殊字符
* 将 encodeUrl 中转换后的字符,替换成原始字符
*
* @param {string} url
* @return {string} new url
* @example
* encodeUrl('http:%2F%2Flocalhost:3000%2Flogin?user%3D123%26pwd%3D123');
* // http://localhost:3000/login?user=123&pwd=123
*/
decodeUrl(val){
if (val){
const regexs = [/(%2B)/gi, /(%20)/g, /(%2F)/gi, /(%3F)/gi, /(%23)/g, /(%26)/g, /(%3D)/gi];
const regexValues = ['+', ' ', '/', '?', '#', '&', '='];
for (let i = 0; i < encodeLen - 1; i++) {
val = val.replace(regexs[i], regexValues[i]);
}
}
return val;
},
/**
* 转码URL中的特殊字符
*
* 特殊字符说明
* 1. '+' URL 中+号表示空格 %2B
* 2. '空格' URL中的空格可以用+号或者编码 %20
* 3. '/' 分隔目录和子目录 %2F
* 4. '?' 分隔实际的 URL 和参数 %3F
* 5. '%' 指定特殊字符 %25
* 6. '#' 表示书签 %23
* 7. '&' URL 中指定的参数间的分隔符 %26
* 8. '=' URL 中指定参数的值 %3D
*
* @param {string} url
* @return {string} new url
* @example
* encodeUrl('http://localhost:3000/login?user=123&pwd=123');
* // http:%2F%2Flocalhost:3000%2Flogin?user%3D123%26pwd%3D123
*/
encodeUrl(val) {
const regexs = [/[+]/g, /[ ]/g, /[\/]/g, /[\?]/g, /[#]/g, /[&]/g, /[=]/g];
const regexValues = ['%2B', '%20', '%2F', '%3F', '%23', '%26', '%3D'];
// 防止多次encodeUrl
val = this.decodeUrl(val);
// 先替换其中的 % ,
val = val.replace(/[%]/g, '%25');
for (let i = 0; i < encodeLen - 1; i++) {
val = val.replace(regexs[i], regexValues[i]);
}
return val;
},
/**
* 转码URL中的特殊字符 【不对 / 进行转码】
*
* 特殊字符说明
* 1. '+' URL 中+号表示空格 %2B
* 2. '空格' URL中的空格可以用+号或者编码 %20
* 3. '?' 分隔实际的 URL 和参数 %3F
* 4. '%' 指定特殊字符 %25
* 5. '#' 表示书签 %23
* 6. '&' URL 中指定的参数间的分隔符 %26
* 7. '=' URL 中指定参数的值 %3D
*
* @param {string} url
* @return {string} new url
* @example
* encodeUrl('http://localhost:3000/login?user=123&pwd=123');
* // http://localhost:3000/login?user%3D123%26pwd%3D123
*/
encodeUrl2(val) {
const regexs = [/[+]/g, /[ ]/g, /[\?]/g, /[#]/g, /[&]/g, /[=]/g];
const regexValues = ['%2B', '%20', '%3F', '%23', '%26', '%3D'];
// 先替换其中的 % ,
val = val.replace(/[%]/g, '%25');
for (let i = 0; i < encodeLen - 2; i++) {
val = val.replace(regexs[i], regexValues[i]);
}
return val;
},
/**
* 转码url 中的 name,如果 name 中包含 +、空格、?、%、#、&、= 特殊符号,则需要进行转码,否则将会被解析为 url 内容
*
* @param {string} url
* @return {string} new url
* @example
* encodeUrl('http://localhost:3000/a/b/cc#rr.jpg'); // http://localhost:3000/a/b/cc%23rr.jpg
*/
encodeName(url) {
Eif (url){
const index = url.lastIndexOf( '/' );
if (index > -1){
const left = url.substr( 0, index + 1 );
const right = url.substr(index + 1);
return left + this.encodeUrl(right);
}
}
return url;
},
/** like Vector3 */
isLikeVec3(vec3) {
if (vec3) {
Iif (vec3.isVector3) {
return true;
} else if (this.isArray(vec3)) {
return vec3.length === 3 && vec3.every(item => tools.isNumber(item));
} else if (this.isObject(vec3)) {
return 'x' in vec3 || 'y' in vec3 || 'z' in vec3;
}
}
return false;
},
/**
* 将目标Object 转化为两部分,一部分由 fields 中的所有值组成的键,另一部分不包含
*
* 返回值为 { include, exclude }, include 为包含 fields 中的键组成的 object
* @param {Object} target
* @param {String|String[]} fields 需要进行分类的属性或属性集合
* @return {Object} { include, exclude }
*/
splitObject(target, fields) {
/** 由 fields 中的值组成的对象 */
const include = {};
/** 不包括 fields 中的值组成的对象 */
const exclude = {};
if (target && fields) {
fields = tools.isArray(fields) ? fields : [fields];
const shallowCopy = {
...target
};
for (let i = 0; i < fields.length; i++) {
const key = fields[i];
if (key in shallowCopy) {
include[key] = shallowCopy[key];
// 删除掉 shallowCopy 中的该属性
delete shallowCopy[key];
}
}
return {
include,
exclude: shallowCopy
};
}
return {
include,
exclude
};
},
getExtension(str = '') {
const strings = str.split('.');
if (strings.length > 1) {
return strings.pop();
}
return '';
},
/**
* 解析数据
* @param {string} text
* @param {object} dataObj
* @param {string|RegExp} regexps 可选
* @returns {string} returns a new str
* @example
* parseText('a/{b}/{c}/d',{a: 1, b:2}); // 'a/1/2/d'
* parseText('a/b?name={name}&pwd={pwd}',{name: 'ilex', pwd:122}); // 'a/b?name=ilex&pwd=123'
*/
parseText(text, dataObj, regexps){
regexps || (regexps = defaultRE);
if (!(text && text.replace)) {
return text;
} else {
return text.replace(regexps, (match, key) => {
return !tools.isUndefined(dataObj[key]) ? dataObj[key] : match;
});
}
},
/**
* 简单 节流 函数
* @param {Function} fn
* @param {Number} wait
* @returns
*/
throttling(fn, wait){
let timer;
let context;
let args;
function run() {
timer = setTimeout(() => {
fn.apply(context, args);
clearTimeout(timer);
timer = null;
}, wait);
}
return function() {
context = this;
args = arguments;
if (!timer) {
run();
}
};
},
/**
* @private
* 判断浮点数是否相同
* @param {Number} v1 第一个浮点数
* @param {Number} v2 第二个浮点数
* @param {Number} epsilon 误差范围, 默认 0.001
*/
isFloatEquals(v1, v2, epsilon = 0.001) {
return Math.abs(v1 - v2) < epsilon;
}
};
export default tools;
|