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
// Usage: | |
// let parseRoute = routeParser("/users/{userId}/posts/{postId}"); | |
// let params = parseRoute("/users/123/posts/456"); | |
// console.log(params); // { userId: "123", postId: "456" } | |
const KIND_KEY = "key" as const; | |
const KIND_VALUE = "value" as const; | |
/** | |
* Create a route parser from a route string. |
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
export const getSheetSize = (spriteWidth, spriteHeight, spriteCount) => { | |
const a = Math.max(spriteWidth, spriteHeight); | |
const b = Math.min(spriteWidth, spriteHeight); | |
let sizeA = 1 << (32 - Math.clz32(a)); | |
let sizeB = 1 << (32 - Math.clz32(b)); | |
let countA = 1; | |
let countB = 1; | |
while (spriteCount > countA * countB) { | |
if (sizeA < sizeB) { |
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
const NOTE = 69; | |
const NOTE_ON = 0x90; | |
const NOTE_OFF = 0x80; | |
const SECONDS = 1000; | |
function startSequencer (destination) { | |
let active = false; | |
setInterval(() => { | |
const now = performance.now(); | |
const type = active ? NOTE_OFF : NOTE_ON; |
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
async function mapAsync (iterator, fn) { | |
let result = []; | |
for ( let itemPromise of await iterator ) { | |
let item = await itemPromise; | |
result.push(await fn(item)); | |
} | |
return result; | |
} | |
async function filterAsync (iterator, fn) { |
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 context = new AudioContext(); | |
var sineWorker = context.createAudioWorker("worker.js"); | |
function createSineNode (frequency) { | |
var node = context.createAudioWorkerNode(sineWorker, { | |
numberOfInputChannels: 0, | |
numberOfOutputChannels: 1, | |
parameters: { | |
frequency: frequency || 440, | |
}, |
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
function loadAudio (url, playbackRate) { | |
return new Promise(function (resolve, reject) { | |
var track = new Audio(url); | |
track.playbackRate = playbackRate; | |
track.oncanplaythrough = function () { | |
resolve(track); | |
}; | |
track.onerror = reject; |
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
function getAudioData (url, time) { | |
return new Promise(function (resolve, reject) { | |
var context = new AudioContext(); | |
var track = new Audio(url); | |
var bufferLength = time * context.sampleRate; | |
var buffer = new Float32Array(bufferLength); | |
var collector = context.createScriptProcessor(0, 1); | |
var audioSource = context.createMediaElementSource(track); | |
var samplesCollected = 0; |
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 context = new AudioContext(); | |
var audioWorker = context.createAudioWorker("worker.js"); | |
var sine1 = context.createAudioWorkerNode(audioWorker, { | |
numberOfInputChannels: 0, | |
numberOfOutputChannels: 1, | |
parameters: { | |
frequency: 440, | |
}, | |
}); | |
var sine2 = context.createAudioWorkerNode(audioWorker, { |
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 context = new AudioContext(); | |
var audioWorker = context.createAudioWorker("worker.js"); | |
var sine = context.createAudioWorkerNode(audioWorker, { | |
numberOfInputChannels: 0, | |
numberOfOutputChannels: 1, | |
parameters: { | |
frequency: 440, | |
}, | |
data: { | |
type: "sine", |
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
// localforage.js | |
// if the module exports a promise, the loader waits until the promise resolves into something, | |
// and that is what gets imported outside. | |
export System.import("./IndexedDbDriver") | |
.catch(=> System.import("./WebSqlDriver") ) | |
.catch(=> System.import("./LocalStorageDriver") ); | |
// IndexedDbDriver.js |
NewerOlder