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

symbology

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

symbology

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

  • 1.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
393
decreased by-28.42%
Maintainers
1
Weekly downloads
 
Created
Source

Symbology.js

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

Coverage Status Build Status npm version License

dependency Status devDependency Status

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

symbology can be downloaded directly or installed via npm.

npm install symbology --save

3. Usage

3.1. Import the module

var symbology = require('symbology');

3.2. Struct

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'
};

3.3. Available functions

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.3.1. Render a base64 png:

createStream(Symbol, data, type)

Writes a base64 string to the output object in a property data.

ParameterTypeValues
SymbolStructStruct of symbology settings
dataStringDesired data to encode
Example
symbology
  .createStream(Symbol, '12345')
  .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==' 
}

3.3.2. Render a file:

createFile(Symbol, data)

Writes a stream in to the output object in a property data.

ParameterTypeValues
SymbolStructStruct of symbology settings
dataStringDesired data to encode
Example
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'
}

4. Available options (struct)

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.No#FFFFFF
backgroundColorHexadecimal numberBarcode background color.No#000000
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

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

To compile the latest, ensure you have node-pre-gyp installed. Then run:

npm run build

7.2. Testing

npm test

7.3. Packaging

npm run package-binary

7.4. Bugs

Replace report all bugs here.

7.5. Changelog

Available here.

8. Credits

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

9. License

MIT.

FAQs

Package last updated on 27 Jan 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc