@gjsify/url 0.41.0 → 0.43.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/lib/esm/index.js +1 -1
- package/lib/types/index.d.ts +20 -2
- package/package.json +4 -4
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import e from"@girs/glib-2.0";import{hostOs as t,isWin32 as n,isWindowsPath as r,pathToFileUrlHref as i}from"@gjsify/utils/core";const a=e.UriFlags.HAS_PASSWORD|e.UriFlags.ENCODED|e.UriFlags.SCHEME_NORMALIZE;function platformOrShapeIsWindows(e){return t()===void 0?r(e):n()}
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import e from"@girs/glib-2.0";import{hostOs as t,isWin32 as n,isWindowsPath as r,pathToFileUrlHref as i}from"@gjsify/utils/core";const a=e.UriFlags.HAS_PASSWORD|e.UriFlags.ENCODED|e.UriFlags.SCHEME_NORMALIZE;function platformOrShapeIsWindows(e){return t()===void 0?r(e):n()}const o=new WeakMap;var s=class URLSearchParams{_entries=[];constructor(e){if(e)if(typeof e==`string`){let t=e.startsWith(`?`)?e.slice(1):e;if(t)for(let e of t.split(`&`)){if(e===``)continue;let t=e.indexOf(`=`);t===-1?this._entries.push([decodeComponent(e),``]):this._entries.push([decodeComponent(e.slice(0,t)),decodeComponent(e.slice(t+1))])}}else if(Array.isArray(e))for(let[t,n]of e)this._entries.push([String(t),String(n)]);else if(e instanceof URLSearchParams)this._entries=e._entries.map(([e,t])=>[e,t]);else for(let t of Object.keys(e))this._entries.push([t,String(e[t])])}get(e){for(let[t,n]of this._entries)if(t===e)return n;return null}getAll(e){return this._entries.filter(([t])=>t===e).map(([,e])=>e)}set(e,t){let n=!1;if(this._entries=this._entries.filter(([t])=>t===e?n?!1:(n=!0,!0):!0),n){for(let n=0;n<this._entries.length;n++)if(this._entries[n][0]===e){this._entries[n][1]=t;break}}else this._entries.push([e,t]);o.get(this)?.()}has(e,t){return t===void 0?this._entries.some(([t])=>t===e):this._entries.some(([n,r])=>n===e&&r===t)}delete(e,t){this._entries=t===void 0?this._entries.filter(([t])=>t!==e):this._entries.filter(([n,r])=>!(n===e&&r===t)),o.get(this)?.()}append(e,t){this._entries.push([e,t]),o.get(this)?.()}sort(){this._entries.sort((e,t)=>e[0]<t[0]?-1:+(e[0]>t[0])),o.get(this)?.()}toString(){return this._entries.map(([e,t])=>encodeComponent(e)+`=`+encodeComponent(t)).join(`&`)}forEach(e){for(let[t,n]of this._entries)e(n,t,this)}*entries(){yield*this._entries}*keys(){for(let[e]of this._entries)yield e}*values(){for(let[,e]of this._entries)yield e}[Symbol.iterator](){return this.entries()}get size(){return this._entries.length}};function decodeComponent(e){try{return decodeURIComponent(e.replace(/\+/g,` `))}catch{return e}}function percentEncodeUtf8(e){let t=``;for(let n of new TextEncoder().encode(e))t+=`%${n.toString(16).toUpperCase().padStart(2,`0`)}`;return t}function encodeComponent(e){let t=``;for(let n of e)n===` `?t+=`+`:/^[A-Za-z0-9*\-._]$/.test(n)?t+=n:t+=percentEncodeUtf8(n);return t}const c=new Set([`http:`,`https:`,`ws:`,`wss:`,`ftp:`,`file:`]);function encodeQuery(e,t){let n=``;for(let r of e){let e=r.codePointAt(0);n+=e<=32||e>126||r===`"`||r===`#`||r===`<`||r===`>`||t&&r===`'`?percentEncodeUtf8(r):r}return n}var l=class URL{#e;#t;#n;constructor(t,n){let r=t instanceof URL?t.href:String(t);try{if(n!==void 0){let t=n instanceof URL?n.href:String(n),i=e.Uri.parse(t,a);this.#e=i.parse_relative(r,a)}else this.#e=e.Uri.parse(r,a)}catch{throw TypeError(`Invalid URL: ${r}`)}if(!this.#e)throw TypeError(`Invalid URL: ${r}`);this.#n=this.#e.get_query()??null,this.#t=new s(this.#n||``),o.set(this.#t,()=>{let e=this.#t.toString();this.#n=e===``?null:e})}get protocol(){return this.#e.get_scheme()+`:`}get hostname(){return(this.#e.get_host()||``).toLowerCase()}get port(){let e=this.#e.get_port();if(e===-1)return``;let t=this.#e.get_scheme();return(t===`http`||t===`ws`)&&e===80||(t===`https`||t===`wss`)&&e===443||t===`ftp`&&e===21?``:String(e)}get host(){let e=this.hostname,t=this.port;return t?`${e}:${t}`:e}get pathname(){return this.#e.get_path()||`/`}get search(){return this.#n?`?`+this.#n:``}set search(e){let t=String(e).replace(/[\t\n\r]/g,``);if(t===``){this.#n=null,this.#t._entries=[];return}let n=t.startsWith(`?`)?t.slice(1):t;this.#n=encodeQuery(n,c.has(this.protocol)),this.#t._entries=new s(n)._entries}get hash(){let e=this.#e.get_fragment();return e?`#`+e:``}get origin(){let e=this.protocol;return e===`http:`||e===`https:`||e===`ftp:`?`${e}//${this.host}`:`null`}get username(){return this.#e.get_user()||``}get password(){return this.#e.get_password()||``}get href(){let e=this.protocol,t=this.#e.get_scheme();(t===`http`||t===`https`||t===`ftp`||t===`file`||t===`ws`||t===`wss`||this.hostname)&&(e+=`//`);let n=this.username,r=this.password;n&&(e+=n,r&&(e+=`:`+r),e+=`@`),e+=this.hostname,this.port&&(e+=`:`+this.port);let i=this.pathname;return e+=i,e+=this.#n===null?``:`?${this.#n}`,e+=this.hash,e}get searchParams(){return this.#t}toString(){return this.href}toJSON(){return this.href}static _objectURLPaths=new Map;static _objectURLCounter=0;static createObjectURL(e){let t=e?._tmpPath;if(typeof t==`string`&&t.length>0){let e=`file://${t}`;return URL._objectURLPaths.set(e,t),e}return`file:///dev/null`}static revokeObjectURL(t){let n=URL._objectURLPaths.get(t);n&&(e.unlink(n),URL._objectURLPaths.delete(t))}};function parse(e,t,n){if(typeof e!=`string`)throw TypeError(`The "url" argument must be of type string. Received type `+typeof e);let r={protocol:null,slashes:null,auth:null,host:null,port:null,hostname:null,hash:null,search:null,query:null,pathname:null,path:null,href:e},i=e.trim(),a=i.indexOf(`#`);a!==-1&&(r.hash=i.slice(a),i=i.slice(0,a));let o=i.indexOf(`?`);o!==-1&&(r.search=i.slice(o),r.query=t?Object.fromEntries(new s(i.slice(o+1))):i.slice(o+1),i=i.slice(0,o));let c=/^([a-z][a-z0-9.+-]*:)/i.exec(i);if(c&&(r.protocol=c[1].toLowerCase(),i=i.slice(r.protocol.length)),(n||r.protocol)&&i.startsWith(`//`)&&(r.slashes=!0,i=i.slice(2)),r.slashes||r.protocol&&![`javascript:`,`data:`,`mailto:`].includes(r.protocol)){let e=-1;for(let t=0;t<i.length;t++){let n=i[t];if(n===`/`||n===`\\`){e=t;break}}let t=e===-1?i:i.slice(0,e);i=e===-1?``:i.slice(e);let n=t.lastIndexOf(`@`);n===-1?parseHostPort(t,r):(r.auth=decodeURIComponent(t.slice(0,n)),parseHostPort(t.slice(n+1),r))}return r.pathname=i||(r.slashes?`/`:null),(r.pathname!==null||r.search!==null)&&(r.path=(r.pathname||``)+(r.search||``)),r.href=format(r),r}function parseHostPort(e,t){if(!e)return;let n=e.indexOf(`[`);if(n!==-1){let r=e.indexOf(`]`,n);if(r!==-1){let i=e.slice(r+1);i.startsWith(`:`)&&(t.port=i.slice(1)),t.hostname=e.slice(n,r+1),t.host=t.hostname+(t.port?`:`+t.port:``);return}}let r=e.lastIndexOf(`:`);if(r!==-1){let n=e.slice(r+1);/^\d*$/.test(n)?(t.port=n||null,t.hostname=e.slice(0,r).toLowerCase()):t.hostname=e.toLowerCase()}else t.hostname=e.toLowerCase();t.host=t.hostname+(t.port?`:`+t.port:``)}function format(e){if(typeof e==`string`)return e;if(e instanceof l)return e.href;let t=e,n=``;if(t.protocol&&(n+=t.protocol),(t.slashes||t.protocol&&![`javascript:`,`data:`,`mailto:`].includes(t.protocol||``))&&(n+=`//`),t.auth&&(n+=encodeURIComponent(t.auth)+`@`),t.host?n+=t.host:(t.hostname&&(n+=t.hostname),t.port&&(n+=`:`+t.port)),t.pathname&&(n+=t.pathname),t.search)n+=t.search;else if(t.query&&typeof t.query==`object`){let e=new s(t.query).toString();e&&(n+=`?`+e)}return t.hash&&(n+=t.hash),n}function resolve(e,t){return new l(t,new l(e,`resolve://`)).href.replace(/^resolve:\/\//,``)}function fileURLToPath(e,n){if(typeof e==`string`&&(e=new l(e)),!(e instanceof l))throw TypeError(`The "url" argument must be of type string or URL. Received type `+typeof e);if(e.protocol!==`file:`)throw TypeError(`The URL must be of scheme file`);let r=e.pathname,i=n?.windows??platformOrShapeIsWindows(r.slice(1));for(let e=0;e<r.length;e++){if(r[e]!==`%`)continue;let t=r.codePointAt(e+2)|32,n=r[e+1]===`2`&&t===102,a=r[e+1]===`5`&&t===99;if(i&&(n||a))throw TypeError(`File URL path must not include encoded \\ or / characters`);if(n)throw TypeError(`File URL path must not include encoded / characters`)}if(e.hostname!==``&&e.hostname!==`localhost`){if(!i)throw TypeError(`File URL host must be "localhost" or empty on ${t()??`this platform`}`);return`\\\\${e.hostname}${decodeURIComponent(r).replace(/\//g,`\\`)}`}if(i){let e=decodeURIComponent(r);return/^\/[A-Za-z]:/.test(e)?e.slice(1).replace(/\//g,`\\`):e.replace(/\//g,`\\`)}return decodeURIComponent(r)}function pathToFileURL(t,n){let a=n?.windows??platformOrShapeIsWindows(t),o=t;return a&&r(t)||t.startsWith(`/`)||(typeof globalThis.process?.cwd==`function`?o=globalThis.process.cwd()+`/`+t:e?.get_current_dir&&(o=e.get_current_dir()+`/`+t)),new l(i(o,{windows:a}))}function domainToASCII(e){try{return new l(`http://${e}`).hostname}catch{return``}}function domainToUnicode(e){try{return new l(`http://${e}`).hostname}catch{return``}}var u={URL:l,URLSearchParams:s,parse,format,resolve,fileURLToPath,pathToFileURL,domainToASCII,domainToUnicode};export{l as URL,s as URLSearchParams,u as default,domainToASCII,domainToUnicode,fileURLToPath,format,parse,pathToFileURL,resolve};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -4,8 +4,13 @@ export declare class URLSearchParams {
|
|
|
4
4
|
get(name: string): string | null;
|
|
5
5
|
getAll(name: string): string[];
|
|
6
6
|
set(name: string, value: string): void;
|
|
7
|
-
has(name: string): boolean;
|
|
8
|
-
|
|
7
|
+
has(name: string, value?: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* The `value` argument is not optional decoration: ignoring it silently — as this did — turns
|
|
10
|
+
* `delete('a', '1')` on `?a=1&a=2` into "delete every a", and with the update steps in place
|
|
11
|
+
* that wipes the whole query out of `href` instead of leaving `?a=2`.
|
|
12
|
+
*/
|
|
13
|
+
delete(name: string, value?: string): void;
|
|
9
14
|
append(name: string, value: string): void;
|
|
10
15
|
sort(): void;
|
|
11
16
|
toString(): string;
|
|
@@ -25,6 +30,19 @@ export declare class URL {
|
|
|
25
30
|
get host(): string;
|
|
26
31
|
get pathname(): string;
|
|
27
32
|
get search(): string;
|
|
33
|
+
/**
|
|
34
|
+
* Replace the whole query.
|
|
35
|
+
*
|
|
36
|
+
* A setter and not merely a getter: assigning `url.search` is how Node code sets a query in
|
|
37
|
+
* one go, and without it the obvious workaround for the missing write-back — building a
|
|
38
|
+
* string and assigning it — threw `TypeError: setting getter-only property`, leaving no way
|
|
39
|
+
* to put a query on a URL at all.
|
|
40
|
+
*
|
|
41
|
+
* The existing `searchParams` object is refilled in place rather than replaced, because the
|
|
42
|
+
* spec makes it a stable identity: code that captured `const p = url.searchParams` before
|
|
43
|
+
* the assignment must still see the new values.
|
|
44
|
+
*/
|
|
45
|
+
set search(value: string);
|
|
28
46
|
get hash(): string;
|
|
29
47
|
get origin(): string;
|
|
30
48
|
get username(): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/url",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"description": "Node.js url module for Gjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@girs/glib-2.0": "^4.1.0",
|
|
43
|
-
"@gjsify/utils": "^0.
|
|
43
|
+
"@gjsify/utils": "^0.43.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@gjsify/cli": "^0.
|
|
47
|
-
"@gjsify/unit": "^0.
|
|
46
|
+
"@gjsify/cli": "^0.43.0",
|
|
47
|
+
"@gjsify/unit": "^0.43.0",
|
|
48
48
|
"@types/node": "^25.9.2",
|
|
49
49
|
"typescript": "^6.0.3"
|
|
50
50
|
},
|