phantom-storm
v0.0.7
Published
Snapshot your code
Downloads
14
Maintainers
Readme
Phantom storm
Installation
$ npm install phantom-storm --save
Example
Take a snapshot of your awesome code. Using Node v7+ you can run the example with node --harmony-async-await file.js
const fs = require('fs');
const phantomStorm = require('phantom-storm');
(async function(){
const editor = await phantomStorm.init()
editor.write('function greet(name) {return `Hello ${name}`}')
const data = await editor.toBase64()
fs.writeFile('greet.png', data, 'base64', err => {
if (err) {
console.log(err);
}
console.log('Done!', 'greet.png')
});
editor.close()
}())
NOTE
Module works only Node v7+ with flag: node --harmony-async-await your_file.js
Node.js v7.6+ now officially supports async functions without using the --harmony
flag
editor
object API
To create a new instance of editor
use phantomStorm.init([options])
which returns a Promise
which should resolve with a editor
object.
phantomStorm.init().then( editor => /* ... */);
editor options
Options of editor may set in init([options])
method phantomStorm. Default options is: { language: 'js', theme: 'zenburn' }
.
editor.setOptions(options)
Also options may changes after create instanse of editor
like this: editor.setOptions({/* some options */})
. For example:
editor.setOptions({ language: 'xml' });
Avaliable 150+ languages and 70+ theme.
editor.listLanguages()
Returns list of avaliable languages.
editor.write(code)
Writes code in your editor.
phantomStorm.init().then( editor => editor.write('Your awesome code'));
editor.clear()
Clears editor
editor.write('Your awesome code');
editor.clear();
editor.toBase64()
Snapshots your js code with hightlight, and returns a Promise
which should resolve with a base64
string.
phantomStorm.init().then( async (editor) => {
editor.write('Your awesome code');
const base64 = await editor.toBase64();
});
editor.toImage(filename, format='png', quality='100')
Snapshots your js code with hightlight and save image. Supported formats: pdf, png, jpeg, bmp, ppm. Quality: An integer between 0 and 100.
phantomStorm.init().then( async (editor) => {
editor.write('function greet(name) {return `Hello ${name}`}');
await editor.toImage('code.png')
});
editor.close()
Closes instance of editor. If you want to end work with editor just shut down it.