forked from OKEAMAH/prettier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandalone.js
More file actions
56 lines (47 loc) · 1.47 KB
/
standalone.js
File metadata and controls
56 lines (47 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import * as core from "./main/core.js";
import { getSupportInfo as getSupportInfoWithoutPlugins } from "./main/support.js";
function withPlugins(
fn,
optionsArgumentIndex = 1, // Usually `options` is the 2nd argument
) {
// Returns Promises to consistent with functions in `index.js`
// eslint-disable-next-line require-await
return async (...args) => {
const options = args[optionsArgumentIndex] ?? {};
const plugins = options.plugins ?? [];
args[optionsArgumentIndex] = {
...options,
plugins: Array.isArray(plugins) ? plugins : Object.values(plugins),
};
return fn(...args);
};
}
const formatWithCursor = withPlugins(core.formatWithCursor);
async function format(text, options) {
const { formatted } = await formatWithCursor(text, {
...options,
cursorOffset: -1,
});
return formatted;
}
async function check(text, options) {
return (await format(text, options)) === text;
}
const getSupportInfo = withPlugins(getSupportInfoWithoutPlugins, 0);
const debugApis = {
parse: withPlugins(core.parse),
formatAST: withPlugins(core.formatAst),
formatDoc: withPlugins(core.formatDoc),
printToDoc: withPlugins(core.printToDoc),
printDocToString: withPlugins(core.printDocToString),
};
export {
debugApis as __debug,
check,
format,
formatWithCursor,
getSupportInfo,
};
export * as doc from "./document/public.js";
export { default as version } from "./main/version.evaluate.cjs";
export * as util from "./utils/public.js";