UNPKG

better-decode-uri-component

Version:
1 lines 699 B
((b,c)=>{"object"==typeof module?module.exports=c():"function"==typeof define&&define.amd?define([],c):b.betterDecodeURIComponent=c();"object"==typeof exports&&(exports.default=exports.betterDecodeURIComponent=c())})("undefined"!=typeof self?self:this,()=>function(b,{maxSequenceSize:c=4,removeMalform:h=!0}={}){if("string"!==typeof b)throw new TypeError("Expected string but got "+typeof b);try{return decodeURIComponent(b)}catch(d){}return b.replace(/(?:%[0-9A-Fa-f]{2})+/g,d=>{let f="",a=0;for(;a<d.length;){let g=!1;for(let e=Math.min(d.length-a,3*c);3<=e;e-=3){const k=d.substring(a,a+e);try{f+=decodeURIComponent(k);a+=e;g=!0;break}catch(l){}}g||(h||(f+=d.substring(a,a+3)),a+=3)}return f})});