@hairy/utils 0.7.1 → 0.7.2
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 +9 -3
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +7 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -74,7 +74,8 @@ __export(src_exports, {
|
|
|
74
74
|
unum: () => unum,
|
|
75
75
|
weexPlatform: () => weexPlatform,
|
|
76
76
|
whenever: () => whenever,
|
|
77
|
-
zerofill: () => zerofill
|
|
77
|
+
zerofill: () => zerofill,
|
|
78
|
+
zeromove: () => zeromove
|
|
78
79
|
});
|
|
79
80
|
module.exports = __toCommonJS(src_exports);
|
|
80
81
|
|
|
@@ -1731,6 +1732,9 @@ function zerofill(value, n = 2, type = "positive") {
|
|
|
1731
1732
|
return zero + value;
|
|
1732
1733
|
return "";
|
|
1733
1734
|
}
|
|
1735
|
+
function zeromove(value) {
|
|
1736
|
+
return value.toString().replace(/\.?0+$/, "");
|
|
1737
|
+
}
|
|
1734
1738
|
function numerfix(value) {
|
|
1735
1739
|
const _isNaN = Number.isNaN(Number(value)) || value.toString() === "NaN";
|
|
1736
1740
|
if (_isNaN)
|
|
@@ -1772,7 +1776,7 @@ function formatNumeric(value = "0", options) {
|
|
|
1772
1776
|
decimals = 2
|
|
1773
1777
|
} = options || {};
|
|
1774
1778
|
const config = parseNumeric(value, delimiters || []);
|
|
1775
|
-
|
|
1779
|
+
let number = unum(value).div(config.v).toFormat(decimals, rounding, {
|
|
1776
1780
|
decimalSeparator: ".",
|
|
1777
1781
|
groupSeparator: ",",
|
|
1778
1782
|
groupSize: 3,
|
|
@@ -1781,6 +1785,7 @@ function formatNumeric(value = "0", options) {
|
|
|
1781
1785
|
fractionGroupSize: 0,
|
|
1782
1786
|
...format
|
|
1783
1787
|
});
|
|
1788
|
+
number = (options == null ? void 0 : options.zeromove) ? zeromove(number) : number;
|
|
1784
1789
|
return `${number}${config.n}`;
|
|
1785
1790
|
}
|
|
1786
1791
|
|
|
@@ -1844,5 +1849,6 @@ function cover(value, mode, symbol = "*") {
|
|
|
1844
1849
|
unum,
|
|
1845
1850
|
weexPlatform,
|
|
1846
1851
|
whenever,
|
|
1847
|
-
zerofill
|
|
1852
|
+
zerofill,
|
|
1853
|
+
zeromove
|
|
1848
1854
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -162,6 +162,7 @@ interface FormatNumericOptions {
|
|
|
162
162
|
delimiters?: Delimiter[] | false;
|
|
163
163
|
rounding?: Bignumber.RoundingMode;
|
|
164
164
|
decimals?: number;
|
|
165
|
+
zeromove?: boolean;
|
|
165
166
|
format?: Bignumber.Format;
|
|
166
167
|
}
|
|
167
168
|
declare function unum(num?: Numeric): Bignumber;
|
|
@@ -183,6 +184,7 @@ declare function percentage(total: Numeric, count: Numeric, options?: DecimalOpt
|
|
|
183
184
|
* @param lh
|
|
184
185
|
*/
|
|
185
186
|
declare function zerofill(value: Numberish, n?: number, type?: 'positive' | 'reverse'): Numberish;
|
|
187
|
+
declare function zeromove(value: Numberish): string;
|
|
186
188
|
declare function numerfix(value: any): string;
|
|
187
189
|
/**
|
|
188
190
|
* format as a positive integer
|
|
@@ -216,4 +218,4 @@ declare function formatNumeric(value?: Numeric, options?: FormatNumericOptions):
|
|
|
216
218
|
*/
|
|
217
219
|
declare function cover(value: string, mode: [number, number, number], symbol?: string): string;
|
|
218
220
|
|
|
219
|
-
export { Arrayable, Awaitable, BIG_INTS, BooleanLike, DecimalOptions, DeepKeyof, DeepPartial, DeepReadonly, DeepReplace, DeepRequired, Deferred, Delimiter, Dimension, DynamicObject, FormatGroupOptions, FormatNumericOptions, Key, NumberObject, Numberish, Numeric, NumericObject, Option, StringObject, SymbolObject, TypeofType, UA, arange, average, compose, cover, decimal, delay, formDataToObject, formatNumeric, formatSize, formatUnit, getTypeof, gt, gte, integer, isAndroid, isArray, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isNull, isNumber, isObject, isPhantomJS, isPlainObject, isString, isTypeof, isWeex, isWindow, loop, lt, lte, noop, numerfix, objectToFormData, pPipe, parseNumeric, percentage, pipe, plus, riposte, unum, weexPlatform, whenever, zerofill };
|
|
221
|
+
export { Arrayable, Awaitable, BIG_INTS, BooleanLike, DecimalOptions, DeepKeyof, DeepPartial, DeepReadonly, DeepReplace, DeepRequired, Deferred, Delimiter, Dimension, DynamicObject, FormatGroupOptions, FormatNumericOptions, Key, NumberObject, Numberish, Numeric, NumericObject, Option, StringObject, SymbolObject, TypeofType, UA, arange, average, compose, cover, decimal, delay, formDataToObject, formatNumeric, formatSize, formatUnit, getTypeof, gt, gte, integer, isAndroid, isArray, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isNull, isNumber, isObject, isPhantomJS, isPlainObject, isString, isTypeof, isWeex, isWindow, loop, lt, lte, noop, numerfix, objectToFormData, pPipe, parseNumeric, percentage, pipe, plus, riposte, unum, weexPlatform, whenever, zerofill, zeromove };
|
package/dist/index.mjs
CHANGED
|
@@ -1651,6 +1651,9 @@ function zerofill(value, n = 2, type = "positive") {
|
|
|
1651
1651
|
return zero + value;
|
|
1652
1652
|
return "";
|
|
1653
1653
|
}
|
|
1654
|
+
function zeromove(value) {
|
|
1655
|
+
return value.toString().replace(/\.?0+$/, "");
|
|
1656
|
+
}
|
|
1654
1657
|
function numerfix(value) {
|
|
1655
1658
|
const _isNaN = Number.isNaN(Number(value)) || value.toString() === "NaN";
|
|
1656
1659
|
if (_isNaN)
|
|
@@ -1692,7 +1695,7 @@ function formatNumeric(value = "0", options) {
|
|
|
1692
1695
|
decimals = 2
|
|
1693
1696
|
} = options || {};
|
|
1694
1697
|
const config = parseNumeric(value, delimiters || []);
|
|
1695
|
-
|
|
1698
|
+
let number = unum(value).div(config.v).toFormat(decimals, rounding, {
|
|
1696
1699
|
decimalSeparator: ".",
|
|
1697
1700
|
groupSeparator: ",",
|
|
1698
1701
|
groupSize: 3,
|
|
@@ -1701,6 +1704,7 @@ function formatNumeric(value = "0", options) {
|
|
|
1701
1704
|
fractionGroupSize: 0,
|
|
1702
1705
|
...format
|
|
1703
1706
|
});
|
|
1707
|
+
number = (options == null ? void 0 : options.zeromove) ? zeromove(number) : number;
|
|
1704
1708
|
return `${number}${config.n}`;
|
|
1705
1709
|
}
|
|
1706
1710
|
|
|
@@ -1763,5 +1767,6 @@ export {
|
|
|
1763
1767
|
unum,
|
|
1764
1768
|
weexPlatform,
|
|
1765
1769
|
whenever,
|
|
1766
|
-
zerofill
|
|
1770
|
+
zerofill,
|
|
1771
|
+
zeromove
|
|
1767
1772
|
};
|