Skip to content

Instantly share code, notes, and snippets.

Ron Buckton rbuckton

Block or report user

Report or block rbuckton

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rbuckton
rbuckton / indexAndInterval.js
Last active Aug 23, 2019
Index and Interval types and syntax
View indexAndInterval.js
// Symbols:
// @@geti - An inverted-get. When present on an object used in an element access, calls this method rather than coercing
// the object to a String.
// ex: `a[b]` --> `b[@@geti](a)`
// @@seti - An inverted-set. When present on an object used in an element access assignment, calls this method rather
// than coercing the object to a String.
// ex: `a[b] = 1` --> `b[@@seti](a, 1)`
// @@indexedGet - Gets a value from an object in relation to a given `Index` instance.
// @@indexedSet - Sets a value on an object in relation to a given `Index` instance.
// @@slice - Gets values from an object in relation to a given `Interval` instance.
View NodeJS Events.ts
export {};
/** A non-existent symbol used to define the types of events defined on an object */
declare const kEvents: unique symbol;
/** Gets the events defined on an object. */
type Events<T> = T extends { readonly [kEvents]: infer Events } ? Events : {};
/** Get the names of events defined on an object. */
type EventNames<T> = keyof Events<T>;
View async-try-using.js
Symbol.asyncDispose = Symbol.for("Symbol.asyncDispose");
function __asyncUsing(obj) {
let state = obj !== null && obj !== undefined ? 0 : 2;
return {
[Symbol.asyncIterator]() { return this; },
async next() {
if (state) return this.return();
state = 1;
return { value: obj };
},
View uid.grammarkdown
//
// Lexical Grammar
//
SourceCharacter::
> Any unicode code point
WhiteSpace::
<TAB>
<VT>
View decorators-again.md

Decorators, Take 4

A decorator is a function that returns a series of "hooks":

function dec() {
  return [
    { register(klass) { } },
    { register(target, key) { } },
    { wrap(f) { return f; } },
    { initialize(target, key, value) { } },
View temporal.d.ts
declare type DateUnit = "year" | "month" | "day";
declare type DateDelta = "years" | "months" | "weeks" | "days";
declare type TimeUnit = "hour" | "minute" | "second" | "millisecond" | "nanosecond";
declare type TimeDelta = "hours" | "minutes" | "seconds" | "milliseconds" | "nanoseconds";
declare type InstantUnit = "milliseconds" | "nanoseconds";
declare type InstantDelta = "milliseconds" | "nanoseconds";
declare type Components<Unit extends string> = Partial<Record<Unit, number>>;
// Represents either a fixed-offset time-zone, the SYSTEM time-zone, or a regional (IANA) time-zone.
declare class Zone {
static readonly Z: Zone;
View jslinq.md

Language-integrated Query syntax for ECMAScript

This is a strawman for an advanced generator-comprehension syntax for ECMAScript based in the LINQ syntax. The syntax allows for custom semantics for evaluation, as each clause in a query is translated into regular function calls for special symbol-named methods that are evaluated if found on the sequence (see Abstract Operations for more information).

Examples

View friend.js
const friendship = new WeakMap();
function friend(ref granteeClass) {
return function (descriptor) {
descriptor.finisher = (granterClass) => {
let info = friendship.get(granterClass);
if (!info) {
const names = descriptor.elements
.filter(element => element.name instanceof PrivateName)
.reduce((map, element) => map.set(element.name.description, element.name), new Map());
View ClassProperty.md

Introduction

This is a strawman for the inclusion of a new ClassProperty syntax:

class C {
  static f() { ... }
  
  g() {
    class.f();
@rbuckton
rbuckton / freezeDecorator.js
Created Mar 2, 2018
A rough outline for a userland `@Freeze` decorator that does not require "instance finishers".
View freezeDecorator.js
//
// definition
//
// marker used to indicate a constructor is a freeesing constructor (see below).
const marker = new WeakSet();
export function freeze(descriptor) {
// save the previous constructor
const previousConstructor = descriptor.constructor;
You can’t perform that action at this time.