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-ponyfill

v0.1.0

Published

ponyfill to import some incompatible umd scripts in module/worker

Downloads

3

Readme

import-ponyfill

Loading incompatible UMD scripts for browser module and worker.

Why you need it

Some lib scripts throw errors in ES module or web worker environments because of specific/deprecated UMD wrappers, which is fixedly using this or window to access the global object. Thus you need another mechanism to load these scripts.

How it works

  • use synchronous XMLHttpRequest to load script
  • use sync <script> (or new Function().call() in web worker) to eval js code
  • use /* global xxx */ to mark imported UMD global vars

Case 1: In module js

If import './some.umd.js' throws error, try importSync('./some.umd.js')

// import './some.umd.js'; /* global Some */

import {importSync} from '/node_modules/import-ponyfill/import.js';
importSync('./some.umd.js'); /* global Some */

or if import('./some.umd.js') rejects with an error,

import('./some.umd.js').then(()=>{ /* global Some */
  console.log(Some);
});

try importAsync('./some.umd.js')

import {importAsync} from '/node_modules/import-ponyfill/import.js';
importAsync('./some.umd.js').then()=>{ /* global Some */
  console.log(Some);
});

Case 2: In worker js

If importScripts('./some.umd.js') throws error, try importScriptsSync('./some.umd.js')

// importScripts('./some.umd.js');
importScripts('/node_modules/import-ponyfill/import-scripts.js'); /* global importScriptsSync importScriptsAsync */
importScriptsSync('./some.umd.js');

Supported features

  • supports standard module name prefixes ./ ../ / http: and https:
  • maintains a module registry and won't initiate multiple requests for same module
  • respects commented sourceMappingURL in main-thread module

These features are designed to be conformant to spec as closer as possible.

Known limitations

  • synchronous import requires synchronous XHR which may hurt performance
  • use of CSP script-src requires 'unsafe-eval'
  • sourceMappingURL in web worker will be ignored

For limitations above, this package gives NO WARRANTY, USE AT YOUR OWN RISK

Install

npm install import-ponyfill

Examples

See ./examples/index.html

To run examples,

  1. checkout
  2. npm install && npm start
  3. open http://localhost:8080/examples/