TFTextShifter
productivityjavascriptpythontext

10 Text Transformations Every Developer Does Daily

10 Text Transformations Every Developer Does Daily (And How to Automate Them)

We don't talk about it, but a surprising chunk of development time goes to text wrangling. Converting between naming conventions, encoding strings, stripping whitespace, escaping characters. It's death by a thousand tiny tasks.

Here are 10 transformations I do constantly, with both the code-it-yourself approach and the fastest shortcut for each.


1. camelCase to snake_case

You're integrating a JavaScript API response into a Python codebase. Every field name needs converting.

The code way (JavaScript):

function camelToSnake(str) {
  return str.replace(/[A-Z]/g, letter => _${letter.toLowerCase()});
}

camelToSnake('firstName'); // "first_name" camelToSnake('userAccountId'); // "user_account_id"

The code way (Python):

import re

def camel_to_snake(name): s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()

The quick way: Paste your text into textshifter.com/tools/snake-case and get the result instantly. Useful when you have a batch of variable names to convert.


2. snake_case to camelCase

The reverse problem. You're pulling from a Python API into a React frontend.

The code way (JavaScript):

function snakeToCamel(str) {
  return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
}

snakeToCamel('user_account_id'); // "userAccountId"

The quick way: Most online case converters handle this. textshifter.com has a camelCase tool that handles batch conversions too.


3. Base64 Encode/Decode

Dealing with JWTs, image data URIs, or basic auth headers? You'll need Base64.

The code way (JavaScript):

// Encode
btoa('hello:world');  // "aGVsbG86d29ybGQ="

// Decode atob('aGVsbG86d29ybGQ='); // "hello:world"

The code way (Terminal):

echo -n "hello:world" | base64          # encode
echo "aGVsbG86d29ybGQ=" | base64 -d    # decode

Watch out: btoa() doesn't handle Unicode. For Unicode strings:

btoa(unescape(encodeURIComponent('hello')));

The quick way: Any decent developer toolkit has a Base64 encoder. I use the one at textshifter.com/tools/base64 when I'm already in the browser.


4. URL Encode/Decode

Query parameters with special characters? You need URL encoding.

The code way (JavaScript):

encodeURIComponent('hello world & goodbye');
// "hello%20world%20%26%20goodbye"

decodeURIComponent('hello%20world%20%26%20goodbye'); // "hello world & goodbye"

The code way (Python):

from urllib.parse import quote, unquote

quote('hello world & goodbye')

'hello%20world%20%26%20goodbye'

The quick way: Copy the URL, paste into any URL decoder tool, done. No need to fire up a REPL for a one-off decode.


5. Strip Trailing Whitespace

Whitespace issues cause failed diffs, broken YAML, and CI failures.

The code way (Terminal):

sed 's/[[:space:]]*$//' input.txt > output.txt

The code way (VS Code): Add to your settings.json:

{
  "files.trimTrailingWhitespace": true
}

The quick way: Paste into any text cleanup tool and select "trim whitespace." This is especially useful when you've copied text from a PDF or email.


6. Remove Duplicate Lines

You've got a log file or a list with duplicates. You need unique lines only.

The code way (Terminal):

sort input.txt | uniq > output.txt

Or preserve original order:

awk '!seen[$0]++' input.txt > output.txt

The code way (Python):

lines = open('input.txt').readlines()
unique = list(dict.fromkeys(lines))

The quick way: Paste the list into a deduplicate tool. Faster than opening a terminal when you're in the middle of writing documentation.


7. JSON to CSV (and back)

Exporting API data for a spreadsheet, or importing CSV into your app.

The code way (Python):

import json, csv, io

data = [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]

output = io.StringIO() writer = csv.DictWriter(output, fieldnames=data[0].keys()) writer.writeheader() writer.writerows(data) print(output.getvalue())

The code way (Terminal with jq):

echo '[{"name":"Alice","age":30},{"name":"Bob","age":25}]' | \
  jq -r '(.[0] | keys_unsorted) as $keys | $keys, (.[] | [.[$keys[]]] ) | @csv'

The quick way: There are plenty of JSON-to-CSV converters online. For quick one-offs where the data isn't sensitive, they save real time.


8. Escape/Unescape HTML Entities

Rendering user input safely, or decoding scraped HTML content.

The code way (JavaScript):

// Escape
function escapeHtml(str) {
  const div = document.createElement('div');
  div.appendChild(document.createTextNode(str));
  return div.innerHTML;
}

// Unescape function unescapeHtml(str) { const div = document.createElement('div'); div.innerHTML = str; return div.textContent; }

The code way (Python):

import html

html.escape('')

'<script>alert("xss")</script>'

html.unescape('<script>')

'