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
// Types for the result object with discriminated union | |
type Success<T> = { | |
data: T; | |
error: null; | |
}; | |
type Failure<E> = { | |
data: null; | |
error: E; | |
}; |
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 addDay = (days = 1) => { | |
const date = new Date() | |
date.setDate(date.getDate() + days) | |
return date | |
} |
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
function waitForElm <T extends Element> (selector: string): Promise<T | null> { | |
return new Promise(resolve => { | |
if (document.querySelector(selector)) { | |
return resolve(document.querySelector(selector) as T | null); | |
} | |
const observer = new MutationObserver(() => { | |
if (document.querySelector(selector)) { | |
resolve(document.querySelector(selector) as T | null); |
This file has been truncated, but you can view the full file.
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
{"words":[{"word":"a","id":1},{"word":"a-","id":2},{"word":"a2 level","id":3},{"word":"a3","id":4},{"word":"a4","id":5},{"word":"a5","id":6},{"word":"aaa","id":7},{"word":"aaas","id":8},{"word":"aad","id":9},{"word":"aadhaar","id":10},{"word":"aam","id":11},{"word":"a — and a half","id":12},{"word":"aapa","id":13},{"word":"aardwolf","id":14},{"word":"aargh","id":15},{"word":"aaronic","id":16},{"word":"aaron's beard","id":17},{"word":"aaron's rod","id":18},{"word":"aarp","id":19},{"word":"a'asia","id":20},{"word":"aasvoel","id":21},{"word":"aau","id":22},{"word":"aaup","id":23},{"word":"ab","id":24},{"word":"ab-","id":25},{"word":"aba","id":26},{"word":"a bad apple","id":27},{"word":"a bad lot","id":28},{"word":"a bad penny always turns up","id":29},{"word":"a bad taste in someone's mouth","id":30},{"word":"a bad workman always blames his tools","id":31},{"word":"a bag of bones","id":32},{"word":"a bag of tricks","id":33},{"word":"abaht","id":34},{"word":"abandon","id":35},{"word":"abandoned","id":36},{"word": |
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 createElement = (HTMLElementName, { ...HTMLAttributes } = {}) => { | |
const $el = document.createElement(HTMLElementName) | |
for (const key in HTMLAttributes) { | |
$el.setAttribute(key, HTMLAttributes[key]) | |
} | |
return $el | |
} |
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
class Observer { | |
#id | |
#container | |
constructor() { | |
this.#id = 0 | |
this.#container = {} | |
} | |
subscribe(topic, f) { |
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
class Observable { | |
constructor(observer){ | |
this._observer = observer; | |
} | |
subscribe(observer) { | |
return this._observer(observer) | |
} | |
} |
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 memoizer = (fn, initialState = null) => { | |
const _cache = initialState || {} | |
return (...params) => { | |
const _stringified = JSON.stringify(params) | |
if (_cache[_stringified] === undefined) { | |
const result = fn(...params) | |
_cache[_stringified] = result |
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
function sortVersions (versions = []) { | |
const sortByVersionNumber = (vA, vB) => { | |
const versionsA = vA.split('.') | |
const versionsB = vB.split('.') | |
const compareVersionNumbers = (index = 0, lastResult = 0) => { | |
const versionNumberA = Number(versionsA[index]) || 0 | |
const versionNumberB = Number(versionsB[index]) || 0 | |
if (lastResult === 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
function promiseAll (promises = []) { | |
return new Promise((resolve, reject) => { | |
let result = [] | |
let resolvedPromisesCount = 0 | |
const handle = (index, data) => { | |
if (data instanceof Error) { | |
return reject(data) | |
} |
NewerOlder