pipr.tools
Pipes
Clean Email Strip formatting from pasted email for clean plain text Clean AI Output Clean plain text from ChatGPT or AI output Decode & Format JWT Decode a JWT and pretty-print header and payload Word Frequency Count word frequency in text

wrap Hard-wrap text at N columns

Aa Text
Input0 chars
Output0 chars

Flags

--width number default: 80

Examples

Hard-wrap a long line at 80 columns

Usage
"This is a very long line of text that should be wrapped at e..." | wrap

Wrap a long message for a plain-text email

Usage
"Hi team, just a reminder that the quarterly review meeting i..." | wrap

Format marketing copy to fit a narrow sidebar layout

Usage
"Our company provides world-class solutions for businesses of..." | wrap --width=40
View source
(input, opts = {})=>{
                const w = parseInt(opts.width) || 80;
                return input.split("\n").map((line)=>{
                    if (line.length <= w) return line;
                    const wrapped = [];
                    let remaining = line;
                    while(remaining.length > w){
                        let breakAt = remaining.lastIndexOf(" ", w);
                        if (breakAt <= 0) breakAt = w;
                        wrapped.push(remaining.slice(0, breakAt));
                        remaining = remaining.slice(breakAt).trimStart();
                    }
                    if (remaining) wrapped.push(remaining);
                    return wrapped.join("\n");
                }).join("\n");
            }