diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index e2a9645..bf3a494 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -542,7 +542,7 @@ var qrcodegen = new function() { for (version = minVersion; ; version++) { var dataCapacityBits = QrCode.getNumDataCodewords(version, ecl) * 8; // Number of data bits available dataUsedBits = qrcodegen.QrSegment.getTotalBits(segs, version); - if (dataUsedBits != null && dataUsedBits <= dataCapacityBits) + if (dataUsedBits <= dataCapacityBits) break; // This version number is found to be suitable if (version >= maxVersion) // All versions in the range could not fit the given data throw "Data too long"; @@ -827,7 +827,7 @@ var qrcodegen = new function() { var ccbits = seg.mode.numCharCountBits(version); // Fail if segment length value doesn't fit in the length field's bit-width if (seg.numChars >= (1 << ccbits)) - return null; + return Infinity; result += 4 + ccbits + seg.getBits().length; } return result; diff --git a/typescript/qrcodegen.ts b/typescript/qrcodegen.ts index 958746f..596df59 100644 --- a/typescript/qrcodegen.ts +++ b/typescript/qrcodegen.ts @@ -85,8 +85,8 @@ namespace qrcodegen { let dataUsedBits: int; for (version = minVersion; ; version++) { let dataCapacityBits: int = QrCode.getNumDataCodewords(version, ecl) * 8; // Number of data bits available - let usedBits: number|null = QrSegment.getTotalBits(segs, version); - if (usedBits != null && usedBits <= dataCapacityBits) { + let usedBits: number = QrSegment.getTotalBits(segs, version); + if (usedBits <= dataCapacityBits) { dataUsedBits = usedBits; break; // This version number is found to be suitable } @@ -774,16 +774,16 @@ namespace qrcodegen { // Package-private helper function. - public static getTotalBits(segs: Array, version: int): int|null { + public static getTotalBits(segs: Array, version: int): number { if (version < QrCode.MIN_VERSION || version > QrCode.MAX_VERSION) throw "Version number out of range"; - let result: int = 0; + let result: number = 0; for (let i = 0; i < segs.length; i++) { let seg: QrSegment = segs[i]; let ccbits: int = seg.mode.numCharCountBits(version); // Fail if segment length value doesn't fit in the length field's bit-width if (seg.numChars >= (1 << ccbits)) - return null; + return Infinity; result += 4 + ccbits + seg.getBits().length; } return result;