This file contains hidden or 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
// 6 May 2023 | |
// Element.innerHTML vs. DOMParser.parseFromString(html) | |
// 7 May 2023 | |
// added unbalanced tags, escaped HTML, event handler attribute cases. | |
// 22 July 2023 | |
// Thanks to sharp eyes (Justin Fignani) who found several assertions were flat | |
// out wrong, probably due to running these tests in the console, frequently the | |
// incognito windows which have different CSP settings depending what "blank" page |
This file contains hidden or 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
// 7 April 2023 | |
// JavaScript event emitter from Wikipedia's Event-Driven Architecture page | |
// https://en.wikipedia.org/wiki/Event-driven_architecture | |
// Modified from the original. | |
// Interesting for the ECMA2023 class features and Map, Set, et al | |
(() => { | |
'use strict'; |
This file contains hidden or 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
// 26 March 2023 | |
// effects of adding or removing a property on elements with or | |
// without their corresponding attribute. | |
// continued from merge-style gist where it was discovered that adding a style property | |
// creates a style attribute on elements without one initially. | |
// [ in progress: lots of cases to think through... ] | |
// I use `var` because I re-run these console tests repeatedly in the browser. |
This file contains hidden or 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
// 8-9 March 2023 | |
// component.create | |
// factory pattern to create worker-like component objects or actors (eventually) | |
// no big plans for expansion, just an illustration; however, | |
// a couple methods trying to wriggle into the implementation include: | |
// 1. extend()...? maybe. | |
// 2. terminate() + onterminate()...? maybe. | |
// suppose we could turn this into a closure and track each created object |
This file contains hidden or 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
// 3-6 March 2023 | |
// style attributes vs. style properties | |
// differences between replace vs. merge | |
// replacing props vs. replacing attributes | |
// no surprises | |
// merging props vs. merging attributes | |
// at least one surprise, namely, that adding a style property | |
// creates a style attribute on elements without one initially. |
This file contains hidden or 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
// 2 March 2023 | |
// intersections from more than two arrays | |
// goaded by https://frontendroom.com/intersection-of-multiple-arrays-in-js/ | |
// works on arrays of values and arrays of objects with a single key; | |
// not sure I agree with the multiple keys matching output. | |
// values | |
var a = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7"] |
This file contains hidden or 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
// 25 February 2023 | |
// detect whether something is a class in JavaScript, not just a function. | |
// warning: this is not tamper-proof. | |
// @webreflection figured this out | |
// https://stackoverflow.com/questions/30758961/how-to-check-if-a-variable-is-an-es6-class-declaration/75567955#75567955 | |
// The test? | |
// The variable is typeof function and its prototype field is not writable. |
This file contains hidden or 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
// 17 February 2023 | |
// lift parts out of a value | |
// using the Object constructor guard | |
function lift(v, key) { | |
var o = Object(v); | |
return Object.hasOwn(o, key) | |
? o[key] | |
: undefined; |
This file contains hidden or 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
// 5 February 2023 | |
// partial-equal in JavaScript | |
// inspired by https://brandur.org/fragments/partial-equal | |
// compare an object's values to a minimal "schema" which can be a primitive, | |
// allows extra fields on the compared object but expected fields must match | |
// expected values, including symbols as field names and field values; | |
// first failure terminates, logs a warning. |
This file contains hidden or 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
// 1 February 2023 | |
// modified template literal data rendering example from | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals | |
// from https://gist.github.com/dfkaye/0597d0bfbfefbd31b72731c2f543b85e | |
function parseHTML(str) { | |
return new DOMParser().parseFromString(String(str).trim(), 'text/html').body; | |
}; | |