UNPKG

sdin

Version:

JavaScript package builder.

2 lines 1.05 kB
import{prompt as v}from"enquirer";import{padEnd as m}from"lodash";import{blue as c}from"./print";import{EnquiringError as d}from"./errors";async function e(e){var{key:t,value:a,preset:r,title:i}=e,l=e.options.filter(e=>!0!==e.disabled);if(0==l.length)throw new d(d.SELECTING_OPTIONS_EMPTY,'Selecting options of enquiring "'.concat(t,'" is empty.'));if(1==l.length)return l[0].value;if(a)for(var n of l)if(n.value===a)return n.value;let o=void 0,s=void 0,u=0;for(let e=0;e<l.length;e++){var p=l[e];void 0===o&&(o=e),void 0===s&&p.value===r&&(s=e),p.label.length>u&&(u=p.label.length)}return(await v([{type:"select",name:t,message:i,required:!0,initial:null!=(e=s)?e:o,choices:l.map(e=>({name:e.label,value:e.value,message:e.desc?"".concat(c(m(e.label,u+2))," ").concat(e.desc):e.label}))}]))[t]}async function t(e){var{key:e,value:t,preset:a,title:r,output:i,validate:l}=e;return t?i?i(t):t:(await v([{type:"input",name:e,message:r,required:!0,initial:a,result:i,validate:l}]))[e]}export{e as select,t as input}; //# sourceMappingURL=enquire.js.map