Gathering detailed insights and metrics for qrcode.react
Gathering detailed insights and metrics for qrcode.react
Gathering detailed insights and metrics for qrcode.react
Gathering detailed insights and metrics for qrcode.react
npm install qrcode.react
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
3,897 Stars
266 Commits
335 Forks
26 Watching
7 Branches
25 Contributors
Updated on 29 Nov 2024
TypeScript (91.22%)
JavaScript (6.14%)
Makefile (2.64%)
Cumulative downloads
Total Downloads
Last day
-24.7%
205,825
Compared to previous day
Last week
-3.7%
1,310,226
Compared to previous week
Last month
4%
5,602,017
Compared to previous month
Last year
42.2%
67,104,423
Compared to previous year
1
24
A React component to generate QR codes for rendering to the DOM.
1npm install qrcode.react
qrcode.react
exports two components, supporting rendering as SVG or Canvas. SVG is generally recommended as it is more flexible, but Canvas may be preferable.
All examples are shown using modern JavaScript modules and syntax. CommonJS require('qrcode.react')
is also supported.
QRCodeSVG
1import ReactDOM from 'react-dom'; 2import {QRCodeSVG} from 'qrcode.react'; 3 4ReactDOM.render( 5 <QRCodeSVG value="https://reactjs.org/" />, 6 document.getElementById('mountNode') 7);
QRCodeCanvas
1import ReactDOM from 'react-dom'; 2import {QRCodeCanvas} from 'qrcode.react'; 3 4ReactDOM.render( 5 <QRCodeCanvas value="https://reactjs.org/" />, 6 document.getElementById('mountNode') 7);
Below is a condensed type definition of the props QRCodeSVG
and QRCodeCanvas
accept.
1type QRProps = { 2 /** 3 * The value to encode into the QR Code. An array of strings can be passed in 4 * to represent multiple segments to further optimize the QR Code. 5 */ 6 value: string | string[]; 7 /** 8 * The size, in pixels, to render the QR Code. 9 * @defaultValue 128 10 */ 11 size?: number; 12 /** 13 * The Error Correction Level to use. 14 * @see https://www.qrcode.com/en/about/error_correction.html 15 * @defaultValue L 16 */ 17 level?: 'L' | 'M' | 'Q' | 'H'; 18 /** 19 * The background color used to render the QR Code. 20 * @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value 21 * @defaultValue #FFFFFF 22 */ 23 bgColor?: string; 24 /** 25 * The foregtound color used to render the QR Code. 26 * @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value 27 * @defaultValue #000000 28 */ 29 fgColor?: string; 30 /** 31 * Whether or not a margin of 4 modules should be rendered as a part of the 32 * QR Code. 33 * @deprecated Use `marginSize` instead. 34 * @defaultValue false 35 */ 36 includeMargin?: boolean; 37 /** 38 * The number of _modules_ to use for margin. The QR Code specification 39 * requires `4`, however you can specify any number. Values will be turned to 40 * integers with `Math.floor`. Overrides `includeMargin` when both are specified. 41 * @defaultValue 0 42 */ 43 marginSize?: number; 44 /** 45 * The title to assign to the QR Code. Used for accessibility reasons. 46 */ 47 title?: string; 48 /** 49 * The minimum version used when encoding the QR Code. Valid values are 1-40 50 * with higher values resulting in more complex QR Codes. The optimal 51 * (lowest) version is determined for the `value` provided, using `minVersion` 52 * as the lower bound. 53 * @defaultValue 1 54 */ 55 minVersion?: number; 56 /** 57 * If enabled, the Error Correction Level of the result may be higher than 58 * the specified Error Correction Level option if it can be done without 59 * increasing the version. 60 * @defaultValue true 61 */ 62 boostLevel?: boolean; 63 /** 64 * The settings for the embedded image. 65 */ 66 imageSettings?: { 67 /** 68 * The URI of the embedded image. 69 */ 70 src: string; 71 /** 72 * The height, in pixels, of the image. 73 */ 74 height: number; 75 /** 76 * The width, in pixels, of the image. 77 */ 78 width: number; 79 /** 80 * Whether or not to "excavate" the modules around the embedded image. This 81 * means that any modules the embedded image overlaps will use the background 82 * color. 83 */ 84 excavate: boolean; 85 /** 86 * The horiztonal offset of the embedded image, starting from the top left corner. 87 * Will center if not specified. 88 */ 89 x?: number; 90 /** 91 * The vertical offset of the embedded image, starting from the top left corner. 92 * Will center if not specified. 93 */ 94 y?: number; 95 /** 96 * The opacity of the embedded image in the range of 0-1. 97 * @defaultValue 1 98 */ 99 opacity?: number; 100 /** 101 * The cross-origin value to use when loading the image. This is used to 102 * ensure compatibility with CORS, particularly when extracting image data 103 * from QRCodeCanvas. 104 * Note: `undefined` is treated differently than the seemingly equivalent 105 * empty string. This is intended to align with HTML behavior where omitting 106 * the attribute behaves differently than the empty string. 107 */ 108 crossOrigin?: 'anonymous' | 'use-credentials' | '' | undefined; 109 }; 110};
value
The value to encode into the QR Code. See Encoding Mode for additional details.
Type | Default Value |
---|---|
string | string[] | — |
size
The size, in pixels, to render the QR Code.
Type | Default Value |
---|---|
number | 128 |
level
The Error Correction Level to use. Information is encoded in QR Codes such that they can lose part of their visible areas and still be decodable. The amount of correction depends on this value. Higher error correction will result in more complex QR Codes.
L
= low (~7%)M
= medium (~15%)Q
= quartile (~25%)H
= high (~30%)See Wikipedia or the official QR Code documentation for a more detailed explaination.
Type | Default Value |
---|---|
L | M | Q | H | L |
bgColor
The background color used to render the QR Code. This is passed directly to the Canvas (ctx.fillStyle = bgColor
) or the SVG <path>
(fill={bgColor}
), both which accept any CSS color.
Type | Default Value |
---|---|
string | #FFFFFF |
fgColor
The foreground color used to render the QR Code. It follows the same constraints as bgColor
Type | Default Value |
---|---|
string | #000000 |
includeMargin
[!WARNING] This has been deprecated in v4 and will be removed in a future version. Use
marginSize
instead.
Whether or not a margin of 4 modules should be rendered as a part of the QR Code.
Type | Default Value |
---|---|
boolean | false |
marginSize
The number of modules to use for margin. The QR Code specification requires 4
, however you can specify any number. Values will be turned to integers with Math.floor
. Overrides includeMargin
when both are specified.
Type | Default Value |
---|---|
number | 0 |
title
The title to assign to the QR Code. Used for accessibility reasons.
Type | Default Value |
---|---|
string | — |
minVersion
The minimum version used when encoding the QR Code. Valid values are 1-40 with higher values resulting in more complex QR Codes. The optimal (lowest) version is determined for the value
provided, using minVersion
as the lower bound.
Type | Default Value |
---|---|
number | 1 |
boostLevel
If enabled, the Error Correction Level of the result may be higher than the specified Error Correction Level option if it can be done without increasing the version.
Type | Default Value |
---|---|
boolean | true |
imageSettings
Used to specify the details for an embedded image, often used to embed a logo.
Type | Default Value |
---|---|
object (see fields below) | — |
imageSettings.src
The URI of the embedded image. This will get passed directly to src
of an img
element for QRCodeCanvas
or the href
of an inline image
for QRCodeSVG
.
Type | Default Value |
---|---|
string | — |
imageSettings.height
The height, in pixels, of the embedded image.
Type | Default Value |
---|---|
number | — |
imageSettings.width
The width, in pixels, of the embedded image.
Type | Default Value |
---|---|
number | — |
imageSettings.excavate
Whether or not to "excavate" the modules around the embedded image. This means that any modules the embedded image overlaps will use the background color. Use this to ensure clean edges around your image. It is also useful when embedding images with transparency.
Type | Default Value |
---|---|
boolean | — |
imageSettings.x
The horizontal offset, in pixels, of the embedded image. Positioning follows standard DOM positioning, with top left corner being 0.
When not specified, will center the image.
Type | Default Value |
---|---|
number | — |
imageSettings.y
The vertical offset, in pixels, of the embedded image. Positioning follows standard DOM positioning, with top left corner being 0.
When not specified, will center the image.
Type | Default Value |
---|---|
number | — |
imageSettings.opacity
The opacity of the embedded image, in the range of 0 to 1.
Type | Default Value |
---|---|
number | 1 |
imageSettings.crossOrigin
The cross-origin
value to use when loading the embedded image. Note that undefined
works as typically does with React, excluding the attribute from the DOM node. This is intended to align with HTML behavior where omitting the attribute behaves differently than the empty string.
Type | Default Value |
---|---|
string | — |
qrcode.react
will pass through any additional props to the underlying DOM node (<svg>
or <canvas>
). This allows the use of inline style
or custom className
to customize the rendering. One common use would be to support a responsive layout.
[!NOTE] In order to render QR Codes in
<canvas>
on high density displays, we scale the canvas element to contain an appropriate number of pixels and then use inline styles to scale back down. We will merge any additional styles, with customheight
andwidth
overriding our own values. This allows scaling to percentages but if scaling beyond thesize
, you will encounter blurry images. I recommend detecting resizes with something like react-measure to detect and pass the appropriate size when rendering to<canvas>
.
qrcode.react
supports encoding text only. Prior to v4.1.0, this was done in a single segment. Since then, the value
prop can be an array of strings. Each member will be encoded separately. The encoding library being used does minimal detection to determine if each segment being encoded can follow an optimized path for Numeric or Alphanumeric modes, allowing for more data to be encoded. Otherwise, it will encode following Byte mode. This mode includes supports multi-byte Unicode characters such as Kanji, however it does not support the optimized Kanji encoding mode.
qrcode.react
is licensed under the ISC license.
qrcode.react
bundles QR Code Generator, which is available under the MIT license.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
3 different organizations found -- score normalized to 10
Details
Reason
no dangerous workflow patterns detected
Reason
update tool detected
Details
Reason
16 commit(s) out of 30 and 13 issue activity out of 30 found in the last 90 days -- score normalized to 10
Reason
19 out of 20 merged PRs checked by a CI test -- score normalized to 9
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
badge detected: in_progress
Reason
found 19 unreviewed changesets out of 26 -- score normalized to 2
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Score
Last Scanned on 2024-11-22T17:40:07Z
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More