Builtin transformers for inline-js
npm install inline-js-default-transformsinline-js-default-transforms
============================



This repository contains builtin transformers for inline-js
Installation
------------
``js
`
npm install inline-js-default-transforms
`
Usage
-----
js
`
const {createInliner} = require("inline-js-core");
const {TRANSFORMS} = require("inline-js-default-transforms");
const inliner = createInliner();
TRANSFORMS.forEach(inliner.transformer.add);
`
TRANSFORMS
----------
$3
Minify css content.
$3
Convert the content into data URL.
The transformer would determine the mimetype from the filename:
js
`
// data:text/css;charset=utf8;base64,...
$inline("mystyle.css|dataurl")
// data:image/png;base64,...
$inline("myimage.png|dataurl")
`
Or you can pass the mimetype manually:
js
`
$inline("somefile.txt|dataurl:text/css")
utf8
Specify charset (default to for text files):
`js
`
$inline("somefile.txt|dataurl:text/css,utf8")
$0
$3
Extract docstring (i.e. the top-most template literal) from the content.
$3
Evaluate JavaScript expression. You can access the content with .
`js
`
var version = $inline("./package.json|eval:JSON.parse($0).version|stringify");
`
$3
Indent the string according to the indent of the current line.
entry.js
js
`
function test() {
$inline("foo.js|indent");
}
`
foo.js
js
`
console.log("foo");
console.log("bar");
inlinejs entry.js result:
`js
`
function test() {
console.log("foo");
console.log("bar");
}
``
$3
Wrap content with markdown codeblock, code, or quote.
js
`
// a.txt
some text
// $inline("a.txt|markdown:codeblock")
`
some text
`
// $inline("a.txt|markdown:codeblock,js")
js
`
some text
some text
// $inline("a.txt|markdown:code")
``
// $inline("a.txt|markdown:quote")
> sometext
JSON.parse
$3
the content. You can access properties by specifying key name.
`js
`
var version = $inline("./package.json|parse:version"),
nestedProp = $inline("./package.json|parse:nested,prop");
JSON.stringify
$3
If the content is a buffer, convert it into a utf8 string. Otherwise do nothing.
$3
the content. Useful to include text content into JavaScript code:
`js
`
var myCssString = $inline("./style.css|cssmin|stringify");
String.prototype.trim
$3
the content.
indent
Changelog
---------
* 0.1.2 (Jun 6, 2020)
- Fix: make work with $inline.start.
markdown:codeblock`.
- Add: support language mark in
* 0.1.1 (Jun 28, 2018)
- Fix: exclude test files from the package.
* 0.1.0 (Jun 27, 2018)
- Split out from inline-js.