update
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
"module": "./dist/timi-web.mjs",
|
||||
"style": "./dist/timi-web.css",
|
||||
"private": false,
|
||||
"version": "0.0.4",
|
||||
"version": "0.0.10",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { TemplateBizType } from "../types";
|
||||
import Toolkit from "../utils/Toolkit";
|
||||
import { axios } from "./BaseAPI";
|
||||
import TextFormat from "../utils/TextFormat";
|
||||
import Text from "../utils/Text";
|
||||
|
||||
const getCaptchaAPI = () => axios.defaults.baseURL + "/captcha";
|
||||
|
||||
@@ -12,7 +12,7 @@ async function getTemplate(bizType: TemplateBizType, code: string): Promise<stri
|
||||
}
|
||||
|
||||
async function getSetting(key: string, args?: { [key: string]: any }): Promise<string> {
|
||||
return axios.get(`/setting/${key}?${TextFormat.urlArgs(args)}`);
|
||||
return axios.get(`/setting/${key}?${Text.urlArgs(args)}`);
|
||||
}
|
||||
|
||||
async function listSetting(keyMap: Map<string, object | undefined>): Promise<Map<string, string>> {
|
||||
|
||||
@@ -71,10 +71,10 @@ export enum ImageType {
|
||||
|
||||
export type KeyValue<V, K = string> = {
|
||||
key: K;
|
||||
value: V;
|
||||
value?: V;
|
||||
}
|
||||
|
||||
export type LabelValue<L, V = string> = {
|
||||
label: L;
|
||||
value: V;
|
||||
value?: V;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import Text from "./Text";
|
||||
|
||||
export enum Unit {
|
||||
|
||||
/** B */
|
||||
@@ -60,7 +62,10 @@ export default class IOSize {
|
||||
* @param stopUnit 停止单位
|
||||
* @return
|
||||
*/
|
||||
public static format(size: number, fixed = 2, stopUnit?: Unit): string {
|
||||
public static format(size?: number, fixed = 2, stopUnit?: Unit): string {
|
||||
if (!size) {
|
||||
return "";
|
||||
}
|
||||
const units = Object.keys(Unit);
|
||||
if (0 < size) {
|
||||
for (let i = 0; i < units.length; i++, size /= 1024) {
|
||||
@@ -93,7 +98,7 @@ export default class IOSize {
|
||||
* @throws Error 格式无效
|
||||
*/
|
||||
public static parse(sizeStr: string): number {
|
||||
if (!sizeStr || sizeStr.trim() === "") {
|
||||
if (sizeStr.trim() === "") {
|
||||
throw new Error("not found sizeStr");
|
||||
}
|
||||
// 正则匹配:可选符号 + 数字(含小数点)+ 可选空格 + 单位
|
||||
@@ -160,13 +165,23 @@ export default class IOSize {
|
||||
/**
|
||||
* 转换值到字节量
|
||||
*
|
||||
* @param value 值
|
||||
* @param val 值
|
||||
* @param unit 单位
|
||||
* @return 字节量
|
||||
*/
|
||||
private static toBytes(value: number, unit: Unit): number {
|
||||
private static toBytes(val: number | undefined, unit: Unit): number {
|
||||
if (!val) {
|
||||
return 0;
|
||||
}
|
||||
const units = Object.values(Unit);
|
||||
const ordinal = units.indexOf(unit);
|
||||
return Math.round(value * Math.pow(1024, ordinal));
|
||||
return Math.round(val * Math.pow(1024, ordinal));
|
||||
}
|
||||
|
||||
public static speed(val?: number) {
|
||||
if (!val) {
|
||||
return "";
|
||||
}
|
||||
return Text.unit(IOSize.format(val, 2), " / s");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import IOSize from "./IOSize";
|
||||
|
||||
export default class TextFormat {
|
||||
export default class Text {
|
||||
|
||||
public static keyValue(obj: object, assign: string, split: string): string {
|
||||
let result = "";
|
||||
@@ -40,15 +40,18 @@ export default class TextFormat {
|
||||
if (Number.isNaN(val)) {
|
||||
return "";
|
||||
}
|
||||
return val.toFixed(fixed) + unit;
|
||||
val = val.toFixed(fixed);
|
||||
}
|
||||
return val.trim() + unit;
|
||||
return `${val.trim()} ${unit}`;
|
||||
};
|
||||
|
||||
public static speed(val?: number) {
|
||||
if (!val) {
|
||||
return "";
|
||||
public static display(val: string | number | null | undefined) {
|
||||
if (typeof val === "string") {
|
||||
return val.trim() || "";
|
||||
}
|
||||
return this.unit(IOSize.format(val, 2), " / s");
|
||||
if (typeof val === "number" && Number.isFinite(val)) {
|
||||
return val.toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ export { default as Prismjs } from "./Prismjs";
|
||||
export { default as Resizer } from "./Resizer";
|
||||
export { default as Scroller } from "./Scroller";
|
||||
export { default as Storage } from "./Storage";
|
||||
export { default as Format } from "./TextFormat";
|
||||
export { default as Text } from "./Text";
|
||||
export { default as Time } from "./Time";
|
||||
export { default as Toolkit } from "./Toolkit";
|
||||
export { default as IconMapper } from "./IconMapper";
|
||||
|
||||
Reference in New Issue
Block a user