dprint@scrapbox
dependencies
code:script.js
import {createStreaming} from '../dprint@0.1.4/script.js';
let tsFormatter;
export async function createTsFormatter() {
tsFormatter = tsFormatter ?? await createStreaming(fetch('/files/60dce0c2052ce30021aa022c.wasm'));
return tsFormatter;
}
test code
code:js
(async () => {
const {execute} = await import('/api/code/takker/dprint@scrapbox/test.js');
console.log(await execute(`
const t = 5;
const s = "aa // ここでエラーが発生する
const k = t + s;
`));
})();
code:test.js
import {createTsFormatter} from './script.js';
export async function execute(text, config) {
const formatter = await createTsFormatter();
try {
return {
success: true,
code: await formatter.formatText('file.ts', text, config ?? {
indentWidth: 2,
lineWidth: 80,
semiColons: 'asi',
}),
};
} catch(e) {
return {success: false, error: e.message ?? e};
}
}