Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exports type definitions #234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { Chunks } from "./decoder/decodeData";
import { Point } from "./locator";
export interface QRCode {
binaryData: number[];
data: string;
chunks: Chunks;
version: number;
location: {
topRightCorner: Point;
topLeftCorner: Point;
bottomRightCorner: Point;
bottomLeftCorner: Point;
topRightFinderPattern: Point;
topLeftFinderPattern: Point;
bottomLeftFinderPattern: Point;
bottomRightAlignmentPattern?: Point;
};
declare namespace jsQR {
interface QRCode {
binaryData: number[];
data: string;
chunks: Chunks;
version: number;
location: {
topRightCorner: Point;
topLeftCorner: Point;
bottomRightCorner: Point;
bottomLeftCorner: Point;
topRightFinderPattern: Point;
topLeftFinderPattern: Point;
bottomLeftFinderPattern: Point;
bottomRightAlignmentPattern?: Point;
};
}
interface Options {
inversionAttempts?: "dontInvert" | "onlyInvert" | "attemptBoth" | "invertFirst";
}
}
export interface Options {
inversionAttempts?: "dontInvert" | "onlyInvert" | "attemptBoth" | "invertFirst";
}
declare function jsQR(data: Uint8ClampedArray, width: number, height: number, providedOptions?: Options): QRCode | null;
export default jsQR;
declare function jsQR(data: Uint8ClampedArray, width: number, height: number, providedOptions?: jsQR.Options): jsQR.QRCode | null;
export = jsQR;
3 changes: 1 addition & 2 deletions dist/jsQR.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ exports.default = GenericGFPoly;

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var binarizer_1 = __webpack_require__(4);
var decoder_1 = __webpack_require__(5);
var extractor_1 = __webpack_require__(11);
Expand Down Expand Up @@ -377,7 +376,7 @@ function jsQR(data, width, height, providedOptions) {
return result;
}
jsQR.default = jsQR;
exports.default = jsQR;
module.exports = jsQR;


/***/ }),
Expand Down
3 changes: 1 addition & 2 deletions docs/jsQR.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ exports.default = GenericGFPoly;

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var binarizer_1 = __webpack_require__(4);
var decoder_1 = __webpack_require__(5);
var extractor_1 = __webpack_require__(11);
Expand Down Expand Up @@ -377,7 +376,7 @@ function jsQR(data, width, height, providedOptions) {
return result;
}
jsQR.default = jsQR;
exports.default = jsQR;
module.exports = jsQR;


/***/ }),
Expand Down
48 changes: 25 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,32 @@ import { Version } from "./decoder/version";
import {extract} from "./extractor";
import {locate, Point} from "./locator";

export interface QRCode {
binaryData: number[];
data: string;
chunks: Chunks;
version: number;
location: {
topRightCorner: Point;
topLeftCorner: Point;
bottomRightCorner: Point;
bottomLeftCorner: Point;
declare namespace jsQR {
interface QRCode {
binaryData: number[];
data: string;
chunks: Chunks;
version: number;
location: {
topRightCorner: Point;
topLeftCorner: Point;
bottomRightCorner: Point;
bottomLeftCorner: Point;

topRightFinderPattern: Point;
topLeftFinderPattern: Point;
bottomLeftFinderPattern: Point;
topRightFinderPattern: Point;
topLeftFinderPattern: Point;
bottomLeftFinderPattern: Point;

bottomRightAlignmentPattern?: Point;
};
bottomRightAlignmentPattern?: Point;
};
}

interface Options {
inversionAttempts?: "dontInvert" | "onlyInvert" | "attemptBoth" | "invertFirst";
}
}

function scan(matrix: BitMatrix): QRCode | null {
function scan(matrix: BitMatrix): jsQR.QRCode | null {
const locations = locate(matrix);
if (!locations) {
return null;
Expand Down Expand Up @@ -58,15 +64,11 @@ function scan(matrix: BitMatrix): QRCode | null {
return null;
}

export interface Options {
inversionAttempts?: "dontInvert" | "onlyInvert" | "attemptBoth" | "invertFirst";
}

const defaultOptions: Options = {
const defaultOptions: jsQR.Options = {
inversionAttempts: "attemptBoth",
};

function jsQR(data: Uint8ClampedArray, width: number, height: number, providedOptions: Options = {}): QRCode | null {
function jsQR(data: Uint8ClampedArray, width: number, height: number, providedOptions: jsQR.Options = {}): jsQR.QRCode | null {

const options = defaultOptions;
Object.keys(options || {}).forEach(opt => { // Sad implementation of Object.assign since we target es5 not es6
Expand All @@ -84,4 +86,4 @@ function jsQR(data: Uint8ClampedArray, width: number, height: number, providedOp
}

(jsQR as any).default = jsQR;
export default jsQR;
export = jsQR;
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"arrow-parens": false,
"max-line-length": [true, 140],
"interface-name": false,
"no-namespace": false,
"object-literal-sort-keys": false
},
"rulesDirectory": []
Expand Down