Add typing for barcode

This commit is contained in:
Pascal Vomhoff
2015-11-01 19:48:02 +01:00
parent eb59a40d3c
commit 1c4e79f075
2 changed files with 47 additions and 0 deletions

22
barcode/barcode-tests.ts Normal file
View File

@@ -0,0 +1,22 @@
/// <reference path="barcode.d.ts" />
import barcode = require('barcode');
import path = require('path');
var code39 = barcode('code39', {
data: "it works",
width: 400,
height: 100,
});
code39.getStream(function (err, readStream) {
if (err) throw err;
// 'readStream' is an instance of ReadableStream
});
var outfile = path.join(__dirname, 'imgs', 'mycode.png');
code39.saveImage(outfile, function (err) {
if (err) throw err;
console.log('File has been written!');
});

25
barcode/barcode.d.ts vendored Normal file
View File

@@ -0,0 +1,25 @@
// Type definitions for barcode
// Project: https://github.com/samt/barcode
// Definitions by: Pascal Vomhoff <https://github.com/pvomhoff>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module "barcode" {
interface BarcodeOptions {
data:string|number;
width:number;
height:number;
}
interface BarcodeResult {
getStream(callback:(err:NodeJS.ErrnoException, stream:NodeJS.ReadableStream) => void):void;
saveImage(outputfilePath:string, callback:(err:NodeJS.ErrnoException) => void):void;
getBase64(callback:(err:NodeJS.ErrnoException, base64String:string) => void):void;
}
function barcode(type:string, options:BarcodeOptions):BarcodeResult;
export = barcode;
}