How to use fuse - 10 common examples

To help you get started, we’ve selected a few fuse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github elmsln / WCFactory / packages / cli / src / questions / operation.js View on Github external
source: (answers, input) => {
      const fuse = new Fuse(ELEMENT_OPTIONS, { keys: ['name'] })
      return new Promise((res,rej) => {
        // fuzzy search the elements
        if (input) {
          const result = fuse.search(input)
          res(result)
        }
        res(ELEMENT_OPTIONS)
      })
    }
  },
github siddharthkp / historie / history.js View on Github external
return new Promise(resolve => {
    /* fuse likes objects */
    const historyMap = history.map(h => ({ command: h }))
    const options = { keys: ['command'] }

    const fuse = new Fuse(historyMap, options)
    const matchingHistory = fuse.search(hint)

    let choices = unique(matchingHistory.map(h => h.command))
    choices = choices.filter((c) => c);

    if (!choices.length) resolve(history)
    else resolve(choices)
  })
}
github ampproject / amphtml / build-system / server / app-index / api / api.js View on Github external
function searchListing(fileSet, opt_searchQuery) {
  if (!opt_searchQuery) {
    return fileSet;
  }

  // Fuzzy find from the file set
  const fuse = new Fuse(fileSet, {
    shouldSort: true,
    threshold: 0.4,
  });

  return fuse.search(opt_searchQuery).map(i => fileSet[i]);
}
github OmerTu / GoogleHomeKodi / helpers.js View on Github external
const fuzzySearchBestMatch = (items, needle, optionalTargetProperties) => {

    let options = fuzzySearchOptions;

    if (optionalTargetProperties) {
        options = Object.assign({}, options);
        options.keys = optionalTargetProperties;
    }

    let cleanNeedle = needle
        .trim()
        .replace(/^of /gi, '');
    let fuse = new Fuse(items, options);
    let searchResult = fuse.search(cleanNeedle);

    if (searchResult.length === 0) {
        throw new Error(`No fuzzy match for '${cleanNeedle}'`);
    }

    let bestMatch = searchResult[0];

    console.log(`best fuzzy match for '${cleanNeedle}' is:`, bestMatch);
    return Promise.resolve(bestMatch);
};
github microsoft / ConversationLearner-UI / src / components / ExtractorResponseEditor / usePicker.ts View on Github external
React.useEffect(() => {
        fuseRef.current = new Fuse(options, fuseOptions)
        const computed = getMatchedOptions(searchText, options, fuseRef.current, maxDisplayedOptions)
        setMatchedOptions(computed)
    }, [options.length, searchText])
github bleenco / abstruse / src / app / repositories / repositories-list / repositories-list.component.ts View on Github external
onKeywordChanged(): void {
    if (this.searchKeyword === '') {
      this.displayedRepos = [...this.repos];
      return;
    }

    const options = {
      keys: ['name', 'full_name', 'repository_provider', 'description', 'html_url'] as any[],
      id: 'id'
    };
    this.fuse = new Fuse(this.repos, options);
    const ids = this.fuse.search(this.searchKeyword).map(id => Number(id));
    this.displayedRepos = this.repos.filter(repo => ids.indexOf(Number(repo.id)) !== -1);
  }
}
github meetalva / alva / packages / model / src / pattern-search.ts View on Github external
public constructor(init: PatternSearchInit) {
		this.fuse = new Fuse(init.patterns.map(item => item.toJSON()), {
			keys: ['name', 'description']
		});
	}
github kufii / Audioshield-PlayMusic / js / server.js View on Github external
run(function*(gen) {
		try {
			var tracks = yield getLibrary(gen());
			tracks = tracks.filter((track) => {
				return (typeof track.storeId === 'undefined');
			});
			var fuse = new Fuse(tracks, FUSE_OPTIONS);
			tracks = fuse.search(q);
			callback(null, tracks.slice(0, 50));
		} catch (err) {
			callback(err);
		}
	});
};
github storyteller / Storyteller / client / lib / presentation / grammar-adder-lookup.js View on Github external
findMatches(query){
		const fuse = new Fuse(this.options, {
			keys: ['title', 'key']
		});

		var fragment = query.toLowerCase();

		var options = fuse.search(query);

		for (var i = 0; i < options.length; i++){
			options[i].holder = this.holder;
			options[i].grammar = this.grammars[options[i].key];
		}

		return options;
	}
}
github storyteller / Storyteller / client / lib / presentation / grammar-adder-lookup.js View on Github external
findMatches(query){
		const fuse = new Fuse(this.options, {
			keys: ['title', 'grammar.key']
		});

		var fragment = query.toLowerCase();

		return fuse.search(query);
/*
		return this.options.filter(x => {
			return x.lower.search(fragment) > -1;
		});
		*/
	}
}

fuse

The magical GraphQL framework

MIT
Latest version published 3 months ago

Package Health Score

75 / 100
Full package analysis

Popular fuse functions