@hairy/utils 1.39.1 → 1.40.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
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  BIG_INTS: () => BIG_INTS,
34
+ Bignumber: () => Bignumber,
34
35
  DEFAULT_BIGNUM_CONFIG: () => DEFAULT_BIGNUM_CONFIG,
35
36
  Deferred: () => Deferred,
36
37
  arange: () => arange,
@@ -3538,7 +3539,7 @@ var DEFAULT_BIGNUM_CONFIG = {
3538
3539
  ROUNDING_MODE: import_bignumber.default.ROUND_UP,
3539
3540
  DECIMAL_PLACES: 6
3540
3541
  };
3541
- var BignumberCLONE = import_bignumber.default.clone(DEFAULT_BIGNUM_CONFIG);
3542
+ var Bignumber = import_bignumber.default.clone(DEFAULT_BIGNUM_CONFIG);
3542
3543
  var BIG_INTS = {
3543
3544
  t: { v: 10 ** 12, d: 13, n: "t" },
3544
3545
  b: { v: 10 ** 9, d: 10, n: "b" },
@@ -3546,10 +3547,10 @@ var BIG_INTS = {
3546
3547
  k: { v: 10 ** 3, d: 4, n: "k" }
3547
3548
  };
3548
3549
  function bignumber(n = "0", base) {
3549
- return new BignumberCLONE(numberish(n), base);
3550
+ return new Bignumber(numberish(n), base);
3550
3551
  }
3551
3552
  bignumber.clone = function(config) {
3552
- return import_bignumber.default.clone({ ...DEFAULT_BIGNUM_CONFIG, ...config });
3553
+ return Bignumber.clone({ ...DEFAULT_BIGNUM_CONFIG, ...config });
3553
3554
  };
3554
3555
  function gte(a, b) {
3555
3556
  return bignumber(a).gte(bignumber(b));
@@ -3564,25 +3565,25 @@ function lt(a, b) {
3564
3565
  return bignumber(a).lt(bignumber(b));
3565
3566
  }
3566
3567
  function plus(array, options) {
3567
- const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
3568
+ const rounding = options?.r || Bignumber.ROUND_DOWN;
3568
3569
  const decimal2 = options?.d || 0;
3569
3570
  return array.filter((v) => bignumber(v).gt(0)).reduce((t, v) => t.plus(bignumber(v)), bignumber(0)).toFixed(decimal2, rounding);
3570
3571
  }
3571
3572
  function divs(array, options) {
3572
- const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
3573
+ const rounding = options?.r || Bignumber.ROUND_DOWN;
3573
3574
  const decimal2 = options?.d || 0;
3574
3575
  return array.reduce((t, v) => t.div(bignumber(v)), bignumber(1)).toFixed(decimal2, rounding);
3575
3576
  }
3576
3577
  function average(array, options) {
3577
- const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
3578
+ const rounding = options?.r || Bignumber.ROUND_DOWN;
3578
3579
  const decimal2 = options?.d || 0;
3579
3580
  if (array.length === 0)
3580
3581
  return "0";
3581
3582
  return bignumber(plus(array)).div(array.length).toFixed(decimal2, rounding);
3582
3583
  }
3583
3584
  function percentage(total, count, options) {
3584
- options ??= { d: 3, r: import_bignumber.default.ROUND_DOWN };
3585
- const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
3585
+ options ??= { d: 3, r: Bignumber.ROUND_DOWN };
3586
+ const rounding = options?.r || Bignumber.ROUND_DOWN;
3586
3587
  const decimal2 = options?.d || 3;
3587
3588
  if (bignumber(total).lte(0) || bignumber(count).lte(0))
3588
3589
  return "0";
@@ -3603,7 +3604,7 @@ function zeromove(value) {
3603
3604
  return numberish(value).toString().replace(/\.?0+$/, "");
3604
3605
  }
3605
3606
  function integer(value) {
3606
- return new import_bignumber.default(numberish(value)).toFixed(0);
3607
+ return new Bignumber(numberish(value)).toFixed(0);
3607
3608
  }
3608
3609
  function decimal(value, n = 2) {
3609
3610
  let [integer2, decimal2] = numberish(value).split(".");
@@ -3633,7 +3634,7 @@ function formatNumeric(value = "0", options) {
3633
3634
  if (options?.default && bignumber(value).isZero())
3634
3635
  return options?.default;
3635
3636
  const {
3636
- rounding = import_bignumber.default.ROUND_DOWN,
3637
+ rounding = Bignumber.ROUND_DOWN,
3637
3638
  delimiters,
3638
3639
  format,
3639
3640
  decimals = 2
@@ -3731,6 +3732,7 @@ function isTypeof(target, type) {
3731
3732
  // Annotate the CommonJS export names for ESM import in node:
3732
3733
  0 && (module.exports = {
3733
3734
  BIG_INTS,
3735
+ Bignumber,
3734
3736
  DEFAULT_BIGNUM_CONFIG,
3735
3737
  Deferred,
3736
3738
  arange,
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { clone, cloneDeep, cloneDeepWith, cloneWith, concat, debounce, find, get, groupBy, isArguments, isArray, isArrayBuffer, isArrayLike, isArrayLikeObject, isBoolean, isBuffer, isDate, isElement, isEmpty, isEqual, isEqualWith, isError, isFunction, isInteger, isMap, isMatch, isMatchWith, isNaN, isNative, isNull, isNumber, isObject, isObjectLike, isPlainObject, isRegExp as isRegexp, isSet, isString, isSymbol, isUndefined, isWeakMap, isWeakSet, join, keyBy, keys, merge, mergeWith, set, truncate, uniq, uniqBy, uniqWith, values } from 'lodash-es';
2
- import Bignumber from 'bignumber.js';
2
+ import _Bignumber from 'bignumber.js';
3
3
 
4
4
  interface OpenFilePickerOptions {
5
5
  /**
@@ -220,7 +220,20 @@ declare function snakeCase(input: string, options?: Options): string;
220
220
  */
221
221
  declare function trainCase(input: string, options?: Options): string;
222
222
 
223
- declare const DEFAULT_BIGNUM_CONFIG: Bignumber.Config;
223
+ declare const DEFAULT_BIGNUM_CONFIG: _Bignumber.Config;
224
+ declare namespace Bignumber {
225
+ type RoundingMode = _Bignumber.RoundingMode;
226
+ type Format = _Bignumber.Format;
227
+ type Config = _Bignumber.Config;
228
+ type Instance = _Bignumber.Instance;
229
+ type Value = _Bignumber.Value;
230
+ }
231
+ declare const Bignumber: typeof _Bignumber;
232
+ /**
233
+ * export bignumber.js
234
+ *
235
+ * do not use Bignumber directly, use bignumber function instead
236
+ */
224
237
  declare const BIG_INTS: {
225
238
  t: {
226
239
  v: number;
@@ -260,9 +273,9 @@ interface FormatNumericOptions {
260
273
  default?: string;
261
274
  format?: Bignumber.Format;
262
275
  }
263
- declare function bignumber(n?: Numberish, base?: number): Bignumber;
276
+ declare function bignumber(n?: Numberish, base?: number): _Bignumber;
264
277
  declare namespace bignumber {
265
- var clone: (config: Bignumber.Config) => typeof Bignumber;
278
+ var clone: (config: Bignumber.Config) => typeof _Bignumber;
266
279
  }
267
280
  declare function gte(a: Numberish, b: Numberish): boolean;
268
281
  declare function gt(a: Numberish, b: Numberish): boolean;
@@ -634,4 +647,4 @@ declare function unwrap<T extends object>(value: T | (() => T)): T;
634
647
  declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
635
648
  declare function call<T extends Fn$1<any>>(fn: T, ...args: Parameters<T>): ReturnType<T>;
636
649
 
637
- export { type AnyFn, type ArgumentsType, type Arrayable, type Assign, type Awaitable, BIG_INTS, 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, formdataFromObject, 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, objectFromFormdata, 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 };
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, formdataFromObject, 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, objectFromFormdata, 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 };
@@ -4706,7 +4706,7 @@
4706
4706
  ROUNDING_MODE: bignumber_default.ROUND_UP,
4707
4707
  DECIMAL_PLACES: 6
4708
4708
  };
4709
- var BignumberCLONE = bignumber_default.clone(DEFAULT_BIGNUM_CONFIG);
4709
+ var Bignumber = bignumber_default.clone(DEFAULT_BIGNUM_CONFIG);
4710
4710
  var BIG_INTS = {
4711
4711
  t: { v: 10 ** 12, d: 13, n: "t" },
4712
4712
  b: { v: 10 ** 9, d: 10, n: "b" },
@@ -4714,10 +4714,10 @@
4714
4714
  k: { v: 10 ** 3, d: 4, n: "k" }
4715
4715
  };
4716
4716
  function bignumber(n = "0", base) {
4717
- return new BignumberCLONE(numberish(n), base);
4717
+ return new Bignumber(numberish(n), base);
4718
4718
  }
4719
4719
  bignumber.clone = function(config) {
4720
- return bignumber_default.clone({ ...DEFAULT_BIGNUM_CONFIG, ...config });
4720
+ return Bignumber.clone({ ...DEFAULT_BIGNUM_CONFIG, ...config });
4721
4721
  };
4722
4722
  function gte(a, b) {
4723
4723
  return bignumber(a).gte(bignumber(b));
@@ -4732,25 +4732,25 @@
4732
4732
  return bignumber(a).lt(bignumber(b));
4733
4733
  }
4734
4734
  function plus(array, options) {
4735
- const rounding = options?.r || bignumber_default.ROUND_DOWN;
4735
+ const rounding = options?.r || Bignumber.ROUND_DOWN;
4736
4736
  const decimal2 = options?.d || 0;
4737
4737
  return array.filter((v) => bignumber(v).gt(0)).reduce((t, v) => t.plus(bignumber(v)), bignumber(0)).toFixed(decimal2, rounding);
4738
4738
  }
4739
4739
  function divs(array, options) {
4740
- const rounding = options?.r || bignumber_default.ROUND_DOWN;
4740
+ const rounding = options?.r || Bignumber.ROUND_DOWN;
4741
4741
  const decimal2 = options?.d || 0;
4742
4742
  return array.reduce((t, v) => t.div(bignumber(v)), bignumber(1)).toFixed(decimal2, rounding);
4743
4743
  }
4744
4744
  function average(array, options) {
4745
- const rounding = options?.r || bignumber_default.ROUND_DOWN;
4745
+ const rounding = options?.r || Bignumber.ROUND_DOWN;
4746
4746
  const decimal2 = options?.d || 0;
4747
4747
  if (array.length === 0)
4748
4748
  return "0";
4749
4749
  return bignumber(plus(array)).div(array.length).toFixed(decimal2, rounding);
4750
4750
  }
4751
4751
  function percentage(total, count, options) {
4752
- options ??= { d: 3, r: bignumber_default.ROUND_DOWN };
4753
- const rounding = options?.r || bignumber_default.ROUND_DOWN;
4752
+ options ??= { d: 3, r: Bignumber.ROUND_DOWN };
4753
+ const rounding = options?.r || Bignumber.ROUND_DOWN;
4754
4754
  const decimal2 = options?.d || 3;
4755
4755
  if (bignumber(total).lte(0) || bignumber(count).lte(0))
4756
4756
  return "0";
@@ -4771,7 +4771,7 @@
4771
4771
  return numberish(value).toString().replace(/\.?0+$/, "");
4772
4772
  }
4773
4773
  function integer(value) {
4774
- return new bignumber_default(numberish(value)).toFixed(0);
4774
+ return new Bignumber(numberish(value)).toFixed(0);
4775
4775
  }
4776
4776
  function decimal(value, n = 2) {
4777
4777
  let [integer2, decimal2] = numberish(value).split(".");
@@ -4801,7 +4801,7 @@
4801
4801
  if (options?.default && bignumber(value).isZero())
4802
4802
  return options?.default;
4803
4803
  const {
4804
- rounding = bignumber_default.ROUND_DOWN,
4804
+ rounding = Bignumber.ROUND_DOWN,
4805
4805
  delimiters,
4806
4806
  format,
4807
4807
  decimals = 2
package/dist/index.js CHANGED
@@ -3138,7 +3138,7 @@ function splitPrefixSuffix(input, options = {}) {
3138
3138
  }
3139
3139
 
3140
3140
  // src/number/index.ts
3141
- import Bignumber from "bignumber.js";
3141
+ import _Bignumber from "bignumber.js";
3142
3142
 
3143
3143
  // src/util/compose-promise.ts
3144
3144
  function pCompose(...fns) {
@@ -3360,10 +3360,10 @@ function call(fn, ...args) {
3360
3360
 
3361
3361
  // src/number/index.ts
3362
3362
  var DEFAULT_BIGNUM_CONFIG = {
3363
- ROUNDING_MODE: Bignumber.ROUND_UP,
3363
+ ROUNDING_MODE: _Bignumber.ROUND_UP,
3364
3364
  DECIMAL_PLACES: 6
3365
3365
  };
3366
- var BignumberCLONE = Bignumber.clone(DEFAULT_BIGNUM_CONFIG);
3366
+ var Bignumber = _Bignumber.clone(DEFAULT_BIGNUM_CONFIG);
3367
3367
  var BIG_INTS = {
3368
3368
  t: { v: 10 ** 12, d: 13, n: "t" },
3369
3369
  b: { v: 10 ** 9, d: 10, n: "b" },
@@ -3371,7 +3371,7 @@ var BIG_INTS = {
3371
3371
  k: { v: 10 ** 3, d: 4, n: "k" }
3372
3372
  };
3373
3373
  function bignumber(n = "0", base) {
3374
- return new BignumberCLONE(numberish(n), base);
3374
+ return new Bignumber(numberish(n), base);
3375
3375
  }
3376
3376
  bignumber.clone = function(config) {
3377
3377
  return Bignumber.clone({ ...DEFAULT_BIGNUM_CONFIG, ...config });
@@ -3555,6 +3555,7 @@ function isTypeof(target, type) {
3555
3555
  }
3556
3556
  export {
3557
3557
  BIG_INTS,
3558
+ Bignumber,
3558
3559
  DEFAULT_BIGNUM_CONFIG,
3559
3560
  Deferred,
3560
3561
  arange,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hairy/utils",
3
3
  "type": "module",
4
- "version": "1.39.1",
4
+ "version": "1.40.0",
5
5
  "description": "Library for anywhere",
6
6
  "author": "Hairyf <wwu710632@gmail.com>",
7
7
  "license": "MIT",