本文整理汇总了TypeScript中qrcode.toDataURL函数的典型用法代码示例。如果您正苦于以下问题:TypeScript toDataURL函数的具体用法?TypeScript toDataURL怎么用?TypeScript toDataURL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了toDataURL函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
// Get 'password' parameter
const [password, passwordErr] = $.str.get(params.password);
if (passwordErr) return rej('invalid password param');
// Compare password
const same = await bcrypt.compare(password, user.password);
if (!same) {
return rej('incorrect password');
}
// Generate user's secret key
const secret = speakeasy.generateSecret({
length: 32
});
await User.update(user._id, {
$set: {
twoFactorTempSecret: secret.base32
}
});
// Get the data URL of the authenticator URL
QRCode.toDataURL(speakeasy.otpauthURL({
secret: secret.base32,
encoding: 'base32',
label: user.username,
issuer: config.host
}), (err, data_url) => {
res({
qr: data_url,
secret: secret.base32,
label: user.username,
issuer: config.host
});
});
});
示例2: convertObjectToQRCodeDataURL
export async function convertObjectToQRCodeDataURL(object: any): Promise<string> {
const string = JSON.stringify(object);
return await QRCode.toDataURL(string);
}
示例3: function
/// <reference path="qrcode.d.ts" />
import * as QRCode from 'qrcode';
QRCode.toDataURL('i am a pony!', function (err, url) {
console.log(url);
});
var qrcodedraw = new QRCodeLib.QRCodeDraw();
qrcodedraw.draw(document.getElementById('test') as HTMLCanvasElement, "this text will be in the code!", function (error, canvas) {
if (error) {
return console.log('Error =( ', error);
}
console.log('success!');
});
示例4:
import * as QRCode from 'qrcode';
const canvas = document.getElementById('canvas') as HTMLCanvasElement;
QRCode.toCanvas(canvas, 'sample text', (error) => {
if (error) console.error(error);
console.log('success!');
});
QRCode.toDataURL('I am a pony!', (err, url) => {
console.log(url);
});
QRCode.toDataURL('some text', { errorCorrectionLevel: 'H' }, (err, url) => {
console.log(url);
});
QRCode.toDataURL('some text', { version: 2 }, (err, url) => {
console.log(url);
});
QRCode.toDataURL([
{ data: 'ABCDEFG', mode: 'alphanumeric' },
{ data: '0123456', mode: 'numeric' }
], (err, url) => {
console.log(url);
});
QRCode.toCanvas('text', { errorCorrectionLevel: 'H' }, (err, canvas) => {
if (err) throw err;
});
示例5: async
const buildRenderParams = async (user?: User, cards?: any[], data?: any) => ({
site: {
title: siteTitle,
admin: adminEmail,
source: sourceCodeUrl,
reg: openRegister,
},
user: user
? {
...user,
ss: {
...shadowsocks,
port: user.connPort,
encryption: user.connEnc,
password: user.connPassword,
uri: new Buffer(
`${user.connEnc}:${user.connPassword}@${shadowsocks.host}:${
user.connPort
}`
).toString("base64"),
qrcode: await makeQrCode(
"ss://" +
Buffer.from(
`${user.connEnc}:${user.connPassword}@${shadowsocks.host}:${
user.connPort
}`
).toString("base64")
),
},
vmess: {
...vmess,
webSocket: {
...vmess.webSocket,
headersJson: JSON.stringify(vmess.webSocket.headers),
},
tcpHeaderJson: JSON.stringify(vmess.tcp.header),
remark: siteTitle,
id: user.vmessUid,
aid: user.vmessAlterId,
link: {
android: Buffer.from(
JSON.stringify({
add: proxyHost,
aid: user.vmessAlterId,
host: `${vmess.webSocket.path};${proxyHost}`,
id: user.vmessUid,
net: vmess.network,
port: vmess.port,
ps: siteTitle,
tls: vmess.tls.status === "off" ? "" : "tls",
type:
vmess.network === "tcp"
? vmess.tcp.header.type
: vmess.network === "kcp"
? vmess.kcp.header.type
: "none",
})
).toString("base64"),
win: Buffer.from(
JSON.stringify({
add: proxyHost,
aid: user.vmessAlterId,
host: `${vmess.webSocket.path};${proxyHost}`,
id: user.vmessUid,
net: vmess.network,
port: vmess.port,
ps: siteTitle,
tls: vmess.tls.status === "off" ? "" : "tls",
type:
vmess.network === "tcp"
? vmess.tcp.header.type
: vmess.network === "kcp"
? vmess.kcp.header.type
: "none",
})
).toString("base64"),
shadowrocket: `${Buffer.from(
`chacha20-poly1305:${user.vmessUid}@${proxyHost}:${vmess.port}`
).toString("base64")}?obfsParam=${vmess.webSocket.host}&path=${
vmess.network === "ws"
? vmess.webSocket.path
: vmess.tcp.header.type
}&obfs=${
vmess.network === "ws"
? "websocket"
: vmess.network === "tcp"
? vmess.tcp.header.type
: "none"
}&tls=${vmess.tls.status === "off" ? 0 : 1}`,
},
qrcode: {
kitsunebi: await makeQrCode(
"vmess://" +
Buffer.from(
`chacha20-poly1305:${user.vmessUid}@${proxyHost}:${
vmess.port
}`
).toString("base64") +
`?network=${vmess.network}` +
(vmess.network === "ws"
//.........这里部分代码省略.........
示例6: async
const getGuide = async (user: IUser, siteName?: string): Promise<IGuide> => {
const ssUri =
"ss://" +
Buffer.from(
`${user.ss.encryption}:${user.ss.password}@${user.ss.host}:${
user.ss.port
}`
).toString("base64");
const ssQr = await makeQrCode(ssUri);
return {
vmess: [
{
os: "Android",
descriptions: [
{
title: "ä¸č˝˝ĺşç¨",
content: "ä¸č˝˝ĺŽ˘ćˇçŤŻĺšśĺŽčŁ
(app-universal-release.apk)ă",
links: [
{
name: "GitHub",
href: "https://github.com/2dust/v2rayNG/releases",
},
],
},
{
title: "桝ĺ é
罎",
content:
"çšĺťä¸é˘çćéŽďźćç
§çłťçťć示ç¨ĺşç¨ v2rayNG ćĺźďźĺšśćç
§ĺşç¨ć示祎莤桝ĺ ă",
links: [
{
name: "é
罎",
href:
"vmess://" +
Buffer.from(
JSON.stringify({
add: user.vmess.host,
aid: user.vmess.aid,
host: `${user.vmess.webSocket.path};${
user.vmess.webSocket.host
}`,
id: user.vmess.id,
net: user.vmess.network,
port: user.vmess.port,
ps: siteName,
tls: user.vmess.tls.status === "off" ? "" : "tls",
type:
user.vmess.network === "tcp"
? user.vmess.tcp.header.type
: user.vmess.network === "kcp"
? user.vmess.kcp.header.type
: "none",
})
).toString("base64"),
},
],
},
{
title: "ćšĺé
罎ďźĺŻéďź",
content:
"çšĺťć°ĺ˘çé
罎ćäťśĺłäž§çźčžĺžć ďźĺ¨ĺźšĺşçé˘ćżĺ
ďźäżŽćšăsecurityă为ăchacha20-poly1305ăďźçšĺťĺłä¸č§ĺŻšĺˇäżĺă",
},
{
title: "莞罎衯çą",
content:
"çšĺťĺłä¸č§čĺďźéćŠăSettingsăďźćĺźăBypass MainlandăďźďźĺŻéďźćĺźăEnable MuxăďźčżĺéŚéĄľă",
},
{
title: "ĺŻĺ¨äťŁç",
content:
"çšĺťä¸ćšçş¸éŁćşďźĺž
ć示ăStart Server SuccessăĺĺłĺŻĺźĺ§ä˝żç¨ç˝çťă个ĺŤçłťçťĺŻč˝äźčŻ˘éŽćéďźčŻˇä¸ĺžĺ
莸ă",
},
],
},
{
os: "iOS(Kitsunebi)",
descriptions: [
{
title: "ä¸č˝˝ĺşç¨",
content:
"ĺ¨ App Store č´äš°ĺşç¨ KitsunebiďźďżĽ12ďźďźćçłčŻˇĺ
č´šçćľčŻçďźéčŚć䝣ç莿éŽďźă",
links: [
{
name: "App Store",
href: "https://itunes.apple.com/cn/app/kitsunebi/id1275446921",
},
{
name: "TestFlight",
href:
"https://docs.google.com/forms/d/e/1FAIpQLSekOGRE7cXk3vBTVjlHiv6RJRXfeItZvjQCDRxyigKYq6ChmA/viewform",
},
],
},
{
title: "桝ĺ é
罎",
content:
"ćĺźĺşç¨ďźçšĺťĺˇŚä¸č§đˇĺžć ćŤćä¸ćšäşçť´ç ďźç§ťĺ¨čŽžĺ¤ĺŻäťĽéżćäżĺäşçť´ç ĺďźçšĺťĺˇŚä¸č§đˇĺžć ďźĺçšĺťĺłä¸č§ć䝜多ĺžć ďźäťç¸ĺä¸éćŠäşçť´ç ĺžçă",
qrcode: await makeQrCode(
"vmess://" +
Buffer.from(
`chacha20-poly1305:${user.vmess.id}@${user.vmess.host}:${
//.........这里部分代码省略.........