This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CRC32 lookup table | |
export const crc32LookupTable = Array.from({ length: 256 }, (_, n) => | |
Array.from({ length: 8 }).reduce( | |
(c) => (c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1), | |
n | |
) | |
); | |
// Calculate the CRC32 checksum on the main thread | |
export const crc32ArrayBuffer = (uint8Array) => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @typedef {string} ElementToStringConverterResult - The result of the ElementToStringConverter (string). | |
*/ | |
/** | |
* @typedef {function(HTMLElement | null, number): ElementToStringConverterResult} ElementToStringConverter - A function that converts an element to an ElementToStringConverterResult (string). | |
*/ | |
/** | |
* @typedef {Object.<ElementToStringConverterResult, ElementToStringConverterResult>} KeysAndElementsMapperResult - The result of the KeysAndElementsMapper (record). | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const require = async (url) => { | |
const scriptAlreadyRequired = document.querySelector(`script[data-origin="${url}"`); | |
if (scriptAlreadyRequired) { | |
return scriptAlreadyRequired; | |
} | |
const script = document.createElement('script'); | |
const code = await fetch(url); | |
script.type = 'text/javascript'; | |
script.setAttribute('data-origin', url); | |
script.innerText = await code.text(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Will throw a TypeError if definition does not match with target. | |
* @param {string} def The types to chec target against. Multiple types have to be separated by | (pipe). | |
* @param {Object.<string, string|Object|Array|number|boolean>} def The object of definitions the target object will be matched against. | |
* @param {[string|Object|Array|number|boolean]} def Target Array(!) will be matched against def[0]. | |
* @param {number|boolean} def Target's value will be matched against the value of definition. | |
* @param {any} target Target to check. | |
* @example See shared/Utils.md | |
*/ | |
function expect(def, target) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test(func, target, iterations = 100000) { | |
const start = Date.now(); | |
for (let i = 0; i < iterations; i++) { | |
func(target.slice(), i); | |
} | |
const end = Date.now(); | |
return { duration: end - start, result: func(target.slice(), 0) }; | |
} | |
function truncate(text, maxLength = 32) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(exports) { | |
'use strict'; | |
class Request { | |
static get METHODS() { | |
return { | |
GET: 'GET', | |
POST: 'POST', | |
PUT: 'PUT', | |
DELETE: 'DELETE', |