2018-04-26 19:38:57 +03:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const version = require("./package.json").version;
|
|
|
|
|
|
|
|
const core = require("./src/main/core");
|
|
|
|
const getSupportInfo = require("./src/main/support").getSupportInfo;
|
2018-05-27 02:25:36 +03:00
|
|
|
const sharedUtil = require("./src/common/util-shared");
|
|
|
|
|
|
|
|
const doc = require("./src/doc");
|
2018-04-26 19:38:57 +03:00
|
|
|
|
|
|
|
const internalPlugins = [
|
|
|
|
require("./src/language-js"),
|
|
|
|
require("./src/language-css"),
|
|
|
|
require("./src/language-graphql"),
|
|
|
|
require("./src/language-markdown"),
|
2018-06-21 05:29:42 +03:00
|
|
|
require("./src/language-vue"),
|
|
|
|
require("./src/language-yaml")
|
2018-04-26 19:38:57 +03:00
|
|
|
];
|
2018-05-24 21:30:45 +03:00
|
|
|
|
|
|
|
const isArray =
|
|
|
|
Array.isArray ||
|
|
|
|
function(arr) {
|
|
|
|
return Object.prototype.toString.call(arr) === "[object Array]";
|
|
|
|
};
|
2018-04-26 19:38:57 +03:00
|
|
|
|
|
|
|
// Luckily `opts` is always the 2nd argument
|
|
|
|
function withPlugins(fn) {
|
|
|
|
return function() {
|
|
|
|
const args = Array.from(arguments);
|
2018-05-24 21:30:45 +03:00
|
|
|
let plugins = (args[1] && args[1].plugins) || [];
|
|
|
|
if (!isArray(plugins)) {
|
|
|
|
plugins = Object.values(plugins);
|
|
|
|
}
|
|
|
|
args[1] = Object.assign({}, args[1], {
|
|
|
|
plugins: internalPlugins.concat(plugins)
|
2018-04-26 19:38:57 +03:00
|
|
|
});
|
|
|
|
return fn.apply(null, args);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-05-27 02:25:36 +03:00
|
|
|
const formatWithCursor = withPlugins(core.formatWithCursor);
|
|
|
|
|
2018-04-26 19:38:57 +03:00
|
|
|
module.exports = {
|
2018-05-27 02:25:36 +03:00
|
|
|
formatWithCursor: formatWithCursor,
|
|
|
|
|
2018-04-26 19:38:57 +03:00
|
|
|
format(text, opts) {
|
2018-05-27 02:25:36 +03:00
|
|
|
return formatWithCursor(text, opts).formatted;
|
2018-04-26 19:38:57 +03:00
|
|
|
},
|
|
|
|
|
2018-05-27 02:25:36 +03:00
|
|
|
check(text, opts) {
|
|
|
|
const formatted = formatWithCursor(text, opts).formatted;
|
|
|
|
return formatted === text;
|
|
|
|
},
|
|
|
|
|
|
|
|
doc,
|
|
|
|
|
2018-04-26 19:38:57 +03:00
|
|
|
getSupportInfo: withPlugins(getSupportInfo),
|
|
|
|
|
|
|
|
version,
|
|
|
|
|
2018-05-27 02:25:36 +03:00
|
|
|
util: sharedUtil,
|
|
|
|
|
2018-04-26 19:38:57 +03:00
|
|
|
__debug: {
|
|
|
|
parse: withPlugins(core.parse),
|
|
|
|
formatAST: withPlugins(core.formatAST),
|
|
|
|
formatDoc: withPlugins(core.formatDoc),
|
|
|
|
printToDoc: withPlugins(core.printToDoc),
|
|
|
|
printDocToString: withPlugins(core.printDocToString)
|
|
|
|
}
|
|
|
|
};
|