@naverpay/nurl 1.0.0 → 1.0.2-rc.251022-7a1a841
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/cjs/index.d.ts +77 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/nurl.js +1 -0
- package/dist/cjs/punycode.js +1 -0
- package/dist/cjs/utils.js +1 -0
- package/dist/esm/index.d.mts +77 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/nurl.mjs +211 -0
- package/dist/esm/punycode.mjs +88 -0
- package/dist/esm/utils.mjs +47 -0
- package/package.json +2 -2
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
type Query = Record<string, any>;
|
|
2
|
+
|
|
3
|
+
interface URLOptions extends Partial<Pick<URL, 'href' | 'protocol' | 'host' | 'hostname' | 'port' | 'pathname' | 'search' | 'hash' | 'username' | 'password'>> {
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
query?: Query;
|
|
6
|
+
basePath?: string;
|
|
7
|
+
}
|
|
8
|
+
declare class NURL implements URL {
|
|
9
|
+
private _href;
|
|
10
|
+
private _protocol;
|
|
11
|
+
private _host;
|
|
12
|
+
private _hostname;
|
|
13
|
+
private _port;
|
|
14
|
+
private _pathname;
|
|
15
|
+
private _search;
|
|
16
|
+
private _hash;
|
|
17
|
+
private _origin;
|
|
18
|
+
private _username;
|
|
19
|
+
private _password;
|
|
20
|
+
private _baseUrl;
|
|
21
|
+
private _searchParams;
|
|
22
|
+
private _basePath;
|
|
23
|
+
constructor(input?: string | URL | URLOptions);
|
|
24
|
+
static withBasePath(basePath: string): (urlOptions?: string | URL | URLOptions) => NURL;
|
|
25
|
+
static create(input?: string | URL | URLOptions): NURL;
|
|
26
|
+
static canParse(input: string): boolean;
|
|
27
|
+
get baseUrl(): string;
|
|
28
|
+
set baseUrl(value: string);
|
|
29
|
+
get href(): string;
|
|
30
|
+
set href(value: string);
|
|
31
|
+
static parseStringToURLLike(value: string): {
|
|
32
|
+
href: string;
|
|
33
|
+
protocol: string;
|
|
34
|
+
host: string;
|
|
35
|
+
hostname: string;
|
|
36
|
+
port: string;
|
|
37
|
+
pathname: string;
|
|
38
|
+
search: string;
|
|
39
|
+
hash: string;
|
|
40
|
+
origin: string;
|
|
41
|
+
username: string;
|
|
42
|
+
password: string;
|
|
43
|
+
searchParams: URLSearchParams;
|
|
44
|
+
} | null;
|
|
45
|
+
get protocol(): string;
|
|
46
|
+
set protocol(value: string);
|
|
47
|
+
get host(): string;
|
|
48
|
+
set host(value: string);
|
|
49
|
+
get hostname(): string;
|
|
50
|
+
set hostname(value: string);
|
|
51
|
+
get port(): string;
|
|
52
|
+
set port(value: string);
|
|
53
|
+
get pathname(): string;
|
|
54
|
+
set pathname(inputPathname: string);
|
|
55
|
+
get search(): string;
|
|
56
|
+
set search(search: string);
|
|
57
|
+
setSearchParams(_params: Record<string, string>): void;
|
|
58
|
+
appendSearchParams(_params: Record<string, string>): void;
|
|
59
|
+
removeSearchParams(..._keys: string[]): void;
|
|
60
|
+
get searchParams(): URLSearchParams;
|
|
61
|
+
get hash(): string;
|
|
62
|
+
set hash(value: string);
|
|
63
|
+
get origin(): string;
|
|
64
|
+
get username(): string;
|
|
65
|
+
set username(value: string);
|
|
66
|
+
get password(): string;
|
|
67
|
+
set password(value: string);
|
|
68
|
+
private updateHref;
|
|
69
|
+
toString(): string;
|
|
70
|
+
toJSON(): string;
|
|
71
|
+
private punycodePrefix;
|
|
72
|
+
private encodeHostname;
|
|
73
|
+
get decodedIDN(): string;
|
|
74
|
+
get decodedHostname(): string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { NURL as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const r=require("./nurl.js");module.exports=r;
|
package/dist/cjs/nurl.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const m=require("./punycode.js"),r=require("./utils.js");class i{constructor(t){if(this._href="",this._protocol="",this._host="",this._hostname="",this._port="",this._pathname="",this._search="",this._hash="",this._origin="",this._username="",this._password="",this._baseUrl="",this._searchParams=new URLSearchParams,this._basePath="",this.punycodePrefix="xn--",this._searchParams=new URLSearchParams,typeof t=="string"||t instanceof URL)this.href=t.toString();else if(t){if(t.basePath&&(this._basePath=t.basePath.startsWith("/")?t.basePath:`/${t.basePath}`),t.baseUrl&&(this.baseUrl=t.baseUrl),t.href&&(this.href=t.href),t.protocol&&(this.protocol=t.protocol),t.host&&(this.host=t.host),t.hostname&&(this.hostname=t.hostname),t.port&&(this.port=t.port),t.pathname!==void 0&&(t.pathname===""?this._pathname="":this.pathname=r.refinePathnameWithQuery(t.pathname,t.query??{})),t.search&&(this.search=t.search),t.hash&&(this.hash=t.hash),t.username&&(this.username=t.username),t.password&&(this.password=t.password),t.query){const s=r.refineQueryWithPathname(t.pathname??"",t.query);Object.keys(s).length>0&&(this.search=new URLSearchParams(r.convertQueryToArray(s)).toString())}this.updateHref()}}static withBasePath(t){return s=>typeof s=="string"||s instanceof URL?new i({href:s.toString(),basePath:t}):new i({...s,basePath:t})}static create(t){return new i(t)}static canParse(t){if(t.startsWith("/"))return/^\/[^?#]*(\?[^#]*)?(#.*)?$/.test(t);try{return new URL(t),!0}catch{return/^[^:/?#]+(\.[^:/?#]+)+(\/[^?#]*(\?[^#]*)?(#.*)?)?$/.test(t)}}get baseUrl(){return this._baseUrl}set baseUrl(t){this._baseUrl=t;try{const s=new URL(t);this._protocol=s.protocol,this._host=s.host,this._hostname=s.hostname,this._port=s.port,this._origin=s.origin,this._username=s.username,this._password=s.password,s.pathname!=="/"&&(this._pathname=s.pathname),s.search&&(this._search=s.search,this._searchParams=new URLSearchParams(s.search)),s.hash&&(this._hash=s.hash),this.updateHref()}catch(s){console.warn(`Invalid baseUrl: ${t}`,s)}}get href(){return this._href}set href(t){try{const s=new URL(t);this._href=s.href,this._protocol=s.protocol,this._host=s.host,this._hostname=s.hostname,this._port=s.port,this._pathname=s.pathname,this._search=s.search,this._hash=s.hash,this._origin=s.origin,this._username=s.username,this._password=s.password,this._searchParams=s.searchParams}catch(s){const e=i.parseStringToURLLike(t);if(!e)throw console.warn(`Can not parse ${t}`),s;this._href=e.href,this._protocol=e.protocol,this._host=e.hostname,this._hostname=e.hostname,this._port=e.port,this._pathname=e.pathname,this._search=e.search,this._hash=e.hash,this._origin=e.origin,this._username=e.username,this._password=e.password,this._searchParams=e.searchParams}}static parseStringToURLLike(t){const s=/^(?:(https?:\/\/)(?:([^:@]+)(?::([^@]+))?@)?((?:[^/:?#]+)(?::(\d+))?)?)?([/][^?#]*)?(\?[^#]*)?(#.*)?$/,e=t.match(s),[h=t,a="",n="",d="",o="",c="",p="",_="",f=""]=e||[];if(!e||a&&!o&&!p&&!_&&!f)return null;const P=a&&o?`${a}//${o}${c?`:${c}`:""}`:"";return{href:h,protocol:a,host:o,hostname:o,port:c,pathname:t?p||"/":"",search:_,hash:f,origin:P,username:n,password:d,searchParams:new URLSearchParams(_)}}get protocol(){return this._protocol}set protocol(t){this._protocol=t,this.updateHref()}get host(){return this._host}set host(t){const[s,e]=t.split(":"),h=this.encodeHostname(s);this._host=e?`${h}:${e}`:h,this._hostname=h,this._port=e||"",this.updateHref()}get hostname(){return this._hostname}set hostname(t){const s=this.encodeHostname(t);this._hostname=s,this._host=this._port?`${s}:${this._port}`:s,this.updateHref()}get port(){return this._port}set port(t){this._port=t,this._host=`${this._hostname}${t?":"+t:""}`,this.updateHref()}get pathname(){return this._pathname}set pathname(t){let s=t;if(t===""){s="/",this._pathname=s,this.updateHref();return}this._basePath&&!s.startsWith(this._basePath)&&(s=`${this._basePath}${s.startsWith("/")?"":"/"}${s}`);const e=s.split("/").map(h=>r.isDynamicPath(h)?h:encodeURI(h)).join("/");this._pathname=e.startsWith("/")?e:`/${e}`,this.updateHref()}get search(){return this._search}set search(t){this._search=t.startsWith("?")?t:`?${t}`,this._searchParams=new URLSearchParams(t),this.updateHref()}setSearchParams(t){const s=new URLSearchParams(t);this._search=s.toString()?`?${s.toString()}`:"",this._searchParams=s,this.updateHref()}appendSearchParams(t){const s=new URLSearchParams(this._searchParams),e=r.getDynamicPaths(this._pathname).map(r.extractPathKey);Object.keys(t).forEach(h=>{e.includes(h)?this._pathname=r.refinePathnameWithQuery(this._pathname,{[h]:t[h]}):s.append(h,t[h])}),this._search=s.toString()?`?${s.toString()}`:"",this._searchParams=s,this.updateHref()}removeSearchParams(...t){const s=new URLSearchParams(this._searchParams);t.forEach(e=>{s.delete(e)}),this._search=s.toString()?`?${s.toString()}`:"",this._searchParams=s,this.updateHref()}get searchParams(){return new Proxy(this._searchParams,{get:(t,s,e)=>{const h=Reflect.get(t,s,e);return typeof h=="function"?(...a)=>{const n=h.apply(t,a);return this._search=this._searchParams.toString()?`?${this._searchParams.toString()}`:"",this.updateHref(),n}:h}})}get hash(){return this._hash}set hash(t){this._hash=t.startsWith("#")?t:`#${t}`,this.updateHref()}get origin(){return this._origin}get username(){return this._username}set username(t){this._username=t,this.updateHref()}get password(){return this._password}set password(t){this._password=t,this.updateHref()}updateHref(){const t=this._pathname;if(this._baseUrl){const s=new URL(this._baseUrl);s.pathname=t,s.search=this._search,s.hash=this._hash,this._href=s.href,this._origin=s.origin}else this._href=`${this._protocol}${this._protocol&&"//"}${this._username}${this._password?":"+this._password:""}${this._username||this._password?"@":""}${this._hostname}${this._port?":"+this._port:""}${t}${this._search}${this._hash}`,this._origin=`${this._protocol}//${this._hostname}${this._port?":"+this._port:""}`}toString(){return this.href}toJSON(){return this.href}encodeHostname(t){return t.split(".").map(s=>{for(const e of s)if(r.isASCIICodeChar(e))return`${this.punycodePrefix}${m.encode(s)}`;return s}).join(".")}get decodedIDN(){let t=this._href;return this._hostname.split(".").forEach(s=>{t=t.replace(s,m.decode(s.replace(this.punycodePrefix,"")))}),t}get decodedHostname(){return this._hostname.split(".").map(t=>m.decode(t.replace(this.punycodePrefix,""))).join(".")}}module.exports=i;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=2147483647,f=36,T=1,v=26,L=38,V=700,I=72,O=128,S="-",q={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},M=f-T,a=Math.floor,m=String.fromCharCode;function p(t){throw new RangeError(q[t])}function j(t){const n=[];let s=0;const e=t.length;for(;s<e;){const o=t.charCodeAt(s++);if(o>=55296&&o<=56319&&s<e){const r=t.charCodeAt(s++);(r&64512)==56320?n.push(((o&1023)<<10)+(r&1023)+65536):(n.push(o),s--)}else n.push(o)}return n}const B=t=>t>=48&&t<58?26+(t-48):t>=65&&t<91?t-65:t>=97&&t<123?t-97:f,A=(t,n)=>t+22+75*(t<26?1:0)-0,y=(t,n,s)=>{let e=0;for(t=s?a(t/V):t>>1,t+=a(t/n);t>M*v>>1;e+=f)t=a(t/M);return a(e+(M+1)*t/(t+L))},D=t=>{const n=[],s=t.length;let e=0,o=O,r=I,u=t.lastIndexOf(S);u<0&&(u=0);for(let c=0;c<u;++c)t.charCodeAt(c)>=128&&p("not-basic"),n.push(t.charCodeAt(c));for(let c=u>0?u+1:0;c<s;){const g=e;for(let d=1,l=f;;l+=f){c>=s&&p("invalid-input");const h=B(t.charCodeAt(c++));h>=f&&p("invalid-input"),h>a((C-e)/d)&&p("overflow"),e+=h*d;const b=l<=r?T:l>=r+v?v:l-r;if(h<b)break;const w=f-b;d>a(C/w)&&p("overflow"),d*=w}const i=n.length+1;r=y(e-g,i,g==0),a(e/i)>C-o&&p("overflow"),o+=a(e/i),e%=i,n.splice(e++,0,o)}return String.fromCodePoint(...n)},E=t=>{const n=[],s=j(t),e=s.length;let o=O,r=0,u=I;for(const i of s)i<128&&n.push(m(i));const c=n.length;let g=c;for(c&&n.push(S);g<e;){let i=C;for(const l of s)l>=o&&l<i&&(i=l);const d=g+1;i-o>a((C-r)/d)&&p("overflow"),r+=(i-o)*d,o=i;for(const l of s)if(l<o&&++r>C&&p("overflow"),l===o){let h=r;for(let b=f;;b+=f){const w=b<=u?T:b>=u+v?v:b-u;if(h<w)break;const k=h-w,x=f-w;n.push(m(A(w+k%x))),h=a(k/x)}n.push(m(A(h))),u=y(r,d,g===c),r=0,++g}++r,++o}return n.join("")};exports.decode=D;exports.encode=E;exports.ucs2decode=j;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=/^:/,P=/^\[.*\]$/;function y(e){return c.test(e)||P.test(e)}function o(e){return e.split("/").filter(y)}function a(e){return e.slice(1,c.test(e)?void 0:-1)}function h(e,r){return o(e).reduce((t,n)=>{const i=a(n),u=r[i];return u&&typeof u=="string"?t.replace(n,u):t},e)}function A(e,r){return o(e).reduce((t,n)=>{const i=a(n);if(typeof t[i]!="string")return t;const{[i]:g,...f}=t;return f},r)}const C=127;function m(e){return e.charCodeAt(0)>C}function s(e){return["string","number","boolean"].includes(typeof e)}function d(e){return Object.entries(e).flatMap(([r,t])=>s(t)?[[r,String(t)]]:Array.isArray(t)&&t.every(s)?t.map(n=>[r,String(n)]):[])}exports.convertQueryToArray=d;exports.extractPathKey=a;exports.getDynamicPaths=o;exports.isASCIICodeChar=m;exports.isDynamicPath=y;exports.refinePathnameWithQuery=h;exports.refineQueryWithPathname=A;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
type Query = Record<string, any>;
|
|
2
|
+
|
|
3
|
+
interface URLOptions extends Partial<Pick<URL, 'href' | 'protocol' | 'host' | 'hostname' | 'port' | 'pathname' | 'search' | 'hash' | 'username' | 'password'>> {
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
query?: Query;
|
|
6
|
+
basePath?: string;
|
|
7
|
+
}
|
|
8
|
+
declare class NURL implements URL {
|
|
9
|
+
private _href;
|
|
10
|
+
private _protocol;
|
|
11
|
+
private _host;
|
|
12
|
+
private _hostname;
|
|
13
|
+
private _port;
|
|
14
|
+
private _pathname;
|
|
15
|
+
private _search;
|
|
16
|
+
private _hash;
|
|
17
|
+
private _origin;
|
|
18
|
+
private _username;
|
|
19
|
+
private _password;
|
|
20
|
+
private _baseUrl;
|
|
21
|
+
private _searchParams;
|
|
22
|
+
private _basePath;
|
|
23
|
+
constructor(input?: string | URL | URLOptions);
|
|
24
|
+
static withBasePath(basePath: string): (urlOptions?: string | URL | URLOptions) => NURL;
|
|
25
|
+
static create(input?: string | URL | URLOptions): NURL;
|
|
26
|
+
static canParse(input: string): boolean;
|
|
27
|
+
get baseUrl(): string;
|
|
28
|
+
set baseUrl(value: string);
|
|
29
|
+
get href(): string;
|
|
30
|
+
set href(value: string);
|
|
31
|
+
static parseStringToURLLike(value: string): {
|
|
32
|
+
href: string;
|
|
33
|
+
protocol: string;
|
|
34
|
+
host: string;
|
|
35
|
+
hostname: string;
|
|
36
|
+
port: string;
|
|
37
|
+
pathname: string;
|
|
38
|
+
search: string;
|
|
39
|
+
hash: string;
|
|
40
|
+
origin: string;
|
|
41
|
+
username: string;
|
|
42
|
+
password: string;
|
|
43
|
+
searchParams: URLSearchParams;
|
|
44
|
+
} | null;
|
|
45
|
+
get protocol(): string;
|
|
46
|
+
set protocol(value: string);
|
|
47
|
+
get host(): string;
|
|
48
|
+
set host(value: string);
|
|
49
|
+
get hostname(): string;
|
|
50
|
+
set hostname(value: string);
|
|
51
|
+
get port(): string;
|
|
52
|
+
set port(value: string);
|
|
53
|
+
get pathname(): string;
|
|
54
|
+
set pathname(inputPathname: string);
|
|
55
|
+
get search(): string;
|
|
56
|
+
set search(search: string);
|
|
57
|
+
setSearchParams(_params: Record<string, string>): void;
|
|
58
|
+
appendSearchParams(_params: Record<string, string>): void;
|
|
59
|
+
removeSearchParams(..._keys: string[]): void;
|
|
60
|
+
get searchParams(): URLSearchParams;
|
|
61
|
+
get hash(): string;
|
|
62
|
+
set hash(value: string);
|
|
63
|
+
get origin(): string;
|
|
64
|
+
get username(): string;
|
|
65
|
+
set username(value: string);
|
|
66
|
+
get password(): string;
|
|
67
|
+
set password(value: string);
|
|
68
|
+
private updateHref;
|
|
69
|
+
toString(): string;
|
|
70
|
+
toJSON(): string;
|
|
71
|
+
private punycodePrefix;
|
|
72
|
+
private encodeHostname;
|
|
73
|
+
get decodedIDN(): string;
|
|
74
|
+
get decodedHostname(): string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { NURL as default };
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { encode as l, decode as p } from "./punycode.mjs";
|
|
2
|
+
import { refinePathnameWithQuery as f, refineQueryWithPathname as g, convertQueryToArray as $, isDynamicPath as u, getDynamicPaths as w, extractPathKey as S, isASCIICodeChar as U } from "./utils.mjs";
|
|
3
|
+
class i {
|
|
4
|
+
constructor(t) {
|
|
5
|
+
if (this._href = "", this._protocol = "", this._host = "", this._hostname = "", this._port = "", this._pathname = "", this._search = "", this._hash = "", this._origin = "", this._username = "", this._password = "", this._baseUrl = "", this._searchParams = new URLSearchParams(), this._basePath = "", this.punycodePrefix = "xn--", this._searchParams = new URLSearchParams(), typeof t == "string" || t instanceof URL)
|
|
6
|
+
this.href = t.toString();
|
|
7
|
+
else if (t) {
|
|
8
|
+
if (t.basePath && (this._basePath = t.basePath.startsWith("/") ? t.basePath : `/${t.basePath}`), t.baseUrl && (this.baseUrl = t.baseUrl), t.href && (this.href = t.href), t.protocol && (this.protocol = t.protocol), t.host && (this.host = t.host), t.hostname && (this.hostname = t.hostname), t.port && (this.port = t.port), t.pathname !== void 0 && (t.pathname === "" ? this._pathname = "" : this.pathname = f(t.pathname, t.query ?? {})), t.search && (this.search = t.search), t.hash && (this.hash = t.hash), t.username && (this.username = t.username), t.password && (this.password = t.password), t.query) {
|
|
9
|
+
const s = g(t.pathname ?? "", t.query);
|
|
10
|
+
Object.keys(s).length > 0 && (this.search = new URLSearchParams($(s)).toString());
|
|
11
|
+
}
|
|
12
|
+
this.updateHref();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
static withBasePath(t) {
|
|
16
|
+
return (s) => typeof s == "string" || s instanceof URL ? new i({
|
|
17
|
+
href: s.toString(),
|
|
18
|
+
basePath: t
|
|
19
|
+
}) : new i({
|
|
20
|
+
...s,
|
|
21
|
+
basePath: t
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
static create(t) {
|
|
25
|
+
return new i(t);
|
|
26
|
+
}
|
|
27
|
+
static canParse(t) {
|
|
28
|
+
if (t.startsWith("/"))
|
|
29
|
+
return /^\/[^?#]*(\?[^#]*)?(#.*)?$/.test(t);
|
|
30
|
+
try {
|
|
31
|
+
return new URL(t), !0;
|
|
32
|
+
} catch {
|
|
33
|
+
return /^[^:/?#]+(\.[^:/?#]+)+(\/[^?#]*(\?[^#]*)?(#.*)?)?$/.test(t);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
get baseUrl() {
|
|
37
|
+
return this._baseUrl;
|
|
38
|
+
}
|
|
39
|
+
set baseUrl(t) {
|
|
40
|
+
this._baseUrl = t;
|
|
41
|
+
try {
|
|
42
|
+
const s = new URL(t);
|
|
43
|
+
this._protocol = s.protocol, this._host = s.host, this._hostname = s.hostname, this._port = s.port, this._origin = s.origin, this._username = s.username, this._password = s.password, s.pathname !== "/" && (this._pathname = s.pathname), s.search && (this._search = s.search, this._searchParams = new URLSearchParams(s.search)), s.hash && (this._hash = s.hash), this.updateHref();
|
|
44
|
+
} catch (s) {
|
|
45
|
+
console.warn(`Invalid baseUrl: ${t}`, s);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
get href() {
|
|
49
|
+
return this._href;
|
|
50
|
+
}
|
|
51
|
+
set href(t) {
|
|
52
|
+
try {
|
|
53
|
+
const s = new URL(t);
|
|
54
|
+
this._href = s.href, this._protocol = s.protocol, this._host = s.host, this._hostname = s.hostname, this._port = s.port, this._pathname = s.pathname, this._search = s.search, this._hash = s.hash, this._origin = s.origin, this._username = s.username, this._password = s.password, this._searchParams = s.searchParams;
|
|
55
|
+
} catch (s) {
|
|
56
|
+
const e = i.parseStringToURLLike(t);
|
|
57
|
+
if (!e)
|
|
58
|
+
throw console.warn(`Can not parse ${t}`), s;
|
|
59
|
+
this._href = e.href, this._protocol = e.protocol, this._host = e.hostname, this._hostname = e.hostname, this._port = e.port, this._pathname = e.pathname, this._search = e.search, this._hash = e.hash, this._origin = e.origin, this._username = e.username, this._password = e.password, this._searchParams = e.searchParams;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
static parseStringToURLLike(t) {
|
|
63
|
+
const s = /^(?:(https?:\/\/)(?:([^:@]+)(?::([^@]+))?@)?((?:[^/:?#]+)(?::(\d+))?)?)?([/][^?#]*)?(\?[^#]*)?(#.*)?$/, e = t.match(s), [h = t, r = "", o = "", d = "", a = "", n = "", _ = "", c = "", m = ""] = e || [];
|
|
64
|
+
if (!e || r && !a && !_ && !c && !m)
|
|
65
|
+
return null;
|
|
66
|
+
const P = r && a ? `${r}//${a}${n ? `:${n}` : ""}` : "";
|
|
67
|
+
return {
|
|
68
|
+
href: h,
|
|
69
|
+
protocol: r,
|
|
70
|
+
host: a,
|
|
71
|
+
hostname: a,
|
|
72
|
+
port: n,
|
|
73
|
+
pathname: t ? _ || "/" : "",
|
|
74
|
+
search: c,
|
|
75
|
+
hash: m,
|
|
76
|
+
origin: P,
|
|
77
|
+
username: o,
|
|
78
|
+
password: d,
|
|
79
|
+
searchParams: new URLSearchParams(c)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
get protocol() {
|
|
83
|
+
return this._protocol;
|
|
84
|
+
}
|
|
85
|
+
set protocol(t) {
|
|
86
|
+
this._protocol = t, this.updateHref();
|
|
87
|
+
}
|
|
88
|
+
get host() {
|
|
89
|
+
return this._host;
|
|
90
|
+
}
|
|
91
|
+
set host(t) {
|
|
92
|
+
const [s, e] = t.split(":"), h = this.encodeHostname(s);
|
|
93
|
+
this._host = e ? `${h}:${e}` : h, this._hostname = h, this._port = e || "", this.updateHref();
|
|
94
|
+
}
|
|
95
|
+
get hostname() {
|
|
96
|
+
return this._hostname;
|
|
97
|
+
}
|
|
98
|
+
set hostname(t) {
|
|
99
|
+
const s = this.encodeHostname(t);
|
|
100
|
+
this._hostname = s, this._host = this._port ? `${s}:${this._port}` : s, this.updateHref();
|
|
101
|
+
}
|
|
102
|
+
get port() {
|
|
103
|
+
return this._port;
|
|
104
|
+
}
|
|
105
|
+
set port(t) {
|
|
106
|
+
this._port = t, this._host = `${this._hostname}${t ? ":" + t : ""}`, this.updateHref();
|
|
107
|
+
}
|
|
108
|
+
get pathname() {
|
|
109
|
+
return this._pathname;
|
|
110
|
+
}
|
|
111
|
+
set pathname(t) {
|
|
112
|
+
let s = t;
|
|
113
|
+
if (t === "") {
|
|
114
|
+
s = "/", this._pathname = s, this.updateHref();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
this._basePath && !s.startsWith(this._basePath) && (s = `${this._basePath}${s.startsWith("/") ? "" : "/"}${s}`);
|
|
118
|
+
const e = s.split("/").map((h) => u(h) ? h : encodeURI(h)).join("/");
|
|
119
|
+
this._pathname = e.startsWith("/") ? e : `/${e}`, this.updateHref();
|
|
120
|
+
}
|
|
121
|
+
get search() {
|
|
122
|
+
return this._search;
|
|
123
|
+
}
|
|
124
|
+
set search(t) {
|
|
125
|
+
this._search = t.startsWith("?") ? t : `?${t}`, this._searchParams = new URLSearchParams(t), this.updateHref();
|
|
126
|
+
}
|
|
127
|
+
setSearchParams(t) {
|
|
128
|
+
const s = new URLSearchParams(t);
|
|
129
|
+
this._search = s.toString() ? `?${s.toString()}` : "", this._searchParams = s, this.updateHref();
|
|
130
|
+
}
|
|
131
|
+
appendSearchParams(t) {
|
|
132
|
+
const s = new URLSearchParams(this._searchParams), e = w(this._pathname).map(S);
|
|
133
|
+
Object.keys(t).forEach((h) => {
|
|
134
|
+
e.includes(h) ? this._pathname = f(this._pathname, {
|
|
135
|
+
[h]: t[h]
|
|
136
|
+
}) : s.append(h, t[h]);
|
|
137
|
+
}), this._search = s.toString() ? `?${s.toString()}` : "", this._searchParams = s, this.updateHref();
|
|
138
|
+
}
|
|
139
|
+
removeSearchParams(...t) {
|
|
140
|
+
const s = new URLSearchParams(this._searchParams);
|
|
141
|
+
t.forEach((e) => {
|
|
142
|
+
s.delete(e);
|
|
143
|
+
}), this._search = s.toString() ? `?${s.toString()}` : "", this._searchParams = s, this.updateHref();
|
|
144
|
+
}
|
|
145
|
+
get searchParams() {
|
|
146
|
+
return new Proxy(this._searchParams, {
|
|
147
|
+
get: (t, s, e) => {
|
|
148
|
+
const h = Reflect.get(t, s, e);
|
|
149
|
+
return typeof h == "function" ? (...r) => {
|
|
150
|
+
const o = h.apply(t, r);
|
|
151
|
+
return this._search = this._searchParams.toString() ? `?${this._searchParams.toString()}` : "", this.updateHref(), o;
|
|
152
|
+
} : h;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
get hash() {
|
|
157
|
+
return this._hash;
|
|
158
|
+
}
|
|
159
|
+
set hash(t) {
|
|
160
|
+
this._hash = t.startsWith("#") ? t : `#${t}`, this.updateHref();
|
|
161
|
+
}
|
|
162
|
+
get origin() {
|
|
163
|
+
return this._origin;
|
|
164
|
+
}
|
|
165
|
+
get username() {
|
|
166
|
+
return this._username;
|
|
167
|
+
}
|
|
168
|
+
set username(t) {
|
|
169
|
+
this._username = t, this.updateHref();
|
|
170
|
+
}
|
|
171
|
+
get password() {
|
|
172
|
+
return this._password;
|
|
173
|
+
}
|
|
174
|
+
set password(t) {
|
|
175
|
+
this._password = t, this.updateHref();
|
|
176
|
+
}
|
|
177
|
+
updateHref() {
|
|
178
|
+
const t = this._pathname;
|
|
179
|
+
if (this._baseUrl) {
|
|
180
|
+
const s = new URL(this._baseUrl);
|
|
181
|
+
s.pathname = t, s.search = this._search, s.hash = this._hash, this._href = s.href, this._origin = s.origin;
|
|
182
|
+
} else
|
|
183
|
+
this._href = `${this._protocol}${this._protocol && "//"}${this._username}${this._password ? ":" + this._password : ""}${this._username || this._password ? "@" : ""}${this._hostname}${this._port ? ":" + this._port : ""}${t}${this._search}${this._hash}`, this._origin = `${this._protocol}//${this._hostname}${this._port ? ":" + this._port : ""}`;
|
|
184
|
+
}
|
|
185
|
+
toString() {
|
|
186
|
+
return this.href;
|
|
187
|
+
}
|
|
188
|
+
toJSON() {
|
|
189
|
+
return this.href;
|
|
190
|
+
}
|
|
191
|
+
encodeHostname(t) {
|
|
192
|
+
return t.split(".").map((s) => {
|
|
193
|
+
for (const e of s)
|
|
194
|
+
if (U(e))
|
|
195
|
+
return `${this.punycodePrefix}${l(s)}`;
|
|
196
|
+
return s;
|
|
197
|
+
}).join(".");
|
|
198
|
+
}
|
|
199
|
+
get decodedIDN() {
|
|
200
|
+
let t = this._href;
|
|
201
|
+
return this._hostname.split(".").forEach((s) => {
|
|
202
|
+
t = t.replace(s, p(s.replace(this.punycodePrefix, "")));
|
|
203
|
+
}), t;
|
|
204
|
+
}
|
|
205
|
+
get decodedHostname() {
|
|
206
|
+
return this._hostname.split(".").map((t) => p(t.replace(this.punycodePrefix, ""))).join(".");
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
export {
|
|
210
|
+
i as default
|
|
211
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const v = "-", k = {
|
|
2
|
+
overflow: "Overflow: input needs wider integers to process",
|
|
3
|
+
"not-basic": "Illegal input >= 0x80 (not a basic code point)",
|
|
4
|
+
"invalid-input": "Invalid input"
|
|
5
|
+
}, g = 35, u = Math.floor, M = String.fromCharCode;
|
|
6
|
+
function b(t) {
|
|
7
|
+
throw new RangeError(k[t]);
|
|
8
|
+
}
|
|
9
|
+
function A(t) {
|
|
10
|
+
const n = [];
|
|
11
|
+
let s = 0;
|
|
12
|
+
const o = t.length;
|
|
13
|
+
for (; s < o; ) {
|
|
14
|
+
const e = t.charCodeAt(s++);
|
|
15
|
+
if (e >= 55296 && e <= 56319 && s < o) {
|
|
16
|
+
const i = t.charCodeAt(s++);
|
|
17
|
+
(i & 64512) == 56320 ? n.push(((e & 1023) << 10) + (i & 1023) + 65536) : (n.push(e), s--);
|
|
18
|
+
} else
|
|
19
|
+
n.push(e);
|
|
20
|
+
}
|
|
21
|
+
return n;
|
|
22
|
+
}
|
|
23
|
+
const T = (t) => t >= 48 && t < 58 ? 26 + (t - 48) : t >= 65 && t < 91 ? t - 65 : t >= 97 && t < 123 ? t - 97 : 36, C = (t, n) => t + 22 + 75 * (t < 26 ? 1 : 0) - 0, I = (t, n, s) => {
|
|
24
|
+
let o = 0;
|
|
25
|
+
for (
|
|
26
|
+
t = s ? u(t / 700) : t >> 1, t += u(t / n);
|
|
27
|
+
/* no initialization */
|
|
28
|
+
t > g * 26 >> 1;
|
|
29
|
+
o += 36
|
|
30
|
+
)
|
|
31
|
+
t = u(t / g);
|
|
32
|
+
return u(o + (g + 1) * t / (t + 38));
|
|
33
|
+
}, B = (t) => {
|
|
34
|
+
const n = [], s = t.length;
|
|
35
|
+
let o = 0, e = 128, i = 72, l = t.lastIndexOf(v);
|
|
36
|
+
l < 0 && (l = 0);
|
|
37
|
+
for (let a = 0; a < l; ++a)
|
|
38
|
+
t.charCodeAt(a) >= 128 && b("not-basic"), n.push(t.charCodeAt(a));
|
|
39
|
+
for (let a = l > 0 ? l + 1 : 0; a < s; ) {
|
|
40
|
+
const p = o;
|
|
41
|
+
for (let h = 1, c = 36; ; c += 36) {
|
|
42
|
+
a >= s && b("invalid-input");
|
|
43
|
+
const f = T(t.charCodeAt(a++));
|
|
44
|
+
f >= 36 && b("invalid-input"), f > u((2147483647 - o) / h) && b("overflow"), o += f * h;
|
|
45
|
+
const x = c <= i ? 1 : c >= i + 26 ? 26 : c - i;
|
|
46
|
+
if (f < x)
|
|
47
|
+
break;
|
|
48
|
+
const d = 36 - x;
|
|
49
|
+
h > u(2147483647 / d) && b("overflow"), h *= d;
|
|
50
|
+
}
|
|
51
|
+
const r = n.length + 1;
|
|
52
|
+
i = I(o - p, r, p == 0), u(o / r) > 2147483647 - e && b("overflow"), e += u(o / r), o %= r, n.splice(o++, 0, e);
|
|
53
|
+
}
|
|
54
|
+
return String.fromCodePoint(...n);
|
|
55
|
+
}, L = (t) => {
|
|
56
|
+
const n = [], s = A(t), o = s.length;
|
|
57
|
+
let e = 128, i = 0, l = 72;
|
|
58
|
+
for (const r of s)
|
|
59
|
+
r < 128 && n.push(M(r));
|
|
60
|
+
const a = n.length;
|
|
61
|
+
let p = a;
|
|
62
|
+
for (a && n.push(v); p < o; ) {
|
|
63
|
+
let r = 2147483647;
|
|
64
|
+
for (const c of s)
|
|
65
|
+
c >= e && c < r && (r = c);
|
|
66
|
+
const h = p + 1;
|
|
67
|
+
r - e > u((2147483647 - i) / h) && b("overflow"), i += (r - e) * h, e = r;
|
|
68
|
+
for (const c of s)
|
|
69
|
+
if (c < e && ++i > 2147483647 && b("overflow"), c === e) {
|
|
70
|
+
let f = i;
|
|
71
|
+
for (let x = 36; ; x += 36) {
|
|
72
|
+
const d = x <= l ? 1 : x >= l + 26 ? 26 : x - l;
|
|
73
|
+
if (f < d)
|
|
74
|
+
break;
|
|
75
|
+
const w = f - d, m = 36 - d;
|
|
76
|
+
n.push(M(C(d + w % m))), f = u(w / m);
|
|
77
|
+
}
|
|
78
|
+
n.push(M(C(f))), l = I(i, h, p === a), i = 0, ++p;
|
|
79
|
+
}
|
|
80
|
+
++i, ++e;
|
|
81
|
+
}
|
|
82
|
+
return n.join("");
|
|
83
|
+
};
|
|
84
|
+
export {
|
|
85
|
+
B as decode,
|
|
86
|
+
L as encode,
|
|
87
|
+
A as ucs2decode
|
|
88
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const s = /^:/, a = /^\[.*\]$/;
|
|
2
|
+
function A(r) {
|
|
3
|
+
return s.test(r) || a.test(r);
|
|
4
|
+
}
|
|
5
|
+
function c(r) {
|
|
6
|
+
return r.split("/").filter(A);
|
|
7
|
+
}
|
|
8
|
+
function f(r) {
|
|
9
|
+
return r.slice(1, s.test(r) ? void 0 : -1);
|
|
10
|
+
}
|
|
11
|
+
function _(r, e) {
|
|
12
|
+
return c(r).reduce((t, n) => {
|
|
13
|
+
const i = f(n), u = e[i];
|
|
14
|
+
return u && typeof u == "string" ? t.replace(n, u) : t;
|
|
15
|
+
}, r);
|
|
16
|
+
}
|
|
17
|
+
function d(r, e) {
|
|
18
|
+
return c(r).reduce((t, n) => {
|
|
19
|
+
const i = f(n);
|
|
20
|
+
if (typeof t[i] != "string")
|
|
21
|
+
return t;
|
|
22
|
+
const {
|
|
23
|
+
[i]: P,
|
|
24
|
+
...y
|
|
25
|
+
} = t;
|
|
26
|
+
return y;
|
|
27
|
+
}, e);
|
|
28
|
+
}
|
|
29
|
+
const C = 127;
|
|
30
|
+
function g(r) {
|
|
31
|
+
return r.charCodeAt(0) > C;
|
|
32
|
+
}
|
|
33
|
+
function o(r) {
|
|
34
|
+
return ["string", "number", "boolean"].includes(typeof r);
|
|
35
|
+
}
|
|
36
|
+
function h(r) {
|
|
37
|
+
return Object.entries(r).flatMap(([e, t]) => o(t) ? [[e, String(t)]] : Array.isArray(t) && t.every(o) ? t.map((n) => [e, String(n)]) : []);
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
h as convertQueryToArray,
|
|
41
|
+
f as extractPathKey,
|
|
42
|
+
c as getDynamicPaths,
|
|
43
|
+
g as isASCIICodeChar,
|
|
44
|
+
A as isDynamicPath,
|
|
45
|
+
_ as refinePathnameWithQuery,
|
|
46
|
+
d as refineQueryWithPathname
|
|
47
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naverpay/nurl",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2-rc.251022-7a1a841",
|
|
4
4
|
"description": "URL build library",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -56,6 +56,6 @@
|
|
|
56
56
|
"release": "changeset publish",
|
|
57
57
|
"markdownlint": "markdownlint '**/*.md' '#.changeset' '#**/CHANGELOG.md'",
|
|
58
58
|
"markdownlint:fix": "markdownlint --fix '**/*.md' '#.changeset' '#**/CHANGELOG.md'",
|
|
59
|
-
"release:canary": "
|
|
59
|
+
"release:canary": "changeset publish --no-git-tag --tag=rc --directory dist"
|
|
60
60
|
}
|
|
61
61
|
}
|