@hairy/utils 0.7.1 → 0.7.3

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 CHANGED
@@ -72,9 +72,11 @@ __export(src_exports, {
72
72
  plus: () => plus,
73
73
  riposte: () => riposte,
74
74
  unum: () => unum,
75
+ unwrap: () => unwrap,
75
76
  weexPlatform: () => weexPlatform,
76
77
  whenever: () => whenever,
77
- zerofill: () => zerofill
78
+ zerofill: () => zerofill,
79
+ zeromove: () => zeromove
78
80
  });
79
81
  module.exports = __toCommonJS(src_exports);
80
82
 
@@ -203,6 +205,9 @@ function riposte(...args) {
203
205
  }
204
206
  return void 0;
205
207
  }
208
+ function unwrap(value) {
209
+ return typeof value === "function" ? value() : value;
210
+ }
206
211
 
207
212
  // ../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.mjs
208
213
  var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
@@ -1731,6 +1736,9 @@ function zerofill(value, n = 2, type = "positive") {
1731
1736
  return zero + value;
1732
1737
  return "";
1733
1738
  }
1739
+ function zeromove(value) {
1740
+ return value.toString().replace(/\.?0+$/, "");
1741
+ }
1734
1742
  function numerfix(value) {
1735
1743
  const _isNaN = Number.isNaN(Number(value)) || value.toString() === "NaN";
1736
1744
  if (_isNaN)
@@ -1772,7 +1780,7 @@ function formatNumeric(value = "0", options) {
1772
1780
  decimals = 2
1773
1781
  } = options || {};
1774
1782
  const config = parseNumeric(value, delimiters || []);
1775
- const number = unum(value).div(config.v).toFormat(decimals, rounding, {
1783
+ let number = unum(value).div(config.v).toFormat(decimals, rounding, {
1776
1784
  decimalSeparator: ".",
1777
1785
  groupSeparator: ",",
1778
1786
  groupSize: 3,
@@ -1781,6 +1789,7 @@ function formatNumeric(value = "0", options) {
1781
1789
  fractionGroupSize: 0,
1782
1790
  ...format
1783
1791
  });
1792
+ number = (options == null ? void 0 : options.zeromove) ? zeromove(number) : number;
1784
1793
  return `${number}${config.n}`;
1785
1794
  }
1786
1795
 
@@ -1842,7 +1851,9 @@ function cover(value, mode, symbol = "*") {
1842
1851
  plus,
1843
1852
  riposte,
1844
1853
  unum,
1854
+ unwrap,
1845
1855
  weexPlatform,
1846
1856
  whenever,
1847
- zerofill
1857
+ zerofill,
1858
+ zeromove
1848
1859
  });
package/dist/index.d.ts CHANGED
@@ -119,7 +119,8 @@ declare function delay(ms: number): Promise<unknown>;
119
119
  declare function arange(x1: number, x2?: number, stp?: number, z?: number[], z0?: number): number[];
120
120
  declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
121
121
  declare function loop<T = void>(fn: (next: (ms: number) => Promise<T>) => Promise<T>): Promise<T>;
122
- declare function riposte<T>(...args: [cond: boolean, value: T][]): T;
122
+ declare function riposte<T>(...args: [cond: boolean, value: T][]): T;
123
+ declare function unwrap<T extends object>(value: T | (() => T)): T;
123
124
 
124
125
  declare const BIG_INTS: {
125
126
  t: {
@@ -162,6 +163,7 @@ interface FormatNumericOptions {
162
163
  delimiters?: Delimiter[] | false;
163
164
  rounding?: Bignumber.RoundingMode;
164
165
  decimals?: number;
166
+ zeromove?: boolean;
165
167
  format?: Bignumber.Format;
166
168
  }
167
169
  declare function unum(num?: Numeric): Bignumber;
@@ -183,6 +185,7 @@ declare function percentage(total: Numeric, count: Numeric, options?: DecimalOpt
183
185
  * @param lh
184
186
  */
185
187
  declare function zerofill(value: Numberish, n?: number, type?: 'positive' | 'reverse'): Numberish;
188
+ declare function zeromove(value: Numberish): string;
186
189
  declare function numerfix(value: any): string;
187
190
  /**
188
191
  * format as a positive integer
@@ -216,4 +219,4 @@ declare function formatNumeric(value?: Numeric, options?: FormatNumericOptions):
216
219
  */
217
220
  declare function cover(value: string, mode: [number, number, number], symbol?: string): string;
218
221
 
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 };
222
+ 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, unwrap, weexPlatform, whenever, zerofill, zeromove };
package/dist/index.mjs CHANGED
@@ -123,6 +123,9 @@ function riposte(...args) {
123
123
  }
124
124
  return void 0;
125
125
  }
126
+ function unwrap(value) {
127
+ return typeof value === "function" ? value() : value;
128
+ }
126
129
 
127
130
  // ../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.mjs
128
131
  var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
@@ -1651,6 +1654,9 @@ function zerofill(value, n = 2, type = "positive") {
1651
1654
  return zero + value;
1652
1655
  return "";
1653
1656
  }
1657
+ function zeromove(value) {
1658
+ return value.toString().replace(/\.?0+$/, "");
1659
+ }
1654
1660
  function numerfix(value) {
1655
1661
  const _isNaN = Number.isNaN(Number(value)) || value.toString() === "NaN";
1656
1662
  if (_isNaN)
@@ -1692,7 +1698,7 @@ function formatNumeric(value = "0", options) {
1692
1698
  decimals = 2
1693
1699
  } = options || {};
1694
1700
  const config = parseNumeric(value, delimiters || []);
1695
- const number = unum(value).div(config.v).toFormat(decimals, rounding, {
1701
+ let number = unum(value).div(config.v).toFormat(decimals, rounding, {
1696
1702
  decimalSeparator: ".",
1697
1703
  groupSeparator: ",",
1698
1704
  groupSize: 3,
@@ -1701,6 +1707,7 @@ function formatNumeric(value = "0", options) {
1701
1707
  fractionGroupSize: 0,
1702
1708
  ...format
1703
1709
  });
1710
+ number = (options == null ? void 0 : options.zeromove) ? zeromove(number) : number;
1704
1711
  return `${number}${config.n}`;
1705
1712
  }
1706
1713
 
@@ -1761,7 +1768,9 @@ export {
1761
1768
  plus,
1762
1769
  riposte,
1763
1770
  unum,
1771
+ unwrap,
1764
1772
  weexPlatform,
1765
1773
  whenever,
1766
- zerofill
1774
+ zerofill,
1775
+ zeromove
1767
1776
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hairy/utils",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.cjs",
6
6
  "publishConfig": {