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