{"id":18075747,"url":"https://github.com/oleiade/colbert","last_synced_at":"2026-01-30T06:11:48.268Z","repository":{"id":258267661,"uuid":"872835536","full_name":"oleiade/colbert","owner":"oleiade","description":"Money handling library in Typescript","archived":false,"fork":false,"pushed_at":"2024-10-23T15:53:33.000Z","size":465,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-11T07:48:29.934Z","etag":null,"topics":["deno","library","money","typescript"],"latest_commit_sha":null,"homepage":"https://jsr.io/@oleiade/colbert","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/oleiade.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}},"created_at":"2024-10-15T06:49:26.000Z","updated_at":"2024-11-14T09:05:51.000Z","dependencies_parsed_at":"2024-10-20T16:23:27.229Z","dependency_job_id":null,"html_url":"https://github.com/oleiade/colbert","commit_stats":null,"previous_names":["oleiade/colbert"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleiade%2Fcolbert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleiade%2Fcolbert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleiade%2Fcolbert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleiade%2Fcolbert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oleiade","download_url":"https://codeload.github.com/oleiade/colbert/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230364982,"owners_count":18214876,"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","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":["deno","library","money","typescript"],"created_at":"2024-10-31T11:07:10.690Z","updated_at":"2026-01-30T06:11:48.216Z","avatar_url":"https://github.com/oleiade.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"logo.png\" alt=\"colbert logo\"/\u003e\u003c/p\u003e\n\u003ch1 align=\"center\"\u003eMoney handling in Typescript\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://choosealicense.com/licenses/mit/\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-green.svg\" alt=\"MIT License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nColbert is a TypeScript-first library designed for precise and currency and monetary operations.\nColbert was built from the ground up for TypeScript, ensuring full type safety, precise financial calculations, and intuitive APIs that eliminate the common pitfalls of floating-point errors and inconsistent rounding.\nEvery operation is designed for financial precision, using banker’s rounding to minimize rounding errors and ensure accurate results, even across multiple currency operations.\n\nIt seamlessly integrates with Deno, Node.js, and browser environments, offering intuitive APIs that prevent floating-point errors.\n\n## Why Colbert?\n\n* Eliminate floating-point precision issues in financial calculations.\n* Built-in currency management with customizable decimal handling.\n* Locale-based formatting for accurate currency display worldwide.\n* TypeScript-first design for full type safety and developer experience.\n\n## Installation\n\nInstall Colbert for TypeScript projects (compatible with Deno, Node.js, and browsers):\n```bash\ndeno add jsr:@oleiade/colbert\n# or for npm\nnpm install @oleiade/colbert\n```\n_For more options like Yarn or Pnpm, see the JSR page._\n\n## Usage\n\nHere is a basic example of how to use the colbert module:\n\n```typescript\nimport { Money, USD, subtract, add } from \"@oleiade/colbert\";\n\n// The Amount class holds the amount of money and the currency\n// in which the amount is expressed.\nconst left = new Money(100, USD);\nconst right = new Money(20, USD);\n\n\n// You can perform basic operations on the Money instances\n// using the dedicated add, subtract, multiply and divide functions. All\n// operations use bankers rounding to ensure the result is as accurate as possible.\n// However, note that the more operations are performed, the more the result\n// will be subject to floating point errors.\n//\n// The result of these operations is a new Money instance.\n//\n// They operation will throw an error if the currencies of the\n// two Money instances do not match.\nconst subtracted = subtract(left, right);\nconst added = add(left, right);\nconst multiplied = multiply(left, 2);\nconst divided = divide(left, 2);\n\n// At any point in time, you can also compute a given percentage of a Money instance\n// using the percentage method.\nconst left.percent(10);\n```\n\n## API\n\n### Types\n\n#### Money\n\nThe Money class is at the core of Colbert, representing precise monetary values in various currencies. It ensures financial accuracy across all operations, making it easy to work with amounts without worrying about floating-point errors or mismatched currencies. It is defined as follows:\n\n| Property   | Type                            | Description                                                                                                                                                                                                                                                                                                                                                        |\n|------------|---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| amount     | number                          | The amount of money, represented as an integer without decimal places. The integer representation avoids issues with floating point precision, especially for calculations involving money. The actual value is scaled based on the currency's decimal places. For example, in USD (which has 2 decimal places), an internal value of 10025 represents 100.25 USD. |\n| currency   | [Currency](#currency)           | The currency in which the amount is expressed. This defines the number of decimal places used when interpreting the `amount` property and formatting the value (_e.g._, 2 decimal places for USD).                                                                                                                                                                 |\n| percentage | `(percentage: number) =\u003e Money` | A method to compute a given percentage of the Money instance. It returns a new Money instance representing the percentage of the original value.                                                                                                                                                                                                                   |\n| format     | `(locale: string) =\u003e string`    | Format your monetary values based on any region, using locale-specific conventions. The format method allows you to display amounts in the correct format for users worldwide, whether in dollars, euros, or any other currency.                                                                                                                                   |\n\n#### Currency\n\nThe `Currency` type represents a currency and is defined as follows:\n\n| Property      | Type                          | Description                                                                      |\n|---------------|-------------------------------|----------------------------------------------------------------------------------|\n| code          | [CurrencyCode](#currencycode) | The ISO4217 currency code (_e.g._: USD, EUR, JPY)                                |\n| decimalPlaces | number                        | The number of decimal places used by the currency (_e.g_: USD has 2, JPY has 0). |\n| name          | string                        | The currency name.                                                               |\n| symbol        | string                        | The currency symbol (_e.g._: $, €, etc.).                                        |\n\nNote that the library exports every ISO4217 currencies as const objects with\nuppercased names, such as `USD`, `EUR`, `JPY`, etc. Ready for your to integrate\nin your code without efforts.\n\n#### CurrencyCode\n\nAn enum representing the currency codes defined by ISO4217, in the form of\n`CurrencyCode.XXX`.\n\n### Operations\n\n| Function | Description                                                                                          |\n|----------|------------------------------------------------------------------------------------------------------|\n| add      | A function to add two Money instances, and returns the result as a new Money instance.               |\n| subtract | A function to subtract two Money instances, and returns the result as a new Money instance.          |\n| multiply | A function to multiply a Money instance by a scalar, and returns the result as a new Money instance. |\n| divide   | A function to divide a Money instance by a scalar, and returns the result as a new Money instance.   |\n\n## License\n\nThis project is licensed under the MIT License.\n\n## Credits \u0026 Copyright\n\nLogo by the incredibly talented\n[Lola Nun](https://www.fiverr.com/lolanun?source=order_page_summary_seller_link).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foleiade%2Fcolbert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foleiade%2Fcolbert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foleiade%2Fcolbert/lists"}