Socket
Socket
Sign inDemoInstall

qr-svg

Package Overview
Dependencies
1
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

17

lib/qr-svg.d.ts
/**
* qr-svg v1.0.0
* qr-svg v1.1.0
* https://github.com/jnordberg/qr-svg

@@ -27,2 +27,13 @@ *

*/
interface Rect {
x: number;
y: number;
width: number;
height: number;
}
declare function render(text: string, level?: 'L' | 'M' | 'Q' | 'H', version?: number): {
rects: Rect[];
size: any;
};
declare function toSvg(size: number, rects: Rect[]): string;
/**

@@ -35,4 +46,4 @@ * Generate QR code.

*/
declare function generate(text: string, level?: 'L' | 'M' | 'Q' | 'H', version?: number): string;
declare function QR(text: string, level?: 'L' | 'M' | 'Q' | 'H', version?: number): string;
export default generate;
export { QR, Rect, render, toSvg };

43

lib/qr-svg.js
/**
* qr-svg v1.0.0
* qr-svg v1.1.0
* https://github.com/jnordberg/qr-svg

@@ -29,2 +29,4 @@ *

Object.defineProperty(exports, '__esModule', { value: true });
var ErrorCorrectLevel = {

@@ -973,10 +975,3 @@ L: 1,

/**
* Generate QR code.
* @param level Error correction level, one of L (7%), M (15%), Q (25%) or H (30%) defaults to L.
* @param version QR Size, 1 to 40, defaults to -1 (autodetect).
* @returns SVG string.
* @author Johan Nordberg <code@johan-nordberg.com>
*/
function generate(text, level = 'L', version = -1) {
function render(text, level = 'L', version = -1) {
const qr = new QRCode(version, ErrorCorrectLevel[level]);

@@ -1021,13 +1016,33 @@ qr.addData(text);

}
const svg = [`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}">`];
for (const rects of rows) {
for (const { x, y, width, height } of rects) {
svg.push(`<rect x="${x}" y="${y}" width="${width}" height="${height}"/>`);
const rects = [];
for (const row of rows) {
for (const rect of row) {
rects.push(rect);
}
}
return { rects, size };
}
function toSvg(size, rects) {
const svg = [`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}">`];
for (const { x, y, width, height } of rects) {
svg.push(`<rect x="${x}" y="${y}" width="${width}" height="${height}"/>`);
}
svg.push('</svg>');
return svg.join('');
}
/**
* Generate QR code.
* @param level Error correction level, one of L (7%), M (15%), Q (25%) or H (30%) defaults to L.
* @param version QR Size, 1 to 40, defaults to -1 (autodetect).
* @returns SVG string.
* @author Johan Nordberg <code@johan-nordberg.com>
*/
function QR(text, level = 'L', version = -1) {
const { size, rects } = render(text, level, version);
return toSvg(size, rects);
}
module.exports = generate;
exports.QR = QR;
exports.render = render;
exports.toSvg = toSvg;
//# sourceMappingURL=qr-svg.js.map
/**
* qr-svg v1.0.0
* qr-svg v1.1.0
* https://github.com/jnordberg/qr-svg

@@ -970,10 +970,3 @@ *

/**
* Generate QR code.
* @param level Error correction level, one of L (7%), M (15%), Q (25%) or H (30%) defaults to L.
* @param version QR Size, 1 to 40, defaults to -1 (autodetect).
* @returns SVG string.
* @author Johan Nordberg <code@johan-nordberg.com>
*/
function generate(text, level = 'L', version = -1) {
function render(text, level = 'L', version = -1) {
const qr = new QRCode(version, ErrorCorrectLevel[level]);

@@ -1018,13 +1011,31 @@ qr.addData(text);

}
const svg = [`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}">`];
for (const rects of rows) {
for (const { x, y, width, height } of rects) {
svg.push(`<rect x="${x}" y="${y}" width="${width}" height="${height}"/>`);
const rects = [];
for (const row of rows) {
for (const rect of row) {
rects.push(rect);
}
}
return { rects, size };
}
function toSvg(size, rects) {
const svg = [`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}">`];
for (const { x, y, width, height } of rects) {
svg.push(`<rect x="${x}" y="${y}" width="${width}" height="${height}"/>`);
}
svg.push('</svg>');
return svg.join('');
}
/**
* Generate QR code.
* @param level Error correction level, one of L (7%), M (15%), Q (25%) or H (30%) defaults to L.
* @param version QR Size, 1 to 40, defaults to -1 (autodetect).
* @returns SVG string.
* @author Johan Nordberg <code@johan-nordberg.com>
*/
function QR(text, level = 'L', version = -1) {
const { size, rects } = render(text, level, version);
return toSvg(size, rects);
}
export default generate;
export { QR, render, toSvg };
//# sourceMappingURL=qr-svg.m.js.map
{
"name": "qr-svg",
"description": "Lightweight SVG QR code generator in JavaScript",
"version": "1.0.0",
"version": "1.1.0",
"homepage": "https://github.com/jnordberg/qr-svg",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -19,3 +19,3 @@ qr-svg

```ts
import QR from 'qr-svg'
import {QR} from 'qr-svg'

@@ -22,0 +22,0 @@ QR('hello') // <svg ...

import ErrorCorrectLevel from './ErrorCorrectLevel'
import QRCode from './QRCode'
interface Rect {
export interface Rect {
x: number

@@ -11,10 +11,3 @@ y: number

/**
* Generate QR code.
* @param level Error correction level, one of L (7%), M (15%), Q (25%) or H (30%) defaults to L.
* @param version QR Size, 1 to 40, defaults to -1 (autodetect).
* @returns SVG string.
* @author Johan Nordberg <code@johan-nordberg.com>
*/
export default function generate(text: string, level: 'L' | 'M' | 'Q' | 'H' = 'L', version = -1) {
export function render(text: string, level: 'L' | 'M' | 'Q' | 'H' = 'L', version = -1) {
const qr = new QRCode(version, ErrorCorrectLevel[level])

@@ -62,11 +55,31 @@

const svg: string[] = [`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}">`]
for (const rects of rows) {
for (const {x, y, width, height} of rects) {
svg.push(`<rect x="${x}" y="${y}" width="${width}" height="${height}"/>`)
const rects: Rect[] = []
for (const row of rows) {
for (const rect of row) {
rects.push(rect)
}
}
return {rects, size}
}
export function toSvg(size: number, rects: Rect[]) {
const svg: string[] = [`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}">`]
for (const {x, y, width, height} of rects) {
svg.push(`<rect x="${x}" y="${y}" width="${width}" height="${height}"/>`)
}
svg.push('</svg>')
return svg.join('')
}
/**
* Generate QR code.
* @param level Error correction level, one of L (7%), M (15%), Q (25%) or H (30%) defaults to L.
* @param version QR Size, 1 to 40, defaults to -1 (autodetect).
* @returns SVG string.
* @author Johan Nordberg <code@johan-nordberg.com>
*/
export function QR(text: string, level: 'L' | 'M' | 'Q' | 'H' = 'L', version = -1) {
const {size, rects} = render(text, level, version)
return toSvg(size, rects)
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc