mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
bwip-js - Add Browser implementation of the BwipJs function (#37548)
* Add Browser implementation of the BwipJs function * Use $ExpectType in unit test for types
This commit is contained in:
parent
8266be6d79
commit
fea56cdd61
@ -37,3 +37,16 @@ bwipjs.toBuffer({
|
||||
// png.readUInt32BE(20) : PNG image height
|
||||
}
|
||||
});
|
||||
|
||||
// Browser canvas implementation
|
||||
const canvas = document.createElement('canvas') as HTMLCanvasElement;
|
||||
bwipjs(canvas, {
|
||||
bcid: 'qrcode',
|
||||
text: 'example',
|
||||
}, (err?: string | Error, cvs?: HTMLCanvasElement): void => {
|
||||
if (err) {
|
||||
err; // $ExpectType string | Error
|
||||
} else if (cvs) {
|
||||
cvs; // $ExpectType HTMLCanvasElement
|
||||
}
|
||||
});
|
||||
|
||||
18
types/bwip-js/index.d.ts
vendored
18
types/bwip-js/index.d.ts
vendored
@ -1,6 +1,7 @@
|
||||
// Type definitions for bwip-js 1.1.1
|
||||
// Type definitions for bwip-js 1.7.3
|
||||
// Project: https://github.com/metafloor/bwip-js
|
||||
// Definitions by: TANAKA Koichi <https://github.com/MugeSo>
|
||||
// Guillaume VanderEst <https://github.com/gvanderest>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
@ -80,4 +81,19 @@ declare namespace BwipJs {
|
||||
|
||||
declare function BwipJs(req: Request, res: Response, opts?:BwipJs.ToBufferOptions): void;
|
||||
|
||||
/**
|
||||
* The Browser version of the library's functionality, which makes use of an HTMLCanvasElement for rendering.
|
||||
* @param canvas ID string or HTML element of the canvas to render within
|
||||
* @param opts Options to use for rendering
|
||||
* @param callback Function to execute when rendering has completed or failed
|
||||
*/
|
||||
declare function BwipJs(
|
||||
canvas: string | HTMLCanvasElement,
|
||||
opts:BwipJs.ToBufferOptions,
|
||||
callback: (
|
||||
err: undefined | string | Error,
|
||||
canvas?: HTMLCanvasElement,
|
||||
) => void,
|
||||
): void;
|
||||
|
||||
export = BwipJs;
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
@ -20,4 +21,4 @@
|
||||
"index.d.ts",
|
||||
"bwip-js-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user