Skip to content

Instantly share code, notes, and snippets.

@aleclarson
aleclarson / rollup-typescript.md
Last active April 7, 2024 14:13
The best Rollup config for TypeScript libraries

Features

🔥 Blazing fast builds
😇 CommonJS bundle
🌲 .mjs bundle
.d.ts bundle + type-checking
🧐 Source maps

Install

const React = require('react')
const ReactDOMServer = require('react-dom/server')
const { createServer } = require('http')
const App = require('./build/static/js/main.49fed57c').default
createServer((req, res) => {
const el = React.createElement(App)
const html = ReactDOMServer.renderToString(el)
res.write(html)
res.end()
@DavidKuennen
DavidKuennen / minimal-analytics-snippet.js
Last active March 28, 2024 01:45
Minimal Analytics Snippet
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
@s-panferov
s-panferov / option.ts
Created November 30, 2014 12:15
Option and Result types from Rust in TypeScript
interface Option<T> {
map <U>(fn: (a: T) => U): Option<U>;
isSome(): boolean;
isNone(): boolean;
isSomeAnd(fn: (a: T) => boolean): boolean;
isNoneAnd(fn: () => boolean): boolean;
unwrap(): T;
unwrapOr(def: T): T;
unwrapOrElse(f: () => T): T;
map<U>(f: (a: T) => U): Option<U>;