string_manipulation.d.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { Numbers } from 'web3-types';
  2. /**
  3. * Adds a padding on the left of a string, if value is a integer or bigInt will be converted to a hex string.
  4. * @param value - The value to be padded.
  5. * @param characterAmount - The amount of characters the string should have.
  6. * @param sign - The sign to be added (default is 0).
  7. * @returns The padded string.
  8. *
  9. * @example
  10. * ```ts
  11. *
  12. * console.log(web3.utils.padLeft('0x123', 10));
  13. * >0x0000000123
  14. * ```
  15. */
  16. export declare const padLeft: (value: Numbers, characterAmount: number, sign?: string) => string;
  17. /**
  18. * Adds a padding on the right of a string, if value is a integer or bigInt will be converted to a hex string.
  19. * @param value - The value to be padded.
  20. * @param characterAmount - The amount of characters the string should have.
  21. * @param sign - The sign to be added (default is 0).
  22. * @returns The padded string.
  23. *
  24. * @example
  25. * ```ts
  26. * console.log(web3.utils.padRight('0x123', 10));
  27. * > 0x1230000000
  28. *
  29. * console.log(web3.utils.padRight('0x123', 10, '1'));
  30. * > 0x1231111111
  31. * ```
  32. */
  33. export declare const padRight: (value: Numbers, characterAmount: number, sign?: string) => string;
  34. /**
  35. * Adds a padding on the right of a string, if value is a integer or bigInt will be converted to a hex string. @alias `padRight`
  36. */
  37. export declare const rightPad: (value: Numbers, characterAmount: number, sign?: string) => string;
  38. /**
  39. * Adds a padding on the left of a string, if value is a integer or bigInt will be converted to a hex string. @alias `padLeft`
  40. */
  41. export declare const leftPad: (value: Numbers, characterAmount: number, sign?: string) => string;
  42. /**
  43. * Converts a negative number into the two’s complement and return a hexstring of 64 nibbles.
  44. * @param value - The value to be converted.
  45. * @param nibbleWidth - The nibble width of the hex string (default is 64).
  46. *
  47. * @returns The hex string of the two’s complement.
  48. *
  49. * @example
  50. * ```ts
  51. * console.log(web3.utils.toTwosComplement(13, 32));
  52. * > 0x0000000000000000000000000000000d
  53. *
  54. * console.log(web3.utils.toTwosComplement('-0x1', 32));
  55. * > 0xffffffffffffffffffffffffffffffff
  56. *
  57. * console.log(web3.utils.toTwosComplement(BigInt('9007199254740992'), 32));
  58. * > 0x00000000000000000020000000000000
  59. * ```
  60. */
  61. export declare const toTwosComplement: (value: Numbers, nibbleWidth?: number) => string;
  62. /**
  63. * Converts the twos complement into a decimal number or big int.
  64. * @param value - The value to be converted.
  65. * @param nibbleWidth - The nibble width of the hex string (default is 64).
  66. * @returns The decimal number or big int.
  67. *
  68. * @example
  69. * ```ts
  70. * console.log(web3.utils.fromTwosComplement(''0x0000000000000000000000000000000d', 32'));
  71. * > 13
  72. *
  73. * console.log(web3.utils.fromTwosComplement('0x00000000000000000020000000000000', 32));
  74. * > 9007199254740992n
  75. * ```
  76. */
  77. export declare const fromTwosComplement: (value: Numbers, nibbleWidth?: number) => number | bigint;