react-native-qrcode-svg 6.3.22 → 6.3.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-qrcode-svg",
3
- "version": "6.3.22",
3
+ "version": "6.3.24",
4
4
  "description": "A QR Code generator for React Native based on react-native-svg and javascript-qrcode.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,22 +1,22 @@
1
- import React from "react";
2
- import { Image } from "react-native-svg";
3
- import { isString, isUrlString } from "../utils";
1
+ import React from 'react'
2
+ import { Image } from 'react-native-svg'
3
+ import { isString, isUrlString } from '../utils'
4
4
 
5
5
  const LogoSVG = ({ svg, logoSize, logoColor }) => {
6
6
  if (isString(svg)) {
7
7
  const href = isUrlString(svg)
8
8
  ? svg
9
- : `data:image/svg+xml;base64,${window.btoa(svg)}`;
9
+ : `data:image/svg+xml;base64,${window.btoa(svg)}`
10
10
 
11
- return <Image href={encodeURI(href)} width={logoSize} height={logoSize} />;
11
+ return <Image href={encodeURI(href)} width={logoSize} height={logoSize} />
12
12
  }
13
13
 
14
14
  // if `svg` prop is actually a svg asset wrapped in a React component, then we can just render it
15
- const LogoSVGComponent = svg;
15
+ const LogoSVGComponent = svg
16
16
 
17
17
  return (
18
18
  <LogoSVGComponent fill={logoColor} width={logoSize} height={logoSize} />
19
- );
20
- };
19
+ )
20
+ }
21
21
 
22
- export default LogoSVG;
22
+ export default LogoSVG
@@ -1,24 +1,24 @@
1
- import React from "react";
2
- import { LocalSvg } from "react-native-svg/css";
3
- import { SvgUri, SvgXml } from "react-native-svg";
4
- import { isString, isUrlString } from "../utils";
1
+ import React from 'react'
2
+ import { LocalSvg } from 'react-native-svg/css'
3
+ import { SvgUri, SvgXml } from 'react-native-svg'
4
+ import { isString, isUrlString } from '../utils'
5
5
 
6
6
  const LogoSVG = ({ svg, logoSize, logoColor }) => {
7
7
  if (isString(svg)) {
8
8
  if (isUrlString(svg)) {
9
9
  return (
10
10
  <SvgUri uri={svg} fill={logoColor} width={logoSize} height={logoSize} />
11
- );
11
+ )
12
12
  }
13
13
 
14
14
  return (
15
15
  <SvgXml xml={svg} fill={logoColor} width={logoSize} height={logoSize} />
16
- );
16
+ )
17
17
  }
18
18
 
19
19
  return (
20
20
  <LocalSvg asset={svg} fill={logoColor} width={logoSize} height={logoSize} />
21
- );
22
- };
21
+ )
22
+ }
23
23
 
