Skip to content

Anuar-boop/text-transform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

text-transform

Text transformation CLI. Zero dependencies. Pipe-friendly. Reads from arguments, files, or stdin.

Features

  • case -- upper, lower, title, sentence, camelCase, snake_case, kebab-case, PascalCase, CONSTANT_CASE
  • reverse -- reverse characters, words, or lines
  • count -- words, characters, lines, sentences
  • replace -- regex find and replace
  • wrap -- word wrap at N characters
  • indent / dedent -- add or remove indentation
  • trim -- strip whitespace (whole text or per-line)
  • pad -- left, right, or center padding
  • encode / decode -- base64, URL encoding, HTML entities
  • hash -- md5, sha1, sha256, sha512
  • lorem -- generate lorem ipsum (words, sentences, paragraphs)
  • slug -- URL-friendly slug from text
  • strip-html -- remove HTML tags, scripts, styles
  • extract -- pull emails, URLs, numbers, IPs, phone numbers from text

Requirements

  • Python 3.6+
  • No external packages

Usage

Every command accepts input three ways:

# Inline arguments
python3 text_transform.py upper "hello world"

# Pipe from stdin
echo "hello world" | python3 text_transform.py upper

# From file
python3 text_transform.py upper -f input.txt

Case Conversion

echo "hello world" | python3 text_transform.py case upper       # HELLO WORLD
echo "HELLO WORLD" | python3 text_transform.py case lower       # hello world
echo "hello world" | python3 text_transform.py case title       # Hello World
echo "hello world" | python3 text_transform.py case camel       # helloWorld
echo "hello world" | python3 text_transform.py case pascal      # HelloWorld
echo "hello world" | python3 text_transform.py case snake       # hello_world
echo "hello world" | python3 text_transform.py case kebab       # hello-world
echo "hello world" | python3 text_transform.py case constant    # HELLO_WORLD
echo "hello. world." | python3 text_transform.py case sentence  # Hello. World.

Reverse

echo "hello" | python3 text_transform.py reverse              # olleh
echo "one two three" | python3 text_transform.py reverse --words   # three two one
echo -e "a\nb\nc" | python3 text_transform.py reverse --lines     # c\nb\na

Count

echo "hello world" | python3 text_transform.py count words       # 2
echo "hello world" | python3 text_transform.py count chars       # 12
echo -e "a\nb\nc" | python3 text_transform.py count lines        # 3
echo "One. Two. Three." | python3 text_transform.py count sentences  # 3

Replace

echo "foo bar foo" | python3 text_transform.py replace "foo" "baz"  # baz bar baz
echo "Hello World" | python3 text_transform.py replace "hello" "hi" -i  # hi World

Encode / Decode

echo "hello" | python3 text_transform.py encode base64    # aGVsbG8K
echo "aGVsbG8=" | python3 text_transform.py decode base64  # hello
echo "a&b" | python3 text_transform.py encode url          # a%26b
echo "<p>hi</p>" | python3 text_transform.py encode html   # &lt;p&gt;hi&lt;/p&gt;

Hash

echo -n "hello" | python3 text_transform.py hash md5       # 5d41402abc4b2a76...
echo -n "hello" | python3 text_transform.py hash sha256    # 2cf24dba5fb0a30e...
python3 text_transform.py hash sha256 "hello"

Lorem Ipsum

python3 text_transform.py lorem 10 words
python3 text_transform.py lorem 3 sentences
python3 text_transform.py lorem 2 paragraphs

Slug

python3 text_transform.py slug "My Blog Post Title!"     # my-blog-post-title
echo "Hello, World!" | python3 text_transform.py slug     # hello-world

Strip HTML

echo '<p>Hello <b>world</b></p>' | python3 text_transform.py strip-html
# Hello world

Extract

echo "Email me at user@example.com or admin@test.org" | python3 text_transform.py extract emails
# user@example.com
# admin@test.org

echo "Visit https://example.com and http://test.org" | python3 text_transform.py extract urls
# https://example.com
# http://test.org

echo "Got 42 items for $19.99" | python3 text_transform.py extract numbers
# 42
# 19.99

# Unique matches only
python3 text_transform.py extract emails -u -f emails.txt

Wrap, Indent, Trim, Pad

echo "long text..." | python3 text_transform.py wrap -w 40
echo "code" | python3 text_transform.py indent -s 4
echo "  padded  " | python3 text_transform.py trim
echo "hi" | python3 text_transform.py pad center -w 20 -c "="   # =========hi=========

Piping Examples

# Chain transforms
echo "My Blog Post" | python3 text_transform.py slug | python3 text_transform.py encode url

# Process files
cat *.html | python3 text_transform.py strip-html | python3 text_transform.py count words

# Generate + transform
python3 text_transform.py lorem 5 sentences | python3 text_transform.py case upper

License

MIT

About

Text transformation CLI. Case conversion, encode/decode, hash, regex replace, extract patterns, lorem ipsum, slug. Zero dependencies, pipe-friendly.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages