npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

alias-extension

v1.0.0

Published

Execute functions remotely in different contexts of your extension

Downloads

7

Readme

Alias-Extension

Execute functions remotely in different contexts of your extension.

Install

npm install --save alias-extension

Get started

An example of the execution of functions from content in the context of background.

content.js:

import { createAliases } from 'alias-extension';

const aliases = {
	FOO: 'foo'
}

const { foo } = createAliases(aliases);

foo();

background.js:

import { executeAliases } from 'alias-extension';

const aliases = {
	FOO: () => {
    	console.log('bar');
        return 'foo';
    }
}

executeAliases(aliases);

Calling the foo function from the content script will cause FOO alias to be executed in the background script. The call will return the value returned from FOO alias.

API

createAliases(aliases[, options])

  • aliases an object in which the key is the name of the alias and the key is the name of the function to call the alias.
  • options:
    • senderName - sender identifier string.
    • extensionId - id of the extension to which alias will be sent.
    • toActiveTab - if true then alias will be sent to the content script of the active page.
    • tabId - sends alias for the content script of the page with the specified id.
    • sendOptions - options for sendMessage.
    • showBrowserError - if true, when an error occurs, the console will also display an error generated by the browser.
    • activeTabNotOptimized - by default, the id for sending alias for the content script of the active page is calculated only once for each createAliases. Set this flag to true so that the id of the active page is calculated each time alias is executed.

createAliasesToTab(aliases[, options])

A wrapper for the createAliases function which sets the toActiveTab flag if tabId is not passed or == false.

executeAliases(aliases[, options])

  • aliases an object in which the key is the name of the alias and the value of the function that is executed when this alias is executed.
  • options:
    • senderName - string or array of strings. If this parameter is specified, aliases will be executed only if the senderName of the sender aliases matches the senderName of the executor or is contained in the senderName array of the executing aliases.
    • tabsOnly - if true only aliases from content scripts are executed.
    • excludeTabs - if true then aliases from content scripts are ignored.
    • extensionId - checks the extension id of the sending alias to match the one specified in the parameter.

executeTabAliases(aliases[, options])

Wrapper for the executeAliases function with set tabsOnly: true and excludeTabs: false.

License

MIT