Socket
Socket
Sign inDemoInstall

symbology

Package Overview
Dependencies
145
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    symbology

Generate 50+ different 1D or 2D barcodes in png, svg, or eps formats.


Version published
Weekly downloads
396
decreased by-37.74%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

logo

A Node.js module that generates barcode images. Supports 50+ different 1D or 2D symbologies in png, eps, or svg formats.

Code coverage Build status: Travis Build status: AppVeyor Dependency Status

Contents

1. Introduction

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.

2. Installation

yarn add symbology --fallback-to-build

2.1 Manual installation

If you run into issues downloading the binary, --fallback-to-build will compile the module from source.

You may also compile from source by running npm rebuild.

2.1.1 Compiling on Windows

Ensure you have windows-build-tools globally installed, which bundles Visual C++ Build Tools.

yarn global add windows-build-tools

Then you can compile the module by running npm rebuild in your project directory.

2.1.2 Compiling on Linux or macOS

Simply run npm rebuild in your project directory. node-gyp will utilize the OS's bundled GCC compiler.

3. API

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).


3.1. Stream a barcode:

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.

ParameterTypeValuesDefault
symbolSymbolStruct of symbology settings
dataStringDesired data to encode
outputTypeStringOutput typePNG

Output Types

EnumDescription
EPSAdobe encapsulated postscript vector
SVGScalable vector graphics
PNGPortable network graphics

Example

try {
  await data = symbology.createStream(Symbol, '12345', symbology.Output.PNG)

  console.log('Result: ', data)
} catch (err) {
  console.error('Error: ', err)
}

Returns:

{
  "message": "",
  "code": 0,
  "data": "data:image/png;base64,iVBOR [...] g=="
}

3.2. Render a file:

createFile(Symbol, data)

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.

ParameterTypeValues
symbolSymbolObject of symbology settings
dataStringDesired data to encode

Example

try {
  await data = symbology.createFile(Symbol, '12345', symbology.Output.PNG)

  console.log('File created! Result: ', data)
} catch (err) {
  console.error('Error: ', err)
}

This creates a file in the specified fileName and will log:

{
  "message": "",
  "code": 0,
  "fileName": "barcode.png"
}

4. Available options (Symbol)

A Symbol is a regular JavaScript object with the following available properties:

Enumerated typeTypeMeaningRequired?Default value
symbologySymbology enumThe enumerated type of the symbology (see Enumerated Barcode Types for more info).Yes
heightNumberThe height of the image. If specified, this will maintain the aspect ratio.No50
whitespaceWidthNumberWidth of whitespace, for barcodes which have this option.No0
borderWidthNumberWidth of border.No0
outputOptionsNumberSymbology-specific output option.NoNULL
foregroundColorHexadecimal numberBarcode foreground color.NoFFFFFF
backgroundColorHexadecimal numberBarcode background color.No000000
fileNameStringFull path to the file to render.Yes*
scaleNumberScale of the barcode image. Applies only to PNG.No1.0
option1NumberSymbology-type-specific option value.NoNULL
option2NumberSymbology-type-specific option value.NoNULL
option3NumberSymbology-type-specific option value.NoNULL
showHumanReadableTextBooleanShow or hide the symbology data as human-readable text (if applicable).Notrue

* required only if using createFile().

5. Error handling

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:

CodeEnumerated typeMeaning
2ZWARN_INVALID_OPTIONOne or more options are invalid but the barcode was created anyway.
5ZERROR_TOO_LONGThe file path was too long.
6ZERROR_INVALID_DATAThe data for the specified symbology is invalid.
7ZERROR_INVALID_CHECKError checking (if any) on the rendered barcode failed.
8ZERROR_INVALID_OPTIONOne or more options are invalid and rendering failed.
9ZERROR_ENCODING_PROBLEMInvalid characters in input data.
10ZERROR_FILE_ACCESSCannot write to the given path.
11ZERROR_MEMORYCorrupt or insufficient memory.

6. Symbology types

There are 53 different available symbology types. For an exhaustive list, please see the Barcode Types list.

7. Development

7.1. Building

yarn build

7.2. Testing

yarn test

7.3. Packaging

yarn package:binary

7.4. Bugs

Please report any bugs here.

7.5. Changelog

Available here.

8. Supported platforms

Node.js 10+ is supported for macOS, Linux, Windows (x32), and Windows (x64).

9. Credits

This library is a JS/C++ wrapper module for the terrific C/C++ library Zint, (C) Robin Stuart. Module by Josh Shor.

10. License

MIT.

Keywords

FAQs

Last updated on 14 Dec 2019

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc