// Static Width (Plain Regex) const wrap = (s) => s.replace( /(?![^ ]{1,32}$)([^ ]{1,32})s/g, '$1 ' ); // Dynamic Width (Build Regex) const wrap = (s, w) => s.replace( new RegExp(`(?![^ ]{1,${w}}$)([^ ]{1,${w}})s`, 'g'), '$1 ' );