0.4.0 • Published 2 months ago

dp v0.4.0

Weekly downloads
4
License
MIT
Repository
github
Last release
2 months ago

dp

JavaScript loader

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-side templating (JSX, Vue, Svelte, Solid, Handlebars, Marko)
  • Import transpiled languages (TypeScript, CoffeeScript)
  • Other stuff (.txt files as string, .wasm modules)

Install

npm install dp

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=dp app.js

import config from "./config.json";

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

Programmatically

If used programmatically, imports coming after dp() must be dynamic (import()).

import dp from "dp";

dp();

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

Configure

This currently applies only programmatically.

extensions

Object property to remap a given extension to a loader. In the following example, the yaml loader will trigger on .yml files in addition to the default .yaml.

import dp from "dp";

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

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

virtuals

Object property in the form of { [path]: code } to load from memory instead of the filesystem. The loading occurs before any loaders are called.

import dp from "dp";

dp({ virtuals: { "/config.json": '{ "foo": "bar" }' } });

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

// config.foo -> "bar"

Loaders

NameExtensionDependency
json.jsonnone
text.txtnone
wasm.wasmnone
csv.csvcsv-parse
json5.json5json5
toml.tomltoml
xml.xmlxml2js
yaml.yamlyaml
react.jsxesbuild
vue.vuevue
svelte.sveltesvelte
solid.solidbabel-present-solid @babel/core
handlebars.hbshandlebars
marko.markomarko
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.3.0

2 months ago

0.2.0

2 months ago

0.4.0

2 months ago

0.0.1

2 years ago

1.0.0

3 years ago

0.1.0

3 years ago

0.0.0

3 years ago