Case Detector API: Identify Text Case Styles Automatically

Need to identify what case style a piece of text uses? The Case Detector API analyzes text and identifies its case format - whether it is camelCase, snake_case, PascalCase, kebab-case, or other common naming conventions.

Why Detect Case Styles?

Consistent naming conventions are crucial for code quality and readability. The Case Detector API helps you enforce coding standards, analyze codebases, and build tools that need to understand text formatting patterns.

Whether you are building a linter, code formatter, or migration tool, automatic case detection is a valuable capability.

Supported Case Styles

The API detects these common case formats:

Case Style Example Common Use
camelCase myVariableName JavaScript variables, Java methods
PascalCase MyClassName Classes, React components
snake_case my_variable_name Python, Ruby, database columns
SCREAMING_SNAKE MY_CONSTANT Constants, environment variables
kebab-case my-css-class CSS classes, URLs
lowercase lowercase Various
UPPERCASE UPPERCASE Acronyms, emphasis
Mixed Case: The API also detects when text does not match any standard pattern, returning "mixed" or "unknown" as appropriate.

Using the Case Detector API

TinyFn provides a simple endpoint to detect case styles:

API Request
POST https://api.tinyfn.io/v1/transform/detect-case
Headers: X-API-Key: your-api-key
Content-Type: application/json

{
  "text": "myVariableName"
}
Response
{
  "text": "myVariableName",
  "detected_case": "camelCase",
  "confidence": 1.0,
  "words": ["my", "Variable", "Name"],
  "word_count": 3
}

Parameters

Parameter Type Description
text string The text to analyze (required)
strict boolean Require exact pattern match (default: false)

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/transform/detect-case',
  {
    method: 'POST',
    headers: {
      'X-API-Key': 'your-api-key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ text: 'user_account_settings' })
  }
);
const { detected_case, words } = await response.json();
console.log(`Case: ${detected_case}`); // snake_case
console.log(`Words: ${words.join(', ')}`); // user, account, settings

Python

import requests

response = requests.post(
    'https://api.tinyfn.io/v1/transform/detect-case',
    headers={'X-API-Key': 'your-api-key'},
    json={'text': 'MY_API_KEY'}
)
result = response.json()
print(f"Detected: {result['detected_case']}")  # SCREAMING_SNAKE_CASE

cURL

curl -X POST "https://api.tinyfn.io/v1/transform/detect-case" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"text": "MyClassName"}'

Common Use Cases

  • Code Linting: Verify naming conventions in code review
  • Code Migration: Identify case styles before converting
  • API Design: Validate field naming consistency
  • Documentation: Analyze naming patterns in codebases
  • Style Enforcement: Build tools that check naming conventions

Best Practices

  1. Handle ambiguous cases: Some text may match multiple patterns
  2. Use with conversion: Detect first, then convert to target format
  3. Check confidence: Lower confidence may indicate mixed styles
  4. Batch analyze: Process multiple identifiers for consistency checks
  5. Consider context: File extensions and language can inform expected patterns

Try the Case Detector API

Get your free API key and start detecting case styles automatically.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key