@ooneex/url 0.0.1 → 0.3.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/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 e=/(?<subdomain>.+)\.(?<domain>[a-z0-9-_]+\.[a-z0-9]+)$/i.exec(this.domain);if(e){let{subdomain:r,domain:U}=e.groups;this.subdomain=r,this.domain=U}}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[e,r]of this.native.searchParams)if(r==="true")this.queries[e]=!0;else if(r==="false")this.queries[e]=!1;else if(/^\d+$/.test(r)&&!r.startsWith("0"))this.queries[e]=Number.parseInt(r,10);else if(/^-?\d+(\.\d+)?$/.test(r)&&!r.startsWith("0"))this.queries[e]=Number.parseFloat(r);else this.queries[e]=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 s extends i{setProtocol(g){let I=this.protocol;if(this.protocol=Q(g,":"),I==="http"&&this.port===80&&this.protocol==="https")this.port=80;else if(I==="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 e=/(?<subdomain>.+)\.(?<domain>[a-z0-9-_]+\.[a-z0-9]+)$/i.exec(g);if(e){let{subdomain:r,domain:U}=e.groups;this.subdomain=r,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=`/${Q(g,"/")}`;return this.updateNativeUrl(),this}addQuery(g,I){return this.queries[g]=I,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}:`,I=this.shouldShowPort()?`:${this.port}`:"",e=this.path,r=this.buildQueryString(),U=this.fragment?`#${this.fragment}`:"",T=`${g}//${this.hostname}${I}${e}${r}${U}`;this.native=new URL(T),this.base=this.shouldShowPort()?`${g}//${this.hostname}${I}`:`${g}//${this.hostname}`,this.origin=this.shouldShowPort()?`${g}//${this.hostname}${I}`:`${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[e,r]of Object.entries(this.queries))g.set(e,String(r));let I=g.toString();return I?`?${I}`:""}}export{s as Url,i as ReadonlyUrl};
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};
2
2
 
3
- //# debugId=E5A2C3518A1FC26E64756E2164756E21
3
+ //# debugId=8D777E4D61C20EA464756E2164756E21
package/dist/index.js.map CHANGED
@@ -6,6 +6,6 @@
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
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,EAAK,KAAK,OAAO,SAAU,GAAG,EAC9C,KAAK,UAAY,KACjB,KAAK,SAAW,KAAK,OAAO,SAC5B,KAAK,OAAS,KAAK,SAIf,CADgB,uCAAuC,KAAK,KAAK,QAAQ,GACzD,KAAK,WAAa,YAAa,CACjD,IAAM,EAAQ,wDAAwD,KAAK,KAAK,MAAM,EACtF,GAAI,EAAO,CACT,IAAQ,YAAW,UAAW,EAAM,OAIpC,KAAK,UAAY,EACjB,KAAK,OAAS,GAKlB,GAAI,KAAK,OAAO,KACd,KAAK,KAAO,EAAY,KAAK,OAAO,IAAI,EACnC,KAGL,IAAM,GADY,OAAO,IAAQ,SAAW,EAAM,EAAI,SAAS,GACnC,MAAM,QAAQ,EAC1C,GAAI,EACF,KAAK,KAAO,EAAY,EAAU,EAAY,EAE9C,UAAK,KAAO,GAIhB,GAAI,KAAK,OAAO,WAAa,IAC3B,KAAK,KAAO,IAGZ,UAAK,KAAO,KAAK,OAAO,SAAS,QAAQ,OAAQ,EAAE,EAErD,KAAK,SAAW,EAAK,KAAK,OAAO,KAAM,GAAG,EAC1C,KAAK,KAAO,GAAG,KAAK,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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": "E5A2C3518A1FC26E64756E2164756E21",
9
+ "debugId": "8D777E4D61C20EA464756E2164756E21",
10
10
  "names": []
11
11
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ooneex/url",
3
- "description": "",
4
- "version": "0.0.1",
3
+ "description": "URL parsing, manipulation, and query string utilities for web applications",
4
+ "version": "0.3.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -25,14 +25,22 @@
25
25
  "test": "bun test tests",
26
26
  "build": "bunup",
27
27
  "lint": "tsgo --noEmit && bunx biome lint",
28
- "publish:prod": "bun publish --tolerate-republish --access public",
29
- "publish:pack": "bun pm pack --destination ./dist",
30
- "publish:dry": "bun publish --dry-run"
28
+ "publish": "bun publish --access public || true"
31
29
  },
32
30
  "dependencies": {
33
31
  "@ooneex/utils": "0.0.8"
34
32
  },
35
33
  "devDependencies": {
36
34
  "@ooneex/types": "0.0.1"
37
- }
35
+ },
36
+ "keywords": [
37
+ "bun",
38
+ "ooneex",
39
+ "path",
40
+ "query-string",
41
+ "routing",
42
+ "typescript",
43
+ "uri",
44
+ "url"
45
+ ]
38
46
  }
Binary file