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