Skip to content

Commit 9f37c7e

Browse files
committed
Release 4.5 - introducing platform-specific packages
1 parent bc71874 commit 9f37c7e

14 files changed

+63
-50
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
bwip-js : Barcode Writer in Pure JavaScript
22

3-
Copyright (c) 2011-2019 Mark Warren
3+
Copyright (c) 2011-2024 Mark Warren
44

55
The MIT License
66

README.md

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
<a href="http://metafloor.github.io/bwip-js"><img alt="bwip-js" align="right" src="http://metafloor.github.io/bwip-js/images/bwip-js.png"></a>
55
bwip-js is a translation to native JavaScript of the amazing code provided in [Barcode Writer in Pure PostScript](https://github.com/bwipp/postscriptbarcode). The translated code can run on any modern browser or JavaScript-based server framework.
66

7-
The software has encoding modules for over 100 different barcode types and standards.
7+
The library has encoding modules for over 100 different barcode types and standards.
88
All linear and two-dimensional barcodes in common use (and many uncommon
99
ones) are available. An exhaustive list of supported barcode types can be
10-
found at the end of this document. Barcode images are generated as png (node-js) or to a canvas (browser)
11-
or as SVG (all platforms).
10+
found at the end of this document. Barcodes are generated as PNG images (node-js and react-native)
11+
or to a canvas (browser) or as SVG (all platforms).
1212

13-
> Version 4 has been released. The primary enhancement is built-in support for generating barcodes in SVG. You can read about the changes here: https://github.com/metafloor/bwip-js/discussions/299
13+
> As of version 4.5, bwip-js has been partitioned into four platform-specific packages plus the cross-platform main package. The sub-packages are currently experimental but are the solution to current build chains not properly supporting the `exports` map in `package.json`. Please use them and report any issues you find.
1414
1515
## Status
1616

17-
* Current bwip-js version is 4.4.0 (2024-06-18)
17+
* Current bwip-js version is 4.5.0 (2024-07-03)
1818
* Current BWIPP version is 2024-06-18
19-
* Node.js compatibility: 0.12+
19+
* Node.js compatibility: 6.0
2020
* Browser compatibility: Edge, Firefox, Chrome
2121

2222
## Supported Platforms
@@ -46,17 +46,33 @@ or as SVG (all platforms).
4646

4747
## Installation
4848

49-
You can download the latest npm module using:
49+
The bwip-js package has been partitioned into four platform-specific packages plus the main cross-platform package. If you install the main package and cannot get its exports to work with your build stack, try installing a platform-specific package. The platform-specific packages are ES modules only, so you will need a modern build environment. The exception is the node package, which also contains a `require()` compatible export.
50+
51+
52+
You can download the main package using:
5053

5154
```
5255
npm install bwip-js
5356
```
5457

55-
Or the latest code from github:
58+
Or one of the platform-specific packages using:
59+
60+
```
61+
npm install @bwip-js/node
62+
npm install @bwip-js/browser
63+
npm install @bwip-js/react-native
64+
npm install @bwip-js/generic
65+
```
66+
67+
The node, browser and react-native packages include both an image rending interface (`toCanvas()` on the browser, `toBuffer()` on node, `toDataURL()` on react-native), plus the SVG and custom drawing context interfaces.
68+
69+
The generic package contains only exports that run on any platform, namely the SVG and custom drawing context interfaces.
70+
71+
The latest code can be obtained from github:
5672

5773
https://github.com/metafloor/bwip-js
5874

59-
(The bwip-js master branch and the npm version are kept sync'd.)
75+
The bwip-js branches and the npm versions are automatically sync'd with each release. The main package is located under the master branch; the platform-specific packages are maintained under their like-named branches.
6076

6177
## Online Barcode Generator
6278

@@ -116,7 +132,7 @@ to determine what options are available for each barcode type.
116132

117133
All of the BWIPP color options (e.g. `barcolor`, `textcolor`, `bordercolor`) can be specified using either RGB, RRGGBB or CCMMYYKK formats or the CSS-style #RGB and #RRGGBB formats.
118134

119-
Note that bwip-js normalizes the BWIPP `width` and `height` options to always be in millimeters.
135+
Note that bwip-js normalizes the BWIPP `width` and `height` options to be in millimeters.
120136
The resulting images are rendered at 72 dpi. To convert to pixels, use a factor of 2.835 px/mm
121137
(72 dpi / 25.4 mm/in). The bwip-js scale options multiply the `width`, `height`, and `padding`.
122138

@@ -157,10 +173,10 @@ module width (scale) of the rendered barcode.
157173
<a name="browser-usage"></a>
158174
## Browser Usage
159175

160-
To use within a browser, add the following to the head of your page:
176+
To use in a browser without a bundler, add the following to the head of your page:
161177

162178
```
163-
<script type="text/javascript" src="file-or-url-path-to/bwip-js/dist/bwip-js-min.js"></script>
179+
<script type="text/javascript" src="url-path-to/bwip-js/dist/bwip-js-min.js"></script>
164180
```
165181

166182
While developing your project, you may want to use `dist/bwip-js.js` to get better stack
@@ -194,7 +210,7 @@ The `bwipjs.toCanvas()` method takes two parameters:
194210
barcode image.
195211
* A bwip-js/BWIPP options object.
196212

197-
On return from `toCanvas()`, the barcode image will have been fully rendered to the canvas.
213+
On return from `toCanvas()`, the barcode image will be fully rendered to the canvas.
198214

199215
If you would prefer to display the barcode using an `<img>` tag or with CSS `background-image`,
200216
pass in a detached or hidden canvas, and use the canvas method
@@ -217,7 +233,9 @@ try {
217233
The ESM provides the same API as the standard browser module using:
218234

219235
```javascript
220-
import bwipjs from 'bwip-js';
236+
import bwipjs from 'bwip-js'; // If using the main package import
237+
// or
238+
import bwipjs from '@bwip-js/browser'; // Platform-specific package import
221239

222240
// ... identical bwipjs.toCanvas() interface as above ...
223241
```
@@ -230,6 +248,8 @@ underscores `_`. For example, to import the `gs1-128` encoder, you would use:
230248

231249
```javascript
232250
import { gs1_128 } from 'bwip-js';
251+
// or
252+
import { gs1_128 } from '@bwipjs/browser';
233253

234254
try {
235255
gs1_128('my-canvas', options);
@@ -333,7 +353,9 @@ bwipjs.toBuffer({
333353
The ESM provides the same API as `require('bwip-js')` using:
334354

335355
```javascript
336-
import bwipjs from 'bwip-js';
356+
import bwipjs from 'bwip-js'; // If using the main package import
357+
// or
358+
import bwipjs from '@bwip-js/node'; // Platform-specific package import
337359

338360
// ... identical to the examples above ...
339361
```
@@ -344,6 +366,8 @@ The exported names are the same as the `bcid` names, with the caveat that dashes
344366

345367
```javascript
346368
import { gs1_128 } from 'bwip-js';
369+
// or
370+
import { gs1_128 } from '@bwip-js/node';
347371

348372
try {
349373
let buf = await gs1_128(options);
@@ -402,6 +426,8 @@ you need, along with the built-in SVG drawing interface.
402426

403427
```javascript
404428
import { qrcode, drawingSVG } from 'bwip-js';
429+
// or <platform> one of : browser, node, react-native, generic
430+
import { qrcode, drawingSVG } from '@bwip-js/<platform>';
405431

406432
// drawingSVG() returns a bwip-js drawing object.
407433
let svg = qrcode(options, drawingSVG());
@@ -417,7 +443,9 @@ It is based on the default `App.js` file generated by `create-react-app`.
417443
import React, { Component } from 'react';
418444
import logo from './logo.svg';
419445
import './App.css';
420-
import bwipjs from 'bwip-js';
446+
import bwipjs from 'bwip-js'; // If using the main package import
447+
// or
448+
import bwipjs from '@bwip-js/browser'; // Plaform-specific package import
421449

422450
class App extends Component {
423451
componentDidMount() {
@@ -457,15 +485,7 @@ See the ES6 Browser Module Usage section for details on importing encoders direc
457485
<a name="react-native"></a>
458486
## React Native
459487

460-
> Note: The react-native module requires an external dependency to polyfill
461-
> missing nodejs built-ins `zlib` and `Buffer`.
462-
>
463-
> You _must_ manually add it to your project. The dependency will not
464-
> be included in bwip-js as it is only needed for react-native. To install:
465-
466-
```
467-
npm install react-zlib-js --save
468-
```
488+
React-native has considerable legacy build environments that are not compatible with the modern `exports` map in `package.json`. For this reason, it is recommended to install the react-native package `@bwip-js/react-native`.
469489

470490
The react-native module provides a specialized version of the `toBuffer()` method,
471491
called `toDataURL()`. The return value is an object with the following properties:
@@ -478,8 +498,7 @@ The returned object is designed to be used with the `<Image>` component:
478498

479499
```javascript
480500
import React from 'react';
481-
import 'react-zlib-js'; // side effects only
482-
import bwipjs from 'bwip-js';
501+
import bwipjs from '@bwip-js/react-native';
483502

484503
const BarCode = (options) => {
485504
let img = null;
@@ -502,7 +521,7 @@ The bwip-js exports also facilitate bundler tree-shaking by providing the indivi
502521
The exported names are the same as the `bcid` names, with the caveat that dashes `-` are replaced with underscores `_`. For example, to import the `gs1-128` encoder, you would use:
503522

504523
```javascript
505-
import { gs1_128 } from 'bwip-js';
524+
import { gs1_128 } from '@bwip-js/react-native';
506525

507526
try {
508527
let buf = await gs1_128(options);
@@ -516,15 +535,9 @@ When named encoders are called, the `bcid` value in the options object is ignore
516535
<a name="electron-example"></a>
517536
## Electron Example
518537

519-
There have been some changes to the Electron bundler, and it may pull in either the
520-
nodejs or browser module, depending on your version of Electron. The example below
521-
assumes the nodejs module.
522-
523-
If you try this example and get the error `bwipjs.toBuffer is not a function`, the
524-
Electron bundler grabbed the browser module. See the [Browser Usage](#browser-usage)
525-
section above and draw to a canvas instead.
538+
With electron, you have the choice to use either the node-specific or browser-specific package. It is not recommended to use the main bwip-js package as developers have reported issues with how the bundler interacts with the package exports.
526539

527-
This is an example `index.html` file for a basic, single window app:
540+
This is an example `index.html` file for a basic, single window app, using the node-js package:
528541

529542
```html
530543
<!DOCTYPE html>
@@ -544,7 +557,7 @@ This is an example `index.html` file for a basic, single window app:
544557
</body>
545558

546559
<script>
547-
var bwipjs = require('bwip-js');
560+
var bwipjs = require('@bwip-js/node');
548561
bwipjs.toBuffer({ bcid:'qrcode', text:'0123456789' }, function (err, png) {
549562
if (err) {
550563
document.getElementById('output').textContent = err;

dist/bwip-js-gen.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for bwip-js 4.4.0 (2024-06-18)
1+
// Type definitions for bwip-js 4.5.0 (2024-07-03)
22
//
33
// THIS DEFINITION FILE IS MACHINE GENERATED - DO NOT EDIT
44
//

dist/bwip-js-gen.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import { bwipp_auspost,bwipp_azteccode,bwipp_azteccodecompact,bwipp_aztecrune,bwipp_bc412,bwipp_channelcode,bwipp_codablockf,bwipp_code11,bwipp_code128,bwipp_code16k,bwipp_code2of5,bwipp_code32,bwipp_code39,bwipp_code39ext,bwipp_code49,bwipp_code93,bwipp_code93ext,bwipp_codeone,bwipp_coop2of5,bwipp_daft,bwipp_databarexpanded,bwipp_databarexpandedcomposite,bwipp_databarexpandedstacked,bwipp_databarexpandedstackedcomposite,bwipp_databarlimited,bwipp_databarlimitedcomposite,bwipp_databaromni,bwipp_databaromnicomposite,bwipp_databarstacked,bwipp_databarstackedcomposite,bwipp_databarstackedomni,bwipp_databarstackedomnicomposite,bwipp_databartruncated,bwipp_databartruncatedcomposite,bwipp_datalogic2of5,bwipp_datamatrix,bwipp_datamatrixrectangular,bwipp_datamatrixrectangularextension,bwipp_dotcode,bwipp_ean13,bwipp_ean13composite,bwipp_ean14,bwipp_ean2,bwipp_ean5,bwipp_ean8,bwipp_ean8composite,bwipp_flattermarken,bwipp_gs1_128,bwipp_gs1_128composite,bwipp_gs1_cc,bwipp_gs1datamatrix,bwipp_gs1datamatrixrectangular,bwipp_gs1dldatamatrix,bwipp_gs1dlqrcode,bwipp_gs1dotcode,bwipp_gs1northamericancoupon,bwipp_gs1qrcode,bwipp_hanxin,bwipp_hibcazteccode,bwipp_hibccodablockf,bwipp_hibccode128,bwipp_hibccode39,bwipp_hibcdatamatrix,bwipp_hibcdatamatrixrectangular,bwipp_hibcmicropdf417,bwipp_hibcpdf417,bwipp_hibcqrcode,bwipp_iata2of5,bwipp_identcode,bwipp_industrial2of5,bwipp_interleaved2of5,bwipp_isbn,bwipp_ismn,bwipp_issn,bwipp_itf14,bwipp_jabcode,bwipp_japanpost,bwipp_kix,bwipp_leitcode,bwipp_mailmark,bwipp_mands,bwipp_matrix2of5,bwipp_maxicode,bwipp_micropdf417,bwipp_microqrcode,bwipp_msi,bwipp_onecode,bwipp_pdf417,bwipp_pdf417compact,bwipp_pharmacode,bwipp_pharmacode2,bwipp_planet,bwipp_plessey,bwipp_posicode,bwipp_postnet,bwipp_pzn,bwipp_qrcode,bwipp_rationalizedCodabar,bwipp_raw,bwipp_rectangularmicroqrcode,bwipp_royalmail,bwipp_sscc18,bwipp_swissqrcode,bwipp_symbol,bwipp_telepen,bwipp_telepennumeric,bwipp_ultracode,bwipp_upca,bwipp_upcacomposite,bwipp_upce,bwipp_upcecomposite,bwipp_lookup,bwipp_encode,BWIPP_VERSION } from './bwipp.mjs';
3434

3535
// exports.js
36-
const BWIPJS_VERSION = '4.4.0 (2024-06-18)';
36+
const BWIPJS_VERSION = '4.5.0 (2024-07-03)';
3737

3838

3939
// bwipjs.toSVG(options)

dist/bwip-js-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/bwip-js-node.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for bwip-js 4.4.0 (2024-06-18)
1+
// Type definitions for bwip-js 4.5.0 (2024-07-03)
22
//
33
// THIS DEFINITION FILE IS MACHINE GENERATED - DO NOT EDIT
44
//

dist/bwip-js-node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333

3434
// exports.js
35-
const BWIPJS_VERSION = '4.4.0 (2024-06-18)';
35+
const BWIPJS_VERSION = '4.5.0 (2024-07-03)';
3636

3737
var url = require('url');
3838
var PNG_ZLIB = require('zlib');

dist/bwip-js-node.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import { bwipp_auspost,bwipp_azteccode,bwipp_azteccodecompact,bwipp_aztecrune,bwipp_bc412,bwipp_channelcode,bwipp_codablockf,bwipp_code11,bwipp_code128,bwipp_code16k,bwipp_code2of5,bwipp_code32,bwipp_code39,bwipp_code39ext,bwipp_code49,bwipp_code93,bwipp_code93ext,bwipp_codeone,bwipp_coop2of5,bwipp_daft,bwipp_databarexpanded,bwipp_databarexpandedcomposite,bwipp_databarexpandedstacked,bwipp_databarexpandedstackedcomposite,bwipp_databarlimited,bwipp_databarlimitedcomposite,bwipp_databaromni,bwipp_databaromnicomposite,bwipp_databarstacked,bwipp_databarstackedcomposite,bwipp_databarstackedomni,bwipp_databarstackedomnicomposite,bwipp_databartruncated,bwipp_databartruncatedcomposite,bwipp_datalogic2of5,bwipp_datamatrix,bwipp_datamatrixrectangular,bwipp_datamatrixrectangularextension,bwipp_dotcode,bwipp_ean13,bwipp_ean13composite,bwipp_ean14,bwipp_ean2,bwipp_ean5,bwipp_ean8,bwipp_ean8composite,bwipp_flattermarken,bwipp_gs1_128,bwipp_gs1_128composite,bwipp_gs1_cc,bwipp_gs1datamatrix,bwipp_gs1datamatrixrectangular,bwipp_gs1dldatamatrix,bwipp_gs1dlqrcode,bwipp_gs1dotcode,bwipp_gs1northamericancoupon,bwipp_gs1qrcode,bwipp_hanxin,bwipp_hibcazteccode,bwipp_hibccodablockf,bwipp_hibccode128,bwipp_hibccode39,bwipp_hibcdatamatrix,bwipp_hibcdatamatrixrectangular,bwipp_hibcmicropdf417,bwipp_hibcpdf417,bwipp_hibcqrcode,bwipp_iata2of5,bwipp_identcode,bwipp_industrial2of5,bwipp_interleaved2of5,bwipp_isbn,bwipp_ismn,bwipp_issn,bwipp_itf14,bwipp_jabcode,bwipp_japanpost,bwipp_kix,bwipp_leitcode,bwipp_mailmark,bwipp_mands,bwipp_matrix2of5,bwipp_maxicode,bwipp_micropdf417,bwipp_microqrcode,bwipp_msi,bwipp_onecode,bwipp_pdf417,bwipp_pdf417compact,bwipp_pharmacode,bwipp_pharmacode2,bwipp_planet,bwipp_plessey,bwipp_posicode,bwipp_postnet,bwipp_pzn,bwipp_qrcode,bwipp_rationalizedCodabar,bwipp_raw,bwipp_rectangularmicroqrcode,bwipp_royalmail,bwipp_sscc18,bwipp_swissqrcode,bwipp_symbol,bwipp_telepen,bwipp_telepennumeric,bwipp_ultracode,bwipp_upca,bwipp_upcacomposite,bwipp_upce,bwipp_upcecomposite,bwipp_lookup,bwipp_encode,BWIPP_VERSION } from './bwipp.mjs';
3434

3535
// exports.js
36-
const BWIPJS_VERSION = '4.4.0 (2024-06-18)';
36+
const BWIPJS_VERSION = '4.5.0 (2024-07-03)';
3737

3838
import url from 'url';
3939
import PNG_ZLIB from 'zlib';

dist/bwip-js-rn.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for bwip-js 4.4.0 (2024-06-18)
1+
// Type definitions for bwip-js 4.5.0 (2024-07-03)
22
//
33
// THIS DEFINITION FILE IS MACHINE GENERATED - DO NOT EDIT
44
//

dist/bwip-js-rn.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import { bwipp_auspost,bwipp_azteccode,bwipp_azteccodecompact,bwipp_aztecrune,bwipp_bc412,bwipp_channelcode,bwipp_codablockf,bwipp_code11,bwipp_code128,bwipp_code16k,bwipp_code2of5,bwipp_code32,bwipp_code39,bwipp_code39ext,bwipp_code49,bwipp_code93,bwipp_code93ext,bwipp_codeone,bwipp_coop2of5,bwipp_daft,bwipp_databarexpanded,bwipp_databarexpandedcomposite,bwipp_databarexpandedstacked,bwipp_databarexpandedstackedcomposite,bwipp_databarlimited,bwipp_databarlimitedcomposite,bwipp_databaromni,bwipp_databaromnicomposite,bwipp_databarstacked,bwipp_databarstackedcomposite,bwipp_databarstackedomni,bwipp_databarstackedomnicomposite,bwipp_databartruncated,bwipp_databartruncatedcomposite,bwipp_datalogic2of5,bwipp_datamatrix,bwipp_datamatrixrectangular,bwipp_datamatrixrectangularextension,bwipp_dotcode,bwipp_ean13,bwipp_ean13composite,bwipp_ean14,bwipp_ean2,bwipp_ean5,bwipp_ean8,bwipp_ean8composite,bwipp_flattermarken,bwipp_gs1_128,bwipp_gs1_128composite,bwipp_gs1_cc,bwipp_gs1datamatrix,bwipp_gs1datamatrixrectangular,bwipp_gs1dldatamatrix,bwipp_gs1dlqrcode,bwipp_gs1dotcode,bwipp_gs1northamericancoupon,bwipp_gs1qrcode,bwipp_hanxin,bwipp_hibcazteccode,bwipp_hibccodablockf,bwipp_hibccode128,bwipp_hibccode39,bwipp_hibcdatamatrix,bwipp_hibcdatamatrixrectangular,bwipp_hibcmicropdf417,bwipp_hibcpdf417,bwipp_hibcqrcode,bwipp_iata2of5,bwipp_identcode,bwipp_industrial2of5,bwipp_interleaved2of5,bwipp_isbn,bwipp_ismn,bwipp_issn,bwipp_itf14,bwipp_jabcode,bwipp_japanpost,bwipp_kix,bwipp_leitcode,bwipp_mailmark,bwipp_mands,bwipp_matrix2of5,bwipp_maxicode,bwipp_micropdf417,bwipp_microqrcode,bwipp_msi,bwipp_onecode,bwipp_pdf417,bwipp_pdf417compact,bwipp_pharmacode,bwipp_pharmacode2,bwipp_planet,bwipp_plessey,bwipp_posicode,bwipp_postnet,bwipp_pzn,bwipp_qrcode,bwipp_rationalizedCodabar,bwipp_raw,bwipp_rectangularmicroqrcode,bwipp_royalmail,bwipp_sscc18,bwipp_swissqrcode,bwipp_symbol,bwipp_telepen,bwipp_telepennumeric,bwipp_ultracode,bwipp_upca,bwipp_upcacomposite,bwipp_upce,bwipp_upcecomposite,bwipp_lookup,bwipp_encode,BWIPP_VERSION } from './bwipp.mjs';
3434

3535
// exports.js
36-
const BWIPJS_VERSION = '4.4.0 (2024-06-18)';
36+
const BWIPJS_VERSION = '4.5.0 (2024-07-03)';
3737

3838
import PNG_ZLIB from 'react-zlib-js';
3939
import Buffer from 'react-zlib-js/buffer.js';

dist/bwip-js.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for bwip-js 4.4.0 (2024-06-18)
1+
// Type definitions for bwip-js 4.5.0 (2024-07-03)
22
//
33
// THIS DEFINITION FILE IS MACHINE GENERATED - DO NOT EDIT
44
//

dist/bwip-js.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
}(typeof self !== 'undefined' ? self : this, function () {
4242

4343
// exports.js
44-
const BWIPJS_VERSION = '4.4.0 (2024-06-18)';
44+
const BWIPJS_VERSION = '4.5.0 (2024-07-03)';
4545

4646
// bwipjs.toCanvas(canvas, options)
4747
// bwipjs.toCanvas(options, canvas)

0 commit comments

Comments
 (0)