9l
Site last updated: (Loading)
Here are some small helper libraries I wrote. They are all actively being updated. All are dependency-free unless explictly stated and can be used by running before the script(s) that use them. Please do not link directly to these. If you have any questions or comments, there is a small form at the bottom of this page.
Note - I am aware this has led to some violations of DRY for the sake of modularity (well, none of these are modules but they behave like modules)
-
08/28/24 - A critical bug fix was implemented for es3-zip.js. The bug caused a somewhat rare condition where zip files with entries having a Last-Modified header written at a timestamp ending in 59 seconds caused the MS-DOS date-time headers to become corrupted. The patch uses a "floor" operation on the bits designated for seconds instead of a "round", which was causing entries within files saved at 59 seconds to round upward and throw off some software such as 7zip. Also, improvements have been added:
- Fully asynchronous queueing and emitting of array buffers, making defining behavior more consistent
- for multi-volume zips, the central directory does not have to be on a dedicated volume if there is enough room for it on the last volume. this eliminates the need for always having an extra file dedicated for the central directory.
- a superficial syntactic change, the "ondataavailable" handler is being deprecated in favor of "ondata". the old method still works, but i added console warnings encouraging switching over.
- heres a link to the official Zip docs (see 4.4.6 for more info on date-time fields)
- swap.js - an implementation of the concept of "swap" space for the browser to increase available temporary storage for array buffers, with promises. i made this to allow the downloading of large streams for devices with limited array buffer memory such as smartphones. it can also be used to store files with persistence so just be aware to clear it after you use it. this requires the library localforage to be used.
- num-to-str.js - this is a "secure" implementation of the built-in Number.toString() method but with ability to provide custom character set and higher radix. At the moment my version is more precise than the built-in method, but probably slower. (the problem I encountered is how to calculate the max number of digits to obtain before stopping on irrational numbers, so I just stopped when the environment recognizes the precision small enough to be equivalent to zero). The reason I say it is "secure" is it does not call any built-ins and instead relies on the consistent behavior of operators. This way, if the global Number methods are redefined elsewhere, its behavior will not be affected. This version uses String.charAt() in order to be compatible with legacy environments, but by changing that to using index accessors for strings it will be completely isolated from protoype pollution.
- zip.js - improved version of my es3 zip utils. This version allows you to create a zip split across multiple volumes (like .z01, .z02, z.0n....zip). And you can also read zip files using Zip.read( data ). You do not need to read the entire zip file, only the end, and it will scan the central directory headers. To create a zip writer, call new Zip( maxVolumeSize ). If max volume size is set to 0 or infinity, the resulting zip will be a single file. Data can be asynchronously written to the zip in chunks. You can then pipe the output through zip.ondataavailable as a handler and call zip.finish() to end the instance.
- escape-unescape.js - polyfills for escape and unescape global methods. they are going to be deprecated but i needed them for something (RFC5987 compatible filenames for content-disposition headers), and yes i am aware of encodeURI and encodeURIComponent (and have polyfilled both of those as well for es3 environments) but all 3 of these percent encoding schemes behave differently
- upload.js - prompts user to pick/upload files. promise-based. can do either file picker, or via drag and drop. attaches 2 functions to the global scope: upload() and uploadWithDrag().
- copy.js - simplified clipboard copy api. literally just do await copy( [your string here] ).
- webp encoder polyfill - this polyfills HTML5 canvas webp encoder for browsers that do not support it, using a webassembly module adapted from the chromium source code. (see the comments at the top of the init file for more info).
- set-frameout - like setTimeout but uses browser frames instead of milliseconds. methods are setFrameout, setFrameInterval, clearFrameout and clearFrameInterval
- apache-table - generate markup for apache-style html table using a list of files as input. the reason i wanted to make this was because in theory people probably already have css for their apache directories so you should be able to easily plop that stylesheet and have it work with this too with minimal tweakage.
- peer-js-wrapper - this is like hyper-specific but it's a set of wrappers i made for the peer-js library to make it easier to interface with.
- progress-measurer - can be used to easily calculate progress for transfer of bytes. simply call .update( bytes ) method and it will return an object containing information such as the amount of bytes loaded and time passed since the instance was created.
- progbar - display progress in a small bar at the top of the viewport. automatically hides when at 0 or 1. to set the progress, simply do window.progbar.value = a float between 0 and 1.
- disk-writer.js - streamed downloads for big files without need for server. this is a bit of a hack, because it relies on a service worker. it allows you to stream a file of infinite size to disk over an indefinite period of time. i made it to facilitate requesting and zipping many files. the old blob-url-anchor-with-download-attribute is more reliable, albeit it requires that the entire file be stored in memory first before downloading, which limits the file size to the amount of memory the client's browser is willing to provide.
- sleep.js - bringing sleep functionality to javascript, because no one asked. and yes, it can block the thread it's running in. or not. your choice.
- run-script.js - a script that...runs more scripts. what did you expect?
- when.js - sort of like the "Object.observer" thing from the mid 10's that was deprecated because everyone agreed it was a bad pattern. well, i needed it for something that can't use events, and i don't like how you can't extend the Proxy api, so i made this.
- random-id.js - what it says on the tin
- discord-webhook.js - a script for sending messages to discord webhooks. you can use this to send messages to a discord server from a website, without a bot. you can also edit any messages you sent. and delete them too. this has the ability to send synchronous requests as well, not that you should. because sync XHR is supposed to be deprecated. but it still works so I am using it here. this way you can send a delete request when the session ends and have it more reliably delete the message (navigator.sendBeacon() only uses post, sadly.).