SCREAMING_SNAKE_CASE Converter
SCREAMING_SNAKE_CASE writes HELLO_WORLD_EXAMPLE. It is the convention for constants in virtually every language and for environment variable names, where POSIX effectively requires uppercase with underscores.
Conversions
| Input | SCREAMING_SNAKE_CASE |
|---|---|
hello world example | HELLO_WORLD_EXAMPLE |
XMLHttpRequest | XML_HTTP_REQUEST |
user_first_name | USER_FIRST_NAME |
Total Order Count | TOTAL_ORDER_COUNT |
XMLHttpRequest becomes XML_HTTP_REQUEST. The conversion is lossy in one direction ā DB_URL could have come from dbUrl or DBUrl, and nothing in the output says which.The Same Text in Other Cases
| Case | Result |
|---|---|
| camelCase | helloWorldExample |
| PascalCase | HelloWorldExample |
| snake_case | hello_world_example |
| kebab-case | hello-world-example |
| Train-Case | Hello-World-Example |
| dot.case | hello.world.example |
Where SCREAMING_SNAKE_CASE Fits
CONSTANT_CASE marks values that never change: compile-time constants, enum members and environment variables. The all-caps convention exists partly so that a constant is visibly different from a variable at the point of use, without needing to look up its declaration.
Converting in Code
``javascript
const constant = (s) => words(s).map((w) => w.toUpperCase()).join('_');
`
POSIX permits only letters, digits and underscore in an environment variable name, and forbids a leading digit. A converter that faithfully preserves a hyphen produces a name the shell silently ignores rather than rejects.
Where SCREAMING_SNAKE_CASE Is the Convention
| Context | Example |
|---|---|
| Environment variables | DATABASE_URL, NODE_ENV |
| Constants | MAX_RETRIES = 3 |
| Enum members (Java, Python) | Status.NOT_FOUND |
| C macros | #define BUFFER_SIZE 1024 |
| Build flags | ENABLE_LOGGING=1 |
Environment variables are the strict case: POSIX reserves lowercase names for the shell's own
use, so uppercase-with-underscores is the portable choice rather than a style preference.The convention signals "this does not change at runtime". In languages without real constants
ā Python has no const ā it is the only signal there is, which is why PEP 8 specifies it
and why reassigning a SCREAMING_SNAKE name reads as a bug even where the language permits it.
Avoid it for things that merely *happen* not to change. Reserved for genuine constants, the
convention carries information; applied broadly it carries none.
Converting at the API Boundary
The recurring friction is that JavaScript uses camelCase and Python, Ruby, Go and SQL use
snake_case. The fix is to convert in exactly one place ā the client that talks to the API ā
rather than letting both conventions into the same codebase.
`javascript
const toCamel = (s) => s.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
const toSnake = (s) => s.replace(/[A-Z]/g, (c) => '_' + c.toLowerCase());
// Recursively, for a whole payload
const convertKeys = (value, fn) =>
Array.isArray(value)
? value.map((v) => convertKeys(v, fn))
: value && typeof value === 'object'
? Object.fromEntries(Object.entries(value).map(([k, v]) => [fn(k), convertKeys(v, fn)]))
: value;
`
Two things to watch: keys that are user data rather than field names must not be
converted, and the round trip is not always lossless ā userID ā user_id ā userId
changes the original.
Where Each Convention Is Mandatory
Not stylistic ā these will break if you deviate:
| Context | Requirement |
|---|---|
| Environment variables | Uppercase with underscores; POSIX reserves lowercase |
| Custom HTML elements | Must contain a hyphen |
| Python modules | Cannot contain hyphens; the import statement will not parse |
| SQL identifiers | Folded to one case unless quoted, so camelCase does not survive |
| React components | Must start uppercase, or JSX treats it as an HTML tag |
Renaming Safely
A find-and-replace across a codebase will hit strings, comments and unrelated identifiers.
Use your language server's rename symbol instead ā it understands scope. For a bulk rename
across files, restrict the pattern with word boundaries and review the diff before
committing:
`bash
grep -rn '\buserId\b' src/ # look first
``