author: @nicholaswmin, 2021
from: Design Patterns: Elements of Object-Oriented Software
by: Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides
License: MIT-0
> [!IMPORTANT]
| { | |
| "scripts": { | |
| "size": "rm -rf .tmp/ && npx ncc build index.js -o .tmp -m -q && gzip .tmp/index.js && wc -c < .tmp/index.js.gz | xargs", | |
| } | |
| } |
| const template = document.createElement('template') | |
| template.innerHTML = /*html*/` | |
| <style> | |
| * { | |
| font-size: 200%; | |
| } | |
| span { | |
| width: 4rem; | |
| display: inline-block; |
| // highlighted.js | |
| // patched to adapt to external layout changes | |
| /*! (c) Andrea Giammarchi @webreflection ISC */ | |
| !function(){"use strict";var e=function(e,t){var n=function(e){for(var t=0,n=e.length;t<n;t++)r(e[t])},r=function(e){var t=e.target,n=e.attributeName,r=e.oldValue;t.attributeChangedCallback(n,r,t.getAttribute(n))};return function(o,a){var l=o.constructor.observedAttributes;return l&&e(a).then((function(){new t(n).observe(o,{attributes:!0,attributeOldValue:!0,attributeFilter:l});for(var e=0,a=l.length;e<a;e++)o.hasAttribute(l[e])&&r({target:o,attributeName:l[e],oldValue:null})})),o}};function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function n(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from( |
| /* | |
| Pretty Syntax Errors | |
| > @nicholaswmin, MIT License | |
| A SyntaxError that pretty-prints the and higlights error line & column, | |
| in your source. | |
| This is only useful if you're building a compiler/lexer/tokenizer. | |
| Although it is an `instanceof SyntaxError`, their similarities end there. |
| /* | |
| ** IMPORTANT: This is rather pointless. The Locator API does most of the work replicated here ** | |
| Browser unit-tests for: `pptr.mixin.js` | |
| > in chrome ~~& firefox~~ | |
| The following should have beeen installed on `npm install`: | |
| ```bash |
| /* | |
| tiny stack-based calculator | |
| - If you're looking for a fancier expression calculator, | |
| this isn't it. What you're looking for is a "Shunting Yard" | |
| implementation. This is intentionally simple. | |
| @nicholaswmin, MIT License | |
| -- Usage: -- |
author: @nicholaswmin, 2021
from: Design Patterns: Elements of Object-Oriented Software
by: Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides
License: MIT-0
> [!IMPORTANT]
| /* examples: | |
| $$('.button').map(el => el.on('click', console.log)) | |
| $('body').on('mouseenter', console.log) */ | |
| Node.prototype.on = Node.prototype.addEventListener | |
| window.$ = document.querySelectorAll.bind(document) | |
| window.$$ = (...a) => Array.from(document.querySelectorAll(...a)) |
| /** @function | |
| * @name validated | |
| * @summary validate the type of a value | |
| * | |
| * @description | |
| * validates a value against a {spec}. object, specifying: | |
| * - parameter {name} | |
| * - expected {type} | |
| * {type} suppers & differentiates non-standard "array" and "null" types. | |
| * |