@armdborg/detector.js
v0.3.0
Published
Access Cloudflare edge data (country, bot detection, etc.) via simple ESM imports
Maintainers
Readme
armdb.org
Access Cloudflare edge data via simple ESM imports.
Install
npm install @armdborg/detector.jsUsage
Async (recommended)
import { country, isBot, city } from '@armdborg/detector.js'
if (await country === 'RU') {
console.log('Hello from Russia!')
}
if (await isBot) {
console.log('You are a bot')
}
const userCity = await city // "Moscow" | undefinedLoad all data
import { load } from '@armdborg/detector.js'
const data = await load()
console.log(data.country, data.city)Sync (after load)
import { sync } from '@armdborg/detector.js'
// Wait a bit for data to load, then:
const data = sync()
if (data?.country === 'RU') {
console.log('Hello from Russia!')
}Available Fields
| Field | Type | Description |
|-------|------|-------------|
| country | string | ISO 3166-1 alpha-2 code |
| city | string | City name |
| region | string | Region/state name |
| regionCode | string | Region code |
| continent | string | AF, AN, AS, EU, NA, OC, SA |
| timezone | string | IANA timezone |
| postalCode | string | Postal code |
| latitude | string | Latitude |
| longitude | string | Longitude |
| asn | number | Autonomous System Number |
| isEUCountry | boolean | Is EU country |
| isBot | boolean | Bot detection* |
| botScore | number | Bot score 0-99* |
*Requires Cloudflare Bot Management
How It Works
- Package fetches
https://detector.armdb.org/ - Cloudflare Worker returns visitor's edge data as JSON
- Data is cached and available via imports
TypeScript
Full TypeScript support included:
import { load, type ArmdbData } from '@armdborg/detector.js'
const data: ArmdbData = await load()License
MIT
