Git Product home page Git Product logo

sgqr's Introduction

sgqr

npm version main.yml publish.yml formatter.yml

A cross-platform typesafe SGQR library for individuals and businesses.

Important

sgqr is still a work-in-progress and may undergo drastic API changes to maximise DX and performance. See the following discussion for more information.

Install

You can depend on sgqr from npm or via CDN.

Node

npm i sgqr
bun add sgqr

Browser

<script src="https://cdn.jsdelivr.net/npm/sgqr/dist/index.global.js"></script>

Usage

Generate SGQR

Minimally, sgqr allows you to generate the SGQR text.

import sgqr from 'sgqr'

const code = sgqr.generate({
  number: '+6591234567',
  amount: '1.69'
})

console.log(code)

Generate SGQR Code

sgqr provides an API capable of generating QR codes in webp, jpeg or png formats.

const data = await sgqr.generate_code({
  number: '+6591234567',
  amount: '1',
  type: 'image/webp'
})

if (!data) {
  throw new Error('Failed to generate QR code')
}

await Bun.write('qr.png', data)

Generate SGQR SVG

SVGs can be generated with the generate_svg API.

const data = await sgqr.generate_svg({
  number: '+6591234567',
  amount: '1.2',
  comments: 'This SGQR was made with sgqr!'
})

Generate SGQR with UEN

If you are a business, you can generate SGQR codes with your UEN.

const data = await sgqr.generate_code({
  number: '0123456789',
  number_type: 'UEN',
  merchant_name: 'Singapore Armed Forces',
  amount: '4.1',
  type: 'image/jpeg'
})

Generate SGQR with Expiry Date

You can specify an expiry date for the SGQR code. According to the SGQR specification, the expiry date must be in the format YYYYMMDD.

const data = await sgqr.generate_svg({
  number: '0123456789',
  number_type: 'UEN',
  amount: '1.00',
  expiry_date: '20251231'
})

if (!data) {
  throw new Error('Failed to generate QR code')
}

await Bun.write('qr.svg', data)

Command Line

sgqr can also be used as a command line tool. The binary can be found here.

sgqr --number +6591234567 --amount 420.69 --type image/svg+xml --output qr.svg
Options:
  --version             Show version number             [boolean]
  --number              mobile or unique entity number  [string] [required]
  --amount              payment amount as a string      [string] [required]
  --output              output file path                [string]
  --number_type         UEN or MOBILE                   [choices: "UEN", "MOBILE"]
  --merchant_name       merchant name                   [string]
  --comments            comments                        [string]
  --country_code        country code                    [string]
  --scale               scale of the image              [number]
  --expiry_date         expiry date as a string         [string]
  --merchant_city       merchant city                   [string]
  --currency_code       currency code                   [string]
  --type                type of image                   [choices: "image/webp", "image/jpeg", "image/svg+xml"]
  --editable            if the code is editable         [boolean]
  --help                Show help                       [boolean]

Development

Setup

Install all dependencies.

bun install

Build

Minify and bundle the library with tsup.

bun run build

Compile

Compile the library into a binary.

bun compile

Test

Run your tests with hot reloading.

bun run test

Run your tests without hot reloading. For testing in a CI pipeline.

bun test

sgqr's People

Contributors

github-actions[bot] avatar renovate[bot] avatar winstxnhdw avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

sgqr's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

bun
package.json
  • qrcode ^1.5.3
  • tslib ^2.6.2
  • @biomejs/biome 1.7.3
  • @changesets/cli ^2.27.3
  • @types/qrcode ^1.5.5
  • @types/yargs ^17.0.32
  • bun-types ^1.1.10
  • tsup ^8.0.2
  • typescript ^5.4.5
  • yargs ^17.7.2
github-actions
.github/workflows/formatter.yml
.github/workflows/main.yml
.github/workflows/publish.yml
  • actions/checkout v4.1.6
  • oven-sh/setup-bun v1.2.1
  • changesets/action v1.4.7
  • actions/checkout v4
  • oven-sh/setup-bun v1.2.1
  • actions/upload-artifact v4.3.3
  • actions/download-artifact v4.1.7

  • Check this box to trigger a request for Renovate to run again on this repository

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.