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 type CamelCase<S extends string> = | |
S extends `${infer P1}_${infer P2}${infer P3}` | |
? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}` | |
: Lowercase<S>; | |
export type ObjectToCamel<T> = { | |
[K in keyof T as CamelCase<string & K>]: T[K] extends Record<string, any> | |
? KeysToCamelCase<T[K]> | |
: T[K]; | |
}; |
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
interface Curry { | |
<T1, R>(func: (t1: T1) => R): CurriedFunction1<T1, R>; | |
<T1, T2, R>(func: (t1: T1, t2: T2) => R): CurriedFunction2<T1, T2, R>; | |
<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R): CurriedFunction3< | |
T1, | |
T2, | |
T3, | |
R | |
>; | |
<T1, T2, T3, T4, R>( |
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
import { renderHook } from '@testing-library/react-hooks'; | |
import useFetch from '../useFetch'; | |
function mockSuccessfulFetch(data) { | |
global.fetch = jest.fn().mockResolvedValue({ | |
json: () => Promise.resolve(data), | |
}); | |
} | |
function mockErrorFetch(error) { |
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
/* eslint-disable no-restricted-syntax, no-console, no-await-in-loop */ | |
const { promises: fs } = require("fs"); | |
const { exec } = require("child_process"); | |
const TEST_COMMANDS = [ | |
"yarn check-types", | |
"yarn lint", | |
"yarn test", | |
"yarn build", | |
]; |
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 isArray = function (a) { | |
return Array.isArray(a); | |
}; | |
const isObject = function (o) { | |
return o === Object(o) && !isArray(o) && typeof o !== 'function'; | |
}; | |
const toCamel = s => ( | |
s.replace(/([-_][a-z])/ig, $1 => $1.toUpperCase().replace(/[-_]/, '')) |
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 toCamel = (s) => { | |
return s.replace(/([-_][a-z])/ig, ($1) => { | |
return $1.toUpperCase() | |
.replace('-', '') | |
.replace('_', ''); | |
}); | |
}; | |
const toSnake = (s) => { | |
return s.split(/(?=[A-Z])/).join('_').toLowerCase(); |
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
import React from 'react'; | |
import useWindowEvent from './useWindowEvent'; | |
function Example() { | |
useWindowEvent('keydown', (e) => { | |
console.log('Pressed', e.key); | |
}); | |
return <div>Example</div>; |
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 findVideos = () => [...document.querySelectorAll('.pl-video')]; | |
const watchedGreaterThanHalf = (video) => { | |
const progressBar = video.querySelector('.resume-playback-progress-bar'); | |
return progressBar && parseInt(progressBar.style.width) > 50; | |
} | |
const removeButton = (video) => x.querySelector('.pl-video-edit-remove'); | |
const click = (button) => button.click(); |
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
'use strict'; | |
function addHeader(headers, key, value) { | |
if (!headers[key.toLowerCase()]) { | |
headers[key.toLowerCase()] = [{ | |
key, | |
value, | |
}]; | |
} | |
} |
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
// Lets say you have a function that creates adders, for adding two numbers | |
function makeAdder(firstNumber) { | |
return function(secondNumber) { | |
return firstNumber + secondNumber; | |
}; | |
} | |
let result |
NewerOlder