@cosmwasm/ts-codegen
Version:
@cosmwasm/ts-codegen converts your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.
60 lines (59 loc) • 1.87 kB
JavaScript
// @ts-nocheck
import { filter } from 'fuzzy';
import { prompt as inquirerer } from 'inquirerer';
export const getFuzzySearch = (list) => {
return (_answers, input) => {
input = input || '';
return new Promise(function (resolve) {
setTimeout(function () {
const fuzzyResult = filter(input, list);
resolve(fuzzyResult.map(function (el) {
return el.original;
}));
}, 25);
});
};
};
export const getFuzzySearchNames = (nameValueItemList) => {
const list = nameValueItemList.map(({ name, value: _value }) => name);
return (_answers, input) => {
input = input || '';
return new Promise(function (resolve) {
setTimeout(function () {
const fuzzyResult = filter(input, list);
resolve(fuzzyResult.map(function (el) {
return nameValueItemList.find(({ name, value: _value }) => el.original == name);
}));
}, 25);
});
};
};
const transform = (questions) => {
return questions.map((q) => {
if (q.type === 'fuzzy') {
const choices = q.choices;
delete q.choices;
return {
...q,
type: 'autocomplete',
source: getFuzzySearch(choices),
};
}
else if (q.type === 'fuzzy:objects') {
const choices = q.choices;
delete q.choices;
return {
...q,
type: 'autocomplete',
source: getFuzzySearchNames(choices),
};
}
else {
return q;
}
});
};
export const prompt = async (questions = [], argv = {}) => {
questions = transform(questions);
return await inquirerer(questions, argv);
};