@gjsify/url 0.3.19 → 0.3.21
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/package.json +3 -3
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@girs/glib-2.0";const t=e.UriFlags.HAS_PASSWORD|e.UriFlags.ENCODED|e.UriFlags.SCHEME_NORMALIZE;var n=class
|
|
1
|
+
import e from"@girs/glib-2.0";const t=e.UriFlags.HAS_PASSWORD|e.UriFlags.ENCODED|e.UriFlags.SCHEME_NORMALIZE;var n=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 r=class URL{#e;#t;constructor(r,i){let a=r instanceof URL?r.href:String(r);try{if(i!==void 0){let n=i instanceof URL?i.href:String(i),r=e.Uri.parse(n,t);this.#e=r.parse_relative(a,t)}else this.#e=e.Uri.parse(a,t)}catch{throw TypeError(`Invalid URL: ${a}`)}if(!this.#e)throw TypeError(`Invalid URL: ${a}`);this.#t=new n(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);if(n){try{e.unlink(n)}catch{}URL._objectURLPaths.delete(t)}}};function parse(e,t,r){if(typeof e!=`string`)throw TypeError(`The "url" argument must be of type string. Received type `+typeof e);let i={protocol:null,slashes:null,auth:null,host:null,port:null,hostname:null,hash:null,search:null,query:null,pathname:null,path:null,href:e},a=e.trim(),o=a.indexOf(`#`);o!==-1&&(i.hash=a.slice(o),a=a.slice(0,o));let s=a.indexOf(`?`);s!==-1&&(i.search=a.slice(s),i.query=t?Object.fromEntries(new n(a.slice(s+1))):a.slice(s+1),a=a.slice(0,s));let c=/^([a-z][a-z0-9.+-]*:)/i.exec(a);if(c&&(i.protocol=c[1].toLowerCase(),a=a.slice(i.protocol.length)),(r||i.protocol)&&a.startsWith(`//`)&&(i.slashes=!0,a=a.slice(2)),i.slashes||i.protocol&&![`javascript:`,`data:`,`mailto:`].includes(i.protocol)){let e=-1;for(let t=0;t<a.length;t++){let n=a[t];if(n===`/`||n===`\\`){e=t;break}}let t=e===-1?a:a.slice(0,e);a=e===-1?``:a.slice(e);let n=t.lastIndexOf(`@`);n===-1?parseHostPort(t,i):(i.auth=decodeURIComponent(t.slice(0,n)),parseHostPort(t.slice(n+1),i))}return i.pathname=a||(i.slashes?`/`:null),(i.pathname!==null||i.search!==null)&&(i.path=(i.pathname||``)+(i.search||``)),i.href=format(i),i}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 r)return e.href;let t=e,i=``;if(t.protocol&&(i+=t.protocol),(t.slashes||t.protocol&&![`javascript:`,`data:`,`mailto:`].includes(t.protocol||``))&&(i+=`//`),t.auth&&(i+=encodeURIComponent(t.auth)+`@`),t.host?i+=t.host:(t.hostname&&(i+=t.hostname),t.port&&(i+=`:`+t.port)),t.pathname&&(i+=t.pathname),t.search)i+=t.search;else if(t.query&&typeof t.query==`object`){let e=new n(t.query).toString();e&&(i+=`?`+e)}return t.hash&&(i+=t.hash),i}function resolve(e,t){return new r(t,new r(e,`resolve://`)).href.replace(/^resolve:\/\//,``)}function fileURLToPath(e){if(typeof e==`string`&&(e=new r(e)),!(e instanceof r))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`);if(e.hostname!==``&&e.hostname!==`localhost`)throw TypeError(`File URL host must be "localhost" or empty on linux`);let t=e.pathname;for(let e=0;e<t.length;e++)if(t[e]===`%`){let n=t.codePointAt(e+2)|32;if(t[e+1]===`2`&&n===102)throw TypeError(`File URL path must not include encoded / characters`)}return decodeURIComponent(t)}function pathToFileURL(t){let n=t;if(t[0]!==`/`)if(typeof globalThis.process?.cwd==`function`)n=globalThis.process.cwd()+`/`+t;else try{e?.get_current_dir&&(n=e.get_current_dir()+`/`+t)}catch{}return new r(`file://`+encodePathForURL(n))}function encodePathForURL(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];r>=`a`&&r<=`z`||r>=`A`&&r<=`Z`||r>=`0`&&r<=`9`||r===`/`||r===`-`||r===`_`||r===`.`||r===`~`||r===`:`||r===`@`||r===`!`?t+=r:t+=encodeURIComponent(r)}return t}function domainToASCII(e){try{return new r(`http://${e}`).hostname}catch{return``}}function domainToUnicode(e){try{return new r(`http://${e}`).hostname}catch{return``}}var i={URL:r,URLSearchParams:n,parse,format,resolve,fileURLToPath,pathToFileURL,domainToASCII,domainToUnicode};export{r as URL,n as URLSearchParams,i as default,domainToASCII,domainToUnicode,fileURLToPath,format,parse,pathToFileURL,resolve};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/url",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.21",
|
|
4
4
|
"description": "Node.js url module for Gjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"@girs/glib-2.0": "2.88.0-4.0.0-rc.14"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@gjsify/cli": "^0.3.
|
|
37
|
-
"@gjsify/unit": "^0.3.
|
|
36
|
+
"@gjsify/cli": "^0.3.21",
|
|
37
|
+
"@gjsify/unit": "^0.3.21",
|
|
38
38
|
"@types/node": "^25.6.2",
|
|
39
39
|
"typescript": "^6.0.3"
|
|
40
40
|
}
|