https://github.com/sec-ant/ansi-qr-code
Make Qr Codes suited for the terminal
https://github.com/sec-ant/ansi-qr-code
ansi-qr-code lib qr-code typescript
Last synced: about 1 year ago
JSON representation
Make Qr Codes suited for the terminal
- Host: GitHub
- URL: https://github.com/sec-ant/ansi-qr-code
- Owner: Sec-ant
- License: mit
- Created: 2023-08-22T06:52:24.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-24T09:46:35.000Z (almost 3 years ago)
- Last Synced: 2025-02-02T04:14:54.813Z (over 1 year ago)
- Topics: ansi-qr-code, lib, qr-code, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@sec-ant/ansi-qr-code/v/latest
- Size: 213 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @sec-ant/ansi-qr-code
Make Qr Codes suited for the terminal. This package provides functions for creating both large and small QR codes, with customizable options such as error correction level, border size, module colors etc.

## Install
```bash
npm i @sec-ant/ansi-qr-code
```
## Usage
First, import the `makeAnsiQrCode` and/or `makeSmallAnsiQrCode` function(s) from the package.
```typescript
import { makeAnsiQrCode, makeSmallAnsiQrCode } from "@sec-ant/ansi-qr-code";
```
You can then generate a QR code by calling the function, passing your desired text along with optional configuration options.
### Large QR Codes
Large QR Codes are generated by `makeAnsiQrCode` function. This function uses ideographic space (" ") to construct the Qr Code.
```typescript
const ansiQrCode = makeAnsiQrCode("Hello, world!", {
ecc: ECC.MEDIUM,
border: 1,
blackModuleColor: BG_BLUE,
whiteModuleColor: BG_BRIGHT_GREEN,
});
console.log(ansiQrCode.value);
```
#### Options (AnsiQrCodeOptions)
- _ecc_: `Ecc` - Determines the error correction level. Can be one of `Ecc` enum values(`Ecc.LOW`, `Ecc.MEDIUM`, `Ecc.QUARTILE`, or `Ecc.HIGH`). Default is `Ecc.LOW`.
- _border_: `number` - Specifies the border size. Default is `4`.
- _blackModuleColor_: `BgColor | Reset` - Defines the ANSI color code for the black modules of the QR code. Default is `BG_BLACK`.
- _whiteModuleColor_: `BgColor | Reset` - Defines the ANSI color code for the white modules of the QR code. Default is `BG_BRIGHT_WHITE`.
### Small QR Codes
Small QR Codes are generated by `makeSmallAnsiQrCode` function. This function uses the combinations of block elements and space as _quadrublocks_ to construct the Qr Code.
| quadrublocks | `00` | `01` | `10` | `11` |
| :----------: | :--: | :--: | :--: | :--: |
| **`00`** | ` ` | ` ▄` | `▄ ` | `▄▄` |
| **`01`** | ` ▀` | ` █` | `▄▀` | `▄█` |
| **`10`** | `▀ ` | `▀▄` | `█ ` | `█▄` |
| **`11`** | `▀▀` | `▀█` | `█▀` | `██` |
```typescript
const smallAnsiQrCode = makeSmallAnsiQrCode("Hello, world!", {
ecc: ECC.MEDIUM,
border: 4,
blackModuleColor: FG_RED,
whiteModuleColor: RESET,
});
console.log(smallAnsiQrCode.value);
```
#### Options (SmallAnsiQrCodeOptions)
- _ecc_: `Ecc` - Determines the error correction level. Can be one of `Ecc` enum values(`Ecc.LOW`, `Ecc.MEDIUM`, `Ecc.QUARTILE`, or `Ecc.HIGH`). Default is `Ecc.LOW`.
- _border_: `number` - Specifies the border size. Default is `4`.
- _blackModuleColor_: `FgColor | Reset` (Default style) or `BgColor | Reset` (Inverted style) - Defines the ANSI color code for the black modules of the QR code.
- _whiteModuleColor_: `BgColor | Reset` (Default style) or `FgColor | Reset` (Inverted style) - Defines the ANSI color code for the white modules of the QR code.
### Additional exports
The package also exports `ECC` (an Enum that determines the error correction level) and some additional ANSI terminal colors and escape codes like `RESET`, `BG_BLACK`, `BG_BRIGHT_WHITE`, and `FG_BLACK`. You can use these constants to set the module colors of your QR codes.
## License
MIT