@naverpay/nurl 0.0.10 → 0.0.12

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,6 +1,7 @@
1
+ import { Query } from './utils';
1
2
  interface URLOptions extends Partial<Pick<URL, 'href' | 'protocol' | 'host' | 'hostname' | 'port' | 'pathname' | 'search' | 'hash' | 'username' | 'password'>> {
2
3
  baseUrl?: string;
3
- query?: Record<string, string>;
4
+ query?: Query;
4
5
  basePath?: string;
5
6
  }
6
7
  export default class NURL implements URL {
package/dist/cjs/nurl.js CHANGED
@@ -1 +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(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;
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;
@@ -1 +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;
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;
@@ -1,18 +1,26 @@
1
+ export type Query = Record<string, string | number | boolean | (string | number | boolean)[]>;
1
2
  export declare function isDynamicPath(path: string): boolean;
2
3
  export declare function getDynamicPaths(pathname: string): string[];
3
4
  export declare function extractPathKey(path: string): string;
4
5
  /**
5
6
  * Replaces dynamic paths in the pathname with values from the query
6
7
  * @param {string} pathname
7
- * @param {Record<string, string>} query
8
+ * @param {Query} query
8
9
  * @returns {string} refined pathname
9
10
  */
10
- export declare function refinePathnameWithQuery(pathname: string, query: Record<string, string>): string;
11
+ export declare function refinePathnameWithQuery(pathname: string, query: Query): string;
11
12
  /**
12
13
  * Removes queries that have already been used in the pathname.
13
14
  * @param {string} pathname
14
- * @param {Record<string, string>} query
15
- * @returns {Record<string, string>} refined query
15
+ * @param {Query} query
16
+ * @returns {Query} refined query
16
17
  */
17
- export declare function refineQueryWithPathname(pathname: string, query: Record<string, string>): Record<string, string>;
18
+ export declare function refineQueryWithPathname(pathname: string, query: Query): Query;
18
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[][];
package/dist/cjs/utils.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=/^:/,h=/^\[.*\]$/;function o(e){return c.test(e)||h.test(e)}function u(e){return e.split("/").filter(o)}function a(e){return e.slice(1,c.test(e)?void 0:-1)}function P(e,t){return u(e).reduce((n,r)=>{const i=a(r);return t[i]?n.replace(r,t[i]):n},e)}function y(e,t){return u(e).reduce((n,r)=>{const i=a(r),{[i]:A,...s}=n;return s},t)}const f=127;function C(e){return e.charCodeAt(0)>f}exports.extractPathKey=a;exports.getDynamicPaths=u;exports.isASCIICodeChar=C;exports.isDynamicPath=o;exports.refinePathnameWithQuery=P;exports.refineQueryWithPathname=y;
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,6 +1,7 @@
1
+ import { Query } from './utils';
1
2
  interface URLOptions extends Partial<Pick<URL, 'href' | 'protocol' | 'host' | 'hostname' | 'port' | 'pathname' | 'search' | 'hash' | 'username' | 'password'>> {
2
3
  baseUrl?: string;
3
- query?: Record<string, string>;
4
+ query?: Query;
4
5
  basePath?: string;
5
6
  }
6
7
  export default class NURL implements URL {
package/dist/esm/nurl.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { encode as c, decode as a } from "./punycode.mjs";
2
- import { refinePathnameWithQuery as i, refineQueryWithPathname as _, isDynamicPath as m, getDynamicPaths as f, extractPathKey as p, isASCIICodeChar as d } from "./utils.mjs";
2
+ import { refinePathnameWithQuery as i, refineQueryWithPathname as _, convertQueryToArray as m, isDynamicPath as f, getDynamicPaths as p, extractPathKey as d, isASCIICodeChar as P } from "./utils.mjs";
3
3
  class r {
4
4
  constructor(t) {
5
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)
@@ -12,7 +12,7 @@ class r {
12
12
  }
13
13
  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) {
14
14
  const s = _(t.pathname ?? "", t.query);
15
- Object.keys(s).length > 0 && (this.search = new URLSearchParams(s).toString());
15
+ Object.keys(s).length > 0 && (this.search = new URLSearchParams(m(s)).toString());
16
16
  }
17
17
  this.updateHref();
18
18
  }
@@ -93,7 +93,7 @@ class r {
93
93
  set pathname(t) {
94
94
  let s = t;
95
95
  this._basePath && !s.startsWith(this._basePath) && (s = `${this._basePath}${s.startsWith("/") ? "" : "/"}${s}`);
96
- const e = s.split("/").map((h) => m(h) ? h : encodeURI(h)).join("/");
96
+ const e = s.split("/").map((h) => f(h) ? h : encodeURI(h)).join("/");
97
97
  this._pathname = e.startsWith("/") ? e : `/${e}`, this.updateHref();
98
98
  }
99
99
  get search() {
@@ -107,7 +107,7 @@ class r {
107
107
  this._search = s.toString() ? `?${s.toString()}` : "", this._searchParams = s, this.updateHref();
108
108
  }
109
109
  appendSearchParams(t) {
110
- const s = new URLSearchParams(this._searchParams), e = f(this._pathname).map(p);
110
+ const s = new URLSearchParams(this._searchParams), e = p(this._pathname).map(d);
111
111
  Object.keys(t).forEach((h) => {
112
112
  e.includes(h) ? this._pathname = i(this._pathname, {
113
113
  [h]: t[h]
@@ -168,7 +168,7 @@ class r {
168
168
  encodeHostname(t) {
169
169
  return t.split(".").map((s) => {
170
170
  for (const e of s)
171
- if (d(e))
171
+ if (P(e))
172
172
  return `${this.punycodePrefix}${c(s)}`;
173
173
  return s;
174
174
  }).join(".");
@@ -1,89 +1,88 @@
1
- import d from "core-js-pure/features/instance/push.js";
2
- const v = 2147483647, f = 36, k = 1, m = 26, q = 38, y = 700, L = 72, O = 128, V = "-", B = {
1
+ const v = "-", k = {
3
2
  overflow: "Overflow: input needs wider integers to process",
4
3
  "not-basic": "Illegal input >= 0x80 (not a basic code point)",
5
4
  "invalid-input": "Invalid input"
6
- }, M = f - k, u = Math.floor, x = String.fromCharCode;
7
- function g(t) {
8
- throw new RangeError(B[t]);
5
+ }, g = 35, u = Math.floor, M = String.fromCharCode;
6
+ function b(t) {
7
+ throw new RangeError(k[t]);
9
8
  }
10
- function S(t) {
9
+ function A(t) {
11
10
  const n = [];
12
- let r = 0;
13
- const e = t.length;
14
- for (; r < e; ) {
15
- const o = t.charCodeAt(r++);
16
- if (o >= 55296 && o <= 56319 && r < e) {
17
- const s = t.charCodeAt(r++);
18
- (s & 64512) == 56320 ? d(n).call(n, ((o & 1023) << 10) + (s & 1023) + 65536) : (d(n).call(n, o), r--);
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--);
19
18
  } else
20
- d(n).call(n, o);
19
+ n.push(e);
21
20
  }
22
21
  return n;
23
22
  }
24
- 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, j = (t, n, r) => {
25
- let e = 0;
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;
26
25
  for (
27
- t = r ? u(t / y) : t >> 1, t += u(t / n);
26
+ t = s ? u(t / 700) : t >> 1, t += u(t / n);
28
27
  /* no initialization */
29
- t > M * m >> 1;
30
- e += f
28
+ t > g * 26 >> 1;
29
+ o += 36
31
30
  )
32
- t = u(t / M);
33
- return u(e + (M + 1) * t / (t + q));
34
- }, F = (t) => {
35
- const n = [], r = t.length;
36
- let e = 0, o = O, s = L, a = t.lastIndexOf(V);
37
- a < 0 && (a = 0);
38
- for (let c = 0; c < a; ++c)
39
- t.charCodeAt(c) >= 128 && g("not-basic"), d(n).call(n, t.charCodeAt(c));
40
- for (let c = a > 0 ? a + 1 : 0; c < r; ) {
41
- const b = e;
42
- for (let p = 1, l = f; ; l += f) {
43
- c >= r && g("invalid-input");
44
- const h = D(t.charCodeAt(c++));
45
- h >= f && g("invalid-input"), h > u((v - e) / p) && g("overflow"), e += h * p;
46
- const w = l <= s ? k : l >= s + m ? m : l - s;
47
- if (h < w)
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)
48
47
  break;
49
- const C = f - w;
50
- p > u(v / C) && g("overflow"), p *= C;
48
+ const d = 36 - x;
49
+ h > u(2147483647 / d) && b("overflow"), h *= d;
51
50
  }
52
- const i = n.length + 1;
53
- s = j(e - b, i, b == 0), u(e / i) > v - o && g("overflow"), o += u(e / i), e %= i, n.splice(e++, 0, o);
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);
54
53
  }
55
54
  return String.fromCodePoint(...n);
56
- }, N = (t) => {
57
- const n = [], r = S(t), e = r.length;
58
- let o = O, s = 0, a = L;
59
- for (const i of r)
60
- i < 128 && d(n).call(n, x(i));
61
- const c = n.length;
62
- let b = c;
63
- for (c && d(n).call(n, V); b < e; ) {
64
- let i = v;
65
- for (const l of r)
66
- l >= o && l < i && (i = l);
67
- const p = b + 1;
68
- i - o > u((v - s) / p) && g("overflow"), s += (i - o) * p, o = i;
69
- for (const l of r)
70
- if (l < o && ++s > v && g("overflow"), l === o) {
71
- let h = s;
72
- for (let w = f; ; w += f) {
73
- const C = w <= a ? k : w >= a + m ? m : w - a;
74
- if (h < C)
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)
75
74
  break;
76
- const A = h - C, T = f - C;
77
- d(n).call(n, x(I(C + A % T))), h = u(A / T);
75
+ const w = f - d, m = 36 - d;
76
+ n.push(M(C(d + w % m))), f = u(w / m);
78
77
  }
79
- d(n).call(n, x(I(h))), a = j(s, p, b === c), s = 0, ++b;
78
+ n.push(M(C(f))), l = I(i, h, p === a), i = 0, ++p;
80
79
  }
81
- ++s, ++o;
80
+ ++i, ++e;
82
81
  }
83
82
  return n.join("");
84
83
  };
85
84
  export {
86
- F as decode,
87
- N as encode,
88
- S as ucs2decode
85
+ B as decode,
86
+ L as encode,
87
+ A as ucs2decode
89
88
  };
@@ -1,18 +1,26 @@
1
+ export type Query = Record<string, string | number | boolean | (string | number | boolean)[]>;
1
2
  export declare function isDynamicPath(path: string): boolean;
2
3
  export declare function getDynamicPaths(pathname: string): string[];
3
4
  export declare function extractPathKey(path: string): string;
4
5
  /**
5
6
  * Replaces dynamic paths in the pathname with values from the query
6
7
  * @param {string} pathname
7
- * @param {Record<string, string>} query
8
+ * @param {Query} query
8
9
  * @returns {string} refined pathname
9
10
  */
10
- export declare function refinePathnameWithQuery(pathname: string, query: Record<string, string>): string;
11
+ export declare function refinePathnameWithQuery(pathname: string, query: Query): string;
11
12
  /**
12
13
  * Removes queries that have already been used in the pathname.
13
14
  * @param {string} pathname
14
- * @param {Record<string, string>} query
15
- * @returns {Record<string, string>} refined query
15
+ * @param {Query} query
16
+ * @returns {Query} refined query
16
17
  */
17
- export declare function refineQueryWithPathname(pathname: string, query: Record<string, string>): Record<string, string>;
18
+ export declare function refineQueryWithPathname(pathname: string, query: Query): Query;
18
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[][];
@@ -1,37 +1,47 @@
1
- const u = /^:/, a = /^\[.*\]$/;
2
- function f(t) {
3
- return u.test(t) || a.test(t);
4
- }
5
- function c(t) {
6
- return t.split("/").filter(f);
7
- }
8
- function o(t) {
9
- return t.slice(1, u.test(t) ? void 0 : -1);
10
- }
11
- function P(t, e) {
12
- return c(t).reduce((n, r) => {
13
- const i = o(r);
14
- return e[i] ? n.replace(r, e[i]) : n;
15
- }, t);
16
- }
17
- function _(t, e) {
18
- return c(t).reduce((n, r) => {
19
- const i = o(r), {
20
- [i]: A,
21
- ...s
22
- } = n;
23
- return s;
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;
24
27
  }, e);
25
28
  }
26
29
  const C = 127;
27
- function h(t) {
28
- return t.charCodeAt(0) > C;
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)]) : []);
29
38
  }
30
39
  export {
31
- o as extractPathKey,
40
+ h as convertQueryToArray,
41
+ f as extractPathKey,
32
42
  c as getDynamicPaths,
33
- h as isASCIICodeChar,
34
- f as isDynamicPath,
35
- P as refinePathnameWithQuery,
36
- _ as refineQueryWithPathname
43
+ g as isASCIICodeChar,
44
+ A as isDynamicPath,
45
+ _ as refinePathnameWithQuery,
46
+ d as refineQueryWithPathname
37
47
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naverpay/nurl",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "URL build library",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",