In this tutorial, we’ll create a plugin that allows you to search for NPM packages and MDN pages.
To create a plugin, run the following command:
npm create @yusyuriv/flow-launcher-plugin
yarn create @yusyuriv/flow-launcher-plugin
pnpm create @yusyuriv/flow-launcher-plugin
bun create @yusyuriv/flow-launcher-plugin
It will ask you a few questions and create a plugin project for you. You should have something like this now:
import {FlowPlugin} from " flow-launcher-extended-plugin " ;
export class NpmAndMdnPlugin extends FlowPlugin {
import {FlowPlugin} from " flow-launcher-extended-plugin " ;
export class NpmAndMdnPlugin extends FlowPlugin {
Let’s add a response for when no command is selected:
return " Type 'npm' or 'mdn' to search for packages or MDN web docs " ;
return " Type 'npm' or 'mdn' to search for packages or MDN web docs " ;
NPM Search
Let’s add a response for when the user types npm
without any package name.
@ FlowPlugin . Search ({ equalTo: " npm " })
return " Type 'npm <package-name>' to search for a package " ;
@ FlowPlugin . Search ({ equalTo: " npm " })
return " Type 'npm <package-name>' to search for a package " ;
After googling for NPM search API, I found
this documentation ,
which looks exactly like what we will need for the plugin.
We’ll need the package name, version, description, and NPM link.
"description" : " yargs the modern, pirate-themed, successor to optimist. " ,
"date" : " 2016-12-30T16:53:16.023Z " ,
"npm" : " https://www.npmjs.com/package/yargs " ,
"homepage" : " http://yargs.js.org/ " ,
"repository" : " https://github.com/yargs/yargs " ,
"bugs" : " https://github.com/yargs/yargs/issues "
"final" : 0.9237841281241451 ,
"quality" : 0.9270640902288084 ,
"popularity" : 0.8484861649808381 ,
"maintenance" : 0.9962706951777409
"searchScore" : 100000.914
"time" : " Wed Jan 25 2017 19:23:35 GMT+0000 (UTC) "
Let’s describe this data as types. This is not mandatory, but it’s nice to have your IDE suggest the properties of the
object as you’re typing them. Also helps preventing typos in the future.
* @typedef {object} NpmResponse
* @property {NpmObject[]} objects
* @typedef {object} NpmObject
* @property {NpmPackage} package
* @typedef {object} NpmPackage
* @property {string} name
* @property {string} version
* @property {string} description
* @typedef {object} NpmLinks
Now that we have our data described, let’s add a method to our plugin that will search for NPM packages and display
search results.
npmApiUrl = " https://registry.npmjs.com/-/v1/search?text= " ;
/** @param {Query} query */
@ FlowPlugin . Search ({ startsWith: " npm " })
async searchNpmQuery ( query ) {
/** @type {NpmResponse} */
const response = await this . api . httpGetJson ( npmApiUrl , query . Search );
return response ?. objects . map ( /** @param {NpmObject} v */ v => ({
title: ` ${ v . package . name } | v ${ v . package . version } ` ,
subtitle: v . package . description ,
action: this . actions . openUrl ( v . package . links . npm ),
private readonly npmApiUrl = " https://registry.npmjs.com/-/v1/search?text= " ;
@ FlowPlugin . Search ({ startsWith: " npm " })
async searchNpmQuery (query: Query) {
const response = await this . api . httpGetJson < NpmResponse > (npmApiUrl , query . search );
return response ?. objects . map ( v => ({
title: ` ${ v . package . name } | v ${ v . package . version } ` ,
subtitle: v . package . description ,
action: this . actions . openUrl (v . package . links . npm ),
We have successfully implemented the NPM search functionality.
Assuming you specified web
as your keyword when creating the plugin, here’s how it should look:
web npm svelte
svelte | v5.1.9
Cybernetically enhanced web apps
Alt+1
hast-util-to-jsx-runtime | v2.3.2
hast utility to transform to preact, react, solid, svelte, vue, etc
Alt+2
eslint-plugin-svelte | v2.46.0
ESLint plugin for Svelte using AST
Alt+3
ai | v3.4.31
AI SDK by Vercel - The AI Toolkit for TypeScript and JavaScript
Alt+4
@sveltejs/kit | v2.7.4
SvelteKit is the fastest way to build Svelte apps
Alt+5
embla-carousel-react | v8.3.1
A lightweight carousel library with fluid motion and great swipe precision
Alt+6
MDN Search
MDN search is a little bit different.
We’ll be doing the search ourselves, locally.
For that, we’ll need to download the full list of MDN pages.
But before that, let’s add a response for when the user types mdn
without any search query.
@ FlowPlugin . Search ({ equalTo: " mdn " })
return " Type 'mdn <search-term>' to search MDN web docs " ;
@ FlowPlugin . Search ({ equalTo: " mdn " })
return " Type 'mdn <search-term>' to search MDN web docs " ;
Now, let’s download the MDN data.
It’s located
here .
This is an array of objects, each object representing an MDN page.
Each object only has two properties: title
and url
. Simple enough. Let’s begin!
First, let’s define the types again. The structure here is much simpler than the NPM data, it’s just one object with
two properties.
* @typedef {object} MdnArticle
* @property {string} title
Now we need to actually download that data. We’ll do this on plugin startup, using the FlowPlugin.Init
decorator:
mdnIndexUrl = " https://developer.mozilla.org/en-US/search-index.json " ;
/** @type {MdnArticle[]} */
async downloadMdnData () {
this . mdnData = await this . api . httpGetJson ( mdnIndexUrl );
private readonly mdnIndexUrl = " https://developer.mozilla.org/en-US/search-index.json " ;
private mdnData: MdnArticle[] = [];
async downloadMdnData () {
this . mdnData = await this . api . httpGetJson < MdnArticle []>( this . mdnIndexUrl );
Now that we have the data, let’s add a method to our plugin that will search for MDN pages and display search results.
/** @param {Query} query */
@ FlowPlugin . Search ({ startsWith: " mdn " })
const search = query . Search . toLowerCase ();
. filter ( v => v . title . toLowerCase () . includes ( search ))
action: this . actions . openUrl ( this . mdnUrlPrefix + v . url ),
@ FlowPlugin . Search (startsWith: " mdn " )
searchMdnQuery (query: Query) {
const search = query . search . toLowerCase ();
. filter ( v => v . title . toLowerCase () . includes (search))
action: this . actions . openUrl ( this . mdnUrlPrefix + v . url ),
Let’s test it out.
web mdn intersectionobserver
IntersectionObserverEntry: isIntersecting property
Alt+2
IntersectionObserver: takeRecords() method
Alt+3
IntersectionObserver: IntersectionObserver() constructor
Alt+4
IntersectionObserver: disconnect() method
Alt+5
It works! We have successfully implemented the MDN search functionality.
The Code
Here’s the full code from this tutorial:
import {FlowPlugin} from " flow-launcher-extended-plugin " ;
* @typedef {object} NpmResponse
* @property {NpmObject[]} objects
* @typedef {object} NpmObject
* @property {NpmPackage} package
* @typedef {object} NpmPackage
* @property {string} name
* @property {string} version
* @property {string} description
* @typedef {object} NpmLinks
* @typedef {object} MdnArticle
* @property {string} title
export class NpmAndMdnPlugin extends FlowPlugin {
npmApiUrl = " https://registry.npmjs.com/-/v1/search?text= " ;
mdnIndexUrl = " https://developer.mozilla.org/en-US/search-index.json " ;
mdnUrlPrefix = " https://developer.mozilla.org " ;
/** @type {MdnArticle[]} */
async downloadMdnData () {
this . mdnData = await this . api . httpGetJson ( this . mdnIndexUrl );
return " Type 'npm' or 'mdn' to search for packages or MDN web docs " ;
@ FlowPlugin . Search ({ equalTo: " npm " })
return " Type 'npm <package-name>' to search for a package " ;
/** @param {Query} query */
@ FlowPlugin . Search ({ startsWith: " npm " })
async searchNpmQuery ( query ) {
/** @type {NpmResponse} */
const response = await this . api . httpGetJson ( this . npmApiUrl , query . Search );
return response ?. objects . map ( /** @param {NpmObject} v */ v => ({
title: ` ${ v . package . name } | v ${ v . package . version } ` ,
subtitle: v . package . description ,
action: this . actions . openUrl ( v . package . links . npm ),
@ FlowPlugin . Search ({ equalTo: " mdn " })
return " Type 'mdn <search-term>' to search MDN web docs " ;
/** @param {Query} query */
@ FlowPlugin . Search ({ startsWith: " mdn " })
const search = query . Search . toLowerCase ();
. filter ( v => v . title . toLowerCase () . includes ( search ))
action: this . actions . openUrl ( this . mdnUrlPrefix + v . url ),
import {FlowPlugin} from " flow-launcher-extended-plugin " ;
export class NpmAndMdnPlugin extends FlowPlugin {
private readonly npmApiUrl = " https://registry.npmjs.com/-/v1/search?text= " ;
private readonly mdnIndexUrl = " https://developer.mozilla.org/en-US/search-index.json " ;
private readonly mdnUrlPrefix = " https://developer.mozilla.org " ;
private mdnData : MdnArticle [] = [];
async downloadMdnData () {
this . mdnData = await this . api . httpGetJson < MdnArticle []>( this . mdnIndexUrl );
return " Type 'npm' or 'mdn' to search for packages or MDN web docs " ;
@ FlowPlugin . Search ({ equalTo: " npm " })
return " Type 'npm <package-name>' to search for a package " ;
@ FlowPlugin . Search ({ startsWith: " npm " })
async searchNpmQuery ( query : Query ) {
const response = await this . api . httpGetJson < NpmResponse > ( this . npmApiUrl , query . search );
return response ?. objects . map ( v => ({
title: ` ${ v . package . name } | v ${ v . package . version } ` ,
subtitle: v . package . description ,
action: this . actions . openUrl (v . package . links . npm ),
@ FlowPlugin . Search ({ equalTo: " mdn " })
return " Type 'mdn <search-term>' to search MDN web docs " ;
@ FlowPlugin . Search (startsWith: " mdn " )
searchMdnQuery ( query : Query ) {
const search = query . search . toLowerCase ();
. filter ( v => v . title . toLowerCase () . includes (search))
action: this . actions . openUrl ( this . mdnUrlPrefix + v . url ),