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 getOwnPropertyTypes(val) { | |
| 'use strict'; | |
| if (val && typeof val === 'object') { | |
| return Object.getOwnPropertyNames(val) | |
| .reduce((obj, key) => Object.defineProperty(obj, key, { value: typeof val[key] }), {}) | |
| } | |
| return {}; | |
| } |
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
| 'use-strict' | |
| const api = 'https://api.magicthegathering.io/v1' | |
| const dominariaPage1 = fetch(new Request(Resource(Page(1)))) | |
| const dominariaPage2 = fetch(new Request(Resource(Page(2)))) | |
| const dominariaPage3 = fetch(new Request(Resource(Page(3)))) | |
| Promise | |
| .all([dominariaPage1, dominariaPage2, dominariaPage3]) |
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 Freeze(constructor: Function) { | |
| Object.freeze(constructor); | |
| Object.freeze(constructor.prototype); | |
| } |
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 Seal(constructor: Function) { | |
| Object.seal(constructor); | |
| Object.seal(constructor.prototype); | |
| } |
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 delay = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds)); |
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 { defer } from 'rxjs'; | |
| import { map } from 'rxjs/operators'; | |
| export const bufferMaxCount = (count = 0) => source => defer(() => { | |
| let buffer = []; | |
| return source.pipe( | |
| map(next => buffer = [next, ...buffer.slice(0, count - 1)]) | |
| ); | |
| }); |
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 cities = new Map([ | |
| ['MG', 'Belzante'], | |
| ['SP', 'Sampa'] | |
| ]); | |
| const getCity = city => cities.get(city) ?? 'Not found'; |
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 fetchWithRetries = async (url, options, retryCount = 0) => { | |
| const { maxRetries = 3, ...remainingOptions } = options; | |
| try { | |
| return await fetch(url, remainingOptions); | |
| } catch (error) { | |
| if (retryCount < maxRetries) { | |
| return fetchWithRetries(url, options, retryCount + 1); | |
| } |
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
| if (!Object.prototype[Symbol.iterator]) { | |
| Object.prototype[Symbol.iterator] = function* () { | |
| for (let key in this) { | |
| yield this[key]; | |
| } | |
| }; | |
| } |
OlderNewer