uqr 0.0.0 → 0.0.2

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) Project Nayuki
4
+ Copyright (c) 2023 Anthony Fu <https://github.com/antfu>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # uqr
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/uqr?color=a1b858&label=)](https://www.npmjs.com/package/uqr)
4
+
5
+ Generate QR Code universally, in any runtime, to ANSI, Unicode or SVG.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ # Using npm
11
+ npm install uqr
12
+
13
+ # Using yarn
14
+ yarn add uqr
15
+
16
+ # Using pnpm
17
+ pnpm add uqr
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```ts
23
+ import {
24
+ encode,
25
+ renderANSI,
26
+ renderSVG,
27
+ renderUnicode,
28
+ renderUnicodeCompact,
29
+ } from 'uqr'
30
+
31
+ const svg = renderSVG('Hello, World!')
32
+
33
+ const ansi = renderANSI('https://192.168.1.100:3000', {
34
+ // Error correction level
35
+ ecc: 'L',
36
+ // Border width
37
+ border: 2,
38
+ })
39
+
40
+ // display QR Code in terminal
41
+ console.log(ansi)
42
+ ```
43
+
44
+ ## API
45
+
46
+ ### `encode`
47
+
48
+ Encode plain text or binary data into QR Code represented by a 2D array.
49
+
50
+ ```ts
51
+ import { encode } from 'uqr'
52
+
53
+ const {
54
+ data, // 2D array of boolean, representing the QR Code
55
+ version, // QR Code version
56
+ size, // size of the QR Code
57
+ } = encode(text, options)
58
+ ```
59
+
60
+ ### `renderANSI`
61
+
62
+ Render QR Code to [ANSI colored](https://ss64.com/nt/syntax-ansi.html) string.
63
+
64
+ ```ts
65
+ import { renderANSI } from 'uqr'
66
+
67
+ const string = renderANSI(text, options)
68
+
69
+ console.log(string)
70
+ ```
71
+
72
+ ### `renderUnicode`
73
+
74
+ Render QR Code to Unicode string for each pixel. By default it uses `█` and `░` to represent black and white pixels, and it can be customizable.
75
+
76
+ ```ts
77
+ import { renderUnicode } from 'uqr'
78
+
79
+ const string = renderUnicode(text, {
80
+ blackChar: '█',
81
+ whiteChar: '░',
82
+ // ...other options
83
+ })
84
+ ```
85
+
86
+ ### `renderUnicodeCompact`
87
+
88
+ Render QR Code with two rows into one line with unicode `▀`, `▄`, `█`, ` `. It is useful when you want to display QR Code in terminal with limited height.
89
+
90
+ ```ts
91
+ import { renderUnicodeCompact } from 'uqr'
92
+
93
+ const string = renderUnicodeCompact(text, options)
94
+
95
+ console.log(string)
96
+ ```
97
+
98
+ ### `renderSVG`
99
+
100
+ Render QR Code to SVG string.
101
+
102
+ ```ts
103
+ import { renderSVG } from 'uqr'
104
+
105
+ const string = renderSVG(text, options)
106
+ ```
107
+
108
+ ## Credits
109
+
110
+ QR Code generation algorithm is modified from [nayuki/QR-Code-generator](https://github.com/nayuki/QR-Code-generator/blob/master/typescript-javascript/qrcodegen.ts) by Project Nayuki.
111
+
112
+ CLI renders are inspired by [qrcode-terminal](https://github.com/gtanner/qrcode-terminal).
113
+
114
+ ## License
115
+
116
+ [MIT](./LICENSE) License