- v2.3.2Latest
- v2.3.1
- v2.3.0
- v2.2.1
- v2.2.0
- v2.1.0
- v2.0.10
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.6.0
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.8
- v1.3.7
- v1.3.6
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.0
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.0
- v0.0.15
- v0.0.14
- v0.0.13
- v0.0.12
- v0.0.11
- v0.0.10
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
Simple Utility for Deno
A handy utility collection.
Example
Show more detailsā¦
BASE64 Binary
const file = await Deno.readFile("/path/to/binary.bin");
const encoded = base64Encode(file); // base64 code.
const decoded = base64Decode(encoded); // Restored.
Easy WebCrypto
const file = await Deno.readFile("/path/to/binary.bin");
const random = await cryptoRandom(16); // random byte array.
const hash = await cryptoHash(true, file); // byte array of SHA2 512 bits hash value.
const keyEcdh = await cryptoGenerateKey(true); // public/private key pair for ECDH, each in byte array.
const keyEcdsa = await cryptoGenerateKey(false); // public/private key pair for ECDSA, each in byte array.
const encrypted = await cryptoEncrypt(keyEcdh, file); // encrypted byte array.
const decrypted = await cryptoDecrypt(keyEcdh, encrypted); // Restored.
const signature = await cryptoSign(keyEcdsa.privateKey, data); // signature byte array.
const verify = await cryptoVerify(signature, keyEcdsa.publicKey, data); // `true` if correct.
Date UnixTime
const date = new Date();
const encoded = dateEncode(date); // unixtime in seconds.
const decoded = dateDecode(encoded); // Restored.
const unixtime = dateParse(date.toISOString()); // unixtime in seconds.
DEFLATE Compress
const file = await Deno.readFile("/path/to/binary.bin");
const encoded = await deflateEncode(file); // "deflate" compressed byte array.
const decoded = await deflateDecode(encoded); // Restored.
Extended Fetch API
const json = await fetchExtend("https://path/to/get", "json"); // response as JSON.
const bytes = await fetchExtend("https://path/to/get", "byte"); // response as Uint8Array.
Minipack Archive
const files = [
["binary.bin", Deno.readFileSync("/path/to/binary.bin")]
];
const encoded = await minipackEncode(files); // byte array in "minipack" format.
const decoded = await minipackDecode(encoded); // Restored.
Text Convert
const text = " Lorem ipsum \t dolor \r sit amet.";
const encoded = ucEncode(text); // byte array in UTF-8 format.
const decoded = ucDecode(encoded); // Restored.
const hexadecimal = hexEncode(encoded); // HEX string.
const formatted = trimExtend(decoded); // formatted string.
Platform Specific
const win = isWin(); // "true" if running on Windows.
const tmp = tmpPath(); // "C:/Windows/Temp" if running on Windows, or "/tmp" if running on Linux or Mac.
cwdMain(); // Move current directory to `Deno.mainModule`.
Details
Itās basically a thin wrapper around Denoās functions to improve usability, but some features are original to this module.
This section describes the original features of this module.
Minipack
āMinipackā is a file archive format original to this module.
Itās structure is inspired by the famous ātarā and is minimal as an archive.
Originally developed for web browser, the purpose was to aggregate multiple files input with the HTML File API into a single binary.
Therefore, there is no concept of directory or filesystem, and itās feature by simple structure that stores only the file body, file name, and hash value for verification.
The actual binary structure looks like this:
Index | Type | Title | Size (Byte) |
---|---|---|---|
1 | Header | HashValue | 32 |
2 | Header | NameSize | 1 |
3 | Header | BodySize | 4 |
4 | Body | FileName | Max 255 (Defined in NameSize) |
5 | Body | FileBody | Max 4294967295 (Defined in BodySize) |
This is for one file and repeats for the number of files.
Browser Compatible
Some methods and classes in this module donāt use globalThis.Deno
internally and are browser compatible.
I have prepared browser compatible code only export as mod.compatible.ts.
By bundling this, you can easily create universal utility scripts.
deno bundle https://deno.land/x/simple_utility@(version)/mod.compatible.ts > ./simple_utility.esm.js
This section may eventually be automated with GitHub Actions, in which case the bundled scripts will be merged into GitHub Releases, making this step unnecessary.
Tips
This section is not directly related to this module, but provides a few line snippets to help you implement your application.
Show more detailsā¦
JSON Import with Type
const {default: data} = await import("./data.json", {assert: {type: "json"}});
API
See Deno Document for details.