Skip to content

Commit

Permalink
chore: value tsdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Aug 28, 2024
1 parent 5797217 commit 3578825
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/internal/value/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import type { GlobalErrorType } from '../errors/error.js'
* Formats a `bigint` Value to its string representation (divided by the given exponent).
*
* @example
* ```ts
* ```ts twoslash
* import { Value } from 'ox'
*
* Value.format(420_000_000_000n, 9)
* // '420'
* // @log: '420'
* ```
*
* @param value - The `bigint` Value to format.
* @param decimals - The exponent to divide the `bigint` Value by.
* @returns The string representation of the Value.
*/
export function Value_format(value: bigint, decimals = 0) {
let display = value.toString()
Expand Down
10 changes: 6 additions & 4 deletions src/internal/value/formatEther.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import { Value_format } from './format.js'
/**
* Formats a `bigint` Value (default: wei) to a string representation of Ether.
*
* - Docs: https://oxlib.sh/api/value/formatEther
*
* @example
* ```ts
* ```ts twoslash
* import { Value } from 'ox'
*
* Value.formatEther(1_000_000_000_000_000_000n)
* // '1'
* // @log: '1'
* ```
*
* @param wei - The Value to format.
* @param unit - The unit to format the Value in. @default 'wei'.
* @returns The Ether string representation of the Value.
*/
export function Value_formatEther(
wei: bigint,
Expand Down
10 changes: 6 additions & 4 deletions src/internal/value/formatGwei.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import { Value_format } from './format.js'
/**
* Formats a `bigint` Value (default: wei) to a string representation of Gwei.
*
* - Docs: https://oxlib.sh/api/value/formatGwei
*
* @example
* ```ts
* ```ts twoslash
* import { Value } from 'ox'
*
* Value.formatGwei(1_000_000_000n)
* // '1'
* // @log: '1'
* ```
*
* @param wei - The Value to format.
* @param unit - The unit to format the Value in. @default 'wei'.
* @returns The Gwei string representation of the Value.
*/
export function Value_formatGwei(wei: bigint, unit: 'wei' = 'wei') {
return Value_format(wei, Value_exponents.gwei - Value_exponents[unit])
Expand Down
8 changes: 6 additions & 2 deletions src/internal/value/from.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import type { GlobalErrorType } from '../errors/error.js'
* Parses a `string` representation of a Value to `bigint` (multiplied by the given exponent).
*
* @example
* ```ts
* ```ts twoslash
* import { Value } from 'ox'
*
* Value.from('420', 9)
* // 420000000000n
* // @log: 420000000000n
* ```
*
* @param value - The string representation of the Value.
* @param decimals - The exponent to multiply the Value by.
* @returns The `bigint` representation of the Value.
*/
export function Value_from(value: string, decimals = 0) {
let [integer = '', fraction = '0'] = value.split('.')
Expand Down
10 changes: 6 additions & 4 deletions src/internal/value/fromEther.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import { Value_from } from './from.js'
/**
* Parses a string representation of Ether to a `bigint` Value (default: wei).
*
* - Docs: https://oxlib.sh/api/value/fromEther
*
* @example
* ```ts
* ```ts twoslash
* import { Value } from 'ox'
*
* Value.fromEther('420')
* // 420000000000000000000n
* // @log: 420000000000000000000n
* ```
*
* @param ether - String representation of Ether.
* @param unit - The unit to parse to. @default 'wei'.
* @returns A `bigint` Value.
*/
export function Value_fromEther(
ether: string,
Expand Down
12 changes: 8 additions & 4 deletions src/internal/value/fromGwei.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ import { Value_from } from './from.js'
* Parses a string representation of Gwei to a `bigint` Value (default: wei).
*
* @example
* ```ts
* ```ts twoslash
* import { Value } from 'ox'
*
* Value.fromGwei('420')
* // 420000000000n
* // @log: 420000000000n
* ```
*
* @param gwei - String representation of Gwei.
* @param unit - The unit to parse to. @default 'wei'.
* @returns A `bigint` Value.
*/
export function Value_fromGwei(ether: string, unit: 'wei' = 'wei') {
return Value_from(ether, Value_exponents.gwei - Value_exponents[unit])
export function Value_fromGwei(gwei: string, unit: 'wei' = 'wei') {
return Value_from(gwei, Value_exponents.gwei - Value_exponents[unit])
}

export declare namespace Value_fromGwei {
Expand Down

0 comments on commit 3578825

Please sign in to comment.