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

node-cups

v1.2.3

Published

Wrapper library for unix cups commands

Downloads

344

Readme

CUPS JavaScript API

The CUPS JavaScript API is a library that provides a convenient way to interact with the CUPS (Common UNIX Printing System) command line tool on Linux distributions. With the provided functions and type definitions, you can easily retrieve print job details, get printer options, print files or buffers, and cancel print jobs. This API enables seamless integration of printing capabilities into your JavaScript applications on Linux distributions.

Getting Started

To use the CUPS JavaScript API in your project, follow these steps:

  1. Install the necessary dependencies:
npm install node-cups
  1. Import the required functions and types into your JavaScript file:
import {
  getCompletedQueue,
  getNotCompletedQueue,
  getPrinterNames,
  getPrinterOptions,
  getAllPrinterOptions,
  printBuffer,
  printFile,
  cancelAllJobs,
  cancelJob,
} from "node-cups";
  1. Start using the API functions in your application as shown in the examples below.

API Summary

The CUPS JavaScript API exposes several functions for interacting with print jobs and printers:

1. Type Definitions

The API also provides the following type definitions to assist in type checking:

type JobQueue = Array<{
  id: string;
  printerName: string;
  user: string;
  size: string;
  date: string;
}>

type QueueOptions = {
  printers?: string[];
}

type PrinterOptions = {
  name: string;
  values: string[];
  defaultValue?: string;
}

type PrintParams = {
  printer?: string;
  copies?: number;
  priority?: number;
  pages?: string;
  fitToPage?: boolean;
  printerOptions: Record<string, string>;
}

type PrintResult = {
  stdout: string;
  requestId?: string;
}

2. Print Job Functions

  • getCompletedQueue(options?: QueueOptions): Promise<JobQueue> Retrieves a list of completed print jobs.

    Example:

    const completedJobs = await getCompletedQueue();
    console.log(completedJobs);
  • getNotCompletedQueue(options?: QueueOptions): Promise<JobQueue> Retrieves a list of print jobs that are not yet completed.

    Example:

    const notCompletedJobs = await getNotCompletedQueue();
    console.log(notCompletedJobs);
  • getPrinterNames(): Promise<string[]> Retrieves a list of printer names available on the system.

    Example:

    const printerNames = await getPrinterNames();
    console.log(printerNames);
  • getPrinterOptions(printerName: string): Promise<Array<PrinterOptions>> Retrieves the available options for a specific printer.

    Example:

    const printerOptions = await getPrinterOptions("printer-1");
    console.log(printerOptions);
  • getAllPrinterOptions(): Promise<Array<{ printerName: string; options: PrinterOptions[] }>> Retrieves all printer options for each printer on the system.

    Example:

    const allPrinterOptions = await getAllPrinterOptions();
    console.log(allPrinterOptions);
  • printBuffer(data: Buffer, params: PrintParams): Promise<PrintResult> Prints a buffer of data using the specified print parameters.

    Example:

    const data = Buffer.from("Hello, World!", "utf8");
    const params = {
      printer: "printer-1",
      copies: 2,
      printerOptions: {
        orientation: "landscape",
      },
    };
    const result = await printBuffer(data, params);
    console.log(result);
  • printFile(file: string, params: PrintParams): Promise<PrintResult> Prints a file using the specified print parameters.

    Example:

    const file = "/path/to/file.pdf";
    const params = {
      printer: "printer-1",
      copies: 1,
      printerOptions: {
        media: "A4",
      },
    };
    const result = await printFile(file, params);
    console.log(result);
  • cancelAllJobs(printer?: string): Promise<void> Cancels all print jobs on the system.

    Example:

    await cancelAllJobs();
  • cancelJob(requestId: string): Promise<void> Cancels a specific print job identified by the requestId.

    Example:

    const requestId = "job-123";
    await cancelJob(requestId);