Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
findMatches: function(string) {
var self = this;
var results = fuzzy.filter(string, this.props.options);
var matches = [];
//results.map(function(result) {
// if (result.score > self.props.minScore) {
// matches.push(result.string);
// }
//});
this.setState({ matches: results });
},
findMatches: function(string) {
var self = this;
var results = fuzzy.filter(string, this.props.options);
var matches = [];
//results.map(function(result) {
// if (result.score > self.props.minScore) {
// matches.push(result.string);
// }
//});
this.setState({ matches: results });
},
filterList: function(filterBy) {
// If user input, returns fuzzy search-delimited list of options;
// else, shows all options.
if (!filterBy) {
this.setState({
visible: this.getOptionNames()
});
return;
}
var visible = _.pluck(fuzzy.filter(filterBy, this.getOptionNames()), 'string');
this.setState({
visible: visible,
clearInput: false
});
},
exports.searchLicense = ({input}, flags) => {
/**
* All but last strings in input are
* concatenated to form one search term
* on which a fuzzy search is performed
* to match a license name
*/
let i = 0;
do {
searchTerm += input[i++];
} while (i < input.length - 1);
// Fuzzy search
const results = fuzzy
.filter(searchTerm, Object.keys(licenses))
.map(({original}) => original);
/**
* If no results for the search
* term are found, output err
* message and abort.
*/
if (!results.length) {
process.stdout.write(red(`\n❌ No license name matching '${searchTerm}' was found.\nPlease try again with another name.\n`));
return;
}
/**
* If called with a year flag use
setTimeout(() => {
const fuzzyResult = fuzzy.filter(input, inputTestFiles);
const val = fuzzyResult.map(el => el.original);
resolve(val);
});
});
function validateInvocation(){
var commands = _.map(program.commands, '_name'),
requestedCommand = _.head(program.args);
if(!program.args.length){
return program.help();
}
else if(!_.includes(commands, requestedCommand)){
var msg = [requestedCommand, ' is not a valid ALKS command.'],
suggests = fuzzy.filter(requestedCommand, commands),
suggest = suggests.map(function(sug){ return sug.string; });
if(suggest.length){
msg.push(clc.white(' Did you mean '));
msg.push(clc.white.underline(suggest[0]));
msg.push(clc.white('?'));
}
return utils.errorAndExit(msg.join(''));
}
}
exports.subcommandSuggestion = function(program, subcommand){
var commands = _.map(program.commands, '_name'),
requestedCommand = _.head(program.args);
if(program.args.length && !_.includes(commands, requestedCommand)){
var prefix = ['alks', subcommand, ''].join(' '),
msg = [prefix, requestedCommand, ' is not a valid ALKS command.'],
suggests = fuzzy.filter(requestedCommand, commands),
suggest = suggests.map(function(sug){ return sug.string; });
if(suggest.length){
msg.push(clc.white(' Did you mean '));
msg.push(clc.white.underline(prefix + suggest[0]));
msg.push(clc.white('?'));
}
exports.errorAndExit(msg.join(''));
}
};
async query(collection: Collection, searchFields: string[], searchTerm: string) {
const entries = await this.listAllEntries(collection);
const hits = fuzzy
.filter(searchTerm, entries, { extract: extractSearchFields(searchFields) })
.sort(sortByScore)
.map(f => f.original);
return { query: searchTerm, hits };
}
filterComponentsIndex() {
const {componentsIndex} = this.props
const {searchedText} = this.state
const options = {pre: ``, post: ''}
if (`${searchedText}`.length > 0)
return fuzzyFilter(searchedText.toLowerCase(), Object.keys(componentsIndex))
.reduce((acc, key) => ({...acc, [key.original]: {...componentsIndex[key.original], highlightedMenu: fuzzyFilter(searchedText.toLowerCase(), [componentsIndex[key.original].menu], options)[0].string}}), {})
return componentsIndex
}
async filter(input: FuzzySearch.Input): Promise[]> {
return fuzzy.filter(input.pattern, input.items.slice(), {
pre: FuzzySearch.PRE,
post: FuzzySearch.POST,
extract: input.transform
}).sort(this.sortResults.bind(this)).map(this.mapResult.bind(this));
}