Coder Social home page Coder Social logo

Comments (10)

thexeos avatar thexeos commented on August 18, 2024 4

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.

amvtek avatar amvtek commented on August 18, 2024 1

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.

nayuki avatar nayuki commented on August 18, 2024

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.

ShahabT avatar ShahabT commented on August 18, 2024

+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.

nuxodin avatar nuxodin commented on August 18, 2024

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.

petrospap avatar petrospap commented on August 18, 2024

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.

nayuki avatar nayuki commented on August 18, 2024

@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.

petrospap avatar petrospap commented on August 18, 2024

@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.

nayuki avatar nayuki commented on August 18, 2024

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.

petrospap avatar petrospap commented on August 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.