#JustWebDeveloperThings

Rick Osbornerick@ricko.social
2024-12-19

I present to you, the most subtly heinous #TypeScript I've had to write this week.

It's just an object deep sorter, used when saving JSON files, so we always get deterministic output.

Except ... it's more tricky than just using `localeCompare` because modern versions of node will ignore key insertion order and return keys in number-sorted order if the keys are all number-like.

Cue: "Thanks, I hate it" or "This is why we can't have nice things".

#JustWebDeveloperThings

Screenshot of some syntax-highlighted TypeScript code.  It shows a function called "deep sort" which does what it sounds like it does.  Most of the logic is pretty easy to follow and linear.  But then there's a big, out-of-place comment toward the bottom which says:

This looks goofy, but ...In modern versions of node, the default implementation will try to numeric-sort keys for you.  Because we want string-sorting only, we have to proxy the call to return the correct order.

Me: Oooh, found a new site that sells Japanese import stationary in my country!

Also me: *spends the next twenty minutes isolating the one element that's making their sticky header take up almost 30% of the available screen height and writing custom css to throw it into the sea*

Listen, the medium may be the message, but never underestimate the value of being able to personally mangle that medium according to your needs

#JustWebDeveloperThings

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst