Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
dfts-qrcode
Advanced tools
tiny and simple-to-use Javascript / TypeScript QR-Code generator library. Fully type-safe and esm module compatible
dfts-qrcode
is a tiny and simple-to-use Javascript / TypeScript QR-Code generator library.
Fully type-safe and esm module compatible.
npm:
npm install dfts-qrcode@latest
pnpm:
pnpm install dfts-qrcode@latest
import { generateQrCodeImage } from 'dfts-qrcode';
const { image, dataUrl } = generateQrCodeImage('data');
Options:
generateOptions
generateWithAccessibleOptions
import { generateQrCodeImage$ } from 'dfts-qrcode';
generateQrCodeImage$('data', {image: {src: './assets/logo.png'}}).then(({image, dataUrl}) => {
...
})
Options:
generateOptions
generateWithAccessibleOptions
generateWithImageOptions
import { generateQrCodeCanvas } from 'dfts-qrcode';
const qrcode = generateQrCodeCanvas('data');
Options:
generateOptions
import { generateQrCodeCanvas$ } from 'dfts-qrcode';
generateQrCodeCanvas$('data', {image: {src: './assets/logo.png'}}).then((qrcode) => {
...
})
Options:
generateOptions
generateWithImageOptions
import { generateQrCodeSVG } from 'dfts-qrcode';
const { svg, dataUrl } = generateQrCodeSVG('data');
Options:
generateOptions
generateWithAccessibleOptions
import { generateQrCodeSVGString } from 'dfts-qrcode';
const svgString = generateQrCodeSVGString('data');
Options:
generateOptions
generateWithAccessibleOptions
import { generateQrCodeSVG$ } from 'dfts-qrcode';
generateQrCodeSVG$('data', {image: {src: './assets/logo.png'}}).then(({ svg, dataUrl }) => {
...
})
Options:
generateOptions
generateWithAccessibleOptions
generateWithImageOptions
import { generateQrCodeMatrix } from 'dfts-qrcode';
const qrcodeMatrix = generateQrCodeMatrix('data');
Options:
generateMatrixOptions
import { ColorValueHex } from './types';
export type QRCodeVersion =
| -1
| 0
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
| 10
| 11
| 12
| 13
| 14
| 15
| 16
| 17
| 18
| 19
| 20
| 21
| 22
| 23
| 24
| 25
| 26
| 27
| 28
| 29
| 30
| 31
| 32
| 33
| 34
| 35
| 36
| 37
| 38
| 39
| 40;
export type QRCodeErrorCorrectionLevel = 'L' | 'M' | 'Q' | 'H';
export type ColorValueHex = `#${string}`;
export type generateMatrixOptions = {
// If undefined or -1, automatically calculated
version?: QRCodeVersion;
// If undefined, automatically calculated
mode?: 'numeric' | 'alphanumeric' | 'octet';
// Defaults to L
errorCorrectionLevel?: QRCodeErrorCorrectionLevel;
// If undefined or -1, automatically calculated
mask?: number;
};
export type generateOptions = generateMatrixOptions & {
// defaults to 5, size in px
size?: number;
// defaults to 4, margin in px
margin?: number;
colors?: {
// defaults to '#FFFFFF', hex color
colorLight?: ColorValueHex;
// defaults to '#00000', hex color
colorDark?: ColorValueHex;
};
};
export type generateWithImageOptions = {
image?: {
src?: string;
height?: number;
width?: number;
};
};
export type generateWithAccessibleOptions = {
alt?: string;
ariaLabel?: string;
title?: string;
};
Error correction capability allows to successfully scan a QR Code even if the symbol is dirty or damaged. Four levels are available to choose according to the operating environment.
Higher levels offer a better error resistance but reduce the symbol's capacity.
If the chances that the QR Code symbol may be corrupted are low (for example if it is showed through a monitor)
is possible to safely use a low error level such as Low
or Medium
.
Possible levels are shown below:
Level | Error resistance |
---|---|
L (Low) | ~7% |
M (Medium) | ~15% |
Q (Quartile) | ~25% |
H (High) | ~30% |
The percentage indicates the maximum amount of damaged surface after which the symbol becomes unreadable.
Error level can be set through options.errorCorrectionLevel
property.
If not specified, the default value is L
.
import { generateQrCodeMatrix } from 'dfts-qrcode';
generateQrCodeMatrix('data', { errorCorrectionLevel: 'M' });
Capacity depends on symbol version and error correction level. Also encoding modes may influence the amount of storable data.
The QR Code versions range from version 1 to version 40.
Each version has a different number of modules (black and white dots), which define the symbol's size.
For version 1 they are 21x21
, for version 2 25x25
e so on.
Higher is the version, more are the storable data, and of course bigger will be the QR Code symbol.
The table below shows the maximum number of storable characters in each encoding mode and for each error correction level.
Mode | L | M | Q | H |
---|---|---|---|---|
Numeric | 7089 | 5596 | 3993 | 3057 |
Alphanumeric | 4296 | 3391 | 2420 | 1852 |
Byte | 2953 | 2331 | 1663 | 1273 |
QR Code version can be set through options.version
property.
If no version is specified, the more suitable value will be used. Unless a specific version is required, this option is not needed.
import { generateQrCodeMatrix } from 'dfts-qrcode';
generateQrCodeMatrix('data', { errorCorrectionLevel: 'M', mode: 'octet', version: 1 });
Modes can be used to encode a string in a more efficient way.
A mode may be more suitable than others depending on the string content.
A list of supported modes are shown in the table below:
Mode | Characters | Compression |
---|---|---|
Numeric | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 | 3 characters are represented by 10 bits |
Alphanumeric | 0–9, A–Z (upper-case only), space, $, %, *, +, -, ., /, : | 2 characters are represented by 11 bits |
Byte | Characters from the ISO/IEC 8859-1 character set | Each characters are represented by 8 bits |
FAQs
tiny and simple-to-use Javascript / TypeScript QR-Code generator library. Fully type-safe and esm module compatible
The npm package dfts-qrcode receives a total of 59 weekly downloads. As such, dfts-qrcode popularity was classified as not popular.
We found that dfts-qrcode demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.