Add Japanese Yen (JPY) Currency Display Support#1
Add Japanese Yen (JPY) Currency Display Support#1ml0-1337 wants to merge 4 commits intoryoppippi:mainfrom ml0-1337:feature/add-jpy-currency-display
Conversation
- Add conf dependency for cross-platform config storage - Create config module with currency preference management - Support USD and JPY currency options with persistence 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add currency conversion module with 1:150 exchange rate - Update formatCurrency to support multiple currencies - Format JPY with ¥ symbol and no decimals - Add comma separators for better readability 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add --currency flag to all commands with persistence - Update daily command to use currency-aware formatting - Update session command to use currency-aware formatting - Display appropriate currency label in table headers 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add tests for currency conversion functions - Add tests for configuration persistence - Update existing tests for new formatCurrency signature - Add currency feature documentation to README 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
Hello @zenmush, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
Hello team, gemini-code-assist here to provide a summary of this pull request from @zenmush. This PR introduces support for displaying Claude Code usage costs in Japanese Yen (JPY) in addition to the existing USD display. It adds a --currency flag to the CLI commands (daily and session) allowing users to switch between currencies. The chosen currency preference is persisted across sessions using a new configuration file. The changes involve adding new modules for currency handling and configuration, updating existing command files to use the new currency logic, and updating the README documentation.
Highlights
- JPY Currency Support: Adds the ability to display usage costs in Japanese Yen (JPY) alongside the default USD.
- Persistent Currency Preference: Introduces configuration management using the
conflibrary to save the user's preferred currency across sessions. - CLI
--currencyFlag: Adds a new--currencyflag to thedailyandsessioncommands, allowing users to specify 'USD' or 'JPY' for the output currency. Using this flag also updates the persistent preference. - Currency Conversion and Formatting: Implements logic for converting USD costs to JPY using a fixed rate (1 USD = 150 JPY) and formats the output with the correct currency symbol ($ or ¥) and decimal places (2 for USD, 0 for JPY).
- Improved Number Formatting: Updates currency formatting to use locale-aware methods (
toLocaleString) for better readability with comma separators.
Changelog
Click here to see the changelog
- README.md
- Updated the features list to mention JPY currency support (line 43-44).
- Added examples for using the
--currency JPYflag withdaily(line 112-113) andsession(line 135-136) commands. - Added the
--currencyflag to the list of shared options, including its description and default/persistence behavior (line 149). - Added a new 'Currency Configuration' section explaining the feature, conversion rate, formatting details, and configuration file location (line 194-206).
- bun.lock
- Added
confand@types/confdependencies to the lock file (line 7, 11). - Added various transitive dependencies required by
conf(e.g.,ajv,atomically,debounce-fn,dot-prop,env-paths,json-schema-traverse,json-schema-typed,require-from-string,stubborn-fs,when-exit,type-fest,uint8array-extras) (lines 127, 129, 145, 177, 185, 195, 217, 219, 253, 255, 313, 347, 359, 363, 379).
- Added
- commands/daily.ts
- Imported
getCurrencyLabelfrom./currency.ts(line 10). - Retrieved the selected
currencyfrom command context (line 21). - Updated the table header for the cost column to use
getCurrencyLabelbased on the selected currency (line 69). - Updated calls to
formatCurrencyto pass the selectedcurrency(line 94, 117).
- Imported
- commands/session.ts
- Imported
getCurrencyLabelfrom./currency.ts(line 10). - Retrieved the selected
currencyfrom command context (line 21). - Updated the table header for the cost column to use
getCurrencyLabelbased on the selected currency (line 72). - Updated calls to
formatCurrencyto pass the selectedcurrency(line 111, 138).
- Imported
- config.test.ts
- New file adding unit tests for the configuration module (
config.ts). - Tests cover getting and setting currency preferences ('USD' and 'JPY'), handling invalid currency input, and verifying configuration path (lines 1-62).
- New file adding unit tests for the configuration module (
- config.ts
- New file defining the configuration module.
- Defines
Currencytype andConfigSchemafor storing thecurrencypreference (lines 4-8). - Initializes
Confwith project name 'ccusage', schema validation, and default currency 'USD' (lines 18-24). - Exports
getCurrency,setCurrency, andgetConfigPathfunctions for managing the currency setting (lines 26-39).
- currency.test.ts
- New file adding unit tests for the currency module (
currency.ts). - Tests cover
convertFromUSDfor USD and JPY conversion (1:150 rate) (lines 8-20). - Tests cover
formatCurrencyAmountfor formatting USD (2 decimals, '$') and JPY (0 decimals, '¥'), including handling negative numbers and rounding (lines 23-41). - Tests cover
getCurrencyLabelfor generating table headers (lines 44-48).
- New file adding unit tests for the currency module (
- currency.ts
- New file defining currency conversion and formatting logic.
- Defines constant maps for conversion rates, currency symbols, and decimal places for USD and JPY (lines 3-16).
- Exports
convertFromUSDfunction to convert a USD amount to a target currency (lines 18-24). - Exports
formatCurrencyAmountfunction to format a numeric amount with the correct symbol and decimal places usingtoLocaleString(lines 26-40). - Exports
getCurrencyLabelfunction to generate the table header string for a given currency (lines 42-44).
- package.json
- Added
confas a production dependency (line 57). - Added
@types/confas a dev dependency (line 39). - Updated
trustedDependencieslist (line 55).
- Added
- shared-args.ts
- Imported
Currency,getCurrency, andsetCurrencyfrom./config.ts(line 3). - Added
parseCurrencyArgfunction to validate the input currency string, convert it to uppercase, set the persistent configuration, and return the validated currency type (lines 15-21). - Added the
--currencyargument definition tosharedArgs, using the newparseCurrencyArgfunction and defaulting to the value retrieved from the configuration (lines 49-55).
- Imported
- utils.test.ts
- Updated
formatCurrencytests to accept thecurrencyparameter. - Added tests specifically for formatting amounts in JPY, including conversion and rounding (lines 68-84).
- Updated existing USD tests to pass 'USD' and adjusted expected values to include comma separators due to the change from
toFixedtotoLocaleString(e.g., line 39, 64, 65).
- Updated
- utils.ts
- Imported
Currencyfrom./config.tsandconvertFromUSD,formatCurrencyAmountfrom./currency.ts(lines 1-2). - Modified the
formatCurrencyfunction signature to accept the targetcurrency(line 8). - Updated
formatCurrencyimplementation to first convert the USD amount usingconvertFromUSDand then format the result usingformatCurrencyAmount(lines 12-13).
- Imported
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Costs in Yen now show,
From dollars, they will grow,
Config remembers.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This is a well-executed PR that successfully adds JPY currency support, persistent configuration, and related CLI enhancements. The code is clearly structured, with good separation of concerns in the new config.ts and currency.ts modules. The addition of 13 new tests, covering currency conversion, formatting, and configuration persistence, is excellent and significantly boosts confidence in the changes. The README updates are also clear and helpful.
Regarding the review focus areas you raised:
- Currency Conversion Rate: The hardcoded rate is simple. My comment on
currency.ts(L3-6) offers thoughts on future configurability if precision becomes more critical. - Number Formatting: Using
en-USlocale for JPY is acceptable for consistency. My comment oncurrency.ts(L34) includes a note onja-JPas an alternative for consideration. - Configuration Location: The
conflibrary's default paths are standard and appropriate for this type of application.
Overall, great work on this feature! The code quality is high, and the new functionality is well-integrated.
Summary of Findings
- Hardcoded Currency Conversion Rate: The JPY conversion rate is hardcoded (1 USD = 150 JPY). While simple, this may not reflect real-time values. This was a point of discussion raised by the author and is acceptable for the current scope but could be a future enhancement area if more precision is needed.
- Number Formatting Locale for JPY: JPY amounts are formatted using the 'en-US' locale for number separation and then the '¥' symbol is prepended. This is consistent but differs from native 'ja-JP' currency formatting. This was a point of discussion raised by the author and the current approach is acceptable for consistency.
- Currency Validation: The currency validation logic is present in
parseCurrencyArgandsetCurrency. Consider centralizing it insetCurrencyfor better maintainability.
Merge Readiness
The pull request is in excellent shape and implements the described features effectively. The new tests and clear code structure are commendable. The comments provided are intended for consideration rather than as blockers. I believe this PR is ready for merging. As an AI, I am not authorized to approve pull requests; please ensure it undergoes any further required human review and approval processes.
| const CONVERSION_RATES: Record<Currency, number> = { | ||
| USD: 1, | ||
| JPY: 150, | ||
| }; |
There was a problem hiding this comment.
You asked in the PR description if the hardcoded conversion rate (1 USD = 150 JPY) is acceptable. For a utility tool like this, a fixed rate offers simplicity in implementation and usage.
However, as exchange rates fluctuate, this fixed rate might lead to discrepancies over time if precise, up-to-date cost tracking is a key requirement for users.
Would it be beneficial to consider any of the following for future enhancements if higher accuracy becomes necessary?
- Making the conversion rate configurable in
config.json? - Implementing a mechanism to fetch the current rate dynamically (e.g., from an API, with this hardcoded value as a fallback)?
For the current scope, this fixed rate is clearly defined and implemented as described, which is fine. It's good to acknowledge this limitation or design choice in the documentation (as you've done in the README).
| const formattedAmount = amount.toLocaleString("en-US", { | ||
| minimumFractionDigits: decimals, | ||
| maximumFractionDigits: decimals, | ||
| }); |
There was a problem hiding this comment.
The PR description asks about using toLocaleString('en-US') for formatting both USD and JPY. This approach is perfectly acceptable and ensures a consistent number formatting style (e.g., comma as a thousands separator, period as a decimal separator) across all currency displays, which can be preferable for users accustomed to en-US conventions.
For context, if catering specifically to users who expect idiomatic Japanese number formatting, an alternative for JPY would be to use the ja-JP locale combined with the currency style. For example:
// Example for consideration if ja-JP specific formatting were a requirement
if (currency === 'JPY') {
return amount.toLocaleString('ja-JP', {
style: 'currency',
currency: 'JPY', // ISO currency code for Yen
minimumFractionDigits: decimals, // Would be 0 for JPY
maximumFractionDigits: decimals, // Would be 0 for JPY
});
}
// ... then handle USD or other currencies, or the current en-US based formattingThis would automatically handle the Yen symbol (often ¥ - the full-width version in some ja-JP contexts, though ¥ is also common) and any other locale-specific nuances for JPY.
However, the current implementation is clear, provides good readability with comma separators, and is consistent. It's a sound choice for this tool.
| const parseCurrencyArg = (value: string): Currency => { | ||
| const upperValue = value.toUpperCase() as Currency; | ||
| if (upperValue !== "USD" && upperValue !== "JPY") { | ||
| throw new TypeError(`Invalid currency: ${value}. Must be USD or JPY.`); | ||
| } | ||
| setCurrency(upperValue); | ||
| return upperValue; | ||
| }; |
There was a problem hiding this comment.
The parseCurrencyArg function could be improved by moving the currency validation logic into the setCurrency function. This would centralize the validation and ensure that only valid currency values are stored in the configuration.
const parseCurrencyArg = (value: string): Currency => {
const upperValue = value.toUpperCase() as Currency;
setCurrency(upperValue);
return upperValue;
};|
I don't want to support other currencies because of maintenance cost |
|
@zenmush I recommend to fork this repo and modify by yourseld. |
Overview
This PR adds support for displaying Claude Code usage costs in Japanese Yen (JPY) alongside the existing USD display. Users can now switch between USD and JPY with a persistent preference that is maintained across sessions.
Changes
Main Changes
conflibrary for cross-platform support--currencyflag to all commands for easy currency switchingTechnical Details
utils.ts- UpdatedformatCurrency()to support multiple currenciescommands/daily.ts&commands/session.ts- Integrated currency-aware formattingshared-args.ts- Added--currencyCLI argumentREADME.md- Added currency feature documentationconfig.ts- Configuration management modulecurrency.ts- Currency conversion and formatting logicconfig.test.ts¤cy.test.ts- Comprehensive test coverageconf@13.1.0for configuration storage@types/conf@3.0.3for TypeScript support~/.config/ccusage/config.json, Windows:%APPDATA%\ccusage\config.json)Impact
Testing
Test Details
formatCurrencysignatureDeployment
Review Focus Areas
toLocaleString('en-US')for both currencies - should JPY use a different locale?conflibrary's default paths - are these appropriate for the project?Related Information
Example output with JPY display:
Checklist
EOF < /dev/null