Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
emg110 committed Feb 11, 2023
1 parent 9ba389e commit 8013918
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 76 deletions.
2 changes: 1 addition & 1 deletion bin/algo-qrcode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const QRCode = require("qrcode-svg")
const QRCodeTerminal = require("../terminal.js")
const QRCodeTerminal = require("../src/terminal.js")
const yargs = require('yargs');


Expand Down
75 changes: 2 additions & 73 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -1,73 +1,2 @@
import QRCode from "qrcode-svg"
import QRCodeTerminal from "./src/terminal"


import { isBrowser, isNode, isWebWorker, isJsDom, isDeno } from "browser-or-node";
function parseOptions(args) {
/*
content: "https://github.com/",
padding: 4,
width: 256,
height: 256,
color: "#000000",
background: "#ffffff",
ecl: "M",
*/
let content = "algorand://"
let amount = args.amount;
let wallet = args.wallet;
let label = args.label;
let asset = args.asset;
let note = args.note;
if (!!label && !!wallet) {
content = "algorand://" + wallet+ "?" + "&label=" + label;
} else if (!!asset && !!wallet) {
if (!!note && amount > 0) {
content = "algorand://" + wallet+ "?" + "&amount=" + amount + "&asset=" + asset + "&note=" + note;
} else if (amount > 0) {
content = "algorand://" + wallet+ "?" + "&amount=" + amount + "&asset=" + asset;
} else if (amount === 0) {
content = "algorand://?" + "amount=0" + "&asset=" + asset;
}

} else if (!!note && !!wallet && !!amount) {
content = "algorand://" + wallet+ "?" + "&amount=" + amount + "&note=" + note;
} else if ( !!wallet && !!amount){
content = "algorand://" + wallet+ "?" + "&amount=" + amount;
}
let options = {
content: content,
container: "svg-viewbox",
ecl: args.ecl || "H",
file: args.file || "algorand-qrcode.svg",
padding: args.margin || 4,
width: args.width || 256,
height: args.height || 256,
output: args.output || "terminal",
background: args.background || "#e1dede",
color: args.color || "#000000"
}
return options
}
const algoqrcode = (options) =>{
if (isBrowser) {
let opts = parseOptions(options)
let qrcode = new QRCode(opts);
return qrcode

} else if (isNode) {
if (options.output === 'svg') {
let opts = parseOptions(options)
let qrcode = new QRCode(opts);
return qrcode
} else {
let opts = parseOptions(options)
return QRCodeTerminal.generate(opts.content);
}


}

}
export default algoqrcode

import algoqrcode from "./src/index.mjs";
export default algoqrcode
2 changes: 1 addition & 1 deletion lib/bundle.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const babelConfig = {
}

export default [{
input: 'index.mjs',
input: 'src',
output: [{
file: 'lib/bundle.min.js',
format: "es",
Expand Down
73 changes: 73 additions & 0 deletions src/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import QRCode from "qrcode-svg"
import QRCodeTerminal from "./terminal"


import { isBrowser, isNode, isWebWorker, isJsDom, isDeno } from "browser-or-node";
function parseOptions(args) {
/*
content: "https://github.com/",
padding: 4,
width: 256,
height: 256,
color: "#000000",
background: "#ffffff",
ecl: "M",
*/
let content = "algorand://"
let amount = args.amount;
let wallet = args.wallet;
let label = args.label;
let asset = args.asset;
let note = args.note;
if (!!label && !!wallet) {
content = "algorand://" + wallet+ "?" + "&label=" + label;
} else if (!!asset && !!wallet) {
if (!!note && amount > 0) {
content = "algorand://" + wallet+ "?" + "&amount=" + amount + "&asset=" + asset + "&note=" + note;
} else if (amount > 0) {
content = "algorand://" + wallet+ "?" + "&amount=" + amount + "&asset=" + asset;
} else if (amount === 0) {
content = "algorand://?" + "amount=0" + "&asset=" + asset;
}

} else if (!!note && !!wallet && !!amount) {
content = "algorand://" + wallet+ "?" + "&amount=" + amount + "&note=" + note;
} else if ( !!wallet && !!amount){
content = "algorand://" + wallet+ "?" + "&amount=" + amount;
}
let options = {
content: content,
container: "svg-viewbox",
ecl: args.ecl || "H",
file: args.file || "algorand-qrcode.svg",
padding: args.margin || 4,
width: args.width || 256,
height: args.height || 256,
output: args.output || "terminal",
background: args.background || "#e1dede",
color: args.color || "#000000"
}
return options
}
const algoqrcode = (options) =>{
if (isBrowser) {
let opts = parseOptions(options)
let qrcode = new QRCode(opts);
return qrcode

} else if (isNode) {
if (options.output === 'svg') {
let opts = parseOptions(options)
let qrcode = new QRCode(opts);
return qrcode
} else {
let opts = parseOptions(options)
return QRCodeTerminal.generate(opts.content);
}


}

}
export default algoqrcode

0 comments on commit 8013918

Please sign in to comment.