sdkscript
Version:
Set up a modern Cosmos app by running one command ⚛️
65 lines • 2.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.prompt = exports.getFuzzySearchNames = exports.getFuzzySearch = void 0;
const fuzzy_1 = require("fuzzy");
const inquirerer_1 = require("inquirerer");
const getFuzzySearch = (list) => {
return (answers, input) => {
input = input || '';
return new Promise(function (resolve) {
setTimeout(function () {
const fuzzyResult = (0, fuzzy_1.filter)(input, list);
resolve(fuzzyResult.map(function (el) {
return el.original;
}));
}, 25);
});
};
};
exports.getFuzzySearch = getFuzzySearch;
const getFuzzySearchNames = (nameValueItemList) => {
const list = nameValueItemList.map(({ name, value }) => name);
return (answers, input) => {
input = input || '';
return new Promise(function (resolve) {
setTimeout(function () {
const fuzzyResult = (0, fuzzy_1.filter)(input, list);
resolve(fuzzyResult.map(function (el) {
return nameValueItemList.find(({ name, value }) => el.original == name);
}));
}, 25);
});
};
};
exports.getFuzzySearchNames = getFuzzySearchNames;
const transform = (questions) => {
return questions.map((q) => {
if (q.type === 'fuzzy') {
const choices = q.choices;
delete q.choices;
return {
...q,
type: 'autocomplete',
source: (0, exports.getFuzzySearch)(choices)
};
}
else if (q.type === 'fuzzy:objects') {
const choices = q.choices;
delete q.choices;
return {
...q,
type: 'autocomplete',
source: (0, exports.getFuzzySearchNames)(choices)
};
}
else {
return q;
}
});
};
const prompt = async (questions = [], argv = {}) => {
questions = transform(questions);
return await (0, inquirerer_1.prompt)(questions, argv);
};
exports.prompt = prompt;
//# sourceMappingURL=prompt.js.map