1.0.1 • Published 3 years ago

string-module-maker v1.0.1

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

String Module Maker

Generate a module exporting an arbitrary string.

Sometimes you may want to bundle a string encoding some binary data with your library, e.g. for initializing a WASM instance easily, making a module that exports that string is trivial if you are using base64, but you should probably use base256 instead for greater memory efficiency, but that requires escaping some characters, this library basically just does that, it escapes some characters, wraps the string in quotes, and generates a module that exports that string for you, which you can then write to disk.

Install

npm install --save string-module-maker

Usage

import ModuleMaker from 'string-module-maker';

// Generate raw string

ModuleMaker.toRaw ( 'foo' ); // => "`foo`"
ModuleMaker.toCJS ( 'foo' ); // => "module exports = `foo`;"
ModuleMaker.toESM ( 'foo' ); // => "export default `foo`;"

License

MIT © Fabio Spampinato