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

receipt

v1.4.0

Published

Generate receipt-like output.

Downloads

437

Readme

Receipt.

Generate receipt-like output for printing in a kiosk, POS system, etc.

Configuration.

Some aspects of the output can be configured via the config property:

const receipt = require('receipt');

receipt.config.currency = '$'; // The currency symbol to use in output.
receipt.config.width = 50;     // The amount of characters used to give the output a "width".
receipt.config.ruler = '=';    // The character used for ruler output.

Example:

const receipt = require('receipt');

receipt.config.currency = '£';
receipt.config.width = 60;
receipt.config.ruler = '-';

const output = receipt.create([
	{ type: 'text', value: [
		'MY AWESOME STORE',
		'123 STORE ST',
		'[email protected]',
		'www.store.com'
	], align: 'center' },
	{ type: 'empty' },
	{ type: 'properties', lines: [
		{ name: 'Order Number', value: 'XXXXXXXXXXXX' },
		{ name: 'Date', value: 'XX/XX/XXXX XX:XX' }
	] },
	{ type: 'table', lines: [
		{ item: 'Product 1', qty: 1, cost: 1000 },
		{ item: 'Product 2 with a really long name', qty: 1, cost: 17500, discount: { type: 'absolute', value: 1000 } },
		{ item: 'Another product wth quite a name', qty: 2, cost: 900 },
		{ item: 'Product 4', qty: 1, cost: 80, discount: { type: 'percentage', value: 0.15 } },
		{ item: 'This length is ridiculously lengthy', qty: 14, cost: 8516 },
		{ item: 'Product 6', qty: 3, cost: 500 },
		{ item: 'Product 7', qty: 3, cost: 500, discount: { type: 'absolute', value: 500, message: '3 for the price of 2' } }
	] },
	{ type: 'empty' },
	{ type: 'text', value: 'Some extra information to add to the footer of this docket.', align: 'center' },
	{ type: 'empty' },
	{ type: 'properties', lines: [
		{ name: 'GST (10.00%)', value: 'AUD XX.XX' },
		{ name: 'Total amount (excl. GST)', value: 'AUD XX.XX' },
		{ name: 'Total amount (incl. GST)', value: 'AUD XX.XX' }
	] },
	{ type: 'empty' },
	{ type: 'properties', lines: [
		{ name: 'Amount Received', value: 'AUD XX.XX' },
		{ name: 'Amount Returned', value: 'AUD XX.XX' }
	] },
	{ type: 'empty' },
	{ type: 'text', value: 'Final bits of text at the very base of a docket. This text wraps around as well!', align: 'center', padding: 5 }
]);

console.log(output);

Which generates:

                 MY AWESOME STORE                 
                   123 STORE ST                   
                  [email protected]                 
                   www.store.com                  
                                                  
Order Number:    XXXXXXXXXXXX
Date:            XX/XX/XXXX XX:XX
--------------------------------------------------
Qty   Product                                Total
--------------------------------------------------
1     Product 1                             £10.00
1     Product 2 with a really long nam     £165.00
        (Item Disc. -£10.00)
2     Another product wth quite a name      £18.00
1     Product 4                              £0.68
        (Item Disc. -15%)
14    This length is ridiculously leng    £1192.24
3     Product 6                             £15.00
3     Product 7                             £10.00
        (3 for the price of 2)
--------------------------------------------------
                                                  
  Some extra information to add to the footer of  
                   this docket.                   
                                                  
GST (10.00%):                AUD XX.XX
Total amount (excl. GST):    AUD XX.XX
Total amount (incl. GST):    AUD XX.XX
                                                  
Amount Received:    AUD XX.XX
Amount Returned:    AUD XX.XX
                                                  
     Final bits of text at the very base of a     
      docket. This text wraps around as well!     

Formatting.

When creating a receipt, simply feed in an array of "chunks". Each chunk defines the format for that chunk, the value to output and other auxiliary information depending on the chunk type.

The inbuilt chunk types and their formats are:

Custom Formatters.

You can define your own formatting types using addFormatter():

const receipt = require('receipt');

receipt.addFormatter('custom', function(chunk) {
	return 'Custom: ' + chunk.value;
});

let output = receipt.create([{ type: 'custom', value: 'Test' }]);

The formatters are bound to receipt, so you are able to access the configuration via this.config or other formatters via this.formatters.x etc.