@gjsify/url 0.38.0 → 0.39.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 +11 -5
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import e from"@girs/glib-2.0";const
|
|
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()}var o=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(`&`)){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])}has(e){return this._entries.some(([t])=>t===e)}delete(e){this._entries=this._entries.filter(([t])=>t!==e)}append(e,t){this._entries.push([e,t])}sort(){this._entries.sort((e,t)=>e[0]<t[0]?-1:+(e[0]>t[0]))}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 encodeComponent(e){return encodeURIComponent(e).replace(/%20/g,`+`)}var s=class URL{#e;#t;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.#t=new o(this.#e.get_query()||``)}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(){let e=this.#e.get_query();return e?`?`+e:``}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.search,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 s=i.indexOf(`?`);s!==-1&&(r.search=i.slice(s),r.query=t?Object.fromEntries(new o(i.slice(s+1))):i.slice(s+1),i=i.slice(0,s));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 s)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 o(t.query).toString();e&&(n+=`?`+e)}return t.hash&&(n+=t.hash),n}function resolve(e,t){return new s(t,new s(e,`resolve://`)).href.replace(/^resolve:\/\//,``)}function fileURLToPath(e,n){if(typeof e==`string`&&(e=new s(e)),!(e instanceof s))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 s(i(o,{windows:a}))}function domainToASCII(e){try{return new s(`http://${e}`).hostname}catch{return``}}function domainToUnicode(e){try{return new s(`http://${e}`).hostname}catch{return``}}var c={URL:s,URLSearchParams:o,parse,format,resolve,fileURLToPath,pathToFileURL,domainToASCII,domainToUnicode};export{s as URL,o as URLSearchParams,c as default,domainToASCII,domainToUnicode,fileURLToPath,format,parse,pathToFileURL,resolve};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -62,8 +62,26 @@ export interface Url extends UrlObject {
|
|
|
62
62
|
export declare function parse(urlString: string, parseQueryString?: boolean, slashesDenoteHost?: boolean): Url;
|
|
63
63
|
export declare function format(urlObject: UrlObject | string | URL): string;
|
|
64
64
|
export declare function resolve(from: string, to: string): string;
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
/**
|
|
66
|
+
* @param options.windows read the URL as naming a win32 path — Node's own escape hatch
|
|
67
|
+
* (`refs/node/lib/internal/url.js`), and the only way to ask for the non-host answer from
|
|
68
|
+
* a POSIX runner. Defaults to the host.
|
|
69
|
+
*/
|
|
70
|
+
export declare function fileURLToPath(url: string | URL, options?: {
|
|
71
|
+
windows?: boolean;
|
|
72
|
+
}): string;
|
|
73
|
+
/**
|
|
74
|
+
* @param options.windows treat `filepath` as a win32 path even where the host is not — Node's
|
|
75
|
+
* own escape hatch (`refs/node/lib/internal/url.js`), and how the win32 behaviour is checked
|
|
76
|
+
* from the Linux runner CI actually has (#1143).
|
|
77
|
+
*
|
|
78
|
+
* Not yet at Node parity: Node runs `path.win32.resolve()` first, so a RELATIVE path gets the
|
|
79
|
+
* current drive. Here a relative path is still joined to the CWD with `/`. Recorded in
|
|
80
|
+
* `status/open-todos.md` rather than half-done.
|
|
81
|
+
*/
|
|
82
|
+
export declare function pathToFileURL(filepath: string, options?: {
|
|
83
|
+
windows?: boolean;
|
|
84
|
+
}): URL;
|
|
67
85
|
export declare function domainToASCII(domain: string): string;
|
|
68
86
|
export declare function domainToUnicode(domain: string): string;
|
|
69
87
|
declare const _default: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/url",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.0",
|
|
4
4
|
"description": "Node.js url module for Gjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -39,11 +39,12 @@
|
|
|
39
39
|
"fs"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@girs/glib-2.0": "^4.1.0"
|
|
42
|
+
"@girs/glib-2.0": "^4.1.0",
|
|
43
|
+
"@gjsify/utils": "^0.39.0"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"@gjsify/cli": "^0.
|
|
46
|
-
"@gjsify/unit": "^0.
|
|
46
|
+
"@gjsify/cli": "^0.39.0",
|
|
47
|
+
"@gjsify/unit": "^0.39.0",
|
|
47
48
|
"@types/node": "^25.9.2",
|
|
48
49
|
"typescript": "^6.0.3"
|
|
49
50
|
},
|
|
@@ -54,7 +55,12 @@
|
|
|
54
55
|
"browser": "native",
|
|
55
56
|
"nativescript": "none"
|
|
56
57
|
},
|
|
57
|
-
"tier": 1
|
|
58
|
+
"tier": 1,
|
|
59
|
+
"os": {
|
|
60
|
+
"linux": "supported",
|
|
61
|
+
"darwin": "supported",
|
|
62
|
+
"win32": "supported"
|
|
63
|
+
}
|
|
58
64
|
},
|
|
59
65
|
"license": "MIT",
|
|
60
66
|
"repository": {
|