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
// Since typescript nominally types string based enums, we emulate | |
// the subtractive type `object - T` by making all the properties | |
// T optional and setting their types to a non-exported enum. | |
// | |
// The enum name is long and descriptive to help with debugging. | |
const enum CannotAssignToPropertyFromExcludedObject { ϕ = "ϕ" } | |
type Excluding<T extends object> = { [P in keyof T]?: CannotAssignToPropertyFromExcludedObject; } & { [prop: string]: any; } | |
// Note: If some overlap is acceptable, providing that the overlapping property extends T[P], use | |
// type Excluding<T extends object> = Partial<T> & { [prop: string]: any }; |
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
// true only when `T = any`. When `T = unknown`, returns false. | |
// `(T extends never ? IsAny : IsNotAny)` produces `IsNotAny` for most types other than any. | |
// but `(never extends never ? IsAny : IsNotAny)` produces `never` and | |
// `(any extends never ? IsAny : IsNotAny)` produces `IsAny|IsNotAny`. | |
// So we wrap it in a second conditional to filter it down to a concrete type. | |
type isAny<T> = (T extends never ? number : string) extends string ? false : true; | |
// variation on the above, without the double-conditional. | |
type standardIsAny<T> = 0 extends T & 1 ? true : false; | |
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 Bind1<T> = T extends (this: unknown, ...args: infer V) => infer W ? (...args: V) => W : T extends (this: infer U, ...args: infer V) => infer W ? (this: U, ...args: V) => W : never; | |
export type EmitterParameters<T extends Emitter<any>> = T extends Emitter<infer U> ? Parameters<U> : []; | |
export interface EmitterEmittable<F extends (...args: any[]) => any, E extends (...args: any[]) => any = F> { | |
/* | |
* Emit the {@link values}. | |
* | |
* @param defaultContext Default context to bind each function's `this`. | |
* @param values Values to emit. |
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
/** | |
* A TypeScript type compatible runtime type-verification system. | |
* | |
* Each instance of {@link Runtype} is a complete type-verification system that | |
* can prove that an _unknown_ type is actually _known_ type. Runtypes can be | |
* composed via the convenience constructors {@link Union}, | |
* {@link Intersection}, {@link Tuple}, and {@link struct}. Additionally, when | |
* constructing a new {@link Runtype}, a parent constraint may be specified in | |
* {@link RuntypeConfig}. | |
* |
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
export interface Multimap<K, V> extends Map<K, V> { | |
clear(): void; | |
delete(key: K): boolean; | |
delete(key: K, value: V): boolean; | |
forEach(callbackfn: (value: V, key: K, map: this) => void, thisArg?: any): void; | |
get(key: K): V | undefined; | |
get(key: K, value: V): V | undefined; | |
getAll(key: K): Set<V> | undefined; | |
has(key: K): boolean; | |
has(key: K, value: V): boolean; |
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 {Multimap, ReadonlyMultimap} from "./multimap"; | |
export type NoInfer<T> = T & { [K in keyof T]: T[K] }; | |
function identityProjection<T>(value: any, primary: T) { return primary } | |
/** | |
* Project some sequence of values onto a Map using keys generated by | |
* {@link surrogate}. Values with the same surrogate key will overwrite, with | |
* the later insertion order overwriting the earlier. |
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
// Find the first item of a list. | |
export type Head<List extends readonly unknown[]> = | |
0 extends keyof List ? List[0] : never; | |
// Find the last item of a list. | |
export type Last<List extends readonly unknown[]> = | |
List["length"] extends 0 ? never | |
: List extends [] ? never | |
: number extends List["length"] ? List[1e+309] | |
: List[Tail<List>["length"]]; |
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 UnionToIntersection< | |
T, | |
U = T extends unknown ? { _: { [_ in T & PropertyKey]: never } } : {}, | |
V = keyof U[keyof U], | |
// We need to remove the primitive we branded T with when we made it a | |
// property key. However, if the union T contains a branded type already, | |
// we must avoid stripping those brands off. | |
X = true extends (T extends PropertyKey ? true : never) ? never : PropertyKey | |
> = T extends never ? never : V extends X & infer W ? W : V; |
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
/** | |
* Unshift T onto the arguments list of S. | |
*/ | |
type Unshift<S extends (...args: any[]) => any, T> = | |
S extends (...args: infer U) => any ? (arg: T, ...args: U) => any : never; | |
/** | |
* Generate all the prefixes of T, not including | |
* the nullary function nor T itself (unless T variadic). | |
* Return types are not preserved. |
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use v5.22; | |
use feature qw(signatures); | |
no warnings qw(experimental::signatures); | |
# This script will, when called by dnsmasq's dhcp-script hook, create a per-host | |
# configuration file. The default configuration will instruct dnsmasq to route | |
# all subdomains (*.hostname.$DOMAIN) to the hosts leased ip address. |