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 options merge #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ const defaultOptions: Options = {
inversionAttempts: "attemptBoth",
};

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

const options = defaultOptions;
Object.keys(options || {}).forEach(opt => { // Sad implementation of Object.assign since we target es5 not es6
(options as any)[opt] = (providedOptions as any)[opt] || (options as any)[opt];
function mergeObject(target: any, src: any) {
Object.keys(src).forEach(opt => { // Sad implementation of Object.assign since we target es5 not es6
target[opt] = src[opt];
});
}

function jsQR(data: Uint8ClampedArray, width: number, height: number, providedOptions: Options = {}): QRCode | null {
const options = Object.create(null);
mergeObject(options, defaultOptions);
mergeObject(options, providedOptions);

const shouldInvert = options.inversionAttempts === "attemptBoth" || options.inversionAttempts === "invertFirst";
const tryInvertedFirst = options.inversionAttempts === "onlyInvert" || options.inversionAttempts === "invertFirst";
Expand Down