You don't have to do all of them... Some coverage is better than nothing. If youre going to link to a regex101 page of examples like the above poster, you could just loop through and verify matches on those same examples.
But wouldn't a simple media query for screen size accurately accommodate like 99% of devices, anyway? Phones and tablets usually have significantly smaller resolutions than PCs.
105
u/Voltra_Neo Mar 01 '22
Given what y'all do with this, I might as well publish my browser "detector" on npm
94
u/Mancobbler Mar 01 '22
At this point if I include any regex in my code, I also include a link to regex101.com with a bunch of examples of what it’s supposed to match.
48
u/nekokattt Mar 01 '22
Code like this is why everyone is shitting themselves that chrome and firefox changing from v99 to v100 is going to break loads of stuff.
29
u/pavilionhp_ learning from the best Mar 01 '22
This is from detectmobilebrowsers.com and is available in multiple other languages if you’d all like to know
23
u/RichCorinthian Mar 01 '22
It's OK, I'm sure there's a whole suite of unit tests to make sure it's correct and to prevent problems if you ever need to maintain or expand it. /s
4
u/RyanNerd shameless Mar 01 '22
The poor human transcriber. Smh.
3
u/Budgiebrain222 Mar 01 '22
This is that regex stuff?
3
u/Lich_Hegemon Mar 02 '22
Regex was a mistake
2
u/ftgander Mar 01 '22
I love Regex but this is too far
2
u/tills1993 Mar 02 '22
What the hell is the point of the iife here? Everything is already scoped to isMobile.
2
u/[deleted] Mar 02 '22
// @ts-ignore
2
u/LeagueJunior9782 Mar 09 '22
this isn't normal regex, this is advanced regex!
Now excuse me, i think my eyes bleed.
44
u/[deleted] Mar 01 '22
[removed] — view removed comment
21
u/[deleted] Mar 01 '22
[removed] — view removed comment