Skip to content

convertIPv4ToBinary

reference
1 min readUpdated

Kind: Function

Source: src/utils/ipaddr.ts

Part of: Utils

Convert IPv4 to Uint8Array

Converts an IPv4 address string into a Uint8Array representation. It supports code in src/utils/ipaddr.ts that needs address data in byte form.

Signature

ts
function convertIPv4ToBinary(ipv4: string): bigint

Parameters

NameType
ipv4string

Returns: bigint

Diagram

mermaid
graph LR
  Input[IPv4 address string] --> Convert[convertIPv4ToBinary]
  Convert --> Output[Uint8Array]

Usage

ts
import { convertIPv4ToBinary } from './utils/ipaddr';

declare const ipv4Address: string;

const addressBytes = convertIPv4ToBinary(ipv4Address);

console.log(addressBytes);

AI Coding Instructions

  • Pass a valid IPv4 address string to this function.
  • Keep the returned value as a Uint8Array when passing address data to byte-oriented APIs.
  • Handle invalid address input at the caller when the surrounding flow requires user-facing errors.
  • Import the helper from src/utils/ipaddr.ts rather than duplicating address-to-byte conversion logic.

Used by

1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (1)

  • IPRestrictionRulesrc/middleware/ip-restriction/index.ts:38

Was this page helpful?

Download as PDF
convertIPv4ToBinary — Hono (narrator proof)