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

@litert/loader

v3.5.8

Published

Simple browser module loader.

Downloads

23

Readme

Simple browser module loader.

Languages

简体中文 | 繁體中文

Features

  • [x] Supports running code in memory.
  • [x] The configuration is simple and lightweight.
  • [x] No intrusion and does not affect the script label.
  • [x] Support the CommonJS / ES6 Module format.
  • [x] The fetch function is automatically supported without additional loading.
  • [x] Support TypeScript.

Installation

This is a module for browsers and eventually needs to be referenced by the script tag.

NPM

You can install directly using NPM:

$ npm i @litert/loader --save

Or install the developing (unstable) version for newest features:

$ npm i @litert/loader@dev --save

CDN (recommend)

Recommended: https://cdn.jsdelivr.net/npm/@litert/[email protected]/dist/loader.min.js, you can also find it here https://cdn.jsdelivr.net/npm/@litert/loader/.

Also available on unpkg.

Usage

Here's a general how to use it:

<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected]/dist/loader.min.js"></script>

The code hint needs to be added in "tsconfig.json":

{
    "compilerOptions": {
        ...
        "typeRoots": [
            "./node_modules/@types",
            "./node_modules/@litert/loader"
        ]
    }
}

All actions are written in the "ready" callback.

loader.ready(function() {
    let files: Record<string, Blob | string> = { ... };
    let tmodule: any, module2: any;
    [tmodule, module2] = loader.require(['../dist/tmodule', './module2'], files);
});

Alternatively, use ?path= to load the ingress file directly, the js file extension can be omitted.

<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected]/dist/index.min.js?path=../lib/test"></script>

Use the ?cdn= parameter to set the source address of the third library load, default is: https://cdn.jsdelivr.net.

<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected]/dist/index.min.js?cdn=https://cdn.xxx.xxx"></script>

Use the ?map= parameter to set the path to the third-party library, a JSON string, that is valid only with the path parameter.

<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected]/dist/index.min.js?&path=xxx&map={'xxx':'https://xx/npm/index'}"></script>

Using the ?npm= parameter loader will automatically go to npm to find the relevant library for sniffing loading, JSON string, module name and version number, only valid with the path parameter.

<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected]/dist/index.min.js?&path=xxx&npm={'xxx':'1.0.0'}"></script>

You can use the fetchFiles method to load network files into memory.

let files: Record<string, Blob | string> = await loader.fetchFiles([
    '../dist/tmodule.js',
    './module2.js',
    'https://cdn.jsdelivr.net/npm/[email protected]/seedrandom.min.js'
]);

Use sniffFiles to load network files into the memory, and sniff the inclusion relationship in the file, such as js import, require, etc., CSS url, etc.

let files: Record<string, Blob | string> = {};
await loader.sniffFiles([
    'https://cdn.jsdelivr.net/npm/@juggle/[email protected]/lib/exports/resize-observer.js'
], {
    'files': files
});

Using the map option, you can specify the alias of the library, the alias of the import command is also based on this.

let cache: Record<string, any> = {};
let files: Record<string, Blob | string> = {};
if (!Object.keys(files).includes('https://cdn.jsdelivr.net/npm/[email protected]/seedrandom.min.js')) {
    await loader.fetchFiles([
        'https://cdn.jsdelivr.net/npm/[email protected]/seedrandom.min.js'
    ], {
        'files': files
    });
}
let sr = loader.require('seedrandom', files, {
    'cache': cache,
    'map': {
        'seedrandom': 'https://cdn.jsdelivr.net/npm/[email protected]/seedrandom.min',
        '~/': './'
    }
})[0];

Test

Node

After compiling the TS code, execute: node dist/test-on-node to observe the execution results of the test code under node.

Browser

Use the browser to visit "test/" to view the comparison results are the same as in the node environment.

You can also click here to access the example online.

License

This library is published under Apache-2.0 license.