A curated set of high-quality, well-tested browser modules
npm install internalA curated set of high-quality, well-tested, minimal browser modules.
Each module has high test-coverage and is tested against Chrome, Firefox and Webkit.
``sh`
npm install internal
A few examples below but see the src/ directory for the list of modules and the tests for usage.
Handle errors more gracefully.
`ts
import maybe from "internal/maybe"
const res = await maybe(fetch("http://mat.tm"))
if (res instanceof Error) {
console.error(res)
return
}
const text = await res.text()
`
Gets the typeof a value at runtime.
`ts`
import typeOf from "internal/typeof"
typeOf("hello") // "string"
typeOf(/asdf/) // "regexp"
A promise you can pass around.
`ts
import Deferred from "internal/deferred"
const deferred = new Deferred()
doSomething(deferred)
const res = await deferred
function doSomething(deferred) {
setTimeout(() => {
deferred.resolve("ok")
}, 1000)
}
`
Ensures that whatever comes back is an Error.
`ts`
import ensureError from "internal/ensure-error"
const err = ensureError("oh no")
err instanceof Error // true
`sh
git clone https://github.com/matthewmueller/internal
MIT