mirror of
https://github.com/GoogleChrome/chrome-extensions-samples.git
synced 2026-03-27 13:29:34 +07:00
* First draft * Rename folder * Tweak comments * Update index.html * remove extra closing div * Rename sw file * Apply first round of @sebastianbenz suggestions * Fix import * Update popover * Second tech review round
24 lines
706 B
JavaScript
24 lines
706 B
JavaScript
import apiList from './api-list.js';
|
|
|
|
/**
|
|
* Returns a list of suggestions and a description for the default suggestion
|
|
*/
|
|
export async function getApiSuggestions(input) {
|
|
const suggestions = apiList.filter((api) => api.content.startsWith(input));
|
|
|
|
// return suggestions if any exist
|
|
if (suggestions.length) {
|
|
return {
|
|
description: 'Matching Chrome APIs',
|
|
suggestions: suggestions
|
|
};
|
|
}
|
|
|
|
// return past searches if no match was found
|
|
const { apiSuggestions } = await chrome.storage.local.get('apiSuggestions');
|
|
return {
|
|
description: 'No matches found. Choose from past searches',
|
|
suggestions: apiList.filter((item) => apiSuggestions.includes(item.content))
|
|
};
|
|
}
|