@ts-utilkit/network
v0.2.2
Published
Network utilities for URL validation, IP address handling, and network-related operations
Maintainers
Readme
@ts-utilkit/network
network Functions - TypeScript utility functions for network operations.
Installation
npm install @ts-utilkit/networkFeatures
- 🚀 TypeScript-first with complete type definitions
- ✅ Comprehensive test coverage (>95%)
- 📦 CommonJS builds with import and require entry points
- 🔒 Type-safe with strict TypeScript configuration
- 📖 Extensive JSDoc documentation
Available Functions (22)
addQueryParams- Adds query parameters to a URLbuildURL- Constructs a URL from componentsdecodeURLComponent- Decodes a URL componentencodeURLComponent- Encodes a URL componentextractDomain- Extracts the domain from a URLgetDomainParts- Parses domain into subdomain, domain, and TLDgetQueryParams- Extracts query parameters from a URLgetURLPath- Extracts the path from a URLgetURLsFromText- Extracts all URLs from texthasQueryParam- Checks whether a query parameter with the given key exists in a URL.isAbsoluteURL- Determines whether a URL string is absolute (has a scheme/protocol).isLocalhost- Checks if URL is localhostisRelativeURL- Determines whether a URL string is relative (has no scheme/protocol).isSameOrigin- Checks if two URLs have the same originisSubdomain- Checks if URL is a subdomain of anotherisValidURL- Validates if a string is a valid URLjoinURLPaths- Joins URL path segmentsnormalizeURL- Normalizes a URL (removes trailing slashes, etc.)parseURL- Parses a URL into its componentsremoveQueryParams- Removes query parameters from a URLsanitizeURL- Sanitizes URL by removing dangerous protocolssetURLFragment- Sets or replaces the fragment (hash) of a URL and returns the updated URL string.
Quick Example
import {
isValidURL,
getQueryParams,
joinURLPaths,
normalizeURL,
} from '@ts-utilkit/network';
isValidURL('https://example.com'); // true
getQueryParams('https://example.com/?page=2&sort=date'); // {page: '2', sort: 'date'}
joinURLPaths('/api//v1', 'users'); // '/api/v1/users'
normalizeURL('https://example.com/?tag=&tag=one&b=2'); // 'https://example.com/?b=2&tag=one'License
MIT © Mykyta Forofontov
Contributing
Contributions are welcome! Please see the main repository for contribution guidelines.
