@naverpay/nurl 1.1.0-canary.251230-92343a8 → 1.1.0-canary.251230-7c2e8df

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,3 +1,5 @@
1
+ import { MaskOptions } from './utils.js';
2
+
1
3
  type Query = Record<string, any>;
2
4
 
3
5
  interface URLOptions extends Partial<Pick<URL, 'href' | 'protocol' | 'host' | 'hostname' | 'port' | 'pathname' | 'search' | 'hash' | 'username' | 'password'>> {
@@ -5,13 +7,6 @@ interface URLOptions extends Partial<Pick<URL, 'href' | 'protocol' | 'host' | 'h
5
7
  query?: Query;
6
8
  basePath?: string;
7
9
  }
8
- interface MaskOptions {
9
- patterns: string[];
10
- sensitiveParams: string[];
11
- maskChar?: string;
12
- maskLength?: number;
13
- preserveLength?: boolean;
14
- }
15
10
  declare class NURL implements URL {
16
11
  private _href;
17
12
  private _protocol;
@@ -80,7 +75,7 @@ declare class NURL implements URL {
80
75
  get decodedIDN(): string;
81
76
  get decodedHostname(): string;
82
77
  static match(url: string, pattern: string): Record<string, string> | null;
83
- static mask(url: string, { patterns, sensitiveParams, maskChar, maskLength, preserveLength }: MaskOptions): string;
78
+ static mask(url: string, options: MaskOptions): string;
84
79
  }
85
80
 
86
81
  export { NURL as default };
package/dist/cjs/nurl.js CHANGED
@@ -1 +1 @@
1
- "use strict";const l=require("./punycode.js"),a=require("./utils.js");class c{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=a.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=a.refineQueryWithPathname(t.pathname??"",t.query);Object.keys(s).length>0&&(this.search=new URLSearchParams(a.convertQueryToArray(s)).toString())}this.updateHref()}}static withBasePath(t){return s=>typeof s=="string"||s instanceof URL?new c({href:s.toString(),basePath:t}):new c({...s,basePath:t})}static create(t){return new c(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=c.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),[r=t,i="",n="",_="",h="",o="",m="",p="",f=""]=e||[];if(!e||i&&!h&&!m&&!p&&!f)return null;const d=i&&h?`${i}//${h}${o?`:${o}`:""}`:"";return{href:r,protocol:i,host:h,hostname:h,port:o,pathname:t?m||"/":"",search:p,hash:f,origin:d,username:n,password:_,searchParams:new URLSearchParams(p)}}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(":"),r=this.encodeHostname(s);this._host=e?`${r}:${e}`:r,this._hostname=r,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(r=>a.isDynamicPath(r)?r:encodeURI(r)).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=a.getDynamicPaths(this._pathname).map(a.extractPathKey);Object.keys(t).forEach(r=>{e.includes(r)?this._pathname=a.refinePathnameWithQuery(this._pathname,{[r]:t[r]}):s.append(r,t[r])}),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 r=Reflect.get(t,s,e);return typeof r=="function"?(...i)=>{const n=r.apply(t,i);return this._search=this._searchParams.toString()?`?${this._searchParams.toString()}`:"",this.updateHref(),n}:r}})}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(a.isASCIICodeChar(e))return`${this.punycodePrefix}${l.encode(s)}`;return s}).join(".")}get decodedIDN(){let t=this._href;return this._hostname.split(".").forEach(s=>{t=t.replace(s,l.decode(s.replace(this.punycodePrefix,"")))}),t}get decodedHostname(){return this._hostname.split(".").map(t=>l.decode(t.replace(this.punycodePrefix,""))).join(".")}static match(t,s){if(!c.canParse(t)||!c.canParse(s))return null;const e=t.split(/[?#]/)[0]?.split("/").filter(Boolean)||[],r=s.split(/[?#]/)[0]?.split("/").filter(Boolean)||[];if(e.length!==r.length)return null;const i={};for(let n=0;n<r.length;n++){const _=r[n],h=e[n];if(a.isDynamicPath(_)){const o=a.extractPathKey(_);i[o]=h}else if(_!==h)return null}return i}static mask(t,{patterns:s,sensitiveParams:e,maskChar:r="*",maskLength:i=4,preserveLength:n=!1}){const _=[...s].sort((h,o)=>a.getPathPriority(o)>a.getPathPriority(h)?1:-1);for(const h of _){const o=c.create(t),m=c.match(o.pathname,h);if(m)return e.forEach(p=>{if(p in m){const f=m[p],d=n?f.length:i;m[p]=r.repeat(d)}}),o.pathname=a.refinePathnameWithQuery(h,m),o.toString()}return t}}module.exports=c;
1
+ "use strict";const m=require("./punycode.js"),d=require("./utils/external.js"),r=require("./utils/internal.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="",P="",o="",c="",p="",_="",f=""]=e||[];if(!e||a&&!o&&!p&&!_&&!f)return null;const l=a&&o?`${a}//${o}${c?`:${c}`:""}`:"";return{href:h,protocol:a,host:o,hostname:o,port:c,pathname:t?p||"/":"",search:_,hash:f,origin:l,username:n,password:P,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(".")}static match(t,s){return d.match(t,s)}static mask(t,s){return d.mask(t,s)}}module.exports=i;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../nurl.js"),l=require("./internal.js"),g=(r,c)=>{if(!f.canParse(r)||!f.canParse(c))return null;const i=r.split(/[?#]/)[0]?.split("/").filter(Boolean)||[],a=c.split(/[?#]/)[0]?.split("/").filter(Boolean)||[];if(i.length!==a.length)return null;const u={};for(let n=0;n<a.length;n++){const o=a[n],t=i[n];if(l.isDynamicPath(o)){const e=l.extractPathKey(o);u[e]=t}else if(o!==t)return null}return u},P=(r,{patterns:c,sensitiveParams:i,maskChar:a="*",maskLength:u=4,preserveLength:n=!1})=>{const o=[...c].sort((t,e)=>l.getPathPriority(e)>l.getPathPriority(t)?1:-1);for(const t of o){const e=f.create(r),s=g(e.pathname,t);if(s)return i.forEach(h=>{if(h in s){const m=s[h],p=n?m.length:u;s[h]=a.repeat(p)}}),e.pathname=l.refinePathnameWithQuery(t,s),e.toString()}return r};exports.mask=P;exports.match=g;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./external.js");exports.mask=e.mask;exports.match=e.match;
@@ -0,0 +1,11 @@
1
+ declare const match: (url: string, pattern: string) => Record<string, string> | null;
2
+ interface MaskOptions {
3
+ patterns: string[];
4
+ sensitiveParams: string[];
5
+ maskChar?: string;
6
+ maskLength?: number;
7
+ preserveLength?: boolean;
8
+ }
9
+ declare const mask: (url: string, { patterns, sensitiveParams, maskChar, maskLength, preserveLength }: MaskOptions) => string;
10
+
11
+ export { type MaskOptions, mask, match };
@@ -1,3 +1,5 @@
1
+ import { MaskOptions } from './utils.mjs';
2
+
1
3
  type Query = Record<string, any>;
2
4
 
3
5
  interface URLOptions extends Partial<Pick<URL, 'href' | 'protocol' | 'host' | 'hostname' | 'port' | 'pathname' | 'search' | 'hash' | 'username' | 'password'>> {
@@ -5,13 +7,6 @@ interface URLOptions extends Partial<Pick<URL, 'href' | 'protocol' | 'host' | 'h
5
7
  query?: Query;
6
8
  basePath?: string;
7
9
  }
8
- interface MaskOptions {
9
- patterns: string[];
10
- sensitiveParams: string[];
11
- maskChar?: string;
12
- maskLength?: number;
13
- preserveLength?: boolean;
14
- }
15
10
  declare class NURL implements URL {
16
11
  private _href;
17
12
  private _protocol;
@@ -80,7 +75,7 @@ declare class NURL implements URL {
80
75
  get decodedIDN(): string;
81
76
  get decodedHostname(): string;
82
77
  static match(url: string, pattern: string): Record<string, string> | null;
83
- static mask(url: string, { patterns, sensitiveParams, maskChar, maskLength, preserveLength }: MaskOptions): string;
78
+ static mask(url: string, options: MaskOptions): string;
84
79
  }
85
80
 
86
81
  export { NURL as default };
package/dist/esm/nurl.mjs CHANGED
@@ -1,28 +1,29 @@
1
- import { encode as $, decode as d } from "./punycode.mjs";
2
- import { refinePathnameWithQuery as l, refineQueryWithPathname as w, convertQueryToArray as S, isDynamicPath as P, getDynamicPaths as y, extractPathKey as g, isASCIICodeChar as b, getPathPriority as u } from "./utils.mjs";
3
- class n {
1
+ import { encode as l, decode as p } from "./punycode.mjs";
2
+ import { match as g, mask as u } from "./utils/external.mjs";
3
+ import { refinePathnameWithQuery as f, refineQueryWithPathname as $, convertQueryToArray as w, isDynamicPath as S, getDynamicPaths as U, extractPathKey as H, isASCIICodeChar as b } from "./utils/internal.mjs";
4
+ class i {
4
5
  constructor(t) {
5
6
  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
7
  this.href = t.toString();
7
8
  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 = l(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 = w(t.pathname ?? "", t.query);
10
- Object.keys(s).length > 0 && (this.search = new URLSearchParams(S(s)).toString());
9
+ 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) {
10
+ const s = $(t.pathname ?? "", t.query);
11
+ Object.keys(s).length > 0 && (this.search = new URLSearchParams(w(s)).toString());
11
12
  }
12
13
  this.updateHref();
13
14
  }
14
15
  }
15
16
  static withBasePath(t) {
16
- return (s) => typeof s == "string" || s instanceof URL ? new n({
17
+ return (s) => typeof s == "string" || s instanceof URL ? new i({
17
18
  href: s.toString(),
18
19
  basePath: t
19
- }) : new n({
20
+ }) : new i({
20
21
  ...s,
21
22
  basePath: t
22
23
  });
23
24
  }
24
25
  static create(t) {
25
- return new n(t);
26
+ return new i(t);
26
27
  }
27
28
  static canParse(t) {
28
29
  if (t.startsWith("/"))
@@ -53,30 +54,30 @@ class n {
53
54
  const s = new URL(t);
54
55
  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
56
  } catch (s) {
56
- const e = n.parseStringToURLLike(t);
57
+ const e = i.parseStringToURLLike(t);
57
58
  if (!e)
58
59
  throw console.warn(`Can not parse ${t}`), s;
59
60
  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
  }
61
62
  }
62
63
  static parseStringToURLLike(t) {
63
- const s = /^(?:(https?:\/\/)(?:([^:@]+)(?::([^@]+))?@)?((?:[^/:?#]+)(?::(\d+))?)?)?([/][^?#]*)?(\?[^#]*)?(#.*)?$/, e = t.match(s), [r = t, a = "", i = "", m = "", h = "", o = "", c = "", _ = "", p = ""] = e || [];
64
- if (!e || a && !h && !c && !_ && !p)
64
+ const s = /^(?:(https?:\/\/)(?:([^:@]+)(?::([^@]+))?@)?((?:[^/:?#]+)(?::(\d+))?)?)?([/][^?#]*)?(\?[^#]*)?(#.*)?$/, e = t.match(s), [h = t, r = "", o = "", d = "", a = "", n = "", _ = "", c = "", m = ""] = e || [];
65
+ if (!e || r && !a && !_ && !c && !m)
65
66
  return null;
66
- const f = a && h ? `${a}//${h}${o ? `:${o}` : ""}` : "";
67
+ const P = r && a ? `${r}//${a}${n ? `:${n}` : ""}` : "";
67
68
  return {
68
- href: r,
69
- protocol: a,
70
- host: h,
71
- hostname: h,
72
- port: o,
73
- pathname: t ? c || "/" : "",
74
- search: _,
75
- hash: p,
76
- origin: f,
77
- username: i,
78
- password: m,
79
- searchParams: new URLSearchParams(_)
69
+ href: h,
70
+ protocol: r,
71
+ host: a,
72
+ hostname: a,
73
+ port: n,
74
+ pathname: t ? _ || "/" : "",
75
+ search: c,
76
+ hash: m,
77
+ origin: P,
78
+ username: o,
79
+ password: d,
80
+ searchParams: new URLSearchParams(c)
80
81
  };
81
82
  }
82
83
  get protocol() {
@@ -89,8 +90,8 @@ class n {
89
90
  return this._host;
90
91
  }
91
92
  set host(t) {
92
- const [s, e] = t.split(":"), r = this.encodeHostname(s);
93
- this._host = e ? `${r}:${e}` : r, this._hostname = r, this._port = e || "", this.updateHref();
93
+ const [s, e] = t.split(":"), h = this.encodeHostname(s);
94
+ this._host = e ? `${h}:${e}` : h, this._hostname = h, this._port = e || "", this.updateHref();
94
95
  }
95
96
  get hostname() {
96
97
  return this._hostname;
@@ -115,7 +116,7 @@ class n {
115
116
  return;
116
117
  }
117
118
  this._basePath && !s.startsWith(this._basePath) && (s = `${this._basePath}${s.startsWith("/") ? "" : "/"}${s}`);
118
- const e = s.split("/").map((r) => P(r) ? r : encodeURI(r)).join("/");
119
+ const e = s.split("/").map((h) => S(h) ? h : encodeURI(h)).join("/");
119
120
  this._pathname = e.startsWith("/") ? e : `/${e}`, this.updateHref();
120
121
  }
121
122
  get search() {
@@ -129,11 +130,11 @@ class n {
129
130
  this._search = s.toString() ? `?${s.toString()}` : "", this._searchParams = s, this.updateHref();
130
131
  }
131
132
  appendSearchParams(t) {
132
- const s = new URLSearchParams(this._searchParams), e = y(this._pathname).map(g);
133
- Object.keys(t).forEach((r) => {
134
- e.includes(r) ? this._pathname = l(this._pathname, {
135
- [r]: t[r]
136
- }) : s.append(r, t[r]);
133
+ const s = new URLSearchParams(this._searchParams), e = U(this._pathname).map(H);
134
+ Object.keys(t).forEach((h) => {
135
+ e.includes(h) ? this._pathname = f(this._pathname, {
136
+ [h]: t[h]
137
+ }) : s.append(h, t[h]);
137
138
  }), this._search = s.toString() ? `?${s.toString()}` : "", this._searchParams = s, this.updateHref();
138
139
  }
139
140
  removeSearchParams(...t) {
@@ -145,11 +146,11 @@ class n {
145
146
  get searchParams() {
146
147
  return new Proxy(this._searchParams, {
147
148
  get: (t, s, e) => {
148
- const r = Reflect.get(t, s, e);
149
- return typeof r == "function" ? (...a) => {
150
- const i = r.apply(t, a);
151
- return this._search = this._searchParams.toString() ? `?${this._searchParams.toString()}` : "", this.updateHref(), i;
152
- } : r;
149
+ const h = Reflect.get(t, s, e);
150
+ return typeof h == "function" ? (...r) => {
151
+ const o = h.apply(t, r);
152
+ return this._search = this._searchParams.toString() ? `?${this._searchParams.toString()}` : "", this.updateHref(), o;
153
+ } : h;
153
154
  }
154
155
  });
155
156
  }
@@ -192,57 +193,26 @@ class n {
192
193
  return t.split(".").map((s) => {
193
194
  for (const e of s)
194
195
  if (b(e))
195
- return `${this.punycodePrefix}${$(s)}`;
196
+ return `${this.punycodePrefix}${l(s)}`;
196
197
  return s;
197
198
  }).join(".");
198
199
  }
199
200
  get decodedIDN() {
200
201
  let t = this._href;
201
202
  return this._hostname.split(".").forEach((s) => {
202
- t = t.replace(s, d(s.replace(this.punycodePrefix, "")));
203
+ t = t.replace(s, p(s.replace(this.punycodePrefix, "")));
203
204
  }), t;
204
205
  }
205
206
  get decodedHostname() {
206
- return this._hostname.split(".").map((t) => d(t.replace(this.punycodePrefix, ""))).join(".");
207
+ return this._hostname.split(".").map((t) => p(t.replace(this.punycodePrefix, ""))).join(".");
207
208
  }
208
209
  static match(t, s) {
209
- if (!n.canParse(t) || !n.canParse(s))
210
- return null;
211
- const e = t.split(/[?#]/)[0]?.split("/").filter(Boolean) || [], r = s.split(/[?#]/)[0]?.split("/").filter(Boolean) || [];
212
- if (e.length !== r.length)
213
- return null;
214
- const a = {};
215
- for (let i = 0; i < r.length; i++) {
216
- const m = r[i], h = e[i];
217
- if (P(m)) {
218
- const o = g(m);
219
- a[o] = h;
220
- } else if (m !== h)
221
- return null;
222
- }
223
- return a;
224
- }
225
- static mask(t, {
226
- patterns: s,
227
- sensitiveParams: e,
228
- maskChar: r = "*",
229
- maskLength: a = 4,
230
- preserveLength: i = !1
231
- }) {
232
- const m = [...s].sort((h, o) => u(o) > u(h) ? 1 : -1);
233
- for (const h of m) {
234
- const o = n.create(t), c = n.match(o.pathname, h);
235
- if (c)
236
- return e.forEach((_) => {
237
- if (_ in c) {
238
- const p = c[_], f = i ? p.length : a;
239
- c[_] = r.repeat(f);
240
- }
241
- }), o.pathname = l(h, c), o.toString();
242
- }
243
- return t;
210
+ return g(t, s);
211
+ }
212
+ static mask(t, s) {
213
+ return u(t, s);
244
214
  }
245
215
  }
246
216
  export {
247
- n as default
217
+ i as default
248
218
  };
@@ -0,0 +1,42 @@
1
+ import h from "../nurl.mjs";
2
+ import { isDynamicPath as g, extractPathKey as P, getPathPriority as m, refinePathnameWithQuery as y } from "./internal.mjs";
3
+ const S = (r, l) => {
4
+ if (!h.canParse(r) || !h.canParse(l))
5
+ return null;
6
+ const c = r.split(/[?#]/)[0]?.split("/").filter(Boolean) || [], o = l.split(/[?#]/)[0]?.split("/").filter(Boolean) || [];
7
+ if (c.length !== o.length)
8
+ return null;
9
+ const i = {};
10
+ for (let n = 0; n < o.length; n++) {
11
+ const a = o[n], t = c[n];
12
+ if (g(a)) {
13
+ const e = P(a);
14
+ i[e] = t;
15
+ } else if (a !== t)
16
+ return null;
17
+ }
18
+ return i;
19
+ }, x = (r, {
20
+ patterns: l,
21
+ sensitiveParams: c,
22
+ maskChar: o = "*",
23
+ maskLength: i = 4,
24
+ preserveLength: n = !1
25
+ }) => {
26
+ const a = [...l].sort((t, e) => m(e) > m(t) ? 1 : -1);
27
+ for (const t of a) {
28
+ const e = h.create(r), s = S(e.pathname, t);
29
+ if (s)
30
+ return c.forEach((f) => {
31
+ if (f in s) {
32
+ const p = s[f], u = n ? p.length : i;
33
+ s[f] = o.repeat(u);
34
+ }
35
+ }), e.pathname = y(t, s), e.toString();
36
+ }
37
+ return r;
38
+ };
39
+ export {
40
+ x as mask,
41
+ S as match
42
+ };
@@ -0,0 +1,5 @@
1
+ import { mask as o, match as r } from "./external.mjs";
2
+ export {
3
+ o as mask,
4
+ r as match
5
+ };
@@ -0,0 +1,11 @@
1
+ declare const match: (url: string, pattern: string) => Record<string, string> | null;
2
+ interface MaskOptions {
3
+ patterns: string[];
4
+ sensitiveParams: string[];
5
+ maskChar?: string;
6
+ maskLength?: number;
7
+ preserveLength?: boolean;
8
+ }
9
+ declare const mask: (url: string, { patterns, sensitiveParams, maskChar, maskLength, preserveLength }: MaskOptions) => string;
10
+
11
+ export { type MaskOptions, mask, match };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naverpay/nurl",
3
- "version": "1.1.0-canary.251230-92343a8",
3
+ "version": "1.1.0-canary.251230-7c2e8df",
4
4
  "description": "URL build library",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",
@@ -16,6 +16,16 @@
16
16
  "default": "./dist/cjs/index.js"
17
17
  }
18
18
  },
19
+ "./utils": {
20
+ "import": {
21
+ "types": "./dist/esm/utils.d.mts",
22
+ "default": "./dist/esm/utils/index.mjs"
23
+ },
24
+ "require": {
25
+ "types": "./dist/cjs/utils.d.ts",
26
+ "default": "./dist/cjs/utils/index.js"
27
+ }
28
+ },
19
29
  "./package.json": "./package.json"
20
30
  },
21
31
  "files": [
File without changes
File without changes