Comparing version 2.1.2 to 2.1.4
@@ -0,1 +1,10 @@ | ||
## [2.1.4](https://github.com/jshor/symbology/compare/v2.1.2...v2.1.4) (2021-04-08) | ||
### Bug Fixes | ||
* **build:** fixes compatibility of module exports and npm ([45ebe3b](https://github.com/jshor/symbology/commit/45ebe3b57fd7e187d5ba624525063938f5cc490a)) | ||
## [2.1.2](https://github.com/jshor/symbology/compare/v2.1.1...v2.1.2) (2021-04-04) | ||
@@ -2,0 +11,0 @@ |
{ | ||
"name": "symbology", | ||
"version": "2.1.2", | ||
"version": "2.1.4", | ||
"description": "🔖 Generates 1D, 2D, and composite barcodes in png, svg, or eps formats. Supports 50+ symbologies.", | ||
"scripts": { | ||
"commit": "yarn git-cz", | ||
"commit": "git-cz", | ||
"release": "standard-version", | ||
"lint": "yarn eslint ./src", | ||
"lint": "eslint ./src", | ||
"test:e2e": "rimraf test/e2e/__rendered__/* && jest test/e2e", | ||
"test:unit": "jest src --collectCoverage true", | ||
"test": "yarn test:unit && yarn test:e2e", | ||
"build": "yarn tsc && npm run binary:rebuild", | ||
"test": "npm run test:unit && npm run test:e2e", | ||
"build": "tsc && npm run binary:rebuild", | ||
"binary:install": "node-pre-gyp install --fallback-to-build", | ||
@@ -82,3 +82,3 @@ "binary:rebuild": "node-pre-gyp rebuild package", | ||
"bundledDependencies": [ | ||
"node-pre-gyp" | ||
"@mapbox/node-pre-gyp" | ||
], | ||
@@ -85,0 +85,0 @@ "husky": { |
111
src/index.ts
@@ -1,4 +0,1 @@ | ||
import fs from 'fs' | ||
import binary from './lib/binary' | ||
import png from './lib/png' | ||
import SymbologyType from './types/enums/SymbologyType' | ||
@@ -9,103 +6,13 @@ import DataMatrix from './types/enums/DataMatrix' | ||
import OutputType from './types/enums/OutputType' | ||
import SymbologyConfig from './types/SymbologyConfig' | ||
import SymbologyResult from './types/SymbologyResult' | ||
import { createStream, createFile } from './main' | ||
/** | ||
* Default Symbology config, populated with default values | ||
*/ | ||
const defaultConfig: SymbologyConfig = { | ||
symbology: 20, | ||
height: 50, | ||
whitespaceWidth: 0, | ||
borderWidth: 0, | ||
outputOptions: OutputOption.BARCODE_NO_ASCII, | ||
foregroundColor: '000000FF', | ||
backgroundColor: 'FFFFFFFF', | ||
scale: 1.0, | ||
option1: -1, | ||
option2: -1, | ||
option3: -1, | ||
showHumanReadableText: true, | ||
encoding: EncodingMode.DATA_MODE, | ||
eci: 0, | ||
primary: '', | ||
rotation: 0, | ||
dotSize: 0.8 | ||
} | ||
export { default as SymbologyType } from './types/enums/SymbologyType' | ||
export { default as DataMatrix } from './types/enums/DataMatrix' | ||
export { default as EncodingMode } from './types/enums/EncodingMode' | ||
export { default as OutputOption } from './types/enums/OutputOption' | ||
export { default as OutputType } from './types/enums/OutputType' | ||
export { default as SymbologyConfig } from './types/SymbologyConfig' | ||
export { default as SymbologyResult } from './types/SymbologyResult' | ||
export { createStream, createFile } from './main' | ||
/** | ||
* Renders a symbology image as a string in SVG, EPS, or base64-encoded PNG format. | ||
* | ||
* @param {SymbologyConfig} config - symbology configuration | ||
* @param {string} barcodeData - data to encode | ||
* @param {OutputType} outputType - `png`, `eps`, or `svg`. | ||
* @returns {Promise<SymbologyResult>} object with resulting props (see docs) | ||
*/ | ||
async function createStream (config: SymbologyConfig, barcodeData: string, outputType: OutputType = OutputType.PNG): Promise<SymbologyResult> { | ||
const symbol: SymbologyConfig = { | ||
...defaultConfig, | ||
...config, | ||
fileName: `out.${outputType}` | ||
} | ||
const res = await binary.invoke(symbol, barcodeData, outputType) | ||
if (outputType === OutputType.PNG) { | ||
// write the bitmap to a base64-encoded PNG string | ||
const image = png.render(res.bitmap, res.width, res.height, symbol.backgroundColor, symbol.foregroundColor) | ||
const base64Data = await png.blobToBase64(image) | ||
return { | ||
data: base64Data, | ||
width: res.width, | ||
height: res.height, | ||
message: res.message | ||
} | ||
} | ||
return { | ||
data: res.encodedData, | ||
width: res.width, | ||
height: res.height, | ||
message: res.message | ||
} | ||
} | ||
/** | ||
* Creates a symbology image file of a PNG, SVG or EPS file in the specified `fileName` path. | ||
* | ||
* @param {SymbologyConfig} config - symbology configuration | ||
* @param {string} barcodeData - data to encode | ||
* @returns {Promise<SymbologyResult>} object with resulting props (see docs) | ||
*/ | ||
async function createFile (config: SymbologyConfig, barcodeData: string): Promise<SymbologyResult> { | ||
const symbol: SymbologyConfig = { | ||
...defaultConfig, | ||
...config | ||
} | ||
if (!symbol.fileName) { | ||
return Promise.reject('fileName is required.') | ||
} | ||
const outputType = binary.getOutputType(symbol.fileName) | ||
const res = await binary.invoke(symbol, barcodeData, outputType) | ||
if (outputType === OutputType.PNG) { | ||
// write the bitmap to a PNG image file | ||
const image = png.render(res.bitmap, res.width, res.height, symbol.backgroundColor, symbol.foregroundColor) | ||
const buffer = png.getBuffer(image) | ||
fs.writeFileSync(symbol.fileName, buffer) | ||
} else { | ||
// write SVG or EPS to a file | ||
fs.writeFileSync(symbol.fileName, res.encodedData) | ||
} | ||
return { | ||
width: res.width, | ||
height: res.height, | ||
message: res.message | ||
} | ||
} | ||
export default { | ||
@@ -112,0 +19,0 @@ DataMatrix, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97375
32
1251