@shopify/cli
Version:
A CLI tool to build for the Shopify platform
3 lines (2 loc) • 1.93 kB
JavaScript
import{g as h}from"./chunk-VPRTJUIN.js";h();h();var o=(i,e)=>{if(!i)throw new Error(e)};var b=i=>{let e={joined:!0,spacerNoNeighbour:" ",spacerNeighbour:"\u2502 ",keyNoNeighbour:"\u2514\u2500 ",keyNeighbour:"\u251C\u2500 ",separator:": ",renderFn:n=>["boolean","string","number"].includes(typeof n)?n:void 0,sortFn:null,breakCircularWith:" (circular ref.)",...i};return o(Object.keys(e).length===9,"Unexpected Option(s) provided"),o(typeof e.joined=="boolean",'Option "joined" has invalid format'),o(typeof e.spacerNoNeighbour=="string",'Option "spacerNoNeighbour" has invalid format'),o(typeof e.spacerNeighbour=="string",'Option "spacerNeighbour" has invalid format'),o(typeof e.keyNoNeighbour=="string",'Option "keyNoNeighbour" has invalid format'),o(typeof e.keyNeighbour=="string",'Option "keyNeighbour" has invalid format'),o(typeof e.separator=="string",'Option "separator" has invalid format'),o(typeof e.renderFn=="function",'Option "renderFn" has invalid format'),o(typeof e.sortFn=="function"||e.sortFn===null,'Option "sortFn" has invalid format'),o(typeof e.breakCircularWith=="string"||e.breakCircularWith===null,'Option "breakCircularWith" has invalid format'),e},m=(i,e={})=>{let n=b(e),s=[],g=n.renderFn(i);g!==void 0&&s.push(String(g));let d=r=>n.sortFn===null?r.reverse():r.sort((t,l)=>n.sortFn(l,t)),u=[],a=d(Object.keys(i)).map(r=>[r]),c=[i];for(;a.length!==0;){let r=a.pop(),t=c[r.length-1][r[r.length-1]],l=n.breakCircularWith!==null&&c.includes(t);u[r.length-1]=a.length!==0&&a[a.length-1].length===r.length;let f=n.renderFn(t);s.push([u.slice(0,r.length-1).map(p=>p?n.spacerNeighbour:n.spacerNoNeighbour).join(""),u[r.length-1]?n.keyNeighbour:n.keyNoNeighbour,r[r.length-1],f===void 0?"":`${n.separator}${t}`,l?n.breakCircularWith:""].join("")),t instanceof Object&&!Array.isArray(t)&&!l&&(a.push(...d(Object.keys(t)).map(p=>r.concat(p))),c[r.length]=t)}return n.joined===!0?s.join(`
`):s};export{m as a};