Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

polotno-node

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polotno-node - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

dist/client.a9b47031.js

26

index.js

@@ -17,9 +17,11 @@ const puppeteer = require('puppeteer');

const run = async (func, ...args) => {
return await page.evaluate(func, ...args);
};
return {
close: async () => await browser.close(),
run: async (func, ...args) => {
return await page.evaluate(func, ...args);
},
run,
jsonToDataURL: async (json) => {
return await instance.run(async (json) => {
return await run(async (json) => {
store.loadJSON(json);

@@ -30,3 +32,19 @@ await store.waitLoading();

},
jsonToImageBase64: async (json) => {
return await run(async (json) => {
store.loadJSON(json);
await store.waitLoading();
const url = store.toDataURL();
return url.split('base64,')[1];
}, json);
},
jsonToPDFBase64: async (json) => {
return await run(async (json) => {
store.loadJSON(json);
await store.waitLoading();
const url = await store.toPDFDataURL();
return url.split('base64,')[1];
}, json);
},
};
};

4

package.json
{
"name": "polotno-node",
"version": "0.1.3",
"version": "0.1.4",
"description": "Polotno workflow from NodeJS",

@@ -17,3 +17,3 @@ "main": "index.js",

"parcel-bundler": "^1.12.4",
"polotno": "^0.17.0",
"polotno": "^0.18.0",
"react": "^17.0.1",

@@ -20,0 +20,0 @@ "react-dom": "^17.0.1"

@@ -27,19 +27,5 @@ # Polotno-node

// execute loading of JSON and export to image
// we can't directly use "json" variable inside the run function
// we MUST pass it as the second argument
const url = await instance.run(async (json) => {
store.loadJSON(json);
await store.waitLoading();
return store.toDataURL();
}, json);
// or the same code, but much shorter:
// const url = await instance.jsonToDataURL(json);
const imageBase64 = await instance.jsonToImageBase64(json);
fs.writeFileSync('out.png', imageBase64, 'base64');
// prepare base64 string to save
var base64Data = url.replace(/^data:image\/png;base64,/, '');
// save it to local file
require('fs').writeFileSync('out.png', base64Data, 'base64');
// close instance

@@ -50,3 +36,40 @@ instance.close();

run();
```
```
## API
### `instance.run()`
Run any Polotno store API directly inside web-page context
```js
// we can't directly use "json" variable inside the run function
// we MUST pass it as the second argument
const url = await instance.run(async (json) => {
store.loadJSON(json);
await store.waitLoading();
return store.toDataURL();
}, json);
```
### `instance.jsonToImageBase64(json)`
Export json into base64 string of image.
```js
const json = JSON.parse(fs.readFileSync('polotno.json'));
const imageBase64 = await instance.jsonToImageBase64(json);
fs.writeFileSync('out.png', imageBase64, 'base64');
```
### `instance.jsonToImageBase64(json)`
Export json into base64 string of pdf file.
```js
const json = JSON.parse(fs.readFileSync('polotno.json'));
const pdfBase64 = await instance.jsonToPDFBase64(json);
fs.writeFileSync('out.pdf', pdfBase64, 'base64');
```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc