Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@barcode-bakery/barcode-common

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@barcode-bakery/barcode-common - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

0

dist/BCGArgumentException.d.ts

@@ -0,0 +0,0 @@ /*!

@@ -0,0 +0,0 @@ 'use strict';

1

dist/BCGBarcode.d.ts

@@ -220,3 +220,4 @@ /*!

private getBiggestLabels;
private isInstanceOfBCGColor;
}
export { BCGBarcode };

735

dist/BCGBarcode.js
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
Object.defineProperty(exports, '__esModule', { value: true });
exports.BCGBarcode = void 0;

@@ -8,6 +8,6 @@ /*!

*/
const BCGColor_1 = require("./BCGColor");
const BCGLabel_1 = require("./BCGLabel");
const BCGArgumentException_1 = require("./BCGArgumentException");
const draw_1 = require("./draw");
const BCGColor_1 = require('./BCGColor');
const BCGLabel_1 = require('./BCGLabel');
const BCGArgumentException_1 = require('./BCGArgumentException');
const draw_1 = require('./draw');
/**

@@ -17,372 +17,419 @@ * Constructor.

class BCGBarcode {
constructor() {
/**
* Color for the foreground.
*/
this.colorFg = new BCGColor_1.BCGColor(0x000000);
/**
* Color for the background.
*/
this.colorBg = new BCGColor_1.BCGColor(0xffffff);
/**
* Scale of the graphic, default: 1.
*/
this.scale = 1;
/**
* Position where to start the drawing in X.
*/
this.offsetX = 0;
/**
* Position where to start the drawing in Y.
*/
this.offsetY = 0;
/**
* Array of BCGLabel.
*/
this.labels = [];
/**
* Push the label, left and top.
*/
this.pushLabel = [0, 0];
}
constructor() {
/**
* Gets the foreground color of the barcode.
*
* @return The foreground color.
* Color for the foreground.
*/
getForegroundColor() {
return this.colorFg;
}
this.colorFg = new BCGColor_1.BCGColor(0x000000);
/**
* Sets the foreground color of the barcode. It could be a Color
* value or simply a language code (white, black, yellow...) or hex value.
*
* @param color The foreground color.
* Color for the background.
*/
setForegroundColor(color) {
if (color instanceof BCGColor_1.BCGColor) {
this.colorFg = color;
}
else {
this.colorFg = new BCGColor_1.BCGColor(color);
}
}
this.colorBg = new BCGColor_1.BCGColor(0xffffff);
/**
* Gets the background color of the barcode.
*
* @return The background color.
* Scale of the graphic, default: 1.
*/
getBackgroundColor() {
return this.colorBg;
}
this.scale = 1;
/**
* Sets the background color of the barcode. It could be a Color
* value or simply a language code (white, black, yellow...) or hex value.
*
* @param color The background color.
* Position where to start the drawing in X.
*/
setBackgroundColor(color) {
if (color instanceof BCGColor_1.BCGColor) {
this.colorBg = color;
}
else {
this.colorBg = new BCGColor_1.BCGColor(color);
}
for (let label of this.labels) {
label.setBackgroundColor(this.colorBg);
}
}
this.offsetX = 0;
/**
* Sets the foreground and background color.
*
* @param foregroundColor The foreground color.
* @param backgroundColor The background color.
* Position where to start the drawing in Y.
*/
setColor(foregroundColor, backgroundColor) {
this.setForegroundColor(foregroundColor);
this.setBackgroundColor(backgroundColor);
}
this.offsetY = 0;
/**
* Gets the scale of the barcode.
*
* @return The scale.
* Array of BCGLabel.
*/
getScale() {
return this.scale;
}
this.labels = [];
/**
* Sets the scale of the barcode in pixel.
* If the scale is lower than 1, an exception is raised.
*
* @param scale Gets the scale of the barcode.
* Push the label, left and top.
*/
setScale(scale) {
scale = parseInt(scale?.toString(), 10);
if (scale <= 0) {
throw new BCGArgumentException_1.BCGArgumentException('The scale must be larger than 0.', 'scale');
}
this.scale = scale;
this.pushLabel = [0, 0];
}
/**
* Gets the foreground color of the barcode.
*
* @return The foreground color.
*/
getForegroundColor() {
return this.colorFg;
}
/**
* Sets the foreground color of the barcode. It could be a Color
* value or simply a language code (white, black, yellow...) or hex value.
*
* @param color The foreground color.
*/
setForegroundColor(color) {
if (this.isInstanceOfBCGColor(color)) {
this.colorFg = color;
} else {
this.colorFg = new BCGColor_1.BCGColor(color);
}
/**
* Returns the maximal size of a barcode.
* [0]->width
* [1]->height
*
* @param width The width.
* @param height The height.
* @return An array, [0] being the width, [1] being the height.
*/
getDimension(width, height) {
let labels = this.getBiggestLabels(false);
let pixelsAround = [0, 0, 0, 0]; // TRBL
let dimension;
if (labels[BCGLabel_1.BCGLabel.Position.Top]) {
dimension = labels[BCGLabel_1.BCGLabel.Position.Top].getDimension();
pixelsAround[0] += dimension[1];
}
if (labels[BCGLabel_1.BCGLabel.Position.Right]) {
dimension = labels[BCGLabel_1.BCGLabel.Position.Right].getDimension();
pixelsAround[1] += dimension[0];
}
if (labels[BCGLabel_1.BCGLabel.Position.Bottom]) {
dimension = labels[BCGLabel_1.BCGLabel.Position.Bottom].getDimension();
pixelsAround[2] += dimension[1];
}
if (labels[BCGLabel_1.BCGLabel.Position.Left]) {
dimension = labels[BCGLabel_1.BCGLabel.Position.Left].getDimension();
pixelsAround[3] += dimension[0];
}
let finalW = (width + this.offsetX) * this.scale;
let finalH = (height + this.offsetY) * this.scale;
// This section will check if a top/bottom label is too big for its width and left/right too big for its height
let reversedLabels = this.getBiggestLabels(true);
reversedLabels.forEach(function (label) {
let dimension = label.getDimension();
let alignment = label.getAlignment();
let temp;
if (label.getPosition() === BCGLabel_1.BCGLabel.Position.Left || label.getPosition() === BCGLabel_1.BCGLabel.Position.Right) {
if (alignment === BCGLabel_1.BCGLabel.Alignment.Top) {
pixelsAround[2] = Math.max(pixelsAround[2], dimension[1] - finalH);
}
else if (alignment === BCGLabel_1.BCGLabel.Alignment.Center) {
temp = Math.ceil((dimension[1] - finalH) / 2);
pixelsAround[0] = Math.max(pixelsAround[0], temp);
pixelsAround[2] = Math.max(pixelsAround[2], temp);
}
else if (alignment === BCGLabel_1.BCGLabel.Alignment.Bottom) {
pixelsAround[0] = Math.max(pixelsAround[0], dimension[1] - finalH);
}
}
else {
if (alignment === BCGLabel_1.BCGLabel.Alignment.Left) {
pixelsAround[1] = Math.max(pixelsAround[1], dimension[0] - finalW);
}
else if (alignment === BCGLabel_1.BCGLabel.Alignment.Center) {
temp = Math.ceil((dimension[0] - finalW) / 2);
pixelsAround[1] = Math.max(pixelsAround[1], temp);
pixelsAround[3] = Math.max(pixelsAround[3], temp);
}
else if (alignment === BCGLabel_1.BCGLabel.Alignment.Right) {
pixelsAround[3] = Math.max(pixelsAround[3], dimension[0] - finalW);
}
}
});
this.pushLabel[0] = pixelsAround[3];
this.pushLabel[1] = pixelsAround[0];
finalW = (width + this.offsetX) * this.scale + pixelsAround[1] + pixelsAround[3];
finalH = (height + this.offsetY) * this.scale + pixelsAround[0] + pixelsAround[2];
return [finalW, finalH];
}
/**
* Gets the background color of the barcode.
*
* @return The background color.
*/
getBackgroundColor() {
return this.colorBg;
}
/**
* Sets the background color of the barcode. It could be a Color
* value or simply a language code (white, black, yellow...) or hex value.
*
* @param color The background color.
*/
setBackgroundColor(color) {
if (this.isInstanceOfBCGColor(color)) {
this.colorBg = color;
} else {
this.colorBg = new BCGColor_1.BCGColor(color);
}
/**
* Gets the X offset.
*
* @return The X offset.
*/
getOffsetX() {
return this.offsetX;
for (let label of this.labels) {
label.setBackgroundColor(this.colorBg);
}
/**
* Sets the X offset.
*
* @param offsetX The X offset.
*/
setOffsetX(offsetX) {
offsetX = parseInt(offsetX.toString(), 10);
if (offsetX < 0) {
throw new BCGArgumentException_1.BCGArgumentException('The offset X must be 0 or larger.', 'offsetX');
}
this.offsetX = offsetX;
}
/**
* Sets the foreground and background color.
*
* @param foregroundColor The foreground color.
* @param backgroundColor The background color.
*/
setColor(foregroundColor, backgroundColor) {
this.setForegroundColor(foregroundColor);
this.setBackgroundColor(backgroundColor);
}
/**
* Gets the scale of the barcode.
*
* @return The scale.
*/
getScale() {
return this.scale;
}
/**
* Sets the scale of the barcode in pixel.
* If the scale is lower than 1, an exception is raised.
*
* @param scale Gets the scale of the barcode.
*/
setScale(scale) {
scale = parseInt(scale?.toString(), 10);
if (scale <= 0) {
throw new BCGArgumentException_1.BCGArgumentException('The scale must be larger than 0.', 'scale');
}
/**
* Gets the Y offset.
*
* @return The Y offset.
*/
getOffsetY() {
return this.offsetY;
this.scale = scale;
}
/**
* Returns the maximal size of a barcode.
* [0]->width
* [1]->height
*
* @param width The width.
* @param height The height.
* @return An array, [0] being the width, [1] being the height.
*/
getDimension(width, height) {
let labels = this.getBiggestLabels(false);
let pixelsAround = [0, 0, 0, 0]; // TRBL
let dimension;
if (labels[BCGLabel_1.BCGLabel.Position.Top]) {
dimension = labels[BCGLabel_1.BCGLabel.Position.Top].getDimension();
pixelsAround[0] += dimension[1];
}
/**
* Sets the Y offset.
*
* @param offsetY The Y offset.
*/
setOffsetY(offsetY) {
offsetY = parseInt(offsetY.toString(), 10);
if (offsetY < 0) {
throw new BCGArgumentException_1.BCGArgumentException('The offset Y must be 0 or larger.', 'offsetY');
}
this.offsetY = offsetY;
if (labels[BCGLabel_1.BCGLabel.Position.Right]) {
dimension = labels[BCGLabel_1.BCGLabel.Position.Right].getDimension();
pixelsAround[1] += dimension[0];
}
/**
* Adds the label to the drawing.
*
* @param label The label.
*/
addLabel(label) {
label.setBackgroundColor(this.colorBg);
this.labels.push(label);
if (labels[BCGLabel_1.BCGLabel.Position.Bottom]) {
dimension = labels[BCGLabel_1.BCGLabel.Position.Bottom].getDimension();
pixelsAround[2] += dimension[1];
}
/**
* Removes the label from the drawing.
*
* @param label The label.
*/
removeLabel(label) {
let remove = -1;
let c = this.labels.length;
for (let i = 0; i < c; i++) {
if (this.labels[i] === label) {
remove = i;
break;
}
if (labels[BCGLabel_1.BCGLabel.Position.Left]) {
dimension = labels[BCGLabel_1.BCGLabel.Position.Left].getDimension();
pixelsAround[3] += dimension[0];
}
let finalW = (width + this.offsetX) * this.scale;
let finalH = (height + this.offsetY) * this.scale;
// This section will check if a top/bottom label is too big for its width and left/right too big for its height
let reversedLabels = this.getBiggestLabels(true);
reversedLabels.forEach(function (label) {
let dimension = label.getDimension();
let alignment = label.getAlignment();
let temp;
if (label.getPosition() === BCGLabel_1.BCGLabel.Position.Left || label.getPosition() === BCGLabel_1.BCGLabel.Position.Right) {
if (alignment === BCGLabel_1.BCGLabel.Alignment.Top) {
pixelsAround[2] = Math.max(pixelsAround[2], dimension[1] - finalH);
} else if (alignment === BCGLabel_1.BCGLabel.Alignment.Center) {
temp = Math.ceil((dimension[1] - finalH) / 2);
pixelsAround[0] = Math.max(pixelsAround[0], temp);
pixelsAround[2] = Math.max(pixelsAround[2], temp);
} else if (alignment === BCGLabel_1.BCGLabel.Alignment.Bottom) {
pixelsAround[0] = Math.max(pixelsAround[0], dimension[1] - finalH);
}
if (remove > -1) {
this.labels.splice(remove, 1);
} else {
if (alignment === BCGLabel_1.BCGLabel.Alignment.Left) {
pixelsAround[1] = Math.max(pixelsAround[1], dimension[0] - finalW);
} else if (alignment === BCGLabel_1.BCGLabel.Alignment.Center) {
temp = Math.ceil((dimension[0] - finalW) / 2);
pixelsAround[1] = Math.max(pixelsAround[1], temp);
pixelsAround[3] = Math.max(pixelsAround[3], temp);
} else if (alignment === BCGLabel_1.BCGLabel.Alignment.Right) {
pixelsAround[3] = Math.max(pixelsAround[3], dimension[0] - finalW);
}
}
});
this.pushLabel[0] = pixelsAround[3];
this.pushLabel[1] = pixelsAround[0];
finalW = (width + this.offsetX) * this.scale + pixelsAround[1] + pixelsAround[3];
finalH = (height + this.offsetY) * this.scale + pixelsAround[0] + pixelsAround[2];
return [finalW, finalH];
}
/**
* Gets the X offset.
*
* @return The X offset.
*/
getOffsetX() {
return this.offsetX;
}
/**
* Sets the X offset.
*
* @param offsetX The X offset.
*/
setOffsetX(offsetX) {
offsetX = parseInt(offsetX.toString(), 10);
if (offsetX < 0) {
throw new BCGArgumentException_1.BCGArgumentException('The offset X must be 0 or larger.', 'offsetX');
}
/**
* Clears the labels.
*/
clearLabels() {
this.labels = [];
this.offsetX = offsetX;
}
/**
* Gets the Y offset.
*
* @return The Y offset.
*/
getOffsetY() {
return this.offsetY;
}
/**
* Sets the Y offset.
*
* @param offsetY The Y offset.
*/
setOffsetY(offsetY) {
offsetY = parseInt(offsetY.toString(), 10);
if (offsetY < 0) {
throw new BCGArgumentException_1.BCGArgumentException('The offset Y must be 0 or larger.', 'offsetY');
}
/**
* Draws the text.
* The coordinate passed are the positions of the barcode.
* x1 and y1 represent the top left corner.
* x2 and y2 represent the bottom right corner.
*
* @param image The sutface.
* @param x1 X1.
* @param y1 Y1.
* @param x2 X2.
* @param y2 Y2.
*/
drawText(image, x1, y1, x2, y2) {
this.labels.forEach(label => {
label.draw(image, (x1 + this.offsetX) * this.scale + this.pushLabel[0], (y1 + this.offsetY) * this.scale + this.pushLabel[1], (x2 + this.offsetX) * this.scale + this.pushLabel[0], (y2 + this.offsetY) * this.scale + this.pushLabel[1]);
});
this.offsetY = offsetY;
}
/**
* Adds the label to the drawing.
*
* @param label The label.
*/
addLabel(label) {
label.setBackgroundColor(this.colorBg);
this.labels.push(label);
}
/**
* Removes the label from the drawing.
*
* @param label The label.
*/
removeLabel(label) {
let remove = -1;
let c = this.labels.length;
for (let i = 0; i < c; i++) {
if (this.labels[i] === label) {
remove = i;
break;
}
}
/**
* Draws 1 pixel on the resource at a specific position with a determined color.
*
* @param image The surface.
* @param x The X.
* @param y The Y.
* @param color The color.
*/
drawPixel(image, x, y, color = BCGBarcode.COLOR_FG) {
let xR = (x + this.offsetX) * this.scale + this.pushLabel[0];
let yR = (y + this.offsetY) * this.scale + this.pushLabel[1];
// We always draw a rectangle
draw_1.imagefilledrectangle(image, xR, yR, xR + this.scale - 1, yR + this.scale - 1, this.getColor(image, color));
if (remove > -1) {
this.labels.splice(remove, 1);
}
/**
* Draws an empty rectangle on the resource at a specific position with a determined color.
*
* @param image The surface.
* @param x1 X1.
* @param y1 Y1.
* @param x2 X2.
* @param y2 Y2.
* @param color The color.
*/
drawRectangle(image, x1, y1, x2, y2, color = BCGBarcode.COLOR_FG) {
if (this.scale === 1) {
draw_1.imagefilledrectangle(image, (x1 + this.offsetX) + this.pushLabel[0], (y1 + this.offsetY) + this.pushLabel[1], (x2 + this.offsetX) + this.pushLabel[0], (y2 + this.offsetY) + this.pushLabel[1], this.getColor(image, color));
}
else {
draw_1.imagefilledrectangle(image, (x1 + this.offsetX) * this.scale + this.pushLabel[0], (y1 + this.offsetY) * this.scale + this.pushLabel[1], (x2 + this.offsetX) * this.scale + this.pushLabel[0] + this.scale - 1, (y1 + this.offsetY) * this.scale + this.pushLabel[1] + this.scale - 1, this.getColor(image, color));
draw_1.imagefilledrectangle(image, (x1 + this.offsetX) * this.scale + this.pushLabel[0], (y1 + this.offsetY) * this.scale + this.pushLabel[1], (x1 + this.offsetX) * this.scale + this.pushLabel[0] + this.scale - 1, (y2 + this.offsetY) * this.scale + this.pushLabel[1] + this.scale - 1, this.getColor(image, color));
draw_1.imagefilledrectangle(image, (x2 + this.offsetX) * this.scale + this.pushLabel[0], (y1 + this.offsetY) * this.scale + this.pushLabel[1], (x2 + this.offsetX) * this.scale + this.pushLabel[0] + this.scale - 1, (y2 + this.offsetY) * this.scale + this.pushLabel[1] + this.scale - 1, this.getColor(image, color));
draw_1.imagefilledrectangle(image, (x1 + this.offsetX) * this.scale + this.pushLabel[0], (y2 + this.offsetY) * this.scale + this.pushLabel[1], (x2 + this.offsetX) * this.scale + this.pushLabel[0] + this.scale - 1, (y2 + this.offsetY) * this.scale + this.pushLabel[1] + this.scale - 1, this.getColor(image, color));
}
}
/**
* Clears the labels.
*/
clearLabels() {
this.labels = [];
}
/**
* Draws the text.
* The coordinate passed are the positions of the barcode.
* x1 and y1 represent the top left corner.
* x2 and y2 represent the bottom right corner.
*
* @param image The sutface.
* @param x1 X1.
* @param y1 Y1.
* @param x2 X2.
* @param y2 Y2.
*/
drawText(image, x1, y1, x2, y2) {
this.labels.forEach(label => {
label.draw(
image,
(x1 + this.offsetX) * this.scale + this.pushLabel[0],
(y1 + this.offsetY) * this.scale + this.pushLabel[1],
(x2 + this.offsetX) * this.scale + this.pushLabel[0],
(y2 + this.offsetY) * this.scale + this.pushLabel[1]
);
});
}
/**
* Draws 1 pixel on the resource at a specific position with a determined color.
*
* @param image The surface.
* @param x The X.
* @param y The Y.
* @param color The color.
*/
drawPixel(image, x, y, color = BCGBarcode.COLOR_FG) {
let xR = (x + this.offsetX) * this.scale + this.pushLabel[0];
let yR = (y + this.offsetY) * this.scale + this.pushLabel[1];
// We always draw a rectangle
draw_1.imagefilledrectangle(image, xR, yR, xR + this.scale - 1, yR + this.scale - 1, this.getColor(image, color));
}
/**
* Draws an empty rectangle on the resource at a specific position with a determined color.
*
* @param image The surface.
* @param x1 X1.
* @param y1 Y1.
* @param x2 X2.
* @param y2 Y2.
* @param color The color.
*/
drawRectangle(image, x1, y1, x2, y2, color = BCGBarcode.COLOR_FG) {
if (this.scale === 1) {
draw_1.imagefilledrectangle(
image,
x1 + this.offsetX + this.pushLabel[0],
y1 + this.offsetY + this.pushLabel[1],
x2 + this.offsetX + this.pushLabel[0],
y2 + this.offsetY + this.pushLabel[1],
this.getColor(image, color)
);
} else {
draw_1.imagefilledrectangle(
image,
(x1 + this.offsetX) * this.scale + this.pushLabel[0],
(y1 + this.offsetY) * this.scale + this.pushLabel[1],
(x2 + this.offsetX) * this.scale + this.pushLabel[0] + this.scale - 1,
(y1 + this.offsetY) * this.scale + this.pushLabel[1] + this.scale - 1,
this.getColor(image, color)
);
draw_1.imagefilledrectangle(
image,
(x1 + this.offsetX) * this.scale + this.pushLabel[0],
(y1 + this.offsetY) * this.scale + this.pushLabel[1],
(x1 + this.offsetX) * this.scale + this.pushLabel[0] + this.scale - 1,
(y2 + this.offsetY) * this.scale + this.pushLabel[1] + this.scale - 1,
this.getColor(image, color)
);
draw_1.imagefilledrectangle(
image,
(x2 + this.offsetX) * this.scale + this.pushLabel[0],
(y1 + this.offsetY) * this.scale + this.pushLabel[1],
(x2 + this.offsetX) * this.scale + this.pushLabel[0] + this.scale - 1,
(y2 + this.offsetY) * this.scale + this.pushLabel[1] + this.scale - 1,
this.getColor(image, color)
);
draw_1.imagefilledrectangle(
image,
(x1 + this.offsetX) * this.scale + this.pushLabel[0],
(y2 + this.offsetY) * this.scale + this.pushLabel[1],
(x2 + this.offsetX) * this.scale + this.pushLabel[0] + this.scale - 1,
(y2 + this.offsetY) * this.scale + this.pushLabel[1] + this.scale - 1,
this.getColor(image, color)
);
}
/**
* Draws a filled rectangle on the resource at a specific position with a determined color.
*
* @param image The surface.
* @param x1 X1.
* @param y1 Y1.
* @param x2 X2.
* @param y2 Y2.
* @param color The color.
*/
drawFilledRectangle(image, x1, y1, x2, y2, color = BCGBarcode.COLOR_FG) {
if (x1 > x2) { // Swap
x1 ^= x2 ^= x1 ^= x2;
}
if (y1 > y2) { // Swap
y1 ^= y2 ^= y1 ^= y2;
}
draw_1.imagefilledrectangle(image, (x1 + this.offsetX) * this.scale + this.pushLabel[0], (y1 + this.offsetY) * this.scale + this.pushLabel[1], (x2 + this.offsetX) * this.scale + this.pushLabel[0] + this.scale - 1, (y2 + this.offsetY) * this.scale + this.pushLabel[1] + this.scale - 1, this.getColor(image, color));
}
/**
* Draws a filled rectangle on the resource at a specific position with a determined color.
*
* @param image The surface.
* @param x1 X1.
* @param y1 Y1.
* @param x2 X2.
* @param y2 Y2.
* @param color The color.
*/
drawFilledRectangle(image, x1, y1, x2, y2, color = BCGBarcode.COLOR_FG) {
if (x1 > x2) {
// Swap
x1 ^= x2 ^= x1 ^= x2;
}
/**
* Allocates the color based on the integer.
*
* @param image The surface.
* @param color The color.
* @return The color.
*/
getColor(image, color) {
if (color === BCGBarcode.COLOR_BG) {
return this.colorBg.allocate(image);
if (y1 > y2) {
// Swap
y1 ^= y2 ^= y1 ^= y2;
}
draw_1.imagefilledrectangle(
image,
(x1 + this.offsetX) * this.scale + this.pushLabel[0],
(y1 + this.offsetY) * this.scale + this.pushLabel[1],
(x2 + this.offsetX) * this.scale + this.pushLabel[0] + this.scale - 1,
(y2 + this.offsetY) * this.scale + this.pushLabel[1] + this.scale - 1,
this.getColor(image, color)
);
}
/**
* Allocates the color based on the integer.
*
* @param image The surface.
* @param color The color.
* @return The color.
*/
getColor(image, color) {
if (color === BCGBarcode.COLOR_BG) {
return this.colorBg.allocate(image);
} else {
return this.colorFg.allocate(image);
}
}
/**
* Returning the biggest label widths for LEFT/RIGHT and heights for TOP/BOTTOM.
*
* @param reversed Reversed.
* @return Labels.
*/
getBiggestLabels(reversed) {
reversed = !!reversed;
let searchLR = reversed ? 1 : 0;
let searchTB = reversed ? 0 : 1;
let labels = [];
this.labels.forEach(function (label) {
let position = label.getPosition();
if (labels[position]) {
let savedDimension = labels[position].getDimension();
let dimension = label.getDimension();
if (position === BCGLabel_1.BCGLabel.Position.Left || position === BCGLabel_1.BCGLabel.Position.Right) {
if (dimension[searchLR] > savedDimension[searchLR]) {
labels[position] = label;
}
} else {
if (dimension[searchTB] > savedDimension[searchTB]) {
labels[position] = label;
}
}
else {
return this.colorFg.allocate(image);
}
} else {
labels[position] = label;
}
});
return labels;
}
isInstanceOfBCGColor(obj) {
// Node might have some problem connecting the right object
// instanceof might not work.
if (obj instanceof BCGColor_1.BCGColor) {
//return true;
}
/**
* Returning the biggest label widths for LEFT/RIGHT and heights for TOP/BOTTOM.
*
* @param reversed Reversed.
* @return Labels.
*/
getBiggestLabels(reversed) {
reversed = !!reversed;
let searchLR = reversed ? 1 : 0;
let searchTB = reversed ? 0 : 1;
let labels = [];
this.labels.forEach(function (label) {
let position = label.getPosition();
if (labels[position]) {
let savedDimension = labels[position].getDimension();
let dimension = label.getDimension();
if (position === BCGLabel_1.BCGLabel.Position.Left || position === BCGLabel_1.BCGLabel.Position.Right) {
if (dimension[searchLR] > savedDimension[searchLR]) {
labels[position] = label;
}
}
else {
if (dimension[searchTB] > savedDimension[searchTB]) {
labels[position] = label;
}
}
}
else {
labels[position] = label;
}
});
return labels;
}
return ['vR', 'vG', 'vB'].every(p => typeof obj[p] === 'number');
}
}

@@ -389,0 +436,0 @@ exports.BCGBarcode = BCGBarcode;

@@ -0,0 +0,0 @@ import { BCGBarcode } from './BCGBarcode';

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ import { BCGBarcode } from './BCGBarcode';

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ /*!

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ /*!

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ /*!

@@ -0,0 +0,0 @@ 'use strict';

@@ -67,4 +67,4 @@ /// <reference types="node" />

setRotationAngle(degree: number | string): void;
toBuffer(format: BCGDrawing.ImageFormat, callback?: (err: Error | null, data: Buffer) => void): void;
toBufferSync(format: BCGDrawing.ImageFormat): void;
toBuffer(format: BCGDrawing.ImageFormat, callback?: (err: Error | null, data: Buffer) => void): Buffer;
toBufferSync(format: BCGDrawing.ImageFormat): Buffer;
save(fileName: string, callback?: (err: NodeJS.ErrnoException) => void): void;

@@ -71,0 +71,0 @@ save(fileName: string, format: BCGDrawing.ImageFormat, callback?: (err: NodeJS.ErrnoException) => void): void;

@@ -92,6 +92,6 @@ 'use strict';

let drawer = getDrawerFromFormat(format, this.image, this.dpi); // !Done in draw.
drawer.toBuffer(callback);
return drawer.toBuffer(callback);
}
toBufferSync(format) {
this.toBuffer(format);
return this.toBuffer(format);
}

@@ -98,0 +98,0 @@ save(fileName, arg2, callback) {

@@ -0,0 +0,0 @@ import { BCGColor } from './BCGColor';

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ import { BCGFont } from './BCGFont';

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ /*!

@@ -0,0 +0,0 @@ 'use strict';

@@ -51,3 +51,3 @@ /// <reference types="node" />

abstract toFile(fileName: string, callback?: (err: NodeJS.ErrnoException) => void): void;
abstract toBuffer(callback?: (err: Error | null, data: Buffer) => void): void;
abstract toBuffer(callback?: (err: Error | null, data: Buffer) => void): Buffer;
}

@@ -57,3 +57,3 @@ export declare class DrawBasic extends Draw {

toFile(fileName: string, callback?: (err: NodeJS.ErrnoException) => void): void;
toBuffer(callback?: (err: Error | null, data: Buffer) => void): void;
toBuffer(callback?: (err: Error | null, data: Buffer) => void): Buffer;
}

@@ -63,3 +63,3 @@ export declare class DrawPNG extends Draw {

toFile(fileName: string, callback?: (err: NodeJS.ErrnoException) => void): void;
toBuffer(callback?: (err: Error | null, data: Buffer) => void): void;
toBuffer(callback?: (err: Error | null, data: Buffer) => void): Buffer;
}

@@ -105,3 +105,3 @@ 'use strict';

toBuffer(callback) {
this.image.canvas.toBuffer(callback);
return this.image.canvas.toBuffer(callback);
}

@@ -108,0 +108,0 @@ }

@@ -0,0 +0,0 @@ /*!

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ /*!

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ Barcode Bakery Common for NodeJS has two possible licenses.

{
"name": "@barcode-bakery/barcode-common",
"version": "2.0.0",
"version": "2.0.1",
"description": "Base code for generating barcode with the Barcode Bakery library. See barcode-bakery-1d.",
"repository": "git://github.com/barcode-bakery/barcode-nodejs-common",
"author": {

@@ -6,0 +7,0 @@ "name": "Jean-Sébastien Goupil",

@@ -0,0 +0,0 @@ <p align="center"><a href="https://www.barcodebakery.com" target="_blank">

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc