/
index.js
1 lines (1 loc) · 4.02 KB
/
index.js
1
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}class LisURLQueryString{static encodeParamValue(a){let b=LisURLEncoder.RFC3986?encodeURIComponent(a).replace(/[!'()*]/g,function(a){return"%"+a.charCodeAt(0).toString(16)}):encodeURIComponent(a);return LisURLEncoder.X_WWW_FORM_URLENCODED?b.replace(/%20/g,"+"):b}static encode(a){return a.map(function(a){let{key:b,value:c}=a;return b+"="+LisURLQueryString.encodeParamValue(c)}).join("&")}static decode(a){return Array.from(new URLSearchParams(a)).filter(function(a){return 0<a.filter(function(a){return a&&""!==a}).length}).map(function(a){return{key:a[0],value:decodeURIComponent(a[1].replace(/\+/g," "))}})}}class LisURLEncode{static queryArray(a){if(a)try{return LisURLQueryString.encode(a)}catch(a){LisURLEncoder.DEBUGGING&&console.warn(a)}return null}static baseURL(a){let b="";if(a)try{b=encodeURI(a)}catch(a){console.warn(a)}return b}static url(a,b){const c=LisURLEncode.baseURL(a),d=LisURLEncode.queryArray(b);return c+(""!==d&&""!==c?(LisURLEncoder.AUTO_QUESTION_MARK?"?":"")+d:"")}}class LisURLDecode{static queryString(a){if(a)try{return LisURLQueryString.decode(new URL(a).searchParams.toString())}catch(a){LisURLEncoder.DEBUGGING&&console.warn(a)}return""}static baseURL(a){let b="";if(a)try{b=decodeURI(a).split("?")[0]}catch(a){LisURLEncoder.DEBUGGING&&console.warn(a)}return b}static url(a){let b="",c="";return a&&""!==a&&(b=LisURLDecode.baseURL(a),c=LisURLDecode.queryString(a)),{baseURL:b,queryString:c}}}class LisURLEncoder{static decode(a){return new RegExp(LisURLEncoder.URL_REGEX,"g").test(a)?LisURLDecode.url(a):(LisURLEncoder.DEBUGGING&&console.warn("The URL specified for decoding is not a URL"),null)}static encode(a,b){const c=new RegExp(LisURLEncoder.URL_REGEX,"g").test(a);if(!c)return LisURLEncoder.DEBUGGING&&console.warn("The base URL specified for encoding is not a URL"),"";const d=LisURLEncoder.RESERVED_CHARS.some(function(b){return a.includes(b)});if(d)return LisURLEncoder.DEBUGGING&&console.warn("The base URL specified contains reserved chars"),"";const e=b.some(function(a){let{key:b}=a;return new RegExp(LisURLEncoder.PARAM_KEY_REGEX,"g").test(b)});return e?LisURLEncode.url(a,b):(LisURLEncoder.DEBUGGING&&console.warn("Check your param keys because some of them do not respect the validation"),"")}static reset(){LisURLEncoder.X_WWW_FORM_URLENCODED=!1,LisURLEncoder.AUTO_QUESTION_MARK=!0,LisURLEncoder.RFC3986=!0,LisURLEncoder.URL_REGEX="^(?:(?:(?:https?|ftp):)?\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u00a1-\\uffff][a-z0-9\\u00a1-\\uffff_-]{0,62})?[a-z0-9\\u00a1-\\uffff]\\.)+(?:[a-z\\u00a1-\\uffff]{2,}\\.?))(?::\\d{2,5})?(?:[/?#]\\S*)?$",LisURLEncoder.RESERVED_CHARS=["&","=","?","+"],LisURLEncoder.PARAM_KEY_REGEX="^[a-zA-Z0-9]*$"}}_defineProperty(LisURLEncoder,"DEBUGGING",!1),_defineProperty(LisURLEncoder,"X_WWW_FORM_URLENCODED",!1),_defineProperty(LisURLEncoder,"URL_REGEX","^(?:(?:(?:https?|ftp):)?\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u00a1-\\uffff][a-z0-9\\u00a1-\\uffff_-]{0,62})?[a-z0-9\\u00a1-\\uffff]\\.)+(?:[a-z\\u00a1-\\uffff]{2,}\\.?))(?::\\d{2,5})?(?:[/?#]\\S*)?$"),_defineProperty(LisURLEncoder,"RESERVED_CHARS",["&","=","?","+"]),_defineProperty(LisURLEncoder,"PARAM_KEY_REGEX","^[a-zA-Z0-9]*$"),_defineProperty(LisURLEncoder,"AUTO_QUESTION_MARK",!0),_defineProperty(LisURLEncoder,"RFC3986",!1),"undefined"!=typeof module&&(module.exports=LisURLEncoder);var _default=LisURLEncoder;exports.default=_default;