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
| // +++ https://blog.garstasio.com/you-dont-need-jquery/selectors/ | |
| // http://youmightnotneedjquery.com/ | |
| /// various access | |
| self // https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope | |
| self.origin | |
| self.isSecureContext | |
| window | |
| window.document |
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
| /////// GET | |
| fetch('/user/search?activeFilter=pending&max-results=11') | |
| .then(response => { | |
| const {ok, status} = response; | |
| if (!ok || status !== 200) | |
| throw new Error(); | |
| return response.json(); | |
| }) | |
| .catch((e => { | |
| console.log('parsing failed or whatever', e) |
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
| // https://github.com/Offirmo/blog/blob/gh-pages/tosort/javascript-daily/mod-floating.md | |
| const floating = require('floating.js) | |
| floating({ | |
| content: '<span style="color: snow">❄</span>', | |
| number: 25, | |
| direction: 'reverse', | |
| size: [0.5, 2.5], | |
| }) |
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
| // http://youmightnotneedjquery.com/ | |
| // DOM manipulation | |
| ///////////////////////////// | |
| // create and insert elements | |
| const fragment = document.createDocumentFragment() | |
| fragment.appendChild(document.createComment('Created by LIB')) |
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
| // new | |
| return (...args) => { | |
| try { | |
| return handler.call(this, ...args); | |
| } catch(e) { | |
| return this.onError(e); | |
| } | |
| }; | |
| // old school |
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
| /////// fetch /////// | |
| const originalFetch = window.fetch; | |
| window.fetch = async (...args) => { | |
| const fetchee = await originalFetch(...args); | |
| return new Proxy(fetchee, {}); | |
| }; | |
| new Proxy(target, { |
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
| // imports | |
| import { Random, Engine } from '@offirmo/random' | |
| import { | |
| State as MetaState, | |
| factory as meta_state_factory, | |
| } from '@oh-my-rpg/state-meta' | |
| // http://www.benmvp.com/learning-es6-enhanced-object-literals/ | |
| return { |
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
| var global_module_instance; | |
| Object.defineProperty(window, 'global_ng_module', { | |
| enumerable: true, // why not ? | |
| set: function() { | |
| throw new Error('You can’t assign window.global_module !'); | |
| }, | |
| get: function() { | |
| if(global_module_instance) return global_module_instance; // already OK | |
| global_module_instance = angular.module('global_ng_module', [ | |
| 'ui.bootstrap' |
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
| // debg | |
| let DEBUG = false | |
| try { // defensive! | |
| DEBUG = DEBUG || !!window.localStorage.getItem(`${APP}.debug`) | |
| } catch (e) { /* swallow */ } | |
| if (DEBUG) console.info(`Hello from ${APP}`) | |
| // prepare an url | |
| // https://devdocs.io/javascript/global_objects/encodeuri |
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
| https://github.com/terkelg/facon | |
| // in Offirmo monorepo! | |
| function poll(predicate, options) { | |
| // early check to save an initial poll period | |
| let result = predicate(); | |
| if (result) | |
| return Promise.resolve(result); |