Comments (10)
It is very simple to set up as module for importing. No need to use other, less performant, libraries available on npm.
Step 1: Add the following line to the end of the qrcodegen.ts
file:
export default qrcodegen
Step 2: Use the following line to import qrcodegen.ts
file anywhere where you need to use this library:
import qrcodegen from '../your/project/path/to/qrcodegen.ts'
Done! You now have access to qrcodegen.QrCode
in your code.
Likewise, if you are using webpack, you can load the code asynchronously like this:
const qrcodegen = await import(/* webpackChunkName: "qrcodegen" */ '../your/project/path/to/qrcodegen.ts')
@nayuki, maybe you could add the "export default qrcodegen
" part in README.md under /typescript-javascript/
? That could clear up some confusion about namespaces for people that haven't used them in their project before.
from qr-code-generator.
I share your perspective on the fad changing problem. However the users of your library may not have a choice, and may discard using your library (which stands out for the clarity of its code) as a result of non compatibility with today leading ecosystems. Additionally by sharing your work on say npm you improve discover ability of your solution. The Python version of your library has a proper setup installer and is distributed through PyPi, this reinsure Python developers that they can commit time integrating it.
If you want I can try tackling packaging your javascript library without changing a line in your qrcodegen.js module.
from qr-code-generator.
This JavaScript packaging stuff looks like busywork and long-term churn as fads change. I don't see the return on effort invested to understand the frameworks, nor the justification to write and maintain more lines of code.
from qr-code-generator.
+1 to amvtek's point. Opted to https://github.com/soldair/node-qrcode/commits/master exactly because it was very hard to use this lib's typescript version in my react project. if it had been an npm module would go with this liberary.
from qr-code-generator.
Hi ShahabT
If you desice to not support it as a module, please consider to making qrcodegen
explicit global:
window.qrcodegen = ...
so i can import the script as a module and still have access to qrcodegen
from qr-code-generator.
Hello, I use your qrcodegen-v1.7.0-es6.js
Working perfect out of box! Thank you..
but when i try to use it as await import (no matter what i have done) i cant make it work.
what i try to do is
async buildCodes(p){
await import('./qrcodegen.js').then((qrcodegen) => {
this.qrcodegen = qrcodegen;
console.dir(this.qrcodegen);
this.drawCanvas();
return this.data;
});
}
this error i got
Object { qrcodegen: {…}, … }
qrcodegen: Object { QrCode: class QrCode, QrSegment: class QrSegment}
QrCode: class QrCode { constructor(version, errorCorrectionLevel, dataCodewords, mask) }
QrSegment: class QrSegment { constructor(mode, numChars, bitData) }
<prototype>: Object { … }
Symbol(Symbol.toStringTag): "Module"
Uncaught (in promise) TypeError: this.qrcodegen.QrCode is undefined at drawCanvas
in drawCanvas has the line
qr = this.qrcodegen.QrCode.encodeText(txt, this.qrcodegen.QrCode.Ecc.MEDIUM),
note this working perfect if i don't use await import and loaded as normal import from.
from qr-code-generator.
@petrospap I don't think the problem you're experiencing is related to await import. QrCode.drawCanvas()
was removed in v1.7.0, in commit 1cc4617d5716. You'll have to copy an implementation from qrcodegen-output-demo.ts into your own main program.
from qr-code-generator.
@nayuki Thank you for your response, the problem is the await import, as if i don't use await everything is working perfect.
seems to me that can't pass out of await this.qrcodegen;
probably have to find another way to use await import
from qr-code-generator.
Read carefully. At https://github.com/nayuki/QR-Code-generator/releases/tag/v1.7.0 , the source file qrcodegen-v1.7.0-es6.js does not contain drawCanvas
anywhere.
from qr-code-generator.
Yes I know! I take it and i adapted to script.. Anyway I found solution to my problem.
Thanks again for this very helpful script (talking to my self, maybe is time to start TS)
from qr-code-generator.
Related Issues (20)
- Hafizullah 8
- New maven release HOT 1
- C++: Default constructor for QrCode or no-throw versions of the factory functions HOT 5
- Custom shapes support HOT 1
- `
- How can I generate urls HOT 2
- How to display a small logo in the middle HOT 2
- Support Shape HOT 1
- Support Embeded Logo Image HOT 2
- MicroQR support? HOT 1
- Alternative to toSvgString HOT 1
- Publish the `rust-no-heap` crate on crates.io HOT 2
- Option to insert an image/logo inside a QR image? HOT 2
- 🇫🇷Emmaus COM whattsapp
- Split data into multiple QR-codes using structured append mode HOT 5
- I would like to create a simple android app using your QR-Code-generator ... is it possible ? HOT 1
- UE5 Integration Hints HOT 1
- Letters get wrongly encoded as Kanji HOT 2
- Deno TypeScript Port HOT 1
- Optimize library footprint HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qr-code-generator.