@levischuck/tiny-qr 0.0.1

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.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Levi Schuck, 2025 kennytm
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # tiny-qr
2
+
3
+ A minimal, dependency-free TypeScript QR code encoder.
4
+
5
+ ## Usage
6
+
7
+ ```typescript
8
+ import { qrCode, EcLevel } from '@levischuck/tiny-qr';
9
+
10
+ // Create a QR code with default settings (Medium error correction)
11
+ const qr = qrCode({ data: 'HELLO WORLD' });
12
+
13
+ // With custom error correction level
14
+ const qrHighEc = qrCode({ data: 'HELLO WORLD', ec: EcLevel.H });
15
+
16
+ // Encode binary data
17
+ const qrBinary = qrCode({ data: new Uint8Array([0x01, 0x02, 0x03]) });
18
+
19
+ // Access the result
20
+ console.log('Size:', qr.width);
21
+ console.log('Version:', qr.version);
22
+
23
+ // Matrix is a 2D boolean array (true = dark, false = light)
24
+ for (let y = 0; y < qr.width; y++) {
25
+ for (let x = 0; x < qr.width; x++) {
26
+ const isDark = qr.matrix[y][x];
27
+ }
28
+ }
29
+ ```
30
+
31
+ This package is intended to be chained with other tiny-packages for rendering:
32
+
33
+ - `@levischuck/tiny-qr-svg` - SVG output
34
+ - `@levischuck/tiny-qr-png` - PNG output
35
+
36
+ If you're looking to manually render from the modules,
37
+ the result contains a `boolean[][]` matrix.
38
+
39
+ ## API
40
+
41
+ ### `qrCode(options: QrOptions): QrResult`
42
+
43
+ Generates a QR code from the given data.
44
+
45
+ **Options:**
46
+ - `data: string | Uint8Array` - The data to encode
47
+ - `ec?: EcLevel` - Error correction level (default: `EcLevel.M`)
48
+
49
+ **Result:**
50
+ - `matrix: boolean[][]` - 2D array of modules (true = dark, false = light)
51
+ - `width: number` - Width/height of the QR code in modules
52
+ - `version: Version` - QR code version (1-40)
53
+ - `ec: EcLevel` - Error correction level used
54
+ - `EcLevel.L` or `0`
55
+ - `EcLevel.M` or `1`
56
+ - `EcLevel.Q` or `2`
57
+ - `EcLevel.H` or `3`
58
+
59
+ ## Rendering
60
+
61
+ ## License
62
+
63
+ MIT Licensed.
64
+
65
+ This code is largely derived from [qrcode-rust](https://github.com/kennytm/qrcode-rust) by kennytm, which provides an MIT and Apache 2 license to its code.
package/dist/bits.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { EcLevel, Version } from './types.ts';
2
+ import { Segment } from './optimize.ts';
3
+ /** The Bits state stores the encoded data for a QR code */
4
+ export interface BitsState {
5
+ readonly data: number[];
6
+ readonly bitOffset: number;
7
+ readonly version: Version;
8
+ }
9
+ /** Creates a new bits state */
10
+ export declare function createBits(version: Version): BitsState;
11
+ /** Gets the version from bits state */
12
+ export declare function bitsVersion(bits: BitsState): Version;
13
+ /** Convert the bits into a bytes array */
14
+ export declare function bitsIntoBytes(bits: BitsState): Uint8Array;
15
+ /** Pushes terminator and padding */
16
+ export declare function bitsPushTerminator(bits: BitsState, ecLevel: EcLevel): BitsState;
17
+ /** Pushes segments */
18
+ export declare function bitsPushSegments(bits: BitsState, data: Uint8Array, segments: Segment[]): BitsState;
19
+ /** Pushes data using optimal encoding */
20
+ export declare function bitsPushOptimalData(bits: BitsState, data: Uint8Array): BitsState;
21
+ /** Automatically determines minimum version and encodes data */
22
+ export declare function encodeAuto(data: Uint8Array, ecLevel: EcLevel): BitsState;
@@ -0,0 +1,20 @@
1
+ import { Color, EcLevel, Version } from './types.ts';
2
+ declare enum Module {
3
+ Empty = 0,
4
+ MaskedLight = 1,
5
+ MaskedDark = 2,
6
+ UnmaskedLight = 3,
7
+ UnmaskedDark = 4
8
+ }
9
+ export interface CanvasState {
10
+ readonly width: number;
11
+ readonly version: Version;
12
+ readonly ecLevel: EcLevel;
13
+ readonly modules: Module[];
14
+ }
15
+ export declare function createCanvas(version: Version, ecLevel: EcLevel): CanvasState;
16
+ export declare function canvasDrawAllFunctionalPatterns(canvas: CanvasState): CanvasState;
17
+ export declare function canvasDrawData(canvas: CanvasState, data: Uint8Array, ecCode: Uint8Array): CanvasState;
18
+ export declare function canvasApplyBestMask(canvas: CanvasState): CanvasState;
19
+ export declare function canvasIntoColors(canvas: CanvasState): Color[];
20
+ export {};
package/dist/ec.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { EcLevel, Version } from './types.ts';
2
+ /** Creates error correction code */
3
+ export declare function createErrorCorrectionCode(data: Uint8Array, ecCodeSize: number): Uint8Array;
4
+ /** Constructs data and error correction codewords */
5
+ export declare function constructCodewords(rawbits: Uint8Array, version: Version, ecLevel: EcLevel): [Uint8Array, Uint8Array];
@@ -0,0 +1,18 @@
1
+ import { EcLevel, QrOptions, QrResult } from './types.ts';
2
+ export type { Version } from './types.ts';
3
+ /**
4
+ * Generates a QR code from the given data
5
+ * @param options - QR code generation options
6
+ * @returns A QR code result object with matrix, width, version, and error correction level
7
+ */
8
+ export declare function qrCode(options: QrOptions): QrResult;
9
+ /**
10
+ * Converts a QR code result to a debug string
11
+ * @param qr - The QR code result object
12
+ * @param darkChar - Character to use for dark modules (default: '#')
13
+ * @param lightChar - Character to use for light modules (default: '.')
14
+ * @returns A string representation of the QR code
15
+ */
16
+ export declare function debugString(qr: QrResult, darkChar?: string, lightChar?: string): string;
17
+ export { EcLevel };
18
+ export type { QrOptions, QrResult };