npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@txnlab/utils-ts

v0.1.0

Published

Utility library for Algorand development providing asset amount handling with precision and formatting utilities

Readme

@txnlab/utils-ts

Utility library for Algorand development providing asset amount handling and formatting utilities.

Installation

# npm
npm install @txnlab/utils-ts

# yarn
yarn add @txnlab/utils-ts

# pnpm
pnpm add @txnlab/utils-ts

Features

AssetAmount

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:

  • Prevents precision errors when working with asset amounts
  • Uses BigNumber for precise decimal arithmetic
  • Provides explicit methods for conversion between micro/standard units
  • Makes unit intentions clear in your code
  • Tracks asset ID and other asset information
  • Supports arithmetic, comparison, and formatting operations
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"

Formatting Utilities

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"

API Reference

AssetAmount Class

// 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 Functions

// 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

License

MIT License