parseHost

utils · /index·function

Tokenize a host header into its hostname/port/app/shop parts.

my-shop.storefront.localhost:443 → { hostname: 'my-shop.storefront.localhost', port: 443, isDev: true, tld: 'localhost', app: 'storefront', shop: 'my-shop', segments: ['my-shop','storefront','localhost'] } demo.nordcom.store.storefront.localhost → { …, app: 'storefront', shop: 'demo.nordcom.store' } storefront.localhost → { …, app: 'storefront', shop: null } localhost → { …, app: null, shop: null } shop.example.com → { …, isDev: false, tld: null, app: null, shop: null }

Returns null when the input cannot be normalized (empty, leading dot, etc.) so the caller can short-circuit before destructuring.

Signature

@nordcom/commerce-utils
function parseHost(host: string): ParsedHost;

Parameters

NameTypeDescription
hoststring

ParsedHost AppName BuildEnv DevTld Hostname ShopHandle appFromHost isDevelopment

Sourcehostname.ts:196Edit the JSDoc directly
Metadata@nordcom/commerce-utils@0.0.0Open in GitHub ↗

On this page