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
/** | |
* Searches for a comment in target document | |
* | |
* @author Gabe M | |
* @param {string} commentText - Comment text to search for | |
* @param {Node} [target=document] - Parent target to search through | |
* @return {Array<Node>} | |
*/ | |
function getCommentsByText(commentText, target = document) { | |
const nodeList = []; |
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
/** | |
* Higher order function which handles | |
* key presses "onKeyDown". | |
* | |
* Passes event to function. | |
* | |
* @param {Function} fn - Function to be invoked with event | |
* @return {function(Event): any} | |
*/ | |
const clickKeyPress = (fn) => (ev) => { |
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
package middlware | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
) | |
// MiddlewareNext invokes the next middleware | |
type MiddlewareNext func() |
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
export default function truncateToDecimal(number, precision = 0) { | |
const floatStr = number.toString(); | |
const index = floatStr.indexOf('.'); | |
// Return number if not a float | |
if (index === -1) { | |
return number; | |
} | |
// Truncate the string starting at the decimal plus any added precision | |
// Increment by 1 to include the specified precision | |
const truncated = floatStr.substring(0, index + precision + 1); |
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
/** | |
* Combines reducers with root reducer | |
* | |
* @param {function(Object, Object): Object} rootReducer | |
* @param {Object<string, function(Object, Object): Object>} [reducers={}] | |
* @returns {function(Object, Object): Object} | |
*/ | |
export default function combineReducersWithRoot(rootReducer, reducers = {}) { | |
const entries = Object.entries(reducers); |
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
/** | |
* Coverts a Javascript string to a | |
* unsigned 8 byte int ArrayBuffer | |
* | |
* @param {string} string - Binary String | |
* @returns {Uint8Array} | |
*/ | |
export default function stringToArrayBuffer(string) { | |
const { length } = string; | |
const buffer = new Uint8Array(length); |
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
/** | |
* Memoize a async function (any function which returns a promise) | |
* | |
* @param {Function} func - Function which returns a promise | |
* @param {boolean} [cacheError=false] - Should cache promise rejections | |
* @param {Function} [resolver] - Resolves cache key. Uses first arg as default | |
* @returns {Function.<Promise>} - Returns memoized function | |
*/ | |
export default function memoizeAsync(func, cacheError = false, resolver) { | |
const cache = new Map(); |
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
/** | |
* Resolves passed function after timeout | |
* | |
* @param {number} timeout | |
* @param {Function} fn | |
* @return {Promise<any>} | |
*/ | |
export default function wait(timeout, fn) { | |
return new Promise((resolve) => { | |
setTimeout(() => resolve(fn()), timeout); |
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 FetchRes<T> = Response & { | |
data: T; | |
}; | |
/** | |
* A Fetch Request that errors on non 2xx status codes | |
*/ | |
export default function betterFetch<T>( | |
input: RequestInfo, | |
init?: RequestInit |
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 GetValue<Obj, Key extends keyof Obj | undefined, Default> = Key extends undefined | |
? Default | |
: Obj[Key]; | |
/** Usage */ | |
type BlueDefault = '#0078d7'; | |
type BlueShades = { | |
50: '#e6f1fb', |