24
- export default LogoSVG;
24
+ export default LogoSVG
@@ -48,9 +48,9 @@ describe('QRCode', () => {
48
48
  it('renders with segmented value', () => {
49
49
  const onErrorMock = jest.fn()
50
50
  const segs = [
51
- { data: "ABCDEFG", mode: "alphanumeric" },
52
- { data: "0123456", mode: "numeric" },
53
- ];
51
+ { data: 'ABCDEFG', mode: 'alphanumeric' },
52
+ { data: '0123456', mode: 'numeric' }
53
+ ]
54
54
  const tree = renderer.create(
55
55
  <QRCode
56
56
  value={segs}
package/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useMemo, useId } from "react";
1
+ import React, { useMemo, useId } from 'react'
2
2
  import Svg, {
3
3
  Defs,
4
4
  G,
@@ -7,11 +7,11 @@ import Svg, {
7
7
  Image,
8
8
  ClipPath,
9
9
  LinearGradient,
10
- Stop,
11
- } from "react-native-svg";
12
- import genMatrix from "./genMatrix";
13
- import transformMatrixIntoPath from "./transformMatrixIntoPath";
14
- import LogoSVG from "./LogoSVG";
10
+ Stop
11
+ } from 'react-native-svg'
12
+ import genMatrix from './genMatrix'
13
+ import transformMatrixIntoPath from './transformMatrixIntoPath'
14
+ import LogoSVG from './LogoSVG'
15
15
 
16
16
  const renderLogo = ({
17
17
  size,
@@ -25,13 +25,13 @@ const renderLogo = ({
25
25
  logoBorderRadius,
26
26
  clipPathId
27
27
  }) => {
28
- const logoPosition = (size - logoSize - logoMargin * 2) / 2;
29
- const logoBackgroundSize = logoSize + logoMargin * 2;
28
+ const logoPosition = (size - logoSize - logoMargin * 2) / 2
29
+ const logoBackgroundSize = logoSize + logoMargin * 2
30
30
  const logoBackgroundBorderRadius =
31
- logoBorderRadius + (logoMargin / logoSize) * logoBorderRadius;
32
- const clipLogoBackgroundId = `clip-logo-background-${clipPathId}`;
33
- const clipLogoId = `clip-logo-${clipPathId}`;
34
-
31
+ logoBorderRadius + (logoMargin / logoSize) * logoBorderRadius
32
+ const clipLogoBackgroundId = `clip-logo-background-${clipPathId}`
33
+ const clipLogoId = `clip-logo-${clipPathId}`
34
+
35
35
  return (
36
36
  <G x={logoPosition} y={logoPosition}>
37
37
  <Defs>
@@ -66,64 +66,66 @@ const renderLogo = ({
66
66
  height={logoBackgroundSize - logoMargin}
67
67
  fill={logoBackgroundColor}
68
68
  />
69
- {logoSVG ? (
70
- <LogoSVG svg={logoSVG} logoSize={logoSize} logoColor={logoColor} />
71
- ) : (
72
- <Image
73
- width={logoSize}
74
- height={logoSize}
75
- preserveAspectRatio="xMidYMid slice"
76
- href={logo}
77
- clipPath={`url(#${clipLogoId})`}
78
- />
79
- )}
69
+ {logoSVG
70
+ ? (
71
+ <LogoSVG svg={logoSVG} logoSize={logoSize} logoColor={logoColor} />
72
+ )
73
+ : (
74
+ <Image
75
+ width={logoSize}
76
+ height={logoSize}
77
+ preserveAspectRatio='xMidYMid slice'
78
+ href={logo}
79
+ clipPath={`url(#${clipLogoId})`}
80
+ />
81
+ )}
80
82
  </G>
81
83
  </G>
82
- );
83
- };
84
+ )
85
+ }
84
86
 
85
87
  const QRCode = ({
86
- value = "this is a QR code",
88
+ value = 'this is a QR code',
87
89
  size = 100,
88
- color = "black",
89
- backgroundColor = "white",
90
+ color = 'black',
91
+ backgroundColor = 'white',
90
92
  logo,
91
93
  logoSVG,
92
94
  logoSize = size * 0.2,
93
- logoBackgroundColor = "transparent",
95
+ logoBackgroundColor = 'transparent',
94
96
  logoColor,
95
97
  logoMargin = 2,
96
98
  logoBorderRadius = 0,
97
99
  quietZone = 0,
98
100
  enableLinearGradient = false,
99
- gradientDirection = ["0%", "0%", "100%", "100%"],
100
- linearGradient = ["rgb(255,0,0)", "rgb(0,255,255)"],
101
- ecl = "M",
101
+ gradientDirection = ['0%', '0%', '100%', '100%'],
102
+ linearGradient = ['rgb(255,0,0)', 'rgb(0,255,255)'],
103
+ ecl = 'M',
102
104
  getRef,
103
105
  onError,
104
- testID,
106
+ testID
105
107
  }) => {
106
- const clipPathId = useId();
108
+ const clipPathId = useId()
107
109
 
108
110
  const result = useMemo(() => {
109
111
  try {
110
- return transformMatrixIntoPath(genMatrix(value, ecl), size);
112
+ return transformMatrixIntoPath(genMatrix(value, ecl), size)
111
113
  } catch (error) {
112
- if (onError && typeof onError === "function") {
113
- onError(error);
114
+ if (onError && typeof onError === 'function') {
115
+ onError(error)
114
116
  } else {
115
117
  // Pass the error when no handler presented
116
- throw error;
118
+ throw error
117
119
  }
118
120
  }
119
- }, [value, size, ecl]);
121
+ }, [value, size, ecl])
120
122
 
121
123
  if (!result) {
122
- return null;
124
+ return null
123
125
  }
124
126
 
125
- const { path, cellSize } = result;
126
- const displayLogo = logo || logoSVG;
127
+ const { path, cellSize } = result
128
+ const displayLogo = logo || logoSVG
127
129
 
128
130
  return (
129
131
  <Svg
@@ -133,21 +135,21 @@ const QRCode = ({
133
135
  -quietZone,
134
136
  -quietZone,
135
137
  size + quietZone * 2,
136
- size + quietZone * 2,
137
- ].join(" ")}
138
+ size + quietZone * 2
139
+ ].join(' ')}
138
140
  width={size}
139
141
  height={size}
140
142
  >
141
143
  <Defs>
142
144
  <LinearGradient
143
- id="grad"
145
+ id='grad'
144
146
  x1={gradientDirection[0]}
145
147
  y1={gradientDirection[1]}
146
148
  x2={gradientDirection[2]}
147
149
  y2={gradientDirection[3]}
148
150
  >
149
- <Stop offset="0" stopColor={linearGradient[0]} stopOpacity="1" />
150
- <Stop offset="1" stopColor={linearGradient[1]} stopOpacity="1" />
151
+ <Stop offset='0' stopColor={linearGradient[0]} stopOpacity='1' />
152
+ <Stop offset='1' stopColor={linearGradient[1]} stopOpacity='1' />
151
153
  </LinearGradient>
152
154
  </Defs>
153
155
  <G>
@@ -162,8 +164,8 @@ const QRCode = ({
162
164
  <G>
163
165
  <Path
164
166
  d={path}
165
- strokeLinecap="butt"
166
- stroke={enableLinearGradient ? "url(#grad)" : color}
167
+ strokeLinecap='butt'
168
+ stroke={enableLinearGradient ? 'url(#grad)' : color}
167
169
  strokeWidth={cellSize}
168
170
  />
169
171
  </G>
@@ -178,10 +180,10 @@ const QRCode = ({
178
180
  logoColor,
179
181
  logoMargin,
180
182
  logoBorderRadius,
181
- clipPathId,
183
+ clipPathId
182
184
  })}
183
185
  </Svg>
184
- );
185
- };
186
+ )
187
+ }
186
188
 
187
- export default QRCode;
189
+ export default QRCode
package/src/utils.js CHANGED
@@ -1,7 +1,7 @@
1
- export function isString(variable) {
2
- return typeof variable === "string";
1
+ export function isString (variable) {
2
+ return typeof variable === 'string'
3
3
  }
4
4
 
5
- export function isUrlString(variable) {
6
- return isString(variable) && variable.startsWith("http");
5
+ export function isUrlString (variable) {
6
+ return isString(variable) && variable.startsWith('http')
7
7
  }