View draggable.ts
import {Chart as ChartJsChart, ChartOptions} from 'chart.js'; | |
import {D3DragEvent, drag} from 'd3-drag'; | |
import {select} from 'd3-selection'; | |
type ChartElement = any; | |
type Chart = ChartJsChart & {options: ChartOptions & DraggableOptions}; | |
type DragEvent = D3DragEvent<ChartElement, number, number>; | |
enum DragEventType { | |
Start = 'start', |
View 99-bottles.ts
const capitalize = (word: string) => word[0].toUpperCase() + word.substr(1); | |
const pluralize = (word: string, amount: number) => { | |
if (amount > 1) return `${amount} ${word}s`; | |
if (amount === 1) return `${amount} ${word}`; | |
return `no more ${word}s`; | |
}; | |
const countBottles = (amount: number) => | |
`${pluralize("bottle", amount)} of beer`; |
View use-date-formatting.ts
import { | |
format, | |
formatDistance, | |
formatDistanceStrict, | |
formatRelative, | |
} from 'date-fns'; | |
import {useRouter} from 'next/router'; | |
import {useEffect, useState} from 'react'; | |
const noop = () => {}; |
View graphql.ts
import {isProduction} from '@/utils'; | |
import {Executor} from '@graphql-tools/delegate'; | |
import {makeExecutableSchema} from '@graphql-tools/schema'; | |
import {stitchSchemas} from '@graphql-tools/stitch'; | |
import {introspectSchema, wrapSchema} from '@graphql-tools/wrap'; | |
import {graphqlHTTP} from 'express-graphql'; | |
import {GraphQLSchema, print} from 'graphql'; | |
import fetch from 'isomorphic-unfetch'; | |
import {NextApiRequest, NextApiResponse} from 'next'; | |
import getConfig from 'next/config'; |
View .eslintrc.js
module.exports = { | |
extends: ['./node_modules/gts'], | |
overrides: [ | |
{ | |
extends: ['plugin:react/recommended', 'plugin:react-hooks/recommended'], | |
files: ['*.ts', '*.tsx'], | |
rules: { | |
'@typescript-eslint/no-explicit-any': 'off', | |
'react-hooks/exhaustive-deps': 'warn', | |
'react-hooks/rules-of-hooks': 'error', |
View generate-favicons.ts
// eslint-disable-next-line node/no-unpublished-import | |
import favicons from 'favicons'; | |
import fs from 'fs'; | |
const [, , source] = process.argv; | |
if (!source) { | |
throw new Error('You need to specify a `source`.'); | |
} |
View pull-schema.ts
import {writeFileSync} from 'fs'; | |
import fetch from 'isomorphic-unfetch'; | |
const [, , schemaPath] = process.argv; | |
const dgraphUrl = process.env.DGRAPH_URL; | |
const dgraphToken = process.env.DGRAPH_TOKEN; | |
if (!dgraphUrl) { | |
throw new Error('You need to specify `DGRAPH_URL` in your environment.'); |
View loader-example.tsx
import React from 'react'; | |
export default function LoaderExample() { | |
comst {data, loading, error} = useMyQuery(); // Implementation specific | |
const {Loader, data: myData} = useLoader({ | |
data, | |
errorMessage: error?.message, | |
isLoading: loading, | |
}); | |
return ( |
View modal-example.tsx
import React from 'react'; | |
import {Button} from '@/design-system'; | |
import {useModal} from './modal'; | |
export default function ModalExample() { | |
const {Modal, closePortal, openPortal} = useModal(); | |
return ( | |
<> | |
<Button onClick={openPortal}>Open modal</Button> | |
<Modal> |
View pipe.ts
type OperatorFn<T> = (value: T) => T; | |
interface PipeFn { | |
<T>(...fns: OperatorFn<T>[]): (value: T) => T; | |
} | |
const pipe: PipeFn = (...fns) => value => | |
fns.reduce((val, fn) => fn(val), value); | |
export default pipe; |
NewerOlder