@ooneex/url 0.16.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,9 @@
1
1
  # @ooneex/url
2
2
 
3
- A comprehensive TypeScript/JavaScript library for working with URLs. This package provides powerful URL parsing, manipulation, and building capabilities with a clean, type-safe API for web applications.
3
+ URL parsing and manipulation library with query string handling, path normalization, and route parameter extraction for web applications.
4
4
 
5
5
  ![Browser](https://img.shields.io/badge/Browser-Compatible-green?style=flat-square&logo=googlechrome)
6
6
  ![Bun](https://img.shields.io/badge/Bun-Compatible-orange?style=flat-square&logo=bun)
7
- ![Deno](https://img.shields.io/badge/Deno-Compatible-blue?style=flat-square&logo=deno)
8
- ![Node.js](https://img.shields.io/badge/Node.js-Compatible-green?style=flat-square&logo=node.js)
9
7
  ![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue?style=flat-square&logo=typescript)
10
8
  ![MIT License](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)
11
9
 
@@ -13,44 +11,26 @@ A comprehensive TypeScript/JavaScript library for working with URLs. This packag
13
11
 
14
12
  ✅ **Complete URL Parsing** - Parse and extract all URL components (protocol, hostname, port, path, queries, fragment)
15
13
 
16
- ✅ **Type-Safe** - Full TypeScript support with proper type definitions
17
-
18
- ✅ **Immutable & Mutable** - Choose between ReadonlyUrl for parsing or Url for manipulation
19
-
20
- ✅ **Cross-Platform** - Works in Browser, Node.js, Bun, and Deno
14
+ ✅ **Immutable & Mutable** - Choose between `ReadonlyUrl` for parsing or `Url` for manipulation with chaining
21
15
 
22
16
  ✅ **Smart Query Parsing** - Automatically converts query parameters to appropriate types (string, number, boolean)
23
17
 
24
- ✅ **Subdomain Detection** - Intelligently separates subdomains from domains
18
+ ✅ **Subdomain Detection** - Intelligently separates subdomains from domains, handles IP addresses and localhost
25
19
 
26
- ✅ **Port Handling** - Proper default port detection and custom port support
20
+ ✅ **Pagination Helpers** - Built-in `getLang`, `getPage`, `getLimit`, `getOrder`, and `getOrderBy` query extractors
27
21
 
28
- ✅ **Path Normalization** - Clean path handling with proper slash management
22
+ ✅ **Path Normalization** - Clean path handling with proper trailing slash management
29
23
 
30
- ✅ **Zero Dependencies** - No external dependencies required (uses workspace utilities)
24
+ ✅ **Type-Safe** - Full TypeScript support with `IReadonlyUrl` and `IUrl` interfaces
25
+
26
+ ✅ **Cross-Platform** - Works in Browser, Node.js, Bun, and Deno
31
27
 
32
28
  ## Installation
33
29
 
34
- ### Bun
35
30
  ```bash
36
31
  bun add @ooneex/url
37
32
  ```
38
33
 
39
- ### pnpm
40
- ```bash
41
- pnpm add @ooneex/url
42
- ```
43
-
44
- ### Yarn
45
- ```bash
46
- yarn add @ooneex/url
47
- ```
48
-
49
- ### npm
50
- ```bash
51
- npm install @ooneex/url
52
- ```
53
-
54
34
  ## Usage
55
35
 
56
36
  ### Basic URL Parsing
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
+ import { LocaleType as LocaleType2 } from "@ooneex/translation";
1
2
  import { ScalarType as ScalarType2 } from "@ooneex/types";
3
+ import { LocaleType } from "@ooneex/translation";
2
4
  import { ScalarType } from "@ooneex/types";
3
5
  interface IReadonlyUrl {
4
6
  getNative: () => URL;
@@ -13,6 +15,11 @@ interface IReadonlyUrl {
13
15
  getBase: () => string;
14
16
  getOrigin: () => string;
15
17
  getQuery: (name: string) => ScalarType | null;
18
+ getLang: () => LocaleType;
19
+ getPage: () => number;
20
+ getLimit: () => number;
21
+ getOrder: () => "ASC" | "DESC";
22
+ getOrderBy: () => string | null;
16
23
  toString: () => string;
17
24
  }
18
25
  interface IUrl extends IReadonlyUrl {
@@ -48,6 +55,11 @@ declare class ReadonlyUrl implements IReadonlyUrl {
48
55
  getPath(): string;
49
56
  getQueries(): Record<string, ScalarType2>;
50
57
  getQuery(name: string): ScalarType2 | null;
58
+ getLang(): LocaleType2;
59
+ getPage(): number;
60
+ getLimit(): number;
61
+ getOrder(): "ASC" | "DESC";
62
+ getOrderBy(): string | null;
51
63
  getFragment(): string;
52
64
  getBase(): string;
53
65
  getOrigin(): string;
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import{parseString as t,trim as x}from"@ooneex/utils";class i{native;protocol;subdomain;domain;hostname;port;path;queries={};fragment;base;origin;constructor(g){if(this.native=new URL(g),this.protocol=x(this.native.protocol,":"),this.subdomain=null,this.hostname=this.native.hostname,this.domain=this.hostname,!/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(this.hostname)&&this.hostname!=="localhost"){let U=/(?<subdomain>.+)\.(?<domain>[a-z0-9-_]+\.[a-z0-9]+)$/i.exec(this.domain);if(U){let{subdomain:r,domain:I}=U.groups;this.subdomain=r,this.domain=I}}if(this.native.port)this.port=t(this.native.port);else{let r=(typeof g==="string"?g:g.toString()).match(/:(\d+)/);if(r)this.port=t(r[1]);else this.port=80}if(this.native.pathname==="/")this.path="/";else this.path=this.native.pathname.replace(/\/+$/,"");this.fragment=x(this.native.hash,"#"),this.base=`${this.native.protocol}//${this.native.host}`,this.origin=this.native.origin;for(let[U,r]of this.native.searchParams)if(r==="true")this.queries[U]=!0;else if(r==="false")this.queries[U]=!1;else if(/^\d+$/.test(r)&&!r.startsWith("0"))this.queries[U]=Number.parseInt(r,10);else if(/^-?\d+(\.\d+)?$/.test(r)&&!r.startsWith("0"))this.queries[U]=Number.parseFloat(r);else this.queries[U]=r}getNative(){return this.native}getProtocol(){return this.protocol}getSubdomain(){return this.subdomain}getDomain(){return this.domain}getHostname(){return this.hostname}getPort(){return this.port}getPath(){return this.path}getQueries(){return{...this.queries}}getQuery(g){return this.queries[g]||null}getFragment(){return this.fragment}getBase(){return this.base}getOrigin(){return this.origin}toString(){return this.native.toString()}}import{trim as Q}from"@ooneex/utils";class T extends i{setProtocol(g){let e=this.protocol;if(this.protocol=Q(g,":"),e==="http"&&this.port===80&&this.protocol==="https")this.port=80;else if(e==="https"&&this.port===443&&this.protocol==="http")this.port=80;return this.updateNativeUrl(),this}setHostname(g){if(this.hostname=g,this.subdomain=null,this.domain=g,!/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(g)&&g!=="localhost"){let U=/(?<subdomain>.+)\.(?<domain>[a-z0-9-_]+\.[a-z0-9]+)$/i.exec(g);if(U){let{subdomain:r,domain:I}=U.groups;this.subdomain=r,this.domain=I}}return this.updateNativeUrl(),this}setPort(g){return this.port=g,this.updateNativeUrl(),this}setPath(g){if(g==="")this.path="/";else this.path=`/${Q(g,"/")}`;return this.updateNativeUrl(),this}addQuery(g,e){return this.queries[g]=e,this.updateNativeUrl(),this}removeQuery(g){return delete this.queries[g],this.updateNativeUrl(),this}setQueries(g){return this.queries={...g},this.updateNativeUrl(),this}clearQueries(){return this.queries={},this.updateNativeUrl(),this}setFragment(g){return this.fragment=Q(g,"#"),this.updateNativeUrl(),this}updateNativeUrl(){let g=this.protocol.includes(":")?this.protocol:`${this.protocol}:`,e=this.shouldShowPort()?`:${this.port}`:"",U=this.path,r=this.buildQueryString(),I=this.fragment?`#${this.fragment}`:"",s=`${g}//${this.hostname}${e}${U}${r}${I}`;this.native=new URL(s),this.base=this.shouldShowPort()?`${g}//${this.hostname}${e}`:`${g}//${this.hostname}`,this.origin=this.shouldShowPort()?`${g}//${this.hostname}${e}`:`${g}//${this.hostname}`}shouldShowPort(){if(this.protocol==="http"&&this.port===80)return!1;if(this.protocol==="https"&&this.port===443)return!1;if(this.port===80)return!1;return!0}buildQueryString(){let g=new URLSearchParams;for(let[U,r]of Object.entries(this.queries))g.set(U,String(r));let e=g.toString();return e?`?${e}`:""}}export{T as Url,i as ReadonlyUrl};
1
+ import{locales as L}from"@ooneex/translation";import{parseString as T,trim as n}from"@ooneex/utils";class I{native;protocol;subdomain;domain;hostname;port;path;queries={};fragment;base;origin;constructor(g){if(this.native=new URL(g),this.protocol=n(this.native.protocol,":"),this.subdomain=null,this.hostname=this.native.hostname,this.domain=this.hostname,!/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(this.hostname)&&this.hostname!=="localhost"){let r=/(?<subdomain>.+)\.(?<domain>[a-z0-9-_]+\.[a-z0-9]+)$/i.exec(this.domain);if(r){let{subdomain:e,domain:U}=r.groups;this.subdomain=e,this.domain=U}}if(this.native.port)this.port=T(this.native.port);else{let e=(typeof g==="string"?g:g.toString()).match(/:(\d+)/);if(e)this.port=T(e[1]);else this.port=80}if(this.native.pathname==="/")this.path="/";else this.path=this.native.pathname.replace(/\/+$/,"");this.fragment=n(this.native.hash,"#"),this.base=`${this.native.protocol}//${this.native.host}`,this.origin=this.native.origin;for(let[r,e]of this.native.searchParams)if(e==="true")this.queries[r]=!0;else if(e==="false")this.queries[r]=!1;else if(/^\d+$/.test(e)&&!e.startsWith("0"))this.queries[r]=Number.parseInt(e,10);else if(/^-?\d+(\.\d+)?$/.test(e)&&!e.startsWith("0"))this.queries[r]=Number.parseFloat(e);else this.queries[r]=e}getNative(){return this.native}getProtocol(){return this.protocol}getSubdomain(){return this.subdomain}getDomain(){return this.domain}getHostname(){return this.hostname}getPort(){return this.port}getPath(){return this.path}getQueries(){return{...this.queries}}getQuery(g){return this.queries[g]||null}getLang(){let g=this.queries.lang;return L.includes(g)?g:"en"}getPage(){return this.queries.page??1}getLimit(){return this.queries.limit??100}getOrder(){let g=this.queries.order;return["ASC","DESC"].includes(g)?g:"ASC"}getOrderBy(){return this.queries.orderBy??null}getFragment(){return this.fragment}getBase(){return this.base}getOrigin(){return this.origin}toString(){return this.native.toString()}}import{trim as i}from"@ooneex/utils";class Q extends I{setProtocol(g){let t=this.protocol;if(this.protocol=i(g,":"),t==="http"&&this.port===80&&this.protocol==="https")this.port=80;else if(t==="https"&&this.port===443&&this.protocol==="http")this.port=80;return this.updateNativeUrl(),this}setHostname(g){if(this.hostname=g,this.subdomain=null,this.domain=g,!/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(g)&&g!=="localhost"){let r=/(?<subdomain>.+)\.(?<domain>[a-z0-9-_]+\.[a-z0-9]+)$/i.exec(g);if(r){let{subdomain:e,domain:U}=r.groups;this.subdomain=e,this.domain=U}}return this.updateNativeUrl(),this}setPort(g){return this.port=g,this.updateNativeUrl(),this}setPath(g){if(g==="")this.path="/";else this.path=`/${i(g,"/")}`;return this.updateNativeUrl(),this}addQuery(g,t){return this.queries[g]=t,this.updateNativeUrl(),this}removeQuery(g){return delete this.queries[g],this.updateNativeUrl(),this}setQueries(g){return this.queries={...g},this.updateNativeUrl(),this}clearQueries(){return this.queries={},this.updateNativeUrl(),this}setFragment(g){return this.fragment=i(g,"#"),this.updateNativeUrl(),this}updateNativeUrl(){let g=this.protocol.includes(":")?this.protocol:`${this.protocol}:`,t=this.shouldShowPort()?`:${this.port}`:"",r=this.path,e=this.buildQueryString(),U=this.fragment?`#${this.fragment}`:"",x=`${g}//${this.hostname}${t}${r}${e}${U}`;this.native=new URL(x),this.base=this.shouldShowPort()?`${g}//${this.hostname}${t}`:`${g}//${this.hostname}`,this.origin=this.shouldShowPort()?`${g}//${this.hostname}${t}`:`${g}//${this.hostname}`}shouldShowPort(){if(this.protocol==="http"&&this.port===80)return!1;if(this.protocol==="https"&&this.port===443)return!1;if(this.port===80)return!1;return!0}buildQueryString(){let g=new URLSearchParams;for(let[r,e]of Object.entries(this.queries))g.set(r,String(e));let t=g.toString();return t?`?${t}`:""}}export{Q as Url,I as ReadonlyUrl};
2
2
 
3
- //# debugId=8D777E4D61C20EA464756E2164756E21
3
+ //# debugId=DB4678099ADEB82564756E2164756E21
package/dist/index.js.map CHANGED
@@ -2,10 +2,10 @@
2
2
  "version": 3,
3
3
  "sources": ["src/ReadonlyUrl.ts", "src/Url.ts"],
4
4
  "sourcesContent": [
5
- "import type { ScalarType } from \"@ooneex/types\";\nimport { parseString, trim } from \"@ooneex/utils\";\nimport type { IReadonlyUrl } from \"./types\";\n\nexport class ReadonlyUrl implements IReadonlyUrl {\n protected native: URL;\n protected protocol: string;\n protected subdomain: string | null;\n protected domain: string;\n protected hostname: string;\n protected port: number;\n protected path: string;\n protected queries: Record<string, ScalarType> = {};\n protected fragment: string;\n protected base: string;\n protected origin: string;\n\n constructor(url: string | URL) {\n this.native = new URL(url);\n\n this.protocol = trim(this.native.protocol, \":\");\n this.subdomain = null;\n this.hostname = this.native.hostname;\n this.domain = this.hostname;\n\n // Only parse domain/subdomain for actual domain names, not IP addresses\n const isIpAddress = /^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/.test(this.hostname);\n if (!isIpAddress && this.hostname !== \"localhost\") {\n const match = /(?<subdomain>.+)\\.(?<domain>[a-z0-9-_]+\\.[a-z0-9]+)$/i.exec(this.domain);\n if (match) {\n const { subdomain, domain } = match.groups as {\n subdomain: string;\n domain: string;\n };\n this.subdomain = subdomain;\n this.domain = domain;\n }\n }\n\n // Handle port parsing - native URL omits default ports, but we need to detect them\n if (this.native.port) {\n this.port = parseString(this.native.port);\n } else {\n // Check if the original URL string had an explicit port\n const urlString = typeof url === \"string\" ? url : url.toString();\n const portMatch = urlString.match(/:(\\d+)/);\n if (portMatch) {\n this.port = parseString(portMatch[1] as string);\n } else {\n this.port = 80; // Default port\n }\n }\n // Handle path - preserve structure but handle trailing slashes correctly\n if (this.native.pathname === \"/\") {\n this.path = \"/\";\n } else {\n // Remove all trailing slashes if present, but preserve internal empty segments\n this.path = this.native.pathname.replace(/\\/+$/, \"\");\n }\n this.fragment = trim(this.native.hash, \"#\");\n this.base = `${this.native.protocol}//${this.native.host}`;\n this.origin = this.native.origin;\n\n for (const [key, value] of this.native.searchParams) {\n // Only parse as number/boolean if it's clearly intended to be\n if (value === \"true\") {\n this.queries[key] = true;\n } else if (value === \"false\") {\n this.queries[key] = false;\n } else if (/^\\d+$/.test(value) && !value.startsWith(\"0\")) {\n // Only parse as number if it's all digits and doesn't start with 0 (to preserve \"001\")\n this.queries[key] = Number.parseInt(value, 10);\n } else if (/^-?\\d+(\\.\\d+)?$/.test(value) && !value.startsWith(\"0\")) {\n // Parse as float if it's a valid number\n this.queries[key] = Number.parseFloat(value);\n } else {\n this.queries[key] = value;\n }\n }\n }\n\n public getNative(): URL {\n return this.native;\n }\n\n public getProtocol(): string {\n return this.protocol;\n }\n\n public getSubdomain(): string | null {\n return this.subdomain;\n }\n\n public getDomain(): string {\n return this.domain;\n }\n\n public getHostname(): string {\n return this.hostname;\n }\n\n public getPort(): number {\n return this.port;\n }\n\n public getPath(): string {\n return this.path;\n }\n\n public getQueries(): Record<string, ScalarType> {\n return { ...this.queries };\n }\n\n public getQuery(name: string): ScalarType | null {\n return this.queries[name] || null;\n }\n\n public getFragment(): string {\n return this.fragment;\n }\n\n public getBase(): string {\n return this.base;\n }\n\n public getOrigin(): string {\n return this.origin;\n }\n\n public toString(): string {\n return this.native.toString();\n }\n}\n",
5
+ "import type { LocaleType } from \"@ooneex/translation\";\nimport { locales } from \"@ooneex/translation\";\nimport type { ScalarType } from \"@ooneex/types\";\nimport { parseString, trim } from \"@ooneex/utils\";\nimport type { IReadonlyUrl } from \"./types\";\n\nexport class ReadonlyUrl implements IReadonlyUrl {\n protected native: URL;\n protected protocol: string;\n protected subdomain: string | null;\n protected domain: string;\n protected hostname: string;\n protected port: number;\n protected path: string;\n protected queries: Record<string, ScalarType> = {};\n protected fragment: string;\n protected base: string;\n protected origin: string;\n\n constructor(url: string | URL) {\n this.native = new URL(url);\n\n this.protocol = trim(this.native.protocol, \":\");\n this.subdomain = null;\n this.hostname = this.native.hostname;\n this.domain = this.hostname;\n\n // Only parse domain/subdomain for actual domain names, not IP addresses\n const isIpAddress = /^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/.test(this.hostname);\n if (!isIpAddress && this.hostname !== \"localhost\") {\n const match = /(?<subdomain>.+)\\.(?<domain>[a-z0-9-_]+\\.[a-z0-9]+)$/i.exec(this.domain);\n if (match) {\n const { subdomain, domain } = match.groups as {\n subdomain: string;\n domain: string;\n };\n this.subdomain = subdomain;\n this.domain = domain;\n }\n }\n\n // Handle port parsing - native URL omits default ports, but we need to detect them\n if (this.native.port) {\n this.port = parseString(this.native.port);\n } else {\n // Check if the original URL string had an explicit port\n const urlString = typeof url === \"string\" ? url : url.toString();\n const portMatch = urlString.match(/:(\\d+)/);\n if (portMatch) {\n this.port = parseString(portMatch[1] as string);\n } else {\n this.port = 80; // Default port\n }\n }\n // Handle path - preserve structure but handle trailing slashes correctly\n if (this.native.pathname === \"/\") {\n this.path = \"/\";\n } else {\n // Remove all trailing slashes if present, but preserve internal empty segments\n this.path = this.native.pathname.replace(/\\/+$/, \"\");\n }\n this.fragment = trim(this.native.hash, \"#\");\n this.base = `${this.native.protocol}//${this.native.host}`;\n this.origin = this.native.origin;\n\n for (const [key, value] of this.native.searchParams) {\n // Only parse as number/boolean if it's clearly intended to be\n if (value === \"true\") {\n this.queries[key] = true;\n } else if (value === \"false\") {\n this.queries[key] = false;\n } else if (/^\\d+$/.test(value) && !value.startsWith(\"0\")) {\n // Only parse as number if it's all digits and doesn't start with 0 (to preserve \"001\")\n this.queries[key] = Number.parseInt(value, 10);\n } else if (/^-?\\d+(\\.\\d+)?$/.test(value) && !value.startsWith(\"0\")) {\n // Parse as float if it's a valid number\n this.queries[key] = Number.parseFloat(value);\n } else {\n this.queries[key] = value;\n }\n }\n }\n\n public getNative(): URL {\n return this.native;\n }\n\n public getProtocol(): string {\n return this.protocol;\n }\n\n public getSubdomain(): string | null {\n return this.subdomain;\n }\n\n public getDomain(): string {\n return this.domain;\n }\n\n public getHostname(): string {\n return this.hostname;\n }\n\n public getPort(): number {\n return this.port;\n }\n\n public getPath(): string {\n return this.path;\n }\n\n public getQueries(): Record<string, ScalarType> {\n return { ...this.queries };\n }\n\n public getQuery(name: string): ScalarType | null {\n return this.queries[name] || null;\n }\n\n public getLang(): LocaleType {\n const lang = this.queries.lang as LocaleType;\n\n return locales.includes(lang) ? lang : \"en\";\n }\n\n public getPage(): number {\n return (this.queries.page as number) ?? 1;\n }\n\n public getLimit(): number {\n return (this.queries.limit as number) ?? 100;\n }\n\n public getOrder(): \"ASC\" | \"DESC\" {\n const order = this.queries.order;\n\n return [\"ASC\", \"DESC\"].includes(order as string) ? (order as \"ASC\" | \"DESC\") : \"ASC\";\n }\n\n public getOrderBy(): string | null {\n return (this.queries.orderBy as string) ?? null;\n }\n\n public getFragment(): string {\n return this.fragment;\n }\n\n public getBase(): string {\n return this.base;\n }\n\n public getOrigin(): string {\n return this.origin;\n }\n\n public toString(): string {\n return this.native.toString();\n }\n}\n",
6
6
  "import type { ScalarType } from \"@ooneex/types\";\nimport { trim } from \"@ooneex/utils\";\nimport { ReadonlyUrl } from \"./ReadonlyUrl\";\nimport type { IUrl } from \"./types\";\n\nexport class Url extends ReadonlyUrl implements IUrl {\n public setProtocol(protocol: string): this {\n const oldProtocol = this.protocol;\n this.protocol = trim(protocol, \":\");\n\n // Update port based on protocol change if it was a default port\n if (oldProtocol === \"http\" && this.port === 80 && this.protocol === \"https\") {\n this.port = 80; // Keep 80 as default for all protocols as per tests\n } else if (oldProtocol === \"https\" && this.port === 443 && this.protocol === \"http\") {\n this.port = 80; // Keep 80 as default for all protocols as per tests\n }\n\n this.updateNativeUrl();\n return this;\n }\n\n public setHostname(hostname: string): this {\n this.hostname = hostname;\n\n this.subdomain = null;\n this.domain = hostname;\n\n // Only parse domain/subdomain for actual domain names, not IP addresses\n const isIpAddress = /^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/.test(hostname);\n if (!isIpAddress && hostname !== \"localhost\") {\n const match = /(?<subdomain>.+)\\.(?<domain>[a-z0-9-_]+\\.[a-z0-9]+)$/i.exec(hostname);\n if (match) {\n const { subdomain, domain } = match.groups as {\n subdomain: string;\n domain: string;\n };\n this.subdomain = subdomain;\n this.domain = domain;\n }\n }\n\n this.updateNativeUrl();\n return this;\n }\n\n public setPort(port: number): this {\n this.port = port;\n this.updateNativeUrl();\n return this;\n }\n\n public setPath(path: string): this {\n if (path === \"\") {\n this.path = \"/\";\n } else {\n this.path = `/${trim(path, \"/\")}`;\n }\n this.updateNativeUrl();\n return this;\n }\n\n public addQuery(key: string, value: ScalarType): this {\n this.queries[key] = value;\n this.updateNativeUrl();\n return this;\n }\n\n public removeQuery(key: string): this {\n delete this.queries[key];\n this.updateNativeUrl();\n return this;\n }\n\n public setQueries(queries: Record<string, ScalarType>): this {\n this.queries = { ...queries };\n this.updateNativeUrl();\n return this;\n }\n\n public clearQueries(): this {\n this.queries = {};\n this.updateNativeUrl();\n return this;\n }\n\n public setFragment(fragment: string): this {\n this.fragment = trim(fragment, \"#\");\n this.updateNativeUrl();\n return this;\n }\n\n private updateNativeUrl() {\n const protocol = this.protocol.includes(\":\") ? this.protocol : `${this.protocol}:`;\n const port = this.shouldShowPort() ? `:${this.port}` : \"\";\n const path = this.path;\n const queryString = this.buildQueryString();\n const fragment = this.fragment ? `#${this.fragment}` : \"\";\n const urlString = `${protocol}//${this.hostname}${port}${path}${queryString}${fragment}`;\n this.native = new URL(urlString);\n this.base = this.shouldShowPort() ? `${protocol}//${this.hostname}${port}` : `${protocol}//${this.hostname}`;\n this.origin = this.shouldShowPort() ? `${protocol}//${this.hostname}${port}` : `${protocol}//${this.hostname}`;\n }\n\n private shouldShowPort(): boolean {\n if (this.protocol === \"http\" && this.port === 80) return false;\n if (this.protocol === \"https\" && this.port === 443) return false;\n if (this.port === 80) return false; // Don't show default port 80\n return true;\n }\n\n private buildQueryString(): string {\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(this.queries)) {\n params.set(key, String(value));\n }\n const queryString = params.toString();\n return queryString ? `?${queryString}` : \"\";\n }\n}\n"
7
7
  ],
8
- "mappings": "AACA,sBAAS,UAAa,sBAGf,MAAM,CAAoC,CACrC,OACA,SACA,UACA,OACA,SACA,KACA,KACA,QAAsC,CAAC,EACvC,SACA,KACA,OAEV,WAAW,CAAC,EAAmB,CAU7B,GATA,KAAK,OAAS,IAAI,IAAI,CAAG,EAEzB,KAAK,SAAW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,KAAK,YACjE,EAAO,KAAK,eAAe,EAAI,IAAI,KAAK,OAAS,GACjD,EAAO,KAAK,KACZ,EAAc,KAAK,iBAAiB,EACpC,EAAW,KAAK,SAAW,IAAI,KAAK,WAAa,GACjD,EAAY,GAAG,MAAa,KAAK,WAAW,IAAO,IAAO,IAAc,IAC9E,KAAK,OAAS,IAAI,IAAI,CAAS,EAC/B,KAAK,KAAO,KAAK,eAAe,EAAI,GAAG,MAAa,KAAK,WAAW,IAAS,GAAG,MAAa,KAAK,WAClG,KAAK,OAAS,KAAK,eAAe,EAAI,GAAG,MAAa,KAAK,WAAW,IAAS,GAAG,MAAa,KAAK,WAG9F,cAAc,EAAY,CAChC,GAAI,KAAK,WAAa,QAAU,KAAK,OAAS,GAAI,MAAO,GACzD,GAAI,KAAK,WAAa,SAAW,KAAK,OAAS,IAAK,MAAO,GAC3D,GAAI,KAAK,OAAS,GAAI,MAAO,GAC7B,MAAO,GAGD,gBAAgB,EAAW,CACjC,IAAM,EAAS,IAAI,gBACnB,QAAY,EAAK,KAAU,OAAO,QAAQ,KAAK,OAAO,EACpD,EAAO,IAAI,EAAK,OAAO,CAAK,CAAC,EAE/B,IAAM,EAAc,EAAO,SAAS,EACpC,OAAO,EAAc,IAAI,IAAgB,GAE7C",
9
+ "debugId": "DB4678099ADEB82564756E2164756E21",
10
10
  "names": []
11
11
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ooneex/url",
3
- "description": "URL parsing, manipulation, and query string utilities for web applications",
4
- "version": "0.16.0",
3
+ "description": "URL parsing and manipulation library with query string handling, path normalization, and route parameter extraction for web applications",
4
+ "version": "1.0.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -28,10 +28,11 @@
28
28
  "npm:publish": "bun publish --tolerate-republish --access public"
29
29
  },
30
30
  "dependencies": {
31
- "@ooneex/utils": "0.1.0"
31
+ "@ooneex/utils": "0.1.1"
32
32
  },
33
33
  "devDependencies": {
34
- "@ooneex/types": "0.0.16"
34
+ "@ooneex/types": "0.0.19",
35
+ "@ooneex/translation": "0.0.18"
35
36
  },
36
37
  "keywords": [
37
38
  "bun",