This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create an array of string literal where all types are required and allowed just once | |
* | |
* ```ts | |
* // Example usage: Make sure test.each() covers all cases for a string literal type | |
* type UserTypes = "admin" | "user" | "anonymous"; | |
* | |
* test.each(["admin", "user", "anonymous"] satisfies UnionToArray<UserTypes>) | |
*/ | |
type UnionToArray< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mixin increase-specificity($times: 1) { | |
$selector: ""; | |
@for $index from 1 through $times { | |
$selector: #{$selector}#{&}; | |
} | |
&#{$selector} { | |
@content; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Forbid importing modules directly from feature directories | |
// Allow importing from feature directory's entrypoint, e.g. src/site/index.ts | |
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-restricted-paths.md | |
"import/no-restricted-paths": [ | |
"error", | |
{ | |
zones: ["actions", "admin", "api", "site", "shared"] | |
.map((directory) => [ | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm --no-git-tag-version version ${npm_package_version}-snapshot-${GIT_COMMIT} | |
$ npm publish --tag snapshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
printHeadings(); | |
function printHeadings() { | |
const headings = document.querySelectorAll("h1,h2,h3,h4,h5,h6"); | |
const formatted = Array.from(headings).map((element) => { | |
const tag = element.tagName; | |
const padding = parseInt(tag.charAt(1)) - 1; | |
const text = element.textContent?.replace(/\s{2,}/g, " "); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type InvertTree<Tree extends Leaf> = Tree extends { | |
left: infer Left; | |
right: infer Right; | |
} | |
? Left extends Leaf | |
? Right extends Leaf | |
? { left: InvertTree<Right>; right: InvertTree<Left>; id: Tree["id"] } | |
: { left: undefined; right: InvertTree<Left>; id: Tree["id"] } // There is left but no right | |
: Right extends Leaf | |
? { left: InvertTree<Right>; right: undefined; id: Tree["id"] } // There is right but no left |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Typings */ | |
type TicTacToe< | |
MovesOrNextBoard extends Board | Turn[], // On initial round this will be a Turn[], on next rounds it will be a Board with some moves done | |
MovesOrMissing extends Turn[] = [], // On initial round this will be empty, on next rounds it will be the moves | |
PreviousMark extends ValidMark | undefined = undefined, // On initial round this will be missing, on next rounds it will be the mark of the last move | |
CurrentBoard extends Board = ResolveBoardFromArgs<MovesOrNextBoard>, // Parsed argument | |
Moves extends Turn[] = ResolveNextMovesFromArgs<MovesOrNextBoard, MovesOrMissing> // Parsed argument | |
> = | |
Moves extends [infer NextMove, ...infer NextMoves] ? | |
NextMove extends Turn ? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
$ node --watch --no-warnings --experimental-vm-modules --experimental-import-meta-resolve vm.mjs | |
*/ | |
import vm from "node:vm"; | |
import { readFileSync } from "node:fs"; | |
import { fileURLToPath } from "node:url"; | |
import { JSDOM } from "jsdom"; | |
const server = { | |
async fetchModule(filename) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Run as `node process.mjs` and open Chrome DevTools or similar debugging tool | |
*/ | |
import { fork } from "node:child_process"; | |
import { fileURLToPath } from "node:url"; | |
import inspector from "node:inspector"; | |
const filename = fileURLToPath(import.meta.url); | |
if (!process.env.SOME_FLAG) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { writeFileSync } from "node:fs"; | |
import inspector from "node:inspector"; | |
function firstMethod() {} | |
function secondMethod() {} | |
const session = new inspector.Session(); | |
const collectedCoverage = []; | |
session.connect(); |
NewerOlder