Skip to content

Commit

Permalink
v1.2.0: fixes rendering issues, file structure
Browse files Browse the repository at this point in the history
Reorganizes project to have separate source directory. Fixes missing
`outputType` parameter in `createStream()`. Adds `Output` enum. Updates
documentation. Fixes #5 and #9.
  • Loading branch information
jshor authored and Josh Shor committed Oct 29, 2018
1 parent afc78ad commit da1084e
Show file tree
Hide file tree
Showing 70 changed files with 565 additions and 447 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ coverage
npm-debug.log
node_modules
build
lib
/lib
*~
*.[ao]
*.swp
*.swo
*.DS_Store
.directory
*.png
!symbologyjs-logo.png
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
v1.2.0

- Reorganizes project to have separate source directory.
- Fixes missing `outputType` parameter in `createStream()`.
- Adds `Output` enum.
- Updates documentation.
- Fixes #5 and #9.

v1.0.8

- updates tests to latest sinon reqs
Expand Down
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)
Symbology.js - v1.1.0.
Copyright (c) 2017 Josh Shor.
Symbology.js - v1.2.0.
Copyright (c) 2018 Josh Shor.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ![Symbology.js](https://raw.githubusercontent.com/jshor/symbology/master/symbologyjs-logo.png) Symbology.js

### v1.1.0
### v1.2.0

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

Expand Down Expand Up @@ -77,24 +77,31 @@ Each function returns a promise that completes with an object containing the exi

### 3.3.1. Stream a barcode:

`createStream(Symbol, data)`
`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 | |
| `type` | `String` | `png`, `svg`, `eps` | `png` |
| Parameter | Type | Values | Default |
|--------------|----------|------------------------------|------------|
| `Symbol` | `Struct` | Struct of symbology settings | |
| `data` | `String` | Desired data to encode | |
| `outputType` | `String` | Output type | `PNG` |

#### Output Types

| Enum | Description |
|--------|--------------------------------------|
| `EPS` | Adobe encapsulated postscript vector |
| `SVG` | Scalable vector graphics |
| `PNG` | Portable network graphics |

#### Example

```javascript
symbology
.createStream(Symbol, '12345')
.createStream(Symbol, '12345', symbology.Output.PNG)
.then(function(data) {
console.log('Result: ', data);
}, function(err) {
Expand Down Expand Up @@ -158,8 +165,8 @@ A Symbol is a regular JavaScript object with the following available properties:
| 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 |
| 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` |
Expand Down
62 changes: 31 additions & 31 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@
{
"target_name": "<(module_name)",
"sources": [
"zint/2of5.c",
"zint/auspost.c",
"zint/aztec.c",
"zint/code.c",
"zint/code1.c",
"zint/code16k.c",
"zint/code49.c",
"zint/code128.c",
"zint/common.c",
"zint/composite.c",
"zint/dmatrix.c",
"zint/gridmtx.c",
"zint/gs1.c",
"zint/imail.c",
"zint/large.c",
"zint/library.c",
"zint/maxicode.c",
"zint/medical.c",
"zint/pdf417.c",
"zint/plessey.c",
"zint/png.c",
"zint/postal.c",
"zint/ps.c",
"zint/qr.c",
"zint/reedsol.c",
"zint/render.c",
"zint/rss.c",
"zint/svg.c",
"zint/telepen.c",
"zint/upcean.c",
"binding.cpp"
"src/lib/zint/2of5.c",
"src/lib/zint/auspost.c",
"src/lib/zint/aztec.c",
"src/lib/zint/code.c",
"src/lib/zint/code1.c",
"src/lib/zint/code16k.c",
"src/lib/zint/code49.c",
"src/lib/zint/code128.c",
"src/lib/zint/common.c",
"src/lib/zint/composite.c",
"src/lib/zint/dmatrix.c",
"src/lib/zint/gridmtx.c",
"src/lib/zint/gs1.c",
"src/lib/zint/imail.c",
"src/lib/zint/large.c",
"src/lib/zint/library.c",
"src/lib/zint/maxicode.c",
"src/lib/zint/medical.c",
"src/lib/zint/pdf417.c",
"src/lib/zint/plessey.c",
"src/lib/zint/png.c",
"src/lib/zint/postal.c",
"src/lib/zint/ps.c",
"src/lib/zint/qr.c",
"src/lib/zint/reedsol.c",
"src/lib/zint/render.c",
"src/lib/zint/rss.c",
"src/lib/zint/svg.c",
"src/lib/zint/telepen.c",
"src/lib/zint/upcean.c",
"src/lib/binding.cpp"
],
"libraries": ["-lpng"],
"include_dirs": [
Expand Down
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "symbology",
"version": "1.1.0",
"version": "1.2.0",
"description": "Generate 50+ different 1D or 2D barcodes in png, eps, or svg format.",
"keywords": [
"barcode",
Expand All @@ -20,16 +20,16 @@
},
"binary": {
"module_name": "symbology",
"module_path": "./lib/binding/{configuration}/{node_abi}-{platform}-{arch}/",
"module_path": "./lib/binding/{configuration}/",
"remote_path": "./{module_name}/v{version}/{configuration}/",
"package_name": "{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz",
"package_name": "{module_name}-v{version}.tar.gz",
"host": "https://symbologyjs.s3-us-west-1.amazonaws.com"
},
"dependencies": {
"nan": "2.x",
"pngjs": "3.3.0",
"node-gyp": "3.2.1",
"node-pre-gyp": "0.x",
"pngjs": "3.3.0",
"pngjs-image": "^0.11.6"
},
"devDependencies": {
Expand All @@ -46,12 +46,13 @@
"node-pre-gyp"
],
"scripts": {
"install": "./node_modules/.bin/node-pre-gyp install --fallback-to-build",
"test-travis": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec ./test/*",
"test": "./node_modules/mocha/bin/mocha ./test/*",
"start": "node ./foo.js",
"install": "node-pre-gyp install --fallback-to-build",
"test-travis": "./node_modules/istanbul/lib/cli.js cover _mocha -- -R spec ./src/**/*.test.js",
"test": "mocha ./test/*",
"prepublish": "npm ls",
"build": "./node_modules/.bin/node-pre-gyp build",
"package-binary": "./node_modules/.bin/node-pre-gyp build package",
"publish-binary": "./node_modules/.bin/node-pre-gyp publish"
"build": "node-pre-gyp build",
"package-binary": "node-pre-gyp build package",
"publish-binary": "node-pre-gyp publish"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ module.exports = function() {
}
}
return data;
};
};
File renamed without changes.
80 changes: 60 additions & 20 deletions test/index.js → src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ var chai = require('chai');
var sinon = require('sinon');
var mocha = require('mocha');
var fs = require('fs');
var symbology = require('../');
var regex = require('./regex');
var library = require('../');
var regex = require('./helpers/regex');
var createSymbology = require('./helpers/createSymbologyStub');
var expect = chai.expect;
var binary = require('node-pre-gyp');
var path = require('path');
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
var barnode = require(binding_path);
var createStream = require('./createStreamStub');
var binding_path = binary.find(path.resolve(path.join(__dirname,'../../package.json')));
var symbology = require(binding_path);

function getSymbol(obj) {
obj = obj || {};
return {
symbology: obj.symbology || symbology.Barcode.CODE128,
symbology: obj.symbology || library.Barcode.CODE128,
foregroundColor: obj.foregroundColor || 'fff000',
backgroundColor: obj.backgroundColor || '000000',
fileName: obj.fileName || 'out.png',
Expand All @@ -29,7 +29,8 @@ function getSymbol(obj) {

var noop = function() {};

describe('the barnode library', function() {
describe('the symbology library', function() {
var sandbox;

beforeEach(function() {
sandbox = sinon.sandbox.create();
Expand All @@ -42,8 +43,12 @@ describe('the barnode library', function() {
describe('the createFile function to create PNG files', function() {
var filePath = 'testfile.png';

beforeEach(function() {
sandbox.stub(symbology, 'createFile').callsFake(createSymbology);
});

it('should return a status code and a message', function() {
return symbology
return library
.createFile(getSymbol({fileName: filePath}), '54321')
.then(function(data) {
expect(data.code).to.be.a('number');
Expand All @@ -52,7 +57,7 @@ describe('the barnode library', function() {
});

it('should return a message and a nonzero status code when invalid', function() {
return symbology
return library
.createFile(getSymbol({
symbology: -1,
fileName: filePath
Expand All @@ -70,45 +75,80 @@ describe('the barnode library', function() {
describe('the createFile function to create SVG files', function() {
var filePath = 'testfile.svg';

beforeEach(function() {
sandbox.stub(symbology, 'createFile').callsFake(createSymbology);
});

it('should return a zero status code and render an SVG file', function() {
return symbology
.createFile(getSymbol({fileName: filePath}), '54321', 'svg')
return library
.createFile(getSymbol({fileName: filePath}), '54321')
.then(function(data) {
expect(data.code).to.be.a('number');
expect(data.message).to.be.a('string');
});
});

it('should render an SVG file with valid XML data', function() {
return symbology
.createFile(getSymbol({fileName: filePath}), '54321', 'svg')
return library
.createFile(getSymbol({fileName: filePath}), '54321')
.then(function(data) {
expect(data.code).to.be.a('number');
expect(data.message).to.be.a('string');
});
});
});


describe('the createStream function for png data', function() {
beforeEach(function() {
sandbox.stub(barnode, 'createStream').callsFake(createStream);
sandbox.stub(symbology, 'createStream').callsFake(createSymbology);
});

it('should return an object with status code and base64 png data', function() {
return symbology
it('should return an object with status code and svg data', function() {
return library
.createStream(getSymbol(), '12345', library.Output.SVG)
.then(function(data) {
expect(data.code).to.be.a('number');
expect(data.message).to.be.a('string');
// expect(data.data).to.match(regex.svg);
});
});
});

describe('the createStream function when `outputType` is not specified', function() {
beforeEach(function() {
sandbox.stub(symbology, 'createStream').callsFake(createSymbology);
});

it('should return default to rendering a png', function () {
return library
.createStream(getSymbol(), '12345')
.then(function(data) {
expect(data.code).to.be.a('number');
expect(data.message).to.be.a('string');
expect(data.data).to.match(regex.base64);
});
});
});

describe('the createStream function for png data', function() {
beforeEach(function() {
sandbox.stub(symbology, 'createStream').callsFake(createSymbology);
});

it('should not stream base64 png data if input is invalid', function() {
return symbology
.createStream(getSymbol({symbology: -1}), '12345')
it('should return an object with status code and base64 png data', function() {
return library
.createStream(getSymbol(), '12345', library.Output.PNG)
.then(function(data) {
expect(data.code).to.be.a('number');
expect(data.message).to.be.a('string');
expect(data.data).to.match(regex.base64);
});
});

it('should reject if input is invalid', function() {
return library
.createStream(getSymbol({symbology: -1}), '12345', library.Output.PNG)
.catch(function(data) {
expect(data.code).to.be.a('number');
expect(data.code).to.not.equal(0);
expect(data.message).to.not.be.null;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/enums/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
PNG: 'png',
SVG: 'svg',
EPS: 'eps'
}

0 comments on commit da1084e

Please sign in to comment.