@hairy/utils 1.42.0 → 1.44.0

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
@@ -52,7 +52,7 @@ __export(index_exports, {
52
52
  decimal: () => decimal,
53
53
  delay: () => delay,
54
54
  dialsPhone: () => dialsPhone,
55
- divs: () => divs,
55
+ divide: () => divide,
56
56
  dotCase: () => dotCase,
57
57
  downloadBlobFile: () => downloadBlobFile,
58
58
  downloadNetworkFile: () => downloadNetworkFile,
@@ -127,6 +127,7 @@ __export(index_exports, {
127
127
  lte: () => lte,
128
128
  merge: () => merge_default,
129
129
  mergeWith: () => mergeWith_default,
130
+ multiply: () => multiply,
130
131
  noCase: () => noCase,
131
132
  nonnanable: () => nonnanable,
132
133
  noop: () => noop2,
@@ -169,8 +170,8 @@ __export(index_exports, {
169
170
  unwrap: () => unwrap,
170
171
  values: () => values_default,
171
172
  whenever: () => whenever,
172
- zerofill: () => zerofill,
173
- zeromove: () => zeromove
173
+ zeroRemove: () => zeroRemove,
174
+ zerofill: () => zerofill
174
175
  });
175
176
  module.exports = __toCommonJS(index_exports);
176
177
 
@@ -3569,11 +3570,16 @@ function plus(array, options) {
3569
3570
  const decimal2 = options?.d || 6;
3570
3571
  return array.filter((v) => bignumber(v).gt(0)).reduce((t, v) => t.plus(numberish(v)), bignumber(0)).toFixed(decimal2, rounding);
3571
3572
  }
3572
- function divs(array, options) {
3573
+ function divide(array, options) {
3573
3574
  const rounding = options?.r || Bignumber.ROUND_DOWN;
3574
- const decimal2 = options?.d || 0;
3575
+ const decimal2 = options?.d || 6;
3575
3576
  return array.reduce((t, v) => t.div(bignumber(v)), bignumber(1)).toFixed(decimal2, rounding);
3576
3577
  }
3578
+ function multiply(array, options) {
3579
+ const rounding = options?.r || Bignumber.ROUND_DOWN;
3580
+ const decimal2 = options?.d || 6;
3581
+ return array.reduce((t, v) => t.times(bignumber(v)), bignumber(1)).toFixed(decimal2, rounding);
3582
+ }
3577
3583
  function average(array, options) {
3578
3584
  const rounding = options?.r || Bignumber.ROUND_DOWN;
3579
3585
  const decimal2 = options?.d || 0;
@@ -3600,8 +3606,9 @@ function zerofill(value, n = 2, type = "positive") {
3600
3606
  return zero + value;
3601
3607
  return "";
3602
3608
  }
3603
- function zeromove(value) {
3604
- return numberish(value).toString().replace(/\.?0+$/, "");
3609
+ function zeroRemove(value, convert = true) {
3610
+ const _value = convert ? numberish(value) : value || "";
3611
+ return _value.toString().replace(/\.?0+$/, "");
3605
3612
  }
3606
3613
  function integer(value) {
3607
3614
  return new Bignumber(numberish(value)).toFixed(0);
@@ -3649,7 +3656,7 @@ function formatNumeric(value = "0", options) {
3649
3656
  fractionGroupSize: 0,
3650
3657
  ...format
3651
3658
  });
3652
- number = options?.zeromove ? zeromove(number) : number;
3659
+ number = options?.decimalsZero ? zeroRemove(number, false) : number;
3653
3660
  return `${number}${config.n}`;
3654
3661
  }
3655
3662
 
@@ -3753,7 +3760,7 @@ function isTypeof(target, type) {
3753
3760
  decimal,
3754
3761
  delay,
3755
3762
  dialsPhone,
3756
- divs,
3763
+ divide,
3757
3764
  dotCase,
3758
3765
  downloadBlobFile,
3759
3766
  downloadNetworkFile,
@@ -3828,6 +3835,7 @@ function isTypeof(target, type) {
3828
3835
  lte,
3829
3836
  merge,
3830
3837
  mergeWith,
3838
+ multiply,
3831
3839
  noCase,
3832
3840
  nonnanable,
3833
3841
  noop,
@@ -3870,8 +3878,8 @@ function isTypeof(target, type) {
3870
3878
  unwrap,
3871
3879
  values,
3872
3880
  whenever,
3873
- zerofill,
3874
- zeromove
3881
+ zeroRemove,
3882
+ zerofill
3875
3883
  });
3876
3884
  /*! Bundled license information:
3877
3885
 
package/dist/index.d.ts CHANGED
@@ -269,7 +269,7 @@ interface FormatNumericOptions {
269
269
  delimiters?: Delimiter[] | false;
270
270
  rounding?: Bignumber.RoundingMode;
271
271
  decimals?: number;
272
- zeromove?: boolean;
272
+ decimalsZero?: boolean;
273
273
  default?: string;
274
274
  format?: Bignumber.Format;
275
275
  }
@@ -282,7 +282,8 @@ declare function gt(a: Numberish, b: Numberish): boolean;
282
282
  declare function lte(a: Numberish, b: Numberish): boolean;
283
283
  declare function lt(a: Numberish, b: Numberish): boolean;
284
284
  declare function plus(array: Numberish[], options?: DecimalOptions): string;
285
- declare function divs(array: Numberish[], options?: DecimalOptions): string;
285
+ declare function divide(array: Numberish[], options?: DecimalOptions): string;
286
+ declare function multiply(array: Numberish[], options?: DecimalOptions): string;
286
287
  declare function average(array: Numberish[], options?: DecimalOptions): string;
287
288
  /**
288
289
  * calculate percentage
@@ -297,7 +298,7 @@ declare function percentage(total: Numberish, count: Numberish, options?: Decima
297
298
  * @param type
298
299
  */
299
300
  declare function zerofill(value: Numberish, n?: number, type?: 'positive' | 'reverse'): Numberish;
300
- declare function zeromove(value: Numberish): string;
301
+ declare function zeroRemove(value: Numberish, convert?: boolean): string;
301
302
  /**
302
303
  * format as a positive integer
303
304
  * @param value
@@ -647,4 +648,4 @@ declare function unwrap<T extends object>(value: T | (() => T)): T;
647
648
  declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
648
649
  declare function call<T extends Fn$1<any>>(fn: T, ...args: Parameters<T>): ReturnType<T>;
649
650
 
650
- export { type AnyFn, type ArgumentsType, type Arrayable, type Assign, type Awaitable, BIG_INTS, Bignumber, type BooleanLike, type BrowserNativeObject, type ConstructorType, DEFAULT_BIGNUM_CONFIG, type DecimalOptions, type DeepKeyof, type DeepMap, type DeepMerge, type DeepPartial, type DeepReadonly, type DeepReplace, type DeepRequired, Deferred, type Delimiter, type Dimension, type DynamicObject, type ElementOf, type Fn$1 as Fn, type FormatGroupOptions, type FormatNumericOptions, type IfAny, type IsAny, type Key, type Looper, type MergeInsertions, type NonUndefined, type Noop, type Nullable, type NumberObject, type Numberish, type Numeric, type NumericObject, type OmitBy, type OpenFilePickerOptions, type OpenImagePickerOptions, type Option, type Overwrite, type PickBy, type PromiseFn, type PromiseType, type Promisify, type ReaderType, type StringObject, type SymbolObject, type Typeof, arange, average, bignumber, call, camelCase, capitalCase, compose, constantCase, cover, decimal, delay, dialsPhone, divs, dotCase, downloadBlobFile, downloadNetworkFile, ensurePrefix, ensureSuffix, formatNumeric, formatSize, formatUnit, formdataToObject, getTypeof, gt, gte, integer, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isTruthy, isTypeof, isWeex, isWindow, jsonTryParse, kebabCase, loop, lt, lte, noCase, nonnanable, noop, numberify, numberish, objectToFormdata, off, on, parseNumeric, pascalCase, pascalSnakeCase, pathCase, percentage, pipe, plus, proxy, randomArray, randomNumber, randomString, readFileReader, redirectTo, riposte, selectImages, sentenceCase, showOpenFilePicker, showOpenImagePicker, slash, snakeCase, stringify, template, to, toArray, trainCase, unindent, unwrap, whenever, zerofill, zeromove };
651
+ export { type AnyFn, type ArgumentsType, type Arrayable, type Assign, type Awaitable, BIG_INTS, Bignumber, type BooleanLike, type BrowserNativeObject, type ConstructorType, DEFAULT_BIGNUM_CONFIG, type DecimalOptions, type DeepKeyof, type DeepMap, type DeepMerge, type DeepPartial, type DeepReadonly, type DeepReplace, type DeepRequired, Deferred, type Delimiter, type Dimension, type DynamicObject, type ElementOf, type Fn$1 as Fn, type FormatGroupOptions, type FormatNumericOptions, type IfAny, type IsAny, type Key, type Looper, type MergeInsertions, type NonUndefined, type Noop, type Nullable, type NumberObject, type Numberish, type Numeric, type NumericObject, type OmitBy, type OpenFilePickerOptions, type OpenImagePickerOptions, type Option, type Overwrite, type PickBy, type PromiseFn, type PromiseType, type Promisify, type ReaderType, type StringObject, type SymbolObject, type Typeof, arange, average, bignumber, call, camelCase, capitalCase, compose, constantCase, cover, decimal, delay, dialsPhone, divide, dotCase, downloadBlobFile, downloadNetworkFile, ensurePrefix, ensureSuffix, formatNumeric, formatSize, formatUnit, formdataToObject, getTypeof, gt, gte, integer, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isTruthy, isTypeof, isWeex, isWindow, jsonTryParse, kebabCase, loop, lt, lte, multiply, noCase, nonnanable, noop, numberify, numberish, objectToFormdata, off, on, parseNumeric, pascalCase, pascalSnakeCase, pathCase, percentage, pipe, plus, proxy, randomArray, randomNumber, randomString, readFileReader, redirectTo, riposte, selectImages, sentenceCase, showOpenFilePicker, showOpenImagePicker, slash, snakeCase, stringify, template, to, toArray, trainCase, unindent, unwrap, whenever, zeroRemove, zerofill };
@@ -3567,7 +3567,7 @@
3567
3567
  };
3568
3568
  }();
3569
3569
  div = /* @__PURE__ */ function() {
3570
- function multiply(x, k, base) {
3570
+ function multiply2(x, k, base) {
3571
3571
  var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
3572
3572
  for (x = x.slice(); i--; ) {
3573
3573
  xlo = x[i] % SQRT_BASE;
@@ -3635,8 +3635,8 @@
3635
3635
  s += 2;
3636
3636
  n = mathfloor(base / (yc[0] + 1));
3637
3637
  if (n > 1) {
3638
- yc = multiply(yc, n, base);
3639
- xc = multiply(xc, n, base);
3638
+ yc = multiply2(yc, n, base);
3639
+ xc = multiply2(xc, n, base);
3640
3640
  yL = yc.length;
3641
3641
  xL = xc.length;
3642
3642
  }
@@ -3657,7 +3657,7 @@
3657
3657
  n = mathfloor(rem0 / yc0);
3658
3658
  if (n > 1) {
3659
3659
  if (n >= base) n = base - 1;
3660
- prod = multiply(yc, n, base);
3660
+ prod = multiply2(yc, n, base);
3661
3661
  prodL = prod.length;
3662
3662
  remL = rem.length;
3663
3663
  while (compare2(prod, rem, prodL, remL) == 1) {
@@ -4736,11 +4736,16 @@
4736
4736
  const decimal2 = options?.d || 6;
4737
4737
  return array.filter((v) => bignumber(v).gt(0)).reduce((t, v) => t.plus(numberish(v)), bignumber(0)).toFixed(decimal2, rounding);
4738
4738
  }
4739
- function divs(array, options) {
4739
+ function divide(array, options) {
4740
4740
  const rounding = options?.r || Bignumber.ROUND_DOWN;
4741
- const decimal2 = options?.d || 0;
4741
+ const decimal2 = options?.d || 6;
4742
4742
  return array.reduce((t, v) => t.div(bignumber(v)), bignumber(1)).toFixed(decimal2, rounding);
4743
4743
  }
4744
+ function multiply(array, options) {
4745
+ const rounding = options?.r || Bignumber.ROUND_DOWN;
4746
+ const decimal2 = options?.d || 6;
4747
+ return array.reduce((t, v) => t.times(bignumber(v)), bignumber(1)).toFixed(decimal2, rounding);
4748
+ }
4744
4749
  function average(array, options) {
4745
4750
  const rounding = options?.r || Bignumber.ROUND_DOWN;
4746
4751
  const decimal2 = options?.d || 0;
@@ -4767,8 +4772,9 @@
4767
4772
  return zero + value;
4768
4773
  return "";
4769
4774
  }
4770
- function zeromove(value) {
4771
- return numberish(value).toString().replace(/\.?0+$/, "");
4775
+ function zeroRemove(value, convert = true) {
4776
+ const _value = convert ? numberish(value) : value || "";
4777
+ return _value.toString().replace(/\.?0+$/, "");
4772
4778
  }
4773
4779
  function integer(value) {
4774
4780
  return new Bignumber(numberish(value)).toFixed(0);
@@ -4816,7 +4822,7 @@
4816
4822
  fractionGroupSize: 0,
4817
4823
  ...format
4818
4824
  });
4819
- number = options?.zeromove ? zeromove(number) : number;
4825
+ number = options?.decimalsZero ? zeroRemove(number, false) : number;
4820
4826
  return `${number}${config.n}`;
4821
4827
  }
4822
4828
 
package/dist/index.js CHANGED
@@ -3393,11 +3393,16 @@ function plus(array, options) {
3393
3393
  const decimal2 = options?.d || 6;
3394
3394
  return array.filter((v) => bignumber(v).gt(0)).reduce((t, v) => t.plus(numberish(v)), bignumber(0)).toFixed(decimal2, rounding);
3395
3395
  }
3396
- function divs(array, options) {
3396
+ function divide(array, options) {
3397
3397
  const rounding = options?.r || Bignumber.ROUND_DOWN;
3398
- const decimal2 = options?.d || 0;
3398
+ const decimal2 = options?.d || 6;
3399
3399
  return array.reduce((t, v) => t.div(bignumber(v)), bignumber(1)).toFixed(decimal2, rounding);
3400
3400
  }
3401
+ function multiply(array, options) {
3402
+ const rounding = options?.r || Bignumber.ROUND_DOWN;
3403
+ const decimal2 = options?.d || 6;
3404
+ return array.reduce((t, v) => t.times(bignumber(v)), bignumber(1)).toFixed(decimal2, rounding);
3405
+ }
3401
3406
  function average(array, options) {
3402
3407
  const rounding = options?.r || Bignumber.ROUND_DOWN;
3403
3408
  const decimal2 = options?.d || 0;
@@ -3424,8 +3429,9 @@ function zerofill(value, n = 2, type = "positive") {
3424
3429
  return zero + value;
3425
3430
  return "";
3426
3431
  }
3427
- function zeromove(value) {
3428
- return numberish(value).toString().replace(/\.?0+$/, "");
3432
+ function zeroRemove(value, convert = true) {
3433
+ const _value = convert ? numberish(value) : value || "";
3434
+ return _value.toString().replace(/\.?0+$/, "");
3429
3435
  }
3430
3436
  function integer(value) {
3431
3437
  return new Bignumber(numberish(value)).toFixed(0);
@@ -3473,7 +3479,7 @@ function formatNumeric(value = "0", options) {
3473
3479
  fractionGroupSize: 0,
3474
3480
  ...format
3475
3481
  });
3476
- number = options?.zeromove ? zeromove(number) : number;
3482
+ number = options?.decimalsZero ? zeroRemove(number, false) : number;
3477
3483
  return `${number}${config.n}`;
3478
3484
  }
3479
3485
 
@@ -3576,7 +3582,7 @@ export {
3576
3582
  decimal,
3577
3583
  delay,
3578
3584
  dialsPhone,
3579
- divs,
3585
+ divide,
3580
3586
  dotCase,
3581
3587
  downloadBlobFile,
3582
3588
  downloadNetworkFile,
@@ -3651,6 +3657,7 @@ export {
3651
3657
  lte,
3652
3658
  merge_default as merge,
3653
3659
  mergeWith_default as mergeWith,
3660
+ multiply,
3654
3661
  noCase,
3655
3662
  nonnanable,
3656
3663
  noop2 as noop,
@@ -3693,8 +3700,8 @@ export {
3693
3700
  unwrap,
3694
3701
  values_default as values,
3695
3702
  whenever,
3696
- zerofill,
3697
- zeromove
3703
+ zeroRemove,
3704
+ zerofill
3698
3705
  };
3699
3706
  /*! Bundled license information:
3700
3707
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hairy/utils",
3
3
  "type": "module",
4
- "version": "1.42.0",
4
+ "version": "1.44.0",
5
5
  "description": "Library for anywhere",
6
6
  "author": "Hairyf <wwu710632@gmail.com>",
7
7
  "license": "MIT",