@naverpay/nurl 0.0.9 → 0.0.11

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.
@@ -1,61 +1 @@
1
- interface URLOptions extends Partial<Pick<URL, 'href' | 'protocol' | 'host' | 'hostname' | 'port' | 'pathname' | 'search' | 'hash' | 'username' | 'password'>> {
2
- baseUrl?: string;
3
- query?: Record<string, string>;
4
- basePath?: string;
5
- }
6
- declare class NURL implements URL {
7
- private _href;
8
- private _protocol;
9
- private _host;
10
- private _hostname;
11
- private _port;
12
- private _pathname;
13
- private _search;
14
- private _hash;
15
- private _origin;
16
- private _username;
17
- private _password;
18
- private _baseUrl;
19
- private _searchParams;
20
- private _basePath;
21
- constructor(input?: string | URL | URLOptions);
22
- static withBasePath(basePath: string): (urlOptions?: string | URL | URLOptions) => NURL;
23
- static create(input?: string | URL | URLOptions): NURL;
24
- static canParse(input: string): boolean;
25
- get baseUrl(): string;
26
- set baseUrl(value: string);
27
- get href(): string;
28
- set href(value: string);
29
- get protocol(): string;
30
- set protocol(value: string);
31
- get host(): string;
32
- set host(value: string);
33
- get hostname(): string;
34
- set hostname(value: string);
35
- get port(): string;
36
- set port(value: string);
37
- get pathname(): string;
38
- set pathname(inputPathname: string);
39
- get search(): string;
40
- set search(search: string);
41
- setSearchParams(_params: Record<string, string>): void;
42
- appendSearchParams(_params: Record<string, string>): void;
43
- removeSearchParams(..._keys: string[]): void;
44
- get searchParams(): URLSearchParams;
45
- get hash(): string;
46
- set hash(value: string);
47
- get origin(): string;
48
- get username(): string;
49
- set username(value: string);
50
- get password(): string;
51
- set password(value: string);
52
- private updateHref;
53
- toString(): string;
54
- toJSON(): string;
55
- private punycodePrefix;
56
- private encodeHostname;
57
- get decodedIDN(): string;
58
- get decodedHostname(): string;
59
- }
60
-
61
- export { NURL as default };
1
+ export { default } from './nurl';
package/dist/cjs/index.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";const y="-",L={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},P=35,f=Math.floor,w=String.fromCharCode;function l(e){throw new RangeError(L[e])}function A(e){const t=[];let s=0;const r=e.length;for(;s<r;){const a=e.charCodeAt(s++);if(a>=55296&&a<=56319&&s<r){const h=e.charCodeAt(s++);(h&64512)==56320?t.push(((a&1023)<<10)+(h&1023)+65536):(t.push(a),s--)}else t.push(a)}return t}const W=e=>e>=48&&e<58?26+(e-48):e>=65&&e<91?e-65:e>=97&&e<123?e-97:36,C=(e,t)=>e+22+75*(e<26?1:0)-0,I=(e,t,s)=>{let r=0;for(e=s?f(e/700):e>>1,e+=f(e/t);e>P*26>>1;r+=36)e=f(e/P);return f(r+(P+1)*e/(e+38))},U=e=>{const t=[],s=e.length;let r=0,a=128,h=72,i=e.lastIndexOf(y);i<0&&(i=0);for(let n=0;n<i;++n)e.charCodeAt(n)>=128&&l("not-basic"),t.push(e.charCodeAt(n));for(let n=i>0?i+1:0;n<s;){const u=r;for(let m=1,c=36;;c+=36){n>=s&&l("invalid-input");const _=W(e.charCodeAt(n++));_>=36&&l("invalid-input"),_>f((2147483647-r)/m)&&l("overflow"),r+=_*m;const p=c<=h?1:c>=h+26?26:c-h;if(_<p)break;const d=36-p;m>f(2147483647/d)&&l("overflow"),m*=d}const o=t.length+1;h=I(r-u,o,u==0),f(r/o)>2147483647-a&&l("overflow"),a+=f(r/o),r%=o,t.splice(r++,0,a)}return String.fromCodePoint(...t)},E=e=>{const t=[],s=A(e),r=s.length;let a=128,h=0,i=72;for(const o of s)o<128&&t.push(w(o));const n=t.length;let u=n;for(n&&t.push(y);u<r;){let o=2147483647;for(const c of s)c>=a&&c<o&&(o=c);const m=u+1;o-a>f((2147483647-h)/m)&&l("overflow"),h+=(o-a)*m,a=o;for(const c of s)if(c<a&&++h>2147483647&&l("overflow"),c===a){let _=h;for(let p=36;;p+=36){const d=p<=i?1:p>=i+26?26:p-i;if(_<d)break;const S=_-d,x=36-d;t.push(w(C(d+S%x))),_=f(S/x)}t.push(w(C(_))),i=I(h,m,u===n),h=0,++u}++h,++a}return t.join("")},M=/^:/,v=/^\[.*\]$/;function R(e){return M.test(e)||v.test(e)}function b(e){return e.split("/").filter(R)}function $(e){return e.slice(1,M.test(e)?void 0:-1)}function H(e,t){return b(e).reduce((s,r)=>{const a=$(r);return t[a]?s.replace(r,t[a]):s},e)}function T(e,t){return b(e).reduce((s,r)=>{const a=$(r),{[a]:h,...i}=s;return i},t)}const j=127;function D(e){return e.charCodeAt(0)>j}class g{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){const s=this._basePath;let r=t.pathname;s&&!r.startsWith(s)&&(r=`${s}${r.startsWith("/")?"":"/"}${r}`),this.pathname=H(r,t.query??{})}if(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=T(t.pathname??"",t.query);Object.keys(s).length>0&&(this.search=new URLSearchParams(s).toString())}this.updateHref()}}static withBasePath(t){return s=>typeof s=="string"||s instanceof URL?new g({href:s.toString(),basePath:t}):new g({...s,basePath:t})}static create(t){return new g(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.pathname.length===1?`${this._href}/`: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){console.warn(`Can not parse ${t}`,s)}}get protocol(){return this._protocol}set protocol(t){this._protocol=t,this.updateHref()}get host(){return this._host}set host(t){const[s,r]=t.split(":"),a=this.encodeHostname(s);this._host=r?`${a}:${r}`:a,this._hostname=a,this._port=r||"",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;this._basePath&&!s.startsWith(this._basePath)&&(s=`${this._basePath}${s.startsWith("/")?"":"/"}${s}`);const r=s.split("/").map(a=>R(a)?a:encodeURI(a)).join("/");this._pathname=r.startsWith("/")?r:`/${r}`,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),r=b(this._pathname).map($);Object.keys(t).forEach(a=>{r.includes(a)?this._pathname=H(this._pathname,{[a]:t[a]}):s.append(a,t[a])}),this._search=s.toString()?`?${s.toString()}`:"",this._searchParams=s,this.updateHref()}removeSearchParams(...t){const s=new URLSearchParams(this._searchParams);t.forEach(r=>{s.delete(r)}),this._search=s.toString()?`?${s.toString()}`:"",this._searchParams=s,this.updateHref()}get searchParams(){return new Proxy(this._searchParams,{get:(t,s,r)=>{const a=Reflect.get(t,s,r);return typeof a=="function"?(...h)=>{const i=a.apply(t,h);return this._search=this._searchParams.toString()?`?${this._searchParams.toString()}`:"",this.updateHref(),i}:a}})}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(){if(this._baseUrl){const t=new URL(this._baseUrl);t.pathname=this._pathname,t.search=this._search,t.hash=this._hash,this._href=t.href,this._origin=t.origin}else this._href=`${this._protocol}${this._protocol&&"//"}${this._username}${this._password?":"+this._password:""}${this._username||this._password?"@":""}${this._hostname}${this._port?":"+this._port:""}${this._pathname==="/"?"":this._pathname}${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 r of s)if(D(r))return`${this.punycodePrefix}${E(s)}`;return s}).join(".")}get decodedIDN(){let t=this._href;return this._hostname.split(".").forEach(s=>{t=t.replace(s,U(s.replace(this.punycodePrefix,"")))}),t}get decodedHostname(){return this._hostname.split(".").map(t=>U(t.replace(this.punycodePrefix,""))).join(".")}}module.exports=g;
2
- //# sourceMappingURL=index.js.map
1
+ "use strict";const r=require("./nurl.js");module.exports=r;
@@ -0,0 +1,61 @@
1
+ import { Query } from './utils';
2
+ interface URLOptions extends Partial<Pick<URL, 'href' | 'protocol' | 'host' | 'hostname' | 'port' | 'pathname' | 'search' | 'hash' | 'username' | 'password'>> {
3
+ baseUrl?: string;
4
+ query?: Query;
5
+ basePath?: string;
6
+ }
7
+ export default class NURL implements URL {
8
+ private _href;
9
+ private _protocol;
10
+ private _host;
11
+ private _hostname;
12
+ private _port;
13
+ private _pathname;
14
+ private _search;
15
+ private _hash;
16
+ private _origin;
17
+ private _username;
18
+ private _password;
19
+ private _baseUrl;
20
+ private _searchParams;
21
+ private _basePath;
22
+ constructor(input?: string | URL | URLOptions);
23
+ static withBasePath(basePath: string): (urlOptions?: string | URL | URLOptions) => NURL;
24
+ static create(input?: string | URL | URLOptions): NURL;
25
+ static canParse(input: string): boolean;
26
+ get baseUrl(): string;
27
+ set baseUrl(value: string);
28
+ get href(): string;
29
+ set href(value: string);
30
+ get protocol(): string;
31
+ set protocol(value: string);
32
+ get host(): string;
33
+ set host(value: string);
34
+ get hostname(): string;
35
+ set hostname(value: string);
36
+ get port(): string;
37
+ set port(value: string);
38
+ get pathname(): string;
39
+ set pathname(inputPathname: string);
40
+ get search(): string;
41
+ set search(search: string);
42
+ setSearchParams(_params: Record<string, string>): void;
43
+ appendSearchParams(_params: Record<string, string>): void;
44
+ removeSearchParams(..._keys: string[]): void;
45
+ get searchParams(): URLSearchParams;
46
+ get hash(): string;
47
+ set hash(value: string);
48
+ get origin(): string;
49
+ get username(): string;
50
+ set username(value: string);
51
+ get password(): string;
52
+ set password(value: string);
53
+ private updateHref;
54
+ toString(): string;
55
+ toJSON(): string;
56
+ private punycodePrefix;
57
+ private encodeHostname;
58
+ get decodedIDN(): string;
59
+ get decodedHostname(): string;
60
+ }
61
+ export {};
@@ -0,0 +1 @@
1
+ "use strict";const i=require("./punycode.js"),r=require("./utils.js");class a{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){const s=this._basePath;let e=t.pathname;s&&!e.startsWith(s)&&(e=`${s}${e.startsWith("/")?"":"/"}${e}`),this.pathname=r.refinePathnameWithQuery(e,t.query??{})}if(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 a({href:s.toString(),basePath:t}):new a({...s,basePath:t})}static create(t){return new a(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.pathname.length===1?`${this._href}/`: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){console.warn(`Can not parse ${t}`,s)}}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;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"?(...o)=>{const n=h.apply(t,o);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(){if(this._baseUrl){const t=new URL(this._baseUrl);t.pathname=this._pathname,t.search=this._search,t.hash=this._hash,this._href=t.href,this._origin=t.origin}else this._href=`${this._protocol}${this._protocol&&"//"}${this._username}${this._password?":"+this._password:""}${this._username||this._password?"@":""}${this._hostname}${this._port?":"+this._port:""}${this._pathname==="/"?"":this._pathname}${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}${i.encode(s)}`;return s}).join(".")}get decodedIDN(){let t=this._href;return this._hostname.split(".").forEach(s=>{t=t.replace(s,i.decode(s.replace(this.punycodePrefix,"")))}),t}get decodedHostname(){return this._hostname.split(".").map(t=>i.decode(t.replace(this.punycodePrefix,""))).join(".")}}module.exports=a;
@@ -0,0 +1,55 @@
1
+ interface PunycodeStatic {
2
+ version: string;
3
+ ucs2: {
4
+ decode(string: string): number[];
5
+ encode(codePoints: number[]): string;
6
+ };
7
+ decode(input: string): string;
8
+ encode(input: string): string;
9
+ toASCII(input: string): string;
10
+ toUnicode(input: string): string;
11
+ }
12
+ /**
13
+ * Creates an array containing the numeric code points of each Unicode
14
+ * character in the string.
15
+ * @param {string} string The Unicode input string (UCS-2).
16
+ * @returns {number[]} The new array of code points.
17
+ */
18
+ declare function ucs2decode(string: string): number[];
19
+ /**
20
+ * Creates a string based on an array of numeric code points.
21
+ * @param {number[]} codePoints The array of numeric code points.
22
+ * @returns {string} The new Unicode string (UCS-2).
23
+ */
24
+ declare const ucs2encode: (codePoints: number[]) => string;
25
+ /**
26
+ * Converts a Punycode string of ASCII-only symbols to a string of Unicode symbols.
27
+ * @param {string} input The Punycode string of ASCII-only symbols.
28
+ * @returns {string} The resulting string of Unicode symbols.
29
+ */
30
+ declare const decode: (input: string) => string;
31
+ /**
32
+ * Converts a string of Unicode symbols to a Punycode string of ASCII-only symbols.
33
+ * @param {string} input The string of Unicode symbols.
34
+ * @returns {string} The resulting Punycode string of ASCII-only symbols.
35
+ */
36
+ declare const encode: (input: string) => string;
37
+ /**
38
+ * Converts a Punycode string representing a domain name or an email address to Unicode.
39
+ * @param {string} input The Punycoded domain name or email address.
40
+ * @returns {string} The Unicode representation of the given Punycode string.
41
+ */
42
+ declare const toUnicode: (input: string) => string;
43
+ /**
44
+ * Converts a Unicode string representing a domain name or an email address to Punycode.
45
+ * @param {string} input The domain name or email address to convert.
46
+ * @returns {string} The Punycode representation of the given domain name or email address.
47
+ */
48
+ declare const toASCII: (input: string) => string;
49
+ /** Define the public API */
50
+ /**
51
+ * @description originated from https://unpkg.com/browse/punycode@2.3.1/
52
+ */
53
+ declare const punycode: PunycodeStatic;
54
+ export { ucs2decode, ucs2encode, decode, encode, toASCII, toUnicode };
55
+ export default punycode;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("core-js-pure/features/instance/push.js"),v=2147483647,f=36,k=1,M=26,L=38,V=700,y=72,O=128,S="-",B={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},m=f-k,u=Math.floor,T=String.fromCharCode;function g(t){throw new RangeError(B[t])}function j(t){const n=[];let r=0;const e=t.length;for(;r<e;){const o=t.charCodeAt(r++);if(o>=55296&&o<=56319&&r<e){const s=t.charCodeAt(r++);(s&64512)==56320?b(n).call(n,((o&1023)<<10)+(s&1023)+65536):(b(n).call(n,o),r--)}else b(n).call(n,o)}return n}const D=t=>t>=48&&t<58?26+(t-48):t>=65&&t<91?t-65:t>=97&&t<123?t-97:f,I=(t,n)=>t+22+75*(t<26?1:0)-0,q=(t,n,r)=>{let e=0;for(t=r?u(t/V):t>>1,t+=u(t/n);t>m*M>>1;e+=f)t=u(t/m);return u(e+(m+1)*t/(t+L))},E=t=>{const n=[],r=t.length;let e=0,o=O,s=y,a=t.lastIndexOf(S);a<0&&(a=0);for(let i=0;i<a;++i)t.charCodeAt(i)>=128&&g("not-basic"),b(n).call(n,t.charCodeAt(i));for(let i=a>0?a+1:0;i<r;){const p=e;for(let d=1,l=f;;l+=f){i>=r&&g("invalid-input");const h=D(t.charCodeAt(i++));h>=f&&g("invalid-input"),h>u((v-e)/d)&&g("overflow"),e+=h*d;const w=l<=s?k:l>=s+M?M:l-s;if(h<w)break;const C=f-w;d>u(v/C)&&g("overflow"),d*=C}const c=n.length+1;s=q(e-p,c,p==0),u(e/c)>v-o&&g("overflow"),o+=u(e/c),e%=c,n.splice(e++,0,o)}return String.fromCodePoint(...n)},F=t=>{const n=[],r=j(t),e=r.length;let o=O,s=0,a=y;for(const c of r)c<128&&b(n).call(n,T(c));const i=n.length;let p=i;for(i&&b(n).call(n,S);p<e;){let c=v;for(const l of r)l>=o&&l<c&&(c=l);const d=p+1;c-o>u((v-s)/d)&&g("overflow"),s+=(c-o)*d,o=c;for(const l of r)if(l<o&&++s>v&&g("overflow"),l===o){let h=s;for(let w=f;;w+=f){const C=w<=a?k:w>=a+M?M:w-a;if(h<C)break;const x=h-C,A=f-C;b(n).call(n,T(I(C+x%A))),h=u(x/A)}b(n).call(n,T(I(h))),a=q(s,d,p===i),s=0,++p}++s,++o}return n.join("")};exports.decode=E;exports.encode=F;exports.ucs2decode=j;
@@ -0,0 +1,26 @@
1
+ export type Query = Record<string, string | number | boolean | (string | number | boolean)[]>;
2
+ export declare function isDynamicPath(path: string): boolean;
3
+ export declare function getDynamicPaths(pathname: string): string[];
4
+ export declare function extractPathKey(path: string): string;
5
+ /**
6
+ * Replaces dynamic paths in the pathname with values from the query
7
+ * @param {string} pathname
8
+ * @param {Query} query
9
+ * @returns {string} refined pathname
10
+ */
11
+ export declare function refinePathnameWithQuery(pathname: string, query: Query): string;
12
+ /**
13
+ * Removes queries that have already been used in the pathname.
14
+ * @param {string} pathname
15
+ * @param {Query} query
16
+ * @returns {Query} refined query
17
+ */
18
+ export declare function refineQueryWithPathname(pathname: string, query: Query): Query;
19
+ export declare function isASCIICodeChar(char: string): boolean;
20
+ /**
21
+ * Convert queries to array, if they are not of the defined primitive types, they will not be included in the array.
22
+ * @param {string} pathname
23
+ * @param {Query} query
24
+ * @returns {string[][]} refined query
25
+ */
26
+ export declare function convertQueryToArray(query: Query): string[][];
@@ -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;
@@ -1,61 +1 @@
1
- interface URLOptions extends Partial<Pick<URL, 'href' | 'protocol' | 'host' | 'hostname' | 'port' | 'pathname' | 'search' | 'hash' | 'username' | 'password'>> {
2
- baseUrl?: string;
3
- query?: Record<string, string>;
4
- basePath?: string;
5
- }
6
- declare class NURL implements URL {
7
- private _href;
8
- private _protocol;
9
- private _host;
10
- private _hostname;
11
- private _port;
12
- private _pathname;
13
- private _search;
14
- private _hash;
15
- private _origin;
16
- private _username;
17
- private _password;
18
- private _baseUrl;
19
- private _searchParams;
20
- private _basePath;
21
- constructor(input?: string | URL | URLOptions);
22
- static withBasePath(basePath: string): (urlOptions?: string | URL | URLOptions) => NURL;
23
- static create(input?: string | URL | URLOptions): NURL;
24
- static canParse(input: string): boolean;
25
- get baseUrl(): string;
26
- set baseUrl(value: string);
27
- get href(): string;
28
- set href(value: string);
29
- get protocol(): string;
30
- set protocol(value: string);
31
- get host(): string;
32
- set host(value: string);
33
- get hostname(): string;
34
- set hostname(value: string);
35
- get port(): string;
36
- set port(value: string);
37
- get pathname(): string;
38
- set pathname(inputPathname: string);
39
- get search(): string;
40
- set search(search: string);
41
- setSearchParams(_params: Record<string, string>): void;
42
- appendSearchParams(_params: Record<string, string>): void;
43
- removeSearchParams(..._keys: string[]): void;
44
- get searchParams(): URLSearchParams;
45
- get hash(): string;
46
- set hash(value: string);
47
- get origin(): string;
48
- get username(): string;
49
- set username(value: string);
50
- get password(): string;
51
- set password(value: string);
52
- private updateHref;
53
- toString(): string;
54
- toJSON(): string;
55
- private punycodePrefix;
56
- private encodeHostname;
57
- get decodedIDN(): string;
58
- get decodedHostname(): string;
59
- }
60
-
61
- export { NURL as default };
1
+ export { default } from './nurl';
@@ -1,298 +1,4 @@
1
- const y = "-", L = {
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
- }, P = 35, f = Math.floor, w = String.fromCharCode;
6
- function l(e) {
7
- throw new RangeError(L[e]);
8
- }
9
- function A(e) {
10
- const t = [];
11
- let s = 0;
12
- const r = e.length;
13
- for (; s < r; ) {
14
- const a = e.charCodeAt(s++);
15
- if (a >= 55296 && a <= 56319 && s < r) {
16
- const h = e.charCodeAt(s++);
17
- (h & 64512) == 56320 ? t.push(((a & 1023) << 10) + (h & 1023) + 65536) : (t.push(a), s--);
18
- } else
19
- t.push(a);
20
- }
21
- return t;
22
- }
23
- const W = (e) => e >= 48 && e < 58 ? 26 + (e - 48) : e >= 65 && e < 91 ? e - 65 : e >= 97 && e < 123 ? e - 97 : 36, C = (e, t) => e + 22 + 75 * (e < 26 ? 1 : 0) - 0, I = (e, t, s) => {
24
- let r = 0;
25
- for (
26
- e = s ? f(e / 700) : e >> 1, e += f(e / t);
27
- /* no initialization */
28
- e > P * 26 >> 1;
29
- r += 36
30
- )
31
- e = f(e / P);
32
- return f(r + (P + 1) * e / (e + 38));
33
- }, U = (e) => {
34
- const t = [], s = e.length;
35
- let r = 0, a = 128, h = 72, i = e.lastIndexOf(y);
36
- i < 0 && (i = 0);
37
- for (let n = 0; n < i; ++n)
38
- e.charCodeAt(n) >= 128 && l("not-basic"), t.push(e.charCodeAt(n));
39
- for (let n = i > 0 ? i + 1 : 0; n < s; ) {
40
- const u = r;
41
- for (let m = 1, c = 36; ; c += 36) {
42
- n >= s && l("invalid-input");
43
- const _ = W(e.charCodeAt(n++));
44
- _ >= 36 && l("invalid-input"), _ > f((2147483647 - r) / m) && l("overflow"), r += _ * m;
45
- const p = c <= h ? 1 : c >= h + 26 ? 26 : c - h;
46
- if (_ < p)
47
- break;
48
- const d = 36 - p;
49
- m > f(2147483647 / d) && l("overflow"), m *= d;
50
- }
51
- const o = t.length + 1;
52
- h = I(r - u, o, u == 0), f(r / o) > 2147483647 - a && l("overflow"), a += f(r / o), r %= o, t.splice(r++, 0, a);
53
- }
54
- return String.fromCodePoint(...t);
55
- }, E = (e) => {
56
- const t = [], s = A(e), r = s.length;
57
- let a = 128, h = 0, i = 72;
58
- for (const o of s)
59
- o < 128 && t.push(w(o));
60
- const n = t.length;
61
- let u = n;
62
- for (n && t.push(y); u < r; ) {
63
- let o = 2147483647;
64
- for (const c of s)
65
- c >= a && c < o && (o = c);
66
- const m = u + 1;
67
- o - a > f((2147483647 - h) / m) && l("overflow"), h += (o - a) * m, a = o;
68
- for (const c of s)
69
- if (c < a && ++h > 2147483647 && l("overflow"), c === a) {
70
- let _ = h;
71
- for (let p = 36; ; p += 36) {
72
- const d = p <= i ? 1 : p >= i + 26 ? 26 : p - i;
73
- if (_ < d)
74
- break;
75
- const S = _ - d, x = 36 - d;
76
- t.push(w(C(d + S % x))), _ = f(S / x);
77
- }
78
- t.push(w(C(_))), i = I(h, m, u === n), h = 0, ++u;
79
- }
80
- ++h, ++a;
81
- }
82
- return t.join("");
83
- }, M = /^:/, v = /^\[.*\]$/;
84
- function R(e) {
85
- return M.test(e) || v.test(e);
86
- }
87
- function b(e) {
88
- return e.split("/").filter(R);
89
- }
90
- function $(e) {
91
- return e.slice(1, M.test(e) ? void 0 : -1);
92
- }
93
- function H(e, t) {
94
- return b(e).reduce((s, r) => {
95
- const a = $(r);
96
- return t[a] ? s.replace(r, t[a]) : s;
97
- }, e);
98
- }
99
- function T(e, t) {
100
- return b(e).reduce((s, r) => {
101
- const a = $(r), {
102
- [a]: h,
103
- ...i
104
- } = s;
105
- return i;
106
- }, t);
107
- }
108
- const j = 127;
109
- function D(e) {
110
- return e.charCodeAt(0) > j;
111
- }
112
- class g {
113
- constructor(t) {
114
- 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)
115
- this.href = t.toString();
116
- else if (t) {
117
- 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) {
118
- const s = this._basePath;
119
- let r = t.pathname;
120
- s && !r.startsWith(s) && (r = `${s}${r.startsWith("/") ? "" : "/"}${r}`), this.pathname = H(r, t.query ?? {});
121
- }
122
- if (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) {
123
- const s = T(t.pathname ?? "", t.query);
124
- Object.keys(s).length > 0 && (this.search = new URLSearchParams(s).toString());
125
- }
126
- this.updateHref();
127
- }
128
- }
129
- static withBasePath(t) {
130
- return (s) => typeof s == "string" || s instanceof URL ? new g({
131
- href: s.toString(),
132
- basePath: t
133
- }) : new g({
134
- ...s,
135
- basePath: t
136
- });
137
- }
138
- static create(t) {
139
- return new g(t);
140
- }
141
- static canParse(t) {
142
- if (t.startsWith("/"))
143
- return /^\/[^?#]*(\?[^#]*)?(#.*)?$/.test(t);
144
- try {
145
- return new URL(t), !0;
146
- } catch {
147
- return /^[^:/?#]+(\.[^:/?#]+)+(\/[^?#]*(\?[^#]*)?(#.*)?)?$/.test(t);
148
- }
149
- }
150
- get baseUrl() {
151
- return this._baseUrl;
152
- }
153
- set baseUrl(t) {
154
- this._baseUrl = t;
155
- try {
156
- const s = new URL(t);
157
- 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();
158
- } catch (s) {
159
- console.warn(`Invalid baseUrl: ${t}`, s);
160
- }
161
- }
162
- get href() {
163
- return this.pathname.length === 1 ? `${this._href}/` : this._href;
164
- }
165
- set href(t) {
166
- try {
167
- const s = new URL(t);
168
- 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;
169
- } catch (s) {
170
- console.warn(`Can not parse ${t}`, s);
171
- }
172
- }
173
- get protocol() {
174
- return this._protocol;
175
- }
176
- set protocol(t) {
177
- this._protocol = t, this.updateHref();
178
- }
179
- get host() {
180
- return this._host;
181
- }
182
- set host(t) {
183
- const [s, r] = t.split(":"), a = this.encodeHostname(s);
184
- this._host = r ? `${a}:${r}` : a, this._hostname = a, this._port = r || "", this.updateHref();
185
- }
186
- get hostname() {
187
- return this._hostname;
188
- }
189
- set hostname(t) {
190
- const s = this.encodeHostname(t);
191
- this._hostname = s, this._host = this._port ? `${s}:${this._port}` : s, this.updateHref();
192
- }
193
- get port() {
194
- return this._port;
195
- }
196
- set port(t) {
197
- this._port = t, this._host = `${this._hostname}${t ? ":" + t : ""}`, this.updateHref();
198
- }
199
- get pathname() {
200
- return this._pathname;
201
- }
202
- set pathname(t) {
203
- let s = t;
204
- this._basePath && !s.startsWith(this._basePath) && (s = `${this._basePath}${s.startsWith("/") ? "" : "/"}${s}`);
205
- const r = s.split("/").map((a) => R(a) ? a : encodeURI(a)).join("/");
206
- this._pathname = r.startsWith("/") ? r : `/${r}`, this.updateHref();
207
- }
208
- get search() {
209
- return this._search;
210
- }
211
- set search(t) {
212
- this._search = t.startsWith("?") ? t : `?${t}`, this._searchParams = new URLSearchParams(t), this.updateHref();
213
- }
214
- setSearchParams(t) {
215
- const s = new URLSearchParams(t);
216
- this._search = s.toString() ? `?${s.toString()}` : "", this._searchParams = s, this.updateHref();
217
- }
218
- appendSearchParams(t) {
219
- const s = new URLSearchParams(this._searchParams), r = b(this._pathname).map($);
220
- Object.keys(t).forEach((a) => {
221
- r.includes(a) ? this._pathname = H(this._pathname, {
222
- [a]: t[a]
223
- }) : s.append(a, t[a]);
224
- }), this._search = s.toString() ? `?${s.toString()}` : "", this._searchParams = s, this.updateHref();
225
- }
226
- removeSearchParams(...t) {
227
- const s = new URLSearchParams(this._searchParams);
228
- t.forEach((r) => {
229
- s.delete(r);
230
- }), this._search = s.toString() ? `?${s.toString()}` : "", this._searchParams = s, this.updateHref();
231
- }
232
- get searchParams() {
233
- return new Proxy(this._searchParams, {
234
- get: (t, s, r) => {
235
- const a = Reflect.get(t, s, r);
236
- return typeof a == "function" ? (...h) => {
237
- const i = a.apply(t, h);
238
- return this._search = this._searchParams.toString() ? `?${this._searchParams.toString()}` : "", this.updateHref(), i;
239
- } : a;
240
- }
241
- });
242
- }
243
- get hash() {
244
- return this._hash;
245
- }
246
- set hash(t) {
247
- this._hash = t.startsWith("#") ? t : `#${t}`, this.updateHref();
248
- }
249
- get origin() {
250
- return this._origin;
251
- }
252
- get username() {
253
- return this._username;
254
- }
255
- set username(t) {
256
- this._username = t, this.updateHref();
257
- }
258
- get password() {
259
- return this._password;
260
- }
261
- set password(t) {
262
- this._password = t, this.updateHref();
263
- }
264
- updateHref() {
265
- if (this._baseUrl) {
266
- const t = new URL(this._baseUrl);
267
- t.pathname = this._pathname, t.search = this._search, t.hash = this._hash, this._href = t.href, this._origin = t.origin;
268
- } else
269
- this._href = `${this._protocol}${this._protocol && "//"}${this._username}${this._password ? ":" + this._password : ""}${this._username || this._password ? "@" : ""}${this._hostname}${this._port ? ":" + this._port : ""}${this._pathname === "/" ? "" : this._pathname}${this._search}${this._hash}`, this._origin = `${this._protocol}//${this._hostname}${this._port ? ":" + this._port : ""}`;
270
- }
271
- toString() {
272
- return this.href;
273
- }
274
- toJSON() {
275
- return this.href;
276
- }
277
- encodeHostname(t) {
278
- return t.split(".").map((s) => {
279
- for (const r of s)
280
- if (D(r))
281
- return `${this.punycodePrefix}${E(s)}`;
282
- return s;
283
- }).join(".");
284
- }
285
- get decodedIDN() {
286
- let t = this._href;
287
- return this._hostname.split(".").forEach((s) => {
288
- t = t.replace(s, U(s.replace(this.punycodePrefix, "")));
289
- }), t;
290
- }
291
- get decodedHostname() {
292
- return this._hostname.split(".").map((t) => U(t.replace(this.punycodePrefix, ""))).join(".");
293
- }
294
- }
1
+ import { default as o } from "./nurl.mjs";
295
2
  export {
296
- g as default
3
+ o as default
297
4
  };
298
- //# sourceMappingURL=index.mjs.map