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

virtual-printer

v1.0.17

Published

A Node.js module that makes Virtual IPP Printer

Downloads

16

Readme

🖨 virtual-printer

A Node.js module that makes Virtual IPP Printer.

https://nodei.co/npm/virtual-printer.png?downloads=true&downloadRank=true&stars=true

Usage

import { Printer, HandledJob, FastifyRequest } from 'virtual-printer';

const printer = new Printer({ //default options
  serverUrl: new URL('http://0.0.0.0:3000'),
  printerUriSupported: new URL('ipp://0.0.0.0:3000'),
  name: 'Printer',
  description: 'IPP Printer created by NodeJS',
  location: '0.0.0.0',
  moreInfo: new URL('ipp://0.0.0.0:3000'),
  format: ['application/pdf'],
  bonjour: true,
})

printer.on('server-opened', (error) => {
  console.error(error);
});

printer.on('data', (handledJob: HandledJob, data: Buffer, request: FastifyRequest) => {
  console.log(handledJob, request.url);
  writeFileSync(resolve('output/', handledJob.createdAt + '.ps'), data);
});

API

Class: Printer

new Printer(PrinterOptions)

The Printer object can be initialized with an object containing:

  • serverUrl: URL|string
    • For fastify listing host and port.
    • If serverUrl is string, listen on socket.
  • bonjour: boolean
    • true will publish printer server to bonjour network using @homebridge/ciao.
  • name: string
    • Name of the printer. (default: Printer )
    • rfc8011#5.4.4: printer-name (name(127))
  • printerUriSupported: URL
    • URL for requesting print job for client.
    • rfc8011#5.4.1: printer-uri-supported (1setOf uri)
  • description: string
    • rfc8011#5.4.6: printer-info (text(127))
  • location: string
    • rfc8011#5.4.5: printer-location (text(127))
  • moreInfo: string
    • rfc8011#5.4.7: printer-more-info (uri)
  • format: string[]
    • Formats in string array must be taken from IANA MIME types.
    • First string in string array will set to document-format-default.
    • rfc8011 #5.4.21: document-format-default (mimeMediaType)
    • rfc8011 #5.4.22: document-format-supported (1setOf mimeMediaType)

All attributes need to follow rules by RFC 8011 and IANA MIME types.

Event: data

Emitted when server received new print job. The handledJob: HandledJob is an instance of HandleJob. data: Buffer is data part parsed from request. A request: FastifyRequest instance of request.body will Buffer and including data and request body.

import { HandledJob, FastifyRequest } from 'virtual-printer';

printer.on('data', (handledJob: HandledJob, data: Buffer, request: FastifyRequest) => {
  console.log(handledJob, request.url);
  // const rawRequest = request.data;
  writeFileSync(resolve('output/', handledJob.createdAt + '.ps'), data);
});

Event: server-opened

Emitted when server started. The error: Error is from fastify server.

printer.on('server-opened', (error?: Error | null) => {
  console.error(error);
});

Event: bonjour-published

Emitted when server published to bonjour network.

printer.on('bonjour-published', () => {
  console.log('Server published to bonjour');
});

Event: bonjour-name-change

Emitted when server name changed which published to bonjour network. The name: string is new name that published to bonjour network.

printer.on('bonjour-name-change', (name: string) => {
  console.log('Bonjour name changed', name);
});

Event: bonjour-hostname-change

Emitted when local hostname changed. The hostname: string is new name from your local.

printer.on('bonjour-name-change', (hostname: string) => {
  console.log('Bonjour hostname changed', hostname);
});

handleJobs: HandleJob[]

The jobs that printer received.

startedAt: Date

server: FastifyInstance

The fastify instance that server listening.

printerOption: PrinterOptions

Printer options when you constructed with default values.

Class: HandledJob

job-id: number

The id of the job.

job-state: number

The state of the job. Always 9. (rfc8011#5.3.7 completed)

job-name: string

The name of the job from request. If name cannot parse, it will be new Date().toISOString().

job-originating-user-name: string

The username of the job from request. If username cannot parse, it will be anonymous.

createdAt: Date

The creation date of the job.

License

MIT