npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prexview

v1.1.0

Published

A JavaScript module to use PrexView, a fast, scalable and friendly service for programatic HTML, PDF, PNG or JPG generation using JSON or XML data.

Downloads

20

Readme

PrexView

Status npm version

A JavaScript module to use PrexView, a fast, scalable and friendly service for programatic HTML, PDF, PNG or JPG generation using JSON or XML data.

See PrexView for more information about the service.

Installation

npm install --save prexview

Getting started

Get your API Key

You can get an API Key from PrexView

Set up your API Key

If you can setup enviroment variables

export PXV_API_KEY="YOUR_API_KEY"

If you can't setup environment variables, create the PrexView object with your API Key as argument

pxv = new PrexView('YOUR_API_KEY');

Include the library

const PrexView = require('prexview')

Sending an XML

To send an XML string use pxv.sendXML(xml, options) method, this method will return a Promise with the Response object on success or an error if something is wrong.

Example
const fs = require('fs')
const PrexView = require('prexview')

const pxv = new Prexview();

const options = {
  template: 'supported_languages',
  output: 'pdf'
}

const xml = `<?xml version="1.0" encoding="UTF-8"?>
<languages>
  <lang code="en">English</lang>
  <lang code="es">Español</lang>
  <lang code="fr">Française</lang>
</languages>`;

const file = 'test.pdf'

pxv.sendXML(xml, options)
  .then((res) => {
    fs.writeFileSync(file, res.file)

    console.log(`File created: ${file}`)
  }).catch((err) => {
    console.log(e.message)
  })

Sending a JSON

To send a JSON string or JavaScript object use pxv.sendJSON(json, options) method, this method will return a Promise with the Response object on success or an error if something is wrong.

Example
const fs = require('fs')
const PrexView = require('prexview')

const pxv = new Prexview();

const options = {
  template: 'supported_languages',
  output: 'pdf'
}

// this can also be a valid string.
const json = {
  languages: [{
    code: 'en',
    name: 'Inglés'
  }, {
    code: 'es',
    name: 'Spanish'
  }, {
    code: 'fr',
    name: 'Française'
  }]
}

const file = 'test.pdf'

pxv.sendXML(xml, options)
  .then((res) => {
    fs.writeFileSync(file, res.file)

    console.log(`File created: ${file}`)
  }).catch((err) => {
    console.log(e.message)
  })
Response object

|Property|Type|Description| |--------|:--:|-----------| |id|string|Transaction ID.| |file|binary|Document created by the service.| |responseTime|int|Response time from service.| |rateLimit|int|Maximum number of calls to the service.| |rateLimitReset|int|Seconds to reset the rate limit.| |rateRemaining|int|Number of remaining call to the service.|

Options

|Name|Type|Required|Description| |----|:--:|:------:|-----------| |template|string|Yes|Template's name to be used to document creation, you can use dynamic values.| |output|string|Yes|Type of document that will be created by PrexView service, it must be html, pdf, png or jpg.| |note|string|No|Custom information to be added to the document's metadata, it's limit up to 500 characters and you can use dynamic values.| |format|string|No|Type of data used to the document creation, it must be xml or json, this should be inferred from library methods.| |templateBackup|string|No|Template's name to use to be used if the option template is not available in the service.|

Dynamic values

In template or note options you can use JSON sintax to access data and have dynamic values, for instance having the following JSON data:

{
  "Data": {
    "customer": "123"
  }
}

Your template or note can use any data attribute or text node, for instance:

'invoice-customer-{{Data.customer}}'

Then we will translate that to the following:

'invoice-customer-123'

And finally the service will try to find the template or note invoice-customer-123 in order to transform the data and generate the document.

License

MIT © PrexView