Skip to content

Instantly share code, notes, and snippets.

View danielweck's full-sized avatar
👀

Daniel Weck danielweck

👀
View GitHub Profile

Unistore Hooks for Preact

Experimental hooks-based bindings for Unistore. Available on npm:

npm i unistore-hooks

Note: this should also work with React, just alias "preact" and "preact/hooks" to "react" in your bundler.

Usage

Module Workers Polyfill npm version

This is a 1.1kb polyfill for Module Workers.

It adds support for new Worker('..',{type:'module'}) to all modern browsers (those that support fetch).

Usage

Copy module-workers-polyfill.js to your web directory, then load it using an import or a script tag. It just needs to be loaded before instantiating your Worker.

@developit
developit / *cjyes.md
Last active July 25, 2023 12:54
more-or-less instant command-line ESM to CJS transform. Copies from src to dist. `cjyes src/*.js`

cjyes npm version

🔍 see jay, yes! 🎉 / 👨🏻‍💻 see, JS! 👾 / ⚓️ sea JS ⛴

If you're publishing ES Modules, you need to also publish CommonJS versions of those modules.

This isn't to support old browsers or Node versions: even in Node 14, using require() to load a module won't work if it's only available as ESM.

cjyes is the bare minimum fix for this problem. You write ES Modules and fill out a valid package.json, and it'll generate the corresponding CommonJS files pretty much instantly. cjyes takes up 500kb of disk space including its two dependencies.

Standalone forwardRef

import { forwardRef } from 'preact-forwardref';

const Foo = forwardRef((props, ref) => {
  return <div ref={ref} />
});

render( console.log(div)} /&gt;, document.body);
import { h, hydrate, Component } from 'preact';
function interopDefault(mod) {
return mod && mod.default || mod;
}
export function ServerHydrator({ load, ...props }) {
const Child = interopDefault(load());
return (
<section>
import regexparam from 'https://unpkg.com/regexparam@1/dist/regexparam.mjs';
/**
* <url-route href="/profile/:user">
* <div>some content here</div>
* </url-route>
*/
customElements.define('url-route', class UrlRoute extends HTMLElement {
connectedCallback() {
this.route = regexparam(this.getAttribute('href'));
; (function (global, define) { define('module-name', function (require, exports, module) {
// CommonJS style code here
/*!
* UMD/AMD/Global context Module Loader wrapper
* based off https://gist.github.com/tejacques/202a8f2d198ddd54a409
*
* This wrapper will try to use a module loader with the
* following priority:
*
@woollsta
woollsta / chunkify.js
Last active December 25, 2023 10:45
Fixes an issue with Google Chrome Speech Synthesis where long texts pause mid-speaking. The function takes in a speechUtterance object and intelligently chunks it into smaller blocks of text that are stringed together one after the other. Basically, you can play any length of text. See http://stackoverflow.com/questions/21947730/chrome-speech-sy…
/**
* Chunkify
* Google Chrome Speech Synthesis Chunking Pattern
* Fixes inconsistencies with speaking long texts in speechUtterance objects
* Licensed under the MIT License
*
* Peter Woolley and Brett Zamir
*/
var speechUtteranceChunker = function (utt, settings, callback) {