@oeos-components/utils 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +11 -4
- package/dist/index.d.cts +10 -4
- package/dist/index.d.mts +10 -4
- package/dist/index.d.ts +10 -4
- package/dist/index.mjs +11 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -610,19 +610,26 @@ function processWidth(initValue, isBase = false) {
|
|
|
610
610
|
}
|
|
611
611
|
return { width: res };
|
|
612
612
|
}
|
|
613
|
-
function toFixed(value,
|
|
613
|
+
function toFixed(value, options = {}) {
|
|
614
|
+
if (typeof options === "number") {
|
|
615
|
+
options = { digit: options };
|
|
616
|
+
}
|
|
617
|
+
let { digit = 2, prefix = "", suffix = "", unit = true } = options;
|
|
614
618
|
let matches = ("" + value).match(/^([\d,]+)(\.?)(\d+)?(\D+)?$/);
|
|
615
619
|
if (!matches) {
|
|
616
620
|
return value;
|
|
617
621
|
}
|
|
618
622
|
let numericString = matches[1].replace(/\D/g, "");
|
|
619
623
|
let decimalString = matches[3] ? `.${matches[3]}` : "";
|
|
620
|
-
let
|
|
624
|
+
let finalUnit = matches[4] || "";
|
|
621
625
|
let res = numericString;
|
|
622
626
|
if (isStringNumber(numericString) || isNumber(numericString)) {
|
|
623
|
-
res = Number(numericString + decimalString).toFixed(
|
|
627
|
+
res = Number(numericString + decimalString).toFixed(digit);
|
|
628
|
+
}
|
|
629
|
+
if (!unit) {
|
|
630
|
+
finalUnit = "";
|
|
624
631
|
}
|
|
625
|
-
return `${res}${
|
|
632
|
+
return `${prefix}${res}${finalUnit}${suffix}`;
|
|
626
633
|
}
|
|
627
634
|
function formatBytes(bytes, { toFixed: toFixed2 = 2, thousands = true } = {}) {
|
|
628
635
|
if (isStringNumber(bytes) || isNumber(bytes)) {
|
package/dist/index.d.cts
CHANGED
|
@@ -241,11 +241,17 @@ declare function processWidth(initValue: any, isBase?: boolean): any;
|
|
|
241
241
|
/**
|
|
242
242
|
* 增加小数点
|
|
243
243
|
* toFixed(22) -> '22.00'
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
244
|
+
* toFixed('22') -> '22.00'
|
|
245
|
+
* toFixed('22', 4) -> '22.0000'
|
|
246
|
+
* toFixed('22', 2) -> 22
|
|
247
|
+
* toFixed('22 TB', {prefix: '$', suffix: '%', unit: false}) -> $22.00%
|
|
247
248
|
*/
|
|
248
|
-
declare function toFixed(value: any,
|
|
249
|
+
declare function toFixed(value: any, options?: {
|
|
250
|
+
digit?: number;
|
|
251
|
+
prefix?: string;
|
|
252
|
+
suffix?: string;
|
|
253
|
+
unit?: boolean;
|
|
254
|
+
} | number): any;
|
|
249
255
|
/**
|
|
250
256
|
* 只有对正整数或者字符串正整数才进行单位的转换,
|
|
251
257
|
* 否则返回原始数据
|
package/dist/index.d.mts
CHANGED
|
@@ -241,11 +241,17 @@ declare function processWidth(initValue: any, isBase?: boolean): any;
|
|
|
241
241
|
/**
|
|
242
242
|
* 增加小数点
|
|
243
243
|
* toFixed(22) -> '22.00'
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
244
|
+
* toFixed('22') -> '22.00'
|
|
245
|
+
* toFixed('22', 4) -> '22.0000'
|
|
246
|
+
* toFixed('22', 2) -> 22
|
|
247
|
+
* toFixed('22 TB', {prefix: '$', suffix: '%', unit: false}) -> $22.00%
|
|
247
248
|
*/
|
|
248
|
-
declare function toFixed(value: any,
|
|
249
|
+
declare function toFixed(value: any, options?: {
|
|
250
|
+
digit?: number;
|
|
251
|
+
prefix?: string;
|
|
252
|
+
suffix?: string;
|
|
253
|
+
unit?: boolean;
|
|
254
|
+
} | number): any;
|
|
249
255
|
/**
|
|
250
256
|
* 只有对正整数或者字符串正整数才进行单位的转换,
|
|
251
257
|
* 否则返回原始数据
|
package/dist/index.d.ts
CHANGED
|
@@ -241,11 +241,17 @@ declare function processWidth(initValue: any, isBase?: boolean): any;
|
|
|
241
241
|
/**
|
|
242
242
|
* 增加小数点
|
|
243
243
|
* toFixed(22) -> '22.00'
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
244
|
+
* toFixed('22') -> '22.00'
|
|
245
|
+
* toFixed('22', 4) -> '22.0000'
|
|
246
|
+
* toFixed('22', 2) -> 22
|
|
247
|
+
* toFixed('22 TB', {prefix: '$', suffix: '%', unit: false}) -> $22.00%
|
|
247
248
|
*/
|
|
248
|
-
declare function toFixed(value: any,
|
|
249
|
+
declare function toFixed(value: any, options?: {
|
|
250
|
+
digit?: number;
|
|
251
|
+
prefix?: string;
|
|
252
|
+
suffix?: string;
|
|
253
|
+
unit?: boolean;
|
|
254
|
+
} | number): any;
|
|
249
255
|
/**
|
|
250
256
|
* 只有对正整数或者字符串正整数才进行单位的转换,
|
|
251
257
|
* 否则返回原始数据
|
package/dist/index.mjs
CHANGED
|
@@ -607,19 +607,26 @@ function processWidth(initValue, isBase = false) {
|
|
|
607
607
|
}
|
|
608
608
|
return { width: res };
|
|
609
609
|
}
|
|
610
|
-
function toFixed(value,
|
|
610
|
+
function toFixed(value, options = {}) {
|
|
611
|
+
if (typeof options === "number") {
|
|
612
|
+
options = { digit: options };
|
|
613
|
+
}
|
|
614
|
+
let { digit = 2, prefix = "", suffix = "", unit = true } = options;
|
|
611
615
|
let matches = ("" + value).match(/^([\d,]+)(\.?)(\d+)?(\D+)?$/);
|
|
612
616
|
if (!matches) {
|
|
613
617
|
return value;
|
|
614
618
|
}
|
|
615
619
|
let numericString = matches[1].replace(/\D/g, "");
|
|
616
620
|
let decimalString = matches[3] ? `.${matches[3]}` : "";
|
|
617
|
-
let
|
|
621
|
+
let finalUnit = matches[4] || "";
|
|
618
622
|
let res = numericString;
|
|
619
623
|
if (isStringNumber(numericString) || isNumber(numericString)) {
|
|
620
|
-
res = Number(numericString + decimalString).toFixed(
|
|
624
|
+
res = Number(numericString + decimalString).toFixed(digit);
|
|
625
|
+
}
|
|
626
|
+
if (!unit) {
|
|
627
|
+
finalUnit = "";
|
|
621
628
|
}
|
|
622
|
-
return `${res}${
|
|
629
|
+
return `${prefix}${res}${finalUnit}${suffix}`;
|
|
623
630
|
}
|
|
624
631
|
function formatBytes(bytes, { toFixed: toFixed2 = 2, thousands = true } = {}) {
|
|
625
632
|
if (isStringNumber(bytes) || isNumber(bytes)) {
|