Text Processing

0 words
Result will appear here...

Sample JavaScript Snippets

Sort Alphabetically
Type of Sorting Required
Input Format Options (separator between the items to be sorted)
Output Format Options
Removal Options
return (() => { const inputSeparator = /\s+/; const outputSeparator = ' '; let items = String(text).split(inputSeparator).map(item => item.trim()).filter(Boolean); const collator = new Intl.Collator('en', { sensitivity: 'base' }); items.sort((a, b) => collator.compare(a, b)); return items.join(outputSeparator); })();
Sorts the text according to your selections and returns the result in the specified format.
Sample input
Hello world! Learning to code is great. hello
Transformed output
code great hello hello learning to world
Unique Words
return [...new Set((text.match(/\p{L}+/gu) || []).map(w => w.toLowerCase()))].join(', ');
Lowercases the words in the text, removes duplicates, and lists unique entries separated by commas.
Sample input
Data data science science learning requires patience.
Transformed output
data, learning, patience, requires, science
Split List Into Lines
return text.split(',').map(pair => pair.trim()).join('\n');
Cleans the comma-separated pairs and moves each item to a new line.
Sample input
1 - one, 2 - two, 3 - three, 4 - four, 5 - five, 6 - six, 7 - seven, 8 - eight, 9 - nine, 10 - ten
Transformed output
1 - one 2 - two 3 - three 4 - four 5 - five 6 - six 7 - seven 8 - eight 9 - nine 10 - ten
Count Sentences, Paragraphs, Words, and Characters
return (() => { const trimmed = text.trim(); if (!trimmed) return '0 sentences, 0 paragraphs, 0 words, 0 characters'; const sentenceCount = trimmed.split(/[.!?]+(?:\s+|$)/).map(s => s.trim()).filter(Boolean).length; const paragraphCount = trimmed.split(/\n\s*\n/).map(p => p.trim()).filter(Boolean).length || 0; const wordCount = trimmed.split(/\s+/).filter(word => word.length > 0).length; const charCount = trimmed.replace(/\n/g, '').length; return `${sentenceCount} sentences, ${paragraphCount} paragraphs, ${wordCount} words, ${charCount} characters`; })();
Analyzes the text and returns the total number of sentences, paragraphs, words, and characters together.
Sample input
I drank my coffee this morning. I started the day energized! In the afternoon there were meetings. I took a few notes. In the evening I watched a movie with my family.
Transformed output
6 sentences, 3 paragraphs, 18 words, 119 characters
Remove Empty Lines
return text.split(/\n+/).map(line => line.trim()).filter(Boolean).join('\n');
Removes blank lines and lists the dialogue lines consecutively.
Sample input
Mira: There is no surprise tonight. Eren: Is there an exception for old friends? Mira: Of course, always.
Transformed output
Mira: There is no surprise tonight. Eren: Is there an exception for old friends? Mira: Of course, always.
Bold Word Segments
const isLetter = ch => ch.toLocaleLowerCase() !== ch.toLocaleUpperCase(); return String(text || '') .split(/(\s+)/) .map(part => { if (/^\s+$/.test(part)) return part; const chars = Array.from(part); let lead = 0; while (lead < chars.length && !isLetter(chars[lead])) lead++; let tail = chars.length; while (tail > lead && !isLetter(chars[tail - 1])) tail--; const leading = chars.slice(0, lead).join(''); const trailing = chars.slice(tail).join(''); const core = chars.slice(lead, tail); const len = core.length; if (!len) return part; let boldCount; if (len <= 3) boldCount = 1; else if (len % 2 === 0) boldCount = len / 2; else boldCount = Math.ceil(len / 2); const boldPart = core.slice(0, boldCount).join(''); const restPart = core.slice(boldCount).join(''); return leading + '<strong>' + boldPart + '</strong>' + restPart + trailing; }) .join('');
Boldens the leading portion of each word based on its length: single letter for 2-3 characters, half for even lengths, and rounded-up half for odd lengths.
Sample input
this very lovely city feels amazing
Transformed output
this very lovely city feels amazing