Skip to content

A collection of handy functions and reference types used across DGTL's Javascript projects

License

Notifications You must be signed in to change notification settings

dgtlworkshop/handyjs

Repository files navigation

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
}

About

A collection of handy functions and reference types used across DGTL's Javascript projects

Resources

License

Stars

Watchers

Forks

Packages