Giter Site home page Giter Site logo

sec-ant / ansi-qr-code Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 218 KB

Make Qr Codes suited for the terminal

Home Page: https://www.npmjs.com/package/@sec-ant/ansi-qr-code/v/latest

License: MIT License

TypeScript 99.00% HTML 1.00%
lib qr-code typescript ansi-qr-code

ansi-qr-code's Introduction

@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.

ansi-qr-code-demo

Install

npm i @sec-ant/ansi-qr-code

Usage

First, import the makeAnsiQrCode and/or makeSmallAnsiQrCode function(s) from the package.

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.

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 ▀▀ ▀█ █▀ ██
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

ansi-qr-code's People

Contributors

sec-ant avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.