Skip to content

Instantly share code, notes, and snippets.

View danieldietrich's full-sized avatar
💭
📡 working from space

Daniel Dietrich danieldietrich

💭
📡 working from space
View GitHub Profile
@danieldietrich
danieldietrich / README.md
Last active February 14, 2024 13:15
The easiest way to bundle a simple TypeScript web application

THIS README IS OUTDATED AND UNMAINTAINED - PLEASE DON'T RELY ON THIS

The easiest way to bundle a simple TypeScript web application

Packaging JavaScript applications can be a bit overwhelming. The popular project uglifyjs does not support ES6, it is cumbersome to configure the allmighty Webpack, bundlers like Parcel and Microbundle still have bugs or do not compile to ESM bundles that work in a browser. It is hard to figure out the best way to bundle an application.

Here I give a small example, how we achieve the goal using the

@danieldietrich
danieldietrich / package.json
Created October 14, 2019 19:13 — forked from jayphelps/package.json
TypeScript output es2015, esm (ES Modules), CJS, UMD, UMD + Min + Gzip. Assumes you install typescript (tsc), rollup, uglifyjs either globally or included as devDependencies
{
"scripts": {
"build": "npm run build:es2015 && npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:umd:min",
"build:es2015": "tsc --module es2015 --target es2015 --outDir dist/es2015",
"build:esm": "tsc --module es2015 --target es5 --outDir dist/esm",
"build:cjs": "tsc --module commonjs --target es5 --outDir dist/cjs",
"build:umd": "rollup dist/esm/index.js --format umd --name YourLibrary --sourceMap --output dist/umd/yourlibrary.js",
"build:umd:min": "cd dist/umd && uglifyjs --compress --mangle --source-map --screw-ie8 --comments --o yourlibrary.min.js -- yourlibrary.js && gzip yourlibrary.min.js -c > yourlibrary.min.js.gz",
}
}
@danieldietrich
danieldietrich / babel-webpack.md
Created October 14, 2019 14:56 — forked from ncochard/babel-webpack.md
The correct way to compile ES6 using babel...

When you create a npm package, remember it might be used in a browser or a server, or even a command line utility… For each package you create, please pay attention at what it will be used for:

  1. Is it going to be used as a dependency to a nodejs application that is not bundled? (e.g. command line utilities)
  2. Is it going to be used as a dependency to a nodejs application that is bundled? (e.g. AWS Lambdas)
  3. Is it going to be used as a dependency to a browser application (always bundled)?.
  • In cases 2) and 3) you want to allow for tree shaking.
  • In cases 1) and 2) you want to benefit from the "ES6"/"ES next" features supported natively by nodejs.
  • In case 3) you also want to benefit from the native support of "ES6" from your browser.
@danieldietrich
danieldietrich / unicode.ts
Created September 5, 2019 06:35
Unicode Dictionary for Slugifying / Hyphenating URLs (see https://github.com/danieldietrich/slugify)
// A subset of Unicode version 12.0
// https://en.wikipedia.org/wiki/List_of_Unicode_characters
// https://en.wiktionary.org/wiki
// Identity translations a-zA-Z0-9 and most punctuations are suppressed.
// Units and currencies and some are translated.
const unicode = {
"Basic Latin": {
// ASCII Punctuation & Symbols
'$': 'dollar',
'%': 'percent',
@danieldietrich
danieldietrich / Fetch.java
Last active August 30, 2019 18:12
Java Fetch
import io.vavr.control.Try;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
public final class Fetch {
@danieldietrich
danieldietrich / vavr-logo-history.txt
Created July 29, 2019 10:18
History of VAVR Logos
2014-2015
/ \____ _ ______ _____ / \____ ____ _____
/ \__ \/ \ / \__ \ / __// \__ \ / \/ __ \
_/ // _\ \ \/ / _\ \\_ \/ // _\ \ /\ \__/ /
/___/ \_____/\____/\_____/____/\___\_____/_/ \_/____/
2015-2016
/ \____ _ _ ____ ______ / \ ____ __ _ _____
/ / \/ \ / \/ \ / /\__\/ // \/ \ / / _ \
_/ / /\ \ \/ / /\ \\__\\ \ // /\ \ /\\/ \__/ /
@danieldietrich
danieldietrich / scratchbook.md
Created May 26, 2019 11:46
Markdown enumerated list

List

  1. first
  2. second
  3. third
@danieldietrich
danieldietrich / README.md
Last active September 25, 2022 21:10
Deeply merging JavaScript objects

Deeply merging JavaScript objects

This method is like Object.assign except that it recursively merges own enumerable string keyed properties of source objects into the destination object. Source properties that resolve to undefined are skipped if a destination value exists. Arrays are concatenated. Plain object properties are merged recursively. Other objects and value types are overridden by assignment. Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources.

Note: This method mutates target.

Motivation

  • The native Object.assign does simply overwrite values on duplicate keys.
  • The Lodash _.merge does not handle arrays the way I would expect it:
@danieldietrich
danieldietrich / .bash_profile
Last active February 22, 2019 08:53
Git prompt
# -----------------------------------------------------------------------------
# This is a fragment of ~/.bash_profile that adds git status and branch
# information to the terminal prompt. The 'colors' section is optional.
# -----------------------------------------------------------------------------
# prompt
export PS1="\[\e[0;32m\]\u@\h:\[\e[1;36m\]\w\[\e[0;33m\]\$(parse_git_status)\[\e[1;32m\]\$(parse_git_branch)\[\e[1;36m\] $\[\e[0m\] "
# colors
export TERM=xterm-color
@danieldietrich
danieldietrich / README.md
Last active January 19, 2019 14:14
Howto install a new JDK on a Mac

Howto install a new JDK on a Mac

  1. Download JDK: http://jdk.java.net/13/ to ~/Downloads
  2. Unpack downloaded .tar.gz bundle
  3. Goto base dir cd /Library/Java/JavaVirtualMachines
  4. Move unpacked JDK mv ~/Downloads/jdk-13.jdk .
  5. Change owner sudo chown -R root jdk-13.jdk/
  6. Change group sudo chgrp -R wheel jdk-13.jdk/
  7. Remove quarantaine flag sudo xattr -dr com.apple.quarantine jdk-13.jdk
  8. Create symlink sudo ln -s jdk-13.jdk/ jdk13