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 withMemoization(func, identifierFunc) { | |
| const cache = new Map() | |
| return (...args) => { | |
| const identifier = identifierFunc(...args) | |
| if (cache.has(identifier)) { | |
| return cache.get(identifier) | |
| } | |
| const result = func(...args) | |
| cache.set(identifier, result) |
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 chainable(obj) { | |
| const proxy = new Proxy(obj, { | |
| get(target, prop) { | |
| return typeof target[prop] === 'function' | |
| ? (...args) => target[prop](...args) || proxy | |
| : target[prop] | |
| }, | |
| }) | |
| return proxy | |
| } |
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 download(filename, text) { | |
| Object.assign(document.createElement("a"), { | |
| download: filename, | |
| href: "data:text/plain;charset=utf-8," + encodeURIComponent(text), | |
| }).click(); | |
| } |
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 secs2Time = (secs) => { | |
| const hours = Math.floor(secs / 60 / 60).toString().padStart(2, 0) | |
| return hours + ':' + new Date(secs * 1000).toISOString().substr(14, 5) | |
| } |
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
| async function fetchLink(q) { | |
| const htmlStr = await fetch( | |
| 'https://duckduckgo.com/?q=' + q + '&ia=web' | |
| ).then((r) => r.text()) | |
| return `https://links.duckduckgo.com/${htmlStr.match(/\/(d.js.+?)&p_ent/)[1]}` | |
| } | |
| async function fetchDuck(q) { | |
| function transform({ u, t, a, i }) { | |
| 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
| function css(obj) { | |
| return Object.keys(obj) | |
| .map((key) => { | |
| const newKey = key.replace( | |
| /[A-Z]/, | |
| (match, index) => "-" + match.toLowerCase() | |
| ); | |
| return `${newKey}:${obj[key]};`; | |
| }) | |
| .join("\n"); |
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 parseToDOM = Range.prototype.createContextualFragment.bind( | |
| document.createRange() | |
| ); |
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 functionalize = (arr) => { | |
| const result = {}; | |
| for (let funcOrArr of arr) { | |
| const [func, indexOfData = 0] = | |
| funcOrArr.constructor.name === "Array" ? funcOrArr : [funcOrArr]; | |
| const name = func.name || func; | |
| result[name] = | |
| (...args) => | |
| (data) => { |
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 fetch = (...args) => | |
| import("node-fetch").then(({ default: fetch }) => fetch(...args)); | |
| const { buildQueryStr, timeTaken } = require("./helpers.js"); | |
| async function getSource({ q, ...params } = {}, page = 1) { | |
| if (!q) throw Error("{ q } is a manadatory parameter!"); | |
| const url = | |
| `https://www.google.com/search?` + | |
| buildQueryStr({ |
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 scrollToBottom() { | |
| const scrollingElement = document.scrollingElement || document.body; | |
| scrollingElement.scrollTop = scrollingElement.scrollHeight; | |
| } |