Skip to content

Instantly share code, notes, and snippets.

View jkrems's full-sized avatar
Modules. Modules everywhere.

Jan Olaf Martin jkrems

Modules. Modules everywhere.
View GitHub Profile
@jkrems
jkrems / README.md
Last active May 4, 2024 23:10
Prefers-Color-Scheme: Site Override

Motivation: What's a "User Preference"?

Supposedly, the prefers-* media features represent the preferences of the user. And in some cases, that is true: User agents dutifully report what the user configured at the OS- or browser-level. And websites are encouraged to accommodate those wishes.

But the model breaks when the user has site-specific preferences. Suddenly the responsibility of keeping track and faithfully representing the user's preferences falls on the site and the user agent's view of the "preference" is plain wrong.

This leaves websites two options:

  1. Ignore the user's real preference for their site and only honor the system-level configuration.
  2. (Mostly) ignore the CSS media feature, outside of gathering initial default values via JS.
@jkrems
jkrems / es-module-history.md
Last active November 5, 2023 19:35
History of ES modules

Modules - History & Future

History

@jkrems
jkrems / index.md
Last active November 3, 2023 14:34
JavaScript: Classic Scripts vs. Modules vs. CommonJS

JavaScript File Format Differences

There's the pervarsive notion that all JS is created equal and that there's only minor and easily detectable differences between the various file formats used to author JavaScript. This is correct, from a certain point of view.

A certain point of view?

For many people writing JavaScript that gets passed into build tools,

@jkrems
jkrems / gh.sh
Created July 7, 2020 16:24
Switch to Github repo checkout, clone if it doesn't exist yet
# Usage: gh <org-or-user>/<repo>
# Example: gh nodejs/node
gh () {
local repo=$1
local target="$HOME/code/src/github.com/$1"
local url="git@github.com:$repo.git"
if [[ ! -d "$target" ]]
then
git clone "$url" "$target"
fi
@jkrems
jkrems / ok.js
Last active June 8, 2020 18:54
Exports Hash
module.exports = 'ok';
@jkrems
jkrems / _.md
Last active February 27, 2020 15:51
Observe compilation cache collision

Repro

  1. Start the server via node server.js.
  2. Open http://localhost:3000.
  3. If the compilation cache leads to bad meta data in dynamic import, the message should only be logged once. ‎‎​
@jkrems
jkrems / generators.md
Last active February 24, 2020 19:09
Generators Are Like Arrays

In all the discussions about ES6 one thing is bugging me. I'm picking one random comment here from this io.js issue but it's something that comes up over and over again:

There's sentiment from one group that Node should have full support for Promises. While at the same time another group wants generator syntax support (e.g. var f = yield fs.stat(...)).

People keep putting generators, callbacks, co, thunks, control flow libraries, and promises into one bucket. If you read that list and you think "well, they are all kind of doing the same thing", then this is to you.

@jkrems
jkrems / .gitignore
Last active February 13, 2020 02:14
Node globals handling in Typescript
/node_modules
/input.js
@jkrems
jkrems / playground.json
Created February 5, 2020 21:53
reglang
{
"scripts": [],
"showConsole": true,
"scriptType": "module"
}
@jkrems
jkrems / index.html
Last active February 5, 2020 21:52
reglang
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<h1>RegLang</h1>
<pre id="result"></pre>
<script src="/script.mjs" type="module"></script>
</body>