{"_id":"@0fprod/smart-amount","_rev":"2-9b3364eacf7a8a8a444714067885fcea","name":"@0fprod/smart-amount","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.0":{"name":"@0fprod/smart-amount","version":"1.0.0","keywords":["number-formatting","currency","percentage","token","formatter","typescript","intl","compact-notation","finance","crypto","web3"],"author":{"name":"0fprod","email":"franp.dev@protonmail.com"},"license":"MIT","_id":"@0fprod/smart-amount@1.0.0","maintainers":[{"name":"0fprod","email":"franp.dev@protonmail.com"}],"homepage":"https://github.com/0fprod/smart-amount#readme","bugs":{"url":"https://github.com/0fprod/smart-amount/issues"},"dist":{"shasum":"a44ecbdd99bf559b428364aeea56b568fcdac212","tarball":"https://registry.npmjs.org/@0fprod/smart-amount/-/smart-amount-1.0.0.tgz","fileCount":36,"integrity":"sha512-uSw13/Xve6Ynby2BG7XRxuCFblJmU5Zzv96s0BI8krG/M/zmVMVGraEAGKqUj9WMPosYLPqnGF7R2oYy+0NMeA==","signatures":[{"sig":"MEYCIQD27p9ZSxojA9Jh0qv3SQKZU7WU6xmOkXqVf8uJ3UNxngIhAIaNIXO5nMw5eU4FurEiI16Pw+kVkrPL1tbJoUx9QlAE","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":30997},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.js","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"}},"gitHead":"ca73a6beece72975cdc29824d819875dfbf14943","scripts":{"dev":"tsc --watch","lint":"eslint src tests --ext .ts","test":"jest","build":"tsc","clean":"rm -rf dist coverage","format":"prettier --write .","prepare":"husky install","lint:fix":"eslint src tests --ext .ts --fix","test:watch":"jest --watch","type-check":"tsc --noEmit","format:check":"prettier --check .","test:coverage":"jest --coverage","prepublishOnly":"npm run type-check && npm run lint && npm test && npm run build"},"_npmUser":{"name":"0fprod","email":"franp.dev@protonmail.com"},"repository":{"url":"git+https://github.com/0fprod/smart-amount.git","type":"git"},"_npmVersion":"10.9.0","description":"A flexible TypeScript library for formatting numbers as currency, percentages, tokens, and raw values with intelligent small number handling","directories":{},"lint-staged":{"*.{js,ts,tsx}":["eslint --fix","prettier --write"],"*.{json,md,css,scss}":["prettier --write"]},"_nodeVersion":"22.12.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","husky":"^9.1.7","eslint":"^8.54.0","ts-jest":"^29.1.1","prettier":"^3.6.2","typescript":"^5.3.2","@types/jest":"^29.5.8","lint-staged":"^16.1.4","@commitlint/cli":"^19.8.1","@typescript-eslint/parser":"^6.12.0","@commitlint/config-conventional":"^19.8.1","@typescript-eslint/eslint-plugin":"^6.12.0"},"_npmOperationalInternal":{"tmp":"tmp/smart-amount_1.0.0_1754341055011_0.12623460423080934","host":"s3://npm-registry-packages-npm-production"}},"2.0.0":{"name":"@0fprod/smart-amount","version":"2.0.0","description":"A flexible TypeScript library for formatting numbers as currency, percentages, tokens, and raw values with intelligent small number handling","main":"dist/index.js","module":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"}},"scripts":{"build":"tsc","dev":"tsc --watch","test":"jest","test:watch":"jest --watch","test:coverage":"jest --coverage","lint":"eslint src tests --ext .ts","lint:fix":"eslint src tests --ext .ts --fix","type-check":"tsc --noEmit","prepublishOnly":"npm run type-check && npm run lint && npm test && npm run build","clean":"rm -rf dist coverage","prepare":"husky install","format":"prettier --write .","format:check":"prettier --check ."},"keywords":["number-formatting","currency","percentage","token","formatter","typescript","intl","compact-notation","finance","crypto","web3"],"author":{"name":"0fprod","email":"franp.dev@protonmail.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/0fprod/smart-amount.git"},"bugs":{"url":"https://github.com/0fprod/smart-amount/issues"},"homepage":"https://github.com/0fprod/smart-amount#readme","devDependencies":{"@commitlint/cli":"^19.8.1","@commitlint/config-conventional":"^19.8.1","@types/jest":"^29.5.8","@typescript-eslint/eslint-plugin":"^6.12.0","@typescript-eslint/parser":"^6.12.0","eslint":"^8.54.0","husky":"^9.1.7","jest":"^29.7.0","lint-staged":"^16.1.4","prettier":"^3.6.2","ts-jest":"^29.1.1","typescript":"^5.3.2"},"engines":{"node":">=18.0.0"},"publishConfig":{"access":"public"},"lint-staged":{"*.{js,ts,tsx}":["eslint --fix","prettier --write"],"*.{json,md,css,scss}":["prettier --write"]},"_id":"@0fprod/smart-amount@2.0.0","gitHead":"32a11a1a6c0ee5e974803b0a4ccfeda978e09cc0","_nodeVersion":"22.12.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-/R4BjTdSV2ajYfc8GBZ78wfmEdHNn7oNle9DugrblXVp08a+VFqkzCsAcPzdQPAbS+X1pByIKvZiXn275QNH0w==","shasum":"54a476c07a599259fb4ee537be66ccd0500f9cac","tarball":"https://registry.npmjs.org/@0fprod/smart-amount/-/smart-amount-2.0.0.tgz","fileCount":36,"unpackedSize":28396,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDfm6dKb3yHy/d1moAnwjSOqku2TOybZyH82NEqyvS9egIgd3ihpwY1bnwhvfS8IRqOKzIg7Rb5oZ7yujZWPVuwFu0="}]},"_npmUser":{"name":"0fprod","email":"franp.dev@protonmail.com"},"directories":{},"maintainers":[{"name":"0fprod","email":"franp.dev@protonmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/smart-amount_2.0.0_1754373625816_0.9432865716475736"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-04T20:57:34.888Z","modified":"2025-08-05T06:00:26.170Z","1.0.0":"2025-08-04T20:57:35.174Z","2.0.0":"2025-08-05T06:00:25.985Z"},"bugs":{"url":"https://github.com/0fprod/smart-amount/issues"},"author":{"name":"0fprod","email":"franp.dev@protonmail.com"},"license":"MIT","homepage":"https://github.com/0fprod/smart-amount#readme","keywords":["number-formatting","currency","percentage","token","formatter","typescript","intl","compact-notation","finance","crypto","web3"],"repository":{"type":"git","url":"git+https://github.com/0fprod/smart-amount.git"},"description":"A flexible TypeScript library for formatting numbers as currency, percentages, tokens, and raw values with intelligent small number handling","maintainers":[{"name":"0fprod","email":"franp.dev@protonmail.com"}],"readme":"# Smart Amount\n\n[![CI](https://github.com/0fprod/smart-amount/actions/workflows/ci.yml/badge.svg)](https://github.com/0fprod/smart-amount/actions/workflows/ci.yml)\n[![npm version](https://img.shields.io/npm/v/@0fprod/smart-amount?color=blue)](https://www.npmjs.com/package/@0fprod/smart-amount)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)\n\nA flexible TypeScript library for formatting numbers as currency, percentages, tokens, and raw values with intelligent small number handling and multi-currency support.\n\n## Installation\n\n```bash\nnpm install @0fprod/smart-amount\n```\n\n## Usage\n\n```typescript\nimport { format } from '@0fprod/smart-amount';\n\n// Currency formatting with multi-currency support\nformat(1234.56, { type: 'currency' });\n// Output: \"$1,234.56\"\n\nformat(1234.56, { locale: 'en-US', currency: 'EUR' });\n// Output: \"€1,234.56\"\n\nformat(1234.56, { locale: 'de-DE', currency: 'EUR' });\n// Output: \"1.234,56 €\"\n\nformat(1234.56, { locale: 'en-GB', currency: 'GBP' });\n// Output: \"£1,234.56\"\n\n// Percentage formatting\nformat(0.12, { type: 'percentage' });\n// Output: \"0.12%\"\n\nformat(25.5, { type: 'percentage' });\n// Output: \"25.50%\"\n\nformat(1234567, { type: 'percentage', compact: true });\n// Output: \"123.46M%\"\n\n// Token formatting\nformat(0.00001234, { type: 'token', tokenSymbol: 'ETH' });\n// Output: \"0.00001234 ETH\"\n\nformat(1234567, { type: 'token', tokenSymbol: 'BTC', compact: true });\n// Output: \"1.23M BTC\"\n\n// Raw number formatting\nformat(1234567, { type: 'raw' });\n// Output: \"1234567\"\n\n// Small numbers with intelligent handling\nformat(0.000000123, { type: 'currency' });\n// Output: \"$0.000000123\"\n\nformat(0.000000123, { type: 'token', tokenSymbol: 'ETH' });\n// Output: \"0.000000123 ETH\"\n\n// Compact notation for large numbers\nformat(1234567, { type: 'currency', compact: true });\n// Output: \"$1.23M\"\n\nformat(1234567, { type: 'percentage', compact: true });\n// Output: \"1.23M%\"\n\n// Auto-compact based on threshold\nformat(1234567, { type: 'currency', autoCompact: true });\n// Output: \"$1.23M\"\n\nformat(1000, { type: 'currency', autoCompact: true });\n// Output: \"$1,000.00\"\n\n// Show signs for positive values\nformat(1234.56, { type: 'currency', showSign: true });\n// Output: \"+$1,234.56\"\n\nformat(1234.56, { type: 'percentage', showSign: true });\n// Output: \"+1,234.56%\"\n\n// Custom decimal places\nformat(1234.56, { type: 'currency', decimals: 0 });\n// Output: \"$1,235\"\n\nformat(1234.56, { type: 'percentage', decimals: 3 });\n// Output: \"1,234.560%\"\n\n// Significant digits for small numbers\nformat(0.0000123, { type: 'currency', significantDigits: 2 });\n// Output: \"$0.000012\"\n\n// Full decimals for tokens (preserves precision)\nformat(\"123456789.123456789\", { type: 'token', tokenSymbol: 'ETH', fullDecimals: true });\n// Output: \"123,456,789.123456789 ETH\"\n```\n\n## Supported Currencies and Locales\n\nThe library supports multiple currencies with their respective locales:\n\n```typescript\n// Available currencies:\ntype CurrencyCode = 'USD' | 'EUR' | 'GBP' | 'AED' | 'INR' | 'NGN';\n\n// Available locales:\ntype LocaleCode = 'en-US' | 'en-GB' | 'de-DE' | 'es-ES' | 'fr-FR' | 'it-IT' | 'ar-AE' | 'hi-IN' | 'en-NG';\n\n// Examples:\nformat(1234.56, { locale: 'en-US', currency: 'USD' });  // $1,234.56\nformat(1234.56, { locale: 'en-US', currency: 'EUR' });  // €1,234.56\nformat(1234.56, { locale: 'de-DE', currency: 'EUR' });  // 1.234,56 €\nformat(1234.56, { locale: 'en-GB', currency: 'GBP' });  // £1,234.56\nformat(1234.56, { locale: 'en-US', currency: 'AED' });  // AED 1,234.56\nformat(1234.56, { locale: 'en-US', currency: 'INR' });  // ₹1,234.56\nformat(1234.56, { locale: 'en-US', currency: 'NGN' });  // NGN 1,234.56\n```\n\n## Features\n\n- **Multiple format types**: Currency, percentage, token, and raw number formatting\n- **Multi-currency support**: USD, EUR, GBP, AED, INR, NGN with proper locale formatting\n- **Intelligent small number handling**: Automatically switches to scientific notation for very small numbers\n- **Compact notation**: K, M, B suffixes for large numbers\n- **Auto-compact**: Automatically applies compact notation based on threshold\n- **Sign display**: Option to show + sign for positive values\n- **Custom precision**: Configurable decimal places and significant digits\n- **Full decimals**: Preserve full precision for token amounts\n- **Internationalization support**: Uses Intl API for locale-aware formatting\n- **TypeScript support**: Full type definitions included\n- **Zero dependencies**: Lightweight and fast\n- **Comprehensive testing**: 80+ tests covering all functionality\n- **Modular architecture**: Clean separation of concerns with dedicated formatters\n\n## Project Structure\n\nThe library is organized with a clean, modular architecture:\n\n```\nsrc/\n├── index.ts              # Main entry point (re-exports everything)\n├── types.ts              # TypeScript interfaces and types\n├── constants.ts          # Constants and configurations\n├── utils.ts              # Utility functions\n├── formatters/\n│   ├── index.ts          # Main format function\n│   ├── currency.ts       # Currency formatting logic\n│   ├── percentage.ts     # Percentage formatting logic\n│   ├── token.ts          # Token formatting logic\n│   └── raw.ts           # Raw number formatting logic\n└── helpers/\n    └── small-numbers.ts  # Small number handling logic\n```\n\n## API\n\n### `format(value: number | string, options?: FormatNumbersOptions): string`\n\nFormats a number according to the specified options.\n\n#### Options\n\n- `type`: The format type ('currency', 'percentage', 'token', 'raw')\n- `locale`: Locale code for formatting (e.g., 'en-US', 'de-DE')\n- `currency`: Currency code for currency formatting (e.g., 'USD', 'EUR')\n- `decimals`: Number of decimal places (default: 2)\n- `compact`: Use compact notation for large numbers\n- `autoCompact`: Automatically apply compact notation based on threshold\n- `compactThreshold`: Threshold for auto-compact (default: 10000)\n- `tokenSymbol`: Token symbol for token formatting\n- `significantDigits`: Number of significant digits for small numbers\n- `showSign`: Show + sign for positive values and - for negative values\n- `rounded`: Round small numbers to zero\n- `fullDecimals`: Preserve full decimal precision for tokens\n\n## Development\n\n### Running Tests\n\n```bash\nnpm test              # Run all tests\nnpm run test:watch    # Run tests in watch mode\nnpm run test:coverage # Run tests with coverage report\n```\n\n### Building\n\n```bash\nnpm run build         # Build for production\nnpm run dev           # Build in watch mode\n```\n\n## License\n\nMIT ","readmeFilename":"README.md"}