0.1.1 • Published 3 months ago

enload v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

enload - universal common loader for JS runtimes

Why?

  • Import a variety of configuration formats (YAML, TOML, JSON5)
  • Loosen Node's standard enforcement of import assertions for JSON
  • Import frontend framework formats for server templating (JSX, Vue, Svelte)
  • Import transpiled languages (TypeScript, CoffeeScript)

Install

npm install enload

For the loaders, peer deps must be installed and you will be informed if they're missing. See loaders for supported loaders.

Use

In the terminal

If you run from the terminal, you get both static and dynamic imports.

node --import=enload/register app.js

import config from "./config.json";

// or (await import("./config.json")).default

Programmatically

If you use programmatically, imports coming after the enload() invocation must be dynamic (import()).

import enload from "enload";

enload();

const config = (await import("./config.json")).default;

Configure

This currently applies only programmatically.

You can pass an extensions object property to remap a given loader to a new extension. In the following example, the yaml loader will trigger on .yml files.

import enload from "enload";

enload({ extensions: { yaml: ".yml" } });

const config = (await import("./config.yml")).default;

Loaders

NameExtensionDependency
csv.csvcsv-parse
json.json
json5.json5json5
toml.tomltoml
xml.xmlxml2js
yaml.yamlyaml
jsx.jsxesbuild
vue.vuevue
svelte.sveltesvelte
typescript.tsesbuild
coffeescript.coffeecoffeescript

License

MIT

Contributing

By submitting code you confirm that you are its sole owner and agree to place it under the terms of MIT, see LICENSE.

0.1.1

3 months ago

0.1.0

3 months ago