Skip to content

🧮 5. URL

Structural URL/URI pattern validator.

⚠️ Pattern validation only — not DNS, reachability, or safety.

typescript
import { URL } from 'drea'

// Pattern only
new URL('http://example.com').verifyPattern() // true

// With constraints (recommended)
new URL('https://api.example.com:443').verifyPattern({
  allowed_protocols: ['https'],
  allowed_ports:     ['443', '80'],
  allowed_domains:   ['api.example.com'],
  contain_query:     false,
  contain_fragment:  false
}) // true | false
ConstraintTypeEffect
allowed_protocolsstring[]URL scheme must be in this list
allowed_portsstring[]URL must carry a port from this list
allowed_domainsstring[]Domain whitelisted (case-insensitive)
contain_fragmentbooleantrue = require #hash; false = forbid it
contain_querybooleantrue = require ?query; false = forbid it
contain_pathbooleantrue = require path segments; false = forbid them
betweennumber[][min] or [min, max] character length