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

crs-modules

v1.0.17

Published

CRS modules allows you to define modules based on keys. The aim is to load modules only when required. Under normal conditions you would just use the import language feature. When working with schema driven UI however you may want to have something

Downloads

20

Readme

CRS Modules

Introduction

CRS modules allows you to define modules based on keys.
The aim is to load modules only when required.
Under normal conditions you would just use the import language feature. When working with schema driven UI however you may want to have something that will dynamically load modules based on the features defined in the modules.

This library aims to be used alongside packages such as crs-schema and crs-components for the above example.

If you are using crs-binding you can extend the binding engine to auto load modules for web components when it parses the dom elements.

await crs.modules.enableBinding([
    ["my-component", "/components/my-component.js"],
    ["other-component", "/components/other-components.js"]
]);

The parameter is an array of module registries.

Functions

dispose

When you are done with the modules, call dispose to clear resources

clear

Clear all resources registered on modules

add

Add new module to load providing a key and value pair.

await crs.modules.add("module-name", "/app/function-test.js");

remove

Remove a module from the registry.

await crs.modules.remove("module-name");

get

Load and get the module from the registry for further use.

await crs.modules.get("module-name");

getDefault

Load the module and return the default exported module item.

const fn = await this.getDefault("module-name");

getPrototype

Get the prototype used to instantiate a class

const proto = await this.getPrototype(key, className);
const intance = new proto();

getInstanceOf

Create a class instance defined on the module.

await crs.modules.getInstanceOf("module-name", "ClassName", param1, param2);

Parameters are sent to the constructor.
If the key and class name is the same you don't need to define the class name.

await crs.modules.getInstanceOf("Test");

getInstanceOfDefault

Create a class instance that is exported as the default

await crs.modules.getInstanceOfDefault("module-name");

call

Call a function defined on the module.

await crs.modules.call("module-name", null, "functionTest", param1, param2);

If the key and the function name is the same you don't need to define the function name.

await crs.modules.call("lib");

callDefault

Call a function that is set as the default export.

await crs.modules.callDefault("default", null, "Hello World"); 

Locations

In some cases you can use a convention over code method to register modules.
This means you don't need to load each module individually but load it based on a location.
This works a little different between auto-loading component files vs library files.

To register a component location

await crs.modules.addComponentLocation("pv", "/components");

To register a module location

await crs.modules.addModuleLocation('pv', "../modules");

Since component registry is separate from the module registry, you can reuse the sake key.

Components using locations

<test-component data-module="pv"></test-component>

Using this option, when crs-binding processes the element it will see you have a module location defined on the component and load it using a naming convention. The convention works like this.

`${location}/${nodeName}/${nodeName}.js` // "/components/test-component/test-component.js"

executing features on path

const result = await crs.modules.call("pv:my-module", "whoAmI");

This example shows how you use a location key with the module name.
This also uses a convention over code.

`${location}/${module}.js` // "/modules/my-module.js"

If you don't want to use the file name, you will need to register the module with

await crs.modules.add("module-name", "/app/function-test.js");