Home > @opengovsg/rate-limit > normalizeIp
normalizeIp() function
Derive the store key for a client IP, or null when the input is not a valid IP address so the caller can warn and fall back to the shared bucket.
IPv4 addresses, including IPv4-mapped IPv6 addresses, are keyed per address. IPv6 addresses are keyed by their /64 prefix, since a subscriber typically holds an entire /64 and could otherwise mint a fresh bucket per request by rotating within it.
Output keys have their colons replaced with |-| to avoid colliding with the common namespace:subkey Redis convention.
Signature:
typescript
normalizeIp: (ip: string) => string | nullParameters
| Parameter | Type | Description |
|---|---|---|
| ip | string |
Returns:
string | null