This file contains 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
type OnPromiseProgressCallback = (resolvedPromises: number) => void; | |
/** | |
* Run `Promise.all` for all given promises inside an array. | |
* For each item complete it will call the given `onProgress` callback. | |
* | |
* NOTE: It will call the `onProgress` at the end as well, since asynchronous | |
* code is a mess to deal with in Javascript. | |
*/ | |
const promiseAllWithProgress = async <TResult>( |
This file contains 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
type ValidateRuleFn<T> = (data: T) => string[] | null | |
type Priority = 'WARN' | 'ERROR' | |
type RuleTuple<T> = [priority: Priority, validateRule: ValidateRuleFn<T>] | |
type ValidationResult = { errors: string[], warnings: string[] } | |
const RESULT_KEYS: Record<Priority, string> = { | |
ERROR: 'errors', |
This file contains 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 hash = (str: string) => { | |
let value = 0; | |
for (let i = 0; i < str.length; i += 1) { | |
const current = str.charCodeAt(i); | |
value += current << (i % 16); | |
} | |
return value.toString(16).padStart(16, '0'); |
This file contains 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 createPageOptions = ((currentPage, pageCount) => { | |
// from component properties | |
const currentPage = currentPage | |
// from Constants | |
const NUM_OF_PAGE_OPTIONS = 7 | |
// useMemo with [currentPage] as deps | |
const pageOptions = (() => { | |
if (pageCount <= 0) return [] |
This file contains 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
import { isNumber, isBetween } from './numbers' | |
type ARGB32 = number | |
/** | |
* Represents a red-green-blue key-value object. | |
* all values are limited from 0 to 255 when used internally. | |
*/ | |
type RGB = { red: number; green: number; blue: number } | |
type RGBA = RGB & { alpha: number } | |
type RGBA32 = number |
This file contains 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 {Array<T>} array The array to be sorted. | |
* @param {number} size The size of the array. | |
* @returns {Array<Array<T>>} The sorted array. | |
* @template {T} T The type of the array. | |
*/ | |
function splitArrayBySize<T>(array: Array<T>, size: number): Array<Array<T>> { | |
if (!Array.isArray(array)) { | |
throw new TypeError(`Expected an array, received ${typeof array}`) |
This file contains 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
[ | |
"af-ZA", | |
"am-ET", | |
"ar-AE", | |
"ar-BH", | |
"ar-DZ", | |
"ar-EG", | |
"ar-IQ", | |
"ar-JO", | |
"ar-KW", |
This file contains 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
type LocaleTag = "af-ZA" | "am-ET" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-OM" | "ar-QA" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "arn-CL" | "as-IN" | "az-Cyrl-AZ" | "az-Latn-AZ" | "az-az" | "ba-RU" | "be-BY" | "bg-BG" | "bn-BD" | "bn-IN" | "bo-CN" | "br-FR" | "bs-Cyrl-BA" | "bs-Latn-BA" | "ca-ES" | "co-FR" | "cs-CZ" | "cy-GB" | "da-DK" | "de-AT" | "de-CH" | "de-DE" | "de-LI" | "de-LU" | "dsb-DE" | "dv-MV" | "el-CY" | "el-GR" | "en-029" | "en-AU" | "en-BZ" | "en-CA" | "en-GB" | "en-IE" | "en-IN" | "en-JM" | "en-MT" | "en-MY" | "en-NZ" | "en-PH" | "en-SG" | "en-TT" | "en-US" | "en-ZA" | "en-ZW" | "en-cb" | "es-AR" | "es-BO" | "es-CL" | "es-CO" | "es-CR" | "es-DO" | "es-EC" | "es-ES" | "es-GT" | "es-HN" | "es-MX" | "es-NI" | "es-PA" | "es-PE" | "es-PR" | "es-PY" | "es-SV" | "es-US" | "es-UY" | "es-VE" | "et-EE" | "eu-ES" | "fa-IR" | "fi-FI" | "fil-PH" | "fo-FO" | "fr-BE" | "fr-CA" | "fr-CH" | "fr-FR" | "fr-LU" | "fr-MC" | "fy-NL" | "ga |
This file contains 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
/** | |
* Wait for given amount of milliseconds. | |
* @param {number} ms time in milliseconds. | |
* @returns {Promise<void>} | |
*/ | |
const wait = async (ms: number): Promise<void> => | |
new Promise(resolve => void setTimeout(resolve, ms)) |
This file contains 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
/** | |
* Creates a timer | |
* @param {number} secondsAmount Amount of time in seconds | |
* @param {number} minutesAmount Amount of time in minutes | |
* @param {number} hoursAmount Amount of time in hours | |
* @param {number} daysAmount Amount of time in days | |
* @returns an object representing the timer. | |
*/ | |
function createTimer( | |
secondsAmount = 0, |