
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
@txnlab/utils-ts
Advanced tools
Utility library for Algorand development providing asset amount handling with precision and formatting utilities
Utility library for Algorand development providing asset amount handling and formatting utilities.
# npm
npm install @txnlab/utils-ts
# yarn
yarn add @txnlab/utils-ts
# pnpm
pnpm add @txnlab/utils-ts
Utility class for safe, explicit conversion between microunits and standard units of Algorand Standard Assets. Based on and intended as a companion to the AlgoAmount class in AlgoKit Utils, but extended to support any Algorand Standard Asset:
import { AssetAmount } from '@txnlab/utils-ts'
// Asset information
const asset = {
id: 123,
decimals: 6,
unitName: 'XYZ',
name: 'XYZ Token',
}
// Create from standard units (e.g. 5.5)
const amount = AssetAmount.StandardUnits(asset, 5.5)
console.log(amount.microUnits) // 5500000n
// Create from microunits
const amount2 = AssetAmount.MicroUnits(asset, 5500000n)
console.log(amount2.standardUnits) // 5.5
// Arithmetic operations
const sum = amount.add(amount2)
const difference = amount.subtract(amount2)
const doubled = amount.multiply(2)
const halved = amount.divide(2)
// Formatting
console.log(amount.format()) // "5.5"
console.log(amount.format({ showSymbol: true })) // "5.5 XYZ"
import { formatNumber, formatShortAddress } from '@txnlab/utils-ts'
// Number formatting
formatNumber(1234.56) // "1,234.56"
formatNumber(1500000, { compact: true }) // "1.5M"
formatNumber(0.00001, { adaptiveDecimals: true }) // "0.00001"
// Algorand address formatting
const address = '2UEQTE5QDNXPI7M3TU44G6SYKLFWLPQO7EBZM7K7MHMQQMFI4QJPLHQFHM'
formatShortAddress(address) // "2UEQT...HQFHM"
// Types
interface AssetInfo {
id: number | bigint;
decimals: number;
unitName?: string;
name?: string;
}
// Static constructors
AssetAmount.StandardUnits(assetInfo: AssetInfo, amount: number | BigNumber | string): AssetAmount
AssetAmount.MicroUnits(assetInfo: AssetInfo, amount: bigint | number | BigNumber | string): AssetAmount
AssetAmount.zero(assetInfo: AssetInfo): AssetAmount
AssetAmount.fromCurrency(assetInfo: AssetInfo, currencyAmount: number | BigNumber | string, assetPrice: number | BigNumber | string): AssetAmount
// Instance properties
amount.microUnits: bigint
amount.standardUnits: number
amount.microBigNum: BigNumber
amount.standardBigNum: BigNumber
amount.decimals: number
amount.assetId: number | bigint
amount.assetInfo: AssetInfo
// Instance methods
amount.add(other: AssetAmount): AssetAmount
amount.subtract(other: AssetAmount): AssetAmount
amount.multiply(scalar: number | BigNumber | string): AssetAmount
amount.divide(scalar: number | BigNumber | string): AssetAmount
amount.round(decimalPlaces?: number, roundingMode?: BigNumber.RoundingMode): AssetAmount
amount.percentageOf(other: AssetAmount): number
amount.format(options?: { showSymbol?: boolean, symbol?: string, decimalPlaces?: number, showMicrounits?: boolean, trimZeroes?: boolean }): string
amount.isZero(): boolean
amount.isPositive(): boolean
amount.isNegative(): boolean
amount.isGreaterThan(other: AssetAmount): boolean
amount.isLessThan(other: AssetAmount): boolean
amount.isGreaterThanOrEqualTo(other: AssetAmount): boolean
amount.isLessThanOrEqualTo(other: AssetAmount): boolean
amount.equals(other: AssetAmount): boolean
amount.toString(): string
amount.valueOf(): number
amount.toJSON(): { assetInfo: AssetInfo, microUnits: string }
// Format a number with various options
formatNumber(
amount: string | number | bigint,
options?: {
style?: 'currency' | 'decimal';
compact?: boolean | 'auto';
fractionDigits?: number;
adaptiveDecimals?: boolean;
}
): string
// Round a number to the first non-zero decimal place
roundToFirstNonZeroDecimal(num: number): number
// Format an Algorand address to show first and last few characters
formatShortAddress(
address?: string | null,
prefixLength?: number,
suffixLength?: number
): string
MIT License
FAQs
Utility library for Algorand development providing asset amount handling with precision and formatting utilities
We found that @txnlab/utils-ts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.