Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
feat: 🎸 adds a feature to search for types
Browse files Browse the repository at this point in the history
Works same as the scopes searching - just start typing
  • Loading branch information
Alexander Bolotskov committed Dec 24, 2019
1 parent 91226ba commit f8c3452
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/questions/scope.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Searches for the scopes starting with the given substring.
* Searches for the scopes containing the given substring.
*
* @param {string} substring Substring to search with.
* @param {string[]} scopes Scopes list.
Expand All @@ -26,7 +26,6 @@ exports.createQuestion = (state) => {
}

const question = {
choices: scopes,
message: 'Select the scope this component affects:',
name: 'scope',
source: (_answers, input) => findScope(input, scopes),
Expand Down
21 changes: 19 additions & 2 deletions lib/questions/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,30 @@ const typeToListItem = ({types, disableEmoji}, type) => {
};
};

/**
* Searches for the type that includes the given substring.
*
* @param {string} substring Substring to search with.
* @param {string[]} config The whole config.
*/
const findType = function (substring, config) {
const input = (substring || '').toLowerCase();
let foundTypes = config.list;

if (input !== '') {
foundTypes = config.list.filter((type) => type.toLowerCase().includes(input));
}

return Promise.resolve(foundTypes.map((type) => typeToListItem(config, type)))
};

exports.createQuestion = (state) => {
const {config} = state;
const question = {
choices: config.list.map((type) => typeToListItem(config, type)),
message: 'Select the type of change that you\'re committing:',
name: 'type',
type: 'list'
source: (_answers, input) => findType(input, config),
type: 'autocomplete'
};

return question;
Expand Down

0 comments on commit f8c3452

Please sign in to comment.