New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@tsofist/webshot

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@tsofist/webshot

A quick and effective way to shoot web pages

unpublished
latest
Source
npmnpm
Version
0.1.6
Version published
Maintainers
1
Created
Source

DEPRECATED

webshot

Быстрый, а главное эффективный, способ "сфотографировать" веб-страницу.

Ключевые моменты

  • Источником может быть html-строка, url (включая file:)
  • Результатом может быть бинарный файл, бинарный буфер; бинарный поток записи может быть приемником
  • Поддерживаемые форматы результата: pdf, png, jpeg

Под капотом electron

Установка

npm i @tsofist/webshot --save --production

Использование

import { startupShooter } "webshot";

const myShooter = startupShooter();

/**
 * Page from URL to binary Buffer
 */
function shotPageByURLToBinaryBuffer(url: string, format: ShotFormat): Promise<Buffer> {
    return myShooter
        .then((shooter) => shooter.shotURL(format, url));
}

/**
 * Page from URL to local file
 */
function shotPageByURLToFile(url: string, format: ShotFormat, filename: string): Promise<string> {
    return myShooter
        .then((shooter) => shooter.shotURL(format, url, filename));
}

/**
 * Page from URL to stream (e.g. Express.Response)
 */
function shotPageByURLToStream(url: string, format: ShotFormat, destination: NodeJS.WritableStream): Promise<NodeJS.WritableStream> {
    return myShooter
        .then((shooter) => shooter.shotURL(format, url, destination));
}

И это не все! Можно проделать тоже самое но с html!

import { startupShooter } "webshot";

const myShooter = startupShooter();

/**
 * Page as HTML-string to binary Buffer
 */
function shotHTMLToBinaryBuffer(html: string, format: ShotFormat): Promise<Buffer> {
    return myShooter
        .then((shooter) => shooter.shotHTML(format, url));
}

/**
 * Page as HTML-string to local file
 */
function shotHTMLToFile(html: string, format: ShotFormat, filename: string): Promise<string> {
    return myShooter
        .then((shooter) => shooter.shotHTML(format, url, filename));
}

/**
 * Page as HTML-string to stream (e.g. Express.Response)
 */
function shotHTMLToStream(html: string, format: ShotFormat, destination: NodeJS.WritableStream): Promise<NodeJS.WritableStream> {
    return myShooter
        .then((shooter) => shooter.shotHTML(format, url, destination));
}

Как только вам надоест потребность в конверторе иссякнет, его можно остановить, либо уничтожить вовсе.

// soft
myShooter.shutdown(() => console.log("Shooter is shutted down"));
// hard
myShooter.halt();

Поддерживаемые форматы

Формат можно описывать следующим образом:

// PDF
{
    type: "pdf",
    marginsType?: 0 // default
        |1          // no
        |2;         // minimum
    pageSize?: "Legal"
        |"Letter"
        |"Tabloid"
        |"A3"|"A4"|"A5"
        |{ height: number; width: number; };
    printBackground?: boolean; // false by default
    landscape?: boolean;       // false by default
}

// PNG
{
    type: "png",
    scaleFactor?: number;
    size?: "auto"|{ height: number; width: number; };
}

// JPEG
{
    type: "jpeg",
    quality: number;
    size?: "auto"|{ height: number; width: number; };    
}

TODO

  • cli (?)
  • Тесты, много тестов!
  • Очереди, пулы страниц, пулы electron-экземпляров
  • Больше документации (?)

Keywords

html-to-pdf

FAQs

Package last updated on 23 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts