View jsx-static.js
function __append (el, children) { | |
for (let child of children) { | |
if (!child) continue; | |
if (Array.isArray(child)) __append(el, child); | |
else if (child instanceof HTMLElement || child instanceof DocumentFragment) el.append(child); | |
else el.append(document.createTextNode(child)); | |
} | |
} |
View async-to-generator.js
function __async (generator) { | |
return function (...args) { | |
let it = generator.apply(this, args); | |
return new Promise((resolve, reject) => { | |
step(it.next()); | |
function step (result) { | |
if (result.done) resolve(result.value); | |
else Promise.resolve(result.value).then(fulfilled, rejected); |
View minified-default.js
// 249 bytes | |
var o={helloWorld:"hello-world-123",fooBar:"foo-bar-245",barBaz:"bar-baz-934"};let l=Object.assign(document.createElement("div"),{textContent:"Hello world!",className:[o.helloWorld,o.helloWorld,o.fooBar,o.barBaz].join(" ")});document.body.append(l); |
View timestamp_to_snowflake.js
let epoch = 1420070400000; | |
let increment = 0; | |
function timestamp_to_snowflake (timestamp = Date.now()) { | |
let snowflake = ''; | |
// timestamp | |
snowflake += (timestamp - epoch).toString(2).padStart(42, '0'); | |
// worker id | |
snowflake += '00001'; |
View count_occurences.js
function count (str: string, search: string) { | |
let n = -1; | |
let i = 0; | |
while (i !== -1) { | |
i = str.indexOf(search, i + 1); | |
n++; | |
} | |
return n; |
View svelte-store.js
function noop () {} | |
export function writable (init, start) { | |
let subscribers = []; | |
let prev = init; | |
let running = false; | |
let stop; | |
function notify () { | |
let subs = subscribers.concat(); |
View store.js
export function readable (init, start) { | |
function subscribe (listener) { | |
let running = true; | |
let prev = init; | |
let stop; | |
function set (curr) { | |
if (running && curr !== prev) { | |
prev = curr; | |
if (stop) listener(curr); |
View make-hot.js
// svelte-hmr/lib/make-hmr.js | |
const defaultHotOptions = { | |
// don't preserve local state | |
noPreserveState: false, | |
// escape hatch from preserve local state -- if this string appears anywhere | |
// in the component's code, then state won't be preserved for this update | |
noPreserveStateKey: '@!hmr', | |
// don't reload on fatal error | |
noReload: false, |
View range.array.js
function range (from, to) { | |
if (!to) { | |
to = from; | |
from = 0; | |
} | |
if (from > to) { | |
throw RangeError('`from` is higher than `to`'); | |
} | |
return Array.from({ length: to - from }, (_, i) => i + from); |
View brainfuck.js
class BrainfuckInterpreter { | |
constructor (program, input) { | |
this.reset(program, input); | |
} | |
reset (program, input) { | |
this.paused = true; | |
this.program = program || ''; | |
this.position = 0; |