
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Generate 50+ different 1D or 2D barcodes in png, eps, or svg format.
This Node.js module will allow you to generate over 50+ different types of 1D or 2D symbologies, including barcodes for books, grocery, shipping carriers, healthcare, and international codes. It can save a png, svg, or eps image, or render a base64 png bitmap.
yarn add symbology
or:
npm install symbology --save
If you run into issues when building compiling the module locally, please make sure you have the prerequisites installed. For more info, see: 7.1.1. Prerequisites.
var symbology = require('symbology');
Prepare a Symbol json object with your desired settings (see 4. Available options (struct) for more info):
var Symbol = {
symbology: symbology.Barcode.CODE128,
foregroundColor: 'fff000',
backgroundColor: '000000',
fileName: '/my/directory/barcode.png'
};
Each function returns a promise that completes with an object containing the exit code and message of the function (see 5. Error handling for more info).
createStream(Symbol, data, outputType)
Writes the file string to the output object in a property data
. Returns a Promise
.
Note: For png, it will render data
as a base64 string.
Parameter | Type | Values | Default |
---|---|---|---|
Symbol | Struct | Struct of symbology settings | |
data | String | Desired data to encode | |
outputType | String | Output type | PNG |
Enum | Description |
---|---|
EPS | Adobe encapsulated postscript vector |
SVG | Scalable vector graphics |
PNG | Portable network graphics |
symbology
.createStream(Symbol, '12345', symbology.Output.PNG)
.then(function(data) {
console.log('Result: ', data);
}, function(err) {
console.log('Error: ', err);
});
Returns:
Result: {
message: '',
code: 0,
data: 'data:image/png;base64,iVBOR [...] g=='
}
createFile(Symbol, data, type)
Creates a file with the requested barcode. Returns a Promise
.
Note: The file type of the barcode to render is based on the extension fileName
setting.
For example, to render an svg, the fileName
must be of the format: <myfile>.svg
.
Parameter | Type | Values |
---|---|---|
Symbol | Struct | Struct of symbology settings |
data | String | Desired data to encode |
symbology
.createFile(Symbol, '12345')
.then(function(data) {
console.log('Result: ', data);
}, function(err) {
console.log('Error: ', err);
});
This creates a file in the specified fileName
and will log:
Result: {
message: '',
code: 0,
fileName: 'barcode.png'
}
A Symbol is a regular JavaScript object with the following available properties:
Enumerated type | Type | Meaning | Required? | Default value |
---|---|---|---|---|
symbology | Symbology enum | The enumerated type of the symbology (see Enumerated Barcode Types for more info). | Yes | |
height | Number | The height of the image. If specified, this will maintain the aspect ratio. | No | 50 |
whitespaceWidth | Number | Width of whitespace, for barcodes which have this option. | No | 0 |
borderWidth | Number | Width of border. | No | 0 |
outputOptions | Number | Symbology-specific output option. | No | NULL |
foregroundColor | Hexadecimal number | Barcode foreground color. | No | FFFFFF |
backgroundColor | Hexadecimal number | Barcode background color. | No | 000000 |
fileName | String | Full path to the file to render. | Yes* | |
scale | Number | Scale of the barcode image. Applies only to PNG. | No | 1.0 |
option1 | Number | Symbology-type-specific option value. | No | NULL |
option2 | Number | Symbology-type-specific option value. | No | NULL |
option3 | Number | Symbology-type-specific option value. | No | NULL |
* required only if using createFile
.
Each function returns an object having property code
, which is the status code of the function, and message
, which contains an error/warning message (if any).
Below are the possible status codes:
Code | Enumerated type | Meaning |
---|---|---|
2 | ZWARN_INVALID_OPTION | One or more options are invalid but the barcode was created anyway. |
5 | ZERROR_TOO_LONG | The file path was too long. |
6 | ZERROR_INVALID_DATA | The data for the specified symbology is invalid. |
7 | ZERROR_INVALID_CHECK | Error checking (if any) on the rendered barcode failed. |
8 | ZERROR_INVALID_OPTION | One or more options are invalid and rendering failed. |
9 | ZERROR_ENCODING_PROBLEM | Invalid characters in input data. |
10 | ZERROR_FILE_ACCESS | Cannot write to the given path. |
11 | ZERROR_MEMORY | Corrupt or insufficient memory. |
There are 53 different available symbology types. For an exhaustive list, please see the Barcode Types list.
yarn build
libpng is a required for building this module. If you receive an error that png.h was not found, it is because libpng is not installed locally.
yarn test
yarn package-binary
Please report any bugs here.
Available here.
This library is a JS/C++ wrapper module for the terrific C/C++ library Zint, (C) Robin Stuart. Module by Josh Shor.
MIT.
FAQs
🔖 Generates 1D, 2D, and composite barcodes in png, svg, or eps formats. Supports 50+ symbologies.
The npm package symbology receives a total of 479 weekly downloads. As such, symbology popularity was classified as not popular.
We found that symbology demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.