Download next.js/packages/next/src/server/web/spec-extension/user-agent.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/server/web/spec-extension/user-agent.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/server/web/spec-extension/user-agent.ts
-
curl -L -o user-agent.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/server/web/spec-extension/user-agent.ts
1.16 kB
| import parseua from 'next/dist/compiled/ua-parser-js' | |
| interface UserAgent { | |
| isBot: boolean | |
| ua: string | |
| browser: { | |
| name?: string | |
| version?: string | |
| major?: string | |
| } | |
| device: { | |
| model?: string | |
| type?: string | |
| vendor?: string | |
| } | |
| engine: { | |
| name?: string | |
| version?: string | |
| } | |
| os: { | |
| name?: string | |
| version?: string | |
| } | |
| cpu: { | |
| architecture?: string | |
| } | |
| } | |
| export function isBot(input: string): boolean { | |
| return /Googlebot|Mediapartners-Google|AdsBot-Google|googleweblight|Storebot-Google|Google-PageRenderer|Google-InspectionTool|Bingbot|BingPreview|Slurp|DuckDuckBot|baiduspider|yandex|sogou|LinkedInBot|bitlybot|tumblr|vkShare|quora link preview|facebookexternalhit|facebookcatalog|Twitterbot|applebot|redditbot|Slackbot|Discordbot|WhatsApp|SkypeUriPreview|ia_archiver/i.test( | |
| input | |
| ) | |
| } | |
| export function userAgentFromString(input: string | undefined): UserAgent { | |
| return { | |
| ...parseua(input), | |
| isBot: input === undefined ? false : isBot(input), | |
| } | |
| } | |
| export function userAgent({ headers }: { headers: Headers }): UserAgent { | |
| return userAgentFromString(headers.get('user-agent') || undefined) | |
| } | |