{"id":26234292,"url":"https://github.com/tamtamchik/exchanger","last_synced_at":"2025-04-22T12:29:38.226Z","repository":{"id":63182949,"uuid":"565189264","full_name":"tamtamchik/exchanger","owner":"tamtamchik","description":"Simple and free npm library to get realtime currency exchange rates.","archived":false,"fork":false,"pushed_at":"2024-10-09T15:21:28.000Z","size":492,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T04:26:51.812Z","etag":null,"topics":["currency","exchange-rates","keyless","package","yahoo-finance"],"latest_commit_sha":null,"homepage":"","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/tamtamchik.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":"2022-11-12T16:07:30.000Z","updated_at":"2024-10-10T01:09:42.000Z","dependencies_parsed_at":"2024-07-23T11:55:09.300Z","dependency_job_id":"22aef810-c4e9-4e7e-9e99-1a6afcaf41c9","html_url":"https://github.com/tamtamchik/exchanger","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"6570491e4057906a9dd635a1546702986030d91e"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamtamchik%2Fexchanger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamtamchik%2Fexchanger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamtamchik%2Fexchanger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamtamchik%2Fexchanger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tamtamchik","download_url":"https://codeload.github.com/tamtamchik/exchanger/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250240640,"owners_count":21397843,"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":["currency","exchange-rates","keyless","package","yahoo-finance"],"created_at":"2025-03-13T01:29:50.818Z","updated_at":"2025-04-22T12:29:38.172Z","avatar_url":"https://github.com/tamtamchik.png","language":"TypeScript","funding_links":["https://www.buymeacoffee.com/tamtamchik"],"categories":[],"sub_categories":[],"readme":"# Exchanger\n\n[![Buy Me A Coffee][ico-coffee]][link-coffee]\n[![Latest Version on NPM][ico-version]][link-npm]\n[![Scrutinizer build][ico-scrutinizer-build]][link-scrutinizer]\n[![Scrutinizer quality][ico-scrutinizer-quality]][link-scrutinizer]\n[![Scrutinizer coverage][ico-scrutinizer-coverage]][link-scrutinizer]\n[![Software License][ico-license]](LICENSE)\n[![Total Downloads][ico-downloads]][link-downloads]\n\nThis package provides functionality to fetch the exchange rates of different currencies using Yahoo Finance APIs.\n\n## Installation\n\nUsing npm:\n\n```shell\nnpm install @tamtamchik/exchanger\n```\n\nUsing yarn:\n\n```shell\nyarn add @tamtamchik/exchanger\n```\n\n## Usage\n\nImport Exchanger in your TypeScript file:\n\n```typescript\nimport { getExchangeRate } from \"@tamtamchik/exchanger\";\n\nasync function fetchRate() {\n  try {\n    const rate = await getExchangeRate(\"USD\", \"EUR\");\n    console.log(`Exchange rate from USD to EUR: ${rate}`);\n  } catch (error) {\n    console.error(`Failed to fetch the exchange rate: ${error.message}`);\n  }\n}\n\nfetchRate();\n```\n\n## Caching\n\nTo improve performance and reduce the number of requests made to the API, you can use the built-in caching feature.\nBy default, caching is **_disabled_**. You can enable and customize caching by passing an options object to the `getExchangeRate` function:\n\n```javascript\n// Cache for 1 hour (3600000 milliseconds)\nconst rate = await getExchangeRate(\"USD\", \"EUR\", { cacheDurationMs: 3600000 });\n```\n\nOnce a rate is fetched, it's stored in an in-memory cache.\nIf you fetch the same rate within the specified caching duration, the cached rate is returned instead ofmaking a new API call.\n\n## Error Handling\n\nThis package defines the following error classes for better error handling:\n\n- `NetworkError`: Thrown when there is a network problem and the request cannot be made.\n- `ServerError`: Thrown when the service does not return a HTTP 200 response.\n- `DataError`: Thrown when the service does not return the expected data structure.\n\nEach error class extends the built-in Error class, so you can use instanceof to check the error type.\n\n```typescript\nimport {\n  ServerError,\n  NetworkError,\n  DataError,\n  getExchangeRate,\n} from \"@tamtamchik/exchanger\";\n\nasync function fetchRate() {\n  try {\n    const rate = await getExchangeRate(\"USD\", \"EUR\");\n    console.log(`Exchange rate from USD to EUR: ${rate}`);\n  } catch (error) {\n    if (error instanceof NetworkError) {\n      console.error(\"Network problem:\", error.message);\n    } else if (error instanceof ServerError) {\n      console.error(\"Backend problem:\", error.message);\n    } else if (error instanceof DataError) {\n      console.error(\"Unexpected response data:\", error.message);\n    } else {\n      console.error(\"Unknown error:\", error.message);\n    }\n  }\n}\n\nfetchRate();\n```\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\n## License\n\nExchanger is [MIT licensed](./LICENSE).\n\n[ico-coffee]: https://img.shields.io/badge/Buy%20Me%20A-Coffee-%236F4E37.svg?style=flat-square\n[ico-version]: https://img.shields.io/npm/v/@tamtamchik/exchanger.svg?style=flat-square\n[ico-license]: https://img.shields.io/npm/l/@tamtamchik/exchanger.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/npm/dt/@tamtamchik/exchanger.svg?style=flat-square\n[ico-scrutinizer-build]: https://img.shields.io/scrutinizer/build/g/tamtamchik/exchanger/main.svg?style=flat-square\n[ico-scrutinizer-quality]: https://img.shields.io/scrutinizer/quality/g/tamtamchik/exchanger/main.svg?style=flat-square\n[ico-scrutinizer-coverage]: https://img.shields.io/scrutinizer/coverage/g/tamtamchik/exchanger/main.svg?style=flat-square\n[link-coffee]: https://www.buymeacoffee.com/tamtamchik\n[link-npm]: https://www.npmjs.com/package/@tamtamchik/exchanger\n[link-downloads]: https://www.npmjs.com/package/@tamtamchik/exchanger\n[link-scrutinizer]: https://scrutinizer-ci.com/g/tamtamchik/exchanger/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftamtamchik%2Fexchanger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftamtamchik%2Fexchanger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftamtamchik%2Fexchanger/lists"}