Skip to content

Instantly share code, notes, and snippets.

View kyusu's full-sized avatar

急須 kyusu

  • Stuttgart, Germany
  • 15:03 (UTC +02:00)
View GitHub Profile
@sindresorhus
sindresorhus / esm-package.md
Last active August 30, 2025 02:23
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@karol-majewski
karol-majewski / 0. What are type guards.ts
Last active September 18, 2021 13:14
Snippets used in my talk “Who Guards the Type Guards?” (https://www.youtube.com/watch?v=StyKp5dgN_Y)
/**
* A.K.A. type guard
*/
type Refinement<T, U extends T> = (candidate: T) => candidate is U;
function isString(candidate: unknown): candidate is string {
return typeof candidate === 'string';
}
@dypsilon
dypsilon / reader-t.js
Last active October 28, 2020 22:25
A simple example of using Reader transformer to combine reader and future.
const {tagged} = require('daggy');
// const
const K = (a) => (b) => a;
// Reader Transformer
module.exports = (M) => {
const ReaderT = tagged('run');
ReaderT.lift = (m) => ReaderT(K(m));