UNPKG

@c_s_v_s_subrahmanyam/string-utils

Version:

A comprehensive utility library for advanced string operations.

18 lines (15 loc) 562 B
// Sorting utilities module.exports = { sortCharacters: (str, order = 'asc') => { const sorted = [...str].sort((a, b) => (order === 'asc' ? a.localeCompare(b) : b.localeCompare(a))); return sorted.join(''); }, sortWords: (str, order = 'asc') => { const words = str.split(/\s+/); const sorted = words.sort((a, b) => (order === 'asc' ? a.localeCompare(b) : b.localeCompare(a))); return sorted.join(' '); }, uniqueCharacters: (str) => { return [...new Set(str)].join(''); }, };