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

import-for-web

v0.5.0

Published

A code modularization support for browsers and asynchronous module loader that supports ECMAScript import and export statements.

Downloads

2

Readme

Import-For-Web shines when employed with multi-page application systems

Available import statement syntax

Source: MDN

import defaultExport from "module-name";
import * as name from "module-name";
import { export1 } from "module-name";
import { export1 as alias1 } from "module-name";
import { default as alias } from "module-name";
import { export1, export2 } from "module-name";
import { export1, export2 as alias2, /* … */ } from "module-name";
import { "string name" as alias } from "module-name";
import defaultExport, { export1, /* … */ } from "module-name";
import defaultExport, * as name from "module-name";
import "module-name";

Supported import statement syntax by I4W

There are four forms of the import declarations. Import-For-Web currently supports two: Named and Default import declarations.

import defaultExport from "module-name";
import { export1 } from "module-name";
import { export1, export2, /* ...and many more */ } from "module-name";

Supported export statement syntax by I4W

export default somethingToExport;
export { first_thingToExport, second_thingToExport, /* ...and many more */ };

Examples

// /src/modules/module-1.js
const add = (a, b)=> a + b;
export { add };    
// /src/modules/module-2.js
const sub = (a, b)=> a - b;
export default sub;    
// /src/modules/index.js

//<@imports>
import { add } from "./module-1"
import sub from "./module-2"
//</>

consol.log(add(8,9) - sub(6,3));

export { add, sub };    

What Actually Happens

In the above codes, export and export default are transpiled into I4W.export =. I4W.export is a setter which stores expoted values into an object where they can be accessed by other modules via the import statements.
In betwewn the imports tag: //<@imports> and //</> is where Import-For-Web looks for import declarations. import is transpiled into const, from is transpiled into = and "module_name" is transpiled into I4W.require('/modules/project_name@project_version/filename.js')

Assuming the package.json file as:

// /package.json
{
    "name": "my_app",
    "version": "1.0.0",
    "main": "src/modules/index.js"
}    

The transpiled form of the example codes above are:

// dist/modules/module-1.js
I4W.pathname = '/modules/[email protected]/module-1.js'
!function(){
    const add = (a, b)=> a + b;
    I4W.export = { add };  
}();  
// dist/modules/module-2.js
I4W.pathname = '/modules/[email protected]/module-2.js'
!function(){
    const sub = (a, b)=> a - b;
    I4W.export = sub;  
}();  
// dist/modules/index.js


I4W.pathname = '/modules/[email protected]'; // Excludes the filename since this file is referenced as the main field in the package.json

// Include statements sets up the dependencies of the module
I4W.include('/modules/[email protected]/module-1.js')
I4W.include('/modules/[email protected]/module-2.js')

//Setting onload callback starts loading all dependencies asynchronously and in parrallel
// All dependencies must be loaded before the onload() callback will execute.
I4W.onload = function(){
    const { add } = I4W.require('/modules/[email protected]/module-1.js');
    const sub = I4W.require('/modules/[email protected]/module-2.js');

    consol.log(add(8,9) - sub(6,3));

    I4W.export = { add, sub }; 
}

NOTICE: Did you observe how each file includes the current version of the project? This makes it easy to either upgrade to newer versions or downgrade to older versions of your project modules cached by users' browsers.You can also upgarde or downgrade some few modeles instead by keeping both versions of your project.

Rules

  • import statements must be surrounded with an imports tag: //<@imports> and //</>
  • Only codes in the /src/modules folder shall be transpiled, bundled and minified by I4W.
  • Output files are stored in dist/modules folder.