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
    
  
  
    
  | export type Epoch = | |
| | "millisecond" | |
| | "milliseconds" | |
| | "ms" | |
| | "second" | |
| | "seconds" | |
| | "sec" | |
| | "s" | |
| | "minute" | |
| | "minutes" | 
  
    
      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
    
  
  
    
  | import { Deferred } from "https://deno.land/std@0.161.0/async/deferred.ts"; | |
| export interface DeferredPromise<T> extends Promise<T> { | |
| readonly state: Deferred<T>["state"]; | |
| } | |
| export function createDeferredPromise<T>( | |
| deferred: Deferred<T> | |
| ): DeferredPromise<T> { | |
| const promise = new Promise((resolve, reject) => { | 
  
    
      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 waitForTimeout = ( | |
| fn: (args?: unknown[]) => void | Promise<void>, | |
| timeout: number, | |
| ...args: any[] | |
| ): Promise<void> => { | |
| return new Promise((resolve) => { | |
| const timeoutId = setTimeout( | |
| async (args) => { | |
| await fn(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
    
  
  
    
  | export function isJSON(str: unknown) { | |
| if (typeof str !== "string") return false; | |
| try { | |
| const result = JSON.parse(str); | |
| const type = Object.prototype.toString.call(result); | |
| return type === "[object Object]" || | |
| type === "[object Array]"; | 
  
    
      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 ArrayBufferView = | |
| Object.getPrototypeOf(Object.getPrototypeOf(new Uint8Array())).constructor; | |
| export function isAbv(value: unknown) { | |
| return value instanceof ArrayBufferView; | |
| } | 
  
    
      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
    
  
  
    
  | type Fn< | |
| Params extends readonly unknown[] = readonly unknown[], | |
| Result = unknown, | |
| > = (...params: Params) => Result; | |
| export class EnhancedSet<T> extends Set<T> { | |
| map(func: Fn<[T], T>): EnhancedSet<unknown> { | |
| const newSet = new EnhancedSet(); | |
| for (const value of this) { | 
  
    
      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
    
  
  
    
  | export type ValueAndKeyFunction<K = unknown, V = unknown, R = unknown> = ( | |
| value: V, | |
| key?: K, | |
| map?: EnhancedMap<K, V>, | |
| ) => R; | |
| // deno-lint-ignore no-explicit-any | |
| export class EnhancedMap<K = any, V = any> extends Map<K, V> { | |
| map<TK = unknown, TV = unknown>( | |
| func: ValueAndKeyFunction<K, V, [TK, TV]>, | 
  
    
      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
    
  
  
    
  | export const createMapEntryIfNotExistsAndGet = <K = unknown, T = unknown>( | |
| map: Map<K, T>, | |
| name: K, | |
| value: T, | |
| ) => { | |
| if (map.has(name)) { | |
| return map.get(name)!; | |
| } | |
| return map.set(name, value).get(name)!; | 
  
    
      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
    
  
  
    
  | type Epoch = 'years' | 'months' | 'days' | 'hours' | 'minutes' | 'seconds' | 'now'; | |
| const epochs: Record<Epoch, number> = { | |
| years: 31536000, | |
| months: 2592000, | |
| days: 86400, | |
| hours: 3600, | |
| minutes: 60, | |
| seconds: 1, | |
| now: 0, |