@davigomesdev/format 0.0.0 → 0.0.1

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/format.d.ts CHANGED
@@ -3,8 +3,10 @@ import { Decimal } from 'decimal.js';
3
3
  export declare class Format {
4
4
  static formatToWei(value: Decimal.Value, decimals?: number): bigint;
5
5
  static formatFromWei(value: BigNumberish, decimals?: number): string;
6
+ static formatCompareWei(valueA: BigNumberish, valueB: BigNumberish, decimalsA?: number, decimalsB?: number): -1 | 0 | 1;
6
7
  static formatTrimDecimals(value: Decimal.Value, maxDecimals?: number): string;
7
8
  static formatAddress(address: string, startChars?: number, endChars?: number): string;
9
+ static formatCapitalize(text: string): string;
8
10
  static formatSanitizeInput(value: string, maxDecimals?: number): string;
9
11
  static formatCountDecimals(value: string): number;
10
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGrC,qBAAa,MAAM;WACH,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,QAAQ,GAAE,MAAW,GAAG,MAAM;WAKhE,aAAa,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,GAAE,MAAW,GAAG,MAAM;WAKjE,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,WAAW,GAAE,MAAW,GAAG,MAAM;WAoB1E,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,GAAE,MAAU,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM;WAWpF,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,GAAE,MAAW,GAAG,MAAM;WAgBpE,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAOzD"}
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGrC,qBAAa,MAAM;WACH,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,QAAQ,GAAE,MAAW,GAAG,MAAM;WAKhE,aAAa,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,GAAE,MAAW,GAAG,MAAM;WAKjE,gBAAgB,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,GAAE,MAAW,EAAE,SAAS,GAAE,MAAW,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;WAWxH,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,WAAW,GAAE,MAAW,GAAG,MAAM;WAoB1E,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,GAAE,MAAU,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM;WAWpF,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;WAItC,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,GAAE,MAAW,GAAG,MAAM;WAgBpE,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAOzD"}
package/dist/format.js CHANGED
@@ -9,6 +9,14 @@ export class Format {
9
9
  const num = Format.formatTrimDecimals(value.toString(), decimals);
10
10
  return formatUnits(num, decimals);
11
11
  }
12
+ static formatCompareWei(valueA, valueB, decimalsA = 18, decimalsB = 18) {
13
+ const a = BigInt(valueA.toString());
14
+ const b = BigInt(valueB.toString());
15
+ const diff = decimalsB - decimalsA;
16
+ const normalizedA = diff > 0 ? a * 10n ** BigInt(diff) : a;
17
+ const normalizedB = diff < 0 ? b * 10n ** BigInt(-diff) : b;
18
+ return normalizedA < normalizedB ? -1 : normalizedA > normalizedB ? 1 : 0;
19
+ }
12
20
  static formatTrimDecimals(value, maxDecimals = 18) {
13
21
  if (value.toString().trim() === '')
14
22
  return '0';
@@ -33,6 +41,9 @@ export class Format {
33
41
  const end = address.slice(-endChars);
34
42
  return `${start}...${end}`;
35
43
  }
44
+ static formatCapitalize(text) {
45
+ return text.charAt(0).toUpperCase() + text.slice(1);
46
+ }
36
47
  static formatSanitizeInput(value, maxDecimals = 18) {
37
48
  let sanitized = value.replace(/[^0-9.]/g, '');
38
49
  const parts = sanitized.split('.');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@davigomesdev/format",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [