Skip to main content
Deno 2 is finally here 🎉️
Learn more

🍱 lowlighter’s standalone libraries

This is a collection of carefully crafted TypeScript standalone libraries. These try to be minimal, unbloated and convenient.

Most of them are written with deno in mind, but as the code honors web standards they should be usable on any runtime that follows web specifications (including browsers).

Important


Love these bytes ? Consider 💝 sponsoring me, even one-time contributions are greatly appreciated !

ℹ️ About

While this repository is open, it is not really intended to be a collaborative project. Pull requests for bug fixes or improvements are still welcome, but I may not accept any feature request if it doesn’t seem to fit the scope of this project.

Additionally, these libraries tends to follow my own coding style which:

  • use ES next syntax
  • try to be minimalistic and visually unbloated (no semicolons, infered typing, etc.)
  • use caseless convention (single whole words are preferred assuming they’re unambiguous depending on the local context)

📜 License

This work is licensed under the MIT License.

If you include a significant part of it in your own project, you should keep the license notice with it, including the mention of the additional original authors if any.

📦 Libraries

🔳 QR Code generator

This library is based on the awesome work of @nayiki. Please take a look at their articles about QR Codes:

I rewrote this because I couldn’t find a suitable implementation using EcmaScript modules. Oddly enough, most of the libraries I found also required a canvas to work (while I specifically wanted a SVG image output) because they were intended for client-side usage, and a few other implementations had either some dated code or obfuscated code which I didn’t want.

Features

  • Support out-of-the-box array, console and svg outputs
  • Customizable colors and error correction level (ECL)
  • No external dependencies
  • Not canvas based (i.e. no DOM dependencies and thus cross-platform)

Usage

import { qrcode } from "./qrcode.ts"

// SVG output
const svg = qrcode("https://example.com", { output: "svg" })
console.assert(svg.includes("</svg>"))

// Console output
qrcode("https://example.com", { output: "console" })

// Array output
const array = qrcode("https://example.com")
console.assert(Array.isArray(array))

🔑 Time-based One-Time Password (TOTP)

This library is based on the well-written article of @rajat-sr on hackernoon :

Their explanation was specifically intended for NodeJS so I rewrote it to make it compatible with native Web APIs. Additionally, the URL scheme for TOTP was implemented, and combined with the QR Code generator library it can be used to make it scannable with with an authenticator app such as Microsoft Authenticator or Google Authenticator.

Features

  • Issue a new TOTP secret with metadata (issuer, account, image, etc.)
  • No external dependencies
  • Lightweight

Usage

import { create, verify } from "./totp.ts"
import { qrcode } from "./qrcode.ts"

// Issue a new TOTP secret
const { url, secret } = create({ issuer: "example.com", account: "alice" })
console.log(`Please scan the following QR Code:`)
qrcode(url.href, { output: "console" })

// Verify a TOTP token
const token = prompt("Please enter the token generated by your app:")!
console.assert(await verify({ token, secret }))

➕ Diff (patience algorithm)

This library is based on the previous work of @jonTrent which is itself based on the work of Bram Cohen.

I wrote this library because I’m working on a side project that allows edition of text content, and I wanted to implemente some kind of versioning system à la git. The thing is I didn’t want to create a binary dependency on a binary, especially since the tracked content are mostly small text that may be anywhere in the filesystem, including remote files which would have been outside boundaries of git versioning.

Note


patch() is not implemented yet because I’m currently working on another personal project that I want to finish first (it’s actually the project that required both the QR code and the TOTP libraries) but it’ll eventually be available in the future.

Features

  • Compute unified patch between two strings
  • Match diff command line output
  • No external dependencies
  • Lightweight

Usage

import { diff } from "./diff.ts"

// Print unified patch
console.log(diff("foo", "bar"))
--- a
+++ b
@@ -1 +1 @@
-foo
+bar