cl-fill-link
Version:
Fill generated nextjs links with dynamic values
2 lines (1 loc) • 761 B
JavaScript
function e(e){try{return String(e)}catch(e){return""}}function r(r,n){return function(r,n){const t=Object.keys(n||{});let o="";if(n&&t.length>0){o+="?";const r=t.length-1;t.forEach(((t,i)=>{const c=encodeURIComponent(e(n[t]));o+=t+"="+c,i<r&&(o+="&")}))}return r+o}(r.split("/").map((t=>{const o=/\[{1,2}\.{0,3}(\w+)\]{1,2}/.exec(t);if(o&&o.length>1){const t=o[1],i=n[t];if(void 0!==i)return Array.isArray(i)?i.join("/"):e(i);throw new Error("Error: key '"+t+"' is missing from replacer object in link '"+r+"'")}return t})).join("/"),n?.$query)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.fillLink=r,exports.fillLinkSafe=function(e,n){try{return r(e,n)}catch(e){"development"===process.env.NODE_ENV&&console.log(e)}return null};
;