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.2.4 to 0.3.0

instance.js

91

index.js
const chrome = require('chrome-aws-lambda');
const puppeteer = require('puppeteer');
const path = require('path');
const DEFAULT_CLIENT = `file:${path.join(__dirname, 'dist', 'client.html')}`;
const { createInstance } = require('./instance');
const getNewPage = async (browser, url) => {
const page = await browser.newPage();
page.on('console', (msg) => {
msg.args().forEach((message) => {
// skip style information
if (message.toString().indexOf('margin') >= 0) {
return;
}
const text = message
.toString()
.replace('JSHandle:', '')
.replace('%c', '');
console.log(text);
});
});
await page.goto(url);
return page;
};
module.exports.createInstance = async ({

@@ -53,62 +30,10 @@ key,

});
const visitPage = url || `${DEFAULT_CLIENT}?key=${key}`;
const firstPage = await getNewPage(browser, visitPage);
const run = async (func, ...args) => {
const page = useParallelPages
? await getNewPage(browser, visitPage)
: firstPage;
const result = await page.evaluate(func, ...args);
if (useParallelPages) {
page.close();
}
return result;
};
const jsonToDataURL = async (json, attrs) => {
return await run(
async (json, attrs) => {
const pixelRatio = attrs.pixelRatio || 1;
store.loadJSON(json);
store.setElementsPixelRatio(pixelRatio);
await store.waitLoading();
return store.toDataURL({ ...attrs, pixelRatio });
},
json,
attrs || {}
);
};
const jsonToImageBase64 = async (json, attrs) => {
const url = await jsonToDataURL(json, attrs);
return url.split('base64,')[1];
};
const jsonToPDFDataURL = async (json, attrs) => {
return await run(
async (json, attrs) => {
store.loadJSON(json);
await store.waitLoading();
return await store.toPDFDataURL(attrs);
},
json,
attrs || {}
);
};
const jsonToPDFBase64 = async (json, attrs) => {
const url = await jsonToPDFDataURL(json, attrs);
return url.split('base64,')[1];
};
return {
close: async () => await browser.close(),
run,
jsonToDataURL,
jsonToImageBase64,
jsonToPDFDataURL,
jsonToPDFBase64,
};
return await createInstance({
browser,
key,
url,
useParallelPages,
browserArgs,
});
};
{
"name": "polotno-node",
"version": "0.2.4",
"version": "0.3.0",
"description": "Polotno workflow from NodeJS",

@@ -13,2 +13,3 @@ "main": "index.js",

"index.js",
"instance.js",
"README.md"

@@ -15,0 +16,0 @@ ],

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