Skip to content

Conversation

@brianfunk
Copy link
Owner

Summary

Adds a REST API server for numberstring, similar to how cAPIta wraps capstring.

Endpoints

  • GET /convert/:number - Convert to words (supports ?lang=es, etc.)
  • GET /ordinal/:number - Convert to ordinal words
  • GET /decimal/:number - Convert decimals to words
  • GET /currency/:amount - Currency to words
  • GET /roman/:number - Roman numerals
  • GET /parse/:words - Parse words back to number
  • GET /comma/:number - Format with commas
  • GET /languages - List supported languages

Usage

cd server && npm install && npm start
# Server runs on port 3456
curl http://localhost:3456/convert/42
# {"input":"42","output":"forty-two","lang":"en"}

Note

Server is excluded from npm package via .npmignore - it's repo-only.

Test plan

  • All endpoints tested manually
  • Quadrillion works correctly
  • Multi-language support works
  • CI should pass

🤖 Generated with Claude Code

brianfunk and others added 2 commits February 1, 2026 01:09
- GET /convert/:number - Convert to words (supports ?lang=es, etc.)
- GET /ordinal/:number - Convert to ordinal
- GET /decimal/:number - Convert decimals
- GET /currency/:amount - Currency to words
- GET /roman/:number - Roman numerals
- GET /parse/:words - Parse words to number
- GET /comma/:number - Format with commas
- GET /languages - List supported languages

Server runs on port 3456 (configurable via PORT env var)
Excluded from npm package via .npmignore

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 523559041e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const { number } = req.params;
const { lang, cap: capStyle, punc } = req.query;

const num = number.includes('n') ? BigInt(number.replace('n', '')) : parseInt(number, 10);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Guard BigInt parsing to avoid 500s on bad inputs

Inputs that contain the character n but are not valid BigInt literals (e.g., /convert/none or /convert/ten) will hit BigInt(number.replace('n','')) and throw a synchronous exception. Express will turn that into a 500 instead of the intended 400, so malformed inputs containing n behave differently from other invalid numbers. This same pattern appears in /comma/:number as well. Consider validating with a strict regex and returning 400 on failure or wrapping the BigInt conversion in a try/catch.

Useful? React with 👍 / 👎.

Comment on lines +83 to +92
const { lang, cap: capStyle, punc } = req.query;

const num = number.includes('n') ? BigInt(number.replace('n', '')) : parseInt(number, 10);

const opt = {};
if (lang) opt.lang = lang;
if (capStyle) opt.cap = capStyle;
if (punc) opt.punc = punc;

const result = lang ? toWords(num, opt) : numberstring(num, opt);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve punctuation option when lang is supplied

When a caller includes lang in the query string, the handler switches from numberstring() to toWords(). toWords() only applies cap and ignores punc, so requests like /convert/42?lang=en&punc=! silently drop the punctuation. This is surprising for clients that always send lang and expect the documented punc option to work. Either keep using numberstring() for English or apply punctuation after toWords() as well.

Useful? React with 👍 / 👎.

@brianfunk brianfunk merged commit 76adb13 into master Feb 1, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants