🔨 优化主机逻辑.
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import { isEmptyStr } from './index';
|
||||
|
||||
/**
|
||||
* 获取 base64 实际数据
|
||||
*/
|
||||
@@ -56,7 +54,7 @@ export function getPathAnalysis(path: string, paths: PathAnalysis[] = []): PathA
|
||||
return paths;
|
||||
}
|
||||
const name = path.substring(lastSeparatorIndex, path.length);
|
||||
if (!isEmptyStr(name) && name !== '/') {
|
||||
if (name && name !== '/') {
|
||||
paths.unshift({
|
||||
name: name.substring(1, name.length),
|
||||
path: path
|
||||
|
||||
@@ -51,13 +51,6 @@ export function dataColor(str: string, colors: string[], defaultColor = ''): str
|
||||
return colors[total % colors.length];
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断值是否非空
|
||||
*/
|
||||
export function isEmptyStr(val: any) {
|
||||
return typeof (val) === 'undefined' || val == null || val === '';
|
||||
}
|
||||
|
||||
export const YMD_HMS = 'yyyy-MM-dd HH:mm:ss';
|
||||
|
||||
/**
|
||||
@@ -144,54 +137,6 @@ export function toAnonymousNumber(value: string | undefined): number {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化数字为 ,分割
|
||||
*/
|
||||
export function formatNumber(value: number = 0) {
|
||||
const list = (value + '').split('.');
|
||||
const prefix = list[0].charAt(0) === '-' ? '-' : '';
|
||||
let num = prefix ? list[0].slice(1) : list[0];
|
||||
let result = '';
|
||||
while (num.length > 3) {
|
||||
result = `,${num.slice(-3)}${result}`;
|
||||
num = num.slice(0, num.length - 3);
|
||||
}
|
||||
if (num) {
|
||||
result = num + result;
|
||||
}
|
||||
return `${prefix}${result}${list[1] ? `.${list[1]}` : ''}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为数字
|
||||
*/
|
||||
export function isNumber(value: any, decimal = true, negative = true) {
|
||||
let reg;
|
||||
if (decimal && negative) {
|
||||
reg = /^-?[0-9]*(\.[0-9]*)?$/;
|
||||
} else if (!decimal && negative) {
|
||||
reg = /^-?[0-9]*$/;
|
||||
} else if (decimal && !negative) {
|
||||
reg = /^[0-9]*(\.[0-9]*)?$/;
|
||||
} else if (!decimal && !negative) {
|
||||
reg = /^[0-9]*$/;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return (!isNaN(value) && reg.test(value)) || value === '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换数字
|
||||
*/
|
||||
export function replaceNumber(value: string) {
|
||||
const s = value.charAt(value.length - 1);
|
||||
if (s === '.' || s === '-') {
|
||||
return s.substring(0, value.length - 1);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重设对象
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user