index.js 933 字节
Newer Older
B
baiy 已提交
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
import js from "./javascript"
import json from "./json"
import ts from "./typescript"
import css from "./css"
import html from "./html"
import sql from "./sql"
import xml from "./xml"
import php from "./php"
import yaml from "./yaml"
import markdown from "./markdown"
import graphql from "./graphql"
import vue from "./vue"
import less from "./less"
import scss from "./scss"
import angular from "./angular"

const methods = {
    js,
    json,
    ts,
    vue,
    graphql,
    markdown,
    css,
    less,
    scss,
    yaml,
    html,
    angular,
    xml,
    php,
    sql
};

// 代码格式化
export const format = (code, lang, isCompress = false, options = {}) => {
    let method = isCompress ? "compress" : "beautify";
B
baiy 已提交
38 39
    if (!(lang in methods) || !(method in methods[lang])){
        throw new Error(`lang:"${lang}" not support ${method}`);
B
baiy 已提交
40 41 42 43 44 45
    }
    return methods[lang][method](code,options)
};

export default format