1.0.6 • Published 5 years ago

@magneds/hapi-plugin-barcode v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

Hapi Barcode Plugin

Generate bar-/QR codes on the fly from a webserver running Hapi

Installation

$ npm install --save @magneds/hapi-plugin-barcode

Usage

As the name might have suggested already, this package is a plugin for the Hapi framework, simply registering the package as plugin will suffice.

Using @magneds/hapi-server

const HapiServer = require('@magneds/node-hapi-server');
const HapiPluginBarcode = require('@magneds/hapi-plugin-barcode');

new HapiServer()
	.configure({ host: 'localhost', port: 3000 })
	.plugin(HapiPluginBarcode)
	.start()
	.then(() => console.log(`Running @${server.info.uri}`));

Using hapi

const Hapi = require('hapi');
const HapiPluginBarcode = require('@magneds/hapi-plugin-barcode');

const server = Hapi.server({ host: 'localhost', port: 3000 });

const init = async () => {
	await server.register(HapiPluginBarcode);
	await server.start();

	console.log(`Running @${server.info.uri}`);
};

init();

API

The barcode plugin registers two routes to do all the heavy lifting, for the examples below we'll assume the routes are not prefixed to reside in another location.

/barcode/qr/{content}

Generate a QR code with the data provided in {content}. Note that as the content is part of the path, the data must be properly url encoded (e.g. using JavaScript encodeURIComponent, PHP urlencode, or the equivalent in your favorite language)

http://localhost:3000/barcode/qr/hello%20world

Parameters

There are several settings that can be overridden, all of these can be provided as query parameters.

http://localhost:3000/barcode/qr/hello%20world?background=%23f90&color=red&width=1000&ecl=Q
optiondefaultdescriptionnote
padding4white space padding0 for no padding
width256width in pixelsif no height is specified, it will be set to width
height256height in pixelsif no width is specified, it will be set to height
colorcurrentColorforeground colorany valid CSS color value (remember # has a special meaning in URLs so it must be escaped (%23))
backgroundtransparentbackground colorany valid CSS color value (remember # has a special meaning in URLs so it must be escaped (%23))
eclHerror correction levelL, M, H, Q

/barcode/{type}/{content}

Generate a barcode of {type} with the specified data provided in {content}

Valid types

typedescription
codabarCodabar
code11Code 11
code39Code 39
code93Code 93
code128Code 128
ean8EAN 8
ean13EAN 13 (International Article Number)
std25Standard 2 of 5 (Industrial 2 of 5)
int25Interleaved 2 of 5

Specifying any invalid type will result in a 404 - Type "${type}" not found response

Parameters

There are several settings that can be overridden, all of these can be provided as query parameters.

http://localhost:3000/barcode/code39/123456789098?height=30&color=red
optiondefaultdescriptionnote
width160width in pixels
height50(bar) height in pixels
colorcurrentColorforeground colorany valid CSS color value (remember # has a special meaning in URLs so it must be escaped (%23))
backgroundtransparentbackground colorany valid CSS color value (remember # has a special meaning in URLs so it must be escaped (%23))
textfalseinclude the code as textnot as pretty as one might expect
1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago