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 caps = Array.from('ABCDEFGHIJKLMNOPQRSTUVWXYZ'), | |
| lower = Array.from('abcdefghijklmnopqrstuvwxyz'), | |
| numbers = Array.from('0123456789') | |
| export function symbols(set = 'all') | |
| { | |
| return set === 'all' ? Array.from([...caps,...lower,...numbers]) : Array.from({ caps, lower, numbers }[set]) | |
| } | |
| export function rndstring(length = 7, signs = 'all') |
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
| /** | |
| * @param {String} data | |
| * @return {{data: String|null, type: String|null}} | |
| */ | |
| export function dataURLMime(data) | |
| { | |
| const decompose = { type: null, data: null }, | |
| regexp = /data:(image\/.+);base64,/ | |
| decompose.data = data.replace(regexp, (h, t) => { |
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 getUserAgent({ brands = [] }) | |
| { | |
| let agent | |
| test: for (const { brand, version } of brands) switch (true) { | |
| case ['Chromium','Google Chrome','CriOS'].includes(brand): | |
| agent = `Chrome/${version}` | |
| break | |
| case ['Firefox'].includes(brand): |
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
| /** | |
| * @param {Function} job | |
| * @return {function(*=): Promise<unknown>} | |
| */ | |
| export function workerInit(job) | |
| { | |
| const url = window.URL.createObjectURL(new Blob( | |
| [`"use strict";\nself.onmessage = ${job.toString()}`], | |
| { type: 'text/javascript' } | |
| )) |
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
| /** | |
| * @param {Function} fn | |
| * @return {Function} | |
| */ | |
| export function createCachedFunction(fn) | |
| { | |
| const handler = { | |
| cache: {}, | |
| apply(target, that, args) |
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
| /** @see https://gist.github.com/alekstar79/11125248f8dc609f5c8dcba3e0f75b5e */ | |
| import { createCachedFunction } from './cached.mjs' | |
| /** @see https://gist.github.com/alekstar79/042a211b62203f1439f2012ce6aa9f55 */ | |
| import { workerInit } from './worker.mjs' | |
| /** | |
| * @param {function} worker | |
| * @return {function(*=): Promise<unknown>} | |
| * @example |
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 h2sl = (hex, isString) => { | |
| // Convert hex to RGB first | |
| let r = 0, g = 0, b = 0 | |
| if (hex.length == 4) { | |
| r = "0x" + hex[1] + hex[1] | |
| g = "0x" + hex[2] + hex[2] | |
| b = "0x" + hex[3] + hex[3] | |
| } else if (hex.length == 7) { | |
| r = "0x" + hex[1] + hex[2] |
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 pipe(...fn) { | |
| return function piped(...args) { | |
| return fn.reduce((result, f) => [f.call(this, ...result)], args)[0] | |
| } | |
| } |
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 pick(obj, keys) { | |
| return keys.reduce((acc, key) => { | |
| if (obj.hasOwnProperty(key)) { | |
| acc[key] = obj[key] | |
| } | |
| return acc | |
| }, {}) | |
| } |
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 omit(obj, keys) { | |
| return Object.keys(obj) | |
| .filter(key => !keys.includes(key)) | |
| .reduce((acc, key) => { | |
| acc[key] = obj[key] | |
| return acc | |
| }, {}) | |
| } |