@blyou/reurl 0.0.2 → 0.0.3
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.cjs +1 -1
- package/dist/index.d.cts +24 -1
- package/dist/index.d.mts +24 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=/^[a-zA-Z][a-zA-Z\d+.-]*:/,t=(e,t)=>e&&t&&t[0]!=e?e+t:t;var n=class{constructor(e){this.href=e}get href(){let{username:e,password:n}=this;return this.t+`//`+(e||n?e+t(`:`,n)+`@`:``)+this.h+this.i+this.o+this.u}set href(t){let n=``+t,r=TypeError(`Invalid URL: `+t);if(!e.test(n))throw r;let i=n.indexOf(`#`);if(~i?(this.u=n.slice(i),n=n.slice(0,i)):this.u=``,i=n.indexOf(`?`),~i?(this.o=n.slice(i),n=n.slice(0,i)):this.o=``,this.t=e.exec(n)[0],n=n.slice(this.t.length),this.h=``,!n.startsWith(`//`))throw r;i=n.indexOf(`/`,2),~i?(this.host=n.slice(2,i),n=n.slice(i)):(this.host=n.slice(2),n=``),this.pathname=n,this.p?.l(this.o)}get protocol(){return this.t}set protocol(t){this.t=e.test(t)?t:t+`:`}get host(){return this.h}set host(e){let t=e.lastIndexOf(`@`);if(~t){let[n,r=``]=e.slice(0,t).split(`:`);this.username=n,this.password=r,e=e.slice(t+1)}else this.username=this.password=``;this.h=e;let n=e.indexOf(`:`,e.lastIndexOf(`]`)+1);~n?(this.m=e.slice(0,n),this.R=e.slice(n+1)):(this.m=e,this.R=``)}get hostname(){return this.m}set hostname(e){this.m=e,this.h=e+t(`:`,this.R)}get port(){return this.R}set port(e){this.h=this.m+t(`:`,this.R=e)}get pathname(){return this.i}set pathname(e){this.i=t(`/`,e)||`/`}get search(){return this.o}set search(e){this.o=t(`?`,e),this.p?.l(this.o)}get hash(){return this.u}set hash(e){this.u=t(`#`,e)}get origin(){return this.h?this.t+`//`+this.h:`null`}get searchParams(){return this.p||(this.p=new r(this.o),this.p.S=this),this.p}toString(){return this.href}toJSON(){return this.href}},r=class e{P=[];constructor(t){if(t instanceof e&&(t=[...t]),typeof t==`string`)this.l(t);else if(t!=null)for(let[e,n=``]of Array.isArray(t)?t:Object.entries(t))this.P.push([e,n])}l(e){if(this.P=[],e=e[0]==`?`?e.slice(1):e)for(let t of e.split(`&`)){let[e,n=``]=t.split(`=`);this.P.push([e,n])}}_(){this.S&&(this.S.o=`?`+this)}append(e,t){this._(this.P.push([e,t]))}delete(e,t){this._(this.P=this.P.filter(n=>n[0]!=e||t!=null&&n[1]!=t))}get(e){return this.P.find(t=>t[0]==e)?.[1]??null}getAll(e){return this.P.filter(t=>t[0]==e).map(e=>e[1])}has(e,t){return this.P.some(n=>n[0]==e&&(t==null||n[1]==t))}set(e,t){this.delete(e),this.append(e,t)}sort(){this._(this.P.sort(([e],[t])=>e<t?-1:+(e>t)))}toString(e){return t(e,this.P.map(e=>e.join(`=`)).join(`&`))}*entries(){for(let e of this.P)yield e}*keys(){for(let e of this.P)yield e[0]}*values(){for(let e of this.P)yield e[1]}[Symbol.iterator](){return this.entries()}},i=class{constructor(e){this.href=e}get href(){return this.i+this.o+this.u}set href(e){let t=``+e,n=t.indexOf(`#`);~n?(this.u=t.slice(n),t=t.slice(0,n)):this.u=``,n=t.indexOf(`?`),~n?(this.o=t.slice(n),t=t.slice(0,n)):this.o=``,this.pathname=t,this.p?.l(this.o)}get pathname(){return this.i}set pathname(e){this.i=t(`/`,e)||`/`}get search(){return this.o}set search(e){this.o=t(`?`,e),this.p?.l(this.o)}get hash(){return this.u}set hash(e){this.u=t(`#`,e)}get searchParams(){return this.p||(this.p=new r(this.o),this.p.S=this),this.p}toString(){return this.href}toJSON(){return this.href}};exports.RePath=i,exports.ReSearchParams=r,exports.ReURL=n,exports.prefix=t;
|
package/dist/index.d.cts
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* - `searchParams.set()` 不保留键的原始位置(先删后插)
|
|
12
12
|
* - userinfo 原样保留(原生 URL 会对 username / password 做 percent 编解码,reurl 不做)
|
|
13
13
|
*/
|
|
14
|
+
/** 前缀拼接,确保前缀不重复出现 */
|
|
15
|
+
declare const prefix: (prefix: string | undefined | null, value: string) => string;
|
|
14
16
|
declare class ReURL {
|
|
15
17
|
private _protocol;
|
|
16
18
|
username: string;
|
|
@@ -68,5 +70,26 @@ declare class ReSearchParams {
|
|
|
68
70
|
values(): IterableIterator<string>;
|
|
69
71
|
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
70
72
|
}
|
|
73
|
+
declare class RePath {
|
|
74
|
+
private _pathname;
|
|
75
|
+
private _search;
|
|
76
|
+
private _hash;
|
|
77
|
+
private _searchParams?;
|
|
78
|
+
/**
|
|
79
|
+
* @param path 合法的路径查询串,如 `/a/b/c?x=1&y=2#frag`
|
|
80
|
+
*/
|
|
81
|
+
constructor(path: string | RePath);
|
|
82
|
+
get href(): string;
|
|
83
|
+
set href(value: string);
|
|
84
|
+
get pathname(): string;
|
|
85
|
+
set pathname(value: string);
|
|
86
|
+
get search(): string;
|
|
87
|
+
set search(value: string);
|
|
88
|
+
get hash(): string;
|
|
89
|
+
set hash(value: string);
|
|
90
|
+
get searchParams(): ReSearchParams;
|
|
91
|
+
toString(): string;
|
|
92
|
+
toJSON(): string;
|
|
93
|
+
}
|
|
71
94
|
//#endregion
|
|
72
|
-
export { ReSearchParams, ReURL };
|
|
95
|
+
export { RePath, ReSearchParams, ReURL, prefix };
|
package/dist/index.d.mts
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* - `searchParams.set()` 不保留键的原始位置(先删后插)
|
|
12
12
|
* - userinfo 原样保留(原生 URL 会对 username / password 做 percent 编解码,reurl 不做)
|
|
13
13
|
*/
|
|
14
|
+
/** 前缀拼接,确保前缀不重复出现 */
|
|
15
|
+
declare const prefix: (prefix: string | undefined | null, value: string) => string;
|
|
14
16
|
declare class ReURL {
|
|
15
17
|
private _protocol;
|
|
16
18
|
username: string;
|
|
@@ -68,5 +70,26 @@ declare class ReSearchParams {
|
|
|
68
70
|
values(): IterableIterator<string>;
|
|
69
71
|
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
70
72
|
}
|
|
73
|
+
declare class RePath {
|
|
74
|
+
private _pathname;
|
|
75
|
+
private _search;
|
|
76
|
+
private _hash;
|
|
77
|
+
private _searchParams?;
|
|
78
|
+
/**
|
|
79
|
+
* @param path 合法的路径查询串,如 `/a/b/c?x=1&y=2#frag`
|
|
80
|
+
*/
|
|
81
|
+
constructor(path: string | RePath);
|
|
82
|
+
get href(): string;
|
|
83
|
+
set href(value: string);
|
|
84
|
+
get pathname(): string;
|
|
85
|
+
set pathname(value: string);
|
|
86
|
+
get search(): string;
|
|
87
|
+
set search(value: string);
|
|
88
|
+
get hash(): string;
|
|
89
|
+
set hash(value: string);
|
|
90
|
+
get searchParams(): ReSearchParams;
|
|
91
|
+
toString(): string;
|
|
92
|
+
toJSON(): string;
|
|
93
|
+
}
|
|
71
94
|
//#endregion
|
|
72
|
-
export { ReSearchParams, ReURL };
|
|
95
|
+
export { RePath, ReSearchParams, ReURL, prefix };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const e=/^[a-zA-Z][a-zA-Z\d+.-]*:/,t=(e,t)=>e&&t&&t[0]!=e?e+t:t;var n=class{constructor(e){this.href=e}get href(){let{username:e,password:n}=this;return this.t+`//`+(e||n?e+t(`:`,n)+`@`:``)+this.h+this.i+this.o+this.u}set href(t){let n=``+t,r=TypeError(`Invalid URL: `+t);if(!e.test(n))throw r;let i=n.indexOf(`#`);if(~i?(this.u=n.slice(i),n=n.slice(0,i)):this.u=``,i=n.indexOf(`?`),~i?(this.o=n.slice(i),n=n.slice(0,i)):this.o=``,this.t=e.exec(n)[0],n=n.slice(this.t.length),this.h=``,!n.startsWith(`//`))throw r;i=n.indexOf(`/`,2),~i?(this.host=n.slice(2,i),n=n.slice(i)):(this.host=n.slice(2),n=``),this.pathname=n,this.p?.l(this.o)}get protocol(){return this.t}set protocol(t){this.t=e.test(t)?t:t+`:`}get host(){return this.h}set host(e){let t=e.lastIndexOf(`@`);if(~t){let[n,r=``]=e.slice(0,t).split(`:`);this.username=n,this.password=r,e=e.slice(t+1)}else this.username=this.password=``;this.h=e;let n=e.indexOf(`:`,e.lastIndexOf(`]`)+1);~n?(this.m=e.slice(0,n),this.S=e.slice(n+1)):(this.m=e,this.S=``)}get hostname(){return this.m}set hostname(e){this.m=e,this.h=e+t(`:`,this.S)}get port(){return this.S}set port(e){this.h=this.m+t(`:`,this.S=e)}get pathname(){return this.i}set pathname(e){this.i=t(`/`,e)||`/`}get search(){return this.o}set search(e){this.o=t(`?`,e),this.p?.l(this.o)}get hash(){return this.u}set hash(e){this.u=t(`#`,e)}get origin(){return this.h?this.t+`//`+this.h:`null`}get searchParams(){return this.p||(this.p=new r(this.o),this.p.A=this),this.p}toString(){return this.href}toJSON(){return this.href}},r=class e{v=[];constructor(t){if(t instanceof e&&(t=[...t]),typeof t==`string`)this.l(t);else if(t!=null)for(let[e,n=``]of Array.isArray(t)?t:Object.entries(t))this.v.push([e,n])}l(e){if(this.v=[],e=e[0]==`?`?e.slice(1):e)for(let t of e.split(`&`)){let[e,n=``]=t.split(`=`);this.v.push([e,n])}}O(){this.A&&(this.A.o=`?`+this)}append(e,t){this.O(this.v.push([e,t]))}delete(e,t){this.O(this.v=this.v.filter(n=>n[0]!=e||t!=null&&n[1]!=t))}get(e){return this.v.find(t=>t[0]==e)?.[1]??null}getAll(e){return this.v.filter(t=>t[0]==e).map(e=>e[1])}has(e,t){return this.v.some(n=>n[0]==e&&(t==null||n[1]==t))}set(e,t){this.delete(e),this.append(e,t)}sort(){this.O(this.v.sort(([e],[t])=>e<t?-1:+(e>t)))}toString(e){return t(e,this.v.map(e=>e.join(`=`)).join(`&`))}*entries(){for(let e of this.v)yield e}*keys(){for(let e of this.v)yield e[0]}*values(){for(let e of this.v)yield e[1]}[Symbol.iterator](){return this.entries()}},i=class{constructor(e){this.href=e}get href(){return this.i+this.o+this.u}set href(e){let t=``+e,n=t.indexOf(`#`);~n?(this.u=t.slice(n),t=t.slice(0,n)):this.u=``,n=t.indexOf(`?`),~n?(this.o=t.slice(n),t=t.slice(0,n)):this.o=``,this.pathname=t,this.p?.l(this.o)}get pathname(){return this.i}set pathname(e){this.i=t(`/`,e)||`/`}get search(){return this.o}set search(e){this.o=t(`?`,e),this.p?.l(this.o)}get hash(){return this.u}set hash(e){this.u=t(`#`,e)}get searchParams(){return this.p||(this.p=new r(this.o),this.p.A=this),this.p}toString(){return this.href}toJSON(){return this.href}};export{i as RePath,r as ReSearchParams,n as ReURL,t as prefix};
|