Skip to content

Instantly share code, notes, and snippets.

Kevin Smith zenparsing

Block or report user

Report or block zenparsing

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
@zenparsing
zenparsing / dedent-template.js
Last active Nov 19, 2019
Dedenting Template Strings
View dedent-template.js
function dedent(callSite, ...args) {
function format(str) {
let size = -1;
return str.replace(/\n(\s+)/g, (m, m1) => {
if (size < 0)
size = m1.replace(/\t/g, " ").length;
View Explainer.md

Symbol Literals

The form @identifierName is a symbol literal. Within any single module or script, two identitical symbol literals refer to the same symbol. Two identical symbol literals in separate modules or scripts refer to different symbols. A symbol literal may appear as a propery name or as a primary expression.

When a symbol literal appears as a primary expression, it is shorthand for this.@identifierName.

When a symbol literal appears as a property name, the corresponding symbol is used as the property key during evaluation.

View combinators-with-async-generators.js
function once(el, event) {
return new Promise((resolve, reject) => {
const handler = e => {
resolve(e);
el.removeEventListener(event, handler);
};
el.addEventListener(event, handler);
});
};
@zenparsing
zenparsing / a.js
Created Feb 1, 2019
Built-time macros strawman
View a.js
import { deprecated } from './macros/deprecated.js';
// Using Rust-like syntax only to make it clear these
// are macros and not "decorators"
#[deprecated]
function dontUseMeAnymore() {
eval('You wrote a bad song, Petey!');
}
@zenparsing
zenparsing / optional-chaining-proxy.js
Last active Nov 22, 2018
Optional chaining with JS Proxy
View optional-chaining-proxy.js
const unwrapSymbol = Symbol();
function unwrap(x) {
if (this == null)
return this;
let f = this[unwrapSymbol];
if (typeof f !== "function")
@zenparsing
zenparsing / observable-to-async-iterator.js
Last active Jul 18, 2018
Observable to Async Iterator
View observable-to-async-iterator.js
Observable.prototype[Symbol.asyncIterator] = async function*() {
function promiseCapability() {
x = {};
x.promise = new Promise((a, b) => {
x.resolve = a;
x.reject = b;
});
return x;
}
@zenparsing
zenparsing / observable-take-random-n.js
Created Jan 31, 2018
Observable: Take a random number of integers
View observable-take-random-n.js
function* range(from, to) {
for (let i = from; i <= to; ++i) {
yield i;
}
}
function take(source, n) {
if (n <= 0) {
return Observable.from([]);
}
@zenparsing
zenparsing / node-module-lookup.md
Last active Dec 12, 2017
Node Module Lookup Rules
View node-module-lookup.md

ES6 Module Loading in Node.js

Guiding Principles

  • The solution must be 100% backward-compatible.
  • In the far future, developers should be able to write Node programs and libraries without knowledge of the CommonJS module system.
  • Module resolution rules should be reasonably compatible with the module resolution rules used by browsers.
  • The ability to import a legacy package is important for adoption.

Design Summary

@zenparsing
zenparsing / CustomEventHub.js
Last active Feb 22, 2016
A simple custom event hub for simple DOM apps
View CustomEventHub.js
let CustomEvent = window.CustomEvent;
if (typeof CustomEvent !== "function") {
// Internet Explorer
CustomEvent = function(name, options = {}) {
let {
bubbles = false,
cancelable = false,
detail
} = options;
@zenparsing
zenparsing / combinators-with-implicit-cancel-tokens.js
Last active Feb 9, 2016
Promise-Observable Combinators with Implicit Cancel Tokens
View combinators-with-implicit-cancel-tokens.js
function takeUntil(control) {
return new Observable(next => new Promise((resolve, reject) => {
this.forEach(next).then(resolve, reject);
control.forEach(resolve).catch(reject);
}));
}
function switch() {
You can’t perform that action at this time.