@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
22 lines (19 loc) • 638 B
JavaScript
import { assert } from "../assert.js";
import { codeToBlob } from "./codeToBlob.js";
/**
*
* @param {string} code
* @param {string} [mime_type]
* @return {string}
*/
export function codeToURL(code, mime_type = 'application/javascript') {
assert.isString(code, 'code');
assert.isString(mime_type, 'mime_type');
const blob = codeToBlob(code, mime_type);
if (blob !== undefined && URL.createObjectURL !== undefined) {
return URL.createObjectURL(blob);
} else {
// build data URL in a slowest way possible
return `data:${mime_type},${encodeURIComponent(code)}`;
}
}