A simple module for helping you write debugger outputs. Makes debug outputs look neat and organized.
Copy and paste the index.ts
file to some debug.ts
file.
import createDebugger from './debug';
type Pipe<T> = { | |
_<V>(fn: (value: T) => V): Pipe<V>; | |
readonly value: T; | |
}; | |
function start<T>(initial: T): Pipe<T> { | |
return { | |
_<V>(fn: (value: T) => V): Pipe<V> { | |
return start(fn(initial)); | |
}, |
export type Listener<T> = (value: T) => void; | |
export type OperatorFunction<T, V> = ( | |
oberver: IObservable<T> | |
) => IObservable<V>; | |
export interface IObservable<T> { | |
subscribe(listner: Listener<T>): () => void; | |
} |
import { useEffect, useRef, useState } from "react"; | |
export default function ExpandableInput( | |
props: React.DetailedHTMLProps< | |
React.InputHTMLAttributes<HTMLInputElement>, | |
HTMLInputElement | |
> | |
) { | |
const [value, setValue] = useState(props.value); | |
const inputRef = useRef<HTMLInputElement | null>(null); |
export type Links = { [key: string]: Link }; | |
export type StatusCode = | |
| "400" | |
| "401" | |
| "402" | |
| "403" | |
| "404" | |
| "405" | |
| "406" |
const path = require("path"); | |
module.exports = { | |
entry: "./src/index.js", | |
output: { | |
path: path.resolve(__dirname, "dist"), | |
filename: "bundle.js", | |
libraryTarget: "commonjs", | |
}, | |
devtool: "source-map", |
/** | |
* This is a class that is analogous to the DOM's `EventTarget` API. | |
* | |
* It is the class for adding event listeners, and emitting events. | |
* | |
* Usage: | |
* | |
* const emitter = new EventEmitter() | |
* | |
* emitter.addEventListener('foo', (value) => { |
This was my attempt at implementing the TC39's observable proposal.
Unfortunately, way too many tests fail.
If you want, you can give it a try to have all the tests pass.
// If I don't care about the status code | |
function fetchJSON(...params) { | |
return fetch(...params).then(res => res.json()); | |
} | |
// If I do care about the status code, but don't care about the type of error. | |
async function fetchJSON(...params) { | |
const res = await fetch(...params); | |
if (res.status >= 400) { | |
throw new Error(res.statusText); |