Files
school_compare/nextjs-app/lib/device.ts
T

16 lines
743 B
TypeScript
Raw Normal View History

/**
* Whether a User-Agent string belongs to a phone or tablet.
*
* Used for one thing: choosing the results view before the first paint, when
* the viewport is not yet known. A wrong answer is corrected client-side (see
* HomeView's MAP_DEFAULT_MIN_WIDTH), so this errs towards "handheld" and is
* kept deliberately small rather than a full UA parser.
*
* iPadOS reports a desktop Mac UA by default and so reads as desktop here,
* which is the right call: a landscape iPad has room for the map layout.
*/
const HANDHELD = /Mobi|Android|iPhone|iPad|iPod|Tablet|Silk|Kindle|PlayBook|BlackBerry|Opera Mini|IEMobile/i;
export function isHandheldUserAgent(ua: string | null | undefined): boolean {
return !!ua && HANDHELD.test(ua);
}