load-everything
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

Load everything

It is now fairly feasible to publish JavaScript that can load everything across all major JavaScript environments:

  • Chromium-based browsers
    • Chrome
    • Edge
    • Opera
    • Brave, Vivaldi, etc.
  • Safari
  • Firefox
  • node
  • deno
  • bun

However, some environments have small quirks. load-everything implements those quirks so you can write compatible code without having to test and research them from scratch.

Usage

Call import.meta.resolve(…) and pass the output directly to one of the provided functions.

import { loadJSON } from "load-everything";

loadJSON(import.meta.resolve("./data.json"));

API

function dynamicImport(import.meta.resolve()): Promise<any>;
function loadText(import.meta.resolve()): Promise<string>;
function loadJSON(import.meta.resolve()): Promise<any>;
function loadBlob(import.meta.resolve()): Promise<Blob>;
function loadArrayBuffer(import.meta.resolve()): Promise<ArrayBuffer>;

URL

For code code that is more widely compatible with older environments and bundlers, you can use import.meta.url to construct a URL instead, and pass this to any of the functions:

import { loadJSON } from "load-everything";

loadJSON(new URL("./data.json", import.meta.url));

Readme

Keywords

none

Package Sidebar

Install

npm i load-everything

Weekly Downloads

0

Version

0.1.2

License

MIT

Unpacked Size

20.4 kB

Total Files

15

Last publish

Collaborators

  • lgarron