Skip to content

feat(formatjs_cli): add base62 support#5996

Closed
longlho wants to merge 1 commit intomainfrom
01-29-feat_formatjs_cli_add_base62_support
Closed

feat(formatjs_cli): add base62 support#5996
longlho wants to merge 1 commit intomainfrom
01-29-feat_formatjs_cli_add_base62_support

Conversation

@longlho
Copy link
Member

@longlho longlho commented Jan 29, 2026

TL;DR

Added support for base62 encoding in message ID generation to provide alphanumeric-only IDs.

What changed?

  • Implemented a new encode_base62 function to encode hash digests using only alphanumeric characters (0-9, A-Z, a-z)
  • Updated the generate_id function to support three distinct encoding options:
    • base64: Standard base64 encoding (may contain +/)
    • base64url: URL-safe base64 encoding (uses -_ instead of +/)
    • base62: Alphanumeric-only encoding (0-9, A-Z, a-z)
  • Added comprehensive tests for the new base62 encoding and clarified differences between encoding types
  • Fixed documentation to reflect the new encoding options

How to test?

Run the new tests that verify:

  • Base62 encoding produces alphanumeric-only IDs
  • Base62 IDs are deterministic (same input produces same ID)
  • Base62 encoding produces different output than base64 and hex
  • Base62 encoding works with various ID lengths

You can also manually test by running the CLI with a pattern like:

formatjs extract --id-interpolation-pattern "[sha512:contenthash:base62:10]" --out-file messages.json source.js

Why make this change?

Base62 encoding provides several advantages:

  • Creates IDs that are alphanumeric-only, making them safer to use in various contexts
  • Avoids special characters (+/=) from base64 and base64url that might require escaping in some environments
  • Provides a more compact representation than hex encoding while maintaining compatibility with systems that only support alphanumeric characters

@longlho longlho marked this pull request as ready for review January 29, 2026 20:00
Copy link
Member Author

longlho commented Jan 29, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • main - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has required the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@longlho longlho force-pushed the 01-29-feat_formatjs_cli_add_base62_support branch 2 times, most recently from 0268d8a to c3e77ca Compare January 29, 2026 20:05
@longlho longlho force-pushed the 01-29-feat_formatjs_cli_add_base62_support branch from c3e77ca to 4696c41 Compare January 29, 2026 20:05
@graphite-app
Copy link

graphite-app bot commented Jan 29, 2026

Merge activity

  • Jan 29, 8:09 PM UTC: longlho added this pull request to the Graphite merge queue.
  • Jan 29, 8:09 PM UTC: CI is running for this pull request on a draft pull request (#5997) due to your merge queue CI optimization settings.
  • Jan 29, 8:12 PM UTC: Merged by the Graphite merge queue via draft PR: #5997.

graphite-app bot pushed a commit that referenced this pull request Jan 29, 2026
### TL;DR

Added support for base62 encoding in message ID generation to provide alphanumeric-only IDs.

### What changed?

- Implemented a new `encode_base62` function to encode hash digests using only alphanumeric characters (0-9, A-Z, a-z)
- Updated the `generate_id` function to support three distinct encoding options:
  - `base64`: Standard base64 encoding (may contain +/)
  - `base64url`: URL-safe base64 encoding (uses -_ instead of +/)
  - `base62`: Alphanumeric-only encoding (0-9, A-Z, a-z)
- Added comprehensive tests for the new base62 encoding and clarified differences between encoding types
- Fixed documentation to reflect the new encoding options

### How to test?

Run the new tests that verify:
- Base62 encoding produces alphanumeric-only IDs
- Base62 IDs are deterministic (same input produces same ID)
- Base62 encoding produces different output than base64 and hex
- Base62 encoding works with various ID lengths

You can also manually test by running the CLI with a pattern like:
```
formatjs extract --id-interpolation-pattern "[sha512:contenthash:base62:10]" --out-file messages.json source.js
```

### Why make this change?

Base62 encoding provides several advantages:
- Creates IDs that are alphanumeric-only, making them safer to use in various contexts
- Avoids special characters (+/=) from base64 and base64url that might require escaping in some environments
- Provides a more compact representation than hex encoding while maintaining compatibility with systems that only support alphanumeric characters
@graphite-app graphite-app bot closed this Jan 29, 2026
@graphite-app graphite-app bot deleted the 01-29-feat_formatjs_cli_add_base62_support branch January 29, 2026 20:12
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.

1 participant