Skip to content

Latest commit

 

History

History
41 lines (28 loc) · 1.14 KB

README.md

File metadata and controls

41 lines (28 loc) · 1.14 KB

DGTL Handy JS 🖐

A collection of handy functions and reference types used across DGTL's Javascript projects. All functions are as close to pure as they can get and nearly all are designed to run in the browser or NodeJs. No modules have top-level await.

"Because JavaScript doesn't really have a standard library"

echo "@dgtlworkshop:registry=https://npm.pkg.github.com" >> .npmrc
npm install @dgtlworkshop/handyjs

Usage

import { Chrono, Maths } from "@dgtlworkshop/handyjs";

await Chrono.timeout(500);

console.info("0.5 of 4 is equal to", Maths.mapRange(0.5, 0, 4, 0, 12), "of 12");

The Browser module can only be imported in the browser due to using document APIs.

import { Downloads } from "@dgtlworkshop/handyjs/browser";

let my_blob = new Blob();
Downloads.downloadFileFromBlob("myimage.jpg", "image/jpg", my_blob);

Similarly, the Server module can only be imported in Node (or other compatible environments).

import { Program } from "@dgtlworkshop/handyjs/server";

if (Program.isMain(import.meta.url)) {
	console.info("Hello World");
} else {
	// This file was imported, not the entrypoint
}