{"id":31805100,"url":"https://github.com/shahradelahi/compact-number","last_synced_at":"2025-10-12T03:02:02.941Z","repository":{"id":318328538,"uuid":"1070110353","full_name":"shahradelahi/compact-number","owner":"shahradelahi","description":"🔢 A tiny and fast library for compact number formatting and parsing.","archived":false,"fork":false,"pushed_at":"2025-10-06T15:05:09.000Z","size":61,"stargazers_count":3,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-06T15:32:40.911Z","etag":null,"topics":["abbreviate","compact","format","i18n","intl","locale","number"],"latest_commit_sha":null,"homepage":"https://npmjs.com/@se-oss/compact-number","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shahradelahi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-05T09:39:11.000Z","updated_at":"2025-10-06T14:49:30.000Z","dependencies_parsed_at":"2025-10-06T15:33:07.633Z","dependency_job_id":null,"html_url":"https://github.com/shahradelahi/compact-number","commit_stats":null,"previous_names":["shahradelahi/compact-number"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/shahradelahi/compact-number","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fcompact-number","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fcompact-number/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fcompact-number/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fcompact-number/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shahradelahi","download_url":"https://codeload.github.com/shahradelahi/compact-number/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fcompact-number/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005963,"owners_count":26084004,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abbreviate","compact","format","i18n","intl","locale","number"],"created_at":"2025-10-11T02:46:29.242Z","updated_at":"2025-10-11T02:46:30.346Z","avatar_url":"https://github.com/shahradelahi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @se-oss/compact-number\n\n[![CI](https://github.com/shahradelahi/compact-number/actions/workflows/ci.yml/badge.svg?branch=main\u0026event=push)](https://github.com/shahradelahi/compact-number/actions/workflows/ci.yml)\n[![NPM Version](https://img.shields.io/npm/v/@se-oss/compact-number.svg)](https://www.npmjs.com/package/@se-oss/compact-number)\n[![MIT License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat)](/LICENSE)\n[![Install Size](https://packagephobia.com/badge?p=@se-oss/compact-number)](https://packagephobia.com/result?p=@se-oss/compact-number)\n\n_@se-oss/compact-number_ is a lightweight, fast, and highly customizable library for compact number formatting and parsing, offering robust internationalization support.\n\n---\n\n- [Installation](#-installation)\n- [Usage](#-usage)\n- [Advanced Usage](#-advanced-usage)\n- [Documentation](#-documentation)\n- [Using Locales](#-using-locales)\n- [Performance](#-performance)\n- [Contributing](#-contributing)\n- [License](#license)\n\n## 📦 Installation\n\n```bash\nnpm install @se-oss/compact-number\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eInstall using your favorite package manager\u003c/summary\u003e\n\n**pnpm**\n\n```bash\npnpm install @se-oss/compact-number\n```\n\n**yarn**\n\n```bash\nyarn add @se-oss/compact-number\n```\n\n\u003c/details\u003e\n\n## 📖 Usage\n\n### `compactNumber`\n\nFormat a number into a compact, human-readable string.\n\n```typescript\nimport { compactNumber } from '@se-oss/compact-number';\n\nconsole.log('Formatting 1234:', compactNumber(1234));\n// =\u003e 1.2K\n\nconsole.log('Formatting 1500000:', compactNumber(1500000));\n// =\u003e 1.5M\n\nconsole.log(\n  'Formatting -1234 with precision 2:',\n  compactNumber(-1234, { maximumFractionDigits: 2 })\n);\n// =\u003e -1.23K\n```\n\n### `uncompactNumber`\n\nParse a compacted string back into a number.\n\n```typescript\nimport { uncompactNumber } from '@se-oss/compact-number';\n\nconsole.log(uncompactNumber('1.2K'));\n// =\u003e 1200\n\nconsole.log(uncompactNumber('1.5M'));\n// =\u003e 1500000\n\nconsole.log(uncompactNumber('-1.23K'));\n// =\u003e -1230\n```\n\n## 💡 Advanced Usage\n\nYou can dynamically load locales from the `cldr-numbers-full` package instead of bundling them. This is useful for applications that support many languages.\n\nFirst, install the CLDR data package:\n\n```bash\npnpm add cldr-numbers-full\n```\n\n### Loading a Single Locale\n\nTo keep your bundle size small, you can import and register individual locales as needed. This works in any environment.\n\n```typescript\nimport { compactNumber, store } from '@se-oss/compact-number';\n// Import any CLDR locale data directly\nimport ca from 'cldr-numbers-full/main/ca/numbers.json';\n\n// Register the Catalan locale from the raw CLDR data\nstore.registerFromCLDR(ca);\n\n// You can now format numbers using the 'ca' locale\nconsole.log(compactNumber(12345, { locale: 'ca' }));\n// =\u003e 12,3 mil\n```\n\n### Loading All Locales (Node.js)\n\nIn Node.js environments, you can register all available CLDR locales at once using `registerFullCLDR`. This is useful for servers that need to handle many different locales.\n\n```typescript\nimport { compactNumber, store } from '@se-oss/compact-number';\n\n// Register all CLDR locales\nawait store.registerFullCLDR();\n\n// Now you can format numbers in any of the registered locales\nconsole.log(compactNumber(12345, { locale: 'ja' })); // Japanese\n// =\u003e 1.2万\n\nconsole.log(compactNumber(54321, { locale: 'fr' })); // French\n// =\u003e 54,3 k\n```\n\n**Note:** This function only works in Node.js. It will throw an error in the browser to prevent bundling the entire `cldr-numbers-full` package.\n\n## 🌍 Using Locales\n\nBy default, only the `en` locale is registered. To use other locales, you must import and register them. This ensures that unused locales are not included in your final bundle.\n\n```typescript\nimport { compactNumber, es, store } from '@se-oss/compact-number';\n\n// Register the Spanish (es) locale\nstore.register(es);\n\nconsole.log(compactNumber(1234, { locale: 'es' }));\n// =\u003e 1.2 mil\n```\n\n## 📚 Documentation\n\nFor all configuration options, please see [the API docs](https://www.jsdocs.io/package/@se-oss/compact-number).\n\n## 🚀 Performance\n\n_@se-oss/compact-number_ is designed for speed. Our benchmarks show it's significantly faster than `Intl.NumberFormat` for compact number formatting.\n\n| Library                    | Operations/second (hz) |\n| :------------------------- | :--------------------- |\n| `@se-oss/compact-number`   | 274,863.69             |\n| `Intl.NumberFormat`        | 22,298.90              |\n| **Performance Difference** | **~12.33x faster**     |\n\n_Benchmark script: [`src/index.bench.ts`](src/index.bench.ts)_\n\n## 🤝 Contributing\n\nWant to contribute? Awesome! To show your support is to star the project, or to raise issues on [GitHub](https://github.com/shahradelahi/compact-number)\n\nThanks again for your support, it is much appreciated! 🙏\n\n## License\n\n[MIT](/LICENSE) © [Shahrad Elahi](https://github.com/shahradelahi) and [contributors](https://github.com/shahradelahi/compact-number/graphs/contributors).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshahradelahi%2Fcompact-number","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshahradelahi%2Fcompact-number","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshahradelahi%2Fcompact-number/lists"}