@h3ravel/url
v1.0.20
Published
Request-aware URI builder and URL manipulation utilities for H3ravel.
Maintainers
Readme
About H3ravel/url
Request-aware URI builder and URL manipulation utilities for H3ravel framework.
Installation
npm install @h3ravel/urlFeatures
- Static factories for creating URLs from strings, paths, routes, and controller actions
- Fluent builder API for modifying URLs with immutable chaining
- Request-aware helpers for working with current request context
- URL signing capabilities for secure temporary URLs
- Type-safe query parameters and route parameters
Usage
Basic URL Creation
import { Url } from '@h3ravel/url';
// From string
const url = Url.of('https://example.com/path');
// From path relative to app URL
const url = Url.to('/users');
// From named route
const url = Url.route('users.show', { id: 1 });
// From controller action
const url = Url.action('UserController@index');Fluent Builder API
const url = Url.of('https://example.com')
.withScheme('http')
.withHost('test.com')
.withPort(8000)
.withPath('/users')
.withQuery({ page: 2 })
.withFragment('section-1')
.toString();
// -> "http://test.com:8000/users?page=2#section-1"Request-Aware Helpers
// Get current URL
url().current();
// Get full URL with query string
url().full();
// Get previous URL
url().previous();
// Get previous path only
url().previousPath();
// Get current query parameters
url().query();Signed URLs
// Create signed route URL
const signedUrl = Url.signedRoute('users.show', { id: 1 });
// Create temporary signed route URL (expires in 5 minutes)
const tempUrl = Url.temporarySignedRoute(
'users.index',
{},
Date.now() + 300000
);API Reference
Static Methods
Url.of(string)- Create from full URL stringUrl.to(path)- Create from path relative to app URLUrl.route(name, params)- Create from named routeUrl.signedRoute(name, params)- Create signed route URLUrl.temporarySignedRoute(name, params, expiration)- Create expiring signed route URLUrl.action(controller)- Create from controller action
Instance Methods
withScheme(scheme: string)- Set URL schemewithHost(host: string)- Set URL hostwithPort(port: number)- Set URL portwithPath(path: string)- Set URL pathwithQuery(query: Record<string, any>)- Set query parameterswithFragment(fragment: string)- Set URL fragmenttoString()- Convert to string representation
Request-Aware Functions
current()- Get current request URLfull()- Get full URL with query stringprevious()- Get previous request URLpreviousPath()- Get previous request pathquery()- Get current query parameters
Contributing
Thank you for considering contributing to the H3ravel framework! The Contribution Guide can be found in the H3ravel documentation and will provide you with all the information you need to get started.
Code of Conduct
In order to ensure that the H3ravel community is welcoming to all, please review and abide by the Code of Conduct.
Security Vulnerabilities
If you discover a security vulnerability within H3ravel, please send an e-mail to Legacy via [email protected]. All security vulnerabilities will be promptly addressed.
License
The H3ravel framework is open-sourced software licensed under the MIT license.
