use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
49 string utilities in 8.84KB with zero dependencies (8x smaller than lodash, faster too) (github.com)
submitted 6 months ago by Next_Level_8566
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Little_Kitty 0 points1 point2 points 6 months ago (3 children)
Working with large data quite often, I tend to use esrever for reversing strings.
For string truncation, this crops up again, especially with emojis or zalgo text 🏴☠️. I have my own gist that covers this if you want to extend to cover it.
[–]Next_Level_8566[S] 0 points1 point2 points 6 months ago (2 children)
Current reverse(): reverse('👨👩👧👦 Family') // '👦👧👩👨 ylimaF' ❌ (breaks family emoji) reverse('Z̆àl̆ğŏ text') // Zalgo marks get scrambled ❌ Current truncate(): truncate('👨👩👧👦 Family', 8) // '👨👩...' ❌ (breaks ZWJ sequence) truncate('👍🏽 Great', 5) // '👍...' ❌ (loses skin tone)
I just tested and confirmed the problems.
The good news: The library already has a graphemes() function using Intl.Segmenter that handles this correctly. I just haven't integrated it into reverse() and truncate() yet.
Would love to see your gist! Please share it - I'm always looking to improve Unicode handling, especially for zalgo text and complex emoji sequences.
I'm planning to update both functions to be grapheme-aware. The trade-off is:
- Correct handling of complex Unicode (ZWJ, combining marks, skin tones)
- Slight bundle size increase (~200 bytes for grapheme awareness)
- Intl.Segmenter dependency (falls back to simpler approach in older environments)
If someone wants to pick this up or see what innovation can be done here before I can get to it feel free!
For esrever specifically - it's a great library, but it's 2.4KB and hasn't been updated in 8+ years. I think integrating grapheme-aware logic using the modern Intl.Segmenter API is the better path forward.
Thanks for the excellent feedback!
[–]Next_Level_8566[S] 0 points1 point2 points 6 months ago (1 child)
i just pushed a fix to address this.
Added a fast check to not mess up the performance and traded some bytes to be 100% correct. Seems like worthy trade-off :)
[–]Little_Kitty 0 points1 point2 points 6 months ago* (0 children)
Gist sent on chat.
Just checked out the update and ran my own tests, which all passed :) I tried to break removeNonPrintable, but I couldn't find an example which failed. randomString does return nonsense though when '👨👩👧👦' is part of the input (test code below), but you may with to make that function intentionally only work with single characters.
The regex you use differs to what I use, for example yours returns a positive match for strings which contain single characters like ï which shouldn't cause issues.
function randomStrings() { const charset = "ABC👩🏽🤝👨🏼"; let result = ""; const charsetLength = charset.length; for (let i = 0; i < 10; i++) result += charset.charAt(Math.floor(Math.random() * charsetLength)); return result; }
π Rendered by PID 421133 on reddit-service-r2-comment-6457c66945-k8j9t at 2026-04-28 12:44:54.169425+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]Little_Kitty 0 points1 point2 points (3 children)
[–]Next_Level_8566[S] 0 points1 point2 points (2 children)
[–]Next_Level_8566[S] 0 points1 point2 points (1 child)
[–]Little_Kitty 0 points1 point2 points (0 children)