@hairy/utils 1.39.1 → 1.41.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,
@@ -61,7 +62,7 @@ __export(index_exports, {
61
62
  formatNumeric: () => formatNumeric,
62
63
  formatSize: () => formatSize,
63
64
  formatUnit: () => formatUnit,
64
- formdataFromObject: () => formdataFromObject,
65
+ formdataToObject: () => formdataToObject,
65
66
  get: () => get_default,
66
67
  getTypeof: () => getTypeof,
67
68
  groupBy: () => groupBy_default,
@@ -131,7 +132,7 @@ __export(index_exports, {
131
132
  noop: () => noop2,
132
133
  numberify: () => numberify,
133
134
  numberish: () => numberish,
134
- objectFromFormdata: () => objectFromFormdata,
135
+ objectToFormdata: () => objectToFormdata,
135
136
  off: () => off,
136
137
  on: () => on,
137
138
  parseNumeric: () => parseNumeric,
@@ -3335,10 +3336,10 @@ function compose(...fns) {
3335
3336
  compose.promise = pCompose;
3336
3337
 
3337
3338
  // src/util/converts.ts
3338
- function objectFromFormdata(formData) {
3339
+ function formdataToObject(formData) {
3339
3340
  return Object.fromEntries(formData.entries());
3340
3341
  }
3341
- function formdataFromObject(object) {
3342
+ function objectToFormdata(object) {
3342
3343
  const formdata = new FormData();
3343
3344
  for (const [key, value] of Object.entries(object))
3344
3345
  formdata.set(key, value);
@@ -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,
@@ -3761,7 +3763,7 @@ function isTypeof(target, type) {
3761
3763
  formatNumeric,
3762
3764
  formatSize,
3763
3765
  formatUnit,
3764
- formdataFromObject,
3766
+ formdataToObject,
3765
3767
  get,
3766
3768
  getTypeof,
3767
3769
  groupBy,
@@ -3831,7 +3833,7 @@ function isTypeof(target, type) {
3831
3833
  noop,
3832
3834
  numberify,
3833
3835
  numberish,
3834
- objectFromFormdata,
3836
+ objectToFormdata,
3835
3837
  off,
3836
3838
  on,
3837
3839
  parseNumeric,
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;
@@ -484,12 +497,12 @@ declare namespace compose {
484
497
  * formData to object
485
498
  * @param formData
486
499
  */
487
- declare function objectFromFormdata(formData: FormData): Record<string, string>;
500
+ declare function formdataToObject(formData: FormData): Record<string, string>;
488
501
  /**
489
502
  * Object to formData
490
503
  * @param object
491
504
  */
492
- declare function formdataFromObject(object: Record<string, string | File>): FormData;
505
+ declare function objectToFormdata(object: Record<string, string | File>): FormData;
493
506
  /**
494
507
  * Check if a value is not NaN.
495
508
  * @param value - The value to check.
@@ -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, 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 };
@@ -4503,10 +4503,10 @@
4503
4503
  compose.promise = pCompose;
4504
4504
 
4505
4505
  // src/util/converts.ts
4506
- function objectFromFormdata(formData) {
4506
+ function formdataToObject(formData) {
4507
4507
  return Object.fromEntries(formData.entries());
4508
4508
  }
4509
- function formdataFromObject(object) {
4509
+ function objectToFormdata(object) {
4510
4510
  const formdata = new FormData();
4511
4511
  for (const [key, value] of Object.entries(object))
4512
4512
  formdata.set(key, value);
@@ -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) {
@@ -3160,10 +3160,10 @@ function compose(...fns) {
3160
3160
  compose.promise = pCompose;
3161
3161
 
3162
3162
  // src/util/converts.ts
3163
- function objectFromFormdata(formData) {
3163
+ function formdataToObject(formData) {
3164
3164
  return Object.fromEntries(formData.entries());
3165
3165
  }
3166
- function formdataFromObject(object) {
3166
+ function objectToFormdata(object) {
3167
3167
  const formdata = new FormData();
3168
3168
  for (const [key, value] of Object.entries(object))
3169
3169
  formdata.set(key, value);
@@ -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,
@@ -3585,7 +3586,7 @@ export {
3585
3586
  formatNumeric,
3586
3587
  formatSize,
3587
3588
  formatUnit,
3588
- formdataFromObject,
3589
+ formdataToObject,
3589
3590
  get_default as get,
3590
3591
  getTypeof,
3591
3592
  groupBy_default as groupBy,
@@ -3655,7 +3656,7 @@ export {
3655
3656
  noop2 as noop,
3656
3657
  numberify,
3657
3658
  numberish,
3658
- objectFromFormdata,
3659
+ objectToFormdata,
3659
3660
  off,
3660
3661
  on,
3661
3662
  parseNumeric,
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.41.0",
5
5
  "description": "Library for anywhere",
6
6
  "author": "Hairyf <wwu710632@gmail.com>",
7
7
  "license": "MIT",