@thomaschaplin/image-to-totp
Version:
image-to-totp converts qr code images to totp codes
27 lines • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseQrCode = void 0;
var jsqr_1 = require("jsqr");
var jimp = require("jimp");
var fs_1 = require("fs");
// eslint-disable-next-line no-unused-vars
var parse_totp_uri_1 = require("./parse-totp-uri");
var parseQrCode = function (filePath) {
if (!(0, fs_1.existsSync)(filePath)) {
throw new Error("File \"".concat(filePath, "\" does not exist."));
}
return new Promise(function (resolve, reject) {
var data = (0, fs_1.readFileSync)(filePath);
jimp.read(data, function (err, img) {
if (err) {
reject(err);
}
var qrCodeImageArray = new Uint8ClampedArray(img.bitmap.data.buffer);
var code = (0, jsqr_1.default)(qrCodeImageArray, img.bitmap.width, img.bitmap.height);
var totp = (0, parse_totp_uri_1.parseTotpUri)(code.data);
resolve(totp);
});
});
};
exports.parseQrCode = parseQrCode;
//# sourceMappingURL=parse-qr-code.js.